summaryrefslogtreecommitdiff
path: root/src/seq/sequencer.rs
diff options
context:
space:
mode:
authorGraham Northup <grissess@nexusg.org>2019-02-12 23:36:38 -0500
committerGraham Northup <grissess@nexusg.org>2019-02-12 23:36:38 -0500
commit5c39a9c26ddd9d7aa4a4fa1af0244348daab0011 (patch)
tree7cc0c140ed8c801d276f87a7663c67be75a842ee /src/seq/sequencer.rs
parent9f2b13aaf422014cb1988a8d91b55aef9c964f12 (diff)
parent23c79cc00eb5d8e76148d79af83a9ab838e602f3 (diff)
Merge branch 'work' into nogfx
Diffstat (limited to 'src/seq/sequencer.rs')
-rw-r--r--src/seq/sequencer.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/seq/sequencer.rs b/src/seq/sequencer.rs
new file mode 100644
index 0000000..2284656
--- /dev/null
+++ b/src/seq/sequencer.rs
@@ -0,0 +1,59 @@
+use super::*;
+
+pub fn coalesce<'a, I: Iterator<Item=&'a NoteStream>>(stream_iter: I) -> NoteStream {
+ let mut output = NoteStream::new();
+
+ for ns in stream_iter {
+ output.extend(ns.iter().cloned());
+ }
+
+ output
+}
+
+pub struct SchedParams {
+ pub epsilon: f32,
+}
+
+impl Default for SchedParams {
+ fn default() -> SchedParams {
+ SchedParams {
+ epsilon: 0.0,
+ }
+ }
+}
+
+pub fn schedule<'a, 'b: 'a, I: Iterator<Item=&'a Note>, F: FnMut(&'a Note) -> Option<&'b str>>(notes: I, mut classifier: F, params: &SchedParams) -> IV {
+ let mut output: IV = Default::default();
+
+ for note in notes {
+ let grp_name = classifier(note);
+ let grp = if let Some(name) = grp_name {
+ if !output.groups.contains_key(name) {
+ output.groups.insert(name.into(), Vec::new());
+ }
+ output.groups.get_mut(name).unwrap()
+ } else {
+ &mut output.default_group
+ };
+
+ let mut found: Option<usize> = None;
+ for (idx, ns) in grp.iter().enumerate() {
+ if ns.len() > 0 {
+ let nt = &ns[ns.len() - 1];
+ if note.time.0 < nt.time.0 + nt.dur.0 + params.epsilon {
+ continue
+ }
+ }
+ found = Some(idx);
+ break;
+ }
+
+ if let Some(nidx) = found {
+ grp[nidx].push(note.clone());
+ } else {
+ grp.push(vec![note.clone()]);
+ }
+ }
+
+ output
+}