File: advanced.html

package info (click to toggle)
csound-doc 3.47b2-2
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 1,492 kB
  • ctags: 272
  • sloc: makefile: 36
file content (196 lines) | stat: -rw-r--r-- 10,486 bytes parent folder | download | duplicates (6)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<HTML>
<TITLE>ADVANCED</TITLE>
<CENTER><A NAME="advanced"></A>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <A HREF="./CSCORE.html">Top of this section</A> - <A HREF="./main.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <A HREF="./compiling.html">Next</A>
<HR></CENTER>


<H2>
<U>More advanced examples</U>.</H2>


<P>The following program demonstrates reading from two different input
files.&nbsp; The idea is to switch between two 2-section scores, and write
out the interleaved sections to a single output file.
<BR>&nbsp;
<UL>&nbsp;<TT>./.htmlinclude "cscore.h"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp; CSCORE_SWITCH.C&nbsp; */</TT><TT></TT>

<P><TT>&nbsp;cscore()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* callable from either csound or standalone cscore */</TT>
<BR><TT>&nbsp;{</TT>
<UL><TT>&nbsp; EVLIST *a, *b;</TT>
<BR><TT>&nbsp; FILE&nbsp;&nbsp; *fp1, *fp2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* declare two scorefile stream pointers */</TT><TT></TT>

<P><TT>&nbsp; fp1 = getcurfp();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp; this is the command-line score */</TT>
<BR><TT>&nbsp; fp2 = filopen("score2.srt"); /*&nbsp; this is an additional
score file */</TT><TT></TT>

<P><TT>&nbsp; a = lget();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* read section from score 1 */</TT>
<BR><TT>&nbsp; lput(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* write it out as is */</TT>
<BR><TT>&nbsp; putstr("s");</TT>
<BR><TT>&nbsp; setcurfp(fp2);</TT>
<BR><TT>&nbsp; b = lget();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* read section from score 2 */</TT>
<BR><TT>&nbsp; lput(b);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* write it out as is */</TT>
<BR><TT>&nbsp; putstr("s");</TT><TT></TT>

<P><TT>&nbsp; lrelev(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* optional to reclaim space */</TT>
<BR><TT>&nbsp; lrelev(b);</TT><TT></TT>

<P><TT>&nbsp; setcurfp(fp1);</TT>
<BR><TT>&nbsp; a = lget();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* read next section from score 1 */</TT>
<BR><TT>&nbsp; lput(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* write it out */</TT>
<BR><TT>&nbsp; putstr("s");</TT>
<BR><TT>&nbsp; setcurfp(fp2);</TT>
<BR><TT>&nbsp; b = lget();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* read next sect from score 2 */</TT>
<BR><TT>&nbsp; lput(b);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/ * write it out */</TT>
<BR><TT>&nbsp; putstr("e");</TT></UL>
<TT>&nbsp;}</TT></UL>


<P>Finally, we show how to take a literal, uninterpreted score file and
imbue it with some expressive timing changes.&nbsp; The theory of composer-related
metric pulses has been investigated at length by Manfred Clynes, and the
following is in the spirit of his work.&nbsp; The strategy here is to first
create an <I>array</I> of new <I>onset </I>times for every possible sixteenth-note
onset, then to index into it so as to adjust the start and duration of
each note of the input score to the interpreted time-points.&nbsp; This
also shows how a<B> Csound</B> orchestra can be invoked repeatedly from
a run-time score generator.
<BR>&nbsp;
<UL>&nbsp;<TT>./.htmlinclude "cscore.h"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* CSCORE_PULSE.C
*/</TT><BR>
<BR>
<BR><TT>&nbsp;&nbsp; /* program to apply interpretive durational pulse
to&nbsp;&nbsp;&nbsp;&nbsp; */</TT>
<BR><TT>&nbsp;&nbsp; /* an existing score in 3/4 time, first beats on 0,
3, 6 ... */</TT><BR>
<BR>
<BR><TT>&nbsp;static float four[4] = { 1.05, 0.97, 1.03, 0.95 };&nbsp;&nbsp;&nbsp;&nbsp;
/* pulse width for 4's*/</TT>
<BR><TT>&nbsp;static float three[3] = { 1.03, 1.05, .92 };&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* pulse width for 3's*/</TT>
<BR><TT>&nbsp;</TT>
<BR><TT>&nbsp;cscore()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* callable from either csound or standalone cscore&nbsp; */</TT>
<BR><TT>&nbsp;{</TT>
<UL><TT>&nbsp; EVLIST&nbsp; *a, *b;</TT>
<BR><TT>&nbsp;register EVENT&nbsp; *e, **ep;</TT>
<BR><TT>&nbsp; float pulse16[4*4*4*4*3*4];&nbsp; /* 16th-note array, 3/4
time, 256 measures */</TT>
<BR><TT>&nbsp; float acc16, acc1,inc1, acc3,inc3, acc12,inc12, acc48,inc48,
acc192,inc192;</TT>
<BR><TT>&nbsp;register float *p = pulse16;</TT>
<BR><TT>&nbsp;register int&nbsp; n16, n1, n3, n12, n48, n192;</TT><TT></TT>

<P><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* fill the array with interpreted
ontimes&nbsp; */</TT>
<BR><TT>&nbsp; for (acc192=0.,n192=0; n192&lt;4; acc192+=192.*inc192,n192++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp; for (acc48=acc192,inc192=four[n192],n48=0; n48&lt;4;
acc48+=48.*inc48,n48++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (acc12=acc48,inc48=inc192*four[n48],n12=0;n12&lt;4;</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
acc12+=12.*inc12,n12++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (acc3=acc12,inc12=inc48*four[n12],n3=0;
n3&lt;4; acc3+=3.*inc3,n3++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (acc1=acc3,inc3=inc12*four[n3],n1=0;
n1&lt;3; acc1+=inc1,n1++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for (acc16=acc1,inc1=inc3*three[n1],n16=0; n16&lt;4;</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
acc16+=.25*inc1*four[n16],n16++)</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*p++ = acc16;</TT>
<BR><TT>&nbsp;</TT>
<BR><TT>&nbsp;/* for (p = pulse16, n1 = 48; n1--; p += 4)&nbsp; /* show
vals &amp; diffs */</TT>
<BR><TT>&nbsp;/*&nbsp;&nbsp; printf("%g %g %g %g %g %g %g %g\n", *p, *(p+1),
*(p+2), *(p+3),</TT>
<BR><TT>&nbsp;/*&nbsp; *(p+1)-*p, *(p+2)-*(p+1), *(p+3)-*(p+2), *(p+4)-*(p+3));
*/</TT><TT></TT>

<P><TT>&nbsp; a = lget();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* read sect from tempo-warped score */</TT>
<BR><TT>&nbsp; b = lseptwf(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* separate warp &amp; fn statements */</TT>
<BR><TT>&nbsp; lplay(b);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp; and send these to performance */</TT><TT></TT>

<P><TT>&nbsp; a = lappstrev(a, "s");&nbsp; /* append a sect statement to
note list */</TT>
<BR><TT>&nbsp; lplay(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* play the note-list without interpretation */</TT><TT></TT>

<P><TT>&nbsp; for (ep = &amp;a->e[1], n1 = a->nevents; n1--; ) { /* now
pulse-modifiy it */</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e = *ep++;</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (e->op == 'i') {</TT>
<BR><TT>&nbsp;&nbsp; e->p[2] = pulse16[(int)(4. * e->p2orig)];</TT>
<BR><TT>&nbsp;&nbsp; e->p[3] = pulse16[(int)(4. * (e->p2orig + e->p3orig))]
- e->p[2];</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</TT>
<BR><TT>&nbsp; }</TT>
<BR><TT>&nbsp; lplay(a);&nbsp;&nbsp; /* now play modified list */</TT></UL>
<TT>&nbsp;}</TT></UL>
<TT></TT>

<P>As stated above, the input files to <B>Cscor</B>e may be in original
or time-warped and pre-sorted form;&nbsp;&nbsp; this modality will be preserved
(section by section) in reading, processing and writing scores. Standalone
processing will most often use unwarped sources and create unwarped new
files.&nbsp; When running from within <B>Csound</B> the input score will
arrive already warped and sorted, and can thus be sent directly (normally
section by section) to the orchestra.

<P>A list of events can be conveyed to a <B>Csound </B>orchestra using
<B>lplay</B>. There may be any number of <B>lplay </B>calls in a Cscore
program.&nbsp; Each list so conveyed can be either time-warped or not,
but each list must be in strict <I>p2</I>-chronological order (either from
presorting or using <B>lsort</B>).&nbsp; If there is no <B>lplay</B> in
a cscore module run from within <B>Csound</B>, all events written out (via
<I>putev, putstr or lput</I>) constitute a new score, which will be sent
initially to <B>scsort</B> then to the <B>Csound </B>orchestra for performance.&nbsp;
These can be examined in the files '<I>cscore.out</I>' and '<I>cscore.srt</I>'.

<P>A standalone cscore program will normally use the put commands to write
into its output file.&nbsp; If a standalone <B>Cscore</B> program contains
lplay, the events thus intended for performance will instead be printed
on the console.

<P>A note list sent by <B>lplay</B> for performance should be temporally
distinct from subsequent note lists.&nbsp; No note-end should extend past
the next list's start time, since<B> lplay</B> will complete each list
before starting the next (i.e. like a Section marker that doesn't reset
local time to zero). This is important when using<B> lgetnext() or lgetuntil()
</B>to fetch and process score segments prior to performance.<BR>
<BR>

<CENTER><P>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A></B>
- <A HREF="./CSCORE.html">Top of this section</A> - <A HREF="./main.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <A HREF="./compiling.html">Next</A>
<HR></CENTER>



<P><CENTER>
<B><I><FONT COLOR="#006600">HTML Csound Manual - <FONT SIZE=-1>&copy;
Jean Pich&eacute; &amp; Peter J. Nix, 1994-97</FONT></FONT></I></B>&nbsp;
</CENTER>
</HTML>