forked from csound/csoundAPI_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsoundMessageBuffer.cpp
More file actions
65 lines (52 loc) · 1.31 KB
/
CsoundMessageBuffer.cpp
File metadata and controls
65 lines (52 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* CsoundMessageBuffer example. Running any Csound API example from
the command line will output Csound messages, but the CsoundMessageBuffer
can be used by host application with GUIs. In this example, all messages
from the MessageBuffer that are printed to the stdout will be preceded
by CSOUND_MESSAGE: */
#include <stdio.h>
#include "csound.hpp"
#include <string>
#include <iostream>
using namespace std;
int main()
{
//Create an instance of Csound
Csound* csound = new Csound();
string csdText = "<CsoundSynthesizer>\n"
"<CsOptions>\n"
"csound -+rtaudio=jack -odac -B4096\n"
"</CsOptions>\n"
"<CsInstruments>\n"
"sr = 44100\n"
"ksmps = 64\n "
"nchnls = 2\n"
"0dbfs = 1\n"
"instr 1\n"
"a1 oscili 1, 300, 1\n"
"outs a1, a1\n"
"endin\n"
"</CsInstruments>\n"
"<CsScore>\n"
"f1 0 1024 10 1\n"
"i1 0 2\n"
"</CsScore>\n"
"</CsoundSynthesizer>\n";
//compile instance of csound.
csound->CompileCsdText(csdText.c_str());
//create message buffer
csound->CreateMessageBuffer (0);
//prepare Csound for performance
csound->Start();
//perform entire score and grab messages from the message buffer
while (csound->PerformKsmps() == 0)
{
while (csound->GetMessageCnt() > 0)
{
cout << "CSOUND_MESSAGE:" << csound->GetFirstMessage();
csound->PopFirstMessage();
}
}
//free Csound object
delete csound;
return 0;
}