Debian Codegraph @

cscore/events.xml

raw symbols SCIP
1
2 <section id="CscoreEvents">
3 <title>Events, Lists, and Operations</title>
4
5 <para>
6 An event in <emphasis>Cscore</emphasis> is equivalent to one statement of a <emphasis>standard numeric score</emphasis> or a time-warped score (the format in which Csound writes a sorted score -- see any score.srt), and is stored internally in time-warped format. It is important to note that when <emphasis>Cscore</emphasis> is used in standalone-mode, it cannot understand any of the non-numeric "conveniences" that Csound allows in the input score format. Therefore, scores making use of features such as carry, ramp, expressions, and others will have to either be sorted first with the <emphasis>scsort</emphasis> utility or used with a modified <emphasis>Csound</emphasis> executable that contains the user's <emphasis>Cscore</emphasis> program. Score opcodes with macro arguments (r, m, n, and {}) are not understood.
7 </para>
8
9 <para>
10 Score events are each read in from an existing score file and stored in a C structure. The structures main components are an opcode and an array of pfield values. <emphasis>Cscore</emphasis> handles reading the events and storing them in memory for you. The format of the structure starts as follows:
11 </para>
12
13 <para>
14 <informalexample>
15 <programlisting>
16 typedef struct {
17 CSHDR h; /* space-managing header */
18 char *strarg; /* address of optional string argument */
19 char op; /* opcode-t, w, f, i, a, s or e */
20 short pcnt;
21 MYFLT p2orig; /* unwarped p2, p3 */
22 MYFLT p3orig;
23 MYFLT p[1]; /* array of pfields p0, p1, p2 ... */
24 } EVENT;</programlisting>
25 </informalexample>
26 </para>
27
28 <para>
29 MYFLT is either the C type <emphasis>float</emphasis> or <emphasis>double</emphasis> depending on how your copy of the Csound library was compiled. You should just declare any floating-point variables as MYFLT in your user program for compatibility.
30 </para>
31
32 <para>
33 Any <emphasis>Cscore</emphasis> function that creates, reads, or copies an event will return a pointer to the storage structure holding the event data. The event pointer can be used to access any component of the structure, in the form of <emphasis>e-&gt;op</emphasis> or <emphasis>e-&gt;p[n]</emphasis>. Each newly stored event will give rise to a new pointer, and a sequence of new events will generate a sequence of distinct pointers that must themselves be stored. Groups of event pointers are stored in an event list, which has its own structure:
34 </para>
35
36 <para>
37 <informalexample>
38 <programlisting>
39 typedef struct {
40 CSHDR h;
41 int nslots; /* max events in this event list */
42 int nevents; /* number of events present */
43 EVENT *e[1]; /* array of event pointers e0, e1, e2.. */
44 } EVLIST;</programlisting>
45 </informalexample>
46 </para>
47
48 <para>
49 Any Cscore function that creates or modifies a list will return a pointer to the new list. The list pointer can be used to access any of its component event pointers, in the form of <emphasis>a-&gt;e[n]</emphasis>. Event pointers and list pointers are thus primary tools for manipulating the data of a score file. Pointers and lists of pointers can be copied and reordered without modifying the data values they refer to. This means that notes and phrases can be copied and manipulated from a high level of control. Alternatively, the data within an event or group of events can be modified without changing the event or list pointers. The <emphasis>Cscore</emphasis> API functions enable scores to be created and manipulated in this way.
50 </para>
51
52 <para>
53 With Csound 5, the names of all of the <emphasis>Cscore</emphasis> API functions have changed to be more explicit. In addition, each function now requires a pointer to a CSOUND object as its first argument. The structure of the CSOUND object is unimportant (and indeed cannot be modified in a user program). How to obtain this CSOUND pointer will be shown in the next section. The <emphasis>Cscore</emphasis> functions and data structures are available in the <filename>cscore.h</filename> header file, which you must include in your program code before you can you use them.
54 </para>
55
56 <para>
57 The names of the <emphasis>Cscore</emphasis> functions specify whether they operate on single events or event lists. In the following summary of available function calls, some simple naming conventions are used:
58 </para>
59
60 <para>
61 <informalexample>
62 <programlisting>
63 The symbol cs is a pointer to a CSOUND object (CSOUND *);
64 The symbols e, f are pointers to events (notes);
65 The symbols a, b are pointers to lists (arrays) of such events;
66 The symbol n is an integer parameter of type int;
67 &quot;...&quot; indicates a string parameter (either a constant or variable of type char *);
68 The symbol fp is a score input stream file pointer (FILE *);
69
70 calling syntax description
71 -------------- -----------
72 /* Functions for working with single events */
73 e = cscoreCreateEvent(cs, n); create a blank event with n pfields
74 e = cscoreDefineEvent(cs, &quot;...&quot;); defines an event as per the character string ...
75 e = cscoreCopyEvent(cs, f); make a new copy of event f
76 e = cscoreGetEvent(cs); read the next event in the score input file
77 cscorePutEvent(cs, e); write event e to the score output file
78 cscorePutString(cs, &quot;...&quot;); write the string-defined event to score output
79
80 /* Functions for working with event lists */
81 a = cscoreListCreate(cs, n); create an empty event list with n slots
82 a = cscoreListAppendEvent(cs, a, e); append event e to list a
83 a = cscoreListAppendStringEvent(cs, a, &quot;...&quot;); append a string-defined event to list a;
84 a = cscoreListCopy(cs, b); copy the list b (but not the events)
85 a = cscoreListCopyEvents(cs, b); copy the events of b, making a new list
86 a = cscoreListGetSection(cs); read all events from score input, up to next s or e
87 a = cscoreListGetNext(cs, nbeats); read next nbeats beats from score input (nbeats is MYFLT)
88 a = cscoreListGetUntil(cs, beatno); read all events from score input up to beat beatno (MYFLT)
89 a = cscoreListSeparateF(cs, b); separate the f statements from list b into list a
90 a = cscoreListSeparateTWF(cs, b); separate the t,w &amp; f statements from list b into list a
91 a = cscoreListAppendList(cs, a, b); append the list b onto the list a
92 a = cscoreListConcatenate(cs, a, b); concatenate (append) the list b onto the list a (same as previous)
93 cscoreListSort(cs, a); sort the list a into chronological order by p[2]
94 n = cscoreListCount(cs, a); returns the number of events in list a
95 a = cscoreListExtractInstruments(cs, b, &quot;...&quot;); extract notes of instruments ... (no new events)
96 a = cscoreListExtractTime(cs, b, from, to); extract notes of time-span, creating new events (from and to are MYFLT)
97 cscoreListPut(cs, a); write the events of list a to the score output file
98 cscoreListPlay(cs, a); send events of list a to the Csound orchestra for
99 immediate performance (or print events if no orchestra)
100 /* Functions for reclaiming memory */
101 cscoreFreeEvent(cs, e); release the space of event e
102 cscoreListFree(cs, a); release the space of list a (but not the events)
103 cscoreListFreeEvents(cs, a); release the events of list a, and the list space
104
105 /* Functions for working with multiple input score files */
106 fp = cscoreFileGetCurrent(cs); get the currently active input scorefile pointer
107 (initially finds the command-line input scorefile pointer)
108 fp = cscoreFileOpen(cs, &quot;filename&quot;); open another input scorefile (maximum of 5)
109 cscoreFileSetCurrent(cs, fp); make fp the currently active scorefile pointer
110 cscoreFileClose(cs, fp); close the scorefile relating to FILE *fp</programlisting>
111 </informalexample>
112 </para>
113
114 <para>
115 Under Csound 4, the function names and parameters were as follows:
116 </para>
117
118 <para>
119 <informalexample>
120 <programlisting>
121 calling syntax description
122 -------------- -----------
123 e = createv(n); create a blank event with n pfields
124 e = defev(&quot;...&quot;); defines an event as per the character string ...
125 e = copyev(f); make a new copy of event f
126 e = getev(); read the next event in the score input file
127 putev(e); write event e to the score output file
128 putstr(&quot;...&quot;); write the string-defined event to score output
129 a = lcreat(n); create an empty event list with n slots
130 int n;
131 a = lappev(a,e); append event e to list a
132 a = lappstrev(a,&quot;...&quot;); append a string-defined event to list a;
133 a = lcopy(b); copy the list b (but not the events)
134 a = lcopyev(b); copy the events of b, making a new list
135 a = lget(); read all events from score input, up to next s or e
136 a = lgetnext(nbeats); read next nbeats beats from score input
137 float nbeats;
138 a = lgetuntil(beatno); read all events from score input up to beat beatno
139 float beatno;
140 a = lsepf(b); separate the f statements from list b into list a
141 a = lseptwf(b); separate the t,w &amp; f statements from list b into list a
142 a = lcat(a,b); concatenate (append) the list b onto the list a
143 lsort(a); sort the list a into chronological order by p[2]
144 a = lxins(b,&quot;...&quot;); extract notes of instruments ... (no new events)
145 a = lxtimev(b,from,to); extract notes of time-span, creating new events
146 float from, to;
147 lput(a); write the events of list a to the score output file
148 lplay(a); send events of list a to the Csound orchestra for
149 immediate performance (or print events if no orchestra)
150 relev(e); release the space of event e
151 lrel(a); release the space of list a (but not the events)
152 lrelev(a); release the events of list a, and the list space
153 fp = getcurfp(); get the currently active input scorefile pointer
154 (initially finds the command-line input scorefile pointer)
155 fp = filopen(&quot;filename&quot;); open another input scorefile (maximum of 5)
156 setcurfp(fp); make fp the currently active scorefile pointer
157 filclose(fp); close the scorefile relating to FILE *fp</programlisting>
158 </informalexample>
159 </para>
160 </section>