public void NoteOff(NoteOffMessage msg) { clock.Schedule(new NoteOffMessage(outputDevice, msg.Channel, msg.Note + 4, msg.Velocity, msg.BeatTime + 1)); clock.Schedule(new NoteOffMessage(outputDevice, msg.Channel, msg.Note + 7, msg.Velocity, msg.BeatTime + 2)); }
public void NoteOff(NoteOffMessage msg) { lock (this) { pitchesPressed.Remove(msg.Pitch); } }
public void NoteOff(NoteOffMessage msg) { lock (this) { Console.WriteLine("NoteOff: " + msg.Pitch); } }
public IMessage getMessage(MidiEvent midiEvent) { switch (midiEvent.CommandCode) { case MidiCommandCode.NoteOn: NoteEvent noteEvent = (NoteEvent)midiEvent; Note note = new Note(noteEvent.channel, noteEvent.NoteNumber, noteEvent.Velocity); NoteOnMessage message = new NoteOnMessage(note); return(message); case MidiCommandCode.NoteOff: NoteEvent noteEvent = (NoteEvent)midiEvent; Note note = new Note(noteEvent.channel, noteEvent.NoteNumber, noteEvent.Velocity); NoteOffMessage message = new NoteOffMessage(note); trackMessages.add(message); return(message); case MidiCommandCode.TimingClock: NoteOffMessage message = new NoteOffMessage(midiEvent.AbsoluteTime); trackMessages.add(message); return(message); case MidiCommandCode.MetaEvent: MetaEvent metaEvent = (MetaEvent)midiEvent; return(getMessage(metaEvent)); default: return(null); // TODO implement remaining IMessage types } }
public void TestNoteOff() { byte channel = 0; byte pitch = 60; byte velocity = 50; NoteOffMessage message = new NoteOffMessage( new Note( channel, pitch, velocity ), 0 ); MidiMessage bytes = message.Message; MidiMessage expected = new MidiMessage { Status = (byte)(0x80 + channel), Data = new byte[] { pitch, velocity }, TimeDelta = 0 }; Assert.Equal(expected, bytes); }
private void Decode(byte[] message) { byte status = message[0]; switch (status & 0b1111_0000) { case Midi.Status.NoteOffBitmask: if (NoteOffMessage.TryDecode(message, out var noteOffMessage)) { NoteOff?.Invoke(this, in noteOffMessage); } break; case Midi.Status.NoteOnBitmask: if (NoteOnMessage.TryDecoce(message, out var noteOnMessage)) { NoteOn?.Invoke(this, in noteOnMessage); } break; case Midi.Status.PolyphonicKeyPressureBitmask: if (PolyphonicKeyPressureMessage.TryDecode(message, out var polyphonicKeyPressureMessage)) { PolyphonicKeyPressure?.Invoke(this, in polyphonicKeyPressureMessage); } break; case Midi.Status.ControlChangeBitmask: if (ControlChangeMessage.TryDecode(message, out var controlChangeMessage)) { _nrpnInterpreters[(int)controlChangeMessage.Channel].HandleControlChangeMessage(in controlChangeMessage); } break; case Midi.Status.ProgramChangeBitmask: if (ProgramChangeMessage.TryDecode(message, out var programChangeMessage)) { ProgramChange?.Invoke(this, in programChangeMessage); } break; case Midi.Status.ChannelPressureBitmask: if (ChannelPressureMessage.TryDecode(message, out var channelPressureMessage)) { ChannelPressure?.Invoke(this, in channelPressureMessage); } break; case Midi.Status.PitchBendChange: if (PitchBendMessage.TryDecode(message, out var pitchBendMessage)) { PitchBend?.Invoke(this, in pitchBendMessage); } break; default: Log.Error("Unknown message type {Bitmask}", $"{status & 0b1111_0000:X2}"); break; } }
public static void NoteOff(NoteOffMessage msg) { lock (NoteOfflock) { logs += $"Time: {DateTime.Now.ToString("HH:mm:ss:ffffff")} Event:NoteOff Pitch:{msg.Pitch} \r\n"; } }
private void D_NoteOff(NoteOffMessage msg) { Dispatcher.Invoke(() => { lbLog.Items.Add(string.Format("Off: {0} {1}", msg.Pitch, msg.Velocity)); }); }
private void OnNoteOffCallback(NoteOffMessage msg) { foreach (var listener in _listeners) { listener.OnNoteReleased(msg.Pitch.PositionInOctave()); } }
public void NoteOff(NoteOffMessage msg) { lock (this) { //pitchesPressed.Remove(msg.Pitch); //PrintStatus(); } }
private DtoMidiMessageNoteOff Map(NoteOffMessage msg) { var off = new DtoMidiMessageNoteOff(); EnrichNoteMessage(msg, off); return(off); }
public void Should_Send_NoteOffMessages() { AllEnums <Channel>(channel => AllEnums <Key>(key => AllInRange(0, 127, velocity => { var noteOffMessage = new NoteOffMessage(channel, key, velocity); _sut.Send(in noteOffMessage); Assert.True(_outputDeviceMock.Messages.TryDequeue(out var msg)); Assert.Equal(NoteOffMessage(channel, key, velocity), msg); })));
// Method called when the input device receives a NoteOff message. Updates // the input status label. Respects GUI thread affinity by invoking to the // GUI thread if necessary. public void NoteOff(NoteOffMessage msg) { if (InvokeRequired) { BeginInvoke(noteOffHandler, msg); return; } inputStatusLabel.Text = String.Format("Note Off {0}", msg.Pitch); }
private void SendNote(Note note) { NoteOnMessage noteOn = new NoteOnMessage(note, TickOf(beatOffset)); NoteOffMessage noteOff = new NoteOffMessage(note, TickOf(beatDuration)); Debug.Log("Sending message: " + noteOn); Debug.Log("Sending message: " + noteOff); instrument.ProcessMidi(new IMessage[] { noteOn, noteOff }); }
public static void NoteOff(NoteOffMessage msg) { lock (NoteOfflock) { if (Convert.ToInt32(msg.Pitch) <= 84 && Convert.ToInt32(msg.Pitch) >= 48) { KeyController.KeyboardRelease(Convert.ToInt32(msg.Pitch)); } } }
private void NoteOff(NoteOffMessage msg) { if (radioButton1.Checked) // Logitech SDK { Gmidi.palette_led((int)msg.Pitch, 0); } else if (radioButton2.Checked) // Razer SDK { Rmidi.palette_led((int)msg.Pitch, 0); } }
//- midi processing --------------------------------------------------- public void handleMidiMessage(byte[] msgData) { Message msg = Message.getMessage(msgData); if (!holdOn) //tracking note on msgs when hold is off { if (msg is NoteOnMessage) { NoteOnMessage noteOn = (NoteOnMessage)msg; keysdown[noteOn.noteNumber] = true; } else if (msg is NoteOffMessage) { NoteOffMessage noteOff = (NoteOffMessage)msg; keysdown[noteOff.noteNumber] = false; } modifier.sendMidiMsg(msg.getDataBytes()); } else { if (msg is NoteOnMessage) { NoteOnMessage noteOn = (NoteOnMessage)msg; int baseNote = noteOn.noteNumber; modifier.sendMidiMsg(msg.getDataBytes()); foreach (int interval in chordNotes) { NoteOnMessage newnote = (NoteOnMessage)noteOn.copy(); newnote.noteNumber += interval; Console.WriteLine("new note number " + newnote.noteNumber); modifier.sendMidiMsg(newnote.getDataBytes()); } } else if (msg is NoteOffMessage) { NoteOffMessage noteOff = (NoteOffMessage)msg; modifier.sendMidiMsg(msg.getDataBytes()); foreach (int interval in chordNotes) { NoteOffMessage newnote = (NoteOffMessage)noteOff.copy(); newnote.noteNumber += interval; modifier.sendMidiMsg(newnote.getDataBytes()); } } else { modifier.sendMidiMsg(msg.getDataBytes()); } } }
public void NoteOff(NoteOffMessage msg) { if (!lastSequenceForPitch.ContainsKey(msg.Pitch)) { return; } List <Pitch> pitches = lastSequenceForPitch[msg.Pitch]; lastSequenceForPitch.Remove(msg.Pitch); for (int i = 1; i < pitches.Count; ++i) { clock.Schedule(new NoteOffMessage(outputDevice, msg.Channel, pitches[i], msg.Velocity, msg.Time + i)); } }
public void NoteOff(NoteOffMessage msg) { if (!_lastSequenceForPitch.ContainsKey(msg.Pitch)) { return; } var pitches = _lastSequenceForPitch[msg.Pitch]; _lastSequenceForPitch.Remove(msg.Pitch); for (var i = 1; i < pitches.Count; ++i) { _clock.Schedule(new NoteOffMessage(_outputDevice, msg.Channel, pitches[i], msg.Velocity, msg.Time + i)); } }
private bool ProcessEvent() { var evt = CurrentTrack.Events[nextEventIndex]; var message = evt.Message; bool trackEnded = false; bool skip = false; switch (message) { // Channel case NoteOnMessage noteOn: // Special case: iMUSE also allows velocity 0 as "note-off" if (noteOn.Velocity == 0) { message = new NoteOffMessage(noteOn.Channel, noteOn.Key, noteOn.Velocity); } break; case PolyPressureMessage: skip = true; logger.DebugWarning("Hey! iMUSE would like you to quit the poly pressure..."); break; case ChannelPressureMessage: skip = true; logger.DebugWarning("Hey! iMUSE would like you to quit the aftertouch..."); break; case EndOfTrackMessage: logger.Verbose("End of track reached..."); trackEnded = true; break; } if (!skip) { // Pass message on to player Player.HandleEvent(message); } return(trackEnded); }
/// <summary> /// "Key Up" midi event handler /// </summary> /// <param name="msg"></param> private void MidiIn_NoteOff(NoteOffMessage msg) { try { var maps = NoteControl.Mappings.Where(p => p.Value == msg.Pitch); foreach (var map in maps) { KeyboardUtil.Send(map.Key, true); } var mouseMaps = NoteControl.MouseMappings.Where(p => p.Value == msg.Pitch); foreach (var map in mouseMaps) { if (map.Key == Models.MouseBindType.LeftClick || map.Key == Models.MouseBindType.MiddleClick || map.Key == Models.MouseBindType.RightClick) { MouseButton btn = MouseButton.Left; if (map.Key == Models.MouseBindType.LeftClick && (ConfigUtil.AppConfig.HoldLeftMouseClick || ConfigUtil.AppConfig.ToggleLeftMouseClick)) { return; } if (map.Key == Models.MouseBindType.MiddleClick) { btn = MouseButton.Middle; } else if (map.Key == Models.MouseBindType.RightClick) { btn = MouseButton.Right; } KeyboardUtil.MouseClick(btn, true); } } } catch (Exception ex) { Logger.Error(ex, "Midi note conversion failed(keyup): "); } }
public void NoteOff(NoteOffMessage msg) { // This note should be in the mapped notes dict from it's note-on. Build the key to find what it was mapped to. String sourceDeviceName = msg.Device.Name; Channel sourceChannel = msg.Channel; Pitch origNote = msg.Pitch; // Look up this note in the mapped notes dict to find what it was mapped to List <MappedNote> mappedNotesAlreadySounding = FindMappedNote(sourceDeviceName, sourceChannel, origNote); if (mappedNotesAlreadySounding.Count > 0) { foreach (MappedNote noteToSilence in mappedNotesAlreadySounding) { // Send a note off for what it was mapped to, and remove this entry from the mapped notes dict. noteToSilence.mappedDevice.SendNoteOff(noteToSilence.mappedChannel, noteToSilence.mappedNote, msg.Velocity); m_mappedNotesList.Remove(noteToSilence); } } else { // No mapping in the mapped notes dict... worth logging, but I'm not sure about the overhead of doing that in a midi event handler. } }
private void Decode(byte[] message) { byte status = message[0]; switch (status & 0b1111_0000) { case Midi.Status.NoteOffBitmask: if (NoteOffMessage.TryDecode(message, out var noteOffMessage)) { NoteOff?.Invoke(this, in noteOffMessage); } break; case Midi.Status.NoteOnBitmask: if (NoteOnMessage.TryDecode(message, out var noteOnMessage)) { NoteOn?.Invoke(this, in noteOnMessage); } break; case Midi.Status.PolyphonicKeyPressureBitmask: if (PolyphonicKeyPressureMessage.TryDecode(message, out var polyphonicKeyPressureMessage)) { PolyphonicKeyPressure?.Invoke(this, in polyphonicKeyPressureMessage); } break; case Midi.Status.ControlChangeBitmask: if (ControlChangeMessage.TryDecode(message, out var controlChangeMessage)) { _nrpnInterpreters[(int)controlChangeMessage.Channel].HandleControlChangeMessage(in controlChangeMessage); } break; case Midi.Status.ProgramChangeBitmask: if (ProgramChangeMessage.TryDecode(message, out var programChangeMessage)) { ProgramChange?.Invoke(this, in programChangeMessage); } break; case Midi.Status.ChannelPressureBitmask: if (ChannelPressureMessage.TryDecode(message, out var channelPressureMessage)) { ChannelPressure?.Invoke(this, in channelPressureMessage); } break; case Midi.Status.PitchBendChange: if (PitchBendMessage.TryDecode(message, out var pitchBendMessage)) { PitchBend?.Invoke(this, in pitchBendMessage); } break; case Midi.Status.System: switch (status) { case Midi.Status.SysExStart: if (SysExMessage.TryDecode(message, out var sysExMessage)) { SysEx?.Invoke(this, in sysExMessage); } break; case Midi.Status.MidiTimeCodeQuarterFrame: if (MidiTimeCodeQuarterFrameMessage.TryDecode(message, out var timeCodeQuarterFrameMessage)) { MidiTimeCodeQuarterFrame?.Invoke(this, in timeCodeQuarterFrameMessage); } break; case Midi.Status.SongPositionPointer: if (SongPositionPointerMessage.TryDecode(message, out var songPositionPointerMessage)) { SongPositionPointer?.Invoke(this, in songPositionPointerMessage); } break; case Midi.Status.SongSelect: if (SongSelectMessage.TryDecode(message, out var songSelectMessage)) { SongSelect?.Invoke(this, in songSelectMessage); } break; case Midi.Status.TuneRequest: if (TuneRequestMessage.TryDecode(message, out var tuneRequestMessage)) { TuneRequest?.Invoke(this, in tuneRequestMessage); } break; default: Log.Error("Unknown system message type {Status}", $"{status:X2}"); break; } break; default: Log.Error("Unknown message type {Bitmask}", $"{status & 0b1111_0000:X2}"); break; } }
private void InputDevice_NoteOff(NoteOffMessage msg) { SendJson(Map(msg)); }
protected virtual void Input_NoteOff(NoteOffMessage msg) { Console.WriteLine(msg.Pitch + "released"); }
private void NoteOffHandler(NoteOffMessage msg) { this.LaunchEventHandler.CallEvent(new LaunchEvent((int)msg.Pitch, msg.Velocity == 127 ? KeyState.Pressed : KeyState.Released)); Console.WriteLine("Got Note message; C: {0} | P: {1} | V: {2}", msg.Channel, (int)msg.Pitch, msg.Velocity); }
protected const Channel PatternChannel = Channel.Channel4; // not only patterns, but also gives programmed stuffs protected override void Input_NoteOff(NoteOffMessage msg) { Console.WriteLine(msg.Pitch + "released"); output.SendNoteOn(ColorChannel, msg.Pitch, 0); }
public override void Run() { // Create a clock running at the specified beats per minute. int beatsPerMinute = 180; Clock clock = new Clock(beatsPerMinute); // Prompt user to choose an output device (or if there is only one, use that one. OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole(); if (outputDevice == null) { Console.WriteLine("No output devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } outputDevice.Open(); // Prompt user to choose an input device (or if there is only one, use that one). InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole(); if (inputDevice != null) { inputDevice.Open(); } Arpeggiator arpeggiator = new Arpeggiator(inputDevice, outputDevice, clock); Drummer drummer = new Drummer(clock, outputDevice, 4); clock.Start(); if (inputDevice != null) { inputDevice.StartReceiving(clock); } bool done = false; while (!done) { Console.Clear(); Console.WriteLine("BPM = {0}, Playing = {1}, Arpeggiator Mode = {2}", clock.BeatsPerMinute, clock.IsRunning, arpeggiator.Status); Console.WriteLine("Escape : Quit"); Console.WriteLine("Down : Slower"); Console.WriteLine("Up: Faster"); Console.WriteLine("Left: Previous Chord or Scale"); Console.WriteLine("Right: Next Chord or Scale"); Console.WriteLine("Space = Toggle Play"); Console.WriteLine("Enter = Toggle Scales/Chords"); ConsoleKey key = Console.ReadKey(true).Key; Pitch pitch; if (key == ConsoleKey.Escape) { done = true; } else if (key == ConsoleKey.DownArrow) { clock.BeatsPerMinute -= 2; } else if (key == ConsoleKey.UpArrow) { clock.BeatsPerMinute += 2; } else if (key == ConsoleKey.RightArrow) { arpeggiator.Change(1); } else if (key == ConsoleKey.LeftArrow) { arpeggiator.Change(-1); } else if (key == ConsoleKey.Spacebar) { if (clock.IsRunning) { clock.Stop(); if (inputDevice != null) { inputDevice.StopReceiving(); } outputDevice.SilenceAllNotes(); } else { clock.Start(); if (inputDevice != null) { inputDevice.StartReceiving(clock); } } } else if (key == ConsoleKey.Enter) { arpeggiator.ToggleMode(); } else if (ExampleUtil.IsMockPitch(key, out pitch)) { // We've hit a QUERTY key which is meant to simulate a MIDI note, so // send the Note On to the output device and tell the arpeggiator. NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, pitch, 100, clock.Time); clock.Schedule(noteOn); arpeggiator.NoteOn(noteOn); // We don't get key release events for the console, so schedule a // simulated Note Off one beat from now. NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, pitch, 100, clock.Time + 1); CallbackMessage.CallbackType noteOffCallback = beatTime => { arpeggiator.NoteOff(noteOff); }; clock.Schedule(new CallbackMessage(beatTime => arpeggiator.NoteOff(noteOff), noteOff.Time)); } } if (clock.IsRunning) { clock.Stop(); if (inputDevice != null) { inputDevice.StopReceiving(); } outputDevice.SilenceAllNotes(); } outputDevice.Close(); if (inputDevice != null) { inputDevice.Close(); inputDevice.RemoveAllEventHandlers(); } // All done. }
private void MidiDeviceOnNoteOff(NoteOffMessage msg) { byte[] buffer = { (byte)(128 + msg.Channel), (byte)(int)msg.Pitch, 127 }; _serialPort.Write(buffer, 0, 3); }
private void HandleMessages() { if (messageQueue == null) { return; } ArrayList q = (ArrayList)messageQueue.Clone(); messageQueue.Clear(); foreach (MDMessage msg in q) { if (msg is DebugMessage) { if (DebugLog == null) { continue; } DebugMessage msg2 = (DebugMessage)msg; DebugLog(msg2.message); continue; } if (msg is NoteOnMessage) { if (NoteOn == null) { continue; } NoteOnMessage msg2 = (NoteOnMessage)msg; NoteOn(msg2.part, msg2.num, msg2.velocity); continue; } if (msg is NoteOffMessage) { if (NoteOff == null) { continue; } NoteOffMessage msg2 = (NoteOffMessage)msg; NoteOff(msg2.part, msg2.num); continue; } if (msg is ParamChangeMessage) { if (ParamChange == null) { continue; } ParamChangeMessage msg2 = (ParamChangeMessage)msg; ParamChange(msg2.part, msg2.param, msg2.value); continue; } if (msg is BeatTickMessage) { if (BeatTick == null) { continue; } BeatTickMessage msg2 = (BeatTickMessage)msg; BeatTick(msg2.tick, msg2.beat, msg2.bar); continue; } if (msg is BeatMessage) { if (Beat == null) { continue; } BeatMessage msg2 = (BeatMessage)msg; Beat(msg2.beat, msg2.bar); continue; } if (msg is BarMessage) { if (Bar == null) { continue; } BarMessage msg2 = (BarMessage)msg; Bar(msg2.bar); continue; } if (msg is TempoChangeMessage) { if (TempoChange == null) { continue; } TempoChangeMessage msg2 = (TempoChangeMessage)msg; TempoChange(msg2.bpm); continue; } if (msg is NewMusicalSeedMessage) { if (NewMusicalSeed == null) { continue; } NewMusicalSeedMessage msg2 = (NewMusicalSeedMessage)msg; NewMusicalSeed(msg2.name); continue; } if (msg is CueChangeMessage) { if (CueChange == null) { continue; } CueChangeMessage msg2 = (CueChangeMessage)msg; CueChange(msg2.cue, msg2.seedName, msg2.style); continue; } if (msg is ProjectLoadMessage) { if (ProjectLoad == null) { continue; } //ProjectLoadMessage msg2 = (ProjectLoadMessage)msg; ProjectLoad(); continue; } } }