mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
simplify main process callback
This commit is contained in:
parent
9d46cb7619
commit
47b2c5da29
3 changed files with 77 additions and 64 deletions
66
src/main.rs
66
src/main.rs
|
|
@ -67,6 +67,8 @@ pub fn main () -> Usually<()> {
|
||||||
]))?,
|
]))?,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
state.tracks[0].sequence = Some(0);
|
||||||
|
state.tracks[1].sequence = Some(0);
|
||||||
state.track_cursor = 1;
|
state.track_cursor = 1;
|
||||||
state.scene_cursor = 1;
|
state.scene_cursor = 1;
|
||||||
state.note_start = 12;
|
state.note_start = 12;
|
||||||
|
|
@ -121,43 +123,47 @@ pub struct App {
|
||||||
|
|
||||||
process!(App |self, _client, scope| {
|
process!(App |self, _client, scope| {
|
||||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
||||||
|
let mut send_all_notes_off = false;
|
||||||
|
if Some(transport.state) != self.playing {
|
||||||
|
send_all_notes_off = true;
|
||||||
|
}
|
||||||
self.playing = Some(transport.state);
|
self.playing = Some(transport.state);
|
||||||
self.playhead = transport.pos.frame() as usize;
|
self.playhead = transport.pos.frame() as usize;
|
||||||
for Track {
|
let frame = scope.last_frame_time() as usize;
|
||||||
sequence, phrases, midi_out, monitoring, recording, ref mut notes_on, ..
|
let frames = scope.n_frames() as usize;
|
||||||
} in self.tracks.iter_mut() {
|
for track in self.tracks.iter_mut() {
|
||||||
if sequence.is_none() { continue }
|
// Output buffer
|
||||||
let phrase = phrases.get_mut(sequence.unwrap());
|
|
||||||
if phrase.is_none() { continue }
|
|
||||||
let phrase = phrase.unwrap();
|
|
||||||
let frame = scope.last_frame_time() as usize;
|
|
||||||
let frames = scope.n_frames() as usize;
|
|
||||||
let mut output: Vec<Option<Vec<Vec<u8>>>> = vec![None;frames];
|
let mut output: Vec<Option<Vec<Vec<u8>>>> = vec![None;frames];
|
||||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
if send_all_notes_off { all_notes_off(&mut output); }
|
||||||
if Some(transport.state) != self.playing {
|
// For highlighting keys
|
||||||
all_notes_off(&mut output);
|
let mut notes_on = vec![false;128];
|
||||||
}
|
// Need to be borrowed outside the if
|
||||||
self.playing = Some(transport.state);
|
let recording = track.recording;
|
||||||
// Play from phrase into output buffer
|
let monitoring = track.monitoring;
|
||||||
if self.playing == Some(TransportState::Rolling) {
|
// If there's an active phrase, play/record
|
||||||
phrase.process_out(
|
if let Some(phrase) = track.phrase_mut() {
|
||||||
&mut output,
|
// Play from phrase into output buffer
|
||||||
notes_on,
|
if self.playing == Some(TransportState::Rolling) {
|
||||||
|
phrase.process_out(
|
||||||
|
&mut output,
|
||||||
|
&mut notes_on,
|
||||||
|
&self.timebase,
|
||||||
|
frame,
|
||||||
|
frames
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Play from input to monitor, and record into phrase.
|
||||||
|
phrase.process_in(
|
||||||
|
self.midi_in.as_ref().unwrap().iter(scope),
|
||||||
|
&mut notes_on,
|
||||||
|
if monitoring { Some(&mut output) } else { None },
|
||||||
|
recording && self.playing == Some(TransportState::Rolling),
|
||||||
&self.timebase,
|
&self.timebase,
|
||||||
frame,
|
frame,
|
||||||
frames
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Play from input to monitor, and record into phrase.
|
track.notes_on = notes_on;
|
||||||
phrase.process_in(
|
write_output(&mut track.midi_out.writer(scope), &mut output, frames);
|
||||||
self.midi_in.as_ref().unwrap().iter(scope),
|
|
||||||
notes_on,
|
|
||||||
if *monitoring { Some(&mut output) } else { None },
|
|
||||||
*recording && self.playing == Some(TransportState::Rolling),
|
|
||||||
&self.timebase,
|
|
||||||
frame,
|
|
||||||
);
|
|
||||||
write_output(&mut midi_out.writer(scope), &mut output, frames);
|
|
||||||
}
|
}
|
||||||
Control::Continue
|
Control::Continue
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,13 @@ impl Track {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn phrase_mut (&mut self) -> Option<&mut Phrase> {
|
||||||
|
if let Some(phrase) = self.sequence {
|
||||||
|
return self.phrases.get_mut(phrase)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ports!(Track {
|
ports!(Track {
|
||||||
|
|
|
||||||
|
|
@ -185,42 +185,42 @@ mod horizontal {
|
||||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||||
c.blit(buf, x, y, Some(style));
|
c.blit(buf, x, y, Some(style));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn footer (
|
|
||||||
buf: &mut Buffer,
|
|
||||||
area: Rect,
|
|
||||||
note0: usize,
|
|
||||||
note: usize,
|
|
||||||
time0: usize,
|
|
||||||
time: usize,
|
|
||||||
time_z: usize,
|
|
||||||
) {
|
|
||||||
let Rect { mut x, y, width, height } = area;
|
|
||||||
buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
|
||||||
Style::default().dim());
|
|
||||||
buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())),
|
|
||||||
Style::default().dim());
|
|
||||||
x = x + 2;
|
|
||||||
{
|
|
||||||
for (_, [letter, title, value]) in [
|
|
||||||
["S", &format!("ync"), &format!("<4/4>")],
|
|
||||||
["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)],
|
|
||||||
["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")],
|
|
||||||
["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
|
|
||||||
].iter().enumerate() {
|
|
||||||
buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim());
|
|
||||||
x = x + 1;
|
|
||||||
buf.set_string(x, y + height + 1, &title, Style::default().bold().dim());
|
|
||||||
x = x + title.len() as u16 + 1;
|
|
||||||
buf.set_string(x, y + height + 1, &value, Style::default().not_dim());
|
|
||||||
x = x + value.len() as u16;
|
|
||||||
buf.set_string(x, y + height + 1, " ", Style::default().dim());
|
|
||||||
x = x + 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pub fn footer (
|
||||||
|
//buf: &mut Buffer,
|
||||||
|
//area: Rect,
|
||||||
|
//note0: usize,
|
||||||
|
//note: usize,
|
||||||
|
//time0: usize,
|
||||||
|
//time: usize,
|
||||||
|
//time_z: usize,
|
||||||
|
//) {
|
||||||
|
//let Rect { mut x, y, width, height } = area;
|
||||||
|
//buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
||||||
|
//Style::default().dim());
|
||||||
|
//buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())),
|
||||||
|
//Style::default().dim());
|
||||||
|
//x = x + 2;
|
||||||
|
//{
|
||||||
|
//for (_, [letter, title, value]) in [
|
||||||
|
//["S", &format!("ync"), &format!("<4/4>")],
|
||||||
|
//["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)],
|
||||||
|
//["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")],
|
||||||
|
//["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
|
||||||
|
//].iter().enumerate() {
|
||||||
|
//buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim());
|
||||||
|
//x = x + 1;
|
||||||
|
//buf.set_string(x, y + height + 1, &title, Style::default().bold().dim());
|
||||||
|
//x = x + title.len() as u16 + 1;
|
||||||
|
//buf.set_string(x, y + height + 1, &value, Style::default().not_dim());
|
||||||
|
//x = x + value.len() as u16;
|
||||||
|
//buf.set_string(x, y + height + 1, " ", Style::default().dim());
|
||||||
|
//x = x + 2;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
//mod vertical {
|
//mod vertical {
|
||||||
//use super::*;
|
//use super::*;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue