protected void DryEventRecieved(MssEvent dryEvent) { if (!enabled) { return; } Debug.WriteLine("In: " + FormatEvent(dryEvent)); }
protected void WetEventRecieved(MssEvent wetEvent) { if (!enabled) { return; } Debug.WriteLine("Out: " + FormatEvent(wetEvent)); }
protected void DryEventRecieved(MssEvent dryEvent) { if (!enabled) { return; } Debug.WriteLine("In: " + FormatEvent(dryEvent)); }
protected void WetEventRecieved(MssEvent wetEvent) { if (!enabled) { return; } Debug.WriteLine("Out: " + FormatEvent(wetEvent)); }
protected string FormatEvent(MssEvent mssEvent) { return string.Format("{0} {1}, {2}, {3} at {4}", mssEvent.mssMsg.Type, Math.Round(mssEvent.mssMsg.Data1, 3), Math.Round(mssEvent.mssMsg.Data2, 3), Math.Round(mssEvent.mssMsg.Data3, 3), mssEvent.sampleTime); }
protected string FormatEvent(MssEvent mssEvent) { return(string.Format("{0} {1}, {2}, {3} at {4}", mssEvent.mssMsg.Type, Math.Round(mssEvent.mssMsg.Data1, 3), Math.Round(mssEvent.mssMsg.Data2, 3), Math.Round(mssEvent.mssMsg.Data3, 3), mssEvent.sampleTime)); }
/// <summary> /// Event handler for MssEvents coming /// </summary> /// <param name="dryMssEvent"></param> protected void dryMssEventOutputPort_DryMssEventRecieved(MssEvent dryMssEvent) { foreach (MssMsg mssMsg in this.mssMsgProcessor.ProcessMssMsg(dryMssEvent.mssMsg)) { MssEvent wetEvent = new MssEvent(); wetEvent.mssMsg = mssMsg; wetEvent.sampleTime = dryMssEvent.sampleTime; //Send the processed MssEvent to the WetMssEventRelay this.wetMssEventInputPort.ReceiveWetMssEvent(wetEvent); } }
/// <summary> /// Event handler for MssEvents coming /// </summary> /// <param name="dryMssEvent"></param> protected void dryMssEventOutputPort_DryMssEventRecieved(MssEvent dryMssEvent) { foreach (MssMsg mssMsg in this.mssMsgProcessor.ProcessMssMsg(dryMssEvent.mssMsg)) { MssEvent wetEvent = new MssEvent(); wetEvent.mssMsg = mssMsg; wetEvent.sampleTime = dryMssEvent.sampleTime; //Send the processed MssEvent to the WetMssEventRelay this.wetMssEventInputPort.ReceiveWetMssEvent(wetEvent); } }
public void ConvertMssEventToVstMidiEvent_NoValidConversion_ReturnsNull() { MidiHandlerProtectedWrapper midiHandler = Factory_MidiHandler_Basic(); long sampleTime = 123456; MssEvent internalEvent = new MssEvent(); internalEvent.mssMsg = new MssMsg(MssMsgType.Generator, 0, 0, 0); internalEvent.sampleTime = sampleTime; VstMidiEvent convertedEvent = midiHandler.ConvertMssEventToVstMidiEventWrapper( internalEvent, sampleTime, this.hostInfoOutputPort.SampleRate); Assert.IsNull(convertedEvent); }
protected void WetEventReceived(MssEvent wetEvent) { lock (MssComponentHub.criticalSectioinLock) { if (wetEvent.mssMsg.Type == MssMsgType.Parameter) { if (Enum.IsDefined(typeof(MssParameterID), (int)wetEvent.mssMsg.Data1) == false) { //Unknown MssParameterId Debug.Assert(false); return; } this.mssParameters.SetParameterRelativeValue( (MssParameterID)(int)wetEvent.mssMsg.Data1, wetEvent.mssMsg.Data3); } } }
protected void ParameterValueChanged(MssParameterID paramId, double newValue) { lock (MssComponentHub.criticalSectioinLock) { if (this.hostInfoOutput.SampleRateIsInitialized == false) { return; } long watchOffestAtParamChanged = this.stopwatch.Elapsed.Ticks; MssParamInfo paramInfo = this.mssParameters.GetParameterInfoCopy(paramId); double relValue = CustomMathUtils.AbsToRelVal(paramInfo.MinValue, paramInfo.MaxValue, newValue); MssMsg paramMsg = new MssMsg(MssMsgType.Parameter, (int)paramId, MssMsgUtil.UNUSED_MSS_MSG_DATA, relValue); MssEvent paramEvent = new MssEvent(); paramEvent.mssMsg = paramMsg; long ticksSinceCycleEnd = watchOffestAtParamChanged - this.watchOffestAtLastCycleEnd; double secondsSinceCycleEnd = ticksSinceCycleEnd / (double)TimeSpan.TicksPerSecond; long samplesSinceCycleEnd = (long)Math.Round(secondsSinceCycleEnd * this.hostInfoOutput.SampleRate); //Sometimes the stopwatch may not be accurate enough to notice the difference //between the end of the last cycle and now. Setting samplesSinceCycleEnd to //1 will cause this event to happen at the very start of this processing cycle. if (samplesSinceCycleEnd == 0) { samplesSinceCycleEnd = 1; } paramEvent.sampleTime = this.sampleTimeAtLastCycleEnd + samplesSinceCycleEnd; this.dryEventInput.ReceiveDryMssEvent(paramEvent); } }
protected void WetEventReceived(MssEvent wetEvent) { lock (MssComponentHub.criticalSectioinLock) { if (wetEvent.mssMsg.Type == MssMsgType.Parameter) { if (Enum.IsDefined(typeof(MssParameterID), (int)wetEvent.mssMsg.Data1) == false) { //Unknown MssParameterId Debug.Assert(false); return; } this.mssParameters.SetParameterRelativeValue( (MssParameterID)(int)wetEvent.mssMsg.Data1, wetEvent.mssMsg.Data3); } } }
public void dryMssEventInputPort_DryMssEventRecieved(MssEvent dryMssEvent) { numDryEventsReceivedByRelay++; }
//*******************************Helpers******************************* //if testMssToMidi is true then this method tests ConvertMssEventToVstMidiEvent. Otherwise this method tests ConvertVstMidiEventToMssEvent protected void Test_MsgConversion(MssMsgType msgType, int midiChannel, int midiParam1, int midiParam2, bool testMssToMidi) { long sampleTimeAtStartOfCycle = 12345; int deltaFrames = 789; MidiHandlerProtectedWrapper midiHandler = Factory_MidiHandler_Basic(); MssEvent mssEvent = new MssEvent(); if (msgType == MssMsgType.PitchBend) { mssEvent.mssMsg = new MssMsg(msgType, midiChannel, MssMsgUtil.UNUSED_MSS_MSG_DATA, (midiParam2 << 7) + midiParam1); } else { mssEvent.mssMsg = new MssMsg(msgType, midiChannel, midiParam1, midiParam2); } mssEvent.sampleTime = sampleTimeAtStartOfCycle + deltaFrames; byte[] midiData = MidiUtil.CreateMidiData(msgType, midiChannel, (byte)midiParam1, (byte)midiParam2); VstMidiEvent midiEvent = new VstMidiEvent(deltaFrames, 0, 0, midiData, 0, 0x00); if (testMssToMidi == true) { MssEvent convertedMssEvent = midiHandler.ConvertVstMidiEventToMssEventWrapper( midiEvent, sampleTimeAtStartOfCycle, this.hostInfoOutputPort.SampleRate); Assert.AreEqual(mssEvent, convertedMssEvent); } else { VstMidiEvent ConvertedMidiEvent = midiHandler.ConvertMssEventToVstMidiEventWrapper( mssEvent, sampleTimeAtStartOfCycle, this.hostInfoOutputPort.SampleRate); Assert.AreEqual(midiEvent.Data, ConvertedMidiEvent.Data); Assert.AreEqual(midiEvent.DeltaFrames, ConvertedMidiEvent.DeltaFrames); } }
public VstMidiEvent ConvertMssEventToVstMidiEventWrapper(MssEvent mssEvent, long processingCycleStartTime, double sampleRate) { return ConvertMssEventToVstMidiEvent(mssEvent, processingCycleStartTime, sampleRate); }
public override bool Equals(object o) { MssEvent compareToEvent = (MssEvent)o; return(this.mssMsg.Equals(compareToEvent.mssMsg) && this.sampleTime == compareToEvent.sampleTime); }
protected void ParameterValueChanged(MssParameterID paramId, double newValue) { lock (MssComponentHub.criticalSectioinLock) { if (this.hostInfoOutput.SampleRateIsInitialized == false) { return; } long watchOffestAtParamChanged = this.stopwatch.Elapsed.Ticks; MssParamInfo paramInfo = this.mssParameters.GetParameterInfoCopy(paramId); double relValue = CustomMathUtils.AbsToRelVal(paramInfo.MinValue, paramInfo.MaxValue, newValue); MssMsg paramMsg = new MssMsg(MssMsgType.Parameter, (int)paramId, MssMsgUtil.UNUSED_MSS_MSG_DATA, relValue); MssEvent paramEvent = new MssEvent(); paramEvent.mssMsg = paramMsg; long ticksSinceCycleEnd = watchOffestAtParamChanged - this.watchOffestAtLastCycleEnd; double secondsSinceCycleEnd = ticksSinceCycleEnd / (double)TimeSpan.TicksPerSecond; long samplesSinceCycleEnd = (long)Math.Round(secondsSinceCycleEnd * this.hostInfoOutput.SampleRate); //Sometimes the stopwatch may not be accurate enough to notice the difference //between the end of the last cycle and now. Setting samplesSinceCycleEnd to //1 will cause this event to happen at the very start of this processing cycle. if (samplesSinceCycleEnd == 0) { samplesSinceCycleEnd = 1; } paramEvent.sampleTime = this.sampleTimeAtLastCycleEnd + samplesSinceCycleEnd; this.dryEventInput.ReceiveDryMssEvent(paramEvent); } }
/// <summary> /// Attempts to create an MssEvent representation of <paramref name="midiEvent"/>. /// </summary> /// <returns>The MssEvent representation of midiEvent or null of there is no valid conversion.</returns> protected static MssEvent ConvertVstMidiEventToMssEvent(VstMidiEvent midiEvent, long sampleTimeAtStartOfProcessingCycle, double sampleRate) { MssEvent mssEvent = new MssEvent(); //Sets the sample time for mssEvent. mssEvent.sampleTime = sampleTimeAtStartOfProcessingCycle + midiEvent.DeltaFrames; MssMsgType msgType = MidiUtil.GetMssTypeFromMidiData(midiEvent.Data); mssEvent.mssMsg.Type = msgType; //If msgType is "Unsupported" then midiEvent cannot be represented as an MssEvent if (msgType == MssMsgType.Unsupported) { return null; } //Sets mssEvent's Data1 (midi channel). //Adds one because channels in an MssMsg start at 1 but channels in a VstMidiEvent start at 0 mssEvent.mssMsg.Data1 = (midiEvent.Data[0] & 0x0F) + 1; //Sets mssEvent's Data2 and Data3 (the midi message's data bytes). if (msgType == MssMsgType.PitchBend) { //The two data bytes for pitch bend are used to store one 14-bit number so this number is stored in //mssEvent.Data3 and mssEvent.Data2 is not used. mssEvent.mssMsg.Data2 = MssMsgUtil.UNUSED_MSS_MSG_DATA; //data1 contains the least significant 7 bits of the pitch bend value and data2 contains the most //significant 7 bits mssEvent.mssMsg.Data3 = (midiEvent.Data[2] << 7) + midiEvent.Data[1]; } else if (msgType == MssMsgType.ChanAftertouch) { mssEvent.mssMsg.Data2 = MssMsgUtil.UNUSED_MSS_MSG_DATA; mssEvent.mssMsg.Data3 = midiEvent.Data[1]; } else { mssEvent.mssMsg.Data2 = midiEvent.Data[1]; mssEvent.mssMsg.Data3 = midiEvent.Data[2]; } return mssEvent; }
/// <summary> /// Attempts to create a VstMidiEvent representation of <paramref name="mssEvent"/>. /// </summary> /// <returns>The VstMidiEvent representation of mssEvent or null of there is no valid conversion.</returns> protected static VstMidiEvent ConvertMssEventToVstMidiEvent(MssEvent mssEvent, long sampleTimeAtStartOfProcessingCycle, double sampleRate) { Debug.Assert(mssEvent.sampleTime >= sampleTimeAtStartOfProcessingCycle); //Calculate delta frames int deltaFrames = (int)(mssEvent.sampleTime - sampleTimeAtStartOfProcessingCycle); byte[] midiData = new byte[3]; //Get status half of first byte. byte statusByte; if (MidiUtil.GetStatusFromMssMsgType(mssEvent.mssMsg.Type, out statusByte) == false) { return null; } //subtract 1 becasue channels are 0 based in midi but 1 based in mss byte channelByte = (byte)(mssEvent.mssMsg.Data1AsInt - 1); midiData[0] = (byte) (statusByte | channelByte); if (mssEvent.mssMsg.Type == MssMsgType.PitchBend) { //most significant bits int MsbVal = (mssEvent.mssMsg.Data3AsInt) >> 7; midiData[2] = (byte)MsbVal; midiData[1] = (byte)((mssEvent.mssMsg.Data3AsInt) - (MsbVal << 7)); } else if (mssEvent.mssMsg.Type == MssMsgType.ChanAftertouch) { midiData[1] = (byte)mssEvent.mssMsg.Data3AsInt; midiData[2] = 0; } else { midiData[1] = (byte)mssEvent.mssMsg.Data2AsInt; midiData[2] = (byte)mssEvent.mssMsg.Data3AsInt; } VstMidiEvent midiEvent = new VstMidiEvent(deltaFrames, 0, 0, midiData, 0, 0); return midiEvent; }