neoscore.western.clef

class neoscore.western.clef.Clef[source]

Bases: MusicText, StaffObject

A graphical and logical staff clef.

These are drawn at the initially specified position, and at the beginning of new lines in the parent Staff until a new Clef is encountered or the end of the Staff.

Staff uses these to map pitches to vertical positions.

__init__(pos_x: Unit, staff: Staff, clef_type: Union[ClefType, str], font: Optional[MusicFont] = None, brush: Optional[Union[Brush, str]] = None, pen: Optional[Union[Pen, str]] = None)[source]
Parameters
  • pos_x – The x position in the staff

  • staff – The parent staff

  • clef_type – The type of clef. String names of common clefs may be given as a convenience; see ClefTypeDef.

  • font – The font used. Defaults to the staff’s font.

  • brush – The brush to fill in text shapes with.

  • pen – The pen to trace text outlines with. This defaults to no pen.

property clef_type: ClefType

The type of clef, both logical and graphical.

breakable_length

Find the length in the staff during which this clef is active.

This is defined as the distance relative to the staff until the next clef is encountered. If no further clefs are found, this is the remaining length of the staff.

property middle_c_staff_position: Unit

The vertical position of middle C for this clef

0 means exactly at the top staff line. Positive values extend downward below the top staff line while negative values extend upward above the top staff line.

This value is primarily useful in calculations of pitch staff positions which take a clef into account

render_complete(pos: Point, flowable_line: Optional[NewLine] = None, flowable_x: Optional[Unit] = None)[source]

Render the entire object.

This is used to render all objects outside flowables, as well as those inside flowables when they fit completely in one line of the flowable.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – If in a Flowable, the line in which this object appears

  • flowable_x – If in a Flowable, the flowable x position of this render

render_before_break(pos: Point, flowable_line: NewLine, flowable_x: Unit)[source]

Render the beginning of the object up to a stopping point.

For use in flowable containers when rendering an object that crosses a line or page break. This function should render the beginning portion of the object up to the break.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • flowable_x – The flowable x position of this render

render_spanning_continuation(pos: Point, flowable_line: NewLine, object_x: Unit)[source]

Render the continuation of an object after a break and before another.

For use in flowable containers when rendering an object that crosses two breaks. This function should render the portion of the object surrounded by breaks on either side.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • object_x – The local object x position of the line’s start.

render_after_break(pos: Point, flowable_line: NewLine, object_x: Unit)[source]

Render the continuation of an object after a break.

For use in flowable containers when rendering an object that crosses a line or page break. This function should render the ending portion of an object after a break.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • object_x – The local object x position of the line’s start.