Unified File Format for Orchestras and ScoresDescription
The Unified File FormatUnified File Format, 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 .csd. This format was originally introduced by Michael Gogins in AXCsound.
.csd.csound6rc<CsFileB><CsFile><CsInstruments><CsMidifileB><CsOptions><CsSampleB><CsScore><CsoundSynthesizer><CsVersion><CsLicense><CsShortLicense>
The file is a structured data file which uses markup language, similar to any SGML such as HTML. Start tags (<tag>) and end tags (</tag>) are used to delimit the various elements. The file is saved as a text file.
Structured Data File FormatMandatory Elements
The first tag in the file must be the start tag <CsoundSynthesizer>. The last tag in the file must be the end tag </CsoundSynthesizer>. This element is used to alert the csound compiler to the .csd format. All text before the start tag and after the end tag is ignored by Csound. The tag may also be spelled <CsoundSynthesiser>.
Options (<CsOptions>)
Csound command line flags are put in the Options Element. This section is delimited by the start tag <CsOptions> and the end tag </CsOptions> Lines beginning with # or ; are treated as comments.
Orchestra (<CsInstruments>)
The instrument definitions (orchestra) are put into the Instruments Element. The statements and syntax in this section are identical to the Csound orchestra file, and have the same requirements, including the header statements (sr, kr, etc.) This Instruments Element is delimited with the start tag <CsInstruments> and the end tag </CsInstruments>.Score (<CsScore>)
Csound score statements are put in the Score Element. The statements and syntax in this section are identical to the Csound score file, and have the same requirements. The Score Element is delimited by the start tag <CsScore> and the end tag </CsScore>.
As an alternative Csound score statements can also be generated by an external
program using the CsScore scheme with an attribute bin. The lines upto the closing
tag </CsScore> are copied to a file
and the external program named is called with that file name and
the destination score file. The external program should create a
standard Csound score.
Optional ElementsIncluded Base64 Files (<CsFileB>)
Base64-encoded files may be included with the tag <CsFileB filename=filename>, where filename is the name of the file to be included. The Base64-encoded data should be terminated with a </CsFileB> tag. For encoding files, the csb64enc and makecsd 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.
Base64-encoded MIDI files may be included with the tag <CsMidifileB filename=filename>, where filename 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 <CsFileB> instead.
Base64-encoded sample files may be included with the tag <CsSampleB filename=filename>, where filename 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 <CsFileB> instead.
Included Unencoded Files (<CsFile>)
Unencoded files may be included with the tag
<CsFile
filename=filename>,
where filename is the name of the file to
be included. The data should be terminated with a
</CsFile> tag alone on a line. 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.
Version Blocking (<CsVersion>)
Versions of Csound may blocked by placing one of the following statements between the start tag <CsVersion> and the end tag </CsVersion>:
Before #.#
or
After #.#
where #.# is the requested Csound version number. The second statement may be written simply as:
#.#
This was added in Csound version 4.09.
Licence Information (<CsLicence> or <CsLicense>)
Licencing details can be included in between the start tag
<CsLicence> and the end tag
</CsLicence>. There is no format
for this information, any text is acceptable. This text will
be printed by Csound to the console when the CSD is run.
Licence Information (<CsShortLicence> or <CsShortLicense>)
From version 6.05 licencing details can be also included in
between the start tag
<CsShortLicence> and the end tag
</CsShortLicence>. This offers
seven well-known licences, coded as as an integer.
0: "All rights reserved" (default)1: "Creative Commons Attribution-NonCommercial-NoDerivatives (CC BY-NC-ND)"2: "Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA)"3: "Creative Commons Attribution-NonCommercial (CC BY-NC)"4: "Creative Commons Attribution-NoDerivatives (CC BY-ND)"5: "Creative Commons Attribution-ShareAlike (CC BY-SA)"6: "Creative Commons Attribution-ShareAlike (CC BY)"7: "Licenced under BSD"Embedded HTML (<html>)
Any valid HTML code can be embedded in the CSD file. This code should be structured exactly like an ordinary Web page. This code
can contain any valid HTML, JavaScript, Cascading Style Sheet, WebGL, etc., etc. code.
In some Csound front ends and programming environments, including at least CsoundQt or Csound for Android, this page will be parsed, executed,
and displayed by a Web browser embedded in the environment. JavaScript code in this page will have access to a global csound
object that implements the following functions, which are a selected subset of the Csound API. The names, data types, and
uses of these functions are exactly the same as detailed in the Csound API Reference Manual.
[int] getVersion ();
compileOrc (orchestra_text);
[double] evalCode (orchestra_expression);
readScore (score_text);
setControlChannel (channel_name, numeric_value);
[double] getControlChannel (channel_name);
message (message_string);
[int] getSr ();
[int] getKsmps ();
[int] getNchnls ();
// Not a part of the Csound API -- called by the environment to detect whether Csound is running.
[int] isPlaying ();
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
using JavaSscript, to store presets for widgets, and for many other purposes. The
GameOfLife3D.csd and
LindenmayerCanvas.csd
examples demonstrate these uses (tested in CsoundQt; running these examples
requires additional resources found in the Csound examples directory in GIT).
Example
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.
<CsoundSynthesizer>;
; test.csd - a Csound structured data file<CsOptions>
-W -d -o tone.wav
</CsOptions><CsVersion>; optional section
Before 4.10 ; these two statements check for
After 4.08 ; Csound version 4.09</CsVersion><CsInstruments>; originally tone.orcsr = 44100
kr = 4410
ksmps = 10
nchnls = 1
instr 1
a1 oscil p4, p5, 1 ; simple oscillatorout a1
endin</CsInstruments><CsScore>; originally tone.scof1 0 8192 10 1
i1 0 1 20000 1000 ; play one second of one kHz tonee</CsScore></CsoundSynthesizer>Command Line Parameter File (.csound6rc)
If the file .csound6rc 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 environment variable), 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 .csd file, but no tags are needed. Lines beginning with # or ; are treated as comments.
A .csound6rc file can contain something like this:
-+rtaudio=portaudio -odac2 -iadc2 -+rtmidi=winmme -M1 -Q1 -m0
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 <CsOptions> of the .csd file or the command line (See Order of precendence).