summaryrefslogtreecommitdiff
path: root/src/seq/sequencer.rs
diff options
context:
space:
mode:
authorGraham Northup <grissess@nexusg.org>2018-07-01 21:37:41 -0400
committerGraham Northup <grissess@nexusg.org>2018-07-01 21:37:41 -0400
commita2d24ef36dd6c4197b1306a84eec4fb290d0d5ce (patch)
tree59c63edb720b95d50ed14fb13b861acc06632a99 /src/seq/sequencer.rs
parent22cb7d7cbcacbfe3a7d3a2d454e6b8cf49ae989c (diff)
Partial commit toward IV/seq implementation!
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
+}