Skip to content

Commit

Permalink
Fix name change errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikNatanael committed Jan 11, 2024
1 parent a891927 commit 5bca218
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 75 deletions.
30 changes: 15 additions & 15 deletions knyst/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1134,40 +1134,40 @@ 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());
},
);
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);
Expand Down Expand Up @@ -1209,28 +1209,28 @@ 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());
},
);
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);

Expand All @@ -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);
Expand Down
30 changes: 13 additions & 17 deletions knyst/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,20 @@ 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<Change>, beats: Beats) -> Self {
Self {
input: channel,
value: value.into(),
time: Time::Beats(beats),
}
}
/// Schedule a change at a specific time in [`Superseconds`]
pub fn superseconds(
channel: NodeInput,
value: impl Into<Change>,
superseconds: Seconds,
) -> Self {
/// Schedule a change at a specific time in [`Seconds`]
pub fn seconds(channel: NodeInput, value: impl Into<Change>, 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.
Expand Down Expand Up @@ -388,7 +384,7 @@ impl ParameterChange {
pub enum Time {
Beats(Beats),
DurationFromNow(Duration),
Superseconds(Seconds),
Seconds(Seconds),
Immediately,
}

Expand All @@ -397,15 +393,15 @@ pub enum Time {
#[derive(Clone, Copy, Debug)]
pub enum TimeOffset {
Frames(i64),
Superseconds(Relative<Seconds>),
Seconds(Relative<Seconds>),
}

impl TimeOffset {
/// Convert self to a time offset in frames/samples
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,
},
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -1884,15 +1880,15 @@ 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<Beats> {
if let Some(ggc) = &self.graph_gen_communicator {
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
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3912,14 +3908,14 @@ impl Scheduler {
}
}
}
fn seconds_to_musical_time_superbeats(&self, ts: Seconds) -> Option<Beats> {
fn seconds_to_musical_time_beats(&self, ts: Seconds) -> Option<Beats> {
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))
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions knyst/src/graph/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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.;
Expand All @@ -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());
Expand All @@ -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(
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 5bca218

Please sign in to comment.