scamp.score.Score

class scamp.score.Score(parts: Optional[Sequence[Staff | StaffGroup]] = None, title: Optional[str] = None, composer: Optional[str] = None, tempo_envelope: Optional[TempoEnvelope] = None)[source]

Bases: ScoreComponent, ScoreContainer

Representation of a score in traditional western notation. Exportable as either LilyPond or MusicXML.

Parameters:
  • parts – A list of parts represented by either StaffGroup or Staff objects

  • title – title to be used

  • composer – composer to be used

  • tempo_envelope – a TempoEnvelope function describing how the tempo changes over time

Variables:
  • title – title to be used in the score

  • composer – composer to be written on the score

  • tempo_envelope – a TempoEnvelope function describing how the tempo changes over time

  • final_barline – what barline to use at the end of the score. Must be one of: “double”, “end”, “regular”, “dotted”, “dashed”, “heavy”, “light-light” (same as “double”), “light-heavy” (same as “end”), “heavy-light”, “heavy-heavy”, “tick”, “short”, or “none”.

Methods

from_performance(performance[, ...])

Builds a new Score from a Performance (list of note events in continuous time and pitch).

from_quantized_performance(performance[, ...])

Constructs a new Score from an already quantized Performance.

length()

Length of this score in beats.

print_lilypond([wrap_as_file, non_score_blocks])

Convert and print LilyPond code, via the abjad library.

to_abjad([wrap_as_file, non_score_blocks])

Convert this score component to its corresponding abjad component

to_lilypond([wrap_as_file, non_score_blocks])

Convert to LilyPond code, via the abjad library.

to_music_xml()

Convert this score component to its corresponding pymusicxml component

Inherited Methods

append(item)

Add a child ScoreComponent of the appropriate type

export_lilypond(file_path[, non_score_blocks])

Convert and wrap as a LilyPond (.ly) file, and save to the given path.

export_music_xml(file_path[, pretty_print])

Convert and wrap as a MusicXML score, and save to the given path.

export_pdf(file_path[, non_score_blocks])

Exports score as a PDF file and saves it to the given file_path

extend(items)

Add several child ScoreComponents of the appropriate type

index(item)

Get the index of the given child ScoreComponent

insert(index, item)

Insert a child ScoreComponent at the given index.

pop([i])

Pop and return the child ScoreComponent at the given index.

print_music_xml([pretty_print])

Convert and wrap as a MusicXML score, and print the resulting XML.

remove(item)

Remove the given child ScoreComponent.

show([non_score_blocks])

Using the abjad.show command, generates and opens a PDF of the music represented by this component

show_xml()

Convert and wrap as a MusicXML score, and open it up in notation software.

Attributes

parts

List of parts (StaffGroup or Staff objects).

staves

List of all staves in this score, expanding out those inside of StaffGroups.

property parts: Sequence[Staff | StaffGroup]

List of parts (StaffGroup or Staff objects).

property staves: Sequence[Staff]

List of all staves in this score, expanding out those inside of StaffGroups.

length() float[source]

Length of this score in beats. (i.e. end beat of the last measure in any of the parts)

classmethod from_performance(performance: Performance, quantization_scheme: Optional[QuantizationScheme] = None, time_signature: Optional[Union[str, Sequence]] = None, bar_line_locations: Optional[Sequence[float]] = None, max_divisor: Optional[int] = None, max_divisor_indigestibility: Optional[int] = None, simplicity_preference: Optional[float] = None, title: str = 'default', composer: str = 'default') Score[source]

Builds a new Score from a Performance (list of note events in continuous time and pitch). In the process, the music must be quantized, for which two different options are available: one can either pass a QuantizationScheme to the first argument, which is very flexible but rather verbose to create, or one can specify arguments such as time_signature and max_divisor directly.

