muspy.visualization

Visualization tools.

This module provides functions for visualizing a Music object.

Classes

  • ScorePlotter

Functions

  • show
  • show_pianoroll
  • show_score
muspy.visualization.show(music: Music, kind: str, **kwargs)[source]

Show visualization.

Parameters:
  • music (muspy.Music) – Music object to convert.
  • kind ({'piano-roll', 'score'}) – Target representation.
muspy.visualization.show_pianoroll(music: Music, **kwargs)[source]

Show pianoroll visualization.

muspy.visualization.show_score(music: Music, figsize: Tuple[float, float] = None, clef: str = 'treble', clef_octave: int = 0, note_spacing: int = None, font_path: Union[str, pathlib.Path] = None, font_scale: float = None) → muspy.visualization.score.ScorePlotter[source]

Show score visualization.

Parameters:
  • music (muspy.Music) – Music object to show.
  • figsize ((float, float), optional) – Width and height in inches. Defaults to Matplotlib configuration.
  • clef ({'treble', 'alto', 'bass'}, default: 'treble') – Clef type.
  • clef_octave (int, default: 0) – Clef octave.
  • note_spacing (int, default: 4) – Spacing of notes.
  • font_path (str or Path, optional) – Path to the music font. Defaults to the path to the downloaded Bravura font.
  • font_scale (float, default: 140) – Font scaling factor for finetuning. The default value of 140 is optimized for the default Bravura font.
Returns:

A ScorePlotter object that handles the score.

Return type:

muspy.ScorePlotter

class muspy.visualization.ScorePlotter(fig: matplotlib.figure.Figure, ax: matplotlib.axes._axes.Axes, resolution: int, note_spacing: int = None, font_path: Union[str, pathlib.Path] = None, font_scale: float = None)[source]

A plotter that handles the score visualization.

fig

Figure object to plot the score on.

Type:matplotlib.figure.Figure
axes

Axes object to plot the score on.

Type:matplotlib.axes.Axes
resolution

Time steps per quarter note.

Type:int
note_spacing

Spacing of notes.

Type:int, default: 4
font_path

Path to the music font. Defaults to the path to the downloaded Bravura font.

Type:str or Path, optional
font_scale

Font scaling factor for finetuning. The default value of 140 is optimized for the default Bravura font.

Type:float, default: 140
adjust_fonts(scale: float = None)[source]

Adjust the fonts.

plot_bar_line() → matplotlib.lines.Line2D[source]

Plot a bar line.

plot_clef(kind='treble', octave=0) → matplotlib.text.Text[source]

Plot a clef.

plot_final_bar_line() → List[matplotlib.artist.Artist][source]

Plot an ending bar line.

plot_key_signature(root: int, mode: str)[source]

Plot a key signature. Supports only major and minor keys.

plot_note(time, duration, pitch) → Optional[Tuple[List[matplotlib.text.Text], List[matplotlib.patches.Arc]]][source]

Plot a note.

plot_object(obj)[source]

Plot an object.

plot_staffs(start: float = None, end: float = None) → List[matplotlib.lines.Line2D][source]

Plot the staffs.

plot_tempo(qpm) → List[matplotlib.artist.Artist][source]

Plot a tempo as a metronome mark.

plot_time_signature(numerator: int, denominator: int) → List[matplotlib.text.Text][source]

Plot a time signature.

set_baseline(y)[source]

Set baseline position (y-coordinate of first staff line).

update_boundaries(left: float = None, right: float = None, bottom: float = None, top: float = None)[source]

Update boundaries.