Skip to content

Commit

Permalink
Refactor MidiEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Oct 5, 2023
1 parent 530f0a6 commit 6de73dc
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 16 deletions.
3 changes: 0 additions & 3 deletions inc.lib/classes/MusicXML/MusicXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function midiToMusicXml($midi, $title, $version = "4.0", $format = MXL::X
}
}



/**
* Create Music XML manualy
*
Expand Down Expand Up @@ -111,7 +109,6 @@ public function getMusicXml($domdoc, $version = "4.0")
$measure = new Measure();
$measure->number = 1;


$key = new Key();
$key->fifths = 1;

Expand Down
4 changes: 2 additions & 2 deletions inc.lib/classes/MusicXML/MusicXMLBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public function initializeArray($initialValue)
public function getTime($timeSignature)
{
$time = new Time();
$time->beats = $timeSignature->beats;
$time->beatType = $timeSignature->beatType;
$time->beats = $timeSignature->getBeats();
$time->beatType = $timeSignature->getBeatType();
return $time;
}

Expand Down
9 changes: 3 additions & 6 deletions inc.lib/classes/MusicXML/MusicXMLFromMidi.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,7 @@ private function getEventList($controlEvents)
$keySignatureList[$time] = array('fifths'=>$fifths, 'mode'=>$message['mode']);
}
}
$midiEvent = new MidiEvent();
$midiEvent->tempoList = $tempoList;
$midiEvent->keySignatureList = $keySignatureList;
return $midiEvent;
return new MidiEvent($tempoList, $keySignatureList);
}

/**
Expand Down Expand Up @@ -852,8 +849,8 @@ private function getMeasure($partId, $channelId, $measureIndex, $timebase)
// events whithout channel information
$controlEvents0 = $this->getControlEvent($midiEventMessages);
$midiEvent = $this->getEventList($controlEvents0);
$tempoList = $midiEvent->tempoList;
$keySignatureList = $midiEvent->keySignatureList;
$tempoList = $midiEvent->getTempoList();
$keySignatureList = $midiEvent->getKeySignatureList();

if(!empty($tempoList))
{
Expand Down
55 changes: 53 additions & 2 deletions inc.lib/classes/MusicXML/Properties/MidiEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,58 @@

class MidiEvent
{
public $tempoList = array();
public $keySignatureList = array();
private $tempoList = array();
private $keySignatureList = array();

/**
* Constructor
*
* @param array $tempoList
* @param array $keySignatureList
*/
public function __construct($tempoList, $keySignatureList)
{
$this->setTempoList($tempoList);
$this->setKeySignatureList($keySignatureList);
}

/**
* Get the value of tempoList
*/
public function getTempoList()
{
return $this->tempoList;
}

/**
* Set the value of tempoList
*
* @return self
*/
public function setTempoList($tempoList)
{
$this->tempoList = $tempoList;

return $this;
}

/**
* Get the value of keySignatureList
*/
public function getKeySignatureList()
{
return $this->keySignatureList;
}

/**
* Set the value of keySignatureList
*
* @return self
*/
public function setKeySignatureList($keySignatureList)
{
$this->keySignatureList = $keySignatureList;

return $this;
}
}
66 changes: 63 additions & 3 deletions inc.lib/classes/MusicXML/Properties/TimeSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class TimeSignature
{
public $time = 0;
public $beats = 0;
public $beatType = 4;
private $time = 0;
private $beats = 0;
private $beatType = 4;

public function __construct($msg)
{
Expand All @@ -15,4 +15,64 @@ public function __construct($msg)
$this->beats = $arr[0];
$this->beatType = $arr[1];
}

/**
* Get the value of time
*/
public function getTime()
{
return $this->time;
}

/**
* Set the value of time
*
* @return self
*/
public function setTime($time)
{
$this->time = $time;

return $this;
}

/**
* Get the value of beats
*/
public function getBeats()
{
return $this->beats;
}

/**
* Set the value of beats
*
* @return self
*/
public function setBeats($beats)
{
$this->beats = $beats;

return $this;
}

/**
* Get the value of beatType
*/
public function getBeatType()
{
return $this->beatType;
}

/**
* Set the value of beatType
*
* @return self
*/
public function setBeatType($beatType)
{
$this->beatType = $beatType;

return $this;
}
}

0 comments on commit 6de73dc

Please sign in to comment.