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 } 180 public class AddSampleFile : UndoableEvent { 181 ModuleConfig mcfg; 182 string modID; 183 int sampleID; 184 string path; 185 Tag backup; 186 public this (ModuleConfig mcfg, string modID, int sampleID, string path) { 187 this.mcfg = mcfg; 188 this.modID = modID; 189 this.sampleID = sampleID; 190 this.path = path; 191 } 192 public void redo() { 193 if (backup is null) { 194 mcfg.addWaveFile(path, modID, sampleID, null, null); 195 } else { 196 mcfg.addWaveFromBackup(modID, backup); 197 } 198 } 199 public void undo() { 200 backup = mcfg.removeWave(modID, sampleID); 201 } 202 } 203 public class AddSampleSlice : UndoableEvent { 204 ModuleConfig mcfg; 205 string modID; 206 int sampleID; 207 int src; 208 int begin; 209 int len; 210 Tag backup; 211 public this (ModuleConfig mcfg, string modID, int sampleID, int src, int begin, int len) { 212 this.mcfg = mcfg; 213 this.modID = modID; 214 this.sampleID = sampleID; 215 this.src = src; 216 this.begin = begin; 217 this.len = len; 218 } 219 public void redo() { 220 if (backup is null) { 221 mcfg.addWaveSlice(modID, sampleID, src, begin, len, null); 222 } else { 223 mcfg.addWaveFromBackup(modID, backup); 224 } 225 } 226 public void undo() { 227 backup = mcfg.removeWave(modID, sampleID); 228 } 229 } 230 public class RemoveSample : UndoableEvent { 231 ModuleConfig mcfg; 232 string modID; 233 int sampleID; 234 Tag backup; 235 public this (ModuleConfig mcfg, string modID, int sampleID) { 236 this.mcfg = mcfg; 237 this.modID = modID; 238 this.sampleID = sampleID; 239 } 240 public void redo() { 241 backup = mcfg.removeWave(modID, sampleID); 242 } 243 public void undo() { 244 mcfg.addWaveFromBackup(modID, backup); 245 } 246 } 247 public class RenameSample : UndoableEvent { 248 ModuleConfig mcfg; 249 string modID; 250 int sampleID; 251 string newName; 252 string oldName; 253 public this (ModuleConfig mcfg, string modID, int sampleID, string newName) { 254 this.mcfg = mcfg; 255 this.modID = modID; 256 this.sampleID = sampleID; 257 this.newName = newName; 258 } 259 public void redo() { 260 oldName = mcfg.renameWave(modID, sampleID, newName); 261 } 262 public void undo() { 263 mcfg.renameWave(modID, sampleID, oldName); 264 } 265 }