mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
control sample start/end with cc20/21
This commit is contained in:
parent
1859f378ea
commit
b992843e1c
5 changed files with 93 additions and 15 deletions
|
|
@ -52,6 +52,30 @@ audio!(|self: GrooveboxTui, client, scope|{
|
|||
if Control::Quit == SamplerAudio(&mut self.sampler).process(client, scope) {
|
||||
return Control::Quit
|
||||
}
|
||||
for RawMidi { time, bytes } in self.sampler.midi_in.iter(scope) {
|
||||
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
|
||||
match message {
|
||||
MidiMessage::Controller { controller, value } => {
|
||||
if controller == u7::from(20) {
|
||||
if let Some(sample) = &self.sampler.mapped[self.editor.note_point()] {
|
||||
let mut sample = sample.write().unwrap();
|
||||
let percentage = value.as_int() as f64 / 127.;
|
||||
sample.start = (percentage * sample.end as f64) as usize;
|
||||
}
|
||||
} else if controller == u7::from(21) {
|
||||
if let Some(sample) = &self.sampler.mapped[self.editor.note_point()] {
|
||||
let mut sample = sample.write().unwrap();
|
||||
let percentage = value.as_int() as f64 / 127.;
|
||||
let length = sample.channels[0].len();
|
||||
sample.end = sample.start + (percentage * (length as f64 - sample.start as f64)) as usize;
|
||||
sample.end = sample.end.min(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.perf.update(t0, scope);
|
||||
Control::Continue
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue