From 6779b0c77cc837014500b691054ea9b0d87108b9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 6 Dec 2024 10:32:07 -0600 Subject: [PATCH] working songs but needs better edge case handling --- src/core/songs.rs | 95 ++++++++++++++++++++--------------------------- test_song.lisp | 95 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 127 insertions(+), 63 deletions(-) diff --git a/src/core/songs.rs b/src/core/songs.rs index fe5e665..0dec7a0 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -241,64 +241,49 @@ fn lisp_to_song(list: Vec) -> Song { let mut lyrics = vec![]; - if let Some(ref verse_order) = verse_order { - for verse in verse_order { - for element in lyric_elements { - let Value::List(lyric) = element else { - continue; - }; - let Value::Symbol(Symbol(lyric_verse)) = &lyric[0] - else { - continue; - }; + for element in lyric_elements { + let Value::List(lyric) = element else { + continue; + }; + let Value::Symbol(Symbol(lyric_verse)) = &lyric[0] else { + continue; + }; - let lyric = String::from(&lyric[1]); + let lyric = String::from(&lyric[1]); - println!("{lyric}"); + let verse_title = match lyric_verse.as_str() { + "i1" => r#"\n\nIntro 1\n"#, + "i2" => r#"\n\nIntro 1\n"#, + "v1" => r#"\n\nVerse 1\n"#, + "v2" => r#"\n\nVerse 2\n"#, + "v3" => r#"\n\nVerse 3\n"#, + "v4" => r#"\n\nVerse 4\n"#, + "v5" => r#"\n\nVerse 5\n"#, + "c1" => r#"\n\nChorus 1\n"#, + "c2" => r#"\n\nChorus 2\n"#, + "c3" => r#"\n\nChorus 3\n"#, + "c4" => r#"\n\nChorus 4\n"#, + "b1" => r#"\n\nBridge 1\n"#, + "b2" => r#"\n\nBridge 2\n"#, + "e1" => r#"\n\nEnding 1\n"#, + "e2" => r#"\n\nEnding 2\n"#, + "o1" => r#"\n\nOther 1\n"#, + "o2" => r#"\n\nOther 2\n"#, + _ => "", + }; - let verse_title = match lyric_verse.as_str() { - "i1" => r#"\n\nIntro 1\n"#, - "i2" => r#"\n\nIntro 1\n"#, - "v1" => r#"\n\nVerse 1\n"#, - "v2" => r#"\n\nVerse 2\n"#, - "v3" => r#"\n\nVerse 3\n"#, - "v4" => r#"\n\nVerse 4\n"#, - "v5" => r#"\n\nVerse 5\n"#, - "c1" => r#"\n\nChorus 1\n"#, - "c2" => r#"\n\nChorus 2\n"#, - "c3" => r#"\n\nChorus 3\n"#, - "c4" => r#"\n\nChorus 4\n"#, - "b1" => r#"\n\nBridge 1\n"#, - "b2" => r#"\n\nBridge 2\n"#, - "e1" => r#"\n\nEnding 1\n"#, - "e2" => r#"\n\nEnding 2\n"#, - "o1" => r#"\n\nOther 1\n"#, - "o2" => r#"\n\nOther 2\n"#, - _ => "", - }; - - let lyric = format!("{verse_title}{lyric}"); - println!("{lyric}"); - if &lyric_verse.to_uppercase() == verse { - lyrics.push(lyric); - } - } - } - } else { - for element in lyric_elements { - let Value::List(lyric) = element else { - continue; - }; - let lyric = - format!("{}{}", String::from(&lyric[1]), "\n"); - lyrics.push(lyric); - } + let lyric = format!("{verse_title}{lyric}"); + println!("lyric_final: {lyric}"); + let lyric = lyric.replace( + "\\n", r#" +"#, + ); + lyrics.push(lyric); } let lyrics: String = lyrics.iter().flat_map(|s| s.chars()).collect(); - let lyrics = lyrics.replace(r#"\"#, "\\"); - let lyrics = lyrics.trim_start_matches("\\n\\n").to_string(); + let lyrics = lyrics.trim_start().to_string(); Song { id, @@ -605,10 +590,10 @@ You saved my soul" #[test] pub fn test_lisp_conversion() { let value = test_lisp_song(); - let song = Song::from(value); + let lisp_song = Song::from(value); let test_song = test_song(); - println!("{}", test_song.lyrics.clone().unwrap()); - println!("{}", song.lyrics.clone().unwrap()); - assert_eq!(test_song, song); + println!("test_song: {}", test_song.lyrics.clone().unwrap()); + println!("lisp_song: {}", lisp_song.lyrics.clone().unwrap()); + assert_eq!(test_song, lisp_song); } } diff --git a/test_song.lisp b/test_song.lisp index ab2c051..fa70b40 100644 --- a/test_song.lisp +++ b/test_song.lisp @@ -6,11 +6,90 @@ :audio "file:///home/chris/music/North Point InsideOut/Nothing Ordinary, Pt. 1 (Live)/05 Death Was Arrested (feat. Seth Condrey).mp3" :verse-order (i1 v1 v2 c1 v3 c1 v4 c1 b1 b1 e1 e2) (i1 "Death Was Arrested\nNorth Point Worship") - (c1 "Oh, Your grace so free,\nWashes over me\n\nYou have made me new,\nNow life begins with You\n\nIt's Your endless love,\nPouring down on us\n\nYou have made us new,\nNow life begins with You") - (b1 "Oh, we're free, free,\nForever we're free\n\nCome join the song\nOf all the redeemed\n\nYes, we're free, free,\nForever amen\n\nWhen death was arrested\nAnd my life began\n\nOh, we're free, free,\nForever we're free\n\nCome join the song\nOf all the redeemed\n\nYes, we're free, free,\nForever amen\n\nWhen death was arrested\nAnd my life began") - (e1 "When death was arrested\nAnd my life began\n\nThat's when death was arrested\nAnd my life began") - (e2 "") - (v1 "Alone in my sorrow\nAnd dead in my sin\n\nLost without hope\nWith no place to begin\n\nYour love made a way\nTo let mercy come in\n\nWhen death was arrested\nAnd my life began") - (v2 "Ash was redeemed\nOnly beauty remains\n\nMy orphan heart\nWas given a name\n\nMy mourning grew quiet,\nMy feet rose to dance\n\nWhen death was arrested\nAnd my life began") - (v3 "Released from my chains,\nI'm a prisoner no more\n\nMy shame was a ransom\nHe faithfully bore\n\nHe cancelled my debt and\nHe called me His friend\n\nWhen death was arrested\nAnd my life began") - (v4 "Our Savior displayed\nOn a criminal's cross\n\nDarkness rejoiced as though\nHeaven had lost\n\nBut then Jesus arose\nWith our freedom in hand\n\nThat's when death was arrested\nAnd my life began\n\nThat's when death was arrested\nAnd my life began")) + (v1 "Alone in my sorrow +And dead in my sin + +Lost without hope +With no place to begin + +Your love made a way +To let mercy come in + +When death was arrested +And my life began") + (v2 "Ash was redeemed +Only beauty remains + +My orphan heart +Was given a name + +My mourning grew quiet, +My feet rose to dance + +When death was arrested +And my life began") + (c1 "Oh, Your grace so free, +Washes over me + +You have made me new, +Now life begins with You + +It's Your endless love, +Pouring down on us + +You have made us new, +Now life begins with You") + (v3 "Released from my chains, +I'm a prisoner no more + +My shame was a ransom +He faithfully bore + +He cancelled my debt and +He called me His friend + +When death was arrested +And my life began") + (v4 "Our Savior displayed +On a criminal's cross + +Darkness rejoiced as though +Heaven had lost + +But then Jesus arose +With our freedom in hand + +That's when death was arrested +And my life began + +That's when death was arrested +And my life began") + (b1 "Oh, we're free, free, +Forever we're free + +Come join the song +Of all the redeemed + +Yes, we're free, free, +Forever amen + +When death was arrested +And my life began + +Oh, we're free, free, +Forever we're free + +Come join the song +Of all the redeemed + +Yes, we're free, free, +Forever amen + +When death was arrested +And my life began") + (e1 "When death was arrested +And my life began + +That's when death was arrested +And my life began") + )