Compare commits
No commits in common. "eee3444c4d542ba8b2ffdb29e2d9b98ead605f72" and "9363be825444ad84c541349aecd251cfb5b17147" have entirely different histories.
eee3444c4d
...
9363be8254
18
src/blip.rs
18
src/blip.rs
|
@ -1,18 +0,0 @@
|
||||||
use crate::note::Note;
|
|
||||||
|
|
||||||
/// thanks to Rumple_Frumpkins from Bitsy Talk for his help in figuring out the blip format.
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct Blip {
|
|
||||||
id: String,
|
|
||||||
notes: Vec<Note>,
|
|
||||||
name: Option<String>,
|
|
||||||
/// Attack (ms), Decay (ms), Sustain (level: 1-15), Hold (sustain duration, ms), Release (ms)
|
|
||||||
envelope: [u8; 5],
|
|
||||||
/// first value is milliseconds per note;
|
|
||||||
/// second value is a modifier to the first note (add or subtract milliseconds)
|
|
||||||
beat: [i16; 2],
|
|
||||||
/// I think this is probably pulse width. apparently the potential values are P2, P4 and P8.
|
|
||||||
square: String,
|
|
||||||
/// Notes can sound repeatedly, or just once as the blip fades out.
|
|
||||||
repeat: bool,
|
|
||||||
}
|
|
46
src/note.rs
46
src/note.rs
|
@ -1,6 +1,5 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
use crate::Error;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum RelativeNote {
|
pub enum RelativeNote {
|
||||||
|
@ -24,35 +23,6 @@ pub struct Note {
|
||||||
octave: u8, // upper limit? 8?
|
octave: u8, // upper limit? 8?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Note {
|
|
||||||
fn from(str: &str) -> Result<Self, Error> {
|
|
||||||
let mut chars: Vec<char> = str.chars().collect();
|
|
||||||
|
|
||||||
// last char may or may not be present / may or may not be an octave number
|
|
||||||
let octave = chars.pop().unwrap_or('4').to_string().parse().unwrap_or(4);
|
|
||||||
|
|
||||||
let chars: String = chars.into_iter().collect();
|
|
||||||
|
|
||||||
let relative = match chars.as_ref() {
|
|
||||||
"C" => RelativeNote::C,
|
|
||||||
"C#" => RelativeNote::CSharp,
|
|
||||||
"D" => RelativeNote::D,
|
|
||||||
"D#" => RelativeNote::DSharp,
|
|
||||||
"E" => RelativeNote::E,
|
|
||||||
"F" => RelativeNote::F,
|
|
||||||
"F#" => RelativeNote::FSharp,
|
|
||||||
"G" => RelativeNote::G,
|
|
||||||
"G#" => RelativeNote::GSharp,
|
|
||||||
"A" => RelativeNote::A,
|
|
||||||
"A#" => RelativeNote::ASharp,
|
|
||||||
"B" => RelativeNote::B,
|
|
||||||
_ => { return Err(Error::RelativeNote); }
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Note { relative, octave })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Note {
|
impl fmt::Display for Note {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
|
@ -90,20 +60,4 @@ mod test {
|
||||||
fn a_sharp_0() {
|
fn a_sharp_0() {
|
||||||
assert_eq!(Note { relative: RelativeNote::ASharp, octave: 0 }.to_string(), "A#0");
|
assert_eq!(Note { relative: RelativeNote::ASharp, octave: 0 }.to_string(), "A#0");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn c_sharp_3_from_str() {
|
|
||||||
assert_eq!(
|
|
||||||
Note::from("C#3").unwrap(),
|
|
||||||
Note { relative: RelativeNote::CSharp, octave: 3 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn b_0_from_str() {
|
|
||||||
assert_eq!(
|
|
||||||
Note::from("B0").unwrap(),
|
|
||||||
Note { relative: RelativeNote::B, octave: 0 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue