public void Send() { using (var seq = new AlsaSequencer(AlsaIOType.Output, AlsaIOMode.NonBlocking)) { var cinfo = new AlsaClientInfo { Client = -1 }; int lastClient = -1; while (seq.QueryNextClient(cinfo)) { if (cinfo.Name.Contains("TiMidity")) { lastClient = cinfo.Client; } } if (lastClient < 0) { Console.Error.WriteLine("TiMidity not found. Not testable."); return; // not testable } int targetPort = 3; try { seq.GetPort(lastClient, targetPort); } catch { Console.Error.WriteLine("TiMidity port #3 not available. Not testable."); return; // not testable } int appPort = seq.CreateSimplePort("alsa-sharp-test-output", AlsaPortCapabilities.Write | AlsaPortCapabilities.NoExport, AlsaPortType.Application | AlsaPortType.MidiGeneric); try { seq.ConnectTo(appPort, lastClient, targetPort); var setup = new byte [] { 0xC0, 0x48, 0xB0, 7, 110, 0xB0, 11, 127 }; var keyon = new byte [] { 0x90, 0x40, 0x70 }; var keyoff = new byte [] { 0x80, 0x40, 0x70 }; seq.Send(appPort, setup, 0, setup.Length); seq.Send(appPort, keyon, 0, keyon.Length); System.Threading.Thread.Sleep(100); seq.Send(appPort, keyoff, 0, keyoff.Length); System.Threading.Thread.Sleep(100); seq.DisconnectTo(appPort, lastClient, targetPort); } finally { seq.DeleteSimplePort(appPort); } } }
public void InputToObserveSystemAnnoucements() { bool passed = false; var evt = new AlsaSequencerEvent(); AlsaSequencer inseq = null; int appPort = -1; Task task = new TaskFactory().StartNew(() => { using (inseq = new AlsaSequencer(AlsaIOType.Input, AlsaIOMode.None)) { appPort = inseq.CreateSimplePort("alsa-sharp-test-input", AlsaPortCapabilities.Write | AlsaPortCapabilities.NoExport, AlsaPortType.Application | AlsaPortType.MidiGeneric); inseq.ConnectFrom(appPort, AlsaSequencer.ClientSystem, AlsaPortInfo.PortSystemAnnouncement); try { inseq.ResetPoolInput(); // ClientStart, PortStart, PortSubscribed, PortUnsubscribed, PortExit inseq.Input(evt, appPort); Assert.AreEqual(AlsaSequencerEventType.ClientStart, evt.EventType, "evt1"); inseq.Input(evt, appPort); Assert.AreEqual(AlsaSequencerEventType.PortStart, evt.EventType, "evt2"); inseq.Input(evt, appPort); Assert.AreEqual(AlsaSequencerEventType.PortSubscribed, evt.EventType, "evt3"); passed = true; } finally { inseq.DisconnectFrom(appPort, AlsaSequencer.ClientSystem, AlsaPortInfo.PortSystemAnnouncement); appPort = -1; } } }); Thread.Sleep(50); // give some time for announcement client to start. // create another port, which is a dummy and just subscribes to notify the system to raise an announcement event. var cinfo = new AlsaClientInfo { Client = -1 }; int lastClient = -1; var outseq = new AlsaSequencer(AlsaIOType.Input, AlsaIOMode.NonBlocking); while (outseq.QueryNextClient(cinfo)) { if (cinfo.Name.Contains("Midi Through")) { lastClient = cinfo.Client; } } if (lastClient < 0) { Console.Error.WriteLine("Midi Through not found. Not testable."); return; // not testable } int targetPort = 0; int testPort = outseq.CreateSimplePort("alsa-sharp-test-output", AlsaPortCapabilities.Write | AlsaPortCapabilities.NoExport, AlsaPortType.Application | AlsaPortType.MidiGeneric); try { outseq.ConnectTo(testPort, lastClient, targetPort); outseq.DisconnectTo(testPort, lastClient, targetPort); Thread.Sleep(50); // give some time for announcement client to finish. Assert.IsTrue(passed, "failed to receive an announcement"); } finally { outseq.DeleteSimplePort(testPort); } }