Debian Codegraph @

cscore/advancd.xml

raw symbols SCIP
1
2 <section id="CscoreAdvancd">
3 <title>More Advanced Examples</title>
4
5 <para>
6 The following program demonstrates reading from two different input files. The idea is to switch between two 2-section scores, and write out the interleaved sections to a single output file.
7 </para>
8
9 <para>
10 <informalexample>
11 <programlisting>
12 #include &quot;cscore.h&quot; /* CSCORE_SWITCH.C */
13 cscore(CSOUND* cs) /* callable from either Csound or standalone cscore */
14 {
15 EVLIST *a, *b;
16 FILE *fp1, *fp2; /* declare two scorefile stream pointers */
17 fp1 = cscoreFileGetCurrent(cs); /* this is the command-line score */
18 fp2 = cscoreFileOpen(cs, &quot;score2.srt&quot;); /* this is an additional score file */
19 a = cscoreListGetSection(cs); /* read section from score 1 */
20 cscoreListPut(cs, a); /* write it out as is */
21 cscorePutString(cs, &quot;s&quot;);
22 cscoreFileSetCurrent(cs, fp2);
23 b = cscoreListGetSection(cs); /* read section from score 2 */
24 cscoreListPut(cs, b); /* write it out as is */
25 cscorePutString(cs, &quot;s&quot;);
26 cscoreListFreeEvents(cs, a); /* optional to reclaim space */
27 cscoreListFreeEvents(cs, b);
28 cscoreFileSetCurrent(cs, fp1);
29 a = cscoreListGetSection(cs); /* read next section from score 1 */
30 cscoreListPut(cs, a); /* write it out */
31 cscorePutString(cs, &quot;s&quot;);
32 cscoreFileSetCurrent(cs, fp2);
33 b = cscoreListGetSection(cs); /* read next sect from score 2 */
34 cscoreListPut(cs, b); /* write it out */
35 cscorePutString(cs, &quot;e&quot;);
36 }</programlisting>
37 </informalexample>
38 </para>
39
40 <para>
41 Finally, we show how to take a literal, uninterpreted score file and imbue it with some expressive timing changes. 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. The strategy here is to first create an <emphasis>array</emphasis> of new <emphasis>onset</emphasis> 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. This also shows how a Csound orchestra can be invoked repeatedly from a run-time score generator.
42 </para>
43
44 <para>
45 <informalexample>
46 <programlisting>
47 #include &quot;cscore.h&quot; /* CSCORE_PULSE.C */
48
49 /* program to apply interpretive durational pulse to */
50 /* an existing score in 3/4 time, first beats on 0, 3, 6 ... */
51
52
53 static float four[4] = { 1.05, 0.97, 1.03, 0.95 }; /* pulse width for 4's */
54 static float three[3] = { 1.03, 1.05, .92 }; /* pulse width for 3's */
55
56
57 cscore(CSOUND* cs) /* This example should be called from Csound */
58 {
59 EVLIST *a, *b;
60 EVENT *e, **ep;
61 float pulse16[4*4*4*4*3*4]; /* 16th-note array, 3/4 time, 256 measures */
62 float acc16, acc1,inc1, acc3,inc3, acc12,inc12, acc48,inc48, acc192,inc192;
63 float *p = pulse16;
64 int n16, n1, n3, n12, n48, n192;
65
66 /* fill the array with interpreted ontimes */
67 for (acc192=0.,n192=0; n192&lt;4; acc192+=192.*inc192,n192++)
68 for (acc48=acc192,inc192=four[n192],n48=0; n48&lt;4; acc48+=48.*inc48,n48++)
69 for (acc12=acc48,inc48=inc192*four[n48],n12=0;n12&lt;4; acc12+=12.*inc12,n12++)
70 for (acc3=acc12,inc12=inc48*four[n12],n3=0; n3&lt;4; acc3+=3.*inc3,n3++)
71 for (acc1=acc3,inc3=inc12*four[n3],n1=0; n1&lt;3; acc1+=inc1,n1++)
72 for (acc16=acc1,inc1=inc3*three[n1],n16=0; n16&lt;4; acc16+=.25*inc1*four[n16],n16++)
73 *p++ = acc16;
74
75
76 /* for (p = pulse16, n1 = 48; n1--; p += 4) /* show vals &amp; diffs */
77 /* printf(&quot;%g %g %g %g %g %g %g %g\n&quot;, *p, *(p+1), *(p+2), *(p+3),
78 /* *(p+1)-*p, *(p+2)-*(p+1), *(p+3)-*(p+2), *(p+4)-*(p+3)); */
79
80 a = cscoreListGetSection(cs); /* read sect from tempo-warped score */
81 b = cscoreListSeparateTWF(cs, a); /* separate warp &amp; fn statements */
82 cscoreListPlay(cs, b); /* and send these to performance */
83 a = cscoreListAppendStringEvent(cs, a, &quot;s&quot;); /* append a sect statement to note list */
84 cscoreListPlay(cs, a); /* play the note-list without interpretation */
85 for (ep = &amp;a-&gt;e[1], n1 = a-&gt;nevents; n1--; ) { /* now pulse-modifiy it */
86 e = *ep++;
87 if (e-&gt;op == 'i') {
88 e-&gt;p[2] = pulse16[(int)(4. * e-&gt;p2orig)];
89 e-&gt;p[3] = pulse16[(int)(4. * (e-&gt;p2orig + e-&gt;p3orig))] - e-&gt;p[2];
90 }
91 }
92
93 cscoreListPlay(cs, a); /* now play modified list */
94 }</programlisting>
95 </informalexample>
96 </para>
97 </section>