scamp.playback_implementations.SoundfontPlaybackImplementation
- class scamp.playback_implementations.SoundfontPlaybackImplementation(bank_and_preset: tuple[int, int] = (0, 0), soundfont: str = 'default', num_channels: int = 8, audio_driver: str = 'default', max_pitch_bend: int = 'default', note_on_and_off_only: bool = False)[source]
Bases:
_MIDIPlaybackImplementation
Playback implementation that does Soundfont playback, via the MIDI protocol.
- Parameters:
bank_and_preset – The bank and preset within the given soundfont to use for playback
soundfont – String representing the soundfont to use for playback. Defaults to the one defined in playback_settings.default_soundfont
num_channels – How many MIDI channels to use for this instrument. Where channel-wide messages (such as pitch-bend messages) are involved, it is essential to have several channels at our disposal.
audio_driver – name of the audio_driver to use. Defaults to the one defined in playback_settings.default_audio_driver
max_pitch_bend – max pitch bend allowed on this instrument. Defaults to the one defined in playback_settings.default_max_soundfont_pitch_bend.
note_on_and_off_only – This enforces a rule of no dynamic pitch bends, expression (volume) changes, or other cc messages. Valuable when using
start_note
instead ofplay_note
in music that doesn’t do any dynamic pitch/volume/parameter changes. Without this flag, notes will all be placed on separate MIDI channels, since they could potentially change pitch or volume; with this flags, we know they won’t, so they can share the same MIDI channels, only using an extra one due to microtonality.
Methods
cc
(chan, cc_number, value_from_0_to_1)Sends an arbitrary midi CC message
expression
(chan, expression_from_0_to_1)Sends a midi expression message
note_off
(chan, pitch)Sends a note_off MIDI message
note_on
(chan, pitch, velocity_from_0_to_1)Sends a note_on MIDI message
pitch_bend
(chan, bend_in_semitones)Sends a MIDI pitch bend message
set_max_pitch_bend
(semitones)Sets the max pitch bend for this MIDI device
Inherited 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
Returns a copy of this object by serializing to and from JSON.
end_note
(note_id)Method that implements the end of a note
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.
start_note
(note_id, pitch, volume, ...)Method that implements the start of a note
Attributes
- soundfont_hosts = {}
- note_on(chan: int, pitch: int, velocity_from_0_to_1: float)[source]
Sends a note_on MIDI message
- Parameters:
chan – channel to send message on
pitch – integer MIDI pitch value
velocity_from_0_to_1 – velocity to send (NB: scaled from 0 to 1)
- note_off(chan: int, pitch: int)[source]
Sends a note_off MIDI message
- Parameters:
chan – channel to send message on
pitch – integer MIDI pitch value
- pitch_bend(chan: int, bend_in_semitones: float)[source]
Sends a MIDI pitch bend message
- Parameters:
chan – channel to send message on
bend_in_semitones – the pitch bend amount (in semitones!)
- set_max_pitch_bend(semitones: int)[source]
Sets the max pitch bend for this MIDI device
- Parameters:
max_bend_in_semitones – value to set as maximum pitch bend
- expression(chan: int, expression_from_0_to_1: float)[source]
Sends a midi expression message
- Parameters:
chan – channel to send message on
expression_from_0_to_1 – expression to send (NB: scaled from 0 to 1)
- Returns:
- cc(chan: int, cc_number: int, value_from_0_to_1: float)[source]
Sends an arbitrary midi CC message
- Parameters:
chan – channel to send the message on
cc_number – number representing the type of the control change message
value_from_0_to_1 – value to send (NB: scaled from 0 to 1)
- change_note_parameter(note_id, parameter_name, new_value)
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
- change_note_pitch(note_id, new_pitch)
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
- change_note_volume(note_id, new_volume)
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
- duplicate() T
Returns a copy of this object by serializing to and from JSON.
- end_note(note_id)
Method that implements the end of a note
- Parameters:
note_id – unique identifier of the note to end
- 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
- start_note(note_id, pitch, volume, properties, note_info_dict)
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.)
note_info_dict – dictionary with auxiliary info about this note (e.g. the clock it’s running on, time stamp, various flags)