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 InputNoteOff(Midi.NoteOffMessage msg) { if (channel == 0 || channel == (int)msg.Channel + 1) { _deviceInterface.OnMidiNote((int)msg.Channel + 1, false, (int)msg.Pitch); } }
public void PlayNote(Note note) { var noteOn = new NoteOnMessage(this._outputDevice, this.PlayerParameters.Channel, note, this._velocity, this._clock.BeatTime); var noteOff = new NoteOffMessage(this._outputDevice, this.PlayerParameters.Channel, note, this._velocity, this._clock.BeatTime + 1); this._clock.Schedule(noteOn); this._clock.Schedule(noteOff); }
private void OnInputDeviceNoteOff(NoteOffMessage msg) { OnButtonClick((Button)msg.Pitch, ButtonClickState.Released); }
public void NoteOff(NoteOffMessage msg, OutputDevice output) { if (msg.Pitch.Octave() * 12 + msg.Pitch.PositionInOctave() < 41) output.SendNoteOff(msg.Channel, msg.Pitch - 12, msg.Velocity); }
public void NoteOff(NoteOffMessage msg) { lock (this) { pitchesPressed.Remove(msg.Pitch); PrintStatus(); } }
public override void Run() { // Create a clock running at the specified beats per minute. int beatsPerMinute = 180; Clock clock = new Clock(beatsPerMinute); // Utility function prompts user to choose an output device (or if there is only one, // returns 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(); // Utility function prompts user to choose an input device (or if there is only one, // returns that one). InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole(); if (inputDevice != null) { inputDevice.Open(); } Arpeggiator arpeggiator = new Arpeggiator(inputDevice, outputDevice, clock); Console.WriteLine("Press Escape when finished."); clock.Start(); if (inputDevice != null) { inputDevice.StartReceiving(clock); } while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { break; } Note note; if (ExampleUtil.IsMockNote(keyInfo.Key, out note)) { NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, note, 100, clock.BeatTime); NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, note, 100, clock.BeatTime+1); clock.Schedule(noteOn); clock.Schedule(noteOff); arpeggiator.NoteOn(noteOn); arpeggiator.NoteOff(noteOff); } } clock.Stop(); // Close the devices. outputDevice.Close(); if (inputDevice != null) { inputDevice.StopReceiving(); inputDevice.Close(); } // All done. }
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. }
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, OutputDevice output) { output.SendNoteOn(msg.Channel, currentNote, 127); }
public override void Run() { if (OutputDevice.InstalledDevices.Count == 0) { Console.WriteLine("Can't do anything with no output device."); return; } float beatsPerMinute = 180; Clock clock = new Clock(beatsPerMinute); OutputDevice outputDevice = OutputDevice.InstalledDevices[0]; outputDevice.Open(); Drummer drummer = new Drummer(clock, outputDevice, 4); InputDevice inputDevice = null; if (InputDevice.InstalledDevices.Count > 0) { // Just pick the first input device. This will throw an exception if there isn't // one. inputDevice = InputDevice.InstalledDevices[0]; inputDevice.Open(); } Scaler scaler = new Scaler(clock, inputDevice, outputDevice); clock.Start(); if (inputDevice != null) { inputDevice.StartReceiving(clock); } bool done = false; while (!done) { Console.Clear(); Console.WriteLine("BPM = {0}, Playing = {1}, Scale = {2}", clock.BeatsPerMinute, clock.IsRunning, scaler.GetScaletoUse()); Console.WriteLine("Escape : Quit"); Console.WriteLine("Down : Slower"); Console.WriteLine("Up: Faster"); Console.WriteLine("Left: Previous Scale"); Console.WriteLine("Right: Next Scale"); Console.WriteLine("Space = Toggle Play"); ConsoleKey key = Console.ReadKey(true).Key; Note note; 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) { scaler.NextScale(); } else if (key == ConsoleKey.LeftArrow) { scaler.PreviousScale(); } 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.D1) { NoteOnMessage msg = new NoteOnMessage(outputDevice, Channel.Channel1, Note.C4, 80, clock.BeatTime); NoteOffMessage msg2 = new NoteOffMessage(outputDevice, Channel.Channel1, Note.C4, 80, clock.BeatTime+0.99f); clock.Schedule(msg); clock.Schedule(msg2); scaler.NoteOn(msg); } else if (ExampleUtil.IsMockNote(key, out note)) { NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, note, 100, clock.BeatTime); NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, note, 100, clock.BeatTime + 1); clock.Schedule(noteOn); clock.Schedule(noteOff); scaler.NoteOn(noteOn); } } if (clock.IsRunning) { clock.Stop(); if (inputDevice != null) { inputDevice.StopReceiving(); } outputDevice.SilenceAllNotes(); } outputDevice.Close(); if (inputDevice != null) { inputDevice.Close(); } }
public void NoteOff(NoteOffMessage msg) { try { NotesDictionary[msg.Pitch.ToString()]. ReleaseKey(); } catch (Exception) { // ignored } }
// 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); }
public void NoteOff(NoteOffMessage msg, OutputDevice output) { }
/// <summary> /// Process the Note Off message. /// </summary> /// <param name="message">The note off message.</param> public void ProcessMidiMessage(NoteOffMessage message) { var channel = message.Channel; Trace.TraceInformation("Got note OFF for channel " + channel.Name() + " and pitch " + message.Pitch.NotePreferringFlats()); NoteOnMessage noteOnMessage = incompleteMessages[channel][message.Pitch]; if (noteOnMessage == null) { Trace.TraceWarning("Got note off message but don't have a note on message for channel " + channel.Name() + " and pitch " + message.Pitch.NotePreferringFlats() + ". Ignoring message."); return; } incompleteMessages[channel][message.Pitch] = null; lock (lockObject) { completedNotes.Add(new Note { Channel = channel, StartTime = noteOnMessage.Time, EndTime = message.Time, Pitch = noteOnMessage.Pitch }); } }
private void NoteOff(NoteOffMessage msg) { notesDown.Remove(msg.Pitch); try { operations[msg.Channel].NoteOff(msg, outputDevice); } catch (KeyNotFoundException) { } finally { Display(); } }