panic if shell desired as not impl

This commit is contained in:
Bel LaPointe
2026-03-13 11:34:10 -06:00
parent 36c047caf7
commit de5717a61a
7 changed files with 121 additions and 74 deletions

7
Cargo.lock generated
View File

@@ -242,6 +242,7 @@ dependencies = [
"chrono", "chrono",
"clap", "clap",
"env_logger", "env_logger",
"io-prompt-prototype",
"itertools 0.14.0", "itertools 0.14.0",
"midir", "midir",
"regex", "regex",
@@ -412,6 +413,12 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "io-prompt-prototype"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca9d71ad6b790f2522eeb0a4f207fa7ef21826777d4714c7ff09483bf17b0ab8"
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.2" version = "1.70.2"

View File

@@ -7,6 +7,7 @@ edition = "2024"
chrono = "0.4.44" chrono = "0.4.44"
clap = { version = "4.5.60", features = ["derive"] } clap = { version = "4.5.60", features = ["derive"] }
env_logger = "0.11.9" env_logger = "0.11.9"
io-prompt-prototype = "1.0.0"
itertools = "0.14.0" itertools = "0.14.0"
midir = "0.10.3" midir = "0.10.3"
regex = "1.12.3" regex = "1.12.3"

View File

@@ -14,7 +14,7 @@ pub struct Flags {
#[arg(long, default_value = "super_small_font.sf2")] #[arg(long, default_value = "super_small_font.sf2")]
pub sound_font: String, pub sound_font: String,
#[arg(short, long, default_value = "c 2e+")] #[arg(short, long, default_value = "c 2*e+")]
pub play: Vec<String>, pub play: Vec<String>,
} }

View File

@@ -1,3 +1,4 @@
use io_prompt_prototype::prompt;
use itertools::Itertools; use itertools::Itertools;
mod flags; mod flags;
@@ -12,11 +13,22 @@ fn main() {
eprintln!("{:?}", flags); eprintln!("{:?}", flags);
} }
let once = flags.play.iter().filter(|x| x.len() > 0).count() > 0;
loop {
play_with_flags(&flags);
if once {
break;
}
}
}
fn play_with_flags(flags: &flags::Flags) {
let mut syn_seq = seq::new_syn(syn::Syn::new( let mut syn_seq = seq::new_syn(syn::Syn::new(
flags.debug, flags.debug.clone(),
flags.sound_font, flags.sound_font.clone(),
flags.sample_rate, flags.sample_rate.clone(),
)); ));
let mut i = 0; let mut i = 0;
for p in flags.play.iter() { for p in flags.play.iter() {
for p in play::new(p.clone()) { for p in play::new(p.clone()) {
@@ -24,11 +36,15 @@ fn main() {
i += 1; i += 1;
} }
} }
if i == 0 {
let s: String = prompt!("> ").parse().expect("failed to readline");
panic!("not impl");
}
play(syn_seq, flags.sample_rate, flags.bpm); play(syn_seq, flags.sample_rate, flags.bpm, true);
} }
fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize) { fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize, sync: bool) {
let samples_per_beat = sample_rate / bpm * 60; let samples_per_beat = sample_rate / bpm * 60;
let params = tinyaudio::prelude::OutputDeviceParameters { let params = tinyaudio::prelude::OutputDeviceParameters {
channels_count: 2, channels_count: 2,
@@ -52,6 +68,8 @@ fn play(mut s: seq::SynSeq, sample_rate: usize, bpm: usize) {
}) })
.unwrap(); .unwrap();
// Wait it out if sync {
std::thread::sleep(std::time::Duration::from_secs(duration as u64)); // Wait it out
std::thread::sleep(std::time::Duration::from_secs(duration as u64));
}
} }

View File

@@ -20,21 +20,22 @@ fn from_string(s: String) -> String {
fn parse(s: String) -> Vec<String> { fn parse(s: String) -> Vec<String> {
let s = s let s = s
.split("\n") .split("\n")
.filter(|x: &&str| !x // doesnt start with # .filter(|x: &&str| {
.split_whitespace() !x // doesnt start with #
.collect::<Vec<_>>() .split_whitespace()
.join("") .collect::<Vec<_>>()
.starts_with("#") .join("")
) .starts_with("#")
.map(|x| x })
.split("#") .map(|x| {
.take(1) // drop after # x.split("#")
.collect::<Vec<_>>() .take(1) // drop after #
.join("") .collect::<Vec<_>>()
.split_whitespace() .join("")
.collect::<Vec<_>>() .split_whitespace()
.join(" ") .collect::<Vec<_>>()
) .join(" ")
})
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
let mut channels = vec![]; let mut channels = vec![];
@@ -44,21 +45,23 @@ fn parse(s: String) -> Vec<String> {
match lines[i] { match lines[i] {
"" => { "" => {
j = 0; j = 0;
}, }
_ => { _ => {
while channels.len() <= j { while channels.len() <= j {
channels.push("".to_string()); channels.push("".to_string());
} }
channels[{ let tmp = j; j += 1; tmp }] += &(" ".to_string() + lines[i]); channels[{
}, let tmp = j;
j += 1;
tmp
}] += &(" ".to_string() + lines[i]);
}
}; };
} }
channels channels
.iter() .iter()
.map(|x| x.split_whitespace().collect::<Vec<_>>() .map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
.join(" ") .collect()
)
.collect()
} }
#[cfg(test)] #[cfg(test)]
@@ -111,9 +114,6 @@ mod test {
#[test] #[test]
fn drop_comment_trailer() { fn drop_comment_trailer() {
assert_eq!( assert_eq!(super::new("a b c # hello world")[0], "a b c".to_string());
super::new("a b c # hello world")[0],
"a b c".to_string()
);
} }
} }

View File

@@ -74,10 +74,20 @@ impl Syn {
match self { match self {
Syn::Real(syn) => syn.render(a, b), Syn::Real(syn) => syn.render(a, b),
Syn::Text { m, i } => { Syn::Text { m, i } => {
eprintln!("{} | render[{}]({:?})", chrono::prelude::Utc::now(), i, m eprintln!(
.iter() "{} | render[{}]({:?})",
.map(|tuple| (tuple.0, tuple.1.iter().map(|v| tone::new(v.0.to_string()).string()).collect::<Vec<_>>())) chrono::prelude::Utc::now(),
.collect::<Vec<_>>(), i,
m.iter()
.map(|tuple| (
tuple.0,
tuple
.1
.iter()
.map(|v| tone::new(v.0.to_string()).string())
.collect::<Vec<_>>()
))
.collect::<Vec<_>>(),
); );
*i += 1; *i += 1;
} }

View File

@@ -20,27 +20,31 @@ impl Tone {
let mut result = match captures.name("letter") { let mut result = match captures.name("letter") {
Some(letter) => Tone::char_to_middle_i32(letter.as_str()), Some(letter) => Tone::char_to_middle_i32(letter.as_str()),
None => match captures.name("major") { None => match captures.name("major") {
Some(major) => Tone::char_to_middle_i32(&major.as_str()[..1]) + match &major.as_str()[2..] { Some(major) => {
"0" => 0, Tone::char_to_middle_i32(&major.as_str()[..1])
"1" => 2, + match &major.as_str()[2..] {
"2" => 4, "0" => 0,
"3" => 5, "1" => 2,
"4" => 7, "2" => 4,
"5" => 9, "3" => 5,
_ => 11, "4" => 7,
}, "5" => 9,
_ => 11,
}
}
None => { None => {
let minor = captures.name("minor").unwrap(); let minor = captures.name("minor").unwrap();
Tone::char_to_middle_i32(&minor.as_str()[..1]) + match &minor.as_str()[2..] { Tone::char_to_middle_i32(&minor.as_str()[..1])
"0" => 0, + match &minor.as_str()[2..] {
"1" => 2, "0" => 0,
"2" => 3, "1" => 2,
"3" => 5, "2" => 3,
"4" => 7, "3" => 5,
"5" => 8, "4" => 7,
_ => 10, "5" => 8,
} _ => 10,
}, }
}
}, },
} as i32; } as i32;
@@ -85,23 +89,30 @@ impl Tone {
pub fn string(&self) -> String { pub fn string(&self) -> String {
let v = self.i32(); let v = self.i32();
let modifier = if v > 0 && v < 57 { "-" } else if v >= 69 { "+" } else { "" }; let modifier = if v > 0 && v < 57 {
modifier.to_string() + match v { "-"
45|57|69 => "a", } else if v >= 69 {
46|58|70 => "a+", "+"
47|59|71 => "b", } else {
48|60|72 => "c", ""
49|61|73 => "c+", };
50|62|74 => "d", modifier.to_string()
51|63|75 => "d+", + match v {
52|64|76 => "e", 45 | 57 | 69 => "a",
53|65|77 => "f", 46 | 58 | 70 => "a+",
54|66|78 => "f+", 47 | 59 | 71 => "b",
55|67|79 => "g", 48 | 60 | 72 => "c",
56|68|80 => "g+", 49 | 61 | 73 => "c+",
0 => " ", 50 | 62 | 74 => "d",
_ => "?", 51 | 63 | 75 => "d+",
} 52 | 64 | 76 => "e",
53 | 65 | 77 => "f",
54 | 66 | 78 => "f+",
55 | 67 | 79 => "g",
56 | 68 | 80 => "g+",
0 => " ",
_ => "?",
}
} }
} }