OpenSheetMusicDisplay
    Preparing search index...

    Class OpenSheetMusicDisplay

    The main class and control point of OpenSheetMusicDisplay.
    It can display MusicXML sheet music files in an HTML element container.
    After the constructor, use load() and render() to load and render a MusicXML file.

    Index

    Constructors

    • Creates and attaches an OpenSheetMusicDisplay object to an HTML element container.
      After the constructor, use load() and render() to load and render a MusicXML file.

      Parameters

      • container: string | HTMLElement

        The container element OSMD will be rendered into.
        Either a string specifying the ID of an HTML container element,
        or a reference to the HTML element itself (e.g. div)

      • options: IOSMDOptions = ...

        An object for rendering options like the backend (svg/canvas) or autoResize.
        For defaults see the OSMDOptionsStandard method in the [[OSMDOptions]] class.

      Returns OpenSheetMusicDisplay

    Properties

    autoResizeEnabled: boolean
    backendType: BackendType
    container: HTMLElement
    cursors: Cursor[] = []
    cursorsOptions: CursorOptions[] = []

    Options from which OSMD creates cursors in enableOrDisableCursors().

    drawBottomLine: boolean
    drawBoundingBox: string
    drawingParameters: DrawingParameters
    drawSkyLine: boolean
    followCursor: boolean
    loadUrlTimeout: number = 5000

    Timeout in milliseconds used in osmd.load(string) when string is a URL.

    needBackendUpdate: boolean
    OnXMLRead: (xml: string) => string

    A function that is executed when the XML has been read. The return value will be used as the actual XML OSMD parses, so you can make modifications to the xml that OSMD will use. Note that this is (re-)set on osmd.setOptions as {return xml}, unless you specify the function in the options.

    resizeHandlerAttached: boolean
    sheet: MusicSheet
    version: string = "2.0.0-release"
    zoom: number = 1.0
    zoomUpdated: boolean = false
    PageFormatStandards: { [type: string]: PageFormat } = ...

    Standard page format options like A4 or Letter, in portrait and landscape. E.g. PageFormatStandards["A4_P"] or PageFormatStandards["Letter_L"].

    Accessors

    Methods

    • Drive renderNext automatically from scrolling: render the next batch whenever the user scrolls within ~1.5 viewports of the not-yet-rendered edge (the page bottom for the endless vertical format, the right edge for RenderSingleHorizontalStaffline). Renders the first batch immediately if none has been rendered yet, then keeps appending as the user scrolls, and detaches itself once the whole sheet is rendered. Re-enabling replaces any previous listener; reset/render/load also detach it.

      Parameters

      • Optionaloptions: IRenderNextOptions & { scrollElement?: HTMLElement | Window }

        batch size (as renderNext) plus an optional scrollElement -- the element whose scrolling drives loading. Defaults to the OSMD container for a single horizontal staffline (it scrolls horizontally) and to window otherwise (the page scrolls vertically).

      Returns void

    • Helper function for managing window's onResize events

      Parameters

      • startCallback: () => void

        is the function called when resizing starts

      • endCallback: () => void

        is the function called when resizing (kind-of) ends

      Returns void

    • Load a MusicXML file

      Parameters

      • content: string | Document | Blob

        is either the url of a file, or the root node of a MusicXML document, or the string content of a .xml/.mxl file, or a file blob.

      • tempTitle: string = "Untitled Score"

        is used as the title for the piece if there is no title in the XML.

      Returns Promise<{}>

    • Re-render and scroll back to previous scroll bar y position in percent. If the document keeps the same height/length, the scroll bar position will basically be unchanged. For example, if you scroll to the bottom of the page, resize by one pixel (or enable dark mode) and call this, for the human eye there will be no detectable scrolling or change in the scroll position at all. If you just call render() instead of renderAndScrollBack(), it will scroll you back to the top of the page, even if you were scrolled to the bottom before.

      Returns void

    • Incrementally render the loaded sheet one batch at a time, appending each batch so a large score paints progressively ("system by system") instead of blocking on a full render(). The first call -- or the first after load(), render() or resetIncrementalRendering() -- starts a fresh session: it clears the container and lays the score out from the first measure. Each later call appends the next batch. Returns progress; once done is true the whole sheet is rendered and further calls are no-ops.

      Pair with enableIncrementalRenderingOnScroll for scroll-to-load, or renderRemaining to finish synchronously (e.g. before PDF/image export). Works for the endless vertical-scroll page format and for RenderSingleHorizontalStaffline (one staffline scrolling right).

      Parameters

      • Optionaloptions: IRenderNextOptions

        batch options; defaults to 8 visual measures (a multi-rest counts as one). Pass systems instead to advance by whole music systems (vertical only); see IRenderNextOptions.

      Returns IRenderNextResult

    • Finish an in-progress incremental render synchronously: render all remaining measures at once. Useful before PDF/image export or printing, which need every system, not just the ones scrolled into view. No-op if no incremental render is in progress, or it is already complete.

      Returns void

    • Abandon any in-progress incremental render and restore the draw-measure range it mutated, so a following normal render() draws the whole sheet again. Called automatically by render(), load() and clear(); call it directly only to cancel a session yourself.

      Returns void

    • Sets the logging level for this OSMD instance. By default, this is set to warn.

      @param: content can be trace, debug, info, warn or error.

      Parameters

      • level: string

      Returns void