brown.core.chordrest

classes

A chord or a rest.

This is a general unified interface for conventionally notated musical notes/chords/rests. It can be given any number of pitches to be used as notes in the chord, or None for a rest.

It will automatically generate and lay out:

  • Noteheads if pitches are given
  • a Stem if pitches are given and required by the given Duration
  • a Flag if pitches are given and required by the given Duration
  • LedgerLines as needed (taking into consideration the given pitches and their location on the Staff)
  • Accidentals as needed by any given pitches
  • a Rest if no pitches are given
  • RhythmDots if needed by the given Duration

Create all required ledger lines and store them in self.ledgers

Returns: None

Warning: This should be called after _position_noteheads_horizontally() as it relies on the position of noteheads in the chord to calculate the position and length of the ledger lines

Create all the RhythmDots needed by this Chordrest.

Create a Stem and stores it in self.stem.

Returns: None

Create a Flag attached to self.stem and store it in self.flag

Returns: None

Reposition noteheads so that they are laid out correctly

Decides which noteheads lie on which side of the staff, and modifies positions when needed.

Returns: None

Reposition accidentals so that they are laid out correctly

TODO: Implement me

Returns: None

__init__ (pos_x, staff, pitches, duration, stem_direction=None) permalink view source

overriden from GraphicObject

arguments:

pos_x (Unit): The horizontal position

staff (Staff): The staff the object is attached to

pitches (list[str] or None): A list of pitch strings representing noteheads. An empty list indicates a rest.

duration (Beat): The duration of the Chordrest

stem_direction (int or None): An optional stem direction override where 1 points down and -1 points up. If omitted, the direction is automatically calculated to point away from the furthest-out notehead.

properties

noteheads: set(Notehead) The noteheads contained in this Chordrest. permalink view source

read-only.

rest: Rest or None A Rest glyph, if no noteheads exist. permalink view source

accidentals: set(Accidental) The accidentals contained in this Chordrest. permalink view source

read-only.

ledgers: set(LedgerLine) The ledger lines contained in this Chordrest. permalink view source

An empty set means no ledgers.

read-only.

stem: Stem or None The Stem for the Chordrest. permalink view source

read-only.

flag: Flag or None The flag attached to the stem. permalink view source

read-only.

duration: Beat The length of this event. permalink view source

This is used to determine which (if any) Flags, RhythmDots, and Notehead/Rest styles. Higher level managers may also use this information to inform layout decisions and Beam groupings.

ledger_line_positions: set(int) A set of staff positions of needed ledger lines. permalink view source

Positions are in centered staff positions.

An empty set means no ledger lines are needed.

read-only.

rhythm_dot_positions: iter(Point) The positions of all rhythm dots needed. permalink view source

read-only.

furthest_notehead: Notehead or None The Notehead furthest from the staff center permalink view source

read-only.

highest_notehead: Notehead or None The highest Notehead in the chord. permalink view source

read-only.

lowest_notehead: Notehead or None The lowest Notehead in the chord. permalink view source

read-only.

leftmost_notehead: Notehead or None the Notehead furthest to the left in the chord permalink view source

read-only.

rightmost_notehead: Notehead or None the Notehead furthest to the right in the chord permalink view source

read-only.

widest_notehead: Notehead or None the Notehead with the greatest visual_width permalink view source

read-only.

notehead_column_width: Unit The total width of all Noteheads in the chord permalink view source

read-only.

noteheads_outside_staff: set(Notehead) All noteheads which are above or below the staff permalink view source

read-only.

leftmost_notehead_outside_staff: Notehead or None the Notehead furthest to the left outside the staff permalink view source

read-only.

rightmost_notehead_outside_staff: Notehead or None the Notehead furthest to the right outside the staff permalink view source

read-only.

notehead_column_outside_staff_width: Unit The total width of any noteheads outside the staff permalink view source

read-only.

stem_direction: int The direction of the stem, either 1 (down) or -1 (up) permalink view source

Takes the notehead furthest from the center of the staff, and returns the opposite direction.

If the furthest notehead is in the center of the staff, the direction defaults to 1.

This automatically calculated property may be overridden using its setter. To revert back to the automatically calculated value set this property to None.

stem_height: Unit The height of the stem permalink view source

read-only.

inherited properties

staff: Staff The staff associated with this object permalink view source

read-only.

inherited from StaffObject

pos_in_staff: Point The position of this object relative to the staff. permalink view source

This position is in non-flowed space.

# TODO: Definitely cache me when property caching is implemented

read-only.

inherited from StaffObject

interfaces: set(GraphicObjectInterface) The interfaces for this object permalink view source

Interface objects are created upon calling GraphicObject.render()

Typically each GraphicObject will have one interface for each flowable line it appears in. Objects which fit completely in one visual line will typically have exactly one interface.

If this is an empty set, the object has not been rendered yet with the render() method.

read-only.

inherited from GraphicObject

pos: Point The position of the object relative to its parent. permalink view source

inherited from GraphicObject

x: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

y: Unit The x position of the object relative to its parent. permalink view source

inherited from GraphicObject

length: Unit The breakable length of the object. permalink view source

This is used to determine how and where rendering cuts should be made.

read-only.

inherited from GraphicObject

pen: Pen The pen to draw outlines with permalink view source

inherited from GraphicObject

brush: Brush The brush to draw outlines with permalink view source

As a convenience, this may be set with a hex color string for a solid color brush of that color. For brushes using alpha channels and non-solid-color fill patterns, a fully initialized brush must be passed to this.

inherited from GraphicObject

parent: GraphicObject The parent object. permalink view source

If this is set to None, it defaults to the first page of the document.

inherited from GraphicObject

children: set(GraphicObject) All objects who have self as their parent. permalink view source

inherited from GraphicObject

descendants: iter[GraphicObject] All of the objects in the children subtree. permalink view source

This recursively searches all of the object's children (and their children, etc.) and provides an iterator over them.

The current implementation performs a simple recursive DFS over the tree, and has the potential to be rather slow.

read-only.

inherited from GraphicObject

ancestors: iter[GraphicObject] All ancestors of this object. permalink view source

Follows the chain of parents until a document page is reached. The iterable will not include the document Page.

The order begins with self.parent and traverses upward in the tree.

read-only.

inherited from GraphicObject

flowable: Flowable or None The flowable this object belongs in. permalink view source

read-only.

inherited from GraphicObject

page_index: The index of the page this object appears on. permalink view source

>>> from brown.core import brown; brown.setup()
>>> some_object = GraphicObject((Mm(20), Mm(50)),
...                             parent=brown.document.pages[5])
>>> some_object.page_index
5
>>> some_object in brown.document.pages[5].descendants
True

read-only.

inherited from GraphicObject

inherited class methods

map_between_items (source, destination) permalink view source

Find a GraphicObject's position relative to another GraphicObject

arguments:

source (GraphicObject): The object to map from

destination (GraphicObject): The object to map to

returns:

Point: The canvas position of destination relative to source

inherited from GraphicObject

inherited static methods

find_staff (graphic_object) permalink view source

Find the first staff which is graphic_object or an ancestor of it.

arguments:

graphic_object (GraphicObject):

returns:

Staff or None

inherited from StaffObject

inherited methods

descendants_of_class_or_subclass (graphic_object_class) permalink view source

Yield all child descendants with a given class or its subclasses.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

descendants_of_exact_class (graphic_object_class) permalink view source

Yield all child descendants with a given class.

Args: graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

Yields: GraphicObject

inherited from GraphicObject

first_ancestor_of_class_or_subclass (graphic_object_class) permalink view source

Get the closest ancestor with a class or its subclasses.

arguments:

graphic_object_class (type): The type to search for. This should be a subclass of GraphicObject.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject

first_ancestor_of_exact_class (graphic_object_class) permalink view source

Get the closest ancestor with a class.

arguments:

graphic_object_class (type or str): The type to search for. This should be a subclass of GraphicObject. A str of a class name may also be used.

returns:

GraphicObject or None

If none can be found, returns None.

inherited from GraphicObject