From 085b53b12866de6c095553bf2809641994e2d4cb Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 12 Feb 2021 00:15:24 +0000 Subject: gemini: show chords based on transposition --- laravel/app/Song.php | 5 +++-- laravel/public/song.gmi.php | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'laravel') diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 102a0ca..46472c4 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -36,9 +36,10 @@ class Song extends Model // TODO: Validate that this is plain. return trim($this->key, "m"); } - public function getChordsAttribute() + public function getChordsAttribute($txt = null) { - $txt = str_replace(['(',')',"\n"]," ",$this->text); + $txt = $txt ?? $this->text; + $txt = str_replace(['(',')',"\n", "\r"]," ",$txt); $words = array_flip(explode(' ', $txt)); $allChords = json_decode(file_get_contents("public/js/chordsdata/chords.json"), TRUE); $chords = array_intersect_key($allChords, $words); diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php index 2535ca2..edf9b2a 100755 --- a/laravel/public/song.gmi.php +++ b/laravel/public/song.gmi.php @@ -25,12 +25,12 @@ printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return; => id ?>?q Transpose from plain_key ?> -``` -textTranspose(getenv('QUERY_STRING')??'') ?> +```chord sheet +textTranspose(getenv('QUERY_STRING')??'') ?> ``` -chords as $symbol => $tabs): ?> -=> /chord.svg/? chord symbol +getChordsAttribute($txt) as $symbol => $tabs): ?> +=> /chord.svg/? () => mailto:zachdecook+songs@gmail.com?subject=