diff --git a/knyst/src/controller.rs b/knyst/src/controller.rs index dc164d3..8535b2c 100644 --- a/knyst/src/controller.rs +++ b/knyst/src/controller.rs @@ -714,12 +714,12 @@ pub enum StartBeat { Multiple(Beats), } -/// Callback that is scheduled in [`Superbeats`]. The closure inside the -/// callback should only schedule changes in Superbeats time guided by the value +/// Callback that is scheduled in [`Beats`]. The closure inside the +/// callback should only schedule changes in Beats time guided by the value /// to start scheduling that is passed to the function. /// /// The closure takes two parameters: the time to start the next scheduling in -/// Superbeats time and a `&mut KnystCommands` for scheduling the changes. The +/// Beats time and a `&mut KnystCommands` for scheduling the changes. The /// timestamp in the first parameter is the start time of the callback plus all /// the returned beat intervals to wait until the next callback. The callback /// can return the time to wait until it gets called again or `None` to remove @@ -1134,20 +1134,20 @@ mod tests { graph_output(0, once_trig()); }); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(5, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(5, sr as u64)), || { graph_output(0, once_trig()); }, ); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(10, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(10, sr as u64)), || { graph_output(0, once_trig()); }, ); let mut og = None; schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(16, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(16, sr as u64)), || { og = Some(one_gen()); graph_output(0, og.unwrap()); @@ -1155,19 +1155,19 @@ mod tests { ); let og = og.unwrap(); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(17, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(17, sr as u64)), || { og.passthrough(2.0); }, ); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(19, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(19, sr as u64)), || { og.passthrough(3.0); }, ); // Try with the pure KnystCommands methods as well. - knyst_commands().start_scheduling_bundle(knyst::graph::Time::Superseconds( + knyst_commands().start_scheduling_bundle(knyst::graph::Time::Seconds( Seconds::from_samples(20, sr as u64), )); og.passthrough(4.0); @@ -1209,20 +1209,20 @@ mod tests { graph_output(0, once_trig()); }); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(5, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(5, sr as u64)), || { graph_output(0, once_trig()); }, ); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(10, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(10, sr as u64)), || { graph_output(0, once_trig()); }, ); let mut og = None; schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(16, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(16, sr as u64)), || { og = Some(one_gen()); graph_output(0, og.unwrap()); @@ -1230,7 +1230,7 @@ mod tests { ); let og = og.unwrap(); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(17, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(17, sr as u64)), || { og.passthrough(2.0); @@ -1239,13 +1239,13 @@ mod tests { }, ); schedule_bundle( - crate::graph::Time::Superseconds(Seconds::from_samples(19, sr as u64)), + crate::graph::Time::Seconds(Seconds::from_samples(19, sr as u64)), || { og.passthrough(3.0); }, ); // Try with the pure KnystCommands methods as well. - knyst_commands().start_scheduling_bundle(knyst::graph::Time::Superseconds( + knyst_commands().start_scheduling_bundle(knyst::graph::Time::Seconds( Seconds::from_samples(20, sr as u64), )); og.passthrough(4.0); diff --git a/knyst/src/graph.rs b/knyst/src/graph.rs index a9e8ea2..359fb34 100644 --- a/knyst/src/graph.rs +++ b/knyst/src/graph.rs @@ -340,7 +340,7 @@ pub struct ParameterChange { } impl ParameterChange { - /// Schedule a change at a specific time in [`Superbeats`] + /// Schedule a change at a specific time in [`Beats`] pub fn beats(channel: NodeInput, value: impl Into, beats: Beats) -> Self { Self { input: channel, @@ -348,16 +348,12 @@ impl ParameterChange { time: Time::Beats(beats), } } - /// Schedule a change at a specific time in [`Superseconds`] - pub fn superseconds( - channel: NodeInput, - value: impl Into, - superseconds: Seconds, - ) -> Self { + /// Schedule a change at a specific time in [`Seconds`] + pub fn seconds(channel: NodeInput, value: impl Into, seconds: Seconds) -> Self { Self { input: channel, value: value.into(), - time: Time::Superseconds(superseconds), + time: Time::Seconds(seconds), } } /// Schedule a change at a duration from right now. @@ -388,7 +384,7 @@ impl ParameterChange { pub enum Time { Beats(Beats), DurationFromNow(Duration), - Superseconds(Seconds), + Seconds(Seconds), Immediately, } @@ -397,7 +393,7 @@ pub enum Time { #[derive(Clone, Copy, Debug)] pub enum TimeOffset { Frames(i64), - Superseconds(Relative), + Seconds(Relative), } impl TimeOffset { @@ -405,7 +401,7 @@ impl TimeOffset { pub fn to_frames(&self, sample_rate: u64) -> i64 { match self { TimeOffset::Frames(frame_offset) => *frame_offset, - TimeOffset::Superseconds(relative_supserseconds) => match relative_supserseconds { + TimeOffset::Seconds(relative_supserseconds) => match relative_supserseconds { Relative::Before(s) => (s.to_samples(sample_rate) as i64) * -1, Relative::After(s) => s.to_samples(sample_rate) as i64, }, @@ -1390,7 +1386,7 @@ impl Graph { Time::DurationFromNow(_) => { return Err(PushError::InvalidStartTimeOnUnstartedGraph(start_time)) } - Time::Superseconds(s) => { + Time::Seconds(s) => { start_timestamp = s.to_samples( self.sample_rate as u64 * self.oversampling.as_usize() as u64, ) @@ -1884,7 +1880,7 @@ impl Graph { graph.start_scheduler(latency, start_ts, clock_update, musical_time_map); } } - /// Returns the current audio thread time in Superbeats based on the + /// Returns the current audio thread time in Beats based on the /// MusicalTimeMap, or None if it is not available (e.g. if the Graph has /// not been started yet). pub fn get_current_time_musical(&self) -> Option { @@ -1892,7 +1888,7 @@ impl Graph { let ts_samples = ggc.timestamp.load(Ordering::Relaxed); let seconds = (ts_samples as f64) / (self.sample_rate as f64); ggc.scheduler - .seconds_to_musical_time_superbeats(Seconds::from_seconds_f64(seconds)) + .seconds_to_musical_time_beats(Seconds::from_seconds_f64(seconds)) } else { None } @@ -3791,7 +3787,7 @@ impl Scheduler { * (*sample_rate as f64) + *latency) as u64 } - Time::Superseconds(superseconds) => superseconds.to_samples(*sample_rate), + Time::Seconds(seconds) => seconds.to_samples(*sample_rate), Time::Beats(mt) => { // TODO: Remove unwrap, return a Result let mtm = musical_time_map.read().unwrap(); @@ -3912,14 +3908,14 @@ impl Scheduler { } } } - fn seconds_to_musical_time_superbeats(&self, ts: Seconds) -> Option { + fn seconds_to_musical_time_beats(&self, ts: Seconds) -> Option { match self { Scheduler::Stopped { .. } => None, Scheduler::Running { musical_time_map, .. } => { let mtm = musical_time_map.read().unwrap(); - Some(mtm.superseconds_to_superbeats(ts)) + Some(mtm.seconds_to_beats(ts)) } } } diff --git a/knyst/src/graph/tests.rs b/knyst/src/graph/tests.rs index 924c3f4..4d0d52c 100644 --- a/knyst/src/graph/tests.rs +++ b/knyst/src/graph/tests.rs @@ -502,21 +502,21 @@ fn scheduling() { graph.connect(constant(2.).to(node1)).unwrap(); graph.update(); graph - .schedule_change(ParameterChange::superseconds( + .schedule_change(ParameterChange::seconds( node0.input(0), 1.0, Seconds::from_samples(3, SR), )) .unwrap(); graph - .schedule_change(ParameterChange::superseconds( + .schedule_change(ParameterChange::seconds( node0.input("passthrough"), 2.0, Seconds::from_samples(2, SR), )) .unwrap(); graph - .schedule_change(ParameterChange::superseconds( + .schedule_change(ParameterChange::seconds( node1.input(0), 10.0, Seconds::from_samples(7, SR), @@ -538,21 +538,21 @@ fn scheduling() { assert_eq!(run_graph.graph_output_buffers().read(0, 2), 6.0); assert_eq!(run_graph.graph_output_buffers().read(0, 3), 5.0); graph - .schedule_change(ParameterChange::superseconds( + .schedule_change(ParameterChange::seconds( node0.input(0), 0.0, Seconds::from_samples(5, SR), )) .unwrap(); graph - .schedule_change(ParameterChange::superseconds( + .schedule_change(ParameterChange::seconds( node1.input(0), 0.0, Seconds::from_samples(6, SR), )) .unwrap(); assert_eq!( - graph.schedule_change(ParameterChange::superseconds( + graph.schedule_change(ParameterChange::seconds( node1.input("pasta"), 100.0, Seconds::from_samples(6, SR) @@ -817,7 +817,7 @@ fn start_nodes_with_sample_precision() { GenState::Continue }) .output("out"), - Time::Superseconds(Seconds::from_samples(1, SR)), + Time::Seconds(Seconds::from_samples(1, SR)), ); graph.connect(n0.to_graph_out()).unwrap(); let mut counter1 = 0.; @@ -830,7 +830,7 @@ fn start_nodes_with_sample_precision() { GenState::Continue }) .output("out"), - Time::Superseconds(Seconds::from_samples(2, SR)), + Time::Seconds(Seconds::from_samples(2, SR)), ); graph.connect(n1.to_graph_out()).unwrap(); let mut run_graph = test_run_graph(&mut graph, RunGraphSettings::default()); @@ -850,7 +850,7 @@ fn start_nodes_with_sample_precision() { GenState::Continue }) .output("out"), - Time::Superseconds(Seconds::from_samples(3 + BLOCK_SIZE as u64, SR)), + Time::Seconds(Seconds::from_samples(3 + BLOCK_SIZE as u64, SR)), ); let mut counter3 = 0.; let n3 = graph.push_at_time( @@ -862,7 +862,7 @@ fn start_nodes_with_sample_precision() { GenState::Continue }) .output("out"), - Time::Superseconds(Seconds::from_samples(4 + BLOCK_SIZE as u64, SR)), + Time::Seconds(Seconds::from_samples(4 + BLOCK_SIZE as u64, SR)), ); graph.connect(n2.to_graph_out()).unwrap(); graph.connect(n3.to_graph_out()).unwrap(); diff --git a/knyst/src/scheduling.rs b/knyst/src/scheduling.rs index acd1826..e0447f3 100644 --- a/knyst/src/scheduling.rs +++ b/knyst/src/scheduling.rs @@ -20,20 +20,20 @@ impl TempoChange { TempoChange::NewTempo { bpm } => (duration.as_beats_f64() * 60.) / bpm, } } - /// Converts a duration in seconds within this TempoChange to Superbeats + /// Converts a duration in seconds within this TempoChange to Beats pub fn secs_f64_to_beats(&self, section_duration: f64) -> Beats { match self { TempoChange::NewTempo { bpm } => Beats::from_beats_f64(*bpm * (section_duration / 60.)), } } } -/// A map detailing tempo changes such that a [`Superbeats`] value can be +/// A map detailing tempo changes such that a [`Beats`] value can be /// mapped to a deterministic time in seconds (wall clock time). The timestamps -/// are stored as [`Superbeats`] in absolute time from the start (0 beats), not +/// are stored as [`Beats`] in absolute time from the start (0 beats), not /// as relative section lengths. /// /// Must always have a first [`TempoChange`] at the start, otherwise it wouldn't -/// be possible to map [`Superbeats`] to seconds. The tempo_changes must be +/// be possible to map [`Beats`] to seconds. The tempo_changes must be /// sorted in ascending order. pub struct MusicalTimeMap { tempo_changes: Vec<(TempoChange, Beats)>, @@ -50,15 +50,15 @@ impl MusicalTimeMap { /// # Example /// ``` /// use knyst::scheduling::{MusicalTimeMap, TempoChange}; - /// use knyst::time::Superbeats; + /// use knyst::time::Beats; /// let mut map = MusicalTimeMap::new(); - /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Superbeats::new(999, 200000)); - /// map.insert(TempoChange::NewTempo { bpm: 50.0 }, Superbeats::new(504, 200)); - /// map.insert(TempoChange::NewTempo { bpm: 34.1 }, Superbeats::new(5, 200)); - /// map.insert(TempoChange::NewTempo { bpm: 642.999 }, Superbeats::new(5, 201)); - /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Superbeats::new(5, 200)); - /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Superbeats::new(2000, 0)); - /// map.insert(TempoChange::NewTempo { bpm: 80.0 }, Superbeats::new(0, 0)); + /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Beats::new(999, 200000)); + /// map.insert(TempoChange::NewTempo { bpm: 50.0 }, Beats::new(504, 200)); + /// map.insert(TempoChange::NewTempo { bpm: 34.1 }, Beats::new(5, 200)); + /// map.insert(TempoChange::NewTempo { bpm: 642.999 }, Beats::new(5, 201)); + /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Beats::new(5, 200)); + /// map.insert(TempoChange::NewTempo { bpm: 60.0 }, Beats::new(2000, 0)); + /// map.insert(TempoChange::NewTempo { bpm: 80.0 }, Beats::new(0, 0)); /// assert!(map.is_sorted()); /// assert_eq!(map.len(), 6); /// ``` @@ -97,7 +97,7 @@ impl MusicalTimeMap { self.tempo_changes[index].0 = tempo_change; } } - /// Move a [`TempoChange`] to a new position in [`Superbeats`]. If the + /// Move a [`TempoChange`] to a new position in [`Beats`]. If the /// first tempo change is moved a 60 bpm tempo change will be inserted at /// the start. pub fn move_tempo_change(&mut self, index: usize, time_stamp: Beats) { @@ -108,30 +108,30 @@ impl MusicalTimeMap { self.insert(TempoChange::NewTempo { bpm: 60.0 }, Beats::new(0, 0)); } } - /// Convert a [`Superbeats`] timestamp to seconds using this map. + /// Convert a [`Beats`] timestamp to seconds using this map. /// /// # Example /// ``` /// use knyst::scheduling::{MusicalTimeMap, TempoChange}; - /// use knyst::time::Superbeats; + /// use knyst::time::Beats; /// let mut map = MusicalTimeMap::new(); - /// assert_eq!(map.musical_time_to_secs_f64(Superbeats::new(0, 0)), 0.0); + /// assert_eq!(map.musical_time_to_secs_f64(Beats::new(0, 0)), 0.0); /// // Starts with a TempoChange for a constant 60 bpm per default - /// assert_eq!(map.musical_time_to_secs_f64(Superbeats::new(1, 0)), 1.0); + /// assert_eq!(map.musical_time_to_secs_f64(Beats::new(1, 0)), 1.0); /// map.replace(0, TempoChange::NewTempo{bpm: 120.0}); // Double the speed - /// assert_eq!(map.musical_time_to_secs_f64(Superbeats::new(1, 0)), 0.5); + /// assert_eq!(map.musical_time_to_secs_f64(Beats::new(1, 0)), 0.5); /// // With multiple tempo changes the accumulated time passed will be returned /// map.insert( /// TempoChange::NewTempo { bpm: 60.0 }, - /// Superbeats::from_beats(16), + /// Beats::from_beats(16), /// ); /// map.insert( /// TempoChange::NewTempo { bpm: 6000.0 }, - /// Superbeats::from_beats(32), + /// Beats::from_beats(32), /// ); /// /// assert_eq!( - /// map.musical_time_to_secs_f64(Superbeats::from_beats(32 + 1000)), + /// map.musical_time_to_secs_f64(Beats::from_beats(32 + 1000)), /// 16.0 * 0.5 + 16.0 * 1.0 + (1000. * 0.01) /// ); /// ``` @@ -177,7 +177,7 @@ impl MusicalTimeMap { accumulated_seconds } /// Convert a timestamp in seconds to beats using self - pub fn superseconds_to_superbeats(&self, ts: Seconds) -> Beats { + pub fn seconds_to_beats(&self, ts: Seconds) -> Beats { // If we have not upheld our promise about the state of the MusicalTimeMap there is a bug assert!(self.tempo_changes.len() > 0); assert_eq!(self.tempo_changes[0].1, Beats::ZERO); @@ -264,7 +264,7 @@ mod tests { 5.75 ); assert_eq!( - map.superseconds_to_superbeats(Seconds::from_seconds_f64(2.)), + map.seconds_to_beats(Seconds::from_seconds_f64(2.)), Beats::from_beats(2) ); map.replace(0, TempoChange::NewTempo { bpm: 120.0 }); @@ -292,7 +292,7 @@ mod tests { 16.0 * 0.5 + 16.0 + 10. ); assert_eq!( - map.superseconds_to_superbeats(Seconds::from_seconds_f64(2.)), + map.seconds_to_beats(Seconds::from_seconds_f64(2.)), Beats::from_beats(4) ); } diff --git a/knyst/src/time.rs b/knyst/src/time.rs index 1c3c443..95d814c 100644 --- a/knyst/src/time.rs +++ b/knyst/src/time.rs @@ -63,7 +63,7 @@ impl Seconds { self.seconds as f64 + (self.subsample_tesimals as f64 / SUBSAMPLE_TESIMALS_PER_SECOND as f64) } - /// Convert a number of samples at a given sample rate to a `Superseconds` + /// Convert a number of samples at a given sample rate to a `Seconds` pub fn from_samples(samples: u64, sample_rate: u64) -> Self { let seconds = (samples / sample_rate) as u32; let subsample_tesimals = @@ -220,7 +220,7 @@ impl Beats { beats, } } - /// Returns Superbeats with `beats` beats and 0 tesimals + /// Returns Beats with `beats` beats and 0 tesimals pub fn from_beats(beats: u32) -> Self { Self::new(beats, 0) } @@ -354,10 +354,10 @@ mod tests { } #[test] fn duration_to_subsample_time() { - for seconds in [73.73, 10.832, 10000.25, 84923.399] { - let superseconds = Seconds::from_seconds_f64(seconds); - let duration = Duration::from_secs_f64(seconds); - assert_eq!(superseconds, duration.into()) + for s in [73.73, 10.832, 10000.25, 84923.399] { + let seconds = Seconds::from_seconds_f64(s); + let duration = Duration::from_secs_f64(s); + assert_eq!(seconds, duration.into()) } } #[test] diff --git a/knyst/src/trig.rs b/knyst/src/trig.rs index a19bf1d..be561ff 100644 --- a/knyst/src/trig.rs +++ b/knyst/src/trig.rs @@ -89,11 +89,11 @@ impl IntervalTrig { // Adding first makes the time until the first trigger the same as // the time between subsequent triggers so it is more consistent. self.counter += one_sample; - let interval_as_superseconds = Seconds::from_seconds_f64(*interval as f64); - *trig_out = if self.counter >= interval_as_superseconds { + let interval_as_seconds = Seconds::from_seconds_f64(*interval as f64); + *trig_out = if self.counter >= interval_as_seconds { self.counter = self .counter - .checked_sub(interval_as_superseconds) + .checked_sub(interval_as_seconds) .expect("Counter was checked to be bigger than or equal to the interval so the subtraction should always work."); 1.0 } else {