private void PlayPlayer() { // spin wait until stopped, if pending a stop while (isStopping) { Thread.Sleep(100); } if (currentplayer == null) { var music = getMusic(); if (music != null) { outputDevice = getDevice(); currentplayer = new MidiPlayer(music, outputDevice); jukebox.Current.TotalTime = currentplayer.GetTotalPlayTimeMilliseconds(); jukebox.Current.CurrentTime = TimeSpan.FromMilliseconds(0); jukebox.Current.RemainingTime = TimeSpan.FromMilliseconds(jukebox.Current.TotalTime); currentplayer.PlaybackCompletedToEnd += player_Finished; currentplayer.EventReceived += player_EventReceived; currentplayer.Play(); jukebox.Current.State = States.Playing; } else { // found a missing/bad file; so signal move ahead signal_next(); } } }
static MidiOrchestrator() { IMidiAccess access = new PortMidiAccess(); IMidiPortDetails mout = access.Outputs.ElementAt(1); output = access.OpenOutputAsync(mout).Result; }
/// <summary> /// Opens a new midi device from a device name and *should* automatically close the previous connection /// </summary> /// <param name="deviceInput">Midi input device name</param> /// <param name="deviceOutput">Midi output device name</param> public void OpenMidiDevice(string deviceInput, string 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).Result; midiInput = access.OpenInputAsync(deviceInput).Result; midiInput.MessageReceived += MidiInput_MessageReceived; } catch (Exception e) { Console.WriteLine(e); } }
public MainWindow() { InitializeComponent(); access = MidiAccessManager.Default; output = access.OpenOutputAsync(access.Outputs.Last().Id).Result; this.KeyDown += new KeyEventHandler(OnButtonKeyDown); }
public async void SetOutputPort(IMidiPortDetails port) { await output.CloseAsync(); // output.Dispose(); this.output = await access.OpenOutputAsync(port.Id); }
public App() { IMidiAccess access = new PortMidiAccess(); IMidiPortDetails mout = access.Outputs.ElementAt(1); output = access.OpenOutputAsync(mout).Result; }
public PushPad(IMidiInput pushIn, IMidiOutput pushOut, IMidiOutput virtualOutput, PushControl pushControl) { PushControl = pushControl; PushIn = pushIn; PushOut = pushOut; VirtualOut = virtualOutput; PushIn.MessageReceived += OnMidiData; }
public IMidiOutput GetMidiOutput(Context context) { if (acc == null) { SetupMidiAccess (context); output = acc.OpenOutputAsync (acc.Outputs.First ().Id).Result; } return output; }
private RawMidiClient(IMidiInput input, string inputName, IMidiOutput output, string outputName, Action <RawMidiMessage> messageHandler) { this.input = input; InputName = inputName; this.output = output; OutputName = outputName; input.MessageReceived += (sender, args) => messageHandler(ConvertMessage(args)); }
public Player(int midiDevice, Song song) { var access = MidiAccessManager.Default; midiOut = access.OpenOutputAsync(access.Outputs.ToList()[midiDevice].Id).Result; buffer = new Buffer(); this.song = song; }
public IMidiOutput GetMidiOutput(Context context) { if (acc == null) { SetupMidiAccess(context); output = acc.OpenOutputAsync(acc.Outputs.First().Id).Result; } return(output); }
public PushEncoder(IMidiInput pushIn, IMidiOutput pushOut, IMidiOutput virtualOut, PushControl pushControl, int mapToCC, MidiValueStore store) { PushControl = pushControl; PushIn = pushIn; PushOut = pushOut; VirtualOut = virtualOut; PushIn.MessageReceived += OnMidiData; MappedToCC = mapToCC; Store = store; }
internal RolandMidiClient(IMidiInput input, IMidiOutput output, string inputName, string outputName, byte rawDeviceId, ModuleIdentifier identifier) { this.input = input; this.output = output; input.MessageReceived += HandleMessage; InputName = inputName; OutputName = outputName; this.rawDeviceId = rawDeviceId; this.Identifier = identifier; }
public MidiCommunicationChannel(IMidiInput input, IMidiOutput output) { Input = input; Output = output; InputPortDetails = new MidiPortDetails(input.Details); OutputPortDetails = new MidiPortDetails(output.Details); Input.MessageReceived += Input_MessageReceived; }
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); } }
public MidiPlayer(MidiMusic music, IMidiOutput output, IMidiTimeManager timeManager) { if (music == null) { throw new ArgumentNullException("music"); } if (output == null) { throw new ArgumentNullException("output"); } if (timeManager == null) { throw new ArgumentNullException("timeManager"); } this.output = output; player = new MidiSyncPlayer(music, timeManager); EventReceived += (m) => { switch (m.EventType) { case MidiEvent.NoteOn: case MidiEvent.NoteOff: if (channel_mask != null && channel_mask [m.Channel]) { return; // ignore messages for the masked channel. } goto default; case MidiEvent.SysEx1: case MidiEvent.SysEx2: if (buffer.Length <= m.Data.Length) { buffer = new byte [buffer.Length * 2]; } buffer [0] = m.StatusByte; Array.Copy(m.Data, 0, buffer, 1, m.Data.Length); output.Send(buffer, 0, m.Data.Length + 1, 0); break; case MidiEvent.Meta: // do nothing. break; default: var size = MidiEvent.FixedDataSize(m.StatusByte); buffer [0] = m.StatusByte; buffer [1] = m.Msb; buffer [2] = m.Lsb; output.Send(buffer, 0, size + 1, 0); break; } }; }
public LaunchPadManager(IMidiAccess access, IMidiInput input, IMidiOutput output) { if (input == null || output == null) { throw new ArgumentException("Please choose the connected Launchpad S before going further"); } this.access = access; this.input = input; this.output = output; StartListener(); }
public ManagedMidiMidiOut(int deviceIndex) { var api = MidiAccessManager.Default; #if DEBUG int i = 0; foreach (var o in api.Outputs) { Console.WriteLine("{0,2}. {1}, version: {2}, id: {3}", i++, o.Name, o.Version, o.Id); } #endif var output = api.Outputs.Skip(deviceIndex).FirstOrDefault(); _device = api.OpenOutputAsync(output.Id).Result; }
private void ConfirmButtonPressed(object sender, RoutedEventArgs e) { input = access.OpenInputAsync(LaunchPadInputs.SelectedValue.ToString()).Result; output = access.OpenOutputAsync(LaunchPadOutputs.SelectedValue.ToString()).Result; try { lpmngr = new LaunchPadManager(access, input, output); InitMacroGrid(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "LaunchPad Macros", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
public MidiPlayer(SmfMusic music, IMidiOutput output, IMidiTimeManager timeManager) { if (music == null) { throw new ArgumentNullException("music"); } if (output == null) { throw new ArgumentNullException("output"); } if (timeManager == null) { throw new ArgumentNullException("timeManager"); } this.output = output; player = new MidiSyncPlayer(music, timeManager); EventReceived += (m) => { switch (m.EventType) { case SmfEvent.SysEx1: case SmfEvent.SysEx2: if (buffer.Length <= m.Data.Length) { buffer = new byte [buffer.Length * 2]; } buffer [0] = m.StatusByte; Array.Copy(m.Data, 0, buffer, 1, m.Data.Length); output.SendAsync(buffer, 0, m.Data.Length + 1, 0); break; case SmfEvent.Meta: // do nothing. break; default: var size = SmfEvent.FixedDataSize(m.StatusByte); buffer [0] = m.StatusByte; buffer [1] = m.Msb; buffer [2] = m.Lsb; output.SendAsync(buffer, 0, size + 1, 0); break; } }; }
public void Tick(IMidiOutput midiOut, float delta) { if (buffer.Count == 0) { return; } for (int i = buffer.Count - 1; i >= 0; i--) { var note = buffer[i]; note.delay -= delta; if (note.delay <= 0) { var drum = TryGetAlternateDrum(note.drum); midiOut.Send(new byte[] { 0x99, (byte)drum, (byte)note.velocity }, 0, 3, 0); buffer.RemoveAt(i); } } }
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 Setup() { var access = MidiAccessManager.Default; _midiOutput = access.OpenOutputAsync(access.Outputs.Last().Id).Result; // Console.WriteLine("NAME {0}", access.Outputs.Last().Name); // _midiOutput.Send(new byte[] { MidiEvent.Program, 0x00 }, 0, 2, 0); // Strings Ensemble // // //output.Send(new byte[] { 0xC0, 0x0 }, 0, 2, 0); // Piano // _midiOutput.Send(new byte[] { MidiEvent.NoteOn, 0x40, 0x70 }, 0, 3, 0); // There are constant fields for each MIDI event // _midiOutput.Send(new byte[] { MidiEvent.NoteOff, 0x40, 0x70 }, 0, 3, 1000); // // _midiOutput.Send(new byte[] { MidiEvent.Program, 0x01 }, 0, 2, 0); // Strings Ensemble // // //output.Send(new byte[] { 0xC0, 0x0 }, 0, 2, 0); // Piano // _midiOutput.Send(new byte[] { MidiEvent.NoteOn, 0x47, 0x70 }, 0, 3, 0); // There are constant fields for each MIDI event // _midiOutput.Send(new byte[] { MidiEvent.NoteOff, 0x47, 0x70 }, 0, 3, 1000); // //output.Send(new byte[] { 0x90, 0x40, 0x70 }, 0, 3, 0); // //output.Send(new byte[] { 0x80, 0x40, 0x70 }, 0, 3, 0); // _midiOutput.CloseAsync(); }
public APCIntance(IMidiOutput output, IMidiInput input) { outdevice = output; indevice = input; indevice.MessageReceived += Message_Received; for (int row = 0; row < 64; row++) { Seq64.Add(row, false); Clips.Add(row, false); } for (int row = 0; row < 8; row++) { Seq8a.Add(row, new Dictionary <int, bool>()); Seq8b.Add(row, new Dictionary <int, bool>()); Chords.Add(row, new List <int>()); for (int col = 0; col < 8; col++) { Seq8a[row].Add(col, false); Seq8b[row].Add(col, false); } } DrawPage(true); }
private void StopPlayer() { if (currentplayer == null) { return; } if (isStopping) { // spin wait until stopped while (isStopping) { Thread.Sleep(100); } } else { isStopping = true; currentplayer.Stop(); // spin wait until stopped while (currentplayer.State != PlayerState.Stopped) { Thread.Sleep(100); } currentplayer.EventReceived -= player_EventReceived; currentplayer.PlaybackCompletedToEnd -= player_Finished; jukebox.Current.Progress = 0d; jukebox.Current.CurrentTime = TimeSpan.FromMilliseconds(0); jukebox.Current.RemainingTime = TimeSpan.FromMilliseconds(jukebox.Current.TotalTime); jukebox.Current.State = States.Stopped; currentplayer.Dispose(); outputDevice.Dispose(); outputDevice = null; currentplayer = null; isStopping = false; } }
public MidiPlayer(SmfMusic music, IMidiOutput output) : this(music, output, new SimpleMidiTimeManager ()) { }
static void Main(string[] args) { //MIDIEngine.ListInputs(); //MIDIEngine.ListOutputs(); PushIn = MIDIEngine.UseInput("Ableton Push 2"); if (PushIn == null) { Console.WriteLine("\nCouldn't find an ableton Push 2 midi input, make sure it's plugged in and switched on"); return; } PushOut = MIDIEngine.UseOutput("Ableton Push 2"); if (PushOut == null) { Console.WriteLine("\nCouldn't find an Ableton Push 2 midi output make sure it's plugged in and switched on"); return; } VirtualOut = MIDIEngine.UseOutput("Push2Standalone"); if (VirtualOut == null) { Console.WriteLine( "Couldn't find a Virtual midi device.\n" + "Install a virtual midi device (https://www.tobias-erichsen.de/software/loopmidi.html)\n" + "and then create a virtual device named \"Push2Standalone\"" ); return; } Console.WriteLine("USING INPUT: " + PushIn.Details.Name); Console.WriteLine("USING OUTPUT: " + VirtualOut.Details.Name); var store = new MidiValueStore(); Enc1 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder1, 1, store); Enc2 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder2, 2, store); Enc3 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder3, 3, store); Enc4 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder4, 4, store); Enc5 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder5, 5, store); Enc6 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder6, 6, store); Enc7 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder7, 7, store); Enc8 = new PushEncoder(PushIn, PushOut, VirtualOut, PushControl.Encoder8, 8, store); Pad11 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad11); Pad12 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad12); Pad13 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad13); Pad14 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad14); Pad15 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad15); Pad16 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad16); Pad17 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad17); Pad18 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad18); Pad21 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad21); Pad22 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad22); Pad23 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad23); Pad24 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad24); Pad25 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad25); Pad26 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad26); Pad27 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad27); Pad28 = new PushPad(PushIn, PushOut, VirtualOut, PushControl.Pad28); PadGroup CCSelectGroup = new PadGroup(122); CCSelectGroup.Add(Pad11); CCSelectGroup.Add(Pad12); CCSelectGroup.Add(Pad13); CCSelectGroup.Add(Pad14); CCSelectGroup.Add(Pad15); CCSelectGroup.Add(Pad16); CCSelectGroup.Add(Pad17); CCSelectGroup.Add(Pad18); CCSelectGroup.Add(Pad21); CCSelectGroup.Add(Pad22); CCSelectGroup.Add(Pad23); CCSelectGroup.Add(Pad24); CCSelectGroup.Add(Pad25); CCSelectGroup.Add(Pad26); CCSelectGroup.Add(Pad27); CCSelectGroup.Add(Pad28); var CCBank1 = Enumerable.Range(0, 8).ToArray(); var CCBank2 = Enumerable.Range(8, 16).ToArray(); var CCBank3 = Enumerable.Range(16, 24).ToArray(); var CCBank4 = Enumerable.Range(24, 32).ToArray(); var CCBank5 = Enumerable.Range(32, 40).ToArray(); var CCBank6 = Enumerable.Range(40, 48).ToArray(); var CCBank7 = Enumerable.Range(48, 56).ToArray(); var CCBank8 = Enumerable.Range(56, 64).ToArray(); var CCBank9 = Enumerable.Range(64, 72).ToArray(); var CCBank10 = Enumerable.Range(72, 80).ToArray(); var CCBank11 = Enumerable.Range(80, 88).ToArray(); var CCBank12 = Enumerable.Range(88, 96).ToArray(); var CCBank13 = Enumerable.Range(96, 104).ToArray(); var CCBank14 = Enumerable.Range(104, 112).ToArray(); var CCBank15 = Enumerable.Range(112, 120).ToArray(); var CCBank16 = Enumerable.Range(120, 127).ToArray(); EncoderGroup Encoders = new EncoderGroup(); Encoders.Add(Enc1); Encoders.Add(Enc2); Encoders.Add(Enc3); Encoders.Add(Enc4); Encoders.Add(Enc5); Encoders.Add(Enc6); Encoders.Add(Enc7); Encoders.Add(Enc8); Pad11.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad11.SetColor(4); Encoders.MapTo(CCBank1); }; Pad12.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad12.SetColor(4); Encoders.MapTo(CCBank2); }; Pad13.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad13.SetColor(4); Encoders.MapTo(CCBank3); }; Pad14.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad14.SetColor(4); Encoders.MapTo(CCBank4); }; Pad15.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad15.SetColor(4); Encoders.MapTo(CCBank5); }; Pad16.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad16.SetColor(4); Encoders.MapTo(CCBank6); }; Pad17.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad17.SetColor(4); Encoders.MapTo(CCBank7); }; Pad18.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad18.SetColor(4); Encoders.MapTo(CCBank8); }; Pad21.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad21.SetColor(4); Encoders.MapTo(CCBank9); }; Pad22.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad22.SetColor(4); Encoders.MapTo(CCBank10); }; Pad23.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad23.SetColor(4); Encoders.MapTo(CCBank11); }; Pad24.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad24.SetColor(4); Encoders.MapTo(CCBank12); }; Pad25.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad25.SetColor(4); Encoders.MapTo(CCBank13); }; Pad26.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad26.SetColor(4); Encoders.MapTo(CCBank14); }; Pad27.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad27.SetColor(4); Encoders.MapTo(CCBank15); }; Pad28.OnNoteOn += (data) => { CCSelectGroup.SetColor(122); Pad28.SetColor(4); Encoders.MapTo(CCBank16); }; Console.WriteLine("\nActive. Press escape to leave..."); while (true) { var key = Console.ReadKey().Key; if (key == ConsoleKey.Escape) { break; } ; } // Turn off lights CCSelectGroup.SetColor(0); // Clean up PushIn.Dispose(); PushOut.Dispose(); VirtualOut.Dispose(); }
public RawMidiProcessor(IMidiOutput output) { this.output = output; }
//A client to read MIDI inputs, send them to a light server, and (optionally) forwards them to an output MIDI device static void Main(string[] args) { Console.WriteLine("MIDI Message splitter client"); var testmode = false; var remapNotes = true; //remap MIDI notes here (src,target) Dictionary <int, int> noteMapping = new Dictionary <int, int> { { 39, 38 }, //Snare Rim -> Snare { 28, 26 }, //Lcymbal -> Hihat { 52, 51 }, //Ride bell -> Ride { 53, 51 }, //Mcymbal -> Ride { 59, 49 }, //xLCymbal -> RCymbal }; string targetAddress = "127.0.0.1"; int targetPort = 5005; if (args.Length > 0) { if (args[0] != null) { targetAddress = args[0]; } if (args[1] != null) { int.TryParse(args[1], out targetPort); } } TcpClient client = new TcpClient(targetAddress, targetPort); NetworkStream stream = client.GetStream(); try { if (testmode) { while (true) { var inputstr = Console.ReadLine(); TransmitMessage(inputstr, stream); Console.WriteLine($"Sent message {inputstr}"); } } var access = MidiAccessManager.Default; IMidiInput input = null; IMidiOutput output = null; string chosenIdIn = ""; string chosenIdOut = ""; foreach (IMidiPortDetails portdetails in access.Inputs) { Console.WriteLine($"Input: {portdetails.Name} / ID: {portdetails.Id}"); } if (access.Inputs.Count() <= 0) { throw new InvalidOperationException("No input devices detected!"); } else if (access.Inputs.Count() == 1) { //Default chosenIdIn = access.Inputs.First().Id; Console.WriteLine("Using default input..."); } else { //Choose from list Console.WriteLine("Enter input device ID to use:"); chosenIdIn = Console.ReadLine(); } input = access.OpenInputAsync(chosenIdIn).Result; if (access.Outputs.Count() > 0) { foreach (IMidiPortDetails portdetails in access.Outputs) { Console.WriteLine($"Output: {portdetails.Name} / ID: {portdetails.Id}"); } Console.WriteLine("Enter output device ID to use:"); chosenIdOut = Console.ReadLine(); } try { output = access.OpenOutputAsync(chosenIdOut).Result; } catch { Console.WriteLine("Couldn't open output device, ignoring..."); } Console.WriteLine("Reading events..."); input.MessageReceived += (object sender, MidiReceivedEventArgs e) => { string[] outputs = new string[5] { "0", "0", "0", "0", "0" }; for (int i = 0; i < e.Length; i++) { outputs[i] = e.Data[i].ToString(); } outputs[4] = e.Timestamp.ToString(); TransmitMessage($"{outputs[0]},{outputs[1]},{outputs[2]},{outputs[3]},{outputs[4]},", stream); Console.WriteLine($"{outputs[0]},{outputs[1]},{outputs[2]},{outputs[3]},{outputs[4]}"); if (output != null) { if (remapNotes) { int noteNumberIn = e.Data[1]; byte noteNumberOut = 0; if (noteMapping.ContainsKey(noteNumberIn)) { Console.WriteLine($"Remapping note {noteNumberIn} to {noteMapping[noteNumberIn]}"); noteNumberOut = (byte)noteMapping[noteNumberIn]; e.Data[1] = noteNumberOut; } } output.Send(e.Data, 0, e.Data.Length, e.Timestamp); } }; Console.ReadKey(); } finally { TransmitMessage("disconnect", stream); stream.Close(); client.Close(); } }
public MidiPlayer(SmfMusic music, IMidiOutput output, IMidiTimeManager timeManager) { if (music == null) throw new ArgumentNullException ("music"); if (output == null) throw new ArgumentNullException ("output"); if (timeManager == null) throw new ArgumentNullException ("timeManager"); this.output = output; player = new MidiSyncPlayer (music, timeManager); EventReceived += (m) => { switch (m.EventType) { case SmfEvent.SysEx1: case SmfEvent.SysEx2: if (buffer.Length <= m.Data.Length) buffer = new byte [buffer.Length * 2]; buffer [0] = m.StatusByte; Array.Copy (m.Data, 0, buffer, 1, m.Data.Length); output.SendAsync (buffer, 0, m.Data.Length + 1, 0); break; case SmfEvent.Meta: // do nothing. break; default: var size = SmfEvent.FixedDataSize (m.StatusByte); buffer [0] = m.StatusByte; buffer [1] = m.Msb; buffer [2] = m.Lsb; output.SendAsync (buffer, 0, size + 1, 0); break; } }; }
public MidiPlayer(MidiMusic music, IMidiOutput output) : this(music, output, new SimpleAdjustingMidiPlayerTimeManager()) { }
public MidiPlayer(MidiMusic music, IMidiOutput output, IMidiPlayerTimeManager timeManager) { if (music == null) { throw new ArgumentNullException("music"); } if (output == null) { throw new ArgumentNullException("output"); } if (timeManager == null) { throw new ArgumentNullException("timeManager"); } this.music = music; this.output = output; messages = SmfTrackMerger.Merge(music).Tracks [0].Messages; player = new MidiEventLooper(messages, timeManager, music.DeltaTimeSpec); player.Starting += () => { // all control reset on all channels. for (int i = 0; i < 16; i++) { buffer [0] = (byte)(i + 0xB0); buffer [1] = 0x79; buffer [2] = 0; output.Send(buffer, 0, 3, 0); } }; EventReceived += (m) => { switch (m.EventType) { case MidiEvent.NoteOn: case MidiEvent.NoteOff: if (channel_mask != null && channel_mask [m.Channel]) { return; // ignore messages for the masked channel. } goto default; case MidiEvent.SysEx1: case MidiEvent.SysEx2: if (buffer.Length <= m.Data.Length) { buffer = new byte [buffer.Length * 2]; } buffer [0] = m.StatusByte; Array.Copy(m.Data, 0, buffer, 1, m.Data.Length); output.Send(buffer, 0, m.Data.Length + 1, 0); break; case MidiEvent.Meta: // do nothing. break; default: var size = MidiEvent.FixedDataSize(m.StatusByte); buffer [0] = m.StatusByte; buffer [1] = m.Msb; buffer [2] = m.Lsb; output.Send(buffer, 0, size + 1, 0); break; } }; }
public Player() { this.access = (IMidiAccess2)MidiAccessManager.Default; this.output = access.OpenOutputAsync(access.Outputs.Last().Id).Result; }