private void MIDIMessageReceived(object sender, MidiInMessageEventArgs e) { if (e.MidiEvent is NoteEvent) { this.Note = new NoteID(((NoteEvent)e.MidiEvent).NoteNumber+1); SetTextCallback d = new SetTextCallback(SetPitchBoxText); this.Invoke(d, new object[] { ((NoteEvent)e.MidiEvent).NoteName }); } }
public void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e) { // Exit if the MidiEvent is null or is the AutoSensing command code if (e.MidiEvent != null && e.MidiEvent.CommandCode == MidiCommandCode.AutoSensing) { return; } if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { NoteOnEvent ne = (NoteOnEvent)e.MidiEvent; OnMidiKeyPressed(ne.NoteNumber); } }
void midiIn_ErrorReceived(object sender, MidiInMessageEventArgs e) { progressLog1.LogMessage(Color.Red, String.Format("Time {0} Message 0x{1:X8} Event {2}", e.Timestamp, e.RawMessage, e.MidiEvent)); }
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); }
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); } }
void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e) { NoteEvent noteEvent = e.MidiEvent as NoteEvent; if (MidiNoteEvent != null && noteEvent != null && noteEvent.CommandCode == MidiCommandCode.NoteOn) { MidiNoteEvent(noteEvent.NoteNumber - 20, noteEvent.NoteName); } }
void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e) { if (checkBoxFilterAutoSensing.Checked && e.MidiEvent != null && e.MidiEvent.CommandCode == MidiCommandCode.AutoSensing) { return; } progressLog1.LogMessage(Color.Blue, String.Format("Time {0} Message 0x{1:X8} Event {2}", e.Timestamp, e.RawMessage, e.MidiEvent)); }
private void MidiDeviceOnMessageReceived(object sender, MidiInMessageEventArgs e) { if (e.MidiEvent != null) { switch (e.MidiEvent.CommandCode) { case MidiCommandCode.NoteOn: { var noteOn = (NoteOnEvent) e.MidiEvent; Note note = Note.FromID(noteOn.NoteNumber); _sintezator.PlayTone(note.Octave, note.Tone, noteOn.Velocity); Application.Current.Dispatcher.BeginInvoke(new Action(() => HighlightNote(note))); } break; case MidiCommandCode.NoteOff: { var noteOn = (NoteEvent) e.MidiEvent; Note note = Note.FromID(noteOn.NoteNumber); _sintezator.StopPlaying(note.Octave, note.Tone); Application.Current.Dispatcher.BeginInvoke(new Action(() => DehightlightNote(note))); } break; } } }
public void MidiEventCallback(MidiInMessageEventArgs aEv) { if (AppController.Instance().DebugOn) { WriteMessage("===== MIDI MESSAGE =====\n" + "event : \t" + aEv.MidiEvent + "\n" + "raw message : \t" + aEv.RawMessage + "\n" + "timestamp :\t" + aEv.Timestamp + "\n" + "=====\n"); } TriggerMessage tT; tT.stEvent = aEv.MidiEvent.ToString(); tT.stRawMessage = aEv.RawMessage; setLatestMidiEvent(tT); }
/// <summary> /// When an input message is received, this event fires /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e) { //cast e.MidiEvent as a NoteEvent so that we can access the relevant properties directly NoteEvent noteEvt = e.MidiEvent as NoteEvent; //if the casting was successful if (noteEvt != null) { //send the key the user pressed to the MidiOut device to hear the note mOut.Send(e.MidiEvent.GetAsShortMessage()); //only listen to the noteon commands to avoid duplicates if (NoteEvent.IsNoteOn(e.MidiEvent)) { //Sometimes a Cross Thread exception is thrown which means that we're trying to update the UI from a non-UI thread. //To avoid this, we check if we need to marshall data to the UI thread at this point in time. //If so, we send the data from the background thread to the UI thread and then update the UI controls if (this.InvokeRequired) { this.Invoke((Action)(() => { tbPlayed.Text += noteEvt.NoteName + "\r\n"; //scroll to the bottom of the textbox when the user reaches the bottom tbPlayed.SelectionStart = tbPlayed.Text.Length; tbPlayed.ScrollToCaret(); } )); } else { //no marshalling required and we can update the UI controls directly tbPlayed.Text += noteEvt.NoteName + "\r\n"; //scroll to the bottom of the textbox when the user reaches the bottom tbPlayed.SelectionStart = tbPlayed.Text.Length; tbPlayed.ScrollToCaret(); } //if it's recording, add to password list if (isRecording) { passwordNotes.Add(noteEvt.NoteName); } else { //user is not recording. At this point, we listen to see if the user has entered the password //add the note just played currentNotes.Add(noteEvt.NoteName); //check if the current sequence played matches the password sequence if (passwordNotes.SequenceEqual(currentNotes)) { //sequences matches, event triggered (e.g. could unlock a door in a game) MessageBox.Show("Correct keys played!"); Clear(); } } } } }
private void MIDIMessageReceived(object sender, MidiInMessageEventArgs e) { try { MIDIMessageCallback callback = new MIDIMessageCallback(MIDICallback); this.Invoke(callback, new object[] { sender, e }); } catch (Exception) { // This catch an exception on form closing } }
private void MIDICallback(object sender, MidiInMessageEventArgs e) { if (this != Form.ActiveForm) return; if (e.MidiEvent is NoteEvent) { NoteEvent noteEvent = (NoteEvent)e.MidiEvent; NoteID id = new NoteID(noteEvent.NoteNumber + 1); Sound s = ShortcutManager<NoteID>.GetInstance(NoteID.Comparer).GetSound(id); if (s != null) { if (noteEvent.Velocity != 0) // KeyDown and not KeyUp { if (NetworkConnection.GetInstance().Connected) { NetworkConnection.GetInstance().PlayOnServer(s.ID); } else { Model.Model.GetInstance().PlaySound(s); } } } } }
void min_MessageReceived(object sender, MidiInMessageEventArgs e) { var mes = e.MidiEvent; if (mes.CommandCode == MidiCommandCode.NoteOn) { var non = mes as NoteEvent; if (non.Velocity == 0 && non.Channel == mch && non.NoteNumber == mnote) { ReleaseFM(non); return; } AttackFM(non); } else if (mes.CommandCode == MidiCommandCode.NoteOff) { ReleaseFM(mes as NoteEvent); } }
private void midiEffectsIn(object sender, MidiInMessageEventArgs e) { //if (e.MidiEvent != null) // if (true) // Console.WriteLine("Inpute message from " + e.MidiEvent.Channel + " Comand" + e.MidiEvent.CommandCode); if (e.MidiEvent.Channel == 1 && e.MidiEvent.CommandCode != MidiCommandCode.AutoSensing) { if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { NoteOnEvent noEvent = (NoteOnEvent)e.MidiEvent; if (noEvent.NoteNumber <= 107 && noEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(noEvent.NoteNumber); int red = noEvent.Velocity & 0x3; int green = noEvent.Velocity & 0x30; green = green >> 4; if(red == 0 && green == 0) buttons[button].LED = Color.FromArgb(170, 170, 170); else buttons[button].LED = Color.FromArgb(red * 85, green * 85, 0); } } if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOff) { NoteEvent nEvent = (NoteEvent)e.MidiEvent; if (nEvent.NoteNumber <= 107 && nEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(nEvent.NoteNumber); buttons[button].LED = Color.FromArgb(170, 170, 170); } } } }