about summary refs log tree commit diff
path: root/laravel/app
diff options
context:
space:
mode:
Diffstat (limited to 'laravel/app')
-rw-r--r--laravel/app/Song.php31
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);
+    }
 }