Example #1
0
        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.");
        }
Example #2
0
        private VstEvent[] CreateMidiEvent(byte statusByte, byte midiNote, byte midiVelocity)
        {
            /*
             * Just a small note on the code for setting up a midi event:
             * You can use the VstEventCollection class (Framework) to setup one or more events
             * and then call the ToArray() method on the collection when passing it to
             * ProcessEvents. This will save you the hassle of dealing with arrays explicitly.
             * http://computermusicresource.com/MIDI.Commands.html
             *
             * Freq to Midi notes etc:
             * http://www.sengpielaudio.com/calculator-notenames.htm
             *
             * Example to use NAudio Midi support
             * http://stackoverflow.com/questions/6474388/naudio-and-midi-file-reading
             */
            byte[] midiData = new byte[4];

            midiData[0] = statusByte;
            midiData[1] = midiNote;                 // Midi note
            midiData[2] = midiVelocity;             // Note strike velocity
            midiData[3] = 0;                        // Reserved, unused

            VstMidiEvent vse = new VstMidiEvent(/*DeltaFrames*/ 0,
                                                /*NoteLength*/ 0,
                                                /*NoteOffset*/ 0,
                                                midiData,
                                                /*Detune*/ 0,
                                                /*NoteOffVelocity*/ 127);             // previously 0

            VstEvent[] ve = new VstEvent[1];
            ve[0] = vse;
            return(ve);
        }
Example #3
0
		private void MIDI(byte Cmd, byte Val1, byte Val2)
		{
			/* 
			 * Just a small note on the code for setting up a midi event:
			 * You can use the VstEventCollection class (Framework) to setup one or more events
			 * and then call the ToArray() method on the collection when passing it to
			 * ProcessEvents. This will save you the hassle of dealing with arrays explicitly.
			 * http://computermusicresource.com/MIDI.Commands.html
			 * 
			 * Freq to Midi notes etc:
			 * http://www.sengpielaudio.com/calculator-notenames.htm
			 * 
			 * Example to use NAudio Midi support
			 * http://stackoverflow.com/questions/6474388/naudio-and-midi-file-reading
			 */

			var midiData = new byte[4];
			midiData[0] = Cmd;
			midiData[1] = Val1;
			midiData[2] = Val2;
			midiData[3] = 0;    // Reserved, unused

			var vse = new VstMidiEvent(/*DeltaFrames*/ 0,
			                                    /*NoteLength*/ 0,
			                                    /*NoteOffset*/  0,
			                                    midiData,
			                                    /*Detune*/        0,
			                                    /*NoteOffVelocity*/ 127);

			var ve = new VstEvent[1];
			ve[0] = vse;

			PluginContext.PluginCommandStub.ProcessEvents(ve);
		}
        public void Test_VstEventCollection_CollectionChanged_Replace()
        {
            var target = new VstEventCollection
            {
                new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0),
                new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0)
            };

            target.Should().HaveCount(2);

            int callCount = 0;

            target.CollectionChanged += (sender, e) =>
            {
                e.Action.Should().Be(NotifyCollectionChangedAction.Replace);
                e.NewItems.Should().NotBeNullOrEmpty();
                e.NewItems[0].Should().NotBeNull();
                e.OldItems.Should().NotBeNullOrEmpty();
                e.OldItems[0].Should().NotBeNull();

                callCount++;
            };

            VstEvent @event = target[0];

            target[0] = target[1];
            target[1] = @event;

            callCount.Should().Be(2);
        }
