function generateOgg($pitches) { $midi = new Midi(); /* $instruments = $midi->getInstrumentList(); $drumset = $midi->getDrumset(); $drumkit = $midi->getDrumkitList(); $notes = $midi->getNoteList(); */ $save_dir = __DIR__.'/tmp/'; srand((double)microtime()*1000000); $file = $save_dir.rand(); //DEFAULTS $rep = 1; //repetitions $bpm = 90; //BPM $midi->open(480); //timebase=480, quarter note=120 $midi->setBpm($bpm); //channel $ch = 1; //$inst = $_POST["inst$k"]; $inst = 0; // pitch //$pitches = array(50,60,70,60,70,60,70,40); // volume $v = 127; $ticksBetweenEvents = 480; // 120 = quarter note $t = 0; $ts = 0; $tn = $midi->newTrack() - 1; $midi->addMsg($tn, "0 PrCh ch=$ch p=$inst"); foreach ($pitches as $n) { if ($ts == $t+$ticksBetweenEvents) $midi->addMsg($tn, "$ts Off ch=$ch n=$n v=127"); $t = $ts; $midi->addMsg($tn, "$t On ch=$ch n=$n v=$v"); $ts += $ticksBetweenEvents; if ($ts == $t+$ticksBetweenEvents) $midi->addMsg($tn, "$ts Off ch=$ch n=$n v=127"); } $midi->addMsg($tn, "$ts Meta TrkEnd"); $midi->saveMidFile($file.'.mid', 0666); system('/usr/bin/timidity -Ow --output-mono --verbose=-2 --output-file=- '.$file.'.mid | oggenc -q-1 -o '.$file.'.ogg -'); //$midi->playMidFile($file,$visible,$autostart,$loop,$player); }
$midi->addMsg($tn, "{$ts} Off ch={$ch} n={$n} v=127"); } if (isset($_POST["n{$k}{$i}"])) { $t = $ts; $midi->addMsg($tn, "{$t} On ch={$ch} n={$n} v={$v}"); } $ts += 120; } if ($ts == $t + 120) { $midi->addMsg($tn, "{$ts} Off ch={$ch} n={$n} v=127"); } } $midi->addMsg($tn, "{$ts} Meta TrkEnd"); } } $midi->saveMidFile($file, 0666); $midi->playMidFile($file, $visible, $autostart, $loop, $player); ?> <br /><br /> <input type="button" name="download" value="Save as SMF (*.mid)" onclick="self.location.href='download.php?f=<?php echo urlencode($file); ?> '" /> <?php } ?> </td></tr></table> </td> <td style="width:10px"> </td> <td valign="top">
>Beatnik <input type="radio" name="engine" value="qt"<?php echo $engine == 'qt' ? ' checked' : ''; ?> >QuickTime <input type="radio" name="engine" value="wm"<?php echo $engine == 'wm' ? ' checked' : ''; ?> >Windows Media <input type="radio" name="engine" value=""<?php echo $engine == '' ? ' checked' : ''; ?> >other (default Player)<br><br> <input type="submit" value=" send "> </form> <?php if (isset($p['txt'])) { $midi = new Midi(); $midi->importTxt($txt); $midi->saveMidFile($file); $midi->playMidFile($file, 1, 1, 0, $engine); ?> <br><br><input type="button" name="download" value="Save as SMF (*.mid)" onClick="self.location.href='sequencer.php?download=<?php echo urlencode($file); ?> '"> <?php } ?> </body> </html>
function generateOgg($pitches) { //var_dump($pitches); $midi = new Midi(); /* $instruments = $midi->getInstrumentList(); $drumset = $midi->getDrumset(); $drumkit = $midi->getDrumkitList(); $notes = $midi->getNoteList(); */ $save_dir = __DIR__.'/tmp/'; // srand((double)microtime()*1000000); // $filename = rand(); $filename = time(); $file = $save_dir.$filename; //DEFAULTS $rep = 1; //repetitions $bpm = 90; //BPM $midi->open(480); //timebase=480, quarter note=120 $midi->setBpm($bpm); //channel $ch = 1; //$inst = $_POST["inst$k"]; $inst = 0; // pitch //$pitches = array(50,60,70,60,70,60,70,40); // volume $v = 127; $ticksBetweenEvents = 480; // 120 = quarter note $t = 0; $ts = 0; $tn = $midi->newTrack() - 1; $midi->addMsg($tn, "0 PrCh ch=$ch p=$inst"); for($r=0; $r<$rep; $r++) { foreach ($pitches as $n) { $n = $n + (12*5); // REMOVE THIS if ($ts == $t+$ticksBetweenEvents) $midi->addMsg($tn, "$ts Off ch=$ch n=$n v=127"); $t = $ts; $midi->addMsg($tn, "$t On ch=$ch n=$n v=$v"); $ts += $ticksBetweenEvents; if ($ts == $t+$ticksBetweenEvents) $midi->addMsg($tn, "$ts Off ch=$ch n=$n v=127"); } } $midi->addMsg($tn, "$ts Meta TrkEnd"); $midi->saveMidFile($file.'.mid', 0666); // system('/usr/bin/timidity -A100 -Ow --output-mono --verbose=-2 --reverb=g,100 --output-file=- '.$file.'.mid | oggenc -q2 -o '.$file.'.ogg -'); //we could also make use of FIFOs: //http://stackoverflow.com/questions/60942/how-can-i-send-the-stdout-of-one-process-to-multiple-processes-using-preferably $command = '/usr/bin/timidity -A110 -Ow --verbose=-2 --reverb=f,100 --output-file=- '.$file.'.mid | tee >(lame --silent -V6 - '.$file.'.mp3) | oggenc -q1 -o '.$file.'.ogg -'; // file_put_contents('command', $command); shell_exec('/bin/bash -c "'.$command.'"'); return ($filename); //$midi->playMidFile($file,$visible,$autostart,$loop,$player); }
$midi->transpose(12); } if (isset($p['down'])) { $midi->transpose(-12); } if (isset($p['double'])) { $midi->setTempo($midi->getTempo() / 2); } if (isset($p['half'])) { $midi->setTempo($midi->getTempo() * 2); } if (isset($p['solo'])) { $midi->soloTrack($p['soloTrackNum']); } if (isset($p['delete'])) { $midi->deleteTrack($p['delTrackNum']); } if (isset($p['insert'])) { $midi->insertMsg(0, "0 On ch=10 n=39 v=127"); $midi->insertMsg(0, "120 On ch=10 n=39 v=127"); $midi->insertMsg(0, "240 On ch=10 n=39 v=127"); } $midi->saveMidFile($new); $midi->playMidFile($new, 1, 1, 0, $plug); if (isset($p['show'])) { echo '<hr>' . nl2br($midi->getTxt()); } } ?> </body> </html>
// Require PHP MIDI class require 'lib/midi_class_v178/classes/midi.class.php'; // Decode post data $mxml = urldecode($_POST["midixmlformhidden"]); // TMP save directory $save_dir = 'tmp/'; // Random filename string srand((double) microtime() * 1000000); $tmpfile = $save_dir . rand() . '.mid'; // Time-limit @set_time_limit(600); # 10 minutes // Convert XMP and save MIDI file $midi = new Midi(); $midi->importXml($mxml); $midi->saveMidFile($tmpfile, 0666); // Download file $destfilename = 'bassline_explorer.mid'; //$midi->downloadMidFile($destFilename, $tmpfile); // Delete tmp file (not working) //sleep(30); //unlink($tmpfile); } else { // No post data echo "Error: No MIDIXML data received"; } ?> <input id="downloadbutton" type="button" name="download" value="Download MIDI File" onclick="self.location.href='download.php?f=<?php echo urlencode($tmpfile); ?> &n=<?php
function checkAndCreateKeysMidiFile() { global $mosConfig_absolute_path; if ($this->getBassNote() != "") { $bass = $this->getNote($this->getBassNote()); } else { $bass = $this->getNote($this->getMainNote()); } $chordKeys = $this->getChordBasicNotesAsNumbers(); $imageFilePath = "{$mosConfig_absolute_path}/components/com_chordbase/keys/" . $bass . "_" . implode("_", $chordKeys) . ".mid"; $chordNotes = $this->getChordNotesAsNumbers(); $instrument = 1; // Piano if (!file_exists($imageFilePath) && $chordNotes) { $midi = new Midi(); $midi->open(480); $midi->setBpm(120); $track = $midi->newTrack() - 1; $midi->addMsg($track, "0 PrCh ch=1 p={$instrument}"); $time = 20; foreach ($chordNotes as $noteDeslocation) { $midi->addMsg($track, "{$time} On ch=1 n={$noteDeslocation} v=127"); $time += 20; } $time += 1000; foreach ($chordNotes as $noteDeslocation) { $midi->addMsg($track, "{$time} Off ch=1 n={$noteDeslocation} v=127"); } foreach ($chordNotes as $noteDeslocation) { $midi->addMsg($track, "{$time} On ch=1 n={$noteDeslocation} v=127"); $time += 150; } $time += 1500; foreach ($chordNotes as $noteDeslocation) { $midi->addMsg($track, "{$time} Off ch=1 n={$noteDeslocation} v=127"); } $midi->addMsg($track, "{$time} Meta TrkEnd"); $midi->saveMidFile($imageFilePath); } }
} if (isset($_POST['half'])) { $midi->setTempo($midi->getTempo() * 2); } if (isset($_POST['solo'])) { $midi->soloTrack($_POST['soloTrackNum']); } if (isset($_POST['delete'])) { $midi->deleteTrack($_POST['delTrackNum']); } if (isset($_POST['insert'])) { $midi->insertMsg(0, "0 On ch=10 n=39 v=127"); $midi->insertMsg(0, "120 On ch=10 n=39 v=127"); $midi->insertMsg(0, "240 On ch=10 n=39 v=127"); } $midi->saveMidFile($new, 0666); $midi->playMidFile($new, $visible, $autostart, $loop, $player); ?> <br /><br /><input type="button" name="download" value="Save as SMF (*.mid)" onclick="self.location.href='download.php?f=<?php echo urlencode($new); ?> '" /> <?php } if (isset($_POST['show'])) { echo '<hr />' . nl2br($midi->getTxt()); } echo '</div>'; } ?>