Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NoteHead

NoteHeads are typically not manipulated directly, but used internally in StaveNote.

See tests/notehead_tests.ts for usage examples.

Hierarchy

Index

Constructors

constructor

Properties

Optional glyph

glyph?: any

glyph_code

glyph_code: string

keyProps

keyProps: KeyProps[]

keys

keys: string[]

render_options

render_options: { annotation_spacing: number; draw?: boolean; draw_dots?: boolean; draw_stem?: boolean; draw_stem_through_stave?: boolean; extend_left?: number; extend_right?: number; font: string; glyph_font_scale: number; glyph_font_size?: number; scale: number; stroke_px: number; y_shift: number }

Type declaration

  • annotation_spacing: number
  • Optional draw?: boolean
  • Optional draw_dots?: boolean
  • Optional draw_stem?: boolean
  • Optional draw_stem_through_stave?: boolean
  • Optional extend_left?: number
  • Optional extend_right?: number
  • font: string
  • glyph_font_scale: number
  • Optional glyph_font_size?: number
  • scale: number
  • stroke_px: number
  • y_shift: number

Static DEBUG

DEBUG: boolean = false

To enable logging for this class. Set Vex.Flow.NoteHead.DEBUG to true.

Static TEXT_FONT

TEXT_FONT: Required<FontInfo> = ...

Default font for text. This is not related to music engraving. Instead, see Flow.setMusicFont(...fontNames) to customize the font for musical symbols placed on the score.

Accessors

font

  • get font(): string
  • set font(f: string): void
  • Returns the CSS compatible font string.

    Returns string

  • Provide a CSS compatible font string (e.g., 'bold 16px Arial').

    Parameters

    • f: string

    Returns void

fontInfo

  • Return a copy of the current FontInfo object.

    Returns Required<FontInfo>

  • Return a copy of the current FontInfo object.

    Parameters

    Returns void

fontSize

  • get fontSize(): string
  • set fontSize(size: string | number): void
  • The size is 1) a string of the form '10pt' or '16px', compatible with the CSS font-size property. or 2) a number, which is interpreted as a point size (i.e. 12 == '12pt').

    Returns string

    a CSS font-size string (e.g., '18pt', '12px', '1em').

  • The size is 1) a string of the form '10pt' or '16px', compatible with the CSS font-size property. or 2) a number, which is interpreted as a point size (i.e. 12 == '12pt').

    Parameters

    • size: string | number

    Returns void

fontSizeInPixels

  • get fontSizeInPixels(): number
  • Returns number

    the font size in px.

fontSizeInPoints

  • get fontSizeInPoints(): number
  • Returns number

    the font size in pt.

fontStyle

  • get fontStyle(): string
  • set fontStyle(style: string): void
  • Returns string

    a CSS font-style string (e.g., 'italic').

  • Parameters

    • style: string

    Returns void

    a CSS font-style string (e.g., 'italic').

fontWeight

  • get fontWeight(): string
  • set fontWeight(weight: string | number): void
  • Returns string

    a CSS font-weight string (e.g., 'bold'). As in CSS, font-weight is always returned as a string, even if it was set as a number.

  • Parameters

    • weight: string | number

    Returns void

    a CSS font-weight string (e.g., 'bold'). As in CSS, font-weight is always returned as a string, even if it was set as a number.

postFormatted

  • get postFormatted(): boolean
  • set postFormatted(value: boolean): void
  • Set postformatted status.

    Returns boolean

  • Set postformatted status.

    Parameters

    • value: boolean

    Returns void

preFormatted

  • get preFormatted(): boolean
  • set preFormatted(value: boolean): void
  • Set preformatted status.

    Returns boolean

  • Set preformatted status.

    Parameters

    • value: boolean

    Returns void

Static CATEGORY

  • get CATEGORY(): string
  • Returns string

Methods

addChildElement

addClass

  • Add a class label (An element can have multiple class labels).

    Parameters

    • className: string

    Returns NoteHead

addModifier

  • Attach a modifier to this note.

    Parameters

    • modifier: Modifier

      the Modifier to add.

    • index: number = 0

      of the key to modify.

    Returns NoteHead

    this

addStroke

addToModifierContext

applyStyle

applyTickMultiplier

  • applyTickMultiplier(numerator: number, denominator: number): void
  • Apply a tick multiplier.

    Parameters

    • numerator: number
    • denominator: number

    Returns void

checkBeam

checkContext

checkModifierContext

checkStave

checkTickContext

draw

  • draw(): void
  • Draw the notehead.

    Returns void

drawWithStyle

  • drawWithStyle(): void
  • Draw the element and all its sub-elements (ie.: Modifiers in a Stave) with the element style.

    Returns void

getAbsoluteX

  • getAbsoluteX(): number
  • Get the canvas x coordinate position of the notehead.

    Returns number

getAttribute

  • getAttribute(name: string): any
  • Return an attribute.

    Parameters

    • name: string

    Returns any

getAttributes

getBeam

  • getBeam(): undefined | Beam

getBoundingBox

getCategory

  • getCategory(): string

getCenterXShift

  • getCenterXShift(): number

getContext

getDuration

  • getDuration(): string

getFirstDotPx

  • getFirstDotPx(): number

getFont

  • getFont(): string

getFontSize

  • getFontSize(): string
  • Returns string

    a CSS font-size string (e.g., '18pt', '12px', '1em'). See Element.fontSizeInPixels or Element.fontSizeInPoints if you need to get a number for calculation purposes.

getFormatterMetrics

getGlyph

getGlyphWidth

  • getGlyphWidth(): number

getIntrinsicTicks

  • getIntrinsicTicks(): number

getKeyProps

getKeys

  • getKeys(): string[]

getLeftDisplacedHeadPx

  • getLeftDisplacedHeadPx(): number

getLeftParenthesisPx

  • getLeftParenthesisPx(index: number): number

getLine

  • getLine(): number
  • Get the stave line the notehead is placed on.

    Returns number

getLineForRest

  • getLineForRest(): number

getLineNumber

  • getLineNumber(isTopNote?: boolean): number
  • Get the stave line number for the note.

    Parameters

    • Optional isTopNote: boolean

    Returns number

getMetrics

getModifierContext

getModifierStartXY

  • getModifierStartXY(position?: number, index?: number, options?: any): { x: number; y: number }
  • Get the coordinates for where modifiers begin.

    Parameters

    • Optional position: number
    • Optional index: number
    • Optional options: any

    Returns { x: number; y: number }

    • x: number
    • y: number

getModifiers

getModifiersByType

  • getModifiersByType(type: string): Modifier[]

getNoteType

  • getNoteType(): string

getPlayNote

  • getPlayNote(): undefined | Note
  • Get the play note, which is arbitrary data that can be used by an audio player.

    Returns undefined | Note

getRightDisplacedHeadPx

  • getRightDisplacedHeadPx(): number

getRightParenthesisPx

  • getRightParenthesisPx(index: number): number

getSVGElement

  • getSVGElement(suffix?: string): undefined | SVGElement
  • Return associated SVGElement.

    Parameters

    • suffix: string = ''

    Returns undefined | SVGElement

getStave

  • getStave(): undefined | Stave

getStemDirection

  • getStemDirection(): number

getStemExtents

  • getStemExtents(): Record<string, number>
  • Get the top and bottom y values of the stem.

    Returns Record<string, number>

getStyle

getTickContext

getTickMultiplier

getTicks

getTieLeftX

  • getTieLeftX(): number
  • Get the x coordinate to the left of the note.

    Returns number

getTieRightX

  • getTieRightX(): number
  • Get the x coordinate to the right of the note.

    Returns number

getTuplet

  • getTuplet(): undefined | Tuplet

getTupletStack

getVoice

  • Return the voice that this note belongs in.

    Returns Voice

getWidth

  • getWidth(): number
  • Get the width of the notehead.

    Returns number

getX

  • getX(): number
  • Get x position of this tick context.

    Returns number

getXShift

  • getXShift(): number
  • Get the x displaced pixels of the note.

    Returns number

getY

  • getY(): number
  • Get the Y coordinate.

    Returns number

getYForTopText

  • getYForTopText(text_line: number): number
  • Get the Y position of the space above the stave onto which text can be rendered.

    Parameters

    • text_line: number

    Returns number

getYs

  • getYs(): number[]
  • Get Y positions for this note. Each Y value is associated with an individual pitch/key within the note/chord.

    Returns number[]

hasBeam

  • hasBeam(): boolean
  • Check it has a beam.

    Returns boolean

hasClass

  • hasClass(className: string): boolean
  • Check if it has a class label (An element can have multiple class labels).

    Parameters

    • className: string

    Returns boolean

hasStem

  • hasStem(): boolean
  • Accessor to hasStem.

    Returns boolean

isCenterAligned

  • isCenterAligned(): boolean

isDisplaced

  • isDisplaced(): boolean
  • Determine if the notehead is displaced.

    Returns boolean

isDotted

  • isDotted(): boolean
  • Accessor to isDotted.

    Returns boolean

isRendered

  • isRendered(): boolean
  • Return the rendered status.

    Returns boolean

isRest

  • isRest(): boolean
  • Returns boolean

    true if this note is a type of rest.

    Rests don't have pitches, but take up space in the score. Subclasses should override this default implementation.

onRegister

postFormat

preFormat

removeClass

  • removeClass(className: string): NoteHead
  • Remove a class label (An element can have multiple class labels).

    Parameters

    • className: string

    Returns NoteHead

reset

  • Reset the Tickable, this function will be overloaded.

    Returns NoteHead

resetFont

  • resetFont(): void
  • Reset the text font to the style indicated by the static TEXT_FONT property. Subclasses can call this to initialize textFont for the first time.

    Returns void

resetTuplet

  • Reset the specific Tuplet if this is not provided, all tuplets are reset. Remove any prior tuplets from the tick calculation and reset the intrinsic tick value.

    Parameters

    Returns NoteHead

restoreStyle

setAttribute

  • setAttribute(name: string, value: any): NoteHead

setBeam

setCenterAlignment

  • setCenterAlignment(align_center: boolean): NoteHead

setCenterXShift

  • setCenterXShift(centerXShift: number): NoteHead

setContext

setDuration

setFont

  • setFont(font?: string | FontInfo, size?: string | number, weight?: string | number, style?: string): NoteHead
  • Set the element's font family, size, weight, style (e.g., Arial, 10pt, bold, italic).

    Parameters

    • Optional font: string | FontInfo

      is 1) a FontInfo object or 2) a string formatted as CSS font shorthand (e.g., 'bold 10pt Arial') or 3) a string representing the font family (at least one of size, weight, or style must also be provided).

    • Optional size: string | number

      a string specifying the font size and unit (e.g., '16pt'), or a number (the unit is assumed to be 'pt').

    • Optional weight: string | number

      is a string (e.g., 'bold', 'normal') or a number (100, 200, ... 900).

    • Optional style: string

      is a string (e.g., 'italic', 'normal'). If no arguments are provided, then the font is set to the default font. Each Element subclass may specify its own default by overriding the static TEXT_FONT property.

    Returns NoteHead

setFontSize

  • setFontSize(size?: string | number): NoteHead
  • Change the font size, while keeping everything else the same.

    Parameters

    • Optional size: string | number

    Returns NoteHead

setGroupStyle

setIgnoreTicks

setIntrinsicTicks

  • setIntrinsicTicks(intrinsicTicks: number): void
  • Set the intrinsic ticks.

    Parameters

    • intrinsicTicks: number

    Returns void

setLeftDisplacedHeadPx

  • setLeftDisplacedHeadPx(x: number): NoteHead

setLine

  • Set the stave line the notehead is placed on.

    Parameters

    • line: number

    Returns NoteHead

setModifierContext

setPlayNote

  • Set the play note, which is arbitrary data that can be used by an audio player.

    Parameters

    Returns NoteHead

setRendered

  • setRendered(rendered?: boolean): NoteHead

setRightDisplacedHeadPx

  • setRightDisplacedHeadPx(x: number): NoteHead

setStave

setStyle

  • Set the element style used to render.

    Example:

    element.setStyle({ fillStyle: 'red', strokeStyle: 'red' });
    element.draw();

    Note: If the element draws additional sub-elements (ie.: Modifiers in a Stave), the style can be applied to all of them by means of the context:

    element.setStyle({ fillStyle: 'red', strokeStyle: 'red' });
    element.getContext().setFillStyle('red');
    element.getContext().setStrokeStyle('red');
    element.draw();

    or using drawWithStyle:

    element.setStyle({ fillStyle: 'red', strokeStyle: 'red' });
    element.drawWithStyle();

    Parameters

    Returns NoteHead

setTickContext

setTuplet

setVoice

setWidth

  • setWidth(width: number): void
  • Set width of note. Used by the formatter for positioning.

    Parameters

    • width: number

    Returns void

setX

  • Set the X coordinate.

    Parameters

    • x: number

    Returns NoteHead

setXShift

  • Displace note by x pixels. Used by the formatter.

    Parameters

    • x: number

    Returns NoteHead

setY

  • Set the Y coordinate.

    Parameters

    • y: number

    Returns NoteHead

setYs

  • Set Y positions for this note. Each Y value is associated with an individual pitch/key within the note/chord.

    Parameters

    • ys: number[]

    Returns NoteHead

shouldIgnoreTicks

  • shouldIgnoreTicks(): boolean
  • True if this note has no duration (e.g., bar notes, spacers, etc.).

    Returns boolean

Static plotMetrics