Exemplo n.º 1
0
        public void InterruptInput()
        {
            bool          passed = false, aborted = false;
            var           evt       = new AlsaSequencerEvent();
            AlsaSequencer seq       = null;
            int           appPort   = -1;
            var           waitStart = new ManualResetEvent(false);

            using (seq = new AlsaSequencer(AlsaIOType.Input, AlsaIOMode.None)) {
                appPort = seq.CreateSimplePort("alsa-sharp-test-input", AlsaPortCapabilities.Write | AlsaPortCapabilities.NoExport, AlsaPortType.Application | AlsaPortType.MidiGeneric);
                var cinfo = new AlsaClientInfo {
                    Client = -1
                };
                int client = -1;
                while (seq.QueryNextClient(cinfo))
                {
                    if (cinfo.Name.Contains("Midi Through"))
                    {
                        client = cinfo.Client;
                    }
                }
                if (client < 0)
                {
                    Console.Error.WriteLine("Midi Through not found. Not testable.");
                    return;                     // not testable
                }
                seq.ConnectFrom(appPort, client, 0);
                try {
                    seq.ResetPoolInput();
                    var task = Task.Run(() => {
                        waitStart.Set();
                        try {
                            seq.Input(evt, appPort);
                            passed = true;
                        } catch (Exception ex) {
                            passed  = false;
                            aborted = true;
                            Console.Error.WriteLine("Input threw an error: " + ex);
                        }
                    });
                    waitStart.WaitOne();
                    // it will cause ALSA error as it's waiting for input in blocking mode.
                    seq.DisconnectFrom(appPort, client, 0);
                    task.Wait(50);
                    Assert.IsFalse(passed, "input should keep listening");
                    seq.DeleteSimplePort(appPort);
                    task.Wait(50);
                    seq.Dispose();
                    seq = null;
                    task.Wait(50);
                } finally {
                    if (seq != null)
                    {
                        seq.Dispose();
                    }
                }
                // It doesn't even run exception part...
                Assert.IsFalse(aborted, "We expect it not to abort...");
            }
        }
Exemplo n.º 2
0
 public static void Stop()
 {
     if (!isRunning)
     {
         return;
     }
     sequencer.Dispose();
     sequencer = null;
     isRunning = false;
 }