From: fennecdjay Date: Tue, 12 Mar 2019 21:53:07 +0000 (+0100) Subject: :art: More Work X-Git-Tag: nightly~2743 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=a5f12b1fa4651cfbdde18df00379f5c66f733251;p=gwion.git :art: More Work --- diff --git a/include/gwion.h b/include/gwion.h index da153986..11ae35a1 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -1,20 +1,19 @@ #ifndef __GWION #define __GWION -struct Arg_; typedef struct Gwion_* Gwion; #include "plug.h" #include "driver.h" +struct Arg_; struct Gwion_ { PlugInfo* plug; - struct Arg_* arg; // sym // mem Env env; Emitter emit; VM* vm; }; -ANN m_bool gwion_ini(const Gwion, int, char**); +ANN m_bool gwion_ini(const Gwion, struct Arg_*); ANN void gwion_run(const Gwion gwion); ANN void gwion_end(const Gwion gwion); #endif diff --git a/include/plug.h b/include/plug.h index 6a0029f9..9b38280e 100644 --- a/include/plug.h +++ b/include/plug.h @@ -8,12 +8,14 @@ enum plug_t { GWPLUG_LAST }; -typedef struct { +typedef struct PlugInfo_ { struct Vector_ vec[GWPLUG_LAST]; struct Map_ drv; } PlugInfo; -void plug_discover(PlugInfo*, Vector); -void plug_end(const Gwion gwion); + +ANN PlugInfo* new_plug(Vector); +ANN void plug_run(const Gwion gwion, const Vector); +ANN void free_plug(const Gwion gwion); #define GWIMPORT_NAME import #define GWMODSTR_NAME gwmodstr @@ -25,6 +27,5 @@ void plug_end(const Gwion gwion); #define GWMODEND(a) ANN void GWMODEND_NAME(const Gwion gwion, void* self) #define GWDRIVER(a) ANN void GWDRIVER_NAME(DriverData* d) -ANN void plug_ini(const Gwion gwion, const Vector); ANN Vector split_args(const m_str str); #endif diff --git a/src/arg.c b/src/arg.c index 5ffc21c3..d3aea336 100644 --- a/src/arg.c +++ b/src/arg.c @@ -20,16 +20,16 @@ ANN void arg_release(Arg* arg) { } static const struct option long_option[] = { - { "pludir", 0, NULL, 'p' }, - { "driver", 1, NULL, 'd' }, - { "sr", 1, NULL, 's' }, - { "in", 1, NULL, 'i' }, - { "out", 1, NULL, 'o' }, - { "loop", 1, NULL, 'l' }, - { "help", 0, NULL, 'h' }, - { "config", 0, NULL, 'c' }, - { "module", 0, NULL, 'm' }, - { NULL, 0, NULL, 0 } + { "plugdir", 0, NULL, 'p' }, + { "driver", 1, NULL, 'd' }, + { "sr", 1, NULL, 's' }, + { "in", 1, NULL, 'i' }, + { "out", 1, NULL, 'o' }, + { "loop", 1, NULL, 'l' }, + { "help", 0, NULL, 'h' }, + { "config", 0, NULL, 'c' }, + { "module", 0, NULL, 'm' }, + { NULL, 0, NULL, 0 } }; static const char usage[] = diff --git a/src/gwion.c b/src/gwion.c index cf56ce38..e9d8a2d2 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -27,21 +27,14 @@ #endif ANN static struct BBQ_ * new_driverinfo(void) { - struct BBQ_ * di = (struct BBQ_*)xcalloc(1, sizeof(struct BBQ_)); + struct BBQ_ * di = (struct BBQ_*)mp_alloc(BBQ); di->func = dummy_driver; di->run = vm_run; di->driver = (DriverData*)mp_alloc(DriverData); + di->is_running = 1; return di; } -ANN static Arg* new_arg(int argc, char** argv) { - Arg *arg = (Arg*)xcalloc(1, sizeof(Arg)); - arg->argc = argc; - arg->argv = argv; - arg->loop = -1; - return arg; -} - ANN m_bool gwion_audio(const Gwion gwion) { struct BBQ_ *di = gwion->vm->bbq; // get driver from string. @@ -66,11 +59,12 @@ ANN static inline m_bool gwion_engine(const Gwion gwion) { return type_engine_init(gwion->vm, &gwion->plug->vec[GWPLUG_IMPORT]) > 0; } -ANN static inline void gwion_compile(const Gwion gwion) { - for(m_uint i = 0; i < vector_size(&gwion->arg->add); i++) - compile_filename(gwion, (m_str)vector_at(&gwion->arg->add, i)); +ANN static inline void gwion_compile(const Gwion gwion, const Vector v) { + for(m_uint i = 0; i < vector_size(v); i++) + compile_filename(gwion, (m_str)vector_at(v, i)); } -ANN m_bool gwion_ini(const Gwion gwion, int argc, char** argv) { + +ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion->vm = new_vm(); gwion->emit = new_emitter(); gwion->env = new_env(); @@ -78,17 +72,16 @@ ANN m_bool gwion_ini(const Gwion gwion, int argc, char** argv) { gwion->vm->gwion = gwion; gwion->env->gwion = gwion; gwion->vm->bbq = new_driverinfo(); - gwion->arg = new_arg(argc, argv); - gwion->arg->si = mp_alloc(SoundInfo); - gwion->arg->si->in = gwion->arg->si->out = 2; - gwion->arg->si->sr = 48000; - gwion->plug = (PlugInfo*)xmalloc(sizeof(PlugInfo)); - arg_parse(gwion->arg); - gwion->vm->bbq->si = gwion->arg->si; - plug_discover(gwion->plug, &gwion->arg->lib); - shreduler_set_loop(gwion->vm->shreduler, gwion->arg->loop); + gwion->vm->bbq->si = mp_alloc(SoundInfo); + gwion->vm->bbq->si->in = gwion->vm->bbq->si->out = 2; + gwion->vm->bbq->si->sr = 48000; + arg->si = gwion->vm->bbq->si; + arg_parse(arg); + gwion->plug = new_plug(&arg->lib); + shreduler_set_loop(gwion->vm->shreduler, arg->loop); if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) { - gwion_compile(gwion); + gwion_compile(gwion, &arg->add); + plug_run(gwion, &arg->mod); return GW_OK; } return GW_ERROR; @@ -96,8 +89,6 @@ ANN m_bool gwion_ini(const Gwion gwion, int argc, char** argv) { ANN void gwion_run(const Gwion gwion) { VM* vm = gwion->vm; - vm->bbq->is_running = 1; - plug_ini(gwion, &gwion->arg->mod); VMBENCH_INI vm->bbq->driver->run(vm, vm->bbq); VMBENCH_END @@ -108,15 +99,13 @@ ANN /* static */ void free_driverinfo(struct BBQ_* bbq, VM* vm) { if(bbq->driver->del) bbq->driver->del(vm, bbq); mp_free(DriverData, bbq->driver); - xfree(bbq); + mp_free(BBQ, bbq); } + ANN void gwion_end(const Gwion gwion) { - arg_release(gwion->arg); - xfree(gwion->arg); free_env(gwion->env); free_emitter(gwion->emit); free_vm(gwion->vm); - plug_end(gwion); - xfree(gwion->plug); + free_plug(gwion); free_symbols(); } diff --git a/src/main.c b/src/main.c index 3f2bed07..c042598d 100644 --- a/src/main.c +++ b/src/main.c @@ -5,17 +5,20 @@ #include "vm.h" #include "env.h" #include "gwion.h" +#include "arg.h" static struct Gwion_ gwion; static void sig(int unused __attribute__((unused))) { gwion.vm->bbq->is_running = 0; } - int main(int argc, char** argv) { + Arg arg = { .argc=argc, .argv=argv, .loop=-1 }; signal(SIGINT, sig); signal(SIGTERM, sig); - if(gwion_ini(&gwion, argc, argv) > 0) + const m_bool ini = gwion_ini(&gwion, &arg); + arg_release(&arg); + if(ini > 0) gwion_run(&gwion); gwion_end(&gwion); return 0; diff --git a/src/plug.c b/src/plug.c index 3a7ac9bb..1f0b9184 100644 --- a/src/plug.c +++ b/src/plug.c @@ -20,7 +20,7 @@ static inline int so_filter(const struct dirent* dir) { typedef m_bool (*import)(Gwi); typedef m_str (*modstr)(void); typedef void* (*modini)(const Gwion, const Vector); -typedef void* (*modend)(const Gwion, void*); +typedef void* (*modrun)(const Gwion, void*); typedef void* (*modend)(const Gwion, void*); struct Plug_ { @@ -58,7 +58,8 @@ ANN static void plug_get(PlugInfo* p, const m_str c) { err_msg(0, "error in %s.", dlerror()); } -void plug_discover(PlugInfo* p, Vector list) { +ANN PlugInfo* new_plug(const Vector list) { + PlugInfo *p = (PlugInfo*)mp_alloc(PlugInfo); for(m_uint i = 0; i < GWPLUG_LAST; ++i) vector_init(&p->vec[i]); map_init(&p->drv); @@ -76,10 +77,12 @@ void plug_discover(PlugInfo* p, Vector list) { free(file); } } + return p; } -void plug_end(const Gwion gwion) { - struct Vector_ * const v = gwion->plug->vec; +void free_plug(const Gwion gwion) { + PlugInfo *p = gwion->plug; + struct Vector_ * const v = p->vec; for(m_uint i = 0; i < vector_size(&v[GWPLUG_MODULE]); ++i) { struct Plug_ *plug = (struct Plug_*)vector_at(&v[GWPLUG_MODULE], i); if(plug->end) @@ -90,7 +93,8 @@ void plug_end(const Gwion gwion) { dlclose((void*)vector_at(&v[GWPLUG_DL], i)); for(m_uint i = 0; i < GWPLUG_LAST; ++i) vector_release(&v[i]); - map_release(&gwion->plug->drv); + map_release(&p->drv); + mp_free(PlugInfo, p); } ANN Vector split_args(const m_str str) { @@ -116,7 +120,7 @@ ANN static Vector get_arg(const m_str name, const Vector v) { return NULL; } -void plug_ini(const Gwion gwion, const Vector args) { +void plug_run(const Gwion gwion, const Vector args) { const Vector v = &gwion->plug->vec[GWPLUG_MODULE]; for(m_uint i = 0; i < vector_size(v); ++i) { struct Plug_ *plug = (struct Plug_*)vector_at(v, i); diff --git a/src/vm/vm.c b/src/vm/vm.c index 068586de..0aeb113c 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -67,22 +67,17 @@ void vm_remove(const VM* vm, const m_uint index) { Except(sh, "MsgRemove"); } } -#include "sound.h" + ANN void free_vm(VM* vm) { vector_release(&vm->shreduler->shreds); vector_release(&vm->ugen); -struct BBQ_* bbq = vm->bbq; + struct BBQ_* bbq = vm->bbq; if(vm->bbq) { - mp_free(SoundInfo, bbq->si); - if(bbq->driver->del) - bbq->driver->del(vm, bbq); - mp_free(DriverData, bbq->driver); if(vm->bbq->in) xfree(vm->bbq->in); if(vm->bbq->out) xfree(vm->bbq->out); - xfree(bbq); -// free_driverinfo(vm->bbq, vm); + free_driverinfo(vm->bbq, vm); } xfree(vm->shreduler); free(vm);