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 void fromJson(json_t *rootJ);

virtual void create();
virtual void _delete();
/** Disconnects cables from all ports
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 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 */
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() {
for (ParamWidget *param : params) {
param->setValue(param->defaultValue);
}
if (module) {
module->reset();
module->onReset();
}
}

@@ -135,7 +147,7 @@ void ModuleWidget::randomize() {
param->randomize();
}
if (module) {
module->randomize();
module->onRandomize();
}
}

@@ -191,7 +203,7 @@ void ModuleWidget::onMouseMove(EventMouseMove &e) {
gRackWidget->deleteModule(this);
this->finalizeEvents();
delete this;
// Kinda sketchy because events will be passed further down the tree
e.consumed = true;
return;
}
}


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

@@ -306,9 +306,11 @@ void RackWidget::fromJson(json_t *rootJ) {

void RackWidget::addModule(ModuleWidget *m) {
moduleContainer->addChild(m);
m->create();
}

void RackWidget::deleteModule(ModuleWidget *m) {
m->_delete();
moduleContainer->removeChild(m);
}



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

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

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


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

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

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



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

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

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



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

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

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


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

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

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



Loading…
Cancel
Save