public Task <IMidiOutput> OpenOutputAsync(IMidiPortDetails port) { if (port != EmptyMidiOutput.Instance.Details) { throw new ArgumentException(string.Format("Port ID {0} does not exist.", port.Id)); } return(Task.FromResult <IMidiOutput> (EmptyMidiOutput.Instance)); }
protected RtMidiPort(IMidiPortDetails portDetails) { if (portDetails == null) { throw new ArgumentNullException("portDetails"); } Details = portDetails; Connection = MidiPortConnectionState.Closed; State = MidiPortDeviceState.Connected; // there is no way to check that... }
private async void OnOutputItemSelected(object sender, SelectedItemChangedEventArgs e) { _device = e.SelectedItem as IMidiPortDetails; if (_device != null) { this.MessageType.IsEnabled = true; this.ResetButton.IsEnabled = true; _synthesizer = await _access.OpenOutputAsync(_device.Id); } }
/// <summary> /// Update UI on device removed /// </summary> /// <param name="sender">The active DeviceWatcher instance</param> /// <param name="args">Event arguments</param> private async void OnDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args) { // If all devices have been enumerated if (this.enumerationCompleted) { await coreDispatcher.RunAsync(CoreDispatcherPriority.High, () => { // Update the device list IMidiPortDetails query = DeviceCollection.Where(s => s.Id == args.Id).FirstOrDefault(); if (query != null) { DeviceCollection.Remove(query); } }); } }
static async Task Play(IMidiPortDetails port) { var access = MidiAccessManager.Default; using (var output = await access.OpenOutputAsync(port.Id)) { Console.WriteLine("Note One"); output.Send(new byte [] { MidiEvent.Program, GeneralMidi.Instruments.AcousticGrandPiano }, 0, 2, 0); // There are constant fields for each GM instrument output.Send(new byte [] { MidiEvent.NoteOn, 0x40, 0x7F }, 0, 3, 0); // There are constant fields for each MIDI event System.Threading.Thread.Sleep(1000); output.Send(new byte [] { MidiEvent.NoteOff, 0x40, 0x7F }, 0, 3, 0); Console.WriteLine("Note Two"); output.Send(new byte [] { MidiEvent.Program, GeneralMidi.Instruments.StringEnsemble1 }, 0, 2, 0); // Strings Ensemble output.Send(new byte [] { MidiEvent.NoteOn, 0x40, 0x7F }, 0, 3, 0); System.Threading.Thread.Sleep(1000); output.Send(new byte [] { MidiEvent.NoteOff, 0x40, 0x7F }, 0, 3, 0); } }
private async Task PollMidiConnection() { //Checking for added devices int numDevices = midi.Inputs.Count(); if (numDevices > inDevice.Count) { foreach (IMidiPortDetails details in midi.Inputs) { IMidiInput input = inDevice.Find(x => x.Details.Name.Equals(details.Name)); if (input == null) { IMidiInput newInput = midi.OpenInputAsync(details.Id).Result; inDevice.Add(newInput); this.Monitor.Log($"{newInput.Details.Name} connected", LogLevel.Info); break; } } } //Checking for removed devices if (numDevices < inDevice.Count) { foreach (IMidiInput input in inDevice) { IMidiPortDetails details = midi.Inputs.ToList().Find(x => x.Id.Equals(input.Details.Id)); if (details == null) { this.Monitor.Log($"{input.Details.Name} disconnected", LogLevel.Info); await input.CloseAsync(); inDevice.Remove(input); break; } } } await Task.Delay(1000 / 60); }
public WinMMMidiInput(IMidiPortDetails details) { Details = details; // prevent garbage collection of the delegate midiInProc = HandleMidiInProc; DieOnError(WinMMNatives.midiInOpen(out handle, uint.Parse(Details.Id), midiInProc, IntPtr.Zero, MidiInOpenFlags.Function | MidiInOpenFlags.MidiIoStatus)); DieOnError(WinMMNatives.midiInStart(handle)); while (lmBuffers.Count < LONG_BUFFER_COUNT) { var buffer = new LongMessageBuffer(handle); buffer.PrepareHeader(); buffer.AddBuffer(); lmBuffers.Add(buffer.Ptr, buffer); } Connection = MidiPortConnectionState.Open; }
public Task <IMidiOutput> OpenOutputAsync(IMidiPortDetails port) { var p = new RtMidiOutput(port); return(p.OpenAsync().ContinueWith(t => (IMidiOutput)p)); }
public RtMidiOutput(IMidiPortDetails portDetails) : base(portDetails) { }
public WinMMMidiOutput(IMidiPortDetails details) { Details = details; WinMMNatives.midiOutOpen(out handle, uint.Parse(Details.Id), null, IntPtr.Zero, MidiOutOpenFlags.Null); Connection = MidiPortConnectionState.Open; }
protected SimpleVirtualMidiPort(IMidiPortDetails details, Action onDispose) { this.details = details; on_dispose = onDispose; connection = MidiPortConnectionState.Open; }
public SimpleVirtualMidiOutput(IMidiPortDetails details, Action onDispose) : base(details, onDispose) { }
public async void SetInputPort(IMidiPortDetails port) { await input.CloseAsync(); this.input = access.OpenInputAsync(port.Id).Result; }
public PortMidiInput(IMidiPortDetails portDetails) : base(portDetails) { }
public WinMMMidiInput(IMidiPortDetails details) { Details = details; WinMMNatives.midiInOpen(out handle, uint.Parse(Details.Id), HandleMidiInProc, IntPtr.Zero, MidiInOpenFlags.Function); Connection = MidiPortConnectionState.Open; }