lisp song changes
This commit is contained in:
parent
717968a178
commit
b81584a76b
|
@ -107,168 +107,113 @@ fn lisp_to_song(list: Vec<Value>) -> Song {
|
||||||
const DEFAULT_SONG_ID: i32 = 0;
|
const DEFAULT_SONG_ID: i32 = 0;
|
||||||
const DEFAULT_SONG_LOCATION: usize = 0;
|
const DEFAULT_SONG_LOCATION: usize = 0;
|
||||||
|
|
||||||
// I probably shouldn't rely upon default locations for these
|
let id = if let Some(key_pos) = list
|
||||||
// It's very unlikely that users of this method of song creation
|
.iter()
|
||||||
// would use them in this order, so instead, since these items are all
|
.position(|v| v == &Value::Keyword(Keyword::from("id")))
|
||||||
// options, let's just treat them as if they don't exist if there isn't
|
{
|
||||||
// a keyword found in the list.
|
let pos = key_pos + 1;
|
||||||
const DEFAULT_BACKGROUND_LOCATION: usize = 1;
|
list.get(pos).map(|c| i32::from(c)).unwrap_or_default()
|
||||||
let background_position = if let Some(background) =
|
} else {
|
||||||
|
DEFAULT_SONG_ID
|
||||||
|
};
|
||||||
|
|
||||||
|
let background = if let Some(key_pos) =
|
||||||
list.iter().position(|v| {
|
list.iter().position(|v| {
|
||||||
v == &Value::Keyword(Keyword::from("background"))
|
v == &Value::Keyword(Keyword::from("background"))
|
||||||
}) {
|
}) {
|
||||||
background + 1
|
let pos = key_pos + 1;
|
||||||
|
list.get(pos).map(|b| slide::lisp_to_background(b))
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_BACKGROUND_LOCATION
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let background =
|
let author = if let Some(key_pos) = list
|
||||||
if let Some(background) = list.get(background_position) {
|
|
||||||
Some(slide::lisp_to_background(background))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_AUTHOR_LOCATION: usize = 1;
|
|
||||||
let author_position = if let Some(author) = list
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|v| v == &Value::Keyword(Keyword::from("author")))
|
.position(|v| v == &Value::Keyword(Keyword::from("author")))
|
||||||
{
|
{
|
||||||
author + 1
|
let pos = key_pos + 1;
|
||||||
} else {
|
list.get(pos).map(|a| String::from(a))
|
||||||
DEFAULT_AUTHOR_LOCATION
|
|
||||||
};
|
|
||||||
|
|
||||||
let author = if let Some(author) = list.get(author_position) {
|
|
||||||
Some(String::from(author))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_AUDIO_LOCATION: usize = 1;
|
let audio = if let Some(key_pos) = list
|
||||||
let audio_position = if let Some(audio) = list
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|v| v == &Value::Keyword(Keyword::from("audio")))
|
.position(|v| v == &Value::Keyword(Keyword::from("audio")))
|
||||||
{
|
{
|
||||||
audio + 1
|
let pos = key_pos + 1;
|
||||||
} else {
|
list.get(pos).map(|a| PathBuf::from(String::from(a)))
|
||||||
DEFAULT_AUDIO_LOCATION
|
|
||||||
};
|
|
||||||
|
|
||||||
let audio = if let Some(audio) = list.get(audio_position) {
|
|
||||||
Some(PathBuf::from(String::from(audio)))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_CCLI_LOCATION: usize = 1;
|
let ccli = if let Some(key_pos) = list
|
||||||
let ccli = if let Some(ccli) = list
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|v| v == &Value::Keyword(Keyword::from("ccli")))
|
.position(|v| v == &Value::Keyword(Keyword::from("ccli")))
|
||||||
{
|
{
|
||||||
let pos = ccli + 1;
|
let pos = key_pos + 1;
|
||||||
list.get(pos).map(|c| i32::from(c).to_string())
|
list.get(pos).map(|c| i32::from(c).to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
// let ccli = if let Some(ccli) = list.get(ccli_position) {
|
let font = if let Some(key_pos) = list
|
||||||
// Some(i32::from(ccli).to_string())
|
|
||||||
// } else {
|
|
||||||
// None
|
|
||||||
// };
|
|
||||||
|
|
||||||
const DEFAULT_FONT_LOCATION: usize = 1;
|
|
||||||
let font_position = if let Some(font) = list
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|v| v == &Value::Keyword(Keyword::from("font")))
|
.position(|v| v == &Value::Keyword(Keyword::from("font")))
|
||||||
{
|
{
|
||||||
font + 1
|
let pos = key_pos + 1;
|
||||||
} else {
|
list.get(pos).map(|f| String::from(f))
|
||||||
DEFAULT_FONT_LOCATION
|
|
||||||
};
|
|
||||||
|
|
||||||
let font = if let Some(font) = list.get(font_position) {
|
|
||||||
Some(String::from(font))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_FONT_SIZE_LOCATION: usize = 1;
|
let font_size = if let Some(key_pos) = list.iter().position(|v| {
|
||||||
let font_size_position = if let Some(font_size) =
|
v == &Value::Keyword(Keyword::from("font-size"))
|
||||||
list.iter().position(|v| {
|
}) {
|
||||||
v == &Value::Keyword(Keyword::from("font-size"))
|
let pos = key_pos + 1;
|
||||||
}) {
|
list.get(pos).map(|f| i32::from(f))
|
||||||
font_size + 1
|
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_FONT_SIZE_LOCATION
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let font_size =
|
let title = if let Some(key_pos) = list
|
||||||
if let Some(font_size) = list.get(font_size_position) {
|
|
||||||
Some(i32::from(font_size))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_TITLE_LOCATION: usize = 1;
|
|
||||||
let title_position = if let Some(title) = list
|
|
||||||
.iter()
|
.iter()
|
||||||
.position(|v| v == &Value::Keyword(Keyword::from("title")))
|
.position(|v| v == &Value::Keyword(Keyword::from("title")))
|
||||||
{
|
{
|
||||||
title + 1
|
let pos = key_pos + 1;
|
||||||
} else {
|
list.get(pos)
|
||||||
DEFAULT_TITLE_LOCATION
|
.map(|t| String::from(t))
|
||||||
};
|
.unwrap_or(String::from("song"))
|
||||||
|
|
||||||
let title = if let Some(title) = list.get(title_position) {
|
|
||||||
String::from(title)
|
|
||||||
} else {
|
} else {
|
||||||
String::from("song")
|
String::from("song")
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_TEXT_ALIGNMENT_LOCATION: usize = 1;
|
let text_alignment = if let Some(key_pos) =
|
||||||
let text_alignment_position = if let Some(text_alignment) =
|
|
||||||
list.iter().position(|v| {
|
list.iter().position(|v| {
|
||||||
v == &Value::Keyword(Keyword::from("text-alignment"))
|
v == &Value::Keyword(Keyword::from("text-alignment"))
|
||||||
}) {
|
}) {
|
||||||
text_alignment + 1
|
let pos = key_pos + 1;
|
||||||
|
list.get(pos).map(|t| TextAlignment::from(t))
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_TEXT_ALIGNMENT_LOCATION
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let text_alignment = if let Some(text_alignment) =
|
let verse_order = if let Some(key_pos) =
|
||||||
list.get(text_alignment_position)
|
|
||||||
{
|
|
||||||
Some(TextAlignment::from(text_alignment))
|
|
||||||
} else {
|
|
||||||
Some(TextAlignment::TopCenter)
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_VERSE_ORDER_LOCATION: usize = 1;
|
|
||||||
let verse_order_position = if let Some(verse_order) =
|
|
||||||
list.iter().position(|v| {
|
list.iter().position(|v| {
|
||||||
v == &Value::Keyword(Keyword::from("verse-order"))
|
v == &Value::Keyword(Keyword::from("verse-order"))
|
||||||
}) {
|
}) {
|
||||||
verse_order + 1
|
let pos = key_pos + 1;
|
||||||
|
list.get(pos).map(|v| match v {
|
||||||
|
Value::List(vals) => vals
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| String::from(v).to_uppercase())
|
||||||
|
.collect::<Vec<String>>(),
|
||||||
|
_ => vec![],
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_VERSE_ORDER_LOCATION
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let verse_order =
|
|
||||||
if let Some(verse_order) = list.get(verse_order_position) {
|
|
||||||
match verse_order {
|
|
||||||
Value::List(vals) => Some(
|
|
||||||
vals.into_iter()
|
|
||||||
.map(|v| String::from(v).to_uppercase())
|
|
||||||
.collect::<Vec<String>>(),
|
|
||||||
),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let first_text_postiion = if let Some(pos) =
|
let first_text_postiion = if let Some(pos) =
|
||||||
list.iter().position(|v| match v {
|
list.iter().position(|v| match v {
|
||||||
Value::List(inner) => {
|
Value::List(inner) => {
|
||||||
|
@ -356,7 +301,7 @@ fn lisp_to_song(list: Vec<Value>) -> Song {
|
||||||
let lyrics = lyrics.trim_start_matches("\\n\\n").to_string();
|
let lyrics = lyrics.trim_start_matches("\\n\\n").to_string();
|
||||||
|
|
||||||
Song {
|
Song {
|
||||||
id: DEFAULT_SONG_ID,
|
id,
|
||||||
title,
|
title,
|
||||||
lyrics: Some(lyrics),
|
lyrics: Some(lyrics),
|
||||||
author,
|
author,
|
||||||
|
|
Loading…
Reference in a new issue