From cf6938739a669a92f2cd172fd7a70b5c4ca7b7f1 Mon Sep 17 00:00:00 2001 From: Micah Wylde Date: Thu, 11 Nov 2021 22:30:32 -0800 Subject: [PATCH] Fix undoing of clear command --- loopers-engine/src/looper.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/loopers-engine/src/looper.rs b/loopers-engine/src/looper.rs index b11ecfa..3cdbc72 100644 --- a/loopers-engine/src/looper.rs +++ b/loopers-engine/src/looper.rs @@ -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; @@ -933,7 +934,6 @@ impl WaveformGenerator { } } -#[derive(Debug)] enum LooperChange { PushSample, PopSample(Sample), @@ -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, @@ -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); @@ -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); @@ -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)