using QuikDawEditor.EditingClasses; using System.Collections.Generic; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.MidiMethods; using static QuikDawEditor.EDITING.StaticProperties; using QuikDawEditor.EDITING.PianoRollModel; namespace QuikDawEditor.Undo; public class MidiEditingSourceClipSelectUndo : UndoClass { public string UndoMainValue { get { return "Midi Clip source to: " + PreviousClipID; } } string PreviousClipID; double PreviousVerticalScroll; PianoRollModel ThisPianoRollModel; public MidiEditingSourceClipSelectUndo(PianoRollModel thisPianoRollModel, string previousClipID, double previousVerticalScroll) { ThisPianoRollModel = thisPianoRollModel; PreviousClipID = previousClipID; PreviousVerticalScroll = previousVerticalScroll; } public override void Undo() { ThisPianoRollModel.myClip = PreviousClipID == "" ? null : GetClipFromID(PreviousClipID); ThisPianoRollModel.VerticalScrollValue = PreviousClipID == "" ? 0 : PreviousVerticalScroll; if (ThisPianoRollModel.myClip != null) { foreach (Clip c in editingProject.GetAllClips) c.IsSelected = false; ThisPianoRollModel.myClip.IsSelected = true; } } } public class MidiEventsSourceSelectUndo : UndoClass { public string UndoMainValue { get { return "Events source index to: " + PreviousSelectedCBIndex.ToString(); } } int PreviousSelectedCBIndex; PianoRollModel thisPianoRollModel; public MidiEventsSourceSelectUndo(int previousSelectedCBIndex, PianoRollModel tPianoRollModel) { thisPianoRollModel = tPianoRollModel; PreviousSelectedCBIndex = previousSelectedCBIndex; } public override void Undo() { thisPianoRollModel.SelectedMidiEventIndex = PreviousSelectedCBIndex; } } public class MidiNoteAddUndo : UndoClass { public string UndoMainValue { get { return "Added midi note: " + GetNoteName(GetClipFromID(UndoClipID).ClipMidiNotes[AddedNoteIndex].Note); } } string UndoClipID; int AddedNoteIndex; public MidiNoteAddUndo(string undoClipID, int addedNoteIndex) { UndoClipID = undoClipID; AddedNoteIndex = addedNoteIndex; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); undoClip.ClipMidiNotes.RemoveAt(AddedNoteIndex) ; undoClip.UpdateMidiImageSource(); } } public class MidiNotesDeleteUndo : UndoClass { public string UndoMainValue { get { return "Deleted midi notes: " + DeletedNotes.Count.ToString(); } } string UndoClipID; List DeletedNotes; List DeletedIndexes; public MidiNotesDeleteUndo(string undoClipID, List deletedNotes, List deletedIndexes) { UndoClipID = undoClipID; DeletedNotes = deletedNotes; DeletedIndexes = deletedIndexes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < DeletedIndexes.Count; idxno += 1) { DeletedNotes[idxno].Selected = false; undoClip.ClipMidiNotes.Insert(DeletedIndexes[idxno], DeletedNotes[idxno]); } undoClip.SortMidiEventSubGroup(typeof(QDMidiNote)); undoClip.UpdateMidiImageSource(); } } public class MidiNoteLengthsChangeUndo : UndoClass { public string UndoMainValue { get { return "Changed midi lengths: " + NoteIndexes.Count.ToString(); } } string UndoClipID; List NoteOffTimes; List NoteIndexes; public MidiNoteLengthsChangeUndo(string undoClipID, List noteIndexes, List noteOffTimes) { UndoClipID = undoClipID; NoteIndexes = noteIndexes; NoteOffTimes = noteOffTimes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < NoteIndexes.Count; idx++) undoClip.ClipMidiNotes[NoteIndexes[idx]].ClipRelNoteOffTimeMs = NoteOffTimes[idx]; undoClip.UpdateMidiImageSource(); } } public class MidiNoteMovesUndo : UndoClass { public string UndoMainValue { get { return "Moved midi notes: " + NoteIndexes.Count.ToString(); } } string UndoClipID; List NoteIndexes; List PreviousNoteNumbers; List PreviousNoteOnTimes; List PreviousNoteOffTimes; public MidiNoteMovesUndo(string undoClipID, List noteIndexes, List prevNoteNumbers, List prevNoteOnTimes, List prevNoteOffTimes) { UndoClipID = undoClipID; NoteIndexes = noteIndexes; PreviousNoteNumbers = prevNoteNumbers; PreviousNoteOnTimes = prevNoteOnTimes; PreviousNoteOffTimes = prevNoteOffTimes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int nidx = 0; nidx < NoteIndexes.Count; nidx++) { undoClip.ClipMidiNotes[NoteIndexes[nidx]].Note = PreviousNoteNumbers[nidx]; undoClip.ClipMidiNotes[NoteIndexes[nidx]].ClipRelNoteOnTimeMs = PreviousNoteOnTimes[nidx]; undoClip.ClipMidiNotes[NoteIndexes[nidx]].ClipRelNoteOffTimeMs = PreviousNoteOffTimes[nidx]; } undoClip.SortMidiEventSubGroup(typeof(QDMidiNote)); undoClip.UpdateMidiImageSource(); } } public class MidiNoteVelocitiesChangeUndo : UndoClass { public string UndoMainValue { get { return "Changed midi velocities: " + NoteIndexes.Count.ToString(); } } string UndoClipID; List NoteVelocities; List NoteIndexes; public MidiNoteVelocitiesChangeUndo(string undoClipID, List noteIndexes, List noteVelocities) { UndoClipID = undoClipID; NoteIndexes = noteIndexes; NoteVelocities = noteVelocities; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < NoteIndexes.Count; idx++) undoClip.ClipMidiNotes[NoteIndexes[idx]].Velocity = NoteVelocities[idx]; } } public class MidiNotesQuantizeUndo : UndoClass { public string UndoMainValue { get { return "Undo quantize midi notes: " + GetClipFromID(UndoClipID).ClipName; } } string UndoClipID; List NoteIndexes; List PreviousNoteOnTimes; List PreviousNoteOffTimes; public MidiNotesQuantizeUndo(string undoClipID, List noteIndexes, List prevNoteOnTimes, List prevNoteOffTimes) { UndoClipID = undoClipID; NoteIndexes = noteIndexes; PreviousNoteOnTimes = prevNoteOnTimes; PreviousNoteOffTimes = prevNoteOffTimes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int nidx = 0; nidx < NoteIndexes.Count; nidx++) { undoClip.ClipMidiNotes[NoteIndexes[nidx]].ClipRelNoteOnTimeMs = PreviousNoteOnTimes[nidx]; undoClip.ClipMidiNotes[NoteIndexes[nidx]].ClipRelNoteOffTimeMs = PreviousNoteOffTimes[nidx]; } undoClip.SortMidiEventSubGroup(typeof(QDMidiNote)); undoClip.UpdateMidiImageSource(); } } public class MidiSustainAddUndo : UndoClass { public string UndoMainValue { get { return "Delete sustain: " + SustainIndex.ToString(); } } string UndoClipID; int SustainIndex; public MidiSustainAddUndo(string addedClipID, int sustainIndex) { UndoClipID = addedClipID; SustainIndex = sustainIndex; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); undoClip.ClipSustainEvents.RemoveAt(SustainIndex); } } public class MidiPitchChangeAddUndo : UndoClass { public string UndoMainValue { get { return "Delete PitchChange: " + PitchChangeIndex.ToString(); } } string UndoClipID; int PitchChangeIndex; public MidiPitchChangeAddUndo(string addedClipID, int pitchChangeIndex) { UndoClipID = addedClipID; PitchChangeIndex = pitchChangeIndex; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); undoClip.ClipPitchChangeEvents.RemoveAt(PitchChangeIndex); } } public class MidiModulationAddUndo : UndoClass { public string UndoMainValue { get { return "Delete Modulation: " + ModulationIndex.ToString(); } } string UndoClipID; int ModulationIndex; public MidiModulationAddUndo(string addedClipID, int modulationIndex) { UndoClipID = addedClipID; ModulationIndex = modulationIndex; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); undoClip.ClipModulationEvents.RemoveAt(ModulationIndex); } } public class MidiSustainsDeleteUndo : UndoClass { public string UndoMainValue { get { return "Delete sustains: " + DeletedSustains.Count.ToString(); } } string UndoClipID; List DeletedSustains; List DeletedIndexes; public MidiSustainsDeleteUndo(string undoClipID, List deletedSustains, List deletedIndexes) { UndoClipID = undoClipID; DeletedSustains = deletedSustains; DeletedIndexes = deletedIndexes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < DeletedIndexes.Count; idxno += 1) { DeletedSustains[idxno].Selected = false; undoClip.ClipSustainEvents.Insert(DeletedIndexes[idxno], DeletedSustains[idxno]); } } } public class MidiPitchChangesDeleteUndo : UndoClass { public string UndoMainValue { get { return "Delete sustains: " + DeletedPitchChanges.Count.ToString(); } } string UndoClipID; List DeletedPitchChanges; List DeletedIndexes; public MidiPitchChangesDeleteUndo(string undoClipID, List deletedPitchChanges, List deletedIndexes) { UndoClipID = undoClipID; DeletedPitchChanges = deletedPitchChanges; DeletedIndexes = deletedIndexes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < DeletedIndexes.Count; idxno += 1) { DeletedPitchChanges[idxno].Selected = false; undoClip.ClipPitchChangeEvents.Insert(DeletedIndexes[idxno], DeletedPitchChanges[idxno]); } } } public class MidiModulationsDeleteUndo : UndoClass { public string UndoMainValue { get { return "Delete sustains: " + DeletedModulations.Count.ToString(); } } string UndoClipID; List DeletedModulations; List DeletedIndexes; public MidiModulationsDeleteUndo(string undoClipID, List deletedModulations, List deletedIndexes) { UndoClipID = undoClipID; DeletedModulations = deletedModulations; DeletedIndexes = deletedIndexes; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < DeletedIndexes.Count; idxno += 1) { DeletedModulations[idxno].Selected = false; undoClip.ClipModulationEvents.Insert(DeletedIndexes[idxno], DeletedModulations[idxno]); } } } //Sustain changes&moves not necessary public class MidiPitchValuesChangeUndo : UndoClass { public string UndoMainValue { get { return "Restore pitchbend changes: " + PitchValues.Count.ToString(); } } string UndoClipID; List PitchValues; List PBIndexes; public MidiPitchValuesChangeUndo(string undoClipID, List pbIndexes, List pitchvalues) { UndoClipID = undoClipID; PBIndexes = pbIndexes; PitchValues = pitchvalues; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < PBIndexes.Count; idx++) undoClip.ClipPitchChangeEvents[PBIndexes[idx]].PitchValue = PitchValues[idx]; } } public class MidiModulationValuesChangeUndo : UndoClass { public string UndoMainValue { get { return "Restore modulation changes: " + ModulationValues.Count.ToString(); } } string UndoClipID; List ModulationValues; List ModIndexes; public MidiModulationValuesChangeUndo(string undoClipID, List modIndexes, List modulationvalues) { UndoClipID = undoClipID; ModIndexes = modIndexes; ModulationValues = modulationvalues; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < ModIndexes.Count; idx++) { undoClip.ClipModulationEvents[ModIndexes[idx]].ModValue = ModulationValues[idx]; //undoClip.ClipModulationEvents[ModIndexes[idx]].UpdateEventReverseZoom(undoClip.ClipModulationEvents[ModIndexes[idx]].revZoomX); } } } public class MidiPitchbendMoveUndo : UndoClass { public string UndoMainValue { get { return "Restore pitch locations: " + PreviousPitchbendMs.Count.ToString(); } } string UndoClipID; List PreviousPitchbendMs; List PCBIndexes; public MidiPitchbendMoveUndo(string undoClipID, List pcbIndexes, List previousPitchbendMs) { UndoClipID = undoClipID; PCBIndexes = pcbIndexes; PreviousPitchbendMs = previousPitchbendMs; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < PCBIndexes.Count; idx++) { undoClip.ClipPitchChangeEvents[PCBIndexes[idx]].ClipRelTimeMs = PreviousPitchbendMs[idx]; undoClip.ClipPitchChangeEvents[PCBIndexes[idx]].UpdateMargin(); } undoClip.SortMidiEventSubGroup(typeof(QDPitchChange)); } } public class MidiModulationMoveUndo : UndoClass { public string UndoMainValue { get { return "Restore mod locations: " + PreviousModulationMs.Count.ToString(); } } string UndoClipID; List PreviousModulationMs; List ModIndexes; public MidiModulationMoveUndo(string undoClipID, List modIndexes, List previousModulationMs) { UndoClipID = undoClipID; ModIndexes = modIndexes; PreviousModulationMs = previousModulationMs; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idx = 0; idx < ModIndexes.Count; idx++) { undoClip.ClipModulationEvents[ModIndexes[idx]].ClipRelTimeMs = PreviousModulationMs[idx]; undoClip.ClipModulationEvents[ModIndexes[idx]].UpdateMargin(); } undoClip.SortMidiEventSubGroup(typeof(QDModulation)); } } public class MidiTransposeUndo : UndoClass { public string UndoMainValue { get { return "Global pitch change: " + RelativePitchChange.ToString(); } } string UndoClipID; int RelativePitchChange; public MidiTransposeUndo(string undoClipID, int relativePitchChange) { UndoClipID = undoClipID; RelativePitchChange = relativePitchChange; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); foreach (QDMidiNote mnote in undoClip.ClipMidiNotes) mnote.Note -= RelativePitchChange; undoClip.UpdateMidiImageSource(); } } //...Draws public class MidiPitchDrawAddUndo : UndoClass { public string UndoMainValue { get { return "Undo pitchbend draw add: " + AddedEventCount.ToString(); } } string UndoClipID; int AddedEventCount; int InsertIndex; List ErasedPitchChanges; public MidiPitchDrawAddUndo(string addedClipID, int addedEventCount, int insertIndex, List erasedPitchChanges) { UndoClipID = addedClipID; AddedEventCount = addedEventCount; InsertIndex = insertIndex; ErasedPitchChanges = erasedPitchChanges; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < AddedEventCount; idxno += 1) undoClip.ClipPitchChangeEvents.RemoveAt(InsertIndex); for (int idxno = 0; idxno < ErasedPitchChanges.Count; idxno += 1) undoClip.ClipPitchChangeEvents.Insert(InsertIndex + idxno, ErasedPitchChanges[idxno]); } } public class MidiModulationDrawAddUndo : UndoClass { public string UndoMainValue { get { return "Undo modulation draw add: " + AddedEventCount.ToString(); } } string UndoClipID; int AddedEventCount; int InsertIndex; List ErasedModulationChanges; public MidiModulationDrawAddUndo(string addedClipID, int addedEventCount, int insertIndex, List erasedModulationChanges) { UndoClipID = addedClipID; AddedEventCount = addedEventCount; InsertIndex = insertIndex; ErasedModulationChanges = erasedModulationChanges; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < AddedEventCount; idxno += 1) undoClip.ClipModulationEvents.RemoveAt(InsertIndex); for (int idxno = 0; idxno < ErasedModulationChanges.Count; idxno += 1) undoClip.ClipModulationEvents.Insert(InsertIndex + idxno, ErasedModulationChanges[idxno]); } } public class MidiPitchDrawChangeUndo : UndoClass { public string UndoMainValue { get { return "Undo pitchbend draw changes: " + PreviousPitchValues.Count.ToString(); } } string UndoClipID; int ChangeStartIndex; List PreviousPitchValues; public MidiPitchDrawChangeUndo(string undoClipID, int changeStartIndex, List previousPitchValues) { UndoClipID = undoClipID; ChangeStartIndex = changeStartIndex; PreviousPitchValues = previousPitchValues; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < PreviousPitchValues.Count; idxno += 1) undoClip.ClipPitchChangeEvents[ChangeStartIndex + idxno].PitchValue = PreviousPitchValues[idxno]; } } public class MidiModulationDrawChangeUndo : UndoClass { public string UndoMainValue { get { return "Undo modulation draw change: " + PreviousModulationValues.Count.ToString(); } } string UndoClipID; int ChangeStartIndex; List PreviousModulationValues; public MidiModulationDrawChangeUndo(string undoClipID, int changeStartIndex, List previousModulationValues) { UndoClipID = undoClipID; ChangeStartIndex = changeStartIndex; PreviousModulationValues = previousModulationValues; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < PreviousModulationValues.Count; idxno += 1) undoClip.ClipModulationEvents[ChangeStartIndex + idxno].ModValue = PreviousModulationValues[idxno]; } } public class MidiVelocityDrawChangeUndo : UndoClass { public string UndoMainValue { get { return "Undo velocity draw change: " + PreviousVelocityValues.Count.ToString(); } } string UndoClipID; int ChangeStartIndex; List PreviousVelocityValues; public MidiVelocityDrawChangeUndo(string undoClipID, int changeStartIndex, List previousVelocityValues) { UndoClipID = undoClipID; ChangeStartIndex = changeStartIndex; PreviousVelocityValues = previousVelocityValues; } public override void Undo() { Clip undoClip = GetClipFromID(UndoClipID); for (int idxno = 0; idxno < PreviousVelocityValues.Count; idxno += 1) undoClip.ClipMidiNotes[ChangeStartIndex + idxno].Velocity = PreviousVelocityValues[idxno]; } }