Skip to content

Instantly share code, notes, and snippets.

@ayaysir
Last active August 2, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayaysir/813caee64b2ae0c3a4d19344ee93af4e to your computer and use it in GitHub Desktop.
Save ayaysir/813caee64b2ae0c3a4d19344ee93af4e to your computer and use it in GitHub Desktop.
Parameter 'pattern' is serial of semitone numbers between two notes, 'transpose' is set interval from root c; if transpose = 0 then
<?php
header('Content-Type: application/json');
$pattern = empty($_GET[pattern]) ? "2122122" : $_GET[pattern];
// transpose: positive(+) only and must be within 11
$transpose = empty($_GET[transpose]) ? 0 : $_GET[transpose];
$str_arr = str_split($pattern);
$names_common = array("", "C", "C+", "D", "E-", "E", "F", "F+", "G", "A-", "A", "B-", "B");
$names_sharp = array("", "C", "C+", "D", "D+", "E", "F", "F+", "G", "G+", "A", "A+", "B");
$sum = 1;
$output_arr = [];
$output_num = [];
$output_json = [];
// show first note
array_push($output_arr, $names_common[$sum + $transpose]);
foreach($str_arr as $e){
$sum += $e;
$disp_num = $transpose + $sum;
if($disp_num > 12){
array_push($output_arr, $names_common[$disp_num - 12]);
} else {
array_push($output_arr, $names_common[$disp_num]);
}
array_push($output_num, $disp_num);
}
$output_json = array("notesByName" => $output_arr, "notesBySemitone" => $output_num,
"root" => $names_common[$transpose + 1] ,
"name" => "example name", "pattern" => $pattern);
echo json_encode($output_json);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment