use std::process::Command;
use std::io::{self, Write};
use std::path::Path;
use crate::notation::pitch::NoteName;
pub mod notation;
pub mod parser;
pub fn compile(input_file: &'static str) -> bool {
if is_lilypond_file(input_file) {
match Command::new("lilypond")
.arg(input_file)
.output() {
Ok(o) => {
if o.status.success() {
println!("Compiled {}", input_file);
io::stdout().write_all(o.stdout.as_ref()).unwrap();
true
} else {
io::stdout().write_all(o.stderr.as_ref()).unwrap();
false
}
}
Err(e) => {
println!("Could not run LilyPond. Error: {}", e);
println!("Install LilyPond at https://lilypond.org/download.html");
false
}
}
} else {
println!("File {} does not exist or is invalid.", input_file);
println!("Make sure your file has the .ly extension");
false
}
}
pub fn is_lilypond_file(filename: &'static str) -> bool {
match Path::new(filename).extension() {
Some(ex) => {
if ex == "ly" {
true
} else {
false
}
}
None => false
}
}
#[derive(PartialEq, Debug)]
pub struct LilyPond {
pub notes: Vec<NoteName>
}
impl LilyPond {
pub fn new() -> LilyPond {
LilyPond {
notes: vec![]
}
}
pub fn parse(&mut self, raw: &'static str) {
println!("{}", raw);
}
}