Parameters:
  • performance – The Performance object we are building the score from.

  • quantization_scheme – The quantization scheme to be used when converting this performance into a score. If this is defined, none of the other quantization-related arguments should be defined.

  • time_signature – the time signature to be used, represented as a string, e.g. “3/4”, or a tuple, e.g. (3, 2). Alternatively, a list of time signatures can be given. If this list ends in “loop”, then the pattern specified by the list will be looped. For example, [“4/4”, “2/4”, “3/4”, “loop”] will cause the fourth measure to be in “4/4”, the fifth in “2/4”, etc. If the list does not end in “loop”, all measures after the final time signature specified will continue to be in that time signature.

  • bar_line_locations – As an alternative to defining the time signatures, a list of numbers representing the bar line locations can be given. For instance, [4.5, 6.5, 8, 11] would result in bars of time signatures 9/8, 2/4, 3/8, and 3/4

  • max_divisor – The largest divisor that will be allowed to divide the beat.

  • max_divisor_indigestibility – Indigestibility, devised by composer Clarence Barlow, is a measure of the “primeness” of a beat divisor, and therefore of its complexity from the point of view of a performer. For instance, it is easier to divide a beat in 8 than in 7, even though 7 is a smaller number. See Clarence’s paper here: https://mat.ucsb.edu/Publications/Quantification_of_Harmony_and_Metre.pdf. By setting a max indigestibility, we can allow larger divisions of the beat, but only so long as they are easy ones. For instance, a max_divisor of 16 and a max_divisor_indigestibility of 8 would allow the beat to be divided in 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, and 16.

  • simplicity_preference – This defines the degree to which the quantizer will favor simple divisors. The higher the simplicity preference, the more precisely the notes have to fit for you to get a divisor like 7. Simplicity preference can range from 0 (in which case the divisor is chosen simply based on the lowest error) to infinity, with a typical value somewhere around 1.

  • title – Title of the piece to be printed on the score.

  • composer – Composer of the piece to be printed on the score.

Returns:

the resulting Score object, which can then be rendered either as XML or LilyPond

classmethod from_quantized_performance(performance: Performance, title: str = 'default', composer: str = 'default') Score[source]

Constructs a new Score from an already quantized Performance.

Parameters:
  • performance – the quantized Performance to convert into a new score

  • title – title to give the score

  • composer – composer to put on the score

to_music_xml() Score[source]

Convert this score component to its corresponding pymusicxml component

to_abjad(wrap_as_file: bool = True, non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) Component[source]

Convert this score component to its corresponding abjad component

Parameters:
  • wrap_as_file – if True, wraps this as an abjad.LilypondFile

  • non_score_blocks – (Only applicable if wrap_as_file is set to True). A list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad). Typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

to_lilypond(wrap_as_file: bool = True, non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) str[source]

Convert to LilyPond code, via the abjad library.

Parameters:
  • wrap_as_file – if True, wraps this as an abjad.LilypondFile

  • non_score_blocks – (Only applicable if wrap_as_file is set to True). A list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad). Typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

Returns:

a string containing the LilyPond code

print_lilypond(wrap_as_file: bool = True, non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) None[source]

Convert and print LilyPond code, via the abjad library.

Parameters:
  • wrap_as_file – if True, wraps this as an abjad.LilypondFile

  • non_score_blocks – (Only applicable if wrap_as_file is set to True). A list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad). Typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

append(item: ScoreComponent) None

Add a child ScoreComponent of the appropriate type

export_lilypond(file_path: str, non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) None

Convert and wrap as a LilyPond (.ly) file, and save to the given path.

Parameters:
  • file_path – file path to save to

  • non_score_blocks – a list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad); typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

export_music_xml(file_path: str, pretty_print: bool = True) None

Convert and wrap as a MusicXML score, and save to the given path.

Parameters:
  • file_path – file path to save to

  • pretty_print – whether or not to take the extra space and format the file with indentations, etc.

export_pdf(file_path: str, non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) None

Exports score as a PDF file and saves it to the given file_path

Parameters:
  • file_path – where to save the PDF

  • non_score_blocks – a list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad); typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

extend(items) None

Add several child ScoreComponents of the appropriate type

index(item) int

Get the index of the given child ScoreComponent

insert(index, item) None

Insert a child ScoreComponent at the given index.

pop(i=-1) ScoreComponent

Pop and return the child ScoreComponent at the given index.

print_music_xml(pretty_print: bool = True) None

Convert and wrap as a MusicXML score, and print the resulting XML.

Parameters:

pretty_print – whether or not to take the extra space and format the file with indentations, etc.

remove(item) None

Remove the given child ScoreComponent.

show(non_score_blocks: Optional[Sequence] = None, **lilypond_file_args) None

Using the abjad.show command, generates and opens a PDF of the music represented by this component

Parameters:
  • non_score_blocks – a list of abjad.Block objects (or strings containing the LilyPond code for such a block, which are then parsed by abjad); typical blocks might be a header block, a layout block, or a paper block. If no header block is specified, one will be created with the score’s title and composer. If a header is specified, title and composer will be added if not present.

  • lilypond_file_args – any additional keyword arguments will be passed along to the constructor of abjad.LilyPondFile (assuming wrap_as_file is True). This allows for setting staff size and various other customizations.

show_xml() None

Convert and wrap as a MusicXML score, and open it up in notation software. (The software to use is defined in engraving_settings.show_music_xml_command_line.)