Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Oct 5, 2023
1 parent 70873d0 commit cf26ca5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ catch(Exception $e)
}
```

Another way


```php
<?php

use MusicXML\MusicXML;
use MusicXML\Util\MXL;

require_once "inc.lib/autoload.php";

$musicXML = new MusicXML();
try
{
$midi = $musicXML->loadMidi("test.mid");
$mxl = $musicXML->midiToMusicXml($midi, "Test", "4.0", MXL::FORMAT_MXL);
file_put_contents("convert.mxl", $mxl);
}
catch(Exception $e)
{
echo $e->getMessage();
}
```

## Progress

1. October 5th 2023 - result is playable but duration longer than expected
Expand Down
2 changes: 1 addition & 1 deletion convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
$midi = $musicXML->loadMidi("test.mid");
$mxl = new MXL();
$xml = $musicXML->midiToMusicXml($midi, "Test", "4.0", "xml");
$xml = $musicXML->midiToMusicXml($midi, "Test", "4.0", MXL::FORMAT_MXL);

//compressed version]
//file_put_contents("convert.mxl", $mxl->createMxl("Test", $xml));
Expand Down
5 changes: 2 additions & 3 deletions inc.lib/classes/MusicXML/MusicXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@ public function loadXml($path)

}


/**
* Convert MIDI to MusicXML
*
* @param MidiMeasure $midi
* @param string $version Version of MusicXML
* @return string
*/
public function midiToMusicXml($midi, $title, $version = "4.0", $format = MXL::XML)
public function midiToMusicXml($midi, $title, $version = "4.0", $format = MXL::FORMAT_XML)
{
$domdoc = $this->getDOMDocument();
$midi2mxl = new MusicXMLFromMidi();
$domdoc->appendChild($midi2mxl->convertMidiToMusicXML($midi, $title, $domdoc, $version));
if($format == MXL::MXL)
if($format == MXL::FORMAT_MXL)
{
$mxl = new MXL();
return $mxl->xmlToMxl($title, $domdoc->saveXML());
Expand Down
6 changes: 3 additions & 3 deletions inc.lib/classes/MusicXML/Util/MXL.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class MXL
{
const MXL = "mxl";
const XML = "xml";
const MUSICXML = "musicxml";
const FORMAT_MXL = "mxl";
const FORMAT_XML = "xml";
const FORMAT_MUSICXML = "musicxml";

public function xmlToMxl($name, $xml, $mimetype = "application/vnd.recordare.musicxml")
{
Expand Down

0 comments on commit cf26ca5

Please sign in to comment.