commit e34c08c8b66e1065b1bd440344ce106f7c4f8d2e
parent 821fd0bf5312f32889643ffbdfdf8deecafb19c7
Author: fundamental <[email protected]>
Date: Fri, 14 Feb 2014 14:49:11 -0500
Experimenting With ASync
- Loads are now done mostly with Async, this should make things more responsive
for instruments that have a lot of padsynth
Diffstat:
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp
@@ -22,6 +22,7 @@
#include "../Effects/EffectMgr.h"
#include <string>
+#include <future>
#include <atomic>
#include <err.h>
@@ -315,6 +316,7 @@ struct MiddleWareImpl
//dummy callback for starters
cb = [](void*, const char*){};
+ idle = 0;
master = new Master();
osc = genOscInterface(this);
@@ -412,14 +414,30 @@ struct MiddleWareImpl
void loadPart(int npart, const char *filename, Master *master, Fl_Osc_Interface *osc)
{
+ printf("loading part...\n");
+ auto alloc = std::async(std::launch::async,
+ [master,filename](){Part *p = new Part(&master->microtonal, master->fft);
+ if(p->loadXMLinstrument(filename))
+ fprintf(stderr, "FAILED TO LOAD PART!!\n");
+
+ p->applyparameters();
+ return p;});
//fprintf(stderr, "loading a part!!\n");
//Load the part
- Part *p = new Part(&master->microtonal, master->fft);
+ if(idle) {
+ while(alloc.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
+ printf("idle...\n");
+ idle();
+ }
+ } else
+ printf("no idle\n");
+ printf("part allocated...\n");
+ Part *p = alloc.get();//new Part(&master->microtonal, master->fft);
//fprintf(stderr, "Part[%d] is stored in '%s'\n", npart, filename);
- if(p->loadXMLinstrument(filename))
- fprintf(stderr, "FAILED TO LOAD PART!!\n");
+ //if(p->loadXMLinstrument(filename))
+ // fprintf(stderr, "FAILED TO LOAD PART!!\n");
- p->applyparameters();
+ //p->applyparameters();
//Update the resource locators
string base = "/part"+to_s(npart)+"/kit";
@@ -480,7 +498,7 @@ struct MiddleWareImpl
void bToUhandle(const char *rtmsg)
{
- //printf("return: got a '%s'\n", rtmsg);
+ printf("return: got a '%s'\n", rtmsg);
if(!strcmp(rtmsg, "/echo")
&& !strcmp(rtosc_argument_string(rtmsg),"ss")
&& !strcmp(rtosc_argument(rtmsg,0).s, "OSC_URL"))
@@ -686,6 +704,7 @@ struct MiddleWareImpl
//backend
Fl_Osc_Interface *osc;
+ void(*idle)(void);
cb_t cb;
void *ui;
};
@@ -910,3 +929,8 @@ void MiddleWare::setUiCallback(void(*cb)(void*,const char *),void *ui)
impl->ui = ui;
}
+void MiddleWare::setIdleCallback(void(*cb)(void))
+{
+ impl->idle = cb;
+}
+
diff --git a/src/Misc/MiddleWare.h b/src/Misc/MiddleWare.h
@@ -10,6 +10,7 @@ class MiddleWare
class Master *spawnMaster(void);
class Fl_Osc_Interface *spawnUiApi(void);
void setUiCallback(void(*cb)(void*,const char *),void *ui);
+ void setIdleCallback(void(*cb)(void));
void tick(void);
static void preparePadSynth(const char *, class PADnoteParameters *){};
diff --git a/src/main.cpp b/src/main.cpp
@@ -84,6 +84,8 @@ extern int main_thread;
//cleanup on signaled exit
void sigterm_exit(int /*sig*/)
{
+ if(Pexitprogram)
+ exit(1);
Pexitprogram = 1;
}
@@ -399,6 +401,7 @@ int main(int argc, char *argv[])
gui = GUI::createUi(middleware->spawnUiApi(), &Pexitprogram);
middleware->setUiCallback(GUI::raiseUi, gui);
+ middleware->setIdleCallback([](){GUI::tickUi(gui);});
if(!noui)
{