diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml deleted file mode 100644 index 1ef7894..0000000 --- a/.github/workflows/php.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: PHP Composer - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - # - name: Run test suite - # run: composer run-script test diff --git a/convert.php b/convert.php index 7c7a180..2776254 100644 --- a/convert.php +++ b/convert.php @@ -8,7 +8,7 @@ $musicXML = new MusicXML(); try { - $midi = $musicXML->loadMidi("test.mid"); + $midi = $musicXML->loadMidi("Cinta Su.mid"); $mxl = new MXL(); $xml = $musicXML->midiToMusicXml($midi, "Test", "4.0", MXL::FORMAT_MXL); diff --git a/inc.lib/classes/MusicXML/Model/Encoding.php b/inc.lib/classes/MusicXML/Model/Encoding.php index bc36426..3501865 100644 --- a/inc.lib/classes/MusicXML/Model/Encoding.php +++ b/inc.lib/classes/MusicXML/Model/Encoding.php @@ -18,7 +18,7 @@ class Encoding extends MusicXMLWriter * @Element(name="software") * @var Software[] */ - public $softwareList; + public $software; /** * Encoding date diff --git a/inc.lib/classes/MusicXML/Model/Notations.php b/inc.lib/classes/MusicXML/Model/Notations.php index a937d69..bc2f05e 100644 --- a/inc.lib/classes/MusicXML/Model/Notations.php +++ b/inc.lib/classes/MusicXML/Model/Notations.php @@ -19,7 +19,7 @@ class Notations extends MusicXMLWriter * @Element(name="tied") * @var Tied[] */ - public $tiedList; + public $tied; /** * Slur list @@ -27,7 +27,7 @@ class Notations extends MusicXMLWriter * @Element(name="slur") * @var Slur[] */ - public $slurList; + public $slur; /** * Articulations diff --git a/inc.lib/classes/MusicXML/MusicXMLBase.php b/inc.lib/classes/MusicXML/MusicXMLBase.php index 948eb23..510dfff 100644 --- a/inc.lib/classes/MusicXML/MusicXMLBase.php +++ b/inc.lib/classes/MusicXML/MusicXMLBase.php @@ -357,12 +357,12 @@ public function getIdentification($copyright = "") $identification->encoding = new Encoding(); $identification->encoding->encodingDate = new DateTime(); - $identification->encoding->softwareList = array(); + $identification->encoding->software = array(); $software = new Software(); $software->textContent = self::SOFTWARE_NAME; - $identification->encoding->softwareList[] = $software; + $identification->encoding->software[] = $software; $identification->encoding->supports[] = array(); $identification->encoding->supports[] = new Supports(array('element' => 'accidental', 'type' => 'yes')); @@ -400,8 +400,8 @@ public function getIdentification($copyright = "") 23 => array('Tango Accordion', ''), 24 => array('Classical Guitar', 'Guit.', 'pluck.guitar.nylon-string'), 25 => array('Acoustic Guitar', 'Guit.', 'pluck.guitar.acoustic'), - 26 => array('Jazz Electric Gtr', ''), - 27 => array('Electric Guitar', 'El. Guit.', 'pluck.guitar.electric'), //NOSONAR + 26 => array('Jazz Electric Gtr', 'J. El. Guit.', 'pluck.guitar.electric'), + 27 => array('Electric Guitar', 'El. Guit.', 'pluck.guitar.electric'), 28 => array('Muted Guitar', ''), 29 => array('Electric Guitar', 'El. Guit.', 'pluck.guitar.electric'), 30 => array('Electric Guitar', 'El. Guit.', 'pluck.guitar.electric'), diff --git a/inc.lib/classes/MusicXML/MusicXMLFromMidi.php b/inc.lib/classes/MusicXML/MusicXMLFromMidi.php index 16bdbeb..1a57577 100644 --- a/inc.lib/classes/MusicXML/MusicXMLFromMidi.php +++ b/inc.lib/classes/MusicXML/MusicXMLFromMidi.php @@ -309,7 +309,7 @@ private function addEvent($eventName, $message, $timebase, $abstime, $n = 0, $ch 'value' => $v ); } - else + else if($eventName == 'On' || $eventName == 'Off') { $this->measures[$ch][$tmInteger][] = array( 'event' => $eventName, @@ -330,6 +330,17 @@ private function addEvent($eventName, $message, $timebase, $abstime, $n = 0, $ch $this->noteMax = $n; } } + else + { + $this->measures[$ch][$tmInteger][] = array( + 'event' => $eventName, + 'message' => $message, + 'time' => $tm, + 'abstime' => $abstime, + 'channel' => $ch, + 'value' => $v + ); + } } /** @@ -661,7 +672,11 @@ public function convertMidiToMusicXML($midi, $title, $domdoc, $version = "4.0") $this->processDuration($timebase); $factor = 4; - $maxMeasure = ceil($midi->getDurationRaw()/($factor * $timebase)); + $maxMeasure = floor($midi->getDurationRaw()/($factor * $timebase)); + if($maxMeasure == 0) + { + $maxMeasure = 1; + } // begin part @@ -756,7 +771,7 @@ private function getEventList($controlEvents) { $rawtime = $message['rawtime']; $tempo = $message['value']; - $bpm = (int)(60000000/$tempo); + $bpm = round((60000000/$tempo)); $tempoList[$time] = array('rawtime'=>$rawtime, 'tempo'=>$tempo, 'bpm'=>$bpm); } if($message['event'] == 'KeySig') @@ -947,39 +962,56 @@ private function addMeasureElement($measureIndex, $measure, $noteMessages, $chan // TODO: if there are notes overlaped, make backup foreach ($noteMessages as $message) { - $duration = $this->calculateDuration($message['duration'], $divisions, $timebase); - $note = new Note(); - - $note->voice = $channelId; - $noteCode = $message['note']; - if($message['value'] > 0 && $noteCode > 13) - { - $note->dynamics = round($message['value'] / 0.9, 4); - $pitch = $this->getPitch($noteCode); - $note->pitch = $pitch; - if($pitch->alter > 0) + $duration = $this->calculateDuration($message['duration'], $divisions, $timebase); + if($duration > 0) + { + $note = new Note(); + + $note->voice = $channelId; + $noteCode = $message['note']; + if($message['value'] > 0 && $noteCode > 13) { - $note->accidental = 'sharp'; + $note->dynamics = round($message['value'] / 0.9, 4); + $pitch = $this->getPitch($noteCode); + $note->pitch = $pitch; + if($pitch->alter > 0) + { + $note->dynamics = floatval(sprintf("%.2f", $message['value'] / 0.9)); + $pitch = $this->getPitch($noteCode); + $note->pitch = $pitch; + if($pitch->alter > 0) + { + $note->accidental = 'sharp'; + } + else if($pitch->alter < 0) + { + $note->accidental = 'flat'; + } + $note->stem = 'up'; + $note->notations = $this->getNotation(); + } + else + { + $rest = new Rest(); + $note->rest = $rest; + } + $note->duration = $duration; + $note->type = $this->getNoteType($note->duration, $divisions); + $measure->note[] = $note; } - else if($pitch->alter < 0) + else { - $note->accidental = 'flat'; + $rest = new Rest(); + $note->rest = $rest; } - $note->stem = 'up'; - $note->notations = $this->getNotation(); - } - else - { - $rest = new Rest(); - $note->rest = $rest; + $note->duration = $duration; + $note->type = $this->getNoteType($note->duration, $divisions); + + $coord = MusicXMLUtil::getNoteCoordinate($measureIndex, $message, $divisions, $timebase); + $note->defaultX = $coord->defaultX; + + $measure->note[] = $note; } - $note->duration = $duration; - $note->type = $this->getNoteType($note->duration, $divisions); - - $coord = MusicXMLUtil::getNoteCoordinate($measureIndex, $message, $divisions, $timebase); - $note->defaultX = $coord->defaultX; - - $measure->note[] = $note; } return $measure; }