set volume to half every other note
This commit is contained in:
parent
51baa068d2
commit
e9591a2388
48
square_1.php
48
square_1.php
@ -7,43 +7,51 @@ foreach ($c1_data as $i => $arr)
|
||||
{
|
||||
//tick delay---------------------------------//
|
||||
$b_arr = array(0);
|
||||
|
||||
|
||||
//only if previous note was a rest or another voice
|
||||
if ($i > 0 && strcmp($c1_data[$i-1][1],"0") > 0)
|
||||
{
|
||||
$b_ticks = strrev(decbin($ticksSinceLastNote));
|
||||
$b_arr = str_split($b_ticks,7);
|
||||
|
||||
|
||||
for ($j = 0; $j < count($b_arr); $j++)
|
||||
{
|
||||
if (strlen($b_arr[$j]) < 7)
|
||||
$b_arr[$j] = str_pad($b_arr[$j],7,"0",STR_PAD_RIGHT);
|
||||
|
||||
|
||||
if ($j > 0)
|
||||
$b_arr[$j][7] = "1";
|
||||
$b_arr[$j] = strrev($b_arr[$j]);
|
||||
}
|
||||
}
|
||||
//--------------------------------------------//
|
||||
|
||||
|
||||
$ticksSinceLastNote += (1/$arr[3])*960;
|
||||
|
||||
if (strcmp($arr[1],"0") == 0) //play a note (square)
|
||||
{
|
||||
// change volume every other note to half volume
|
||||
$volume = 80;
|
||||
$bin_data[] = 0; // delta
|
||||
$bin_data[] = 176; // controller event, channel 0
|
||||
$bin_data[] = 7; // change volume
|
||||
$bin_data[] = $i % 2 === 0 ? $volume : ($volume / 2); // volume level
|
||||
|
||||
//note on event
|
||||
for ($j = count($b_arr)-1; $j >= 0; $j--) //tick delay
|
||||
array_push($bin_data,bindec($b_arr[$j]));
|
||||
|
||||
|
||||
|
||||
array_push($bin_data,144); //note on, channel 0
|
||||
array_push($bin_data,$note_array['square'][$arr[2]][5]); //MIDI note index
|
||||
array_push($bin_data,100); //velocity
|
||||
|
||||
|
||||
//pitch bend
|
||||
array_push($bin_data,0); //delta time (immediate bend)
|
||||
array_push($bin_data,224); //pitch bend, channel 0
|
||||
array_push($bin_data,$note_array['square'][$arr[2]][6]); //left bits
|
||||
array_push($bin_data,$note_array['square'][$arr[2]][7]); //right bits
|
||||
|
||||
|
||||
//tick delay for note off
|
||||
$b_ticks = strrev(decbin((1/$arr[3])*960));
|
||||
|
||||
@ -52,20 +60,21 @@ foreach ($c1_data as $i => $arr)
|
||||
{
|
||||
if (strlen($b_arr[$j]) < 7)
|
||||
$b_arr[$j] = str_pad($b_arr[$j],7,"0",STR_PAD_RIGHT);
|
||||
|
||||
|
||||
if ($j > 0)
|
||||
$b_arr[$j][7] = "1";
|
||||
$b_arr[$j] = strrev($b_arr[$j]);
|
||||
}
|
||||
|
||||
|
||||
//note off
|
||||
for ($j = count($b_arr)-1; $j >= 0; $j--) //tick delay
|
||||
array_push($bin_data,bindec($b_arr[$j]));
|
||||
|
||||
|
||||
|
||||
array_push($bin_data,128); //note off, channel 0
|
||||
array_push($bin_data,$note_array['square'][$arr[2]][5]);
|
||||
array_push($bin_data,100); //velocity of release
|
||||
|
||||
|
||||
$ticksSinceLastNote = 0;
|
||||
}
|
||||
}
|
||||
@ -85,10 +94,10 @@ $byte3 = hexdec(substr($h,4,2));
|
||||
$byte2 = hexdec(substr($h,2,2));
|
||||
$byte1 = hexdec(substr($h,0,2));
|
||||
|
||||
fwrite($filehandle,pack("I",$byte1),1);
|
||||
fwrite($filehandle,pack("I",$byte2),1);
|
||||
fwrite($filehandle,pack("I",$byte3),1);
|
||||
fwrite($filehandle,pack("I",$byte4),1);
|
||||
fwrite($filehandle,pack("I",$byte1),1);
|
||||
fwrite($filehandle,pack("I",$byte2),1);
|
||||
fwrite($filehandle,pack("I",$byte3),1);
|
||||
fwrite($filehandle,pack("I",$byte4),1);
|
||||
|
||||
//change to square voice
|
||||
fwrite($filehandle,pack("I",0),1); //delta time
|
||||
@ -101,13 +110,14 @@ fwrite($filehandle,pack("I",176),1); //controller event, channel 0
|
||||
fwrite($filehandle,pack("I",7),1); //change volume
|
||||
fwrite($filehandle,pack("I",80),1); //volume level
|
||||
|
||||
foreach ($bin_data as $val)
|
||||
fwrite($filehandle,pack("I",$val),1);
|
||||
foreach ($bin_data as $val) {
|
||||
fwrite($filehandle, pack("I", $val), 1);
|
||||
}
|
||||
|
||||
//End track
|
||||
fwrite($filehandle,pack("I",0),1);
|
||||
fwrite($filehandle,pack("I",0),1);
|
||||
fwrite($filehandle,pack("I",255),1);
|
||||
fwrite($filehandle,pack("I",47),1);
|
||||
fwrite($filehandle,pack("I",0),1);
|
||||
//END TRACK 2 DATA
|
||||
?>
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user