diff options
| author | Zach DeCook <zachdecook@librem.one> | 2021-03-12 03:32:40 +0000 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2021-03-12 03:32:40 +0000 |
| commit | b1d7f183ab715c7498da4a772dfbffcbfca68299 (patch) | |
| tree | 7f43f39a38a2dc35485c95e9533df6a03a7b958e /laravel/app | |
| parent | d99588ac37284194202a677ea9cc2a2ccb5846a1 (diff) | |
| download | prosongsa-b1d7f183ab715c7498da4a772dfbffcbfca68299.tar.gz | |
* Chords: Conform to the chordsdata better
Diffstat (limited to 'laravel/app')
| -rw-r--r-- | laravel/app/Song.php | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 46472c4..fbbeac6 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -40,9 +40,36 @@ class Song extends Model { $txt = $txt ?? $this->text; $txt = str_replace(['(',')',"\n", "\r"]," ",$txt); - $words = array_flip(explode(' ', $txt)); + $words = explode(' ', $txt); + $wordsT = array_map(['self','chordTransform'], $words); + $wordsTKey = array_flip($wordsT); $allChords = json_decode(file_get_contents("public/js/chordsdata/chords.json"), TRUE); - $chords = array_intersect_key($allChords, $words); + $chords = array_intersect_key($allChords, $wordsTKey); + // TODO: Replace keys from $chords with values from $words. return $chords; } + public static function chordTransform($chord) + { + $repl = [ + 'sus' => 's', + 's4' => 's', + 's' => 'sus', + '7sus' => 'sus7', + 'mj7' => 'maj7', + '/A' => '/a', + '/B' => '/b', + '/C' => '/c', + '/D' => '/d', + '/E' => '/e', + '/F' => '/f', + '/G' => '/g', + '♭' => 'b', + 'Db' => 'C#', + 'Eb' => 'D#', + 'Gb' => 'F#', + 'Ab' => 'G#', + 'Bb' => 'A#', + ]; + return str_replace(array_keys($repl), array_values($repl), $chord); + } } |
