Midi 2 RTTTL Converter with PHP

liunx

Guest
i have question about midi 2 rtttl convertor.

this is midi file in txt format :

MFile 0 1 384
MTrk
0 Meta Copyright ""
0 Meta TrkName "Coca-Cola"
0 Par ch=1 c=7 v=127
0 Tempo 480000
0 PrCh ch=1 p=0
0 On ch=1 n=78 v=100
192 Off ch=1 n=78 v=0
192 On ch=1 n=78 v=100
384 Off ch=1 n=78 v=0
384 On ch=1 n=78 v=100
576 Off ch=1 n=78 v=0
576 On ch=1 n=78 v=100
768 Off ch=1 n=78 v=0
768 On ch=1 n=79 v=100
960 Off ch=1 n=79 v=0
960 On ch=1 n=78 v=100
1152 Off ch=1 n=78 v=0
1152 On ch=1 n=76 v=100
1344 Off ch=1 n=76 v=0
1344 On ch=1 n=76 v=100
1536 Off ch=1 n=76 v=0
1536 On ch=1 n=81 v=100
1728 Off ch=1 n=81 v=0
1728 On ch=1 n=78 v=100
1920 Off ch=1 n=78 v=0
1920 On ch=1 n=74 v=100
2112 Off ch=1 n=74 v=0
2112 Meta TrkEnd
TrkEnd

this is rtttl format
Coca-Cola:d=4,o=5,b=125:8f#6,8f#6,8f#6,8f#6,g6,8f#6,e6,8e6,8a6,f#6,d6,2p

i have some php code to get note and scale :

$line = '2400 On ch=2 n=58 v=43'; // note-number 58
$note_list = array("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#",
"A","A#", "B");
$msg = explode(' ', $line);
$time = (int) $msg[0];
eval("\$".$msg[3].';'); // now $n = 58
$note = $note_list[$n % 12];
$scale = floor($n/12)-2;
echo $note; // A#
echo $scale; // 2

if use php programming language how to get duration, special duration (dotted note) and pauze note.

please help me
 
Back
Top