Skip to content

Commit

Permalink
Cleanup: remove some of the unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrGlad committed Nov 30, 2023
1 parent d2f4398 commit cee926b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
35 changes: 1 addition & 34 deletions src/changeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -127,32 +123,3 @@ impl Snapshot {
}
}
}

pub type EventFn = dyn Fn(&TrackEvent) -> Option<EventAction> + 'static;

/// Convenience wrapper
pub fn to_event_action<NoteFn: Fn(&Note) -> Option<Note> + 'static>(
action: NoteFn,
) -> Box<EventFn> {
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
}
})
}
19 changes: 0 additions & 19 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
}
Expand Down
8 changes: 0 additions & 8 deletions src/track_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Time>, changeset: &mut Changeset) {
for ev in &track.events {
if range_contains(range, ev.at) {
changeset.add(EventAction::Delete(ev.clone()));
}
}
}

pub fn tape_insert(range: &Range<Time>) -> AppliedCommand {
let mut diffs = vec![];
let delta = range.1 - range.0;
Expand Down
3 changes: 1 addition & 2 deletions src/track_history.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::fs;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::time::{Duration, Instant};

use glob::glob;
use regex::Regex;
use serde::{Deserialize, Serialize};

use crate::changeset::{Changeset, EventAction, HistoryLogEntry, Snapshot};
use crate::changeset::{EventAction, HistoryLogEntry, Snapshot};
use crate::common::VersionId;
use crate::track::{import_smf, Track};
use crate::track_edit::{apply_diffs, revert_diffs, CommandDiff, EditCommandId};
Expand Down

0 comments on commit cee926b

Please sign in to comment.