Example #5
0
        void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
        {
            progressLog1.LogMessage(Color.Blue, String.Format("Time {0} Message 0x{1:X8} Event {2}",
                                                              e.Timestamp, e.RawMessage, e.MidiEvent));

            //SendMidiOutMessage(e.MidiEvent);
            if (VSTForm.vst != null)
            {
                MidiEvent midiEvent = e.MidiEvent;
                byte[]    midiData  = { 0, 0, 0 };
                if (midiEvent is NAudio.Midi.NoteEvent)
                {
                    NAudio.Midi.NoteEvent me = (NAudio.Midi.NoteEvent)midiEvent;
                    midiData = new byte[] {
                        0x90,                                           // Cmd
                        (byte)me.NoteNumber,                            // Val 1
                        (byte)me.Velocity,                              // Val 2
                    };
                }
                else if (midiEvent is NAudio.Midi.ControlChangeEvent)
                {
                    NAudio.Midi.ControlChangeEvent cce = (NAudio.Midi.ControlChangeEvent)midiEvent;
                    midiData = new byte[] {
                        0xB0,                                                   // Cmd
                        (byte)cce.Controller,                                   // Val 1
                        (byte)cce.ControllerValue,                              // Val 2
                    };
                }
                else if (midiEvent is NAudio.Midi.PitchWheelChangeEvent)
                {
                    // Pitch Wheel Value 0 is minimum, 0x2000 (8192) is default, 0x4000 (16384) is maximum
                    NAudio.Midi.PitchWheelChangeEvent pe = (PitchWheelChangeEvent)midiEvent;
                    midiData = new byte[] {
                        0xE0,                                                   // Cmd
                        (byte)(pe.Pitch & 0x7f),                                // Val 1
                        (byte)((pe.Pitch >> 7) & 0x7f),                         // Val 2
                    };
                }
                progressLog1.LogMessage(Color.Chocolate, String.Format("Sending mididata 0x00{0:X2}{1:X2}{2:X2}",
                                                                       midiData[2], midiData[1], midiData[0]));
                VstMidiEvent vse =
                    new VstMidiEvent(/*DeltaFrames*/ 0,
                                     /*NoteLength*/ 0,
                                     /*NoteOffset*/ 0,
                                     midiData,
                                     /*Detune*/ 0,
                                     /*NoteOffVelocity*/ 0);

                VstEvent[] ve = new VstEvent[1];
                ve[0] = vse;

                VSTForm.vst.pluginContext.PluginCommandStub.ProcessEvents(ve);
            }
        }
        public void Test_VstEventCollection_ReadOnlyConstructor()
        {
            var events = new VstEvent[2];

            events[0] = new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0);
            events[1] = new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0);

            var target = new VstEventCollection(events);

            target.Should().HaveCount(events.Length);
            target.IsReadOnly.Should().BeTrue();
            target[0].Should().Be(events[0]);
            target[1].Should().Be(events[1]);
        }
Example #7
0
        public void Test_VstEventCollection_ReadOnlyConstructor()
        {
            VstEvent[] events = new VstEvent[2];
            events[0] = new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0);
            events[1] = new VstMidiEvent(0, 100, 0, new byte[] { 100, 110, 120 }, 0, 0);

            VstEventCollection target = new VstEventCollection(events);

            Assert.AreEqual(events.Length, target.Count, "Count does not match.");
            Assert.AreEqual(2, target.Count, "Count is not as expected.");
            Assert.IsTrue(target.IsReadOnly, "Collection is not read-only.");
            Assert.AreEqual(events[0], target[0], "First item does not match.");
            Assert.AreEqual(events[1], target[1], "Second item does not match.");
        }
Example #8
0
        private void MIDI(byte Cmd, byte Val1, byte Val2)
        {
            byte[] midiData = new byte[4];
            midiData[0] = Cmd;
            midiData[1] = Val1;
            midiData[2] = Val2;
            midiData[3] = 0;    // Reserved, unused

            VstMidiEvent vse = new VstMidiEvent(/*DeltaFrames*/ 0,
                                                /*NoteLength*/ 0,
                                                /*NoteOffset*/ 0,
                                                midiData,
                                                /*Detune*/ 0,
                                                /*NoteOffVelocity*/ 127);

            VstEvent[] ve = new VstEvent[1];
            ve[0] = vse;

            pluginContext.PluginCommandStub.ProcessEvents(ve);
        }
