Skip to content

Commit

Permalink
Fix undoing of clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
mwylde committed Nov 12, 2021
1 parent d552d7b commit cf69387
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion loopers-engine/src/looper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use loopers_common::gui_channel::{
};
use loopers_common::music::PanLaw;
use std::collections::VecDeque;
use std::fmt::{Debug, Formatter};
use std::mem::swap;

use atomic::Atomic;
Expand Down Expand Up @@ -933,7 +934,6 @@ impl WaveformGenerator {
}
}

#[derive(Debug)]
enum LooperChange {
PushSample,
PopSample(Sample),
Expand All @@ -946,6 +946,17 @@ enum LooperChange {
UnClear,
}

impl Debug for LooperChange {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
LooperChange::PushSample => write!(f, "PushSample"),
LooperChange::PopSample(sample) => write!(f, "PopSample<{}>", sample.length()),
LooperChange::Clear { samples, .. } => write!(f, "Clear<{}>", samples.len()),
LooperChange::UnClear => write!(f, "UnClear"),
}
}
}

pub struct LooperBackend {
pub id: u32,
pub samples: Vec<Sample>,
Expand Down Expand Up @@ -1138,6 +1149,8 @@ impl LooperBackend {
));
},
ControlMessage::Undo => {
info!("Performing Undo on queue: {:?}", self.undo_queue);

if let Some(change) = self.undo_queue.pop_back() {
if let Some(change) = self.undo_change(change) {
self.redo_queue.push_back(change);
Expand All @@ -1148,6 +1161,7 @@ impl LooperBackend {
));
}
ControlMessage::Redo => {
info!("Performing Redo on queue: {:?}", self.redo_queue);
if let Some(change) = self.redo_queue.pop_back() {
if let Some(change) = self.undo_change(change) {
self.undo_queue.push_back(change);
Expand Down Expand Up @@ -1485,6 +1499,10 @@ impl LooperBackend {
self.out_time = out_time;
self.offset = offset;

if !self.samples.is_empty() {
self.length.store(self.samples[0].length(), Ordering::Relaxed);
}

self.gui_needs_reset = true;

Some(LooperChange::UnClear)
Expand Down

0 comments on commit cf69387

Please sign in to comment.