1 module test1.editorevents; 2 3 import pixelperfectengine.concrete.eventchainsystem; 4 import pixelperfectengine.audio.base.modulebase; 5 import pixelperfectengine.audio.base.config; 6 import sdlang : Tag, Value; 7 import collections.commons : defaultHash; 8 /** 9 * Adds a module to the module configuration. 10 */ 11 public class AddModuleEvent : UndoableEvent { 12 Tag backup; 13 ModuleConfig mcfg; 14 string type; 15 string name; 16 public this(ModuleConfig mcfg, string type, string name) { 17 this.mcfg = mcfg; 18 this.type = type; 19 this.name = name; 20 } 21 22 public void redo() { 23 if (backup) { 24 mcfg.addModule(backup); 25 } else { 26 mcfg.addModule(type, name); 27 } 28 } 29 30 public void undo() { 31 backup = mcfg.removeModule(name); 32 } 33 } 34 public class RenameModuleEvent : UndoableEvent { 35 ModuleConfig mcfg; 36 string oldName; 37 string newName; 38 public this(ModuleConfig mcfg, string oldName, string newName) { 39 this.mcfg = mcfg; 40 this.oldName = oldName; 41 this.newName = newName; 42 } 43 44 public void redo() { 45 mcfg.renameModule(oldName, newName); 46 } 47 48 public void undo() { 49 mcfg.renameModule(newName, oldName); 50 } 51 } 52 /** 53 * Deletes a module from the audio configuration while holding a backup of it. 54 */ 55 public class DeleteModuleEvent : UndoableEvent { 56 Tag backup; 57 ModuleConfig mcfg; 58 string name; 59 public this(ModuleConfig mcfg, string name) { 60 this.mcfg = mcfg; 61 this.name = name; 62 } 63 public void redo() { 64 backup = mcfg.removeModule(name); 65 } 66 public void undo() { 67 mcfg.addModule(backup); 68 } 69 } 70 /** 71 * Edits or adds a preset parameter to the audio configuration, also edits the one in the module. 72 */ 73 public class EditPresetParameterEvent : UndoableEvent { 74 ModuleConfig mcfg; 75 Value oldVal, newVal; 76 Value paramID; 77 string modID; 78 int presetID; 79 string presetName; 80 /* AudioModule mod; */ 81 public this(VT, PT)(ModuleConfig mcfg, VT newVal, PT paramID, string modID, int presetID, string presetName, 82 /* AudioModule mod */) { 83 this.mcfg = mcfg; 84 this.newVal = Value(newVal); 85 this.paramID = Value(paramID); 86 this.modID = modID; 87 this.presetID = presetID; 88 this.presetName = presetName; 89 /* this.mod = mod; */ 90 /* if (mod !is null) { 91 if (newVal.peek!int) { 92 oldVal = Value(mod.readParam_int(presetID, _paramID)); 93 } else if (newVal.peek!long) { 94 oldVal = Value(mod.readParam_long(presetID, _paramID)); 95 } else if (newVal.peek!double) { 96 oldVal = Value(mod.readParam_double(presetID, _paramID)); 97 } else { 98 oldVal = Value(mod.readParam_string(presetID, _paramID)); 99 } 100 } */ 101 } 102 103 public void redo() { 104 mcfg.editPresetParameter(modID, presetID, paramID, newVal, oldVal, presetName); 105 /* if (mod !is null) { 106 uint _paramID; 107 if (paramID.peek!string) { 108 _paramID = defaultHash(paramID.get!string); 109 } else { 110 _paramID = cast(uint)paramID.get!long; 111 } 112 if (newVal.peek!int) { 113 mod.writeParam_int(presetID, _paramID, newVal.get!int); 114 } else if (newVal.peek!long) { 115 mod.writeParam_long(presetID, _paramID, newVal.get!long); 116 } else if (newVal.peek!double) { 117 mod.writeParam_double(presetID, _paramID, newVal.get!double); 118 } else { 119 mod.writeParam_string(presetID, _paramID, newVal.get!string); 120 } 121 } */ 122 } 123 124 public void undo() { 125 Value dummy; 126 mcfg.editPresetParameter(modID, presetID, paramID, oldVal, dummy, presetName); 127 /* if (mod !is null) { 128 uint _paramID; 129 if (paramID.peek!string) { 130 _paramID = defaultHash(paramID.get!string); 131 } else { 132 _paramID = cast(uint)paramID.get!long; 133 } 134 if (oldVal.peek!int) { 135 mod.writeParam_int(presetID, _paramID, oldVal.get!int); 136 } else if (oldVal.peek!long) { 137 mod.writeParam_long(presetID, _paramID, oldVal.get!long); 138 } else if (oldVal.peek!double) { 139 mod.writeParam_double(presetID, _paramID, oldVal.get!double); 140 } else { 141 mod.writeParam_string(presetID, _paramID, oldVal.get!string); 142 } 143 } */ 144 } 145 } 146 public class AddRoutingNodeEvent : UndoableEvent { 147 ModuleConfig mcfg; 148 string from, to; 149 public this (ModuleConfig mcfg, string from, string to) { 150 this.mcfg = mcfg; 151 this.from = from; 152 this.to = to; 153 } 154 public void redo() { 155 mcfg.addRouting(from, to); 156 } 157 158 public void undo() { 159 mcfg.removeRouting(from, to); 160 } 161 } 162 public class RemovePresetEvent : UndoableEvent { 163 ModuleConfig mcfg; 164 string modID; 165 int presetID; 166 Tag backup; 167 public this (ModuleConfig mcfg, string modID, int presetID) { 168 this.mcfg = mcfg; 169 this.modID = modID; 170 this.presetID = presetID; 171 } 172 public void redo() { 173 backup = mcfg.removePreset(modID, presetID); 174 } 175 176 public void undo() { 177 mcfg.addPreset(modID, backup); 178 } 179 }