Ejemplo n.º 1
0
 public void TestPerformanceThread()
 {
     using (var cs = new Csound6NetRealtime())
     {
         var result = cs.Compile(new string[] { "-odac0", "csdFiles\\xanadu.csd" });
         Assert.AreEqual(CsoundStatus.Success, result);
         m_perfTheadCalledBack = false;
         using (var pt = new Csound6PerformanceThread(cs))
         {
             pt.ProcessCallback += TestPerfThreadCallback;
             Assert.IsFalse(pt.IsRunning);//test initial state
             Assert.IsTrue(pt.IsPaused);
             Assert.IsTrue(pt.Status == CsoundStatus.Success);
             pt.Play();
             pt.SendScoreEvent(false, ScoreEventType.Note, new double[] { 3, 0, 15, 0, 5.10, 1.4, 0.8 });
             Thread.Sleep(1000);
             Assert.IsTrue(pt.IsRunning);
             Assert.IsFalse(pt.IsPaused);
             Assert.IsTrue(pt.Status == CsoundStatus.Success);
             Thread.Sleep(3000);
             pt.Pause();
             Thread.Sleep(1000);
             Assert.IsTrue(pt.IsRunning);
             Assert.IsTrue(pt.IsPaused);
             pt.SetScoreOffset(44.00);
             pt.TogglePause();
             Thread.Sleep(1000);
             pt.SendInputMessage("i3 0 20 0 5.10 1.4 0.8");
             Thread.Sleep(18000);
             Assert.IsTrue(pt.IsRunning);
             Assert.IsFalse(pt.IsPaused);
             pt.Stop();
             Thread.Sleep(1500);                                 //wait for threads do settle
             Assert.IsTrue(m_perfTheadCalledBack);               //insure that we executed the callback beyound the first ksmps
             Assert.IsFalse(pt.IsRunning);                       //flags eventually got set
             Assert.IsTrue(pt.Status == CsoundStatus.Completed); //finished all events
             Assert.IsTrue(cs.ScoreTime > 60.0);                 //last input message should extend past 60 seconds.
         }
     }
 }
Ejemplo n.º 2
0
   /**
    * Example 4 - Using Csound's Performance Thread
    * Example 4.1 - Using Csound in a C# async/await Task for threaded execution
    * 
    * In this example, we use a CsoundPerformanceThread to run Csound in 
    * a native thread.  Using a native thread is important to get the best
    * runtime performance for the audio engine.
    * CsoundPerformanceThread has some convenient methods for handling events,
    * but does not have features for doing regular processing at block boundaries.
    * In general, use CsoundPerformanceThread when the only kinds of communication you
    * are doing with Csound are through events, and not using channels.
    * 
    * Since VS2012, C# programmers have become comfortable with the async/await Task-based
    * paradigm for running background processes.
    * Example 4.1 shows an alternative to running csound in a separate thread (really Task)
    * to achieve the same result as example 4.
    * This approach is very useful in a GUI where a cancel event and a progress dialog
    * would be desireable.
    * This example bypasses these features; later examples will use them.
    */

        public void Example4()
        {
            using (var c = new Csound6NetRealtime())
            {
                c.SetOutputDac(0);      // Set realtime output for Csound
                c.CompileOrc(orc);      // Compile Orchestra from String
                c.ReadScore("i1 0 1");  // Read in Score from String

                c.Start();              // When compiling from strings, this call needed before performing

                // Create a new CsoundPerformanceThread, passing in the Csound object
                var t = new Csound6PerformanceThread(c);
                t.Play();   // starts the thread, which is now running separately from the main thread. This 
                // call is asynchronous and will immediately return back here to continue code
                // execution.
                t.Join();   // Join will wait for the other thread to complete. If we did not call Join(),
                // after t.Play() returns we would immediate move to the next line, c.Stop(). 
                // That would stop Csound without really giving it time to run. 
                c.Stop();   // stops Csound
                c.Cleanup();// clean up Csound; this is useful if you're going to reuse a Csound instance
            }
        }
Ejemplo n.º 3
0
        /**
         * Example 4 - Using Csound's Performance Thread
         * Example 4.1 - Using Csound in a C# async/await Task for threaded execution
         *
         * In this example, we use a CsoundPerformanceThread to run Csound in
         * a native thread.  Using a native thread is important to get the best
         * runtime performance for the audio engine.
         * CsoundPerformanceThread has some convenient methods for handling events,
         * but does not have features for doing regular processing at block boundaries.
         * In general, use CsoundPerformanceThread when the only kinds of communication you
         * are doing with Csound are through events, and not using channels.
         *
         * Since VS2012, C# programmers have become comfortable with the async/await Task-based
         * paradigm for running background processes.
         * Example 4.1 shows an alternative to running csound in a separate thread (really Task)
         * to achieve the same result as example 4.
         * This approach is very useful in a GUI where a cancel event and a progress dialog
         * would be desireable.
         * This example bypasses these features; later examples will use them.
         */

        public void Example4()
        {
            using (var c = new Csound6NetRealtime())
            {
                c.SetOutputDac(0);      // Set realtime output for Csound
                c.CompileOrc(orc);      // Compile Orchestra from String
                c.ReadScore("i1 0 1");  // Read in Score from String

                c.Start();              // When compiling from strings, this call needed before performing

                // Create a new CsoundPerformanceThread, passing in the Csound object
                var t = new Csound6PerformanceThread(c);
                t.Play();   // starts the thread, which is now running separately from the main thread. This
                // call is asynchronous and will immediately return back here to continue code
                // execution.
                t.Join();   // Join will wait for the other thread to complete. If we did not call Join(),
                // after t.Play() returns we would immediate move to the next line, c.Stop().
                // That would stop Csound without really giving it time to run.
                c.Stop();    // stops Csound
                c.Cleanup(); // clean up Csound; this is useful if you're going to reuse a Csound instance
            }
        }