From cee926bbfdfdbef78b51018f4a57889582403786 Mon Sep 17 00:00:00 2001 From: Petr Gladkikh Date: Thu, 30 Nov 2023 17:50:07 +0100 Subject: [PATCH] Cleanup: remove some of the unused code --- src/changeset.rs | 35 +---------------------------------- src/track.rs | 19 ------------------- src/track_edit.rs | 8 -------- src/track_history.rs | 3 +-- 4 files changed, 2 insertions(+), 63 deletions(-) diff --git a/src/changeset.rs b/src/changeset.rs index c897f1d..7f290ea 100644 --- a/src/changeset.rs +++ b/src/changeset.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::common::VersionId; -use crate::track::{EventId, Note, Track, TrackEvent, TrackEventType}; +use crate::track::{EventId, Track, TrackEvent}; use crate::track_edit::{CommandDiff, EditCommandId}; /// Simplest track edit operation. See [Changeset] for uses. @@ -94,10 +94,6 @@ impl Changeset { self.add(a); } } - - pub fn merge(&mut self, other: Self) { - self.changes.extend(other.changes); - } } /// Serializable changeset, diff. Storing these to keep whole edit history persistent, help with @@ -127,32 +123,3 @@ impl Snapshot { } } } - -pub type EventFn = dyn Fn(&TrackEvent) -> Option + 'static; - -/// Convenience wrapper -pub fn to_event_action Option + 'static>( - action: NoteFn, -) -> Box { - Box::new(move |ev| { - if let TrackEvent { - event: TrackEventType::Note(n), - .. - } = &ev - { - match action(n) { - Some(note) => Some(EventAction::Update( - ev.clone(), - TrackEvent { - id: ev.id, - at: ev.at, - event: TrackEventType::Note(note), - }, - )), - None => None, - } - } else { - None - } - }) -} diff --git a/src/track.rs b/src/track.rs index 1f028ce..1bdb779 100644 --- a/src/track.rs +++ b/src/track.rs @@ -111,7 +111,6 @@ impl Track { } pub fn patch(&mut self, changeset: &Changeset) { - // TODO (DRY) See also [revert] let mut track_map = self.index_events(); for ea in changeset.changes.values() { match ea.after() { @@ -129,24 +128,6 @@ impl Track { self.splat_events(&track_map); } - pub fn revert(&mut self, changeset: &Changeset) { - let mut track_map = self.index_events(); - for ea in changeset.changes.values() { - match ea.before() { - Some(ev) => { - assert_eq!( - track_map.insert(ev.id, ev.clone()).is_some(), - matches!(ea, EventAction::Update(_, _)) - ); - } - None => { - assert!(track_map.remove(&ea.event_id()).is_some()); - } - } - } - self.splat_events(&track_map); - } - pub fn commit(&mut self) { assert!(is_ordered(&self.events)); } diff --git a/src/track_edit.rs b/src/track_edit.rs index 7434115..82172c3 100644 --- a/src/track_edit.rs +++ b/src/track_edit.rs @@ -109,14 +109,6 @@ fn do_shift_tail(track: &Track, at: &Time, delta: &Time, changeset: &mut Changes changeset.add_all(&actions); } -fn do_delete_events_range(track: &Track, range: &Range