Download the PHP package planetbiru/musicxml without Composer

On this page you can find all versions of the php package planetbiru/musicxml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package musicxml

Planetbiru MusicXML Converter

Latest Stable Version License

This is more than just a MIDI-to-MusicXML converter; it's a comprehensive PHP toolkit for developers working with musical data. It provides robust tools to parse, convert, and render music from various formats, including MIDI, MusicXML, and DAWProject. The library excels at generating beautiful, interactive sheet music as PDFs or SVGs, all in pure PHP with minimal dependencies. This library is actively used in production and powers the online sheet music generator at https://composer.planetbiru.com/.

Key Features

Conversion Workflows

The library supports the following conversion workflows:

Format Comparison and Data Loss

When converting between MIDI, MusicXML, and DAWProject, it's important to understand that each format was designed for a different purpose. As a result, some information can be lost in translation.

Feature Comparison Matrix

Feature MIDI (.mid) MusicXML (.xml, .mxl) DAWProject (.dawproject)
Primary Purpose Performance Data Digital Sheet Music DAW Session Interchange
Note Data Yes (Pitch, Velocity, Timing) Yes (with rich notation) Yes (within clips)
Sheet Music Notation No (Inferred by converter) Yes (Primary feature) No (Inferred by converter)
Lyrics Yes (as timed meta-events) Yes (syllable-based, well-structured) No (Not supported in the spec)
Continuous Controllers Yes (Pitch Bend, Modulation, etc.) Limited (often simplified or lost) Yes (as automation curves)
Track Structure Yes Yes (as "Parts") Yes (Audio, Instrument, etc.)
Audio Clips No No Yes (References external files)
Plugin/VST State No No Yes (Can store plugin info)

Conversion Data Loss

Understanding what is lost during conversion is key to choosing the right workflow for your needs.

MIDI → MusicXML

This is a "performance-to-notation" conversion. The goal is to create readable sheet music from raw performance data.

MusicXML → MIDI

This is a "notation-to-performance" conversion. The goal is to create an audible representation of the sheet music.

MIDI → DAWProject

This conversion focuses on preserving core musical data like notes, tracks, and tempo for interoperability between DAWs.

DAWProject → MIDI

This conversion extracts musical event data from a DAW session file.

Conclusion: The Best Format for the Job

Due to these differences, a round-trip conversion like MIDI → MusicXML → MIDI will not produce a file identical to the original. The resulting MIDI will be a quantized, simplified performance based on the generated sheet music, not a perfect copy of the original performance.

MusicXML 4.0 Compliance

The object model in this library, primarily located within the MusicXML\Model namespace, is designed to accurately reflect the official MusicXML 4.0 specification. Each PHP class, such as Accidental, Note, MeasurePartwise, and others, corresponds directly to an element defined in the MusicXML standard.

This 1:1 mapping approach ensures that the generated XML output is well-structured, valid, and broadly compatible with various music notation software that supports MusicXML (such as Sibelius, Finale, MuseScore, etc.). When you work with the PHP objects in this library, you are essentially building a MusicXML document programmatically.

For a complete and detailed reference of all elements, their attributes, and expected values, please refer to the official element reference from W3C MusicXML 4.0. For instance, the Accidental class in this library corresponds to the <accidental> element described in the documentation. You can find a complete list of all elements at:

As a specific example, the <accidental-text> element can be found in this documentation.

Installation

Install the library via Composer:

Usage

The MusicConverter class is the main entry point and the easiest way to use this library. Think of it as the primary "conversion engine" that does all the heavy lifting for you.

When you provide a MIDI file, MusicConverter automatically performs the following steps behind the scenes:

  1. Reads & Analyzes MIDI: It understands all the data from the MIDI file, such as notes, tempo, instruments, and lyrics.
  2. Converts to MusicXML: It translates that MIDI data into the MusicXML format, which is the standard "language" for digital music notation.
  3. Renders to Visuals: It draws the MusicXML structure into your desired visual format, either a print-ready PDF or an interactive SVG for the web.

