Backend for songs.zachdecook.com
Transposition: Support special ♯ and ♭ symbols
Zach DeCook 2022-09-23
parent 6661a27 · commit 120199b
-rw-r--r--laravel/app/Http/Controllers/SongController.php16
1 files changed, 14 insertions, 2 deletions
diff --git a/laravel/app/Http/Controllers/SongController.php b/laravel/app/Http/Controllers/SongController.php
index 2ad3f75..4e4dee5 100644
--- a/laravel/app/Http/Controllers/SongController.php
+++ b/laravel/app/Http/Controllers/SongController.php
@@ -134,7 +134,8 @@ class SongController extends Controller
$newline = '';
$space = 0; ///@< Spaces that need to be added or removed.
$inCurly = 0;
- for($i = 0; $i < strlen($line); $i++) {
+ $line = mb_str_split($line);
+ for($i = 0; $i < count($line); $i++) {
$char = $line[$i];
$nchar = isset($line[$i+1]) ? $line[$i+1] : '';
$upchar = strtoupper($line[$i]);
@@ -146,7 +147,7 @@ class SongController extends Controller
// Exception for Cmaj7
if( $upchar == 'A' && $nchar == 'j' ) {
$newline .= $char;
- } else if( $nchar == 'b' || $nchar =='#') {
+ } else if( $nchar == 'b' || $nchar =='#' || $nchar == '♭' || $nchar == '♯') {
$i++; //We have read an extra character now.
$newchord = $newchords[$upchar . $nchar];
if( strlen($newchord) == 1 ) {
@@ -197,6 +198,17 @@ class SongController extends Controller
$newchords["Gb"] = $newchords["F#"];
$newchords["Ab"] = $newchords["G#"];
$newchords["A#"] = $newchords["Bb"];
+ // special flat/sharp aliases...
+ $newchords["D♭"] = $newchords["C#"];
+ $newchords["C♯"] = $newchords["C#"];
+ $newchords["E♭"] = $newchords["D#"];
+ $newchords["D♯"] = $newchords["D#"];
+ $newchords["G♭"] = $newchords["F#"];
+ $newchords["F♯"] = $newchords["F#"];
+ $newchords["A♭"] = $newchords["G#"];
+ $newchords["G♯"] = $newchords["G#"];
+ $newchords["A♯"] = $newchords["Bb"];
+ $newchords["B♭"] = $newchords["Bb"];
return $newchords;
}
private function transpadd( $fromkey, $integer )