Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #3

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions .github/workflows/php.yml

This file was deleted.

2 changes: 1 addition & 1 deletion convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion inc.lib/classes/MusicXML/Model/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Encoding extends MusicXMLWriter
* @Element(name="software")
* @var Software[]
*/
public $softwareList;
public $software;

/**
* Encoding date
Expand Down
4 changes: 2 additions & 2 deletions inc.lib/classes/MusicXML/Model/Notations.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class Notations extends MusicXMLWriter
* @Element(name="tied")
* @var Tied[]
*/
public $tiedList;
public $tied;

/**
* Slur list
*
* @Element(name="slur")
* @var Slur[]
*/
public $slurList;
public $slur;

/**
* Articulations
Expand Down
8 changes: 4 additions & 4 deletions inc.lib/classes/MusicXML/MusicXMLBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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'),
Expand Down
94 changes: 63 additions & 31 deletions inc.lib/classes/MusicXML/MusicXMLFromMidi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
);
}
}

/**
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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;
}
Expand Down