public void Test_VstEventCollection_CollectionChanged_Replace() { VstEventCollection target = new VstEventCollection(); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); Assert.AreEqual(2, target.Count, "Collection Count is not as expected."); int callCount = 0; target.CollectionChanged += (sender, e) => { Assert.AreEqual(NotifyCollectionChangedAction.Replace, e.Action, "Unexpected collection changed action."); Assert.IsNotNull(e.NewItems, "NewItems collection is null."); Assert.AreEqual(1, e.NewItems.Count, "Not the expected number of items in the NewItems collection."); Assert.IsNotNull(e.NewItems[0], "NewItems[0] is null."); Assert.IsNotNull(e.OldItems, "OldItems collection is null."); Assert.AreEqual(1, e.OldItems.Count, "Not the expected number of items in the OldItems collection."); Assert.IsNotNull(e.OldItems[0], "OldItems[0] is null."); callCount++; }; VstEvent @event = target[0]; target[0] = target[1]; target[1] = @event; Assert.AreEqual(2, callCount, "Call count is not as expected."); }
/// <summary> /// Midi events are received from the host on this method and are either send to the DryMssEventRelay or /// stored internally. /// </summary> /// <param name="events">A collection with midi events. Never null.</param> /// <remarks> /// Note that some hosts will only receieve midi events during audio processing. /// See also <see cref="IVstPluginAudioProcessor"/>. /// </remarks> public void Process(VstEventCollection vstEvents) { if (vstEvents == null || vstEvents.Count == 0 || this.vstHost == null) { return; } // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in vstEvents) { if (evnt.EventType == VstEventTypes.MidiEvent) { VstMidiEvent midiEvent = (VstMidiEvent)evnt; MssEvent mssEvent = ConvertVstMidiEventToMssEvent(midiEvent, this.SampleTimeAtStartOfProcessingCycle, this.hostInfoOutputPort.SampleRate); if (mssEvent == null) { outEvents.Add(evnt); } else { this.dryMssEventInputPort.ReceiveDryMssEvent(mssEvent); } } else { // non VstMidiEvent outEvents.Add(evnt); } } }
public void Test_VstEventCollection_Constructor() { var target = new VstEventCollection(); target.IsReadOnly.Should().BeFalse(); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); target.Should().HaveCount(2); target.Clear(); target.Should().BeEmpty(); }
public void Test_VstEventCollection_Constructor() { VstEventCollection target = new VstEventCollection(); Assert.IsFalse(target.IsReadOnly, "Collection is read-only."); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); Assert.AreEqual(2, target.Count, "Count is not as expected."); target.Clear(); Assert.AreEqual(0, target.Count, "Count is not zero."); }
public void ProcessCurrentEvents() { //_plugin.PluginEditor.Log("ProcessCurrentEvents"); // a plugin must implement IVstPluginMidiSource or this call will throw an exception. var midiHost = _plugin.Host.GetInstance <IVstMidiProcessor>(); // always expect some hosts not to support this. if (midiHost != null) { var outEvents = new VstEventCollection(); var someCommands = _plugin.Host.GetInstance <IVstHostCommands20>(); var timeInfo = someCommands.GetTimeInfo( VstTimeInfoFlags.PpqPositionValid | VstTimeInfoFlags.BarStartPositionValid | VstTimeInfoFlags.TempoValid); if (CurrentEvents != null) { // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in CurrentEvents) { switch (evnt.EventType) { case VstEventTypes.MidiEvent: var midiEvent = (VstMidiEvent)evnt; midiEvent = Cascade.ProcessEvent(midiEvent, timeInfo); //_plugin.PluginEditor.Log("tempo" + x.Tempo); outEvents.Add(midiEvent); break; default: // non VstMidiEvent outEvents.Add(evnt); break; } } } outEvents.AddRange(Cascade.CreateNotes(timeInfo)); midiHost.Process(outEvents); } // Clear the cache, we've processed the events. CurrentEvents = null; }
public void Process_SomeSupportedSomeUnsupporedEvents_SomeSentToRelay() { VstEventCollection vstEvents = new VstEventCollection(); //Supported event type vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.PitchBend))); //Unsupported event type VstMidiSysExEvent unsupportedEvent = new VstMidiSysExEvent(0, new byte[3]); vstEvents.Add(unsupportedEvent); //Supported event type vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.PolyAftertouch))); Test_Process_VstEventCollection_SentToReplay(vstEvents, 2); }
public void Process_NoteOn_SentToRelay() { VstEventCollection vstEvents = new VstEventCollection(); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.NoteOn))); Test_Process_VstEventCollection_SentToReplay(vstEvents, 1); }
public void Process_SysExEvent_NothingSentToRelay() { VstEventCollection vstEvents = new VstEventCollection(); VstMidiSysExEvent unsupportedEvent = new VstMidiSysExEvent(0, new byte[3]); vstEvents.Add(unsupportedEvent); Test_Process_VstEventCollection_SentToReplay(vstEvents, 0); }
public void SetMidiEvent(int deltaFrames, byte[] msg) { if (FCanEvents) { VstEvent evt = new VstMidiEvent(deltaFrames, 0, 0, msg, 0, 0); MidiEvents.Add(evt); FHasEvents = true; } }
public void Test_VstEventCollection_CollectionChanged_Add() { var target = new VstEventCollection(); int callCount = 0; target.CollectionChanged += (sender, e) => { e.Action.Should().Be(NotifyCollectionChangedAction.Add); e.NewItems.Should().NotBeNullOrEmpty(); e.NewItems[0].Should().NotBeNull(); callCount++; }; target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); target.Add(new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)); callCount.Should().Be(2); }
public void ProcessCurrentEvents() { if (CurrentEvents == null || CurrentEvents.Count == 0) { return; } // a plugin must implement IVstPluginMidiSource or this call will throw an exception. IVstMidiProcessor midiHost = _plugin.Host.GetInstance <IVstMidiProcessor>(); // always expect some hosts not to support this. if (midiHost != null) { VstEventCollection outEvents = new VstEventCollection(); // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in CurrentEvents) { switch (evnt.EventType) { case VstEventTypes.MidiEvent: VstMidiEvent midiEvent = (VstMidiEvent)evnt; midiEvent = Gain.ProcessEvent(midiEvent); midiEvent = Transpose.ProcessEvent(midiEvent); outEvents.Add(midiEvent); break; default: // non VstMidiEvent outEvents.Add(evnt); break; } } midiHost.Process(outEvents); } // Clear the cache, we've processed the events. CurrentEvents = null; }
public void ProcessCurrentEvents() { if (CurrentEvents == null || CurrentEvents.Count == 0) { return; } // always expect some hosts not to support this. if (_midiHost != null) { VstEventCollection outEvents = new VstEventCollection(); // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in CurrentEvents) { switch (evnt.EventType) { case VstEventTypes.MidiEvent: VstMidiEvent midiEvent = (VstMidiEvent)evnt; midiEvent = Gain.ProcessEvent(midiEvent); midiEvent = Transpose.ProcessEvent(midiEvent); outEvents.Add(midiEvent); break; default: // non VstMidiEvent outEvents.Add(evnt); break; } } _midiHost.Process(outEvents); } // Clear the cache, we've processed the events. CurrentEvents = null; }
public void Process_MultipleMsgTypes_SentToRelay() { VstEventCollection vstEvents = new VstEventCollection(); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.NoteOn))); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.NoteOff))); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.CC))); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.ChanAftertouch))); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.PitchBend))); vstEvents.Add(Factory_VstMidiEvent_Basic(0, CreateMidiDataWithDefaultValues(MssMsgType.PolyAftertouch))); Test_Process_VstEventCollection_SentToReplay(vstEvents, 6); }
public void ProcessCurrentEvents() { if (CurrentEvents == null || CurrentEvents.Count == 0) return; // a plugin must implement IVstPluginMidiSource or this call will throw an exception. IVstMidiProcessor midiHost = _plugin.Host.GetInstance<IVstMidiProcessor>(); // always expect some hosts not to support this. if (midiHost != null) { VstEventCollection outEvents = new VstEventCollection(); // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in CurrentEvents) { if (evnt.EventType == VstEventTypes.MidiEvent) { VstMidiEvent midiEvent = (VstMidiEvent)evnt; if ((midiEvent.Data[0] & 0xF0) == 0x80) { _plugin._synth.ProcessNoteOffEvent(midiEvent.Data[1]); } if ((midiEvent.Data[0] & 0xF0) == 0x90) { // note on with velocity = 0 is a note off if (midiEvent.Data[2] == 0) { _plugin._synth.ProcessNoteOffEvent(midiEvent.Data[1]); } else { //midiEvent = _gain.ProcessEvent(midiEvent); //midiEvent = _transpose.ProcessEvent(midiEvent); _plugin._synth.ProcessNoteOnEvent(midiEvent.Data[1]); } } } else { // non VstMidiEvent outEvents.Add(evnt); } } //midiHost.Process(outEvents); } }
public void ProcessCurrentEvents() { if (CurrentEvents == null || CurrentEvents.Count == 0) { return; } // a plugin must implement IVstPluginMidiSource or this call will throw an exception. IVstMidiProcessor midiHost = _plugin.Host.GetInstance <IVstMidiProcessor>(); // always expect some hosts not to support this. if (midiHost != null) { VstEventCollection outEvents = new VstEventCollection(); // NOTE: other types of events could be in the collection! foreach (VstEvent evnt in CurrentEvents) { switch (evnt.EventType) { case VstEventTypes.MidiEvent: VstMidiEvent midiEvent = (VstMidiEvent)evnt; //General midi effects for all inputs midiEvent = Gain.ProcessEvent(midiEvent); midiEvent = Transpose.ProcessEvent(midiEvent); //Process Midi Note in SampleManager if ((midiEvent.Data[0] & 0xF0) == 0x80) { _plugin.SampleManager.ProcessNoteOffEvent(midiEvent.Data[1]); } if ((midiEvent.Data[0] & 0xF0) == 0x90) { // note on with velocity = 0 is a note off if (MidiHelper.IsNoteOff(midiEvent.Data)) { _plugin.SampleManager.ProcessNoteOffEvent(midiEvent.Data[1]); } else { _plugin.SampleManager.ProcessNoteOnEvent(midiEvent.Data[1]); } } outEvents.Add(midiEvent); break; default: // non VstMidiEvent outEvents.Add(evnt); break; } } midiHost.Process(outEvents); } // Clear the cache, we've processed the events. CurrentEvents = null; }