add: shortest note modifier

Signed-off-by: Tobias Reisinger <tobias@msrg.cc>
This commit is contained in:
Tobias Reisinger 2020-03-06 00:28:43 +01:00
parent 9d53b7f498
commit 421bcef330
6 changed files with 59 additions and 14 deletions

View file

@ -14,6 +14,7 @@ $id = $_GET["id"];
$tempo = $_GET["tempo"];
$time = $_GET["time"];
$bars = intval($_GET["bars"]);
$shortest_note = intval($_GET["shortest_note"]);
$dynamic_beat = $_GET["dynamic_beat"];
$dynamic_rhythm = $_GET["dynamic_rhythm"];
@ -24,14 +25,14 @@ $bars_count = 0;
$rhythm_length = 0;
$time_explode = explode("/", $time, 2);
$rhythm_length_max = MAX_FRACTION * (intval($time_explode[0]) / intval($time_explode[1]));
$rhythm_length_max = $shortest_note * (intval($time_explode[0]) / intval($time_explode[1]));
$id_hashed = md5($id);
do {
$notes_input = [];
for($i = 0; $i < strlen($id_hashed); $i+=2)
{
$notes_input[] = strval(pow(2, (ord(substr($id_hashed, $i)) % intval(log(MAX_FRACTION, 2))) + 1));
$notes_input[] = strval(pow(2, (ord(substr($id_hashed, $i)) % intval(log($shortest_note, 2))) + 1));
$notes_modifiers[] = ord(substr($id_hashed, $i + 1));
}
for($i = 0; $i < count($notes_input); $i++)
@ -41,15 +42,15 @@ do {
continue;
}
$note_val = intval($notes_input[$i]);
if(($note_val == 0) || ($note_val > MAX_FRACTION) || (!is_valid_note($note_val)))
if(($note_val == 0) || ($note_val > $shortest_note) || (!is_valid_note($note_val)))
{
continue;
}
if($rhythm_length + (MAX_FRACTION / $note_val) > $rhythm_length_max)
if($rhythm_length + ($shortest_note / $note_val) > $rhythm_length_max)
{
continue;
}
$rhythm_length += MAX_FRACTION / $note_val;
$rhythm_length += $shortest_note / $note_val;
if($notes_modifiers[$i] & 0b0111)
{
@ -102,9 +103,10 @@ echo(render(
"time" => $time,
"tempo" => $tempo,
"bars" => $bars,
"file_name" => $file_name,
"shortest_note" => $shortest_note,
"dynamic_beat" => $dynamic_beat,
"dynamic_rhythm" => $dynamic_rhythm,
"file_name" => $file_name,
)
));

View file

@ -1,9 +1,13 @@
<?php
// https://stackoverflow.com/a/600306/9123061
function is_valid_note($x)
function is_valid_note($check_note)
{
return ($x & ($x - 1)) == 0;
if(!intval($check_note))
{
return false;
}
return ($check_note & ($check_note - 1)) == 0;
}
function is_valid_time($check_time)
@ -101,6 +105,11 @@ function validate_get_parameter()
$_GET["bars"] = "2";
}
if(!(isset($_GET["shortest_note"]) && is_valid_note($_GET["shortest_note"])))
{
$_GET["shortest_note"] = "8";
}
if(!(isset($_GET["dynamic_beat"]) && is_valid_dynamic($_GET["dynamic_beat"])))
{
$_GET["dynamic_beat"] = "pp";

View file

@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.0.1 VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-05 21:21+0100\n"
"POT-Creation-Date: 2020-03-06 00:22+0100\n"
"PO-Revision-Date: 2020-03-05 18:53+0100\n"
"Last-Translator: <serguzim@msrg.cc>\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
@ -57,10 +57,19 @@ msgid "Anything between %s and %s"
msgstr "Alles zwischen %s und %s"
#: templates/index.tpl.php:73
msgid "Shortest Note"
msgstr "Kürzeste Note"
#: templates/index.tpl.php:76
#, php-format
msgid "Full note: %s; half note: %s; eigth note: %s; ...."
msgstr "Ganze Note: %s; Halbe Note: %s; Achtel Note: %s; ...."
#: templates/index.tpl.php:80
msgid "Dynamic for Beat"
msgstr "Dynamik für den Beat"
#: templates/index.tpl.php:80
#: templates/index.tpl.php:87
msgid "Dynamic for Rhythm"
msgstr "Dynamik für den Rhytmus"

View file

@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.0.1 VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-05 21:21+0100\n"
"POT-Creation-Date: 2020-03-06 00:22+0100\n"
"PO-Revision-Date: 2020-03-05 19:14+0100\n"
"Last-Translator: <serguzim@msrg.cc>\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
@ -57,10 +57,19 @@ msgid "Anything between %s and %s"
msgstr "Anything between %s and %s"
#: templates/index.tpl.php:73
msgid "Shortest Note"
msgstr "Shortest Note"
#: templates/index.tpl.php:76
#, php-format
msgid "Full note: %s; half note: %s; eigth note: %s; ...."
msgstr "Full note: %s; half note: %s; eigth note: %s; ...."
#: templates/index.tpl.php:80
msgid "Dynamic for Beat"
msgstr "Dynamic for Beat"
#: templates/index.tpl.php:80
#: templates/index.tpl.php:87
msgid "Dynamic for Rhythm"
msgstr "Dynamic for Rhythm"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-05 21:22+0100\n"
"POT-Creation-Date: 2020-03-06 00:22+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -59,9 +59,18 @@ msgid "Anything between %s and %s"
msgstr ""
#: templates/index.tpl.php:73
msgid "Dynamic for Beat"
msgid "Shortest Note"
msgstr ""
#: templates/index.tpl.php:76
#, php-format
msgid "Full note: %s; half note: %s; eigth note: %s; ...."
msgstr ""
#: templates/index.tpl.php:80
msgid "Dynamic for Beat"
msgstr ""
#: templates/index.tpl.php:87
msgid "Dynamic for Rhythm"
msgstr ""

View file

@ -69,6 +69,13 @@
<?php printf(_("Anything between %s and %s"), 1, 64) ?>
</small>
</div>
<div class="form-group">
<?php echo(_("Shortest Note")) ?>
<input type="number" class="form-control" min="1" name="shortest_note" value="<?php echo($shortest_note); ?>" />
<small>
<?php printf(_("Full note: %s; half note: %s; eigth note: %s; ...."), 1, 2, 8) ?>
</small>
</div>
<div class="form-group">
<?php echo(_("Dynamic for Beat")) ?>
<input type="text" class="form-control" name="dynamic_beat" value="<?php echo($dynamic_beat); ?>" />