Browse Source

Remove Module::reset(), Module::initialize(), and Module::randomize(),

add onRandomize(), onReset(), onCreate(), and onDelete()
pull/1639/head
Andrew Belt 7 years ago
parent
commit
ea36ea1874
9 changed files with 32 additions and 13 deletions
  1. +2
    -0
      include/app.hpp
  2. +8
    -5
      include/engine.hpp
  3. +15
    -3
      src/app/ModuleWidget.cpp
  4. +2
    -0
      src/app/RackWidget.cpp
  5. +1
    -1
      src/core/AudioInterface.cpp
  6. +1
    -1
      src/core/MidiCCToCV.cpp
  7. +1
    -1
      src/core/MidiToCV.cpp
  8. +1
    -1
      src/core/MidiTriggerToCV.cpp
  9. +1
    -1
      src/core/QuadMidiToCV.cpp

+ 2
- 0
include/app.hpp View File

@@ -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.
*/ */


+ 8
- 5
include/engine.hpp View File

@@ -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; }


+ 15
- 3
src/app/ModuleWidget.cpp View File

@@ -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;
} }
} }


+ 2
- 0
src/app/RackWidget.cpp View File

@@ -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);
} }




+ 1
- 1
src/core/AudioInterface.cpp View File

@@ -128,7 +128,7 @@ struct AudioInterface : Module {
openStream(); openStream();
} }


void reset() override {
void onReset() override {
closeStream(); closeStream();
} }
}; };


+ 1
- 1
src/core/MidiCCToCV.cpp View File

@@ -81,7 +81,7 @@ struct MIDICCToCVInterface : MidiIO, Module {
} }
} }


void reset() override {
void onReset() override {
resetMidi(); resetMidi();
} }




+ 1
- 1
src/core/MidiToCV.cpp View File

@@ -74,7 +74,7 @@ struct MIDIToCVInterface : MidiIO, Module {
baseFromJson(rootJ); baseFromJson(rootJ);
} }


void reset() override {
void onReset() override {
resetMidi(); resetMidi();
} }




+ 1
- 1
src/core/MidiTriggerToCV.cpp View File

@@ -63,7 +63,7 @@ struct MIDITriggerToCVInterface : MidiIO, Module {
} }
} }


void reset() override {
void onReset() override {
resetMidi(); resetMidi();
} }
}; };


+ 1
- 1
src/core/QuadMidiToCV.cpp View File

@@ -72,7 +72,7 @@ struct QuadMIDIToCVInterface : MidiIO, Module {
baseFromJson(rootJ); baseFromJson(rootJ);
} }


void reset() override {
void onReset() override {
resetMidi(); resetMidi();
} }




Loading…
Cancel
Save