]> Nishi Git Mirror - gwion.git/commitdiff
:art: More Work
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 12 Mar 2019 21:53:07 +0000 (22:53 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 12 Mar 2019 21:53:07 +0000 (22:53 +0100)
include/gwion.h
include/plug.h
src/arg.c
src/gwion.c
src/main.c
src/plug.c
src/vm/vm.c

index da15398620d07db88a8a152b19e987463b7397f9..11ae35a17921167b234e58b36f15b2633c2d8ab3 100644 (file)
@@ -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
index 6a0029f9f84749a4fbf4a30c346cdd2f20fe2d8a..9b38280e844cc84c9f86aa038fc78bf711e0b1fa 100644 (file)
@@ -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
index 5ffc21c36f9356fa35a578d3904f1ca88175c0b4..d3aea336db64df4669ba909ac0cba8174c8a2ebf 100644 (file)
--- 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[] =
index cf56ce38819b8c4cdc01d4a8b3e966e8d8dd4561..e9d8a2d2cdd71db0a396dabd7c038c4ae89bc2c5 100644 (file)
 #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();
 }
index 3f2bed072a3c20ee42c5073c6d6de526f000f204..c042598d703b015756886b44b8ef54f147f54d23 100644 (file)
@@ -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;
index 3a7ac9bb99aefb444451240bb309ff8e0079accf..1f0b9184970b6b9d95403daa3d85fe5f9c547e37 100644 (file)
@@ -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);
index 068586dec8df2a13c747c8aac10f4512286bec1c..0aeb113ca84f0bdad64255aa680fac9ea5234b03 100644 (file)
@@ -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);