add: formatting, cleaning of notes

Signed-off-by: Tobias Reisinger <tobias@msrg.cc>
This commit is contained in:
Tobias Reisinger 2020-03-07 16:22:08 +01:00
parent ed101c6b4f
commit edbb9d45c6
6 changed files with 102 additions and 19 deletions

View file

@ -1,8 +1,10 @@
<?php
require("./lib//config.php");
require("./lib//helpers.php");
require("./lib//validation.php");
require("./lib/config.php");
require("./lib/helpers.php");
require("./lib/validation.php");
require("./lib/fix_notation.php");
require("./lib/combine_rests.php");
session_start();
@ -19,8 +21,8 @@ $shortest_note = intval($_GET["shortest_note"]);
$dynamic_beat = $_GET["dynamic_beat"];
$dynamic_rhythm = $_GET["dynamic_rhythm"];
$notes_final_mod = [];
$notes_final = [];
$notes_modifiers = [];
$bars_count = 0;
$rhythm_length = 0;
@ -30,10 +32,11 @@ $rhythm_length_max = $shortest_note * (intval($time_explode[0]) / intval($time_e
$id_hashed = md5($id);
do {
$notes_input = [];
$notes_input_mod = [];
for($i = 0; $i < strlen($id_hashed); $i+=2)
{
$notes_input[] = strval(pow(2, (ord(substr($id_hashed, $i)) % intval(log($shortest_note, 2))) + 1));
$notes_modifiers[] = ord(substr($id_hashed, $i + 1));
$notes_input[] = pow(2, (ord(substr($id_hashed, $i)) % intval(log($shortest_note, 2))) + 1);
$notes_mod[] = ord(substr($id_hashed, $i + 1));
}
for($i = 0; $i < count($notes_input); $i++)
{
@ -41,7 +44,7 @@ do {
{
continue;
}
$note_val = intval($notes_input[$i]);
$note_val = $notes_input[$i];
if(($note_val == 0) || ($note_val > $shortest_note) || (!is_valid_note($note_val)))
{
continue;
@ -52,18 +55,13 @@ do {
}
$rhythm_length += $shortest_note / $note_val;
if($notes_modifiers[$i] & 0b0111)
{
$notes_final[] = PERCUSSION_CLAP . $note_val;
}
else
{
$notes_final[] = PERCUSSION_REST . $note_val;
}
$notes_final[] = $note_val;
$notes_final_mod[] = $notes_mod[$i];
if($rhythm_length == $rhythm_length_max)
{
$notes_final[] = "|";
$notes_final_mod[] = $notes_mod[$i];
$rhythm_length = 0;
$bars_count++;
}
@ -71,6 +69,9 @@ do {
$id_hashed = md5($id_hashed);
} while($bars_count < $bars);
list($notes_final, $notes_final_mod) = fix_notation($notes_final, $notes_final_mod);
list($notes_final, $notes_final_mod) = combine_rests($notes_final, $notes_final_mod);
$notes_final = implode(" ", $notes_final);
$rest_padding = array_fill(0, $time_explode[0], PERCUSSION_REST . $time_explode[1]);
@ -97,7 +98,6 @@ exec(sprintf("lilypond --png -o %1\$s %1\$s$file_name.ly && convert %1\$s$file_n
echo(render(
"./templates/index.tpl.php",
$locale,
array(
"id" => $id,
"time" => $time,