You don't need to worry about the technical details of each step; you just need to call a single function.

Constructor

new MusicConverter($compressEmptyMeasures, $showTempoChanges, $useRestFilling, $lyricFontSize, $systemHeight, $drawBeam)

Initializes the converter with optional rendering settings.

Core Conversion Methods

Here are the main public methods available in the MusicConverter class:

midiToMusicXML($midiData, $songTitle, $version, $format)

Converts MIDI data into a MusicXML string.

midiToDAWProject($midiData)

Converts MIDI data into a .dawproject file format. This method takes binary MIDI data and converts it into a ZIP archive containing project.xml and metadata.xml, which is compatible with DAWs like Bitwig Studio.

dawProjectToMIDI($dawProjectData)

Converts a .dawproject file back into MIDI data. This method reads a .dawproject ZIP archive, parses its contents, and reconstructs the corresponding binary MIDI data.

dawProjectToPDF($dawProjectData, $songTitle, $composer, $targetChannelOrPartId, $singlePage)

Converts a .dawproject file into a PDF file. This method first converts the .dawproject data into an intermediate MIDI format, and then renders that MIDI data to a PDF.

musicXMLToMIDI($musicXmlContent)

Converts a MusicXML string into a binary MIDI data string.

midiToPDF($midiData, $songTitle, $composer, $targetChannelOrPartId, $mainMelody)

Renders MIDI data directly into a PDF sheet music string.

musicXMLToPDF($xmlStr, $songTitle, $composer, $targetChannelOrPartId, $showLyric)

Renders MusicXML data into a PDF sheet music string.

midiToSVG($midiData, $songTitle, $composer, $targetChannelOrPartId, $mainMelody, $singlePage)

midiToSVG($midiData, $songTitle, $composer, $targetChannelOrPartId, $mainMelody, $singlePage, $mobile)

Renders MIDI data directly into an interactive SVG image string.

musicXMLToSVG($xmlStr, $songTitle, $composer, $targetChannelOrPartId, $showLyric, $singlePage, $mobile)

Renders MusicXML data into an interactive SVG image string.

dawProjectToSVG($dawProjectData, $songTitle, $composer, $targetChannelOrPartId, $singlePage, $mobile)

Converts a .dawproject file into an SVG image. This method first converts the .dawproject data into an intermediate MIDI format, and then renders that MIDI data to an SVG.

Examples

Basic Example: Convert MIDI to PDF

This example demonstrates the simplest use case: converting a MIDI file into a PDF.

Advanced Examples

Convert to SVG

The process is nearly identical for generating an SVG. You can also control whether the output is a single continuous page or a multi-page layout.

Select a Specific Track/Channel

You can specify a MIDI channel number (1-16) to render a specific instrument part.

Batch Convert All Tracks to a ZIP

The provided example/run-examples.php file contains a complete implementation for iterating through all tracks in a MIDI file, converting each one to a separate PDF, and packaging them into a single ZIP archive. This is useful for creating individual instrumental parts from a full arrangement.

Building a DAWProject Player

You can leverage the library's roundtrip capabilities to build a fully interactive player for .dawproject files, complete with synchronized sheet music and audio playback. This is ideal for creating custom DAW environments or analysis tools on the web.

The workflow involves two parallel conversion paths:

  1. Audio Generation (.dawprojectMIDI):

    • Use dawProjectToMIDI() to convert the .dawproject file into binary MIDI data.
    • This MIDI data can then be loaded into a web-based player like MIDI.js for audio playback.
  2. Visual Score Generation (.dawprojectMIDIMusicXMLSVG):
    • First, convert the .dawproject file to MIDI using dawProjectToMIDI().
    • Next, convert the resulting MIDI data to MusicXML using midiToMusicXML().
    • Finally, render the MusicXML into an interactive SVG using musicXMLToSVG().

