Advertisement
Jousway

.SM to SMM

Apr 17th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?
  2. $bpm = 150;
  3. $data = "0000
  4. 0000
  5. 0000
  6. 0000
  7. ";
  8.  
  9. function cleanEmpty($arr)   {
  10.     $newarray = array();
  11.     foreach($arr as $x) {
  12.         if(!empty($x))
  13.             array_push($newarray,$x);
  14.     }
  15.     return $newarray;
  16. }
  17. function swap(&$valor_1, &$valor_2) {
  18.     list($valor_1, $valor_2) = array($valor_2, $valor_1);
  19. }
  20.  
  21. function sortBeats($arr)    {
  22.     $len = count($arr);
  23.     for($i=0;$i<$len;$i++)  {
  24.         for($j=$i;$j<$len;$j++) {
  25.             if($arr[$i][1] > $arr[$j][1])
  26.                 swap($arr[$i],$arr[$j]);
  27.         }
  28.     }
  29.     return $arr;
  30. }
  31.        
  32. $bps = 4;
  33. //$bps = round(($bpm / 60)*100000)/100000;
  34. $beats = explode(",",$data);
  35. $beatn = 0;
  36.  
  37. $convertedbeats = array();
  38.  
  39. foreach($beats as $beat)    {
  40.     //print "B:".$beatn." T: ".($beatn * $bps)."\n";
  41.     $subbeats = cleanEmpty(explode("\n",$beat));
  42.     $subbeattime = $bps / count($subbeats);
  43.     $n = 0;
  44.     foreach($subbeats as $subbeat)  {
  45.         if($subbeat != "0000")  {
  46.             $time = round( (($beatn * $bps) + $subbeattime * $n)*100000)/100000;
  47.             for($p=0;$p<4;$p++) {
  48.                 if($subbeat[$p] > 0 )   {
  49.                     $beatdata = array( $time, $p, new stdClass() );
  50.                     array_push($convertedbeats, $beatdata);
  51.                 }
  52.             }
  53.         }
  54.         $n++;
  55.     }
  56.     $beatn++;
  57. }
  58. $convertedbeats = sortBeats($convertedbeats);
  59. print json_encode($convertedbeats);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement