scamp.performance.PerformanceNote

class scamp.performance.PerformanceNote(start_beat: float, length: Union[float, Tuple[float]], pitch: Union[float, expenvelope.envelope.Envelope, Sequence], volume: Union[float, expenvelope.envelope.Envelope], properties: dict)[source]

Bases: expenvelope.json_serializer.SavesToJSON

Represents a single note played by a ScampInstrument.

Parameters
  • start_beat – the start beat of the note

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

  • pitch – the pitch of the note (float or Envelope)

  • volume – the volume of the note (float or Envelope)

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

Variables
  • start_beat – the start beat of the note

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

  • pitch – the pitch of the note (float or Envelope); note that this can also be a tuple of pitches representing a chord, but that this usually happens in the process of quantization when notes that can be merged into chords are merged.

  • volume – the volume of the note (float or Envelope)

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

Methods

attempt_chord_merger_with(other)

Try to merge this note with another note to form a chord.

average_pitch()

Averages the pitch of this note, accounting for if it’s a glissando or a chord

length_sum()

Total length of this note, adding together any tied segments.

next_id()

Return a new unique ID number for this note, different from all PerformanceNotes created so far.

play(instrument[, clock, blocking])

Play this note with the given instrument on the given clock

split_at_beat(split_beat)

Splits this note at the given beat, returning a tuple of the pieces created

split_at_length_divisions()

If the self.length is a tuple, indicating a set of tied constituents, splits this into separate PerformanceNotes

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 this note

length_sum() → float[source]

Total length of this note, adding together any tied segments. (The attribute “length” can be a list of floats representing tied segments.)

Returns

length of note as a float

property end_beat

End beat of this note

average_pitch() → float[source]

Averages the pitch of this note, accounting for if it’s a glissando or a chord

Returns

the averaged pitch as a float

play(instrument: scamp.instruments.ScampInstrument, clock: clockblocks.clock.Clock = None, blocking: bool = True) → None[source]

Play this note with the given instrument on the given clock

Parameters
  • instrument – instrument to play back with

  • clock – the clock to play back on (if None, infers it from context)

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

static next_id() → int[source]

Return a new unique ID number for this note, different from all PerformanceNotes created so far.

Returns

id number (int)

split_at_beat(split_beat: float) → Sequence[scamp.performance.PerformanceNote][source]

Splits this note at the given beat, returning a tuple of the pieces created

Parameters

split_beat – where to split (relative to the performance start time, not the note start time)

Returns

tuple of (first half note, second half note) if split beat is within the note. Otherwise just return the unchanged note in a length-1 tuple.

split_at_length_divisions() → Sequence[scamp.performance.PerformanceNote][source]

If the self.length is a tuple, indicating a set of tied constituents, splits this into separate PerformanceNotes

Returns

a list of pieces

attempt_chord_merger_with(other: scamp.performance.PerformanceNote) → bool[source]

Try to merge this note with another note to form a chord. Returns whether it worked or not, and when it did, has the side effect of changing this note into a chord that incorporates the other note.

Parameters

other – another PerformanceNote

Returns

True if the merger works, False otherwise

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