Compare commits

..

3 Commits

4 changed files with 141 additions and 91 deletions

View File

@ -135,5 +135,7 @@
{
echo "<script>alert('not enough data! argh!');</script>";
}
die();
}
?>

View File

@ -104,42 +104,38 @@ function validateForm()
function toggleColor()
{
showColor = !showColor;
var x = document.getElementsByName('key');
var keys = document.getElementsByName('key');
const distMap = {
square: 0,
lead: 1,
saw: 2,
bass: 3,
};
if (showColor)
{
for (i = 0; i < x.length; i++)
for (let i = 0; i < keys.length; i++)
{
var dist = x[i].id.substring(0,x[i].id.indexOf("_"));
var atariIndex = x[i].id.substring(x[i].id.indexOf("_")+1);
const [ dist, atariIndex ] = keys[i].id.split('_');
const distValue = distMap[dist];
if (atariIndex != "nil")
{
if (dist == "square") dist = 0;
else if (dist == "lead") dist = 1;
else if (dist == "saw") dist = 2;
else if (dist == "bass") dist = 3;
x[i].style.backgroundColor = noteArray[dist][atariIndex][8];
const noteData = typeof distValue === 'number' && noteArray[distValue] && noteArray[distValue][atariIndex];
if (noteData) {
console.log(noteData[8]);
keys[i].style.backgroundColor = noteData[8];
}
}
}
else
{
for (i = 0; i < x.length; i++)
for (let i = 0; i < keys.length; i++)
{
var dist = x[i].id.substring(0,x[i].id.indexOf("_"));
var atariIndex = x[i].id.substring(x[i].id.indexOf("_")+1);
const [dist, atariIndex] = keys[i].id.split('_');
const distValue = distMap[dist];
if (atariIndex != "nil")
{
if (dist == "square") dist = 0;
else if (dist == "lead") dist = 1;
else if (dist == "saw") dist = 2;
else if (dist == "bass") dist = 3;
if (x[i].className.match("wkey")) x[i].style.backgroundColor = "#FFFFFF";
else x[i].style.backgroundColor = "#000000";
if (typeof distValue === 'number' && atariIndex !== 'nil') {
keys[i].style.backgroundColor = keys[i].classList.contains('wkey') ? '#FFFFFF' : '#000000';
}
}
}
@ -185,22 +181,24 @@ function showFloatingDiv(keyID,e)
function exchange()
{
var dist = activeKeyID.substring(0,activeKeyID.indexOf("_"));
var distName = activeKeyID.substring(0,activeKeyID.indexOf("_"));
var atariIndex = activeKeyID.substring(activeKeyID.indexOf("_")+1);
let dist = null;
if (dist == "square") dist = 0;
else if (dist == "lead") dist = 1;
else if (dist == "saw") dist = 2;
else if (dist == "bass") dist = 3;
if (distName == "square") dist = 0;
else if (distName == "lead") dist = 1;
else if (distName == "saw") dist = 2;
else if (distName == "bass") dist = 3;
else return;
for (j = 0; j < 32; j++)
if (j != atariIndex && noteArray[dist][atariIndex][1] == noteArray[dist][j][1])
{
document.getElementById(activeKeyID).id = dist+"_"+j;
activeKeyID = dist+"_"+j;
for (j = 0; j < 32; j++) {
if (j != atariIndex && noteArray[dist][atariIndex][1] == noteArray[dist][j][1]) {
document.getElementById(activeKeyID).id = distName + "_" + j;
activeKeyID = distName + "_" + j;
atariIndex = j;
break;
}
}
//update floating div
var x = document.getElementById('floatDiv');

View File

@ -70,26 +70,65 @@
while (($file = readdir($dir)) != null)
{
//format: distortion_atari note index_note name_octave_freq_error_MIDI note index_pitch bend left bits_pitch bend right bits
// $note_array[dist][x]:
// [0] audio file name
// [1] note name w/ octave
// [2] octave
// [3] frequency
// [4] error (cents)
// [5] MIDI note (0-255)
// [6] pitch bend left bits
// [7] pitch bend right bits
// [8] color
if (strpos($file,".ogg"))
{
$info = explode("_",$file);
$info[2] = str_replace("+","#",$info[2]);
$info[count($info)-1] = substr($info[count($info)-1],0,strpos($info[count($info)-1],".ogg"));
// print_r($info);
if (!isset($note_array[$info[0]][$info[1]]))
$note_array[$info[0]][$info[1]] = array();
$dist = $info[0];
$noteIndex = $info[1];
array_push($note_array[$info[0]][$info[1]],$file);
for ($i = 2; $i < count($info); $i++)
array_push($note_array[$info[0]][$info[1]],$info[$i]);
// [0] distortion name
// [1] note index
// [2] note name w/ octave
// [3] octave
// [4] frequency
// [5] error (cents)
// [6] MIDI note (0-255)
// [7] pitch bend left bits
// [8] pitch bend right bits
if (!isset($note_array[$dist][$noteIndex]))
$note_array[$dist][$noteIndex] = array();
array_push($note_array[$dist][$noteIndex],$file);
for ($i = 2; $i < count($info); $i++) {
array_push($note_array[$dist][$noteIndex], $info[$i]);
}
$hue = 135;
$sat = 50;
$lum = 65;
// info = [ distortion, note index, note name w/ octave, octave, freq error
$hueCorrection = 270 - $hue;
$errorCents = $info[5];
$errorHue = $hueCorrection * ($errorCents / 50);
$hue = $hue + $errorHue;
$red = str_pad(dechex(100+2*$note_array[$info[0]][$info[1]][4]),2,"0",STR_PAD_LEFT);
$green = str_pad(dechex(150),2,"0",STR_PAD_LEFT);
$blue = str_pad(dechex(100-2*$note_array[$info[0]][$info[1]][4]),2,"0",STR_PAD_LEFT);
$color = $red.$green.$blue;
$note_array[$info[0]][$info[1]][8] = '#' . $color;
// $red = str_pad(dechex(100+2*$note_array[$info[0]][$info[1]][4]),2,"0",STR_PAD_LEFT);
// $green = str_pad(dechex(150),2,"0",STR_PAD_LEFT);
// $blue = str_pad(dechex(100-2*$note_array[$info[0]][$info[1]][4]),2,"0",STR_PAD_LEFT);
// $color = $red.$green.$blue;
$note_array[$dist][$noteIndex][8] = "hsl({$hue} {$sat} {$lum})"; //'#' . $color;
}
}
@ -163,6 +202,7 @@
</head>
<body>
<?php
$xstart = 10;

View File

@ -30,10 +30,18 @@ foreach ($c1_data as $i => $arr)
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
@ -62,6 +70,7 @@ foreach ($c1_data as $i => $arr)
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
@ -101,8 +110,9 @@ 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)
foreach ($bin_data as $val) {
fwrite($filehandle, pack("I", $val), 1);
}
//End track
fwrite($filehandle,pack("I",0),1);