/// <summary> /// Callback called when data dump is received from device /// </summary> private void OnSysExMessageReceived(object sender, SysExMessageEventArgs e) { // At 11 byte we have effect type, so we check value there var effect = (Effect)e.Message[10]; var expectedDumpLength = ExpectedDumpLength(effect) + SysExUtils.DumpPaddingSize; var actualDumpLength = e.Message.Length; if (actualDumpLength != expectedDumpLength) { throw new InvalidDumpSizeException(expectedDumpLength, actualDumpLength); } _logger.Receive($"Received {effect}"); _dataDumps.Add(effect, e.Message); _dumpCount++; if (_dumpCount == 4) { _timer.Stop(); _device.StopRecording(); _device.Dispose(); DataDumpReceived?.Invoke(this, new EffectsPatchDumpReceivedEventArgs(new Patch(_dataDumps))); } }
/// <summary> /// Callback called when data dump is received from device /// </summary> private void OnSysExMessageReceived(object sender, SysExMessageEventArgs e) { switch (e.Message.Length) { case ExpectedCommonDumpLength + SysExUtils.DumpPaddingSize: _commonDump = e.Message; _logger.Receive("Received Patch.Common"); break; case ExpectedPartialDumpLength + SysExUtils.DumpPaddingSize: { // At 11 byte we have partial identifier, so we check value at that byte var key = (DrumKey)e.Message[10]; _partialsDump[key] = e.Message; _logger.Receive($"Received Patch.Partials[{key}]"); break; } } _dumpCount++; if (_dumpCount == 39) { _timer.Stop(); _device.StopRecording(); _device.Dispose(); DataDumpReceived?.Invoke(this, new DrumKitPatchDumpReceivedEventArgs(new Patch(_commonDump, _partialsDump))); } }
/// <summary> /// Callback called when data dump is received from device /// </summary> private void OnSysExMessageReceived(object sender, SysExMessageEventArgs e) { switch (e.Message.Length) { case ExpectedCommonDumpLength + SysExUtils.DumpPaddingSize: _logger.Receive("Received Patch.Common"); _commonDump = e.Message; break; case ExpectedVfxDumpLength + SysExUtils.DumpPaddingSize: _vfxDump = e.Message; _logger.Receive("Received Patch.VocalEffect"); break; } _dumpCount++; if (_dumpCount == 2) { _timer.Stop(); _device.StopRecording(); _device.Dispose(); DataDumpReceived?.Invoke(this, new CommonAndVocalFxDumpReceivedEventArgs(new CommonAndVocalEffectPatch(_commonDump, _vfxDump))); } }
public void Dispose() { if (midiinput != null) { midiinput.Dispose(); } }
/// <summary> /// /// </summary> public static void SetInputMidiDeviceA(string deviceName) { if (inputDeviceA != null && inputDeviceA.Name.Equals(deviceName)) { return; } if (inputDeviceB != null && inputDeviceB.Name.Equals(deviceName)) { return; } if (inputDeviceA != null) { try { inputDeviceA.StopEventsListening(); } catch { } finally { inputDeviceA.Dispose(); } } Settings.Default.MidiIF = deviceName; inputDeviceA = InputDevice.GetByName(deviceName); if (inputDeviceA != null) { inputDeviceA.EventReceived += midiEventReceivedA; inputDeviceA.StartEventsListening(); } }
private void Form1_Leave(object sender, EventArgs e) { inputDevice.Dispose(); outputDevice.Dispose(); Disconnect(); if (udpServer != null) { udpServer.Close(); } if (thdUDPServer != null) { thdUDPServer.Join(2000); thdUDPServer.Abort(); } }
public void Dispose() { if (_inputDevice != null) { Close(); _inputDevice.Dispose(); } }
private void OnDestroy() { Debug.Log("Closing MIDI device."); if (inputDevice != null) { inputDevice.Dispose(); } }
/// <summary> /// Callback called when data dump is received from device /// </summary> private void OnSysExMessageReceived(object sender, SysExMessageEventArgs e) { _timer.Stop(); _device.StopRecording(); _device.Dispose(); var actualLength = e.Message.Length - SysExUtils.DumpPaddingSize; if (actualLength != ExpectedDumpLength) { throw new InvalidDumpSizeException(ExpectedDumpLength, actualLength); } _logger.Receive("Received Patch"); DataDumpReceived?.Invoke(this, new AnalogPatchDumpReceivedEventArgs(new Patch(e.Message))); }
public void Cleanup(SyncObject syncObject) { if (device != null) { device.EventReceived -= OnEventReceived; device.Dispose(); } syncObject.BeforeSync -= OnBeforeSync; }
public void Disconnect() { lock (MidiCom.lock_obj) { InputDevice inDevice = this.inDevice; OutputDevice outDevice = this.outDevice; this.inDevice = (InputDevice)null; this.outDevice = (OutputDevice)null; if (inDevice != null) { Logger.Log("Disconnecting MIDI-in Device"); try { inDevice.StopRecording(); } catch (Exception ex) { } try { inDevice.Close(); } catch (Exception ex) { } try { inDevice.Dispose(); } catch (Exception ex) { } } if (outDevice != null) { Logger.Log("Disconnecting MIDI-out Device"); try { outDevice.Close(); } catch (Exception ex) { } try { outDevice.Dispose(); } catch (Exception ex) { } } Form1.m_CurrentPatch.m_GETRequestWaiting = false; } }
/// <summary> /// Releases all resources used by the clock. /// </summary> public override void Dispose() { Interlocked.Exchange(ref _isDisposing, 1); _inDev.RealTime -= RealTime; if (_ownsInputDevice) { _inDev.StopReceiving(); _inDev.Dispose(); } }
public void Close() { try { inputDevice.StopEventsListening(); inputDevice.EventReceived -= OnEventReceived; inputDevice.Dispose(); } catch (Exception ex) { logger.Error(ex); throw; } }
public void Disconnect() { if (_iDevice != null && !_iDevice.IsDisposed) { _iDevice.Dispose(); } if (_oDevice != null && !_oDevice.IsDisposed) { _oDevice.Dispose(); } OnStatusChanged(this, EMidiEvent.DeviceDisconnected); }
public void Dispose() { if (_inDevice == null) { return; } _inDevice.ChannelMessageReceived -= InDevice_ChannelMessageReceived; try { _inDevice.StopRecording(); _inDevice.Dispose(); } catch (Exception e) { Console.WriteLine(e.Message); } _inDevice = null; }
private void SelectDevice(int id) { InputDevice newDevice = InputDevice.GetById(id); if (currentMidiDevice?.Id == newDevice.Id) { return; } else { if (currentMidiDevice != null) { currentMidiDevice.EventReceived -= OnMidiEventReceived; currentMidiDevice.Dispose(); } } currentMidiDevice = newDevice; currentMidiDevice.EventReceived += OnMidiEventReceived; Log($"Selected {currentMidiDevice.Name}."); }
public static void Disconnect() { if (wetMidiKeyboard == null) { return; } if (wetMidiKeyboard.IsListeningForEvents) { try { wetMidiKeyboard.StopEventsListening(); wetMidiKeyboard.Reset(); wetMidiKeyboard.EventReceived -= MidiKeyboard_EventReceived; wetMidiKeyboard.Dispose(); cts.Cancel(); } catch (Exception e) { MessageBox.Show($"断开错误 \r\n {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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 button2_Click(object sender, EventArgs e) { try { //var inputDevice = InputDevice.GetById(comboBox1.SelectedIndex); //inputDevice.EventReceived -= OnEventReceived1; inputDevice.StopEventsListening(); inputDevice.Dispose(); serialPort1.Close(); button2.Enabled = false; button1.Enabled = true; comboBox1.Enabled = true; comboBox3.Enabled = true; comboBox4.Enabled = true; textBox1.AppendText("All devices has been closed." + Environment.NewLine); toolStripStatusLabel1.Text = "No device opened"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void Dispose() { _inDevice.StartRecording(); _inDevice.Dispose(); _outDevice.Dispose(); }
public void Cleanup() { _inputDevice.Dispose(); _outputDevice.Dispose(); }
private static void Main() { Console.WriteLine("WELCOME TO MIDI PRACTICE\n"); Console.WriteLine("Select gametype by typing number (1 to 4) and hitting ENTER.\n\n"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("1: Score Attack"); Console.WriteLine("2: Score Attack - Text To Speech DISABLED"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("3: Endless Mode"); Console.WriteLine("4: Endless Mode - Text To Speech DISABLED"); Console.ResetColor(); bool endlessMode = EndlessOrScore(); Console.ForegroundColor = endlessMode ? ConsoleColor.Cyan : ConsoleColor.Yellow; Console.WriteLine(endlessMode ? EndlessModeASCII : ScoreAttackASCII); Console.WriteLine("Select difficulty by typing number (1 to 5) and hitting ENTER.\n\n"); Console.ResetColor(); Console.WriteLine("1: Numpad\n Numbers 0 to 9, no MIDI keyboard required!\n"); Console.WriteLine("2: Basic\n White keys only, notes are always natural.\n"); Console.WriteLine("3: Regular\n White keys are always natural, and black keys are always sharp.\n"); Console.WriteLine("4: Semi-Advanced\n White keys are always natural, and black keys can be either sharp or flat.\n"); Console.WriteLine("5: Advanced\n White keys are NOT always natural, and black keys can be either sharp or flat.\n"); Console.WriteLine("x: Exit\n"); bool game = int.TryParse(Console.ReadLine(), out int gameDifficulty); // get the game difficulty the user selected string modeString = endlessMode ? "Endless Mode." : "Score Attack - 20 rounds."; switch (gameDifficulty) { case 1: Console.WriteLine("Numpad selected. \n" + (endlessMode ? modeString : "Score Attack - 30 rounds.")); break; case 2: Console.WriteLine("Basic selected. \n" + modeString); break; case 3: Console.WriteLine("Regular selected. \n" + modeString); break; case 4: Console.WriteLine("Semi-Advanced selected. \n" + modeString); break; case 5: Console.WriteLine("Advanced selected. \n" + modeString); break; default: Console.WriteLine("Press ENTER to exit."); break; } OutputDevice outputDevice = null; InputDevice inputDevice = null; if (game) { outputDevice = SelectMidiDevice(OutputDevice.GetAll().ToList()); // get output device outputDevice.EventSent += EmptyEvent; if (gameDifficulty > 1) { inputDevice = SelectMidiDevice(InputDevice.GetAll().ToList()); // get input device for MIDI mode if (inputDevice == default) // if no input devices, default to Numpad { gameDifficulty = 1; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("A MIDI keyboard is required for this difficulty! Starting Numpad instead.\nPress ENTER to continue."); Console.ResetColor(); Console.ReadLine(); } } } while (game) // we're playing { GameCode(endlessMode, gameDifficulty, outputDevice, inputDevice); // the game is in here Console.WriteLine("Want to play again? Type Y to replay the game."); if (Console.ReadLine().ToLower() != "y") // if the user doesn't want to play { game = false; // change the game bool to false Console.WriteLine("\nPress ENTER to exit."); } } if (inputDevice != null) { inputDevice.Dispose(); // always dispose your IDisposables when you're done with them } if (outputDevice != null) { outputDevice.Dispose(); // always dispose your IDisposables when you're done with them } Console.ReadLine(); }
static void Main(string[] args) { var isCanceled = false; Console.CancelKeyPress += (sender, eventArgs) => { Console.WriteLine("Got the Ctrl-C"); isCanceled = true; eventArgs.Cancel = true; }; var deviceName = "X"; var vb = new VmClient(); var od = new OutputDevice(GetMidiOutputDevice(deviceName)); var id = new InputDevice(GetMidiInputDevice(deviceName)); for (int channel = 1; channel <= 8; channel++) { od.Send(new ChannelMessage(ChannelCommand.Controller, 0, channel, 0)); } //UpdateCCVoiceMeter(vb, "Bus[0].Gain", 116); //UpdateCCVoiceMeter(vb, "Bus[1].Gain", 89); //UpdateCCVoiceMeter(vb, "Bus[2].Gain", 0); //UpdateCCVoiceMeter(vb, "Bus[3].Gain", 127, 12.0f); //UpdateCCVoiceMeter(vb, "Bus[4].Gain", 127, 12.0f); //UpdateCCVoiceMeter(vb, "Strip[0].Gain", 102); //UpdateCCVoiceMeter(vb, "Strip[1].Gain", 102); //UpdateCCVoiceMeter(vb, "Strip[2].Gain", 127, 12.0f); //UpdateCCVoiceMeter(vb, "Strip[3].Gain", 102); //UpdateCCVoiceMeter(vb, "Strip[4].Gain", 102); id.ChannelMessageReceived += (ob, e) => { var m = e.Message; if (m.MessageType == MessageType.Channel && m.Command == ChannelCommand.NoteOff) { float vmVal; switch (m.Data1) { case 8: ToggleVoiceMeeter(vb, "Strip[0].B1"); break; case 16: ToggleVoiceMeeter(vb, "Strip[0].B2"); break; case 9: ToggleVoiceMeeter(vb, "Strip[1].B1"); break; case 17: ToggleVoiceMeeter(vb, "Strip[1].B2"); break; case 10: ToggleVoiceMeeter(vb, "Strip[2].B1"); break; case 18: ToggleVoiceMeeter(vb, "Strip[2].B2"); break; case 12: ToggleVoiceMeeter(vb, "Strip[3].A1"); break; case 20: ToggleVoiceMeeter(vb, "Strip[3].A2"); break; case 13: ToggleVoiceMeeter(vb, "Strip[4].A1"); break; case 21: ToggleVoiceMeeter(vb, "Strip[4].A2"); break; case 14: ToggleVoiceMeeter(vb, "Bus[0].Mute"); break; case 15: ToggleVoiceMeeter(vb, "Bus[1].Mute"); break; case 23: ToggleVoiceMeeter(vb, "Bus[2].Mute"); break; } } else if (m.MessageType == MessageType.Channel && m.Command == ChannelCommand.Controller) { switch (m.Data1) { case 1: // CC1 UpdateCCVoiceMeter(vb, "Strip[0].Gain", m.Data2); break; case 2: // CC2 UpdateCCVoiceMeter(vb, "Strip[1].Gain", m.Data2); break; case 3: UpdateCCVoiceMeter(vb, "Strip[2].Gain", m.Data2); //UpdateCCVoiceMeter(vb, "Strip[2].Gain", m.Data2, 12.0f); break; case 5: UpdateCCVoiceMeter(vb, "Strip[3].Gain", m.Data2); break; case 6: UpdateCCVoiceMeter(vb, "Strip[4].Gain", m.Data2); break; case 7: UpdateCCVoiceMeter(vb, "Bus[0].Gain", m.Data2); break; case 8: UpdateCCVoiceMeter(vb, "Bus[1].Gain", m.Data2); break; case 9: UpdateCCVoiceMeter(vb, "Bus[2].Gain", m.Data2); break; } } }; id.StartRecording(); while (!isCanceled) { if (vb.Poll()) { //strip 0 var vmVal = vb.GetParam($"Strip[0].B1"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 0, (int)vmVal)); vmVal = vb.GetParam($"Strip[0].B2"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 8, (int)vmVal)); //strip 1 vmVal = vb.GetParam($"Strip[1].B1"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 1, (int)vmVal)); vmVal = vb.GetParam($"Strip[1].B2"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 9, vmVal == 1 ? 2 : 0)); //strip 2 vmVal = vb.GetParam($"Strip[2].B1"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 2, (int)vmVal)); vmVal = vb.GetParam($"Strip[2].B2"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 10, vmVal == 1 ? 2 : 0)); //strip 3 vmVal = vb.GetParam($"Strip[3].A1"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 4, (int)vmVal)); vmVal = vb.GetParam($"Strip[3].A2"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 12, (int)vmVal)); //strip 4 vmVal = vb.GetParam($"Strip[4].A1"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 5, (int)vmVal)); vmVal = vb.GetParam($"Strip[4].A2"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 13, (int)vmVal)); //Bus 0 vmVal = vb.GetParam($"Bus[0].Mute"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 6, vmVal == 1 ? 2 : 0)); vmVal = vb.GetParam($"Bus[1].Mute"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 7, vmVal == 1 ? 2 : 0)); vmVal = vb.GetParam($"Bus[2].Mute"); od.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, 15, vmVal == 1 ? 2 : 0)); } Thread.Sleep(20); } id.Dispose(); od.Dispose(); vb.Dispose(); }
/// <summary> /// Callback called when data dump is received from device /// </summary> private void OnSysExMessageReceived(object sender, SysExMessageEventArgs e) { switch (e.Message.Length) { case ExpectedCommonDumpLength + SysExUtils.DumpPaddingSize: _logger.Receive("Received Patch.Common"); _commonDump = e.Message; break; case ExpectedModifiersDumpLength + SysExUtils.DumpPaddingSize: _logger.Receive("Received Patch.Modifiers"); _modifiersDump = e.Message; break; case ExpectedPartialDumpLength + SysExUtils.DumpPaddingSize: { // At 11 byte we have partial number, so we check value at that byte var partial = (DigitalPartial)e.Message[10]; switch (partial) { case DigitalPartial.First: _logger.Receive($"Received Patch.PartialOne"); _partialsDump[0] = e.Message; break; case DigitalPartial.Second: _logger.Receive($"Received Patch.PartialTwo"); _partialsDump[1] = e.Message; break; case DigitalPartial.Third: _logger.Receive($"Received Patch.PartialThree"); _partialsDump[2] = e.Message; break; default: throw new ArgumentOutOfRangeException(nameof(partial), partial, null); } break; } default: throw new InvalidDumpSizeException(); } _dumpCount++; if (_dumpCount == 5) { _timer.Stop(); _device.StopRecording(); _device.Dispose(); DataDumpReceived?.Invoke(this, new DigitalPatchDumpReceivedEventArgs( new Patch(_commonDump, _partialsDump, _modifiersDump) )); } }
public void Shutdown() { inDevice.Close(); inDevice.Dispose(); }
public void Dispose() { input.Dispose(); output.Dispose(); }
public void Dispose() { Input.StopRecording(); Input.Dispose(); Link.Dispose(); }
public void GlobalCleanup() { _inputDevice.EventReceived -= OnEventReceived; _inputDevice.Dispose(); _outputDevice.Dispose(); }
public void Dispose() { Deactivate(); _device.Dispose(); }
public void Dispose() { MidiIn.StopRecording(); MidiIn.Dispose(); MidiOut.Dispose(); }