View Source SuperCollider.SynthDef.ScFile (SuperCollider v0.1.5)
A struct representing a .scsyndef file in Elixir and a module for parsing (decoding) and encoding (to binary) SuperCollider synthdef files.
Currently only version 2 files are supported.
As a struct, %ScFile{}
contains the following:
type_id
: a string (SCgf
) representing the SuperCollider file formatfile_version
: currently set to 2 (version 2 is the only file format currently supported)synth_defs_count
: an integer count of the number of synthdefs within the file.nil
if emptysynth_defs
: a list of synth definitions. These will use the%SynthDef{}
struct.
Key functions in this module include:
parse/1
: for parsing a .scsyndef file. This will read the file from disc and call thedecode/1
function.decode/1
: for deconding a scsyndef binary into an%ScFile{}
struct.encode/1
: for encoding one or more%SynthDef{}
into the scsyndef binary format.
example
Example
alias SuperCollider.SynthDef.ScFile
# Parse the scsyndef file
sc_file = ScFile.parse("/supercollider/ambient.scsyndef")
# returns the parsed file as a `%ScFile{}` struct
See below for further examples.
Link to this section Summary
Functions
Decodes a scsyndef binary into an %ScFile{}
struct.
Encodes an %ScFile{}
or %SynthDef{}
structs into SuperCollider's scsyndef binary format.
Takes a a filename as as single parameter, which is a the filename (and path) of the .scsyndef file to parse. This currently parses SuperCollider version 2 file format only.
Link to this section Functions
Decodes a scsyndef binary into an %ScFile{}
struct.
example
Example
Read a .scsyndef file from disc and decode it:
alias SuperCollider.SynthDef.ScFile
filename = "/supercollider/closedhat.scsyndef"
sc_file =
File.read!(filename)
|> ScFile.decode()
Note: If decoding directly from a file, you can use the ScFile.parse(filename)
instead.
Encodes an %ScFile{}
or %SynthDef{}
structs into SuperCollider's scsyndef binary format.
This can be used to either send as binary data to to scynth or supernova via the :d_recv
command, or write as a file to disc .scsyndef file.
Takes either of the following as the first parameter:
- an
%ScFile{}
and encodes it into a new scsyndef binary - single
%SynthDef{}
and encodes it into a new scsyndef binary (converting it to a%ScFile{}
first) - list of
%SynthDef{}
and encodes them into a new scsyndef binary (converting it to a%ScFile{}
first).
Takes a a filename as as single parameter, which is a the filename (and path) of the .scsyndef file to parse. This currently parses SuperCollider version 2 file format only.
Returns the populated %ScFile{}
struct.
You can access the individual synth definitions via the :synth_def
key on the struct.
example
Example
alias SuperCollider.SynthDef.ScFile
# Parse the scsyndef file
sc_file = ScFile.parse("/supercollider/ambient.scsyndef")
This returns the parsed file as a struct:
%SuperCollider.SynthDef.ScFile{
type_id: "SCgf",
file_version: 2,
synth_defs_count: 1,
synth_defs: [
# ... truncated, see below for example contents of the synth_defs key
],
varient_count: 0,
varient_specs_list: []
}
]
}
You can access the list of synth definitions using the synth_def key:
sc_file.synth_defs
Which will return
[
%SuperCollider.SynthDef{
name: "ambient",
constant_values_list: [0.2],
parameter_values_list: [0.0],
parameter_names_list: [%{parameter_index: 0, parameter_name: "out"}],
ugen_specs_list: [
%SuperCollider.SynthDef.UGen{
class_name: "Control",
calculation_rate: 1,
special_index: 0,
input_specs_list: [],
output_specs_list: [%{_enum_count: 0, calculation_rate: 1}]
},
%SuperCollider.SynthDef.UGen{
class_name: "BrownNoise",
calculation_rate: 2,
special_index: 0,
input_specs_list: [],
output_specs_list: [%{_enum_count: 0, calculation_rate: 2}]
},
%SuperCollider.SynthDef.UGen{
class_name: "BinaryOpUGen",
calculation_rate: 2,
special_index: 2,
input_specs_list: [
%{index: 1, output_index: 0, type: :ugen},
%{index: 0, type: :constant}
],
output_specs_list: [%{_enum_count: 0, calculation_rate: 2}]
},
%SuperCollider.SynthDef.UGen{
class_name: "Out",
calculation_rate: 2,
special_index: 0,
input_specs_list: [
%{index: 0, output_index: 0, type: :ugen},
%{index: 2, output_index: 0, type: :ugen}
],
output_specs_list: []
}
],
varient_specs_list: []
}
]