Debian Codegraph @

command/unifile.xml

raw symbols SCIP
1
2 <section id="CommandUnifile">
3 <title>Unified File Format for Orchestras and Scores</title>
4
5 <section id="CommandUnifileDescription">
6 <title>Description</title>
7 <para>
8 The Unified File Format<indexterm id="IndexUnifiedFile"><primary>Unified File Format</primary></indexterm>, introduced in Csound version 3.50, enables the orchestra and score files, as well as command line flags, to be combined in one file. The file has the extension <emphasis>.csd</emphasis>. This format was originally introduced by Michael Gogins in AXCsound.
9
10 <indexterm id="IndexCSD"><primary>.csd</primary></indexterm>
11 <indexterm id="IndexCsoundrcUnifile"><primary>.csound6rc</primary></indexterm>
12 <indexterm id="IndexCsFileB"><primary>&lt;CsFileB&gt;</primary></indexterm>
13 <indexterm id="IndexCsFile"><primary>&lt;CsFile&gt;</primary></indexterm>
14 <indexterm id="IndexCsInstruments"><primary>&lt;CsInstruments&gt;</primary></indexterm>
15 <indexterm id="IndexCsMidifileB"><primary>&lt;CsMidifileB&gt;</primary></indexterm>
16 <indexterm id="IndexCsOptions"><primary>&lt;CsOptions&gt;</primary></indexterm>
17 <indexterm id="IndexCsSampleB"><primary>&lt;CsSampleB&gt;</primary></indexterm>
18 <indexterm id="IndexCsScore"><primary>&lt;CsScore&gt;</primary></indexterm>
19 <indexterm id="IndexCsoundSynthesizer"><primary>&lt;CsoundSynthesizer&gt;</primary></indexterm>
20 <indexterm id="IndexCsVersion"><primary>&lt;CsVersion&gt;</primary></indexterm>
21 <indexterm id="IndexCsLicense"><primary>&lt;CsLicense&gt;</primary></indexterm>
22 <indexterm id="IndexCsShortLicense"><primary>&lt;CsShortLicense&gt;</primary></indexterm>
23 </para>
24
25 <para>
26 The file is a structured data file which uses markup language, similar to any SGML such as HTML. Start tags (&lt;<emphasis>tag</emphasis>&gt;) and end tags (&lt;/<emphasis>tag</emphasis>&gt;) are used to delimit the various elements. The file is saved as a text file.
27 </para>
28
29 <bridgehead>Structured Data File Format</bridgehead>
30 <bridgehead>Mandatory Elements</bridgehead>
31 <para>
32 The first tag in the file must be the start tag <emphasis>&lt;CsoundSynthesizer&gt;. </emphasis>The last tag in the file must be the end tag <emphasis>&lt;/CsoundSynthesizer&gt;. </emphasis>This element is used to alert the csound compiler to the <emphasis>.csd</emphasis> format. All text before the start tag and after the end tag is ignored by Csound. The tag may also be spelled <emphasis>&lt;CsoundSynthesiser&gt;</emphasis>.
33 </para>
34
35 <bridgehead>Options (&lt;CsOptions&gt;)</bridgehead>
36 <para>
37 Csound <link linkend="CommandFlagsCategory"><citetitle>command line flags</citetitle></link> are put in the Options Element. This section is delimited by the start tag <emphasis>&lt;CsOptions&gt;</emphasis> and the end tag <emphasis>&lt;/CsOptions&gt; </emphasis>Lines beginning with <emphasis>#</emphasis> or <emphasis>;</emphasis> are treated as comments.
38 </para>
39
40 <bridgehead>Orchestra (&lt;CsInstruments&gt;)</bridgehead>
41 <para>
42 The instrument definitions (orchestra) are put into the Instruments Element. The statements and syntax in this section are identical to the Csound <link linkend="OrchTop"><citetitle>orchestra file</citetitle></link>, and have the same requirements, including the header statements (<emphasis>sr</emphasis>, <emphasis>kr</emphasis>, etc.) This Instruments Element is delimited with the start tag <emphasis>&lt;CsInstruments&gt;</emphasis> and the end tag <emphasis>&lt;/CsInstruments&gt;.</emphasis>
43 </para>
44
45 <bridgehead>Score (&lt;CsScore&gt;)</bridgehead>
46 <para>
47 Csound score statements are put in the Score Element. The statements and syntax in this section are identical to the Csound <link linkend="ScoreTop"><citetitle>score file</citetitle></link>, and have the same requirements. The Score Element is delimited by the start tag <emphasis>&lt;CsScore&gt; </emphasis>and the end tag <emphasis>&lt;/CsScore&gt;.</emphasis>
48 </para>
49 <para>
50 As an alternative Csound score statements can also be generated by an external
51 program using the CsScore scheme with an attribute bin. The lines upto the closing
52 tag <emphasis>&lt;/CsScore&gt;</emphasis> are copied to a file
53 and the external program named is called with that file name and
54 the destination score file. The external program should create a
55 standard Csound score.
56 </para>
57
58 <bridgehead>Optional Elements</bridgehead>
59
60 <bridgehead>Included Base64 Files (&lt;CsFileB&gt;)</bridgehead>
61 <para>
62 Base64-encoded files may be included with the tag <emphasis>&lt;CsFileB filename=</emphasis><emphasis>filename</emphasis><emphasis>&gt;</emphasis>, where <emphasis>filename</emphasis> is the name of the file to be included. The Base64-encoded data should be terminated with a <emphasis>&lt;/CsFileB&gt;</emphasis> tag. For encoding files, the csb64enc and <link linkend="makecsd"><citetitle>makecsd</citetitle></link> utilities (included with Csound 5.00 and newer) can be used. The file will be extracted to the current directory, and deleted at end of performance. If there is an already existing file with the same name, it is not overwritten, but an error will occur instead.
63 </para>
64 <para>
65 Base64-encoded MIDI files may be included with the tag <emphasis>&lt;CsMidifileB filename=</emphasis><emphasis>filename</emphasis><emphasis>&gt;</emphasis>, where <emphasis>filename</emphasis> is the name of the file containing the MIDI information. There is no matching end tag. This was added in Csound version 4.07. Note: using this tag is not recommended; use <emphasis>&lt;CsFileB&gt;</emphasis> instead.
66 </para>
67
68 <para>
69 Base64-encoded sample files may be included with the tag <emphasis>&lt;CsSampleB filename=</emphasis><emphasis>filename</emphasis><emphasis>&gt;</emphasis>, where <emphasis>filename</emphasis> is the name of the file containing the sample. There is no matching end tag. This was added in Csound version 4.07. Note: using this tag is not recommended; use <emphasis>&lt;CsFileB&gt;</emphasis> instead.
70 </para>
71
72 <bridgehead>Included Unencoded Files (&lt;CsFile&gt;)</bridgehead>
73 <para>
74 Unencoded files may be included with the tag
75 <emphasis>&lt;CsFile
76 filename=</emphasis><emphasis>filename</emphasis><emphasis>&gt;</emphasis>,
77 where <emphasis>filename</emphasis> is the name of the file to
78 be included. The data should be terminated with a
79 <emphasis>&lt;/CsFile&gt;</emphasis> tag alone on a line. The
80 file will be extracted to the current directory, and deleted at
81 end of performance. If there is an already existing file with
82 the same name, it is not overwritten, but an error will occur
83 instead.
84 </para>
85
86 <bridgehead>Version Blocking (&lt;CsVersion&gt;)</bridgehead>
87 <para>
88 Versions of Csound may blocked by placing one of the following statements between the start tag &lt;CsVersion&gt; and the end tag &lt;/CsVersion&gt;:
89
90 <informalexample>
91 <programlisting>Before #.#</programlisting>
92 </informalexample>
93
94 or
95
96 <informalexample>
97 <programlisting>After #.#</programlisting>
98 </informalexample>
99
100 where #.# is the requested Csound version number. The second statement may be written simply as:
101
102 <informalexample>
103 <programlisting>#.#</programlisting>
104 </informalexample>
105
106 This was added in Csound version 4.09.
107 </para>
108
109 <bridgehead>Licence Information (&lt;CsLicence&gt; or &lt;CsLicense&gt;)</bridgehead>
110 <para>
111 Licencing details can be included in between the start tag
112 <emphasis>&lt;CsLicence&gt;</emphasis> and the end tag
113 <emphasis>&lt;/CsLicence&gt;</emphasis>. There is no format
114 for this information, any text is acceptable. This text will
115 be printed by Csound to the console when the CSD is run.
116 </para>
117
118 <bridgehead>Licence Information (&lt;CsShortLicence&gt; or &lt;CsShortLicense&gt;)</bridgehead>
119 <para>
120 From version 6.05 licencing details can be also included in
121 between the start tag
122 <emphasis>&lt;CsShortLicence&gt;</emphasis> and the end tag
123 <emphasis>&lt;/CsShortLicence&gt;</emphasis>. This offers
124 seven well-known licences, coded as as an integer.
125 </para>
126 <para>
127 <simplelist>
128 <member>0: "All rights reserved" (default)</member>
129 <member>1: "Creative Commons Attribution-NonCommercial-NoDerivatives (CC BY-NC-ND)"</member>
130 <member>2: "Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA)"</member>
131 <member>3: "Creative Commons Attribution-NonCommercial (CC BY-NC)"</member>
132 <member>4: "Creative Commons Attribution-NoDerivatives (CC BY-ND)"</member>
133 <member>5: "Creative Commons Attribution-ShareAlike (CC BY-SA)"</member>
134 <member>6: "Creative Commons Attribution-ShareAlike (CC BY)"</member>
135 <member>7: "Licenced under BSD"</member>
136 </simplelist>
137 </para>
138
139 <bridgehead>Embedded HTML (&lt;html&gt;)</bridgehead>
140 <para>
141 Any valid HTML code can be embedded in the CSD file. This code should be structured exactly like an ordinary Web page. This code
142 can contain any valid HTML, JavaScript, Cascading Style Sheet, WebGL, etc., etc. code.
143 </para>
144 <para>
145 In some Csound front ends and programming environments, including at least CsoundQt or Csound for Android, this page will be parsed, executed,
146 and displayed by a Web browser embedded in the environment. JavaScript code in this page will have access to a global <emphasis>csound</emphasis>
147 object that implements the following functions, which are a selected subset of the Csound API. The names, data types, and
148 uses of these functions are exactly the same as detailed in the Csound API Reference Manual.
149 </para>
150 <para>
151 <programlisting>
152 [int] getVersion ();
153 compileOrc (orchestra_text);
154 [double] evalCode (orchestra_expression);
155 readScore (score_text);
156 setControlChannel (channel_name, numeric_value);
157 [double] getControlChannel (channel_name);
158 message (message_string);
159 [int] getSr ();
160 [int] getKsmps ();
161 [int] getNchnls ();
162 // Not a part of the Csound API -- called by the environment to detect whether Csound is running.
163 [int] isPlaying ();
164 </programlisting>
165 </para>
166
167 <para>
168 The HTML element of the CSD file can be used to create custom user interfaces for the piece, to generate score events and even orchestra code
169 using JavaSscript, to store presets for widgets, and for many other purposes. The
170 <ulink url="examples/GameOfLife3D.csd"><citetitle>GameOfLife3D.csd</citetitle></ulink> and
171 <ulink url="examples/LindenmayerCanvas.csd"><citetitle>LindenmayerCanvas.csd</citetitle></ulink>
172 examples demonstrate these uses (tested in CsoundQt; running these examples
173 requires additional resources found in the Csound examples directory in GIT).
174 </para>
175
176 </section>
177
178 <section id="CommandUnifileExample">
179 <title>Example</title>
180 <para>
181 Below is a sample file, test.csd, which renders a .wav file at 44.1 kHz sample rate containing one second of a 1 kHz sine wave. Displays are suppressed. test.csd was created from two files, tone.orc and tone.sco, with the addition of command line flags.
182
183 <informalexample>
184 <programlisting>
185 <emphasis role="csdtag">&lt;CsoundSynthesizer&gt;</emphasis>;
186 <emphasis role="comment">; test.csd - a Csound structured data file</emphasis>
187
188 <emphasis role="csdtag">&lt;CsOptions&gt;</emphasis>
189 -W -d -o tone.wav
190 <emphasis role="csdtag">&lt;/CsOptions&gt;</emphasis>
191
192 <emphasis role="csdtag">&lt;CsVersion&gt;</emphasis> <emphasis role="comment">; optional section</emphasis>
193 Before 4.10 <emphasis role="comment">; these two statements check for</emphasis>
194 After 4.08 <emphasis role="comment">; Csound version 4.09</emphasis>
195 <emphasis role="csdtag">&lt;/CsVersion&gt;</emphasis>
196
197 <emphasis role="csdtag">&lt;CsInstruments&gt;</emphasis>
198 <emphasis role="comment">; originally tone.orc</emphasis>
199 <emphasis role="ohdr">sr</emphasis> = 44100
200 <emphasis role="ohdr">kr</emphasis> = 4410
201 <emphasis role="ohdr">ksmps</emphasis> = 10
202 <emphasis role="ohdr">nchnls</emphasis> = 1
203 <emphasis role="oblock">instr</emphasis> 1
204 a1 <emphasis role="opc">oscil</emphasis> p4, p5, 1 <emphasis role="comment">; simple oscillator</emphasis>
205 <emphasis role="opc">out</emphasis> a1
206 <emphasis role="oblock">endin</emphasis>
207 <emphasis role="csdtag">&lt;/CsInstruments&gt;</emphasis>
208
209 <emphasis role="csdtag">&lt;CsScore&gt;</emphasis>
210 <emphasis role="comment">; originally tone.sco</emphasis>
211 <emphasis role="stamnt">f</emphasis>1 0 8192 10 1
212 <emphasis role="stamnt">i</emphasis>1 0 1 20000 1000 <emphasis role="comment">; play one second of one kHz tone</emphasis>
213 <emphasis role="stamnt">e</emphasis>
214 <emphasis role="csdtag">&lt;/CsScore&gt;</emphasis>
215
216 <emphasis role="csdtag">&lt;/CsoundSynthesizer&gt;</emphasis></programlisting>
217 </informalexample>
218 </para>
219 </section>
220
221
222 </section>
223 <section id="CommandUnifileParFile">
224 <title>Command Line Parameter File (.csound6rc)</title>
225 <para>
226 If the file <emphasis>.csound6rc</emphasis> exists, it will be used to set the command line parameters. These can be overridden. Csound 5.00 and newer versions read this file from the HOME directory first (or the full path file name defined by the CSOUND6RC <link linkend="CommandEnvironment"><citetitle>environment variable</citetitle></link>), and then the current directory. If both exist, options in the .csound6rc in the current directory will have higher precedence. It uses the same form as a <emphasis>.csd</emphasis> file, but no tags are needed. Lines beginning with <emphasis>#</emphasis> or <emphasis>;</emphasis> are treated as comments.
227 </para>
228 <para>
229 A <emphasis>.csound6rc</emphasis> file can contain something like this:
230 </para>
231 <literallayout>
232 -+rtaudio=portaudio -odac2 -iadc2 -+rtmidi=winmme -M1 -Q1 -m0
233 </literallayout>
234 <para>
235 In this case, csound will generate real-time output and take realtime input from device 2, using the portaudio driver interface. It will input and output realtime MIDI on interface 1. It will print very few messages (-m0). These options will be used by default when other options are not given inside the &lt;CsOptions&gt; of the .csd file or the command line (See <link linkend="CommandOrder"><citetitle>Order of precendence</citetitle></link>).
236 </para>
237 </section>