|
From: Bantai <ba...@us...> - 2007-11-06 22:25:42
|
Update of /cvsroot/xrns-php/xrns-php/scripts In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2377 Modified Files: xrns2midi.php xrns2midi_classes.php Log Message: Added PHP Version checking and debugger detection, some cleanups and a lot of wasted time on failed attempts to implement AllNotesOff, the FF00 (Kill all notes and fx) command and the F100 (Stop Song) command. Index: xrns2midi_classes.php =================================================================== RCS file: /cvsroot/xrns-php/xrns-php/scripts/xrns2midi_classes.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** xrns2midi_classes.php 6 Sep 2007 21:22:57 -0000 1.3 --- xrns2midi_classes.php 6 Nov 2007 22:25:14 -0000 1.4 *************** *** 1,10 **** <?php ! // XRNS2MID version 0.20 by Marvin Tjon (Bantai) ! // ! // Last saved on 6 Sep 2007 // Based on XRNS2MID version 0.03 by Dac Chartrand ! // ! // This file contains helper classes for the main script: // - xrns2midi.php [...1405 lines suppressed...] ! elseif ($pan > 0xD0 && $pan <= 0xDF) ! $lastnote->offset = $pan - 0xD0; ! //Retrig note X ticks (E0 - EF) ! //Notes = ceil(speed / X); X(0) = 1; ! elseif ($pan > 0xE0 && $pan <= 0xEF) ! $lastnote->retrig = $pan - 0xE0; ! ! //Cut Note after X Ticks (F0 - FE) ! elseif ($pan > 0xF0 && $pan <= 0xFE) { $evt = clone $lastnote; $evt->evttype = 2; ! MidiList::getTrack($evt->inst)->addEvent($pos, $pan-0xF0, $evt->col, $evt); } ! } ! } } ! ?> Index: xrns2midi.php =================================================================== RCS file: /cvsroot/xrns-php/xrns-php/scripts/xrns2midi.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** xrns2midi.php 6 Sep 2007 21:22:57 -0000 1.5 --- xrns2midi.php 6 Nov 2007 22:25:14 -0000 1.6 *************** *** 1,15 **** <?php ! // XRNS2MID version 0.20 by Marvin Tjon (Bantai) ! // ! // Last saved on 6 Sep 2007 ! // Based on XRNS2MID version 0.03 by Dac Chartrand ! // ! // Requires: // - midi_class_v16 // - xrns2midi_classes.php ! // - xrns_functions.php $time['start'] = microtime(true); // ---------------------------------------------------------------------------- --- 1,20 ---- + #!/usr/bin/php -n -q <?php ! // XRNS2MIDI version 0.21 by Marvin Tjon (Bantai) ! // ! // Last saved on 8 Oct 2007 ! // Based on XRNS2MIDI version 0.03 by Dac Chartrand ! // ! // Requires: // - midi_class_v16 // - xrns2midi_classes.php ! // - xrns_functions.php ! ! // To-Do for 0.21: ! // - poly-aftertouch for volume $time['start'] = microtime(true); + $xrns2midi_version = "0.21"; // ---------------------------------------------------------------------------- *************** *** 17,28 **** // ---------------------------------------------------------------------------- ! // Script usually exectues in a few seconds. During the conversion from xml to mid, ! // the script may hang if the midi events are incorrectly sorted. set_time_limit(240); //4 minutes ! // Valididate song $schema_check = true; // ---------------------------------------------------------------------------- // Variables --- 22,53 ---- // ---------------------------------------------------------------------------- ! if (!defined('DEBUGGER_VERSION')) ! { //FOR USERS + // Check PHP Version. PHP versions below 5.2.3 may + // lower this script's performance to 3% and even lower! + echo "\nCurrent PHP version: ". PHP_VERSION . "\n"; + if (version_compare(PHP_VERSION, "5.2.3", "<")) + { + echo "\n*=====================================*\n"; + echo "\n WARNING: Update your PHP installation!\n\n PHP versions below 5.2.3 may increase\n execution time by a factor 30 to 90.\n\n"; + echo "*=====================================*\n"; + sleep(3); + } + + // Script usually exectues in a few seconds. During the conversion from xml to mid, + // the script may hang if the midi events are incorrectly sorted. set_time_limit(240); //4 minutes ! // Validate song $schema_check = true; + } + else + { //FOR DEBUGGERS + // Do not validate song + $schema_check = false; + + } // ---------------------------------------------------------------------------- // Variables *************** *** 30,34 **** // Files are extracted in the root temp folder. ! $tmp_dir = '/temp'; // ---------------------------------------------------------------------------- --- 55,62 ---- // Files are extracted in the root temp folder. ! $tmp_dir = '/temp'; ! ! // Exit status ! $err = 0; // ---------------------------------------------------------------------------- *************** *** 66,70 **** */ ! if (isset($argv[1]) && !isset($argv[2]) || isset($argv[2]) && !isset($argv[1])) { echo "Error: $argv[0] expects at least 2 parameters.\n"; --- 94,98 ---- */ ! if (isset($argv[1]) && !isset($argv[2]) || isset($argv[2]) && !isset($argv[1])) { echo "Error: $argv[0] expects at least 2 parameters.\n"; *************** *** 73,97 **** die(); } ! elseif (isset($argv[1]) && isset($argv[2])) { // Specify by command line ! if (!file_exists($argv[1])) ! die("Error: Input file `".$argv[1]."` not found.\n"); $xrns_file = $argv[1]; $mid_file = $argv[2]; ! } elseif (isset($_GET['xrns']) && isset($_GET['mid'])) { //Server version: xrns2midi.php?xrns=filename.xrns&mid=filename.mid //TODO: security, form, upload ! if (!file_exists($_GET['xrns'])) ! die("Error: Input file `".$_GET['xrns']."` not found.\n"); $xrns_file = $_GET['xrns']; ! $mid_file = $_GET['mid']; } ! else ! { //Specify manually ! $xrns_file = "C:/[bb5entries]/test/note-off.xrns"; ! $mid_file = "C:/[bb5entries]/test/note-off.020.mid"; if (!file_exists($xrns_file)) ! die("Error: Input file not found.\n"); } --- 101,125 ---- die(); } ! elseif (isset($argv[1]) && isset($argv[2])) { // Specify by command line ! if (!file_exists($argv[1])) ! die("Error: Input file `".$argv[1]."` not found.\n"); $xrns_file = $argv[1]; $mid_file = $argv[2]; ! } elseif (isset($_GET['xrns']) && isset($_GET['mid'])) { //Server version: xrns2midi.php?xrns=filename.xrns&mid=filename.mid //TODO: security, form, upload ! if (!file_exists($_GET['xrns'])) ! die("Error: Input file `".$_GET['xrns']."` not found.\n"); $xrns_file = $_GET['xrns']; ! $mid_file = $_GET['mid']; } ! else ! { //Specify manually ! $xrns_file = "C:/[bb5entries]/test/ff00.xrns"; ! $mid_file = "C:/[bb5entries]/test/ff00.$xrns2midi_version.mid"; if (!file_exists($xrns_file)) ! die("Error: Input file not found.\n"); } *************** *** 100,107 **** // ---------------------------------------------------------------------------- ! echo "---------------------------------------\n"; ! echo "$argv[0] is working...\n"; echo date("D M j G:i:s T Y\n"); ! echo "---------------------------------------\n"; echo "Using temporary directory: $tmp_dir\n"; echo "Input: $xrns_file \nOutput: $mid_file (+.xml, +.txt)\n\n"; --- 128,135 ---- // ---------------------------------------------------------------------------- ! echo "\n---------------------------------------\n"; ! echo "XRNS2MIDI v$xrns2midi_version is working...\n"; echo date("D M j G:i:s T Y\n"); ! echo "---------------------------------------\n\n"; echo "Using temporary directory: $tmp_dir\n"; echo "Input: $xrns_file \nOutput: $mid_file (+.xml, +.txt)\n\n"; *************** *** 124,128 **** // ---------------------------------------------------------------------------- ! echo "XRNS Document Version: " . $doc_version = $sx['doc_version'] . "\n\n"; if ($schema_check) { --- 152,156 ---- // ---------------------------------------------------------------------------- ! echo "XRNS Document Version: " . $doc_version = $sx['doc_version'] . "\n"; if ($schema_check) { *************** *** 132,138 **** die("\n". $xrns_file . " failed to validate against schema. The song appears to be broken.\n\n" ); } ! echo "\n"; } ! // ---------------------------------------------------------------------------- --- 160,174 ---- die("\n". $xrns_file . " failed to validate against schema. The song appears to be broken.\n\n" ); } ! else ! { ! echo "Document has succesfully passed validation.\n"; ! //unfortunately also displayed when the schema is not found ! } } ! else ! { ! echo "Document validation disabled.\n"; ! } ! echo "\n"; // ---------------------------------------------------------------------------- *************** *** 159,163 **** /* ! MidiList MidiTracks id (#miditrack) --- 195,199 ---- /* ! MidiList MidiTracks id (#miditrack) *************** *** 165,169 **** name (instrument name) channel ! MidiEvents[line][tick][originating note column][subevent] getMsg() */ --- 201,205 ---- name (instrument name) channel ! MidiEvents[line][tick][originating note column][subevent] getMsg() */ *************** *** 173,179 **** // PARSE SEQUENCE // ================================================================ $seq = array(); ! foreach ($sx->PatternSequence->PatternSequence->Pattern as $p) { $seq[] = (int)$p; --- 209,216 ---- // PARSE SEQUENCE // ================================================================ + $seq = array(); ! foreach ($sx->PatternSequence->PatternSequence->Pattern as $p) { $seq[] = (int)$p; *************** *** 189,203 **** { $p = $sx->PatternPool->Patterns->Pattern[$patternid]; ! //foreach ($sx->PatternPool->Patterns->Pattern as $p) { ! $track = 0; // reset track ! $NumberOfLines[$pn] = (int)$p->NumberOfLines; //$patternid = (int)$sx->PatternSequence->PatternSequence->Pattern[$pn]; if (isset($p->Name)) $patternName = (string)$p->Name; else $patternName = ''; ! echo " Parsing pattern [$pn]: $patternid $patternName... \n"; ! $master->addEventArr($lines,0, 0,11,array('type'=>'Marker', 'string'=>"Pattern [$pn]: $patternid $patternName")); ! foreach (array($p->Tracks->PatternTrack,$p->Tracks->PatternMasterTrack, $p->Tracks->PatternSendTrack) as $tx) ! foreach ($tx as $x){ ! ! if ($x->Lines->Line) foreach ($x->Lines->Line as $y) { if ((int)$y['index'] > $NumberOfLines[$pn] - 1) break; --- 226,240 ---- { $p = $sx->PatternPool->Patterns->Pattern[$patternid]; ! //foreach ($sx->PatternPool->Patterns->Pattern as $p) { ! $track = 0; // reset track ! $NumberOfLines[$pn] = (int)$p->NumberOfLines; //$patternid = (int)$sx->PatternSequence->PatternSequence->Pattern[$pn]; if (isset($p->Name)) $patternName = (string)$p->Name; else $patternName = ''; ! echo " Parsing pattern [$pn]: $patternid $patternName... \n"; ! $master->addEventArr($lines,0, 0,11,array('type'=>'Marker', 'string'=>"Pattern [$pn]: $patternid $patternName")); ! foreach (array($p->Tracks->PatternTrack,$p->Tracks->PatternMasterTrack, $p->Tracks->PatternSendTrack) as $tx) ! foreach ($tx as $x){ ! ! if ($x->Lines->Line) foreach ($x->Lines->Line as $y) { if ((int)$y['index'] > $NumberOfLines[$pn] - 1) break; *************** *** 211,217 **** $n_column = 100 * $track; $nn=0; ! if ($y->NoteColumns->NoteColumn) foreach ($y->NoteColumns->NoteColumn as $z) ! { ! $n_column += $nn++; // Parse note string into note number if($z->Note) --- 248,254 ---- $n_column = 100 * $track; $nn=0; ! if ($y->NoteColumns->NoteColumn) foreach ($y->NoteColumns->NoteColumn as $z) ! { ! $n_column += $nn++; // Parse note string into note number if($z->Note) *************** *** 222,226 **** // Fetch Instrument Number if($z->Instrument) ! { //midi tracks start with 1, so instr has to be inc by 1 $inst = (int) intval((string) $z->Instrument, 16) + 1; --- 259,263 ---- // Fetch Instrument Number if($z->Instrument) ! { //midi tracks start with 1, so instr has to be inc by 1 $inst = (int) intval((string) $z->Instrument, 16) + 1; *************** *** 244,249 **** if ($note && $note != 'Off' && $inst != 0) { ! //NNA: note-cut (only by this instr) ! $lnF = MasterTrack::getLastNote($n_column); //find last note originating from this note-column if ($lnF !== false && $lnF->evttype != 2) //if there is a new note with instr number and there is a note before it --- 281,286 ---- if ($note && $note != 'Off' && $inst != 0) { ! //NNA: note-cut (only by this instr) ! $lnF = MasterTrack::getLastNote($n_column); //find last note originating from this note-column if ($lnF !== false && $lnF->evttype != 2) //if there is a new note with instr number and there is a note before it *************** *** 253,267 **** $evt = clone $lnF; //make a copy of the last note $evt->evttype = 2; //set it to note-off ! $evt->vol = 0; //another way to set note-off $evt->setOffset(0); ! $evt->retrig = null; if (false) //bypass note-off offset for now { $evt->setOffset(-1); //put the note-off n ticks before the new note //by convention, if the offset is negative, we decrease $pos by 1 line ! MidiList::getTrack($evt->inst)->addEvent($pos-1, -1, $n_column, $evt); ! } ! else ! MidiList::getTrack($evt->inst)->addEvent($pos, 0, $n_column, $evt); } //if the current midicol is occupied, create a new event on a new midicol --- 290,304 ---- $evt = clone $lnF; //make a copy of the last note $evt->evttype = 2; //set it to note-off ! $evt->vol = 0; //another way to set note-off $evt->setOffset(0); ! $evt->retrig = null; if (false) //bypass note-off offset for now { $evt->setOffset(-1); //put the note-off n ticks before the new note //by convention, if the offset is negative, we decrease $pos by 1 line ! MidiList::getTrack($evt->inst)->addEvent($pos-1, -1, $n_column, $evt); ! } ! else ! MidiList::getTrack($evt->inst)->addEvent($pos, 0, $n_column, $evt); } //if the current midicol is occupied, create a new event on a new midicol *************** *** 274,283 **** $lnF = MasterTrack::getLastNote($n_column); //find last note originating from this note-column if ($lnF !== false && $lnF->evttype != 2) //if there is a new note with instr number and there is a note before it ! { $evt = clone $lnF; //make a copy of the last note $evt->evttype = 2; //set it to note-off ! $evt->vol = 0; //another way to set note-off ! MidiList::getTrack($evt->inst)->addEvent($pos, 0,$n_column, $evt); ! } } else if ($note && $inst != 0) --- 311,320 ---- $lnF = MasterTrack::getLastNote($n_column); //find last note originating from this note-column if ($lnF !== false && $lnF->evttype != 2) //if there is a new note with instr number and there is a note before it ! { $evt = clone $lnF; //make a copy of the last note $evt->evttype = 2; //set it to note-off ! $evt->vol = 0; //another way to set note-off ! MidiList::getTrack($evt->inst)->addEvent($pos, 0,$n_column, $evt); ! } } else if ($note && $inst != 0) *************** *** 285,289 **** //ghost note //Renoise disallows instr numbers on note-offs, but not vol/pan ! } else if (!$note && $inst == 0) --- 322,326 ---- //ghost note //Renoise disallows instr numbers on note-offs, but not vol/pan ! } else if (!$note && $inst == 0) *************** *** 292,299 **** //instr switch feature? } ! else { ! // Do something with empty note? } --- 329,336 ---- //instr switch feature? } ! else { ! // Do something with empty note? } *************** *** 303,313 **** // ---------------------------------------------------------------- //applies to closest note of any instr in this col ! //TODO: vol/pan fx without note/instr if($lastnote = MasterTrack::getLastNote($n_column)) { ! $master->doVolPanFx($pos, $z->Volume, $z->Panning, $lastnote); } ! ! $n_column++; } // end note columns --- 340,350 ---- // ---------------------------------------------------------------- //applies to closest note of any instr in this col ! //TODO: vol/pan fx without note/instr if($lastnote = MasterTrack::getLastNote($n_column)) { ! $master->doVolPanFx($pos, $z->Volume, $z->Panning, $lastnote); } ! ! $n_column++; } // end note columns *************** *** 315,319 **** // Effect Columns // ---------------------------------------------------------------- ! if ($y->EffectColumns->EffectColumn) { --- 352,356 ---- // Effect Columns // ---------------------------------------------------------------- ! if ($y->EffectColumns->EffectColumn) { *************** *** 322,326 **** if ($z->Number == '00') continue; ! //fetch hexadecimal pattern command from song.xrns $effectNumber = (int)intval((string)$z->Number,16); --- 359,363 ---- if ($z->Number == '00') continue; ! //fetch hexadecimal pattern command from song.xrns $effectNumber = (int)intval((string)$z->Number,16); *************** *** 332,359 **** switch ($effectNumber) { ! case 0xF0: if ($effectValue >= 0x20 && $effectValue <= 0xFF) { ! $master->globals['bpm'][$pos] = $effectValue; } break; ! case 0xF1: ! if ($effectValue >= 0x00 && $effectValue <= 0x1F) { ! $master->globals['speed'][$pos] = $effectValue; $master->globals['lpb'][$pos] = $master->getLpb($effectValue); } ! break; //TODO: `stop` command F100 //case 0xFB - Pattern break //TODO: automation follow //case 0xFD - Delay complete pattern xx lines. ! //case 0xFF: Stop all track effects and notes. ! } } } ! } //end lines ! ++$track; ! } // end tracks ! $pn++; ! $lines += $p->NumberOfLines; } //end patterns --- 369,408 ---- switch ($effectNumber) { ! case 0x0C: //track volume ! break; ! case 0xF0: if ($effectValue >= 0x20 && $effectValue <= 0xFF) { ! $master->globals['bpm'][$pos] = $effectValue; } break; ! case 0xF1: ! if ($effectValue > 0x00 && $effectValue <= 0x1F) { ! $master->globals['speed'][$pos] = $effectValue; $master->globals['lpb'][$pos] = $master->getLpb($effectValue); } ! elseif ($effectValue == 0) ! { // F100 (Stop Song) ! //ignore command for now ! //$master->addEvent($pos,0,0, new MidiEvent(12, null)); ! } ! break; ! case 0xFC: //master volume ! break; //case 0xFB - Pattern break //TODO: automation follow //case 0xFD - Delay complete pattern xx lines. ! case 0xFF: //Stop all track effects and notes on track. ! //Very hard to do, because notes in the track may be spreaded over several midi channels. ! //$master->addEvent($pos,0,0, new MidiEvent(5, array('ch'=>4, 'val'=>0))); ! break; ! } } } ! } //end lines ! ++$track; ! } // end tracks ! $pn++; ! $lines += $p->NumberOfLines; } //end patterns *************** *** 369,396 **** echo "\nCommited global events in {$ms}ms \n\n"; ! //note-off on every column at end of song foreach(MasterTrack::$lastNotes as $n_column=>&$evt) { ! $evt = clone $evt; $evt->evttype = 2; ! $evt->vol = 0; $evt->offset = 0; ! MidiList::getTrack($evt->inst)->addEvent($lines, 0, $n_column, $evt); } //add Pattern Sequencer loop if (($cp = (int)$sx->PatternSequence->LoopSelection->CursorPos) > -1) { $rp = (int)$sx->PatternSequence->LoopSelection->RangePos; ! $loopstart = 0; ! for ($i=0; $i<$cp;$i++) ! $loopstart += $NumberOfLines[$i]; ! $loopend = $loopstart; for ($i=$cp; $i<$rp;$i++) ! $loopend += $NumberOfLines[$i]; ! $master->addEventArr($loopstart,0,0,11,array('type'=>'Marker', 'string'=>'Loop start')); $master->addEventArr($loopend,0,0,11,array('type'=>'Marker', 'string'=>'Loop end')); --- 418,449 ---- echo "\nCommited global events in {$ms}ms \n\n"; ! ! //forced note-off on every column at end of song foreach(MasterTrack::$lastNotes as $n_column=>&$evt) { ! if ($evt->evttype == 2) ! continue; ! $evt = clone $evt; $evt->evttype = 2; ! $evt->vol = 0; $evt->offset = 0; ! MidiList::getTrack($evt->inst)->addEvent($lines, 0, $n_column, $evt); } + //add Pattern Sequencer loop if (($cp = (int)$sx->PatternSequence->LoopSelection->CursorPos) > -1) { $rp = (int)$sx->PatternSequence->LoopSelection->RangePos; ! $loopstart = 0; ! for ($i=0; $i<$cp;$i++) ! $loopstart += $NumberOfLines[$i]; ! $loopend = $loopstart; for ($i=$cp; $i<$rp;$i++) ! $loopend += $NumberOfLines[$i]; ! $master->addEventArr($loopstart,0,0,11,array('type'=>'Marker', 'string'=>'Loop start')); $master->addEventArr($loopend,0,0,11,array('type'=>'Marker', 'string'=>'Loop end')); *************** *** 398,486 **** ! //Sorting MidiList is useless; midi tracks are generated in order of //the instrument's first appearance in the song. ! //Take notice: use references in foreach, or the updates to the arrays //will be ignored! foreach($midiList as &$miditrack) ! { $id = $miditrack->id; ! echo " Sending events for MidiTrack $id...\n"; foreach ($miditrack as $pos=>&$ticks) ! { ! //echo "Line: $pos \n"; //TODO: remove previous data foreach ($ticks as $tick=>&$events) ! { //echo "\tTick: $tick \n"; foreach ($events as &$subevents) ! { foreach ($subevents as $evtnum=>&$evt) ! { //note-delay //if offset is valid, move event to tick position //if offset exceeds speed, do event on this tick, further down this loop if (isset($evt->offset) && $evt->offset != 0) ! { $offset = $evt->offset; ! $evt->offset = 0; ! $speed = $master->getNearestGlobal($pos, 'speed')->val; ! if ($speed > $offset) ! { $ticks[$offset][$evt->col][] = $evt; ! unset($subevents[$evtnum]); ! ksort($ticks); continue; ! } ! } ! //everything that comes after this needs this timestamp ! $timestamp = $master->getTimeStamp($pos,$tick); $evt->setTimestamp($timestamp); ! //retrigger if (isset($evt->retrig) && $evt->retrig != 0 && $evt->evttype != 2) ! { ! $retrig = $evt->retrig; $evt->retrig = 0; ! $speed = $master->getNearestGlobal($pos, 'speed')->val; if ($speed > $retrig) ! { $offset = 0; $ticksleft = $speed; unset($lastevt); ! while($ticksleft > 0) ! { if (isset($lastevt)) { ! $lastevt->evttype = 2; ! $ticks[$offset][$lastevt->col][] = $lastevt; } if ($offset == 0) MasterTrack::$midi->addMsg($id, $evt->getMsg()); ! else ! { ! $ticks[$offset][$evt->col][] = $evt; } ! $ticksleft -= $retrig; $offset += $retrig; ! $lastevt = clone $evt; ! } ksort($ticks); ! unset($subevents[$evtnum]); ! continue; //this is event is done, so skip the rest } ! } ! MasterTrack::$midi->addMsg($id, $evt->getMsg()); ! unset($subevents[$evtnum]); } //unset($subevents); } ! //unset($events); ! } ! //unset($ticks); } ! MasterTrack::$midi->addMsg($id, $master->getTimestamp($lines, null)+1 . " Meta TrkEnd"); } --- 451,543 ---- ! //Sorting MidiList is useless; midi tracks are generated in order of //the instrument's first appearance in the song. ! //Take notice: use references in foreach, or the updates to the arrays //will be ignored! foreach($midiList as &$miditrack) ! { $id = $miditrack->id; ! echo " Sending events for MidiTrack $id...\n"; foreach ($miditrack as $pos=>&$ticks) ! { ! //echo "Line: $pos \n"; //TODO: remove previous data foreach ($ticks as $tick=>&$events) ! { //echo "\tTick: $tick \n"; foreach ($events as &$subevents) ! { foreach ($subevents as $evtnum=>&$evt) ! { //note-delay //if offset is valid, move event to tick position //if offset exceeds speed, do event on this tick, further down this loop if (isset($evt->offset) && $evt->offset != 0) ! { $offset = $evt->offset; ! $evt->offset = 0; ! $speed = $master->getNearestGlobal($pos, 'speed')->val; ! if ($speed > $offset) ! { $ticks[$offset][$evt->col][] = $evt; ! unset($subevents[$evtnum]); ! ksort($ticks); continue; ! } ! } ! //everything that comes after this needs this timestamp ! $timestamp = $master->getTimeStamp($pos,$tick); $evt->setTimestamp($timestamp); ! //retrigger if (isset($evt->retrig) && $evt->retrig != 0 && $evt->evttype != 2) ! { ! $retrig = $evt->retrig; $evt->retrig = 0; ! $speed = $master->getNearestGlobal($pos, 'speed')->val; if ($speed > $retrig) ! { $offset = 0; $ticksleft = $speed; unset($lastevt); ! while($ticksleft > 0) ! { if (isset($lastevt)) { ! $lastevt->evttype = 2; ! $ticks[$offset][$lastevt->col][] = $lastevt; } if ($offset == 0) MasterTrack::$midi->addMsg($id, $evt->getMsg()); ! else ! { ! $ticks[$offset][$evt->col][] = $evt; } ! $ticksleft -= $retrig; $offset += $retrig; ! $lastevt = clone $evt; ! } ksort($ticks); ! unset($subevents[$evtnum]); ! continue; //this is event is done, so skip the rest } ! } ! MasterTrack::$midi->addMsg($id, $evt->getMsg()); ! unset($subevents[$evtnum]); } //unset($subevents); } ! //unset($events); ! } ! //unset($ticks); } ! //All notes off MIDI command ! //if ($id > 0) ! // MasterTrack::$midi->addMsg($id, $master->getTimestamp($lines, null) . " Par ch=$id c=123 v=0"); ! ! //MIDI Meta Event: Track End MasterTrack::$midi->addMsg($id, $master->getTimestamp($lines, null)+1 . " Meta TrkEnd"); } *************** *** 509,520 **** $time['mid_start'] = microtime(true); ! try { ! MasterTrack::$midi->saveMidFile($mid_file); } catch (Exception $e) { echo $e->getMessage() . "\n"; ! echo $e->getTraceAsString(); } --- 566,578 ---- $time['mid_start'] = microtime(true); ! try { ! MasterTrack::$midi->saveMidFile($mid_file); } catch (Exception $e) { echo $e->getMessage() . "\n"; ! echo $e->getTraceAsString(); ! $err = 1; } *************** *** 528,537 **** echo "\nTotal execution time: {$ms} seconds\n"; ! echo "---------------------------------------\n"; echo "$argv[0] is done!\n"; echo date("D M j G:i:s T Y\n"); echo "---------------------------------------\n"; ! ! ?> \ No newline at end of file --- 586,595 ---- echo "\nTotal execution time: {$ms} seconds\n"; ! echo "\n---------------------------------------\n"; echo "$argv[0] is done!\n"; echo date("D M j G:i:s T Y\n"); echo "---------------------------------------\n"; + exit($err); ! ?> |