Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $bpm = 150;
- $data = "0000
- 0000
- 0000
- 0000
- ";
- function cleanEmpty($arr) {
- $newarray = array();
- foreach($arr as $x) {
- if(!empty($x))
- array_push($newarray,$x);
- }
- return $newarray;
- }
- function swap(&$valor_1, &$valor_2) {
- list($valor_1, $valor_2) = array($valor_2, $valor_1);
- }
- function sortBeats($arr) {
- $len = count($arr);
- for($i=0;$i<$len;$i++) {
- for($j=$i;$j<$len;$j++) {
- if($arr[$i][1] > $arr[$j][1])
- swap($arr[$i],$arr[$j]);
- }
- }
- return $arr;
- }
- $bps = 4;
- //$bps = round(($bpm / 60)*100000)/100000;
- $beats = explode(",",$data);
- $beatn = 0;
- $convertedbeats = array();
- foreach($beats as $beat) {
- //print "B:".$beatn." T: ".($beatn * $bps)."\n";
- $subbeats = cleanEmpty(explode("\n",$beat));
- $subbeattime = $bps / count($subbeats);
- $n = 0;
- foreach($subbeats as $subbeat) {
- if($subbeat != "0000") {
- $time = round( (($beatn * $bps) + $subbeattime * $n)*100000)/100000;
- for($p=0;$p<4;$p++) {
- if($subbeat[$p] > 0 ) {
- $beatdata = array( $time, $p, new stdClass() );
- array_push($convertedbeats, $beatdata);
- }
- }
- }
- $n++;
- }
- $beatn++;
- }
- $convertedbeats = sortBeats($convertedbeats);
- print json_encode($convertedbeats);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement