import { Note } from "./Note" ; import log from "loglevel" ; /**
 * A note head with shape and fill information belonging to a [[Note]].
 */ export class Notehead { param sourceNote param shapeTypeXml param filledXml constructor ( sourceNote , shapeTypeXml , filledXml = undefined ) { this . sourceNote = sourceNote ; this . setShapeFromXml ( shapeTypeXml , filledXml ) ; } /** shape of the note head (normal, square, triangle, etc.) */ private shape : NoteHeadShape ; private filled : boolean ; /** the [[Note]] this NoteHead belongs to. */ private sourceNote : Note ; param shapeTypeXml param filledXmlAttribute public setShapeFromXml ( shapeTypeXml , filledXmlAttribute = undefined ) { this . shape = Notehead . ShapeTypeXmlToShape ( shapeTypeXml ) ; let filled = filledXmlAttribute ; if ( filled === undefined ) { if ( ! this . sourceNote ) { log . warn ( "notehead: sourceNote and filledXmlAttribute undefined." ) ; filled = true ; } else { filled = this . sourceNote . Length . Denominator > 2 ; } } this . filled = filled ; } public get SourceNote ( ) : Note { return this . sourceNote ; } public get Shape ( ) : NoteHeadShape { return this . shape ; } public get Filled ( ) : boolean { return this . filled ; } /** Converts xml attribute to NoteHeadShape.
     * Necessary because "circle-x" is not a valid enum member name.
     */ public static ShapeTypeXmlToShape ( shapeTypeXml ) { switch ( shapeTypeXml . toLowerCase ( ) ) { case "normal" : return NoteHeadShape . NORMAL ; case "x" : return NoteHeadShape . X ; case "slash" : return NoteHeadShape . SLASH ; case "diamond" : return NoteHeadShape . DIAMOND ; case "square" : return NoteHeadShape . SQUARE ; case "la" : return NoteHeadShape . SQUARE ; case "do" : case "triangle" : return NoteHeadShape . TRIANGLE ; case "rectangle" : return NoteHeadShape . RECTANGLE ; case "circle-x" : return NoteHeadShape . CIRCLEX ; default : log . info ( "unsupported/unhandled xml notehead '" + shapeTypeXml + "'. Using normal notehead." ) ; return NoteHeadShape . NORMAL ; } } } /** shape of a note head, needs to be supported by MusicXML and Vexflow. */ export enum NoteHeadShape { CIRCLEX , DIAMOND , NORMAL , RECTANGLE , SLASH , SQUARE , TRIANGLE , X }