Esempio n. 1
0
        public void TestBridge2C()
        {
            FileInfo fi        = new FileInfo("csdfiles\\xanadu.csd");
            string   shortname = BridgeToCpInvoke.wGetShortPathName(fi.FullName);

            Assert.IsFalse(string.IsNullOrWhiteSpace(shortname));
            Assert.IsFalse(shortname.Contains(" "));

            IntPtr pFile = BridgeToCpInvoke.cfopen(shortname, "r");

            Assert.AreNotEqual(IntPtr.Zero, pFile);
            StringBuilder text  = new StringBuilder();
            int           count = 0;
            string        line  = null;

            do
            {
                line = BridgeToCpInvoke.cfgets(pFile, 120);
                if (line != null)
                {
                    text.Append(line);
                    count++;
                }
            } while (line != null);
            Assert.AreNotEqual(0, count);
            string result = text.ToString();

            Assert.IsTrue(result.EndsWith("</CsoundSynthesizer>\n"));
            int done = BridgeToCpInvoke.cfclose(pFile);

            Assert.AreEqual(0, done);
        }
Esempio n. 2
0
        public void TestRuntimeProperties()
        {
            bool set = Csound6Net.SetGlobalEnv("RGHMUSIC", "Henninger");

            Assert.IsTrue(set);
            object o = new Object();

            using (Csound6Net cs = new Csound6Net(o, CsoundInitFlag.NoFlags, null))
            {
                try
                {
                    m_messageText       = new StringBuilder();
                    m_count             = 0;
                    cs.MessageCallback += TestMessageEvent;

                    m_fileopened         = false;
                    cs.FileOpenCallback += TestFileOpenEvent;

                    FileInfo     csdFile   = new FileInfo("csdFiles\\Simple.csd");
                    string       path      = csdFile.FullName;
                    string       shortpath = BridgeToCpInvoke.wGetShortPathName(csdFile.FullName); //test long strings
                    CsoundStatus result    = cs.Compile(new string[] { shortpath });
                    Assert.AreEqual(CsoundStatus.Success, result);
                    object o1 = cs.HostData; //test marshalling of host data.
                    Assert.AreEqual(o, o1);
                    cs.HostData = "abc";
                    Assert.IsTrue("abc".Equals(cs.HostData));
                    string sfdir = cs.GetEnv("SFDIR");
                    Assert.IsNotNull(sfdir);
                    Assert.IsTrue(sfdir.Length > 0);
                    string garbage = cs.GetEnv("garbage");
                    Assert.IsTrue(string.IsNullOrWhiteSpace(garbage));
                    string rgh = cs.GetEnv("RGHMUSIC");
                    Assert.AreEqual("Henninger", rgh);
                    //test for sample rate, control rate, ksamps, filename from simple.csd...
                    Assert.AreEqual(44100.0, cs.Sr);
                    Assert.AreEqual(441.0, cs.Kr);
                    Assert.AreEqual(100, cs.Ksmps);
                    Assert.AreEqual(1.0, cs.OdBFS);
                    Assert.AreEqual(1, cs.Nchnls);
                    Assert.AreNotEqual(0, m_count);
                    Assert.AreEqual("simple.wav", cs.OutputFileName);

                    //confirm that all stdout text went here: for Simple.csd, chatter ends "SECTION 1:\n"
                    string text = m_messageText.ToString();
                    Assert.IsTrue(text.EndsWith("SECTION 1:\n"));
                    Assert.IsTrue(m_fileopened); //make sure we enterred the tests in TestFileOpenEvent
                }
                catch (Exception e)
                {
                    string x = e.Message;
                    Assert.Fail(x);
                }
            }
        }
Esempio n. 3
0
        public async Task TestExternalRun()
        {
            var    fi = new FileInfo("soundFiles\\rv_mono.wav");
            string pathToSoundfile = BridgeToCpInvoke.wGetShortPathName(fi.FullName);
            var    p = new CsoundExternalProcess();

            p.ProgramName      = "sndinfo";
            p.Arguments        = new List <string>(new string[] { pathToSoundfile });
            m_count            = 0;
            m_messageText      = new StringBuilder();
            p.MessageCallback += TestMessageEvent;
            int result = await p.RunAsync(CancellationToken.None);

            Assert.AreEqual(0, result);
            Assert.IsTrue(m_count > 0);
            string text = m_messageText.ToString();

            Assert.IsTrue(text.Length > 0);
            Assert.IsTrue(text.Contains("srate 44100, monaural, 16 bit WAV"));

            using (var cs = new Csound6Net())
            {
                int count1 = m_count;
                m_count       = 0;
                m_messageText = new StringBuilder();
                long done = await cs.RunCommandAsync(new string[] { "sndinfo", pathToSoundfile }, TestMessageEvent, CancellationToken.None);

                string text2 = m_messageText.ToString();
                Assert.AreEqual(0L, done);
                Assert.AreEqual(count1, m_count);
                Assert.AreEqual(text.Substring(0, 150), text2.Substring(0, 150));//1st 150 chars should be the same - no variable statistics.

                int count2 = m_count;
                m_count       = 0;
                m_messageText = new StringBuilder();
                var sndinfo = cs.GetUtility(Csound6Utility.SHOW_SOUNDFILE_METADATA);
                sndinfo.InputFile = new FileInfo(pathToSoundfile);
                int done2 = await sndinfo.RunAsync(TestMessageEvent, CancellationToken.None);

                Assert.AreEqual(0, done2);
                Assert.IsTrue(count2 >= m_count);//sometimes 13, sometimes 14 - leading crlf
                string text3 = m_messageText.ToString();
                Assert.AreEqual(text.Substring(0, 150), text3.Substring(0, 150));
            }
        }