public override void Run() { // Prompt user to choose an input device (or if there is only one, use that one). InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole(); if (inputDevice == null) { Console.WriteLine("No input devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } inputDevice.Open(); inputDevice.StartReceiving(null); Summarizer summarizer = new Summarizer(inputDevice); ExampleUtil.PressAnyKeyToContinue(); inputDevice.StopReceiving(); inputDevice.Close(); inputDevice.RemoveAllEventHandlers(); }
/// <summary> /// Déconnexion MIDI de l'APC40 /// </summary> /// <exception cref="AlreadyDisconnectedAPC40Device" public void close() { if (connected) { try { Log.writeLine("Déconnexion APC40"); if (_virtualMidiPort != null) //déconnexion du MIDI virtuel { _virtualMidiPort.shutdown(); } if (_InputAPC40 != null) //déconnexion Input { _InputAPC40.StopRecording(); //fin de la capture des Input _InputAPC40.Close(); } if (_OuputAPC40 != null) //déconnexion Output { _OuputAPC40.Send(new SysExMessage(InitConfByteMode0)); //remise en mode par defaut _OuputAPC40.Close(); } } catch { Log.writeLine("Erreur de deconnexion de l'APC40"); Log.writeLine("----------------------------------------------------------------------------"); Log.writeLine("----------------------------------------------------------------------------"); throw new ErrorAPC40DisconnectionException(); } connected = false; } else { Log.writeLine("APC40 déja déconnecté"); Log.writeLine("----------------------------------------------------------------------------"); Log.writeLine("----------------------------------------------------------------------------"); throw new AlreadyDisconnectedAPC40Device(); //interface deja deconnecté } }
/* Likewise, when we're finished reading, stop recording and then close the device. * If we want to print the captured note sequence, we do so now. */ public void Stop() { try { inputDevice.StopRecording(); inputDevice.Reset(); inputDevice.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } if (debugPrintTimestamps) { foreach (NoteEvent ne in noteEvents) { Console.WriteLine("Note " + ne.Channel + ", Vel " + ne.Velocity + ", Time " + ne.Timestamp.TotalMilliseconds); } } }
private void ConnectDevice() { if (isConnected == false) { isConnected = true; // Connect to input midi device based on index inDevice = new InputDevice(MidiDeviceIndex); ChannelStopper stopper = new ChannelStopper(); MidiLogBox.Items.Add("Connected to MIDI input device " + InputDevice.GetDeviceCapabilities(MidiDeviceIndex).name); MidiLogBox.Items.Add("Driver Version: " + InputDevice.GetDeviceCapabilities(MidiDeviceIndex).driverVersion); MidiLogBox.Items.Add("Manufacturer ID: " + InputDevice.GetDeviceCapabilities(MidiDeviceIndex).mid); inDevice.ChannelMessageReceived += delegate(object midiSender, ChannelMessageEventArgs eMidi) { if (midiChannels.Contains(eMidi.Message.MidiChannel + 1)) { // log midi messages stopper.Process(eMidi.Message); MidiLogBox.Items.Add("Ch:" + (eMidi.Message.MidiChannel + 1) + " Cmd:" + eMidi.Message.Command + " D1:" + eMidi.Message.Data1 + " D2:" + eMidi.Message.Data2); MidiLogBox.SelectedIndex = MidiLogBox.Items.Count - 1; MidiLogBox.SelectedIndex = -1; } }; // Show that we're connected now! inDevice.StartRecording(); MidiConnectBtn.Text = "Disconnect"; } else { isConnected = false; // Switch the button back to "Connect" and close our previous midi connection MidiConnectBtn.Text = "Connect"; inDevice.Close(); } }
public static void Stop() { Log.WriteLine("PAW-01 Host shutting down..."); stopped = true; midiin.StopRecording(); mouseProc.Join(); controllerPort.DataReceived -= ControllerInHandler; keyboardPort.DataReceived -= KeyboardInHandler; Log.WriteLine("Processors offline."); keyboardPort.Close(); controllerPort.Close(); midiin.Close(); midiin.Dispose(); midiout.Close(); midiout.Dispose(); Log.WriteLine("Ports offline."); }
private void cbMidi_SelectedIndexChanged(object sender, EventArgs e) { int stName = cbMidi.SelectedIndex; if (stName > -1) { RegSaveSetting("DanceFloorControl", "Midi", "Device", InputDevice.InstalledDevices[stName].Name); try { if (inputDevice != null) { inputDevice.StopReceiving(); inputDevice.Close(); inputDevice = null; } } catch (Exception ee) { Console.WriteLine(ee.ToString()); } try { inputDevice = InputDevice.InstalledDevices[stName]; inputDevice.Open(); inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn); inputDevice.ControlChange += new InputDevice.ControlChangeHandler(MidiCC); inputDevice.StartReceiving(null); } catch (Exception ee) { MessageBox.Show("Midi Open Error: " + ee.ToString()); inputDevice = null; } } }
private void Button5_Click(object sender, EventArgs e) { int ii = (listBox3.SelectedIndex + 1); int i = (listBox4.SelectedIndex - 1); context = SynchronizationContext.Current; toAPCmini = new OutputDevice(ii); fromAPCmini = new InputDevice(i); // fromAPCmini.StartRecording(); if (toAPCmini != null) { toAPCmini.Dispose(); } if (fromAPCmini != null) { fromAPCmini.StopRecording(); fromAPCmini.Close(); } toAPCmini = new OutputDevice(ii); outconnected = true; for (int a = 0; a < 24; a = a + 1) { builder.Command = ChannelCommand.NoteOn; builder.MidiChannel = 1; builder.Data1 = a; builder.Data2 = 1; builder.Build(); toAPCmini.Send(builder.Result); } for (int a = 24; a < 40; a = a + 1) { builder.Command = ChannelCommand.NoteOn; builder.MidiChannel = 1; builder.Data1 = a; builder.Data2 = 5; builder.Build(); toAPCmini.Send(builder.Result); } for (int a = 40; a < 64; a = a + 1) { builder.Command = ChannelCommand.NoteOn; builder.MidiChannel = 1; builder.Data1 = a; builder.Data2 = 3; builder.Build(); toAPCmini.Send(builder.Result); } int milliseconds = 500; Thread.Sleep(milliseconds); for (int a = 0; a < 120; a = a + 1) { builder.Command = ChannelCommand.NoteOn; builder.MidiChannel = 1; builder.Data1 = a; builder.Data2 = 0; builder.Build(); toAPCmini.Send(builder.Result); } context.Post(delegate(object dummy) { channelListBox.Items.Add("CONNECTION APC MINI Attempted"); channelListBox.SelectedIndex = channelListBox.Items.Count - 1; }, null); fromAPCmini = new InputDevice(i); fromAPCmini.ChannelMessageReceived += HandleFromAPCminiMessageReceived; fromAPCmini.StartRecording(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button6.Enabled = true; connectAPCmini.Enabled = false; }
protected override void OnClosed(EventArgs e) { _device?.Close(); base.OnClosed(e); }
private void InitLaunchpad() { if (ready) { return; } if (launchpadOutput != null && launchpadOutput.IsOpen) { launchpadOutput.Close(); } if (launchpadInput != null && launchpadInput.IsOpen) { launchpadInput.Close(); } launchpadOutput = null; launchpadInput = null; Debug.Log("Looking for output device..."); foreach (OutputDevice device in OutputDevice.InstalledDevices) { if (device.Name.Contains("Launchpad")) { launchpadOutput = device; Debug.Log("Launchpad output found!"); } } if (launchpadOutput == null) { Debug.Log("Unable to find launchpad output :("); ready = false; return; } Debug.Log("Looking for input device..."); foreach (InputDevice device in InputDevice.InstalledDevices) { if (device.Name.Contains("Launchpad")) { launchpadInput = device; Debug.Log("Launchpad input found!"); } } if (launchpadInput == null) { Debug.Log("Unable to find launchpad input :("); ready = false; return; } launchpadOutput.Open(); launchpadInput.Open(); ready = true; launchpadInput.NoteOn += new InputDevice.NoteOnHandler(MyNoteOn); launchpadInput.StartReceiving(null); }
public void Shutdown() { inDevice.Close(); inDevice.Dispose(); }
public void Close() { inDevice.Close(); }
public void Close() { inputDevice.StopRecording(); inputDevice.Close(); }
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 Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { indev.StopRecording(); indev.Close(); }
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 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. }