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

26
lib/combine_rests.php Normal file
View file

@ -0,0 +1,26 @@
<?php
function combine_rests($unfixed, $unfixed_mod)
{
$fixed = [];
for($i = 0; $i < count($unfixed); $i++)
{
if($unfixed[$i] == "" || $unfixed[$i] == LY_BAR_SEPARATOR)
{
continue;
}
if(modifier_is_rest($unfixed_mod[$i]) && $unfixed[$i] == $unfixed[$i + 1])
{
$note_val = intval(substr($unfixed[$i], strlen(PERCUSSION_REST)));
$fixed[] = PERCUSSION_REST . strval($note_val / 2);
$fixed_mod[] = $unfixed_mod[$i];
$unfixed[$i + 1] = "";
continue;
}
$fixed[] = $unfixed[$i];
$fixed_mod[] = $unfixed_mod[$i];
}
return array($fixed, $fixed_mod);
}
?>

View file

@ -1,6 +1,7 @@
<?php
const MAX_FRACTION = 8;
const LY_BAR_SEPARATOR = "|";
const LY_DOT = ".";
const PERCUSSION_REST = "r";
const PERCUSSION_CLAP = "hc";
const PERCUSSION_BEAT = "ss";

51
lib/fix_notation.php Normal file
View file

@ -0,0 +1,51 @@
<?php
function fix_notation($unfixed, $unfixed_mod)
{
$fixed = [];
$fixed_mod = [];
for($i = 0; $i < count($unfixed); $i++)
{
if(is_string($unfixed[$i]) && $unfixed[$i] == LY_BAR_SEPARATOR)
{
$fixed[] = LY_BAR_SEPARATOR;
$fixed_mod[] = $unfixed_mod[$i];
continue;
}
if($unfixed[$i] == 0)
{
continue;
}
if(modifier_is_rest($unfixed_mod[$i]))
{
$fixed[] = PERCUSSION_REST . strval($unfixed[$i]);
$fixed_mod[] = $unfixed_mod[$i];
continue;
}
if(
($unfixed[$i + 1] != BAR_SEPARATOR) &&
modifier_is_rest($unfixed_mod[$i + 1])
)
{
if($unfixed[$i] * 2 == $unfixed[$i + 1])
{
$fixed[] = PERCUSSION_CLAP . strval($unfixed[$i]) . LY_DOT;
$fixed_mod[] = $unfixed_mod[$i];
$unfixed[$i + 1] = 0;
continue;
}
if($unfixed[$i] == $unfixed[$i + 1])
{
$fixed[] = PERCUSSION_CLAP . strval($unfixed[$i] / 2);
$fixed_mod[] = $unfixed_mod[$i];
$unfixed[$i + 1] = 0;;
continue;
}
}
$fixed[] = PERCUSSION_CLAP . strval($unfixed[$i]);
$fixed_mod[] = $unfixed_mod[$i];
}
return array($fixed, $fixed_mod);
}
?>

View file

@ -5,7 +5,7 @@ function remove_whitespace($target)
return str_replace(" ", "", $target);
}
function render($template, $locale, $param){
function render($template, $param){
ob_start();
extract($param, EXTR_SKIP);
include($template);
@ -34,4 +34,9 @@ function setup_locale()
textdomain($domain);
}
function modifier_is_rest($modifier)
{
return !($modifier & 0b0111);
}
?>

View file

@ -29,7 +29,7 @@ function is_valid_time($check_time)
return false;
}
$ratio = $check_time_explode[0] / $check_time_explode[1];
$new_rhythm_length = intval(MAX_FRACTION * $ratio);
$new_rhythm_length = intval(16 * $ratio); // 64 is a generic value. insert any valid note (8 and up should be good)
if(!is_int($new_rhythm_length) || $new_rhythm_length == 0)
{
return false;