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 --- chordsdata | 2 +- laravel/app/Song.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chordsdata b/chordsdata index 0fdbc66..15fac73 160000 --- a/chordsdata +++ b/chordsdata @@ -1 +1 @@ -Subproject commit 0fdbc6604dd6dc4ea84e72f7670de35b55c10669 +Subproject commit 15fac73c2d51857ff0b95055187f14b6ff4c0405 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