#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
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
#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
}
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[] =
#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.
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();
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;
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
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();
}
#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;
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_ {
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);
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)
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) {
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);
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);