The .csd
file format
The Unified 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.
The file is a structured data file which uses markup language, similar to any SGML such as HTML. Start tags (
Mandatory Elements
Enclosing tag (<CsoundSynthesizer>)
The first tag in the file must be the start tag
Options (<CsOptions>)
Csound command line flags are put in the Options Element. This section is delimited by the start tag
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
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
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 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 Elements
Included Base64 Files (<CsFileB>)
Base64-encoded files may be included with the tag
Base64-encoded MIDI files may be included with the tag
Base64-encoded sample files may be included with the tag
Included Unencoded Files (<CsFile>)
Unencoded files may be included with the tag
Version Blocking (<CsVersion>)
Versions of Csound may blocked by placing one of the following statements between the start tag
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
Licence Information (<CsShortLicence> or <CsShortLicense>)
From version 6.05 licencing details can be also included in between the start tag
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).