using QuikDawEditor.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using static QuikDawEditor.EDITING.StaticProperties; using static QuikDawEditor.EDITING.MiscMethods; using QuikDawEditor.EditingClasses; using System.Windows.Media; using System.Text.Json; namespace QuikDawEditor.Undo; public class TrackAddUndo : UndoClass { public string UndoMainValue { get { return "Delete track:" + GetTrackFromID(AddedTrackID).TrackName; } } string AddedTrackID; public TrackAddUndo(string addedTrackID) { AddedTrackID = addedTrackID; PreventWhilePlaying = true; } public override void Undo() { Track addedTrack = GetTrackFromID(AddedTrackID); if (addedTrack.parentTrack == null) editingProject.Tracks.Remove(addedTrack); else GetTrackFromID(addedTrack.parentTrack.UndoTrackID).SubTracks.Remove(addedTrack); } } public class TrackDuplicateUndo : UndoClass { public string UndoMainValue { get { return "Delete duped track:" + GetTrackFromID(UndoTrackID).TrackName; } } string UndoTrackID; public TrackDuplicateUndo(string undotrackID) { UndoTrackID = undotrackID; PreventWhilePlaying = true; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); if (undoTrack.parentTrack == null) editingProject.Tracks.Remove(undoTrack); else GetTrackFromID(undoTrack.parentTrack.UndoTrackID).SubTracks.Remove(undoTrack); } } public class TrackMoveUndo : UndoClass { public string UndoMainValue { get { return "Return track idx to:" + PreMoveTrackIndex.ToString(); } } string PremoveParentTrackID; int PreMoveTrackIndex; string MovedTrackID; public TrackMoveUndo(string premoveParentTrackID, int premoveTrackIndex, string movedTrackID) { PremoveParentTrackID = premoveParentTrackID; PreMoveTrackIndex = premoveTrackIndex; MovedTrackID = movedTrackID; PreventWhilePlaying = true; } public override void Undo() { Track undoTrack = GetTrackFromID(MovedTrackID); Track premoveParentTrack = GetTrackFromID(PremoveParentTrackID); //Debug.WriteLine("PremoveaprentID=" + PremoveParentTrackID + "\npremovepT is null? " + (premoveParentTrack == null).ToString()); if (premoveParentTrack == null) { //was originally a base track if (undoTrack.parentTrack == null) editingProject.Tracks.Move(editingProject.Tracks.IndexOf(undoTrack), PreMoveTrackIndex); else { undoTrack.parentTrack.SubTracks.Remove(undoTrack); editingProject.Tracks.Insert(PreMoveTrackIndex, undoTrack); } } else { //was originally a subtrack if (premoveParentTrack == undoTrack.parentTrack) premoveParentTrack.SubTracks.Move(premoveParentTrack.SubTracks.IndexOf(undoTrack), PreMoveTrackIndex); else { if (undoTrack.parentTrack == null) editingProject.Tracks.Remove(undoTrack); else undoTrack.parentTrack.SubTracks.Remove(undoTrack); premoveParentTrack.SubTracks.Insert(PreMoveTrackIndex, undoTrack); } } } } public class TrackDeleteUndo : UndoClass { public string UndoMainValue { get { return "Restore deleted track at idx:" + TrackIndex.ToString(); } } string TrackJson; int TrackIndex; string ParentTrackID; public TrackDeleteUndo(int trackindex, string trackJson, string parentTrackID) { TrackIndex = trackindex; TrackJson = trackJson; ParentTrackID = parentTrackID; IsLongUndoAction = true; PreventWhilePlaying = true; } public override void Undo() { Track restoreTrack = CreateTrackFromJson(TrackJson); Track parentTrack = GetTrackFromID(ParentTrackID); if (parentTrack == null) editingProject.Tracks.Insert(TrackIndex, restoreTrack); else parentTrack.SubTracks.Insert(TrackIndex, restoreTrack); } } public class TrackRenameUndo : UndoClass { public string UndoMainValue { get { return "Rename track to:" + TrackName.ToString(); } } string UndoTrackID; string TrackName; public TrackRenameUndo(string undoTrackID, string trackName) { UndoTrackID = undoTrackID; TrackName = trackName; } public override void Undo() { GetTrackFromID(UndoTrackID).TrackName = TrackName; } } public class TrackColorChangeUndo : UndoClass { public string UndoMainValue { get { return "Color change to: " + ColorString; } } string UndoTrackID; string ColorString; public TrackColorChangeUndo(string undoTrackID, string colorString) { UndoTrackID = undoTrackID; ColorString = colorString; } public override void Undo() { GetTrackFromID(UndoTrackID).TrackBackgroundColor = (Color)ColorConverter.ConvertFromString(ColorString); } } public class TrackHeightResizeUndo : UndoClass { public string UndoMainValue { get { return "Restore height to:" + RestoreHeight.ToString(); } } string UndoTrackID; double RestoreHeight; public TrackHeightResizeUndo(string undoTrackID, double restoreHeight) { UndoTrackID = undoTrackID; RestoreHeight = restoreHeight; } public override void Undo() { GetTrackFromID(UndoTrackID).TrackHeight = RestoreHeight; } } public class TrackVolumeChangeUndo : UndoClass { public string UndoMainValue { get { return "Restore vol to:" + RestoreVolume.ToString(); } } string UndoTrackID; float RestoreVolume; public TrackVolumeChangeUndo(string undoTrackID, float restoreVolume) { UndoTrackID = undoTrackID; RestoreVolume = restoreVolume; } public override void Undo() { GetTrackFromID(UndoTrackID).Volume = RestoreVolume; } } public class TrackPanChangeUndo : UndoClass { public string UndoMainValue { get { return "Restore pan to:" + RestorePan.ToString(); } } string UndoTrackID; float RestorePan; public TrackPanChangeUndo(string undoTrackID, float restorePan) { UndoTrackID = undoTrackID; RestorePan = restorePan; } public override void Undo() { GetTrackFromID(UndoTrackID).Pan = RestorePan; } } public class SubmixToggleUndo : UndoClass { public string UndoMainValue { get { return "Toggle submix:" + (!GetTrackFromID(UndoTrackID).SubTracksVisible).ToString(); } } string UndoTrackID; public SubmixToggleUndo(string undoTrackID) { UndoTrackID = undoTrackID; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); undoTrack.SubTracksVisible= !undoTrack.SubTracksVisible; } } public class TrackSoloToggleUndo : UndoClass { public string UndoMainValue { get { return "Solo to: " + (!GetTrackFromID(UndoTrackID)?.IsSoloed).ToString(); } } string UndoTrackID; public TrackSoloToggleUndo(string undoTrackID) { UndoTrackID = undoTrackID; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); undoTrack.ToggleSolo(); } } public class TrackMuteToggleUndo : UndoClass { public string UndoMainValue { get { return "Mute to: " + (!GetTrackFromID(UndoTrackID)?.IsMuted).ToString(); } } string UndoTrackID; public TrackMuteToggleUndo(string undoTrackID) { UndoTrackID = undoTrackID; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); undoTrack.IsMuted = !undoTrack.IsMuted; } } public class TrackHideToggleUndo : UndoClass { public string UndoMainValue { get { return "Hide/unhide track to:" + (!GetTrackFromID(UndoTrackID).IsTrackCollapsed).ToString(); } } string UndoTrackID; public TrackHideToggleUndo(string undoTrackID) { UndoTrackID = undoTrackID; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); undoTrack.IsTrackCollapsed = !undoTrack.IsTrackCollapsed; if (undoTrack.IsTrackCollapsed) editingProject.hiddenTracks.Add(undoTrack); else editingProject.hiddenTracks.Remove(undoTrack); } } public class AutomationLanesCollapseToggleUndo : UndoClass { public string UndoMainValue { get { return (GetTrackFromID(UndoTrackID).AutomationLanesVisible ? "Hide" : "Show") + " automation lanes"; } } string UndoTrackID; public AutomationLanesCollapseToggleUndo(string undotrackID) { UndoTrackID = undotrackID; } public override void Undo() { Track undoTrack = GetTrackFromID(UndoTrackID); undoTrack.AutomationLanesVisible = !undoTrack.AutomationLanesVisible; } } public class SelectedAutomationLaneChangeUndo : UndoClass { public string UndoMainValue { get { return "selected autoLane to:" + GetTrackFromID(UndoTrackID).AutomationLanes[PrevSelectedAutoLaneIndex].AutomationType; } } string UndoTrackID; int PrevSelectedAutoLaneIndex; public SelectedAutomationLaneChangeUndo(string undotrackID, int prevSelectedAutoLaneIndex) { UndoTrackID = undotrackID; PrevSelectedAutoLaneIndex = prevSelectedAutoLaneIndex; } public override void Undo() { GetTrackFromID(UndoTrackID).SelectedAutomationLaneIndex = PrevSelectedAutoLaneIndex; } } public class TrackClearAllClipsUndo : UndoClass { public string UndoMainValue { get { return "Restore clips: " + ClipJsonStrings.Count.ToString(); } } string UndoTrackID; List ClipJsonStrings; public TrackClearAllClipsUndo(string undoTrackID, List clipJsonStrings) { UndoTrackID = undoTrackID; ClipJsonStrings = clipJsonStrings; IsLongUndoAction = true; PreventWhilePlaying = true; } public override void Undo() { Track thisTrack = GetTrackFromID(UndoTrackID); foreach (string clipJS in ClipJsonStrings) { Clip restoreClip = (Clip)JsonSerializer.Deserialize(clipJS, typeof(Clip)); thisTrack.InsertClip(0, restoreClip); } } } public class AddMidiFileTracksUndo : UndoClass { public string UndoMainValue { get { return "Delete added midi tracks:" + MidiTracksCount.ToString(); } } int StartingTrackIndex; int MidiTracksCount; public AddMidiFileTracksUndo(int startingTrackIndex, int midiTracksCount) { StartingTrackIndex = startingTrackIndex; MidiTracksCount = midiTracksCount; PreventWhilePlaying = true; } public override void Undo() { for (int i = 0; i < MidiTracksCount; i++) editingProject.Tracks.RemoveAt(StartingTrackIndex); } }