commit 1ac686b28f2eda42a4823217c42cd94f39064fd2
parent f9d2c2518147fb87d22f87c7139ce24c0517a324
Author: fundamental <[email protected]>
Date: Sun, 29 Nov 2015 21:09:37 -0500
Middleware: Add Autosave
Add Autosave with:
- Fixed path (/tmp/autosave.xmz)
- Fixed interval (60 sec)
- No Disable
- No Queue For Discarded Events
Some work needs to be done for the above items, but this small
implementation should satisfy the basic requirements of an automatic
save.
Diffstat:
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/Misc/CMakeLists.txt b/src/Misc/CMakeLists.txt
@@ -14,6 +14,7 @@ set(zynaddsubfx_misc_SRCS
Misc/MiddleWare.cpp
Misc/PresetExtractor.cpp
Misc/Allocator.cpp
+ Misc/CallbackRepeater.cpp
)
diff --git a/src/Misc/CallbackRepeater.cpp b/src/Misc/CallbackRepeater.cpp
@@ -0,0 +1,13 @@
+#include "CallbackRepeater.h"
+CallbackRepeater::CallbackRepeater(int interval, cb_t cb_)
+ :last(time(0)), dt(interval), cb(cb_)
+{}
+
+void CallbackRepeater::tick(void)
+{
+ auto now = time(0);
+ if(now-last > dt) {
+ cb();
+ last = now;
+ }
+}
diff --git a/src/Misc/CallbackRepeater.h b/src/Misc/CallbackRepeater.h
@@ -0,0 +1,17 @@
+#include <functional>
+#include <ctime>
+
+struct CallbackRepeater
+{
+ typedef std::function<void(void)> cb_t ;
+
+ //Call interval in seconds and callback
+ CallbackRepeater(int interval, cb_t cb_);
+
+ //Time Check
+ void tick(void);
+
+ std::time_t last;
+ std::time_t dt;
+ cb_t cb;
+};
diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp
@@ -19,6 +19,7 @@
#include <map>
#include "Util.h"
+#include "CallbackRepeater.h"
#include "Master.h"
#include "Part.h"
#include "PresetExtractor.h"
@@ -589,14 +590,18 @@ public:
{
if(server)
while(lo_server_recv_noblock(server, 0));
+
while(bToU->hasNext()) {
const char *rtmsg = bToU->read();
bToUhandle(rtmsg);
}
+
while(auto *m = multi_thread_source.read()) {
handleMsg(m->memory);
multi_thread_source.free(m);
}
+
+ autoSave.tick();
}
@@ -672,6 +677,8 @@ public:
const SYNTH_T synth;
PresetsStore presetsstore;
+
+ CallbackRepeater autoSave;
};
/*****************************************************************************
@@ -1105,7 +1112,11 @@ static rtosc::Ports middlewareReplyPorts = {
MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, SYNTH_T synth_,
Config* config, int preferrred_port)
:parent(mw), config(config), ui(nullptr), synth(std::move(synth_)),
- presetsstore(*config)
+ presetsstore(*config), autoSave(60, [this]() {
+ auto master = this->master;
+ this->doReadOnlyOp([master](){
+ int res = master->saveXML("/tmp/autosave.xmz");
+ (void)res;});})
{
bToU = new rtosc::ThreadLink(4096*2,1024);
uToB = new rtosc::ThreadLink(4096*2,1024);