scamp.playback_implementations.PlaybackImplementation¶
-
class
scamp.playback_implementations.
PlaybackImplementation
(*args, **kwargs)[source]¶ Bases:
expenvelope.json_serializer.SavesToJSON
Abstract base class for playback implementations, which do the actual work of playback, either by playing sounds or by sending messages to external synthesizers to play sounds.
- Parameters
host_instrument – The
ScampInstrument
that will use this playback implementation for playback. When this PlaybackImplementation is constructed, it is automatically added to the list of PlaybackImplementations that the host instrument uses.
Methods
change_note_parameter
(note_id, …)Method that implements the change of a parameter other than pitch or volume
change_note_pitch
(note_id, new_pitch)Method that implements the change of a note’s pitch
change_note_volume
(note_id, new_volume)Method that implements the change of a note’s volume
end_note
(note_id)Method that implements the end of a note
get_shared_resource
(key)Gets the shared resource for this type of playback implementation under the given key.
has_shared_resource
(key)Checks whether there is a shared resource for this type of playback implementation under the given key.
set_host_instrument
(host_instrument)Sets the host instrument for this PlaybackImplementation.
set_max_pitch_bend
(semitones)Method that sets the max pitch bend for MIDI-based playback implementations This is only relevant when playback is happening via the MIDI protocol.
set_shared_resource
(key, value)Sets a shared resource for this type of playback implementation under the given key.
start_note
(note_id, pitch, volume, properties)Method that implements the start of a note
Inherited Methods
Returns a copy of this object by serializing to and from JSON.
Dump this object as a JSON string.
json_loads
(s)Load this object from a JSON string.
load_from_json
(file_path)Load this object from a JSON file with the given path.
save_to_json
(file_path)Save this object to a JSON file using the given path.
Attributes
Dictionary of shared resources for this type of playback implementation.
-
set_host_instrument
(host_instrument: scamp.instruments.ScampInstrument)[source]¶ Sets the host instrument for this PlaybackImplementation. Ordinarily, the host instrument is supplied as an argument to the __init__ method, which then automatically calls this method. However, it is also possible to pass the value None to the host instrument argument initially and later set it with this method.
- Parameters
host_instrument – The
ScampInstrument
that will use this playback implementation for playback. This PlaybackImplementation will be added to the host instrument’s playback_implementations attribute.
-
property
resource_dictionary
¶ Dictionary of shared resources for this type of playback implementation. For instance, SoundfontPlaybackImplementation uses this to store an instance of SoundfontHost. Only one instance of fluidsynth (and therefore SoundfontHost) needs to be running for all instruments in the ensemble, so this is a way of pooling that resource.
Checks whether there is a shared resource for this type of playback implementation under the given key.
- Parameters
key – key name for this resource
Gets the shared resource for this type of playback implementation under the given key.
- Parameters
key – key name for this resource
Sets a shared resource for this type of playback implementation under the given key.
- Parameters
key – key name for this resource
value – value to set for that key
-
abstract
start_note
(note_id: int, pitch: float, volume: float, properties: dict, other_parameter_values: dict = None) → None[source]¶ Method that implements the start of a note
- Parameters
note_id – unique identifier for the note we are starting
pitch – floating-point MIDI pitch value
volume – floating-point volume value (from 0 to 1)
properties – a NotePropertiesDictionary
other_parameter_values – dictionary mapping parameter name to parameter value for parameters other than pitch and volume. (This information was extracted from the properties dictionary.)
-
abstract
end_note
(note_id: int) → None[source]¶ Method that implements the end of a note
- Parameters
note_id – unique identifier of the note to end
-
abstract
change_note_pitch
(note_id: int, new_pitch: float) → None[source]¶ Method that implements the change of a note’s pitch
- Parameters
note_id – unique identifier of the note whose pitch to change
new_pitch – new (floating-point) MIDI pitch value
-
abstract
change_note_volume
(note_id: int, new_volume: float) → None[source]¶ Method that implements the change of a note’s volume
- Parameters
note_id – unique identifier of the note whose volume to change
new_volume – new floating point volume value from 0 to 1
-
abstract
change_note_parameter
(note_id: int, parameter_name: str, new_value: float) → None[source]¶ Method that implements the change of a parameter other than pitch or volume
- Parameters
note_id – unique identifier of the note to effect
parameter_name – name of the parameter to change
new_value – new floating-point value of that parameter
-
abstract
set_max_pitch_bend
(semitones: int) → None[source]¶ Method that sets the max pitch bend for MIDI-based playback implementations This is only relevant when playback is happening via the MIDI protocol.
- Parameters
semitones – unique identifier of the note to effect
-
duplicate
() → T¶ Returns a copy of this object by serializing to and from JSON.
-
json_dumps
() → str¶ Dump this object as a JSON string. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.
-
classmethod
json_loads
(s: str) → T¶ Load this object from a JSON string. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).
- Parameters
s – a string representing this object in JSON format
-
classmethod
load_from_json
(file_path: str) → T¶ Load this object from a JSON file with the given path. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).
- Parameters
file_path – path for loading the file
-
save_to_json
(file_path: str) → None¶ Save this object to a JSON file using the given path. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.
- Parameters
file_path – path for saving the file