View Source SuperCollider.SynthDef.ScFile (SuperCollider v0.1.1)
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.nilif 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/1function.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{}` structSee below for further examples.
Link to this section Summary
Functions
Decodes a scsyndef binary into an %ScFile{} struct.
Takes either a
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.
Takes either a
- single
%SynthDef{}and encodes it into a new scsyndef binary - list of
%SynthDef{}and encodes them into a new scsyndef binary.
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_count: 1,
constant_values_list: [{0, 0.2}],
parameter_count: 1,
parameter_values_list: [{0, 0.0}],
parameter_names_count: 1,
parameter_names_list: [
%{_enum_index: 0, parameter_index: 0, parameter_name: "out"}
],
ugen_count: 4,
ugen_specs_list: [
%SuperCollider.SynthDef.UGen{
class_name: "Out",
calculation_rate: 2,
special_index: 0,
inputs_count: 2,
input_specs_list: [
%{_enum_count: 1, index: 2, output_index: 0, type: :ugen},
%{_enum_count: 0, index: 0, output_index: 0, type: :ugen}
],
outputs_count: 0,
output_specs_list: []
},
%SuperCollider.SynthDef.UGen{
class_name: "BinaryOpUGen",
calculation_rate: 2,
special_index: 2,
inputs_count: 2,
input_specs_list: [
%{_enum_count: 1, index: 0, type: :constant},
%{_enum_count: 0, index: 1, output_index: 0, type: :ugen}
],
outputs_count: 1,
output_specs_list: [%{calculation_rate: 2, count: 0}]
},
%SuperCollider.SynthDef.UGen{
class_name: "BrownNoise",
calculation_rate: 2,
special_index: 0,
inputs_count: 0,
input_specs_list: [],
outputs_count: 1,
output_specs_list: [%{calculation_rate: 2, count: 0}]
},
%SuperCollider.SynthDef.UGen{
class_name: "Control",
calculation_rate: 1,
special_index: 0,
inputs_count: 0,
input_specs_list: [],
outputs_count: 1,
output_specs_list: [%{calculation_rate: 1, count: 0}]
}
]