By running these two processes, you get both the audio and the visual score from a single .dawproject source. The generated SVG will contain the necessary data-tick attributes to synchronize the note highlighting and playhead with the audio from the MIDI player, just like in the vocal-training.php example.

This powerful workflow allows you to create rich, interactive experiences directly from a modern DAW project format.

Note on Lyrics: The .dawproject format does not natively support lyric events. Therefore, any lyrics present in an original MIDI file will be lost during the MIDI.dawproject conversion and will not appear in the final generated score.

Interactive SVG with Player Synchronization

A powerful feature of this library is its ability to generate SVGs ready for synchronization with an audio player (like a MIDI player). Each note, rest, and measure element in the SVG is tagged with data-start-tick and data-end-tick attributes.

This metadata allows you to build interactive web applications where:

This makes the library ideal for creating:

Standalone Example: vocal-training.php

The library includes a powerful, self-contained example in d:\MagicServer\www\MusicXML\example\vocal-training.php. This file demonstrates how to build a complete interactive sheet music player for the web.

How It Works:

  1. Backend (PHP):

    • It loads a MIDI file (example.mid).
    • It uses MidiFilter to get a list of all tracks and to apply transposition.
    • It uses MusicConverter to render the selected MIDI track into an interactive SVG.
    • The final MIDI data (for playback) and the SVG data (for display) are passed to the frontend.
  2. Frontend (JavaScript):
    • MIDI Playback: It uses the MIDI.js library (loaded via its CDN) to play the MIDI audio directly in the browser.
    • Score Synchronization: The core logic is in vocal-training.js. It uses the MIDIjs.player_callback function, which fires approximately 10 times per second during playback.
    • Real-time Updates: On each callback, the script:
      • Calculates the current position (tick) in the music.
      • Highlights the currently playing note(s) by adding a .active CSS class to the corresponding SVG elements.
      • Moves a red vertical line (#playhead-line) across the staff to show the exact playback position.
      • Automatically scrolls the score down as the music progresses to keep the current system in view.
    • Interactive Controls: The example includes fully functional controls for:
      • Play / Pause / Resume: Simulates pause/resume since MIDI.js lacks a native function.
      • Seeking: The user can drag the timeline slider to any point in the song. Playback will resume from the selected position.
      • Track Selection & Transposition: The page can be reloaded to show a different track or apply a different transposition.
      • Audio-Visual Sync Compensation: A slider allows the user to adjust the visual offset to compensate for any audio latency, ensuring the playhead and note highlights are perfectly synchronized with the sound.

Notes on MusicXML to MIDI Conversion

While a MIDI file converted from MusicXML is nearly identical to the original MIDI before it was converted to MusicXML, there are several important points to consider regarding data loss in a MIDI -> MusicXML -> MIDI round trip:

  1. Controller Data: The MusicXML generated by this library does not store continuous controller data like pitch bend, modulation, or detailed CC7 (Volume) and CC11 (Expression) curves. When converted back to MIDI, this nuanced performance data is lost.
  2. Note Velocity: MusicXML note dynamics are calculated from a combination of the original MIDI velocity, volume (CC7), and expression (CC11). This means the velocity of a note in the final MIDI file is a computed value and will not be the same as the original velocity.
  3. Panning: Since pan information is not stored in the generated MusicXML, the resulting audio from the converted MIDI file will be mono.
  4. Quantization: Note onsets that do not fall precisely on standard rhythmic grid lines (e.g., 1, 1/2, 1/4, 1/8, 1/16, 1/32) are quantized. This can cause slight timing shifts compared to the original performance.
  5. Drum Note Durations: Note durations on the percussion channel (Channel 10) are also quantized.

Due to these factors, the MusicXML format as used here is not intended for perfect preservation of an original musical performance. It is best used as an intermediate format for tasks such as:

Dependencies

License

This library is open-source software licensed under the MIT license.


All versions of musicxml with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
fpdf/fpdf Version ^1.8
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package planetbiru/musicxml contains the following files

Loading the files please wait ...