コード例 #1
0
        public void TestSoftwareBus()
        {
            using (var cs = new Csound6NetRealtime())
            {
                var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
                Assert.AreEqual(CsoundStatus.Success, result);

                var bus = cs.GetSoftwareBus();
                Assert.IsNotNull(bus);
                Assert.IsTrue(bus.Count > 0);
                Assert.AreEqual(8, bus.Count);
                foreach (var channel in bus.Channels)
                {
                    switch (channel.Type)
                    {
                    case ChannelType.Control:
                        Assert.IsTrue(channel.Name.StartsWith("chan"));
                        Assert.IsInstanceOfType(channel, typeof(Csound6ControlChannel));
                        Assert.IsInstanceOfType(channel.Value, typeof(double));
                        Assert.AreEqual(channel.Value, bus[channel.Name]);
                        break;

                    case ChannelType.String:
                        Assert.IsInstanceOfType(channel, typeof(Csound6StringChannel));
                        Assert.IsInstanceOfType(channel.Value, typeof(string));
                        Assert.IsTrue(channel.Name.StartsWith("schan"));
                        Assert.AreEqual(channel.Value, bus[channel.Name]);
                        break;

                    case ChannelType.Audio:
                        Assert.IsInstanceOfType(channel, typeof(Csound6AudioChannel));
                        Assert.IsTrue(channel.Name.StartsWith("achan"));
                        Assert.IsInstanceOfType(channel.Value, typeof(double[]));
                        var values = channel.Value as double[];
                        Assert.AreEqual(cs.Ksmps, values.Length);
                        break;

                    case ChannelType.Pvs:
                        Assert.Fail("PVS data type not yet supported in .net");
                        break;

                    default:
                        Assert.Fail(string.Format("Software bus has unsupported channel {0} of type: {1}", channel.Name, channel.Type));
                        break;
                    }
                }
            }
        }
コード例 #2
0
 public void TestOutInCallbacks()
 {
     m_messageText = new StringBuilder();
     m_count       = 0;
     m_outval      = -1;
     using (var cs = new Csound6NetRealtime())
     {
         cs.OutputChannelCallback += TestOutputCallback;
         cs.InputChannelCallback  += TestInputCallback;
         var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
         Assert.AreEqual(CsoundStatus.Success, result);
         if (result == CsoundStatus.Success)
         {
             while (!cs.PerformKsmps())
             {
                 ;
             }
         }
         cs.Cleanup();
     }
 }
コード例 #3
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.
         }
     }
 }
コード例 #4
0
        public void TestChannelDirectAccess()
        {
            using (var cs = new Csound6NetRealtime())
            {
                var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
                Assert.AreEqual(CsoundStatus.Success, result);
                if (result == CsoundStatus.Success)
                {
                    var bus   = cs.GetSoftwareBus();
                    var chan2 = bus.GetChannel("chan2") as Csound6ControlChannel;
                    chan2.SetValueDirect(chan2.Default);
                    double val = chan2.GetValueDirect();
                    Assert.AreEqual(chan2.Default, val);

                    while (!cs.PerformKsmps())
                    {
                        Assert.AreEqual(val, chan2.GetValueDirect());
                        chan2.SetValueDirect(++val);
                    }
                }
            }
        }
コード例 #5
0
 public void TestPerfTimeChannels()
 {
     m_messageText = new StringBuilder();
     m_count       = 0;
     m_outval      = -1;
     using (var cs = new Csound6NetRealtime())
     {
         var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
         Assert.AreEqual(CsoundStatus.Success, result);
         if (result == CsoundStatus.Success)
         {
             var bus = cs.GetSoftwareBus();
             while (!cs.PerformKsmps())
             {
                 double[] samps   = bus["achan1"] as double[];
                 double[] sampInv = new double[samps.Length];
                 if (cs.ScoreTime <= 0.1)
                 {
                     foreach (double samp in samps)
                     {
                         Assert.IsTrue(samp == 0.0);
                     }
                     bool hasPvs = bus.HasChannel("0");
                     if (hasPvs)
                     {
                         object o = bus["0"];
                     }
                 }
                 else if (cs.ScoreTime == 0.2)
                 {
                     double prev = -1.0;
                     for (int i = 0; i < 26; i++)
                     {
                         Assert.IsTrue(samps[i] > prev);
                         prev = samps[i];
                     }
                     for (int i = 26; i < 75; i++)
                     {
                         Assert.IsTrue(prev > samps[i]);
                         prev = samps[i];
                     }
                     for (int i = 0; i < sampInv.Length; i++)
                     {
                         sampInv[i] = -samps[i];
                     }
                     bus["achan2"] = sampInv;
                 }
                 else if (cs.ScoreTime == 0.3)
                 {
                     double[] samp2 = bus["achan2"] as double[];
                     double[] samp3 = bus["achan3"] as double[]; //instrument will have put samp2 into achan3 during 0.2 second; now available in 0.3 sec
                     for (int i = 0; i < samp3.Length; i++)
                     {
                         Assert.AreEqual(samp2[i], samp3[i]);
                     }
                 }
             }
         }
         cs.Cleanup();
     }
 }