Example #9
0
        private void MIDI(byte Cmd,byte Val1,byte Val2)
        {
            byte[] midiData = new byte[4];
            midiData[0] = Cmd;
            midiData[1] = Val1;
            midiData[2] = Val2;
            midiData[3] = 0;    // Reserved, unused

            VstMidiEvent vse = new VstMidiEvent(/*DeltaFrames*/ 0,
                /*NoteLength*/ 0,
                /*NoteOffset*/  0,
                 midiData,
                /*Detune*/        0,
                /*NoteOffVelocity*/ 127);

            VstEvent[] ve = new VstEvent[1];
            ve[0] = vse;

            pluginContext.PluginCommandStub.ProcessEvents(ve);
        }
Example #10
0
        private void MIDI(byte Cmd, byte Val1, byte Val2, int deltaFrames = 0)
        {
            /*
             * Just a small note on the code for setting up a midi event:
             * You can use the VstEventCollection class (Framework) to setup one or more events
             * and then call the ToArray() method on the collection when passing it to
             * ProcessEvents. This will save you the hassle of dealing with arrays explicitly.
             * http://computermusicresource.com/MIDI.Commands.html
             *
             * Freq to Midi notes etc:
             * http://www.sengpielaudio.com/calculator-notenames.htm
             *
             * Example to use NAudio Midi support
             * http://stackoverflow.com/questions/6474388/naudio-and-midi-file-reading
             */

            var midiData = new byte[4];

            midiData[0] = Cmd;
            midiData[1] = Val1;
            midiData[2] = Val2;
            midiData[3] = 0; // Reserved, unused

            var vse = new VstMidiEvent(deltaFrames,
                                       /*NoteLength*/ 0,
                                       /*NoteOffset*/ 0,
                                       midiData,
                                       /*Detune*/ 0,
                                       /*NoteOffVelocity*/ 127);

            var ve = new VstEvent[1];

            ve[0] = vse;

            PluginContext.PluginCommandStub.ProcessEvents(ve);
        }
Example #11
0
		void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e)
		{
			progressLog1.LogMessage(Color.Blue, String.Format("Time {0} Message 0x{1:X8} Event {2}",
			                                                  e.Timestamp, e.RawMessage, e.MidiEvent));

			//SendMidiOutMessage(e.MidiEvent);
			if (VSTForm.vst != null) {
				MidiEvent midiEvent = e.MidiEvent;
				byte[] midiData = { 0, 0, 0 };
				if (midiEvent is NAudio.Midi.NoteEvent)
				{
					var me = (NAudio.Midi.NoteEvent) midiEvent;
					midiData = new byte[] {
						0x90, 					// Cmd
						(byte) me.NoteNumber,	// Val 1
						(byte) me.Velocity,		// Val 2
					};
				}
				else if (midiEvent is NAudio.Midi.ControlChangeEvent)
				{
					var cce = (NAudio.Midi.ControlChangeEvent) midiEvent;
					midiData = new byte[] {
						0xB0, 						// Cmd
						(byte)cce.Controller,		// Val 1
						(byte)cce.ControllerValue,	// Val 2
					};
				}
				else if (midiEvent is NAudio.Midi.PitchWheelChangeEvent)
				{
					// Pitch Wheel Value 0 is minimum, 0x2000 (8192) is default, 0x4000 (16384) is maximum
					NAudio.Midi.PitchWheelChangeEvent pe = (PitchWheelChangeEvent) midiEvent;
					midiData = new byte[] {
						0xE0, 							// Cmd
						(byte)(pe.Pitch & 0x7f),		// Val 1
						(byte)((pe.Pitch >> 7) & 0x7f),	// Val 2
					};
				}
				progressLog1.LogMessage(Color.Chocolate, String.Format("Sending mididata 0x00{0:X2}{1:X2}{2:X2}",
				                                                       midiData[2], midiData[1], midiData[0]));
				var vse =
					new VstMidiEvent(/*DeltaFrames*/ 0,
					                 /*NoteLength*/ 0,
					                 /*NoteOffset*/ 0,
					                 midiData,
					                 /*Detune*/ 0,
					                 /*NoteOffVelocity*/ 0);

				var ve = new VstEvent[1];
				ve[0] = vse;
				
				VSTForm.vst.pluginContext.PluginCommandStub.ProcessEvents(ve);
			}
		}
Example #12
0
 static int SortAlgo(VstEvent a, VstEvent b)
 {
     return(a.DeltaFrames.CompareTo(b.DeltaFrames));
 }
        public bool ProcessEvents(VstEvent[] events)
        {
            const byte MIDI_NOTE_ON = 0x90;
            const byte MIDI_NOTE_OFF = 0x80;
            const byte MIDI_PITCH_BEND =0xE0;
              const byte MIDI_TICK = 0xF8;
              const byte MIDI_START = 0xFA;

              foreach(VstEvent ev in events)
              {
              if(ev.EventType == VstEventTypes.MidiEvent)
              {
                  byte status = ev.Data[0];

                  switch (status)
                  {
                      case MIDI_NOTE_ON:
                          theSynth.noteOn(ev.Data[1], ev.Data[2]);
                      break;
                      case MIDI_NOTE_OFF:
                          theSynth.noteOff(ev.Data[1], ev.Data[2]);
                      break;
                      case MIDI_PITCH_BEND:
                          byte amount = (byte)(ev.Data[2] << 1 | ((ev.Data[1] >> 6) & 0x01));
                          theSynth.pitchBend(amount);
                      break;
                      case MIDI_TICK:
                        theSynth.writeCommand(Synth.TICK_ADDR,0xFF);
                      break;
                      case MIDI_START:
                        theSynth.writeCommand(Synth.TICK_RESET_ADDR,0xFF);
                      break;
                  }

              }
              }
              return false;
        }
Example #14
0
 public bool ProcessEvents(VstEvent[] events)
 {
     return false;
 }
Example #15
0
		//midi out
		void ReceiveEvents(VstEvent[] events)
		{
            foreach (var evt in events) 
            {
                MidiEventSender.SendRawMessage(evt.DeltaFrames, evt.Data[0], evt.Data[1], evt.Data[2]);
            }
		}
Example #16
0
        private VstEvent[] CreateMidiEvent(byte statusByte, byte midiNote, byte midiVelocity)
        {
            /*
             * Just a small note on the code for setting up a midi event:
             * You can use the VstEventCollection class (Framework) to setup one or more events
             * and then call the ToArray() method on the collection when passing it to
             * ProcessEvents. This will save you the hassle of dealing with arrays explicitly.
             * http://computermusicresource.com/MIDI.Commands.html
             *
             * Freq to Midi notes etc:
             * http://www.sengpielaudio.com/calculator-notenames.htm
             *
             * Example to use NAudio Midi support
             * http://stackoverflow.com/questions/6474388/naudio-and-midi-file-reading
             */
            byte[] midiData = new byte[4];

            midiData[0] = statusByte;
            midiData[1] = midiNote;   	// Midi note
            midiData[2] = midiVelocity; // Note strike velocity
            midiData[3] = 0;    		// Reserved, unused

            VstMidiEvent vse = new VstMidiEvent(/*DeltaFrames*/ 	0,
                                                /*NoteLength*/ 	0,
                                                /*NoteOffset*/ 	0,
                                                midiData,
                                                /*Detune*/    		0,
                                                /*NoteOffVelocity*/ 127); // previously 0

            VstEvent[] ve = new VstEvent[1];
            ve[0] = vse;
            return ve;
        }
        /// <summary>
        /// Called by the host when the plugin has implemented the <see cref="IVstMidiProcessor"/> interface.
        /// </summary>
        /// <param name="events">The (Midi) events for the current 'block'.</param>
        /// <returns>Returns true when the call was forwarded to the plugin.</returns>
        public virtual bool ProcessEvents(VstEvent[] events)
        {
            IVstMidiProcessor midiProcessor = pluginCtx.Plugin.GetInstance<IVstMidiProcessor>();

            if (midiProcessor != null)
            {
                midiProcessor.Process(new VstEventCollection(events));
                return true;
            }

            return false;
        }
Example #18
0
 public bool ProcessEvents(VstEvent[] events)
 {
     //throw new NotImplementedException();
     return false;
 }