예제 #1
0
파일: midigen.php 프로젝트: niieani/nandu
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);
}
예제 #2
0
 />show MIDI result as Text<br />
<input type="checkbox" name="showXml"<?php 
echo isset($_POST['showXml']) ? ' checked="checked"' : '';
?>
 />show MIDI result as XML
-->
<br /><br />
<input type="submit" name="play" value=" PLAY! " />&nbsp;&nbsp;
<input type="submit" name="publish" value="Publish" onclick="return confirm('Are you sure this mix is worth to be published?')" />&nbsp;&nbsp;<br /><br />

<?php 
if ($play) {
    $save_dir = 'tmp/';
    srand((double) microtime() * 1000000);
    $file = $save_dir . rand() . '.mid';
    $midi->open(480);
    //timebase=480, quarter note=120
    $midi->setBpm($bpm);
    for ($k = 1; $k <= 8; $k++) {
        if ($aktiv[$k]) {
            $ch = $k < 5 ? 10 : $k;
            $inst = $_POST["inst{$k}"];
            $n = $_POST["note{$k}"];
            $v = $_POST["vol{$k}"];
            $t = 0;
            $ts = 0;
            $tn = $midi->newTrack() - 1;
            $midi->addMsg($tn, "0 PrCh ch={$ch} p={$inst}");
            for ($r = 0; $r < $rep; $r++) {
                for ($i = 0; $i < 16; $i++) {
                    if ($ts == $t + 120) {
예제 #3
0
	$note[$k] = isset($_POST["note$k"])?$_POST["note$k"]:35;
	$vol[$k] = isset($_POST["vol$k"])?$_POST["vol$k"]:127;
}*/


//if ($play){

	$save_dir = 'tmp/';
	srand((double)microtime()*1000000);
	$file = $save_dir.rand().'.mid';
	
	//DEFAULTS
	$rep = 1; //repetitions
	$bpm = 60; //BPM

	$midi->open(480); //timebase=480, quarter note=120
	$midi->setBpm($bpm);
	
	//for ($k=1;$k<=8;$k++) 
	{		
		//$ch = ($k<5) ? 10 : $k;
		
		//channel
		$ch = 1;
		
		//$inst = $_POST["inst$k"];
		$inst = 0;
		
		// pitch
		$n = 70; 
		//$n = $_POST["note$k"];
예제 #4
0
 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);
 }
예제 #5
0
 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);
     }
 }