Exemplo n.º 1
0
        public void TestChannelDefinition()
        {
            m_messageText = new StringBuilder();
            m_count       = 0;
            using (var cs = new Csound6NetRealtime())
            {
                cs.MessageCallback += TestMessageEvent;
                FileInfo     csf    = new FileInfo("csdFiles\\SimpleRuntime.csd");
                CsoundStatus result = cs.CompileArgs(new string[] { csf.FullName });
                Assert.AreEqual(CsoundStatus.Success, result);
                result = cs.Start();
                Assert.AreEqual(CsoundStatus.Success, result);
                var cch = new Csound6ControlChannel("chan1", ChannelDirection.Input, cs);
                Assert.AreEqual(ChannelDirection.Input, cch.Direction);
                Assert.AreEqual(ChannelBehavior.Exponential, cch.Behavior);
                Assert.AreEqual(ChannelType.Control, cch.Type);
                Assert.AreEqual(1000.0, cch.Default);
                Assert.AreEqual(500.0, cch.Minimum);
                Assert.AreEqual(2000.0, cch.Maximum);

                cch.Behavior = ChannelBehavior.Integer;
                cch.Maximum  = 2500.0;
                cch.Minimum  = 400.0;

                var cch1 = new Csound6ControlChannel("chan1", ChannelDirection.Input, cs);
                Assert.AreEqual(cch.Name, cch1.Name);
                Assert.AreEqual(cch.Minimum, cch1.Minimum);
                Assert.AreEqual(400.0, cch1.Minimum);
                Assert.AreEqual(2500.0, cch.Maximum);
                Assert.AreEqual(cch.Maximum, cch1.Maximum);
                Assert.AreEqual(ChannelBehavior.Integer, cch1.Behavior);

                var bus = new Csound6SoftwareBus(cs);
                IDictionary <string, ChannelInfo> chans = cs.GetChannelList();
                Assert.IsNotNull(chans);
                Assert.IsTrue(chans.Count > 0);
                foreach (string key in chans.Keys)//now in test for software bus. remove this part?
                {
                    ChannelInfo info = chans[key];
                    var         chan = bus.AddChannel(info);
                    switch (chan.Type)
                    {
                    case ChannelType.String:
                        Assert.IsInstanceOfType(chan, typeof(Csound6StringChannel));
                        Assert.AreEqual(256, chan.DataSize);
                        break;

                    case ChannelType.Audio:
                        Assert.IsInstanceOfType(chan, typeof(Csound6AudioChannel));
                        Assert.AreEqual(35280, chan.DataSize);      //ksmps = 4410 * sizeof(MYFLT)
                        break;

                    case ChannelType.Control:
                        Assert.IsInstanceOfType(chan, typeof(Csound6ControlChannel));
                        Assert.AreEqual(8, chan.DataSize);
                        if (chan.Name.Equals(cch1.Name))
                        {
                            Assert.AreEqual(cch.Maximum, ((Csound6ControlChannel)chan).Maximum);
                            Assert.AreEqual(cch.Minimum, ((Csound6ControlChannel)chan).Minimum);
                            Assert.AreEqual(cch.Default, ((Csound6ControlChannel)chan).Default);
                        }
                        break;

                    case ChannelType.Pvs:
                    case ChannelType.Var:
                    default:
                        Assert.IsFalse(false, string.Format("Unsupported Channel type:{0}", chan.GetType()));
                        break;
                    } //end switch
                }     //end foreach key
            }         //end using csound
            string text = m_messageText.ToString(); //if need to analyze output...
        }