mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
move Phrase::process_in logic to Track::process
This commit is contained in:
parent
4b909ffdc3
commit
163ecaaed6
6 changed files with 107 additions and 105 deletions
|
|
@ -22,7 +22,15 @@ pub struct Track {
|
|||
/// Device selector
|
||||
pub device: usize,
|
||||
}
|
||||
|
||||
ports!(Track {
|
||||
audio: {
|
||||
outs: |_t|Ok(vec![]),
|
||||
}
|
||||
midi: {
|
||||
ins: |_t|Ok(vec![]),
|
||||
outs: |_t|Ok(vec![]),
|
||||
}
|
||||
});
|
||||
impl Track {
|
||||
pub fn new (
|
||||
name: &str,
|
||||
|
|
@ -43,6 +51,75 @@ impl Track {
|
|||
device: 0,
|
||||
})
|
||||
}
|
||||
pub fn process (
|
||||
&mut self,
|
||||
input: MidiIter,
|
||||
timebase: &Arc<Timebase>,
|
||||
playing: Option<TransportState>,
|
||||
scope: &ProcessScope,
|
||||
frame0: usize,
|
||||
frames: usize,
|
||||
panic: bool,
|
||||
) {
|
||||
// Need to be borrowed outside the conditional
|
||||
let recording = self.recording;
|
||||
let monitoring = self.monitoring;
|
||||
// Output buffer
|
||||
let mut output: Vec<Option<Vec<Vec<u8>>>> = vec![None;frames];
|
||||
// For highlighting keys
|
||||
let mut notes_on = vec![false;128];
|
||||
if panic { all_notes_off(&mut output); }
|
||||
// Play from phrase into output buffer
|
||||
if let Some(phrase) = self.phrase() {
|
||||
if playing == Some(TransportState::Rolling) {
|
||||
phrase.process_out(
|
||||
&mut output,
|
||||
&mut notes_on,
|
||||
timebase,
|
||||
frame0,
|
||||
frames
|
||||
);
|
||||
}
|
||||
}
|
||||
// Monitor and record input
|
||||
let phrase = &mut self.phrase_mut();
|
||||
for (time, event, bytes) in parse_midi_input(input) {
|
||||
let pulse = timebase.frames_pulses((frame0 + time) as f64) as usize;
|
||||
match event {
|
||||
LiveEvent::Midi { message, .. } => {
|
||||
if monitoring {
|
||||
if let Some(Some(frame)) = output.get_mut(time) {
|
||||
frame.push(bytes.into())
|
||||
} else {
|
||||
output[time] = Some(vec![bytes.into()]);
|
||||
}
|
||||
}
|
||||
if recording {
|
||||
if let Some(phrase) = phrase {
|
||||
let contains = phrase.notes.contains_key(&pulse);
|
||||
if contains {
|
||||
phrase.notes.get_mut(&pulse).unwrap().push(message.clone());
|
||||
} else {
|
||||
phrase.notes.insert(pulse, vec![message.clone()]);
|
||||
}
|
||||
};
|
||||
}
|
||||
match message {
|
||||
MidiMessage::NoteOn { key, .. } => {
|
||||
notes_on[key.as_int() as usize] = true;
|
||||
}
|
||||
MidiMessage::NoteOff { key, .. } => {
|
||||
notes_on[key.as_int() as usize] = false;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
self.notes_on = notes_on;
|
||||
write_midi_output(&mut self.midi_out.writer(scope), &output, frames);
|
||||
}
|
||||
pub fn add_device (
|
||||
&mut self, device: JackDevice
|
||||
) -> &mut JackDevice {
|
||||
|
|
@ -84,13 +161,3 @@ impl Track {
|
|||
&mut self.phrases[index]
|
||||
}
|
||||
}
|
||||
|
||||
ports!(Track {
|
||||
audio: {
|
||||
outs: |_t|Ok(vec![]),
|
||||
}
|
||||
midi: {
|
||||
ins: |_t|Ok(vec![]),
|
||||
outs: |_t|Ok(vec![]),
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue