Browse Source

Add Module Save event.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
661fd3863d
4 changed files with 23 additions and 1 deletions
  1. +4
    -0
      include/engine/Engine.hpp
  2. +8
    -1
      include/engine/Module.hpp
  3. +9
    -0
      src/engine/Engine.cpp
  4. +2
    -0
      src/patch.cpp

+ 4
- 0
include/engine/Engine.hpp View File

@@ -142,6 +142,10 @@ struct Engine {
Write-locks.
*/
void moduleFromJson(Module* module, json_t* rootJ);
/** Dispatches Save event to all modules
Read-locks.
*/
void prepareSave();

// Cables
size_t getNumCables();


+ 8
- 1
include/engine/Module.hpp View File

@@ -321,7 +321,7 @@ struct Module {
}

struct RemoveEvent {};
/** Called before removing the module to the Engine.
/** Called before removing the module from the Engine.
*/
virtual void onRemove(const RemoveEvent& e) {
// Call deprecated event method by default
@@ -341,6 +341,7 @@ struct Module {
struct PortChangeEvent {
/** True if connecting, false if disconnecting. */
bool connecting;
/** Port::INPUT or Port::OUTPUT */
Port::Type type;
int portId;
};
@@ -380,6 +381,12 @@ struct Module {
*/
virtual void onRandomize(const RandomizeEvent& e);

struct SaveEvent {};
/** Called when the user saves the patch to a file.
If your module uses patch asset storage, make sure all files are saved in this event.
*/
virtual void onSave(const SaveEvent& e) {}

/** DEPRECATED. Override `onAdd(e)` instead. */
virtual void onAdd() {}
/** DEPRECATED. Override `onRemove(e)` instead. */


+ 9
- 0
src/engine/Engine.cpp View File

@@ -852,6 +852,15 @@ void Engine::moduleFromJson(Module* module, json_t* rootJ) {
}


void Engine::prepareSave() {
ReadLock lock(internal->mutex);
for (Module* module : internal->modules) {
Module::SaveEvent e;
module->onSave(e);
}
}


size_t Engine::getNumCables() {
return internal->cables.size();
}


+ 2
- 0
src/patch.cpp View File

@@ -88,6 +88,8 @@ static bool promptClear(std::string text) {

void PatchManager::save(std::string path) {
INFO("Saving patch %s", path.c_str());
// Dispatch SaveEvent to modules
APP->engine->prepareSave();
// Save patch.json
saveAutosave();
// Clean up autosave directory (e.g. removed modules)


Loading…
Cancel
Save