scamp.performance.PerformancePart

class scamp.performance.PerformancePart(instrument: scamp.instruments.ScampInstrument = None, name: str = None, voices: Union[dict, Sequence] = None, instrument_id: Tuple[str, int] = None, voice_quantization_records: dict = None, clef_preference: Sequence[Union[str, Tuple[str, numbers.Real]]] = None)[source]

Bases: expenvelope.json_serializer.SavesToJSON

Transcription of the notes played by a single ScampInstrument. Can be saved to and loaded from a json file and played back on a clock.

Parameters
  • instrument – the ScampInstrument associated with this part; used for playback

  • name – The name of this part

  • voices – either a list of PerformanceNotes (which is interpreted as one unnamed voice), a list of lists of PerformanceNotes (which is interpreted as several numbered voices), or a dictionary mapping voice names to lists of notes.

  • instrument_id – a json serializable record of the instrument used

  • voice_quantization_records – a record of how this part was quantized if it has been quantized

Variables
  • instrument – the ScampInstrument associated with this part; used for playback

  • name – The name of this part

  • voices – dictionary mapping voice names to lists of notes.

  • instrument_id – a json serializable record of the instrument used

  • voice_quantization_records – dictionary mapping voice names to QuantizationRecords, if this is quantized

Methods

add_note(note[, voice])

Add a new Performance note to this PerformancePart.

get_note_iterator([start_beat, stop_beat, …])

Returns an iterator returning all the notes from start_beat to stop_beat in the selected voices

is_quantized()

Checks if this part has been quantized

name_count()

When there are multiple instrument of the same name in an ensemble, keeps track of which one we mean

new_note(start_beat, length, pitch, volume, …)

Construct and add a new PerformanceNote to this Performance

num_measures()

If this PerformancePart has been quantized, gets the number of measures

play([start_beat, stop_beat, instrument, …])

Play this PerformancePart (or a selection of it)

quantize([quantization_scheme, …])

Quantizes this PerformancePart according to the quantization_scheme

quantized([quantization_scheme, …])

Same as quantize, except that it returns a new copy, rather than changing this PerformancePart in place.

set_instrument(instrument)

Set the instrument with which this PerformancePart will play back by default

set_instrument_from_ensemble(ensemble)

Set the default instrument to play back with based on the best fit in the given ensembel

to_staff_group()

Converts this PerformancePart to a StaffGroup object.

Inherited Methods

duplicate()

Returns a copy of this object by serializing to and from JSON.

json_dumps()

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

end_beat

End beat of the last note in this part.

measure_lengths

If this PerformancePart has been quantized, gets the lengths of all the measures

add_note(note: scamp.performance.PerformanceNote, voice: str = None)scamp.performance.PerformanceNote[source]

Add a new Performance note to this PerformancePart.

Parameters
  • note – the note to add

  • voice – name of the voice to which to add it (defaults to “_unspecified_”)

Returns

the note you just added (for chaining purposes)

new_note(start_beat: float, length, pitch, volume, properties: dict)scamp.performance.PerformanceNote[source]

Construct and add a new PerformanceNote to this Performance

Parameters
  • start_beat – the start beat of the note

  • length – length of the note in beats (either a float or a list of floats representing tied segments)

  • pitch – pitch of the note (float, Envelope, or list to interpret as an envelope)

  • volume – volume of the note (float or Envelope, or list to interpret as an envelope)

  • properties – dictionary of note properties, or string representing those properties

Returns

the note just added

set_instrument(instrument: scamp.instruments.ScampInstrument) → None[source]

Set the instrument with which this PerformancePart will play back by default

Parameters

instrument – the instrument to use

property end_beat

End beat of the last note in this part.

get_note_iterator(start_beat: float = 0, stop_beat: float = None, selected_voices: Sequence[str] = None) → Iterator[scamp.performance.PerformanceNote][source]

Returns an iterator returning all the notes from start_beat to stop_beat in the selected voices

Parameters
  • start_beat – beat to start on

  • stop_beat – beat to stop on (None keeps going until the end of the part)

  • selected_voices – which voices to take notes from (defaults to all if None)

Returns

an iterator

play(start_beat: float = 0, stop_beat: float = None, instrument: scamp.instruments.ScampInstrument = None, clock: clockblocks.clock.Clock = None, blocking: bool = True, tempo_envelope: clockblocks.tempo_envelope.TempoEnvelope = None, selected_voices: Sequence[str] = None, note_filter: Callable[[scamp.performance.PerformanceNote], scamp.performance.PerformanceNote] = None)clockblocks.clock.Clock[source]

Play this PerformancePart (or a selection of it)

Parameters
  • start_beat – Place to start playing from

  • stop_beat – Place to stop playing at

  • instrument – instrument to play back with

  • clock – clock to use for playback

  • blocking – if True, don’t return until the part is done playing; if False, return immediately

  • tempo_envelope – (optional) a tempo envelope to use for playback

  • selected_voices – which voices to play back (defaults to all if None)

  • note_filter – a function that takes the PerformanceNote about to be played and returns a modified PerformanceNote to play. NB: this will modify the original note unless the input to the function is duplicated and left unaltered!

Returns

the Clock on which playback takes place

set_instrument_from_ensemble(ensemble: scamp.instruments.Ensemble)scamp.performance.PerformancePart[source]

Set the default instrument to play back with based on the best fit in the given ensembel

Parameters

ensemble – the ensemble to search in

Returns

self

quantize(quantization_scheme: scamp.quantization.QuantizationScheme = 'default', onset_weighting: float = 'default', termination_weighting: float = 'default')scamp.performance.PerformancePart[source]

Quantizes this PerformancePart according to the quantization_scheme

Parameters
  • quantization_scheme – the QuantizationScheme to use. If “default”, uses the default time signature defined in the quantization_settings.

  • onset_weighting – how much to weight note onsets in the quantization. If “default”, uses the default value defined in the quantization_settings.

  • termination_weighting – how much to weight note terminations in the quantization. If “default”, uses the default value defined in the quantization_settings.

Returns

this PerformancePart, having been quantized

quantized(quantization_scheme: scamp.quantization.QuantizationScheme = 'default', onset_weighting: float = 'default', termination_weighting: float = 'default')scamp.performance.PerformancePart[source]

Same as quantize, except that it returns a new copy, rather than changing this PerformancePart in place.

Parameters
  • quantization_scheme – the QuantizationScheme to use. If “default”, uses the default time signature defined in the quantization_settings.

  • onset_weighting – how much to weight note onsets in the quantization. If “default”, uses the default value defined in the quantization_settings.

  • termination_weighting – how much to weight note terminations in the quantization. If “default”, uses the default value defined in the quantization_settings.

Returns

a quantized copy of this PerformancePart

is_quantized() → bool[source]

Checks if this part has been quantized

Returns

True if quantized, False if not

property measure_lengths

If this PerformancePart has been quantized, gets the lengths of all the measures

Returns

list of measure lengths

num_measures() → int[source]

If this PerformancePart has been quantized, gets the number of measures

Returns

number of measures

to_staff_group()scamp.score.StaffGroup[source]

Converts this PerformancePart to a StaffGroup object. (Quantizes in a default way, if necessary, but it should be quantized already.)

Returns

a new StaffGroup made from this PerformancePart

name_count() → int[source]

When there are multiple instrument of the same name in an ensemble, keeps track of which one we mean

Returns

int representing which instrument we mean

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