hum/lib.rs
1/*
2Hum: A Music Markup Language Synthesizer
3Copyright (C) 2018 Connor R. Bulakites
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19mod hum_parse;
20mod hum_process;
21
22pub mod hum_error;
23pub mod hum_io;
24
25
26// Some information about the library.
27pub const VERSION: &str = "0.6.0";
28pub const AUTHOR: &str = "Connor Bulakites <connor@bulakites.net>";
29pub const ABOUT: &str = "Hum is a music notation language and synthesizer.";
30
31
32fn parse_score_contents(score_contents: String) -> Result<Vec<f32>, hum_error::HumError> {
33 // Parse the score file and use the derived commands to generate the waveform.
34 let score_commands = hum_parse::hum_grammar::score(&score_contents[..])?;
35 Ok(hum_process::run_commands(score_commands)?)
36}
37
38
39pub fn convert_to_wav(score_contents: String, outfname: &str) -> Result<(), hum_error::HumError> {
40 // Generate the waveform and save it to a WAV file.
41 let waveform = parse_score_contents(score_contents)?;
42 Ok(hum_io::save(waveform, outfname)?)
43}