more sensible port creation

This commit is contained in:
🪞👃🪞 2025-01-22 00:10:31 +01:00
parent 4028b3bb29
commit bbe49ad463
7 changed files with 133 additions and 125 deletions

View file

@ -80,23 +80,12 @@ pub struct Clock {
pub sync: Arc<LaunchSync>,
/// Size of buffer in samples
pub chunk: Arc<AtomicUsize>,
}
impl From<&Jack> for Clock {
fn from (jack: &Jack) -> Self {
let (chunk, transport) = jack.with_client(|c|(c.buffer_size(), c.transport()));
let timebase = Arc::new(Timebase::default());
Self {
quant: Arc::new(24.into()),
sync: Arc::new(384.into()),
transport: Arc::new(Some(transport)),
chunk: Arc::new((chunk as usize).into()),
global: Arc::new(Moment::zero(&timebase)),
playhead: Arc::new(Moment::zero(&timebase)),
offset: Arc::new(Moment::zero(&timebase)),
started: RwLock::new(None).into(),
timebase,
}
}
/// For syncing the clock to an external source
pub midi_in: Arc<RwLock<Option<JackMidiIn>>>,
/// For syncing other devices to this clock
pub midi_out: Arc<RwLock<Option<JackMidiOut>>>,
/// For emitting a metronome
pub click_out: Arc<RwLock<Option<JackAudioOut>>>,
}
impl std::fmt::Debug for Clock {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
@ -112,12 +101,27 @@ impl std::fmt::Debug for Clock {
}
}
impl Clock {
pub fn new (jack: &Jack, bpm: Option<f64>) -> Self {
let clock = Self::from(jack);
pub fn new (jack: &Jack, bpm: Option<f64>) -> Usually<Self> {
let (chunk, transport) = jack.with_client(|c|(c.buffer_size(), c.transport()));
let timebase = Arc::new(Timebase::default());
let clock = Self {
quant: Arc::new(24.into()),
sync: Arc::new(384.into()),
transport: Arc::new(Some(transport)),
chunk: Arc::new((chunk as usize).into()),
global: Arc::new(Moment::zero(&timebase)),
playhead: Arc::new(Moment::zero(&timebase)),
offset: Arc::new(Moment::zero(&timebase)),
started: RwLock::new(None).into(),
timebase,
midi_in: Arc::new(RwLock::new(Some(JackMidiIn::new(jack, "M/clock", &[])?))),
midi_out: Arc::new(RwLock::new(Some(JackMidiOut::new(jack, "clock/M", &[])?))),
click_out: Arc::new(RwLock::new(Some(JackAudioOut::new(jack, "click", &[])?))),
};
if let Some(bpm) = bpm {
clock.timebase.bpm.set(bpm);
}
clock
Ok(clock)
}
pub fn timebase (&self) -> &Arc<Timebase> {
&self.timebase