From 4492535d2a36287b92e31e0af4e82be9c14bef9e Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Tue, 5 Jan 2021 03:51:16 +0000 Subject: * Song: Detect chords --- laravel/app/Song.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'laravel/app') diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 4ae3920..102a0ca 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -36,4 +36,12 @@ class Song extends Model // TODO: Validate that this is plain. return trim($this->key, "m"); } + public function getChordsAttribute() + { + $txt = str_replace(['(',')',"\n"]," ",$this->text); + $words = array_flip(explode(' ', $txt)); + $allChords = json_decode(file_get_contents("public/js/chordsdata/chords.json"), TRUE); + $chords = array_intersect_key($allChords, $words); + return $chords; + } } -- cgit 1.4.1