wip: cleanup old code

This commit is contained in:
🪞👃🪞 2025-01-13 00:24:40 +01:00
parent 0d7f78e74f
commit 5d3e564949
10 changed files with 1464 additions and 1512 deletions

View file

@ -1,232 +0,0 @@
use crate::*;
impl HasJack for App {
fn jack (&self) -> &Arc<RwLock<JackConnection>> { &self.jack }
}
//impl HasJack for Arranger {
//fn jack (&self) -> &Arc<RwLock<JackConnection>> { &self.jack }
//}
audio!(|self: App, client, scope|{
// Start profiling cycle
let t0 = self.perf.get_t0();
// Update transport clock
if Control::Quit == ClockAudio(self).process(client, scope) {
return Control::Quit
}
// Collect MIDI input (TODO preallocate)
let midi_in = self.midi_ins.iter()
.map(|port|port.port.iter(scope)
.map(|RawMidi { time, bytes }|(time, LiveEvent::parse(bytes)))
.collect::<Vec<_>>())
.collect::<Vec<_>>();
// Update standalone MIDI sequencer
if let Some(player) = self.player.as_mut() {
if Control::Quit == PlayerAudio(
player,
&mut self.note_buf,
&mut self.midi_buf,
).process(client, scope) {
return Control::Quit
}
}
// Update standalone sampler
if let Some(sampler) = self.sampler.as_mut() {
if Control::Quit == SamplerAudio(sampler).process(client, scope) {
return Control::Quit
}
//for port in midi_in.iter() {
//for message in port.iter() {
//match message {
//Ok(M
//}
//}
//}
}
// TODO move these to editor and sampler?:
for port in midi_in.iter() {
for event in port.iter() {
match event {
(time, Ok(LiveEvent::Midi {message, ..})) => match message {
MidiMessage::NoteOn {ref key, ..} if let Some(editor) = self.editor.as_ref() => {
editor.set_note_point(key.as_int() as usize);
},
MidiMessage::Controller {controller, value} if let (Some(editor), Some(sampler)) = (
self.editor.as_ref(),
self.sampler.as_ref(),
) => {
// TODO: give sampler its own cursor
if let Some(sample) = &sampler.mapped[editor.note_point()] {
sample.write().unwrap().handle_cc(*controller, *value)
}
}
_ =>{}
},
_ =>{}
}
}
}
// Update track sequencers
let tracks = &mut self.tracks;
let note_buf = &mut self.note_buf;
let midi_buf = &mut self.midi_buf;
if Control::Quit == TracksAudio(tracks, note_buf, midi_buf).process(client, scope) {
return Control::Quit
}
// TODO: update timeline position in editor.
// must be in sync with clip's playback. since
// a clip can be on multiple tracks and launched
// at different times, add a playhead with the
// playing track's color.
//self.now.set(0.);
//if let ArrangerSelection::Clip(t, s) = self.selected {
//let clip = self.scenes.get(s).map(|scene|scene.clips.get(t));
//if let Some(Some(Some(clip))) = clip {
//if let Some(track) = self.tracks().get(t) {
//if let Some((ref started_at, Some(ref playing))) = track.player.play_clip {
//let clip = clip.read().unwrap();
//if *playing.read().unwrap() == *clip {
//let pulse = self.current().pulse.get();
//let start = started_at.pulse.get();
//let now = (pulse - start) % clip.length as f64;
//self.now.set(now);
//}
//}
//}
//}
//}
// End profiling cycle
self.perf.update(t0, scope);
Control::Continue
});
/// Hosts the JACK callback for a collection of tracks
pub struct TracksAudio<'a>(
// Track collection
pub &'a mut [ArrangerTrack],
/// Note buffer
pub &'a mut Vec<u8>,
/// Note chunk buffer
pub &'a mut Vec<Vec<Vec<u8>>>,
);
impl Audio for TracksAudio<'_> {
#[inline] fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
let model = &mut self.0;
let note_buffer = &mut self.1;
let output_buffer = &mut self.2;
for track in model.iter_mut() {
if PlayerAudio(track.player_mut(), note_buffer, output_buffer).process(client, scope) == Control::Quit {
return Control::Quit
}
}
Control::Continue
}
}
//audio!(|self: Sequencer, client, scope|{
//// Start profiling cycle
//let t0 = self.perf.get_t0();
//// Update transport clock
//if Control::Quit == ClockAudio(self).process(client, scope) {
//return Control::Quit
//}
//// Update MIDI sequencer
//if Control::Quit == PlayerAudio(
//&mut self.player, &mut self.note_buf, &mut self.midi_buf
//).process(client, scope) {
//return Control::Quit
//}
//// End profiling cycle
//self.perf.update(t0, scope);
//Control::Continue
//});
//audio!(|self: Groovebox, client, scope|{
//// Start profiling cycle
//let t0 = self.perf.get_t0();
//// Update transport clock
//if Control::Quit == ClockAudio(&mut self.player).process(client, scope) {
//return Control::Quit
//}
//// Update MIDI sequencer
//if Control::Quit == PlayerAudio(
//&mut self.player, &mut self.note_buf, &mut self.midi_buf
//).process(client, scope) {
//return Control::Quit
//}
//// Update sampler
//if Control::Quit == SamplerAudio(&mut self.sampler).process(client, scope) {
//return Control::Quit
//}
//// TODO move these to editor and sampler:
//for RawMidi { time, bytes } in self.player.midi_ins[0].port.iter(scope) {
//if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
//match message {
//MidiMessage::NoteOn { ref key, .. } => {
//self.editor.set_note_point(key.as_int() as usize);
//},
//MidiMessage::Controller { controller, value } => {
//if let Some(sample) = &self.sampler.mapped[self.editor.note_point()] {
//sample.write().unwrap().handle_cc(controller, value)
//}
//}
//_ => {}
//}
//}
//}
//// End profiling cycle
//self.perf.update(t0, scope);
//Control::Continue
//});
//audio!(|self: Arranger, client, scope|{
//// Start profiling cycle
//let t0 = self.perf.get_t0();
//// Update transport clock
//if Control::Quit == ClockAudio(self).process(client, scope) {
//return Control::Quit
//}
////// Update MIDI sequencers
////let tracks = &mut self.tracks;
////let note_buf = &mut self.note_buf;
////let midi_buf = &mut self.midi_buf;
////if Control::Quit == TracksAudio(tracks, note_buf, midi_buf).process(client, scope) {
////return Control::Quit
////}
//// FIXME: one of these per playing track
////self.now.set(0.);
////if let ArrangerSelection::Clip(t, s) = self.selected {
////let clip = self.scenes.get(s).map(|scene|scene.clips.get(t));
////if let Some(Some(Some(clip))) = clip {
////if let Some(track) = self.tracks().get(t) {
////if let Some((ref started_at, Some(ref playing))) = track.player.play_clip {
////let clip = clip.read().unwrap();
////if *playing.read().unwrap() == *clip {
////let pulse = self.current().pulse.get();
////let start = started_at.pulse.get();
////let now = (pulse - start) % clip.length as f64;
////self.now.set(now);
////}
////}
////}
////}
////}
//// End profiling cycle
//self.perf.update(t0, scope);
//return Control::Continue
//});