]> Nishi Git Mirror - gwion.git/commitdiff
:art: Few improv
authorfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 7 Mar 2019 13:04:56 +0000 (14:04 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 7 Mar 2019 13:04:56 +0000 (14:04 +0100)
include/arg.h
include/gwion.h
src/gwion.c
src/main.c

index fb74eb5a4fe6a5ee5b16a4de3b374a24b027df1f..c1cd4f46754be67b5251d2706c71bba7c5617277 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __ARG
 #define __ARG
-typedef struct {
+
+typedef struct Arg_ {
   int argc;
   char** argv;
   struct Vector_ add;
index cdacd0efbfe3b499813834c1de9c893874b5d4b4..4f5bc951f4400a5d65ddb0926b882cb05a0b5afb 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef __GWION
 #define __GWION
+
+struct Arg_;
 typedef struct Gwion_* Gwion;
 #include "plug.h"
 #include "driver.h"
 struct Gwion_ {
   PlugInfo* plug;
   DriverInfo* di;
-// arg
+//  struct Arg* arg;
 
 // sym
 // mem
@@ -14,9 +16,9 @@ struct Gwion_ {
   Emitter  emit;
   VM*      vm;
 };
-ANN void gwion_init(const Gwion, const Vector);
-ANN m_bool gwion_audio(const Gwion gwion, DriverInfo* di);
-ANN void gwion_run(const Gwion gwion, DriverInfo* di);
+ANN void gwion_init(const Gwion, struct Arg_*);
+ANN m_bool gwion_audio(const Gwion gwion);
+ANN void gwion_run(const Gwion gwion);
 ANN m_bool gwion_engine(const Gwion gwion);
-ANN void gwion_release(const Gwion gwion, DriverInfo* di);
+ANN void gwion_release(const Gwion gwion);
 #endif
index 79a920dbcd1af011646ea74196aa07dd063b8dbc..04084e30679917e96260bda0618fb58c760239ad 100644 (file)
@@ -7,8 +7,9 @@
 #include "instr.h"
 #include "emit.h"
 #include "engine.h"
-#include "gwion.h"
+#include "driver.h"
 #include "arg.h"
+#include "gwion.h"
 
 
 #ifdef VMBENCH
@@ -28,11 +29,13 @@ ANN static DriverInfo* new_driverinfo(void) {
   DriverInfo *di = (DriverInfo*)xcalloc(1, sizeof(DriverInfo));
   di->sr = 48000;
   di->in = di->out = 2;
+  di->func = dummy_driver;
+  di->run = vm_run;
   di->driver = (Driver*)xcalloc(1, sizeof(Driver));
   return di;
 }
 
-ANN void gwion_init(const Gwion gwion, const Vector args) {
+ANN void gwion_init(const Gwion gwion, Arg* arg) {
   gwion->vm = new_vm();
   gwion->emit = new_emitter();
   gwion->env = new_env();
@@ -40,13 +43,14 @@ ANN void gwion_init(const Gwion gwion, const Vector args) {
   gwion->vm->gwion = gwion;
   gwion->env->gwion = gwion;
   gwion->di = new_driverinfo();
-//  gwion->di = (Driver*)xcalloc(1, sizeof(DriverInfo));
-//  gwion->di->driver = (Driver*)xcalloc(1, sizeof(Driver));
   gwion->plug = (PlugInfo*)xmalloc(sizeof(PlugInfo));
-  plug_discover(gwion->plug, args);
+  arg_parse(arg, gwion->di);
+  plug_discover(gwion->plug, &arg->lib);
+  shreduler_set_loop(gwion->vm->shreduler, arg->loop);
 }
 
-ANN m_bool gwion_audio(const Gwion gwion, DriverInfo* di) {
+ANN m_bool gwion_audio(const Gwion gwion) {
+  DriverInfo *di = gwion->di;
   // get driver from string.
   if(di->arg) {
     for(m_uint i = 0; i < map_size(&gwion->plug->drv); ++i) {
@@ -58,7 +62,7 @@ ANN m_bool gwion_audio(const Gwion gwion, DriverInfo* di) {
       }
     }
   }
-  di->func(gwion->di->driver);
+  di->func(di->driver);
   VM* vm = gwion->vm;
   CHECK_BB(gwion->di->driver->ini(vm, di));
   vm->bbq = new_bbq(di);
@@ -69,19 +73,22 @@ ANN m_bool gwion_engine(const Gwion gwion) {
   return type_engine_init(gwion->vm, &gwion->plug->vec[GWPLUG_IMPORT]) > 0;
 }
 
-ANN void gwion_run(const Gwion gwion, DriverInfo* di) {
+ANN void gwion_run(const Gwion gwion) {
   VM* vm = gwion->vm;
   vm->is_running = 1;
   VMBENCH_INI
-  gwion->di->driver->run(vm, di);
+  gwion->di->driver->run(vm, gwion->di);
   VMBENCH_END
 }
 
-ANN void gwion_release(const Gwion gwion, DriverInfo* di) {
-  if(gwion->di->driver->del)
-    gwion->di->driver->del(gwion->vm, di);
-  xfree(gwion->di->driver);
-  xfree(gwion->di);
+ANN static void free_driverinfo(DriverInfo* di, VM* vm) {
+  if(di->driver->del)
+    di->driver->del(vm, di);
+  xfree(di->driver);
+  xfree(di);
+}
+ANN void gwion_release(const Gwion gwion) {
+  free_driverinfo(gwion->di, gwion->vm);
   plug_end(gwion);
   free_env(gwion->env);
   free_emitter(gwion->emit);
index ec57e85cd26a94f4fe9536781b328af867b28285..c5f554e2625b37b5867308e8a07efdca906103a0 100644 (file)
@@ -17,19 +17,16 @@ static void sig(int unused __attribute__((unused))) {
 
 int main(int argc, char** argv) {
   Arg arg = { .argc = argc, .argv=argv, .loop=-1 };
-  DriverInfo di = { .in=2, .out=2, .sr=48000, .func=dummy_driver, .run=vm_run };
-  arg_parse(&arg, &di);
-  gwion_init(&gwion, &arg.lib);
+  gwion_init(&gwion, &arg);
   signal(SIGINT, sig);
   signal(SIGTERM, sig);
-  if(gwion_audio(&gwion, &di) > 0 && gwion_engine(&gwion)) {
+  if(gwion_audio(&gwion) > 0 && gwion_engine(&gwion)) {
     plug_ini(&gwion, &arg.mod);
     for(m_uint i = 0; i < vector_size(&arg.add); i++)
       compile_filename(&gwion, (m_str)vector_at(&arg.add, i));
-    shreduler_set_loop(gwion.vm->shreduler, arg.loop);
-    gwion_run(&gwion, &di);
+    gwion_run(&gwion);
   }
-  gwion_release(&gwion, &di);
+  gwion_release(&gwion);
   arg_release(&arg);
   return 0;
 }