/// <summary> /// Opens a new midi device and *should* automatically close the previous connection /// </summary> /// <param name="deviceInput">Midi input device ID</param> /// <param name="deviceOutput">Midi output device ID</param> public void OpenMidiDevice(IMidiPortDetails deviceInput, IMidiPortDetails deviceOutput) { if (midiOutput != null) { midiOutput.CloseAsync();//Will this wait for the port to be closed or does it really matter? } if (midiInput != null) { midiInput.MessageReceived -= MidiInput_MessageReceived; midiInput.CloseAsync();//Will this wait for the port to be closed or does it really matter? } var access = MidiAccessManager.Default; try { midiOutput = access.OpenOutputAsync(deviceOutput.Id).Result; midiInput = access.OpenInputAsync(deviceInput.Id).Result; midiInput.MessageReceived += MidiInput_MessageReceived; } catch (Exception e) { Console.WriteLine(e); } }
public async void SetOutputPort(IMidiPortDetails port) { await output.CloseAsync(); // output.Dispose(); this.output = await access.OpenOutputAsync(port.Id); }
public void Dispose() { // Calling CloseAsync is significantly faster than calling Dispose. // This is slightly odd, as the implementation for desktop seems to call // CloseAsync too. Not sure what's going on, and maybe we should be waiting // the task to complete... but it doesn't seem to cause any harm. input.CloseAsync(); output.CloseAsync(); }
public void UpdateSelectedInstrument(SoundFontSelection item) { if (skip_loading) { return; } var prevItem = SelectedSoundItem; SelectedSoundItem = item; if (output != null && item.File != prevItem.File) { output.CloseAsync(); keyon_flags = new bool [128]; } if (prevItem?.File != item.File) { access = new FluidsynthMidiAccess(); if (File.Exists("/dev/snd/seq")) // ALSA { access.ConfigureSettings = s => s [NFluidsynth.ConfigurationKeys.AudioDriver].StringValue = "alsa"; } access.SoundFonts.Add(item.File); output = access.OpenOutputAsync(access.Outputs.First().Id).Result; } int ch = item.Bank >= 128 ? 9 : 0; /* * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.BankSelect, (byte) (item.Bank / 0x80)}, 0, 3, 0); * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.BankSelectLsb, (byte) (item.Bank % 0x80)}, 0, 3, 0); * output.Send (new byte[] {(byte) (MidiEvent.Program + ch), (byte) (item.Instrument % 128)}, 0, 2, 0); * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.Volume, 120}, 0, 3, 0); */ output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.BankSelect, (byte)(item.Bank / 0x80) }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.BankSelectLsb, (byte)(item.Bank % 0x80) }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.Program + ch), (byte)(item.Patch % 128) }, 0, 2, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.Volume, 127 }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.Expression, 127 }, 0, 3, 0); }
public void Dispose() { // FIXME input.CloseAsync(); output.CloseAsync(); }
public async void Close() => await MidiOutput.CloseAsync();