add onRandomize(), onReset(), onCreate(), and onDelete()pull/1639/head
@@ -47,6 +47,8 @@ struct ModuleWidget : OpaqueWidget { | |||||
virtual json_t *toJson(); | virtual json_t *toJson(); | ||||
virtual void fromJson(json_t *rootJ); | virtual void fromJson(json_t *rootJ); | ||||
virtual void create(); | |||||
virtual void _delete(); | |||||
/** Disconnects cables from all ports | /** Disconnects cables from all ports | ||||
Called when the user clicks Disconnect Cables in the context menu. | Called when the user clicks Disconnect Cables in the context menu. | ||||
*/ | */ | ||||
@@ -65,11 +65,14 @@ struct Module { | |||||
virtual void step() {} | virtual void step() {} | ||||
virtual void onSampleRateChange() {} | virtual void onSampleRateChange() {} | ||||
/** Override these to implement spacial behavior when user clicks Initialize and Randomize */ | |||||
virtual void reset() {} | |||||
virtual void randomize() {} | |||||
/** Deprecated */ | |||||
virtual void initialize() final {} | |||||
/** Called when module is created by the Add Module popup, cloning, or when loading a patch or autosave */ | |||||
virtual void onCreate() {} | |||||
/** Called when user explicitly deletes the module, not when Rack is closed or a new patch is loaded */ | |||||
virtual void onDelete() {} | |||||
/** Called when user clicks Initialize in the module context menu */ | |||||
virtual void onReset() {} | |||||
/** Called when user clicks Randomize in the module context menu */ | |||||
virtual void onRandomize() {} | |||||
/** Override these to store extra internal data in the "data" property */ | /** Override these to store extra internal data in the "data" property */ | ||||
virtual json_t *toJson() { return NULL; } | virtual json_t *toJson() { return NULL; } | ||||
@@ -121,12 +121,24 @@ void ModuleWidget::disconnect() { | |||||
} | } | ||||
} | } | ||||
void ModuleWidget::create() { | |||||
if (module) { | |||||
module->onCreate(); | |||||
} | |||||
} | |||||
void ModuleWidget::_delete() { | |||||
if (module) { | |||||
module->onDelete(); | |||||
} | |||||
} | |||||
void ModuleWidget::reset() { | void ModuleWidget::reset() { | ||||
for (ParamWidget *param : params) { | for (ParamWidget *param : params) { | ||||
param->setValue(param->defaultValue); | param->setValue(param->defaultValue); | ||||
} | } | ||||
if (module) { | if (module) { | ||||
module->reset(); | |||||
module->onReset(); | |||||
} | } | ||||
} | } | ||||
@@ -135,7 +147,7 @@ void ModuleWidget::randomize() { | |||||
param->randomize(); | param->randomize(); | ||||
} | } | ||||
if (module) { | if (module) { | ||||
module->randomize(); | |||||
module->onRandomize(); | |||||
} | } | ||||
} | } | ||||
@@ -191,7 +203,7 @@ void ModuleWidget::onMouseMove(EventMouseMove &e) { | |||||
gRackWidget->deleteModule(this); | gRackWidget->deleteModule(this); | ||||
this->finalizeEvents(); | this->finalizeEvents(); | ||||
delete this; | delete this; | ||||
// Kinda sketchy because events will be passed further down the tree | |||||
e.consumed = true; | |||||
return; | return; | ||||
} | } | ||||
} | } | ||||
@@ -306,9 +306,11 @@ void RackWidget::fromJson(json_t *rootJ) { | |||||
void RackWidget::addModule(ModuleWidget *m) { | void RackWidget::addModule(ModuleWidget *m) { | ||||
moduleContainer->addChild(m); | moduleContainer->addChild(m); | ||||
m->create(); | |||||
} | } | ||||
void RackWidget::deleteModule(ModuleWidget *m) { | void RackWidget::deleteModule(ModuleWidget *m) { | ||||
m->_delete(); | |||||
moduleContainer->removeChild(m); | moduleContainer->removeChild(m); | ||||
} | } | ||||
@@ -128,7 +128,7 @@ struct AudioInterface : Module { | |||||
openStream(); | openStream(); | ||||
} | } | ||||
void reset() override { | |||||
void onReset() override { | |||||
closeStream(); | closeStream(); | ||||
} | } | ||||
}; | }; | ||||
@@ -81,7 +81,7 @@ struct MIDICCToCVInterface : MidiIO, Module { | |||||
} | } | ||||
} | } | ||||
void reset() override { | |||||
void onReset() override { | |||||
resetMidi(); | resetMidi(); | ||||
} | } | ||||
@@ -74,7 +74,7 @@ struct MIDIToCVInterface : MidiIO, Module { | |||||
baseFromJson(rootJ); | baseFromJson(rootJ); | ||||
} | } | ||||
void reset() override { | |||||
void onReset() override { | |||||
resetMidi(); | resetMidi(); | ||||
} | } | ||||
@@ -63,7 +63,7 @@ struct MIDITriggerToCVInterface : MidiIO, Module { | |||||
} | } | ||||
} | } | ||||
void reset() override { | |||||
void onReset() override { | |||||
resetMidi(); | resetMidi(); | ||||
} | } | ||||
}; | }; | ||||
@@ -72,7 +72,7 @@ struct QuadMIDIToCVInterface : MidiIO, Module { | |||||
baseFromJson(rootJ); | baseFromJson(rootJ); | ||||
} | } | ||||
void reset() override { | |||||
void onReset() override { | |||||
resetMidi(); | resetMidi(); | ||||
} | } | ||||