mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
fixed keyboard add
This commit is contained in:
parent
a3f8f411ae
commit
b162e6f2c3
1 changed files with 27 additions and 22 deletions
|
|
@ -72,8 +72,7 @@ pub fn process (state: &mut Sequencer, client: &Client, scope: &ProcessScope) ->
|
|||
fn process_in (state: &mut Sequencer, scope: &ProcessScope) {
|
||||
let pos = state.transport.query().unwrap().pos;
|
||||
let usecs = Frame(pos.frame()).to_usec(&state.rate).0;
|
||||
let step = state.tempo.usec_per_step(state.divisions as u64).0;
|
||||
let steps = usecs / step;
|
||||
let steps = usecs / state.tempo.usec_per_step(state.divisions as u64).0;
|
||||
let step = steps % state.steps;
|
||||
let tick = step * state.ppq / state.divisions;
|
||||
|
||||
|
|
@ -110,15 +109,18 @@ fn process_out (state: &mut Sequencer, scope: &ProcessScope) {
|
|||
let end = start + size;
|
||||
let mut writer = state.output_port.writer(scope);
|
||||
let pulse_usec = state.tempo.usec_per_step(state.ppq as u64).0;
|
||||
let tick_start = Frame(start).to_usec(&state.rate).0;
|
||||
let tick_start = tick_start / pulse_usec;
|
||||
let tick_end = Frame(start).to_usec(&state.rate).0;
|
||||
let tick_end = tick_start / pulse_usec;
|
||||
for time in 0..size {
|
||||
let usecs = Frame(start + time).to_usec(&state.rate).0;
|
||||
let ticks = usecs / state.tempo.usec_per_step(state.ppq as u64).0;
|
||||
//println!("{usecs} = {ticks}");
|
||||
let tick_start = Frame(start).to_usec(&state.rate).0 / pulse_usec;
|
||||
let tick_end = Frame(end).to_usec(&state.rate).0 / pulse_usec;
|
||||
for (i, (t, events)) in state.sequence.range(tick_start as u32..tick_end as u32).enumerate() {
|
||||
if events.len() > 0 {
|
||||
panic!("{events:?}");
|
||||
}
|
||||
}
|
||||
//for time in start..end {
|
||||
//let usecs = Frame(time).to_usec(&state.rate).0;
|
||||
//let ticks = usecs / state.tempo.usec_per_step(state.ppq as u64).0;
|
||||
////println!("{usecs} = {ticks}");
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -402,21 +404,24 @@ const COMMANDS: [(KeyCode, &'static str, &'static str, &'static dyn Fn(&mut Sequ
|
|||
fn nop (_: &mut Sequencer) {
|
||||
}
|
||||
fn note_add (s: &mut Sequencer) {
|
||||
let time = (s.time_axis.0 + s.time_cursor) as u32;
|
||||
let time_start = time * s.ppq as u32;
|
||||
let time_end = (time + 1) * s.ppq as u32;
|
||||
let key = ::midly::num::u7::from_int_lossy((s.note_cursor + s.note_axis.0) as u8);
|
||||
let note_on = ::midly::MidiMessage::NoteOn { key, vel: 100.into() };
|
||||
let note_off = ::midly::MidiMessage::NoteOff { key, vel: 100.into() };
|
||||
if s.sequence.contains_key(&time_start) {
|
||||
s.sequence.get_mut(&time_start).unwrap().push(note_on.clone());
|
||||
let pos = s.transport.query().unwrap().pos;
|
||||
let usecs = Frame(pos.frame()).to_usec(&s.rate).0;
|
||||
let steps = usecs / s.tempo.usec_per_step(s.divisions as u64).0;
|
||||
let step = (s.time_axis.0 + s.time_cursor) as u32;
|
||||
let start = (step as u64 * s.ppq / s.divisions) as u32;
|
||||
let end = ((step + 1) as u64 * s.ppq / s.divisions) as u32;
|
||||
let key = ::midly::num::u7::from_int_lossy((s.note_cursor + s.note_axis.0) as u8);
|
||||
let note_on = ::midly::MidiMessage::NoteOn { key, vel: 100.into() };
|
||||
let note_off = ::midly::MidiMessage::NoteOff { key, vel: 100.into() };
|
||||
if s.sequence.contains_key(&start) {
|
||||
s.sequence.get_mut(&start).unwrap().push(note_on.clone());
|
||||
} else {
|
||||
s.sequence.insert(time_start, vec![note_on]);
|
||||
s.sequence.insert(start, vec![note_on]);
|
||||
}
|
||||
if s.sequence.contains_key(&time_end) {
|
||||
s.sequence.get_mut(&time_end).unwrap().push(note_off.clone());
|
||||
if s.sequence.contains_key(&end) {
|
||||
s.sequence.get_mut(&end).unwrap().push(note_off.clone());
|
||||
} else {
|
||||
s.sequence.insert(time_end, vec![note_off]);
|
||||
s.sequence.insert(end, vec![note_off]);
|
||||
}
|
||||
}
|
||||
fn note_del (_: &mut Sequencer) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue