]> Nishi Git Mirror - gwion.git/commitdiff
:art: Some clean
authorfennecdjay <astor.jeremie@wanadoo.fr>
Wed, 13 Mar 2019 00:53:01 +0000 (01:53 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Wed, 13 Mar 2019 00:53:01 +0000 (01:53 +0100)
include/driver.h
include/sound.h [deleted file]
include/vm.h
src/arg.c
src/gwion.c
src/lib/prim.c
src/lib/ugen.c
src/lib/vec.c
src/vm/driver.c
src/vm/shreduler.c
src/vm/vm.c

index 2dc2956ccd38dc3808717fd5bb37797032d0a3c8..b336f6f8ca412a29d69fcb99b3d16977beb9933e 100644 (file)
@@ -5,10 +5,6 @@ typedef m_bool (*f_drvini)(struct VM_*, struct BBQ_*);
 typedef void   (*f_drvrun)(struct VM_*, struct BBQ_*);
 typedef void   (*f_drvdel)(struct VM_*, struct BBQ_*);
 
-#define DRVINI(a) ANN m_bool a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-#define DRVRUN(a) ANN void   a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-#define DRVDEL(a) ANN void   a(struct VM_ *vm __attribute__((unused)), struct BBQ_* di __attribute__((unused)))
-
 typedef struct DriverData_ {
   void* data;
   f_drvini ini;
@@ -16,6 +12,31 @@ typedef struct DriverData_ {
   f_drvdel del;
 } DriverData;
 
+struct SoundInfo_ {
+  uint32_t sr;
+  uint8_t in, out;
+  m_str arg;
+};
+
+typedef void (*f_bbqset)(struct DriverData_*);
+typedef void (*f_bbqrun)(const struct VM_*);
+typedef struct BBQ_ {
+  uint64_t pos;
+  m_float* in;
+  m_float* out;
+  volatile uint is_running;
+  struct SoundInfo_ *si;
+  f_bbqset func;
+  f_bbqrun run;
+  struct DriverData_* driver;
+} Driver;
+
+#define DRVINI(a) ANN m_bool a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+#define DRVRUN(a) ANN void   a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+#define DRVDEL(a) ANN void   a(struct VM_ *vm __attribute__((unused)), Driver* di __attribute__((unused)))
+
 ANN void dummy_driver(DriverData*);
-ANN void bbq_alloc(struct BBQ_*);
+ANN void driver_alloc(Driver*);
+ANN Driver* new_driver(void);
+ANN void free_driver(Driver*, struct VM_*);
 #endif
diff --git a/include/sound.h b/include/sound.h
deleted file mode 100644 (file)
index 5b4784a..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __SOUND
-#define __SOUND
-struct SoundInfo_ {
-  uint32_t sr;
-  uint8_t in, out;
-  m_str arg;
-};
-#endif
index 1e7c27159dc18744305e2b6da770613aa401090b..4ba888eef947bde0fc21b66182da6d2923d99aec 100644 (file)
@@ -14,21 +14,6 @@ struct VM_Code_ {
   HAS_OBJ
 };
 
-struct VM_;
-struct DriverData_;
-typedef void (*f_bbqset)(struct DriverData_*);
-typedef void (*f_bbqrun)(const struct VM_*);
-struct BBQ_ {
-  uint64_t pos;
-  m_float* in;
-  m_float* out;
-  volatile uint is_running;
-  struct SoundInfo_ *si;
-  f_bbqset func;
-  f_bbqrun run;
-  struct DriverData_* driver;
-};
-
 typedef struct Shreduler_* Shreduler;
 typedef struct Emitter_   * Emitter;
 typedef struct VM_ {
index a30226a0938a1c4cd22d1ab7913294a5a5d2ac15..44a1d174262728a15ad66643208973d6bfdefed0 100644 (file)
--- a/src/arg.c
+++ b/src/arg.c
@@ -4,7 +4,6 @@
 #include "vm.h"
 #include "driver.h"
 #include "arg.h"
-#include "sound.h"
 #define GWIONRC ".gwionrc"
 
 ANN static inline void config_end(const Vector config) {
index e9d8a2d2cdd71db0a396dabd7c038c4ae89bc2c5..d60af87621d7e686802f9ff954739bb70a7bfba4 100644 (file)
@@ -11,7 +11,6 @@
 #include "arg.h"
 #include "gwion.h"
 #include "compile.h"
-#include "sound.h"
 
 #ifdef VMBENCH
 #include <time.h>
 #define VMBENCH_END
 #endif
 
-ANN static struct BBQ_ * new_driverinfo(void) {
-  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 m_bool gwion_audio(const Gwion gwion) {
-  struct BBQ_ *di = gwion->vm->bbq;
-  // get driver from string.
+  Driver* di = gwion->vm->bbq;
   if(di->si->arg) {
     for(m_uint i = 0; i < map_size(&gwion->plug->drv); ++i) {
       const m_str name = (m_str)VKEY(&gwion->plug->drv, i);
@@ -49,9 +38,8 @@ ANN m_bool gwion_audio(const Gwion gwion) {
     }
   }
   di->func(di->driver);
-  VM* vm = gwion->vm;
-  CHECK_BB(di->driver->ini(vm, di));
-  bbq_alloc(di);
+  CHECK_BB(di->driver->ini(gwion->vm, di));
+  driver_alloc(di);
   return GW_OK;
 }
 
@@ -71,7 +59,6 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) {
   gwion->emit->env = gwion->env;
   gwion->vm->gwion = gwion;
   gwion->env->gwion = gwion;
-  gwion->vm->bbq = new_driverinfo();
   gwion->vm->bbq->si = mp_alloc(SoundInfo);
   gwion->vm->bbq->si->in = gwion->vm->bbq->si->out = 2;
   gwion->vm->bbq->si->sr = 48000;
@@ -94,14 +81,6 @@ ANN void gwion_run(const Gwion gwion) {
   VMBENCH_END
 }
 
-ANN /* static */ void free_driverinfo(struct BBQ_* bbq, VM* vm) {
-  mp_free(SoundInfo, bbq->si);
-  if(bbq->driver->del)
-    bbq->driver->del(vm, bbq);
-  mp_free(DriverData, bbq->driver);
-  mp_free(BBQ, bbq);
-}
-
 ANN void gwion_end(const Gwion gwion) {
   free_env(gwion->env);
   free_emitter(gwion->emit);
index fc44fa450b3e4dcdcd8467bcf90fd3d91102f42f..15f1764c915a4c99fc18a1d684f001bb34b253c9 100644 (file)
@@ -9,7 +9,7 @@
 #include "import.h"
 #include "emit.h"
 #include "operator.h"
-#include "sound.h"
+#include "driver.h"
 
 #define CHECK_OP(op, check, func) _CHECK_OP(op, check, int_##func)
 
index 3e9a2eb82ee497541dfbb4b0191c85f0c39e972f..43be23a6484b670c5836af883bb324049e0892ba 100644 (file)
@@ -9,7 +9,7 @@
 #include "object.h"
 #include "import.h"
 #include "ugen.h"
-#include "sound.h"
+#include "driver.h"
 
 ANN static inline void ugop_add   (const UGen u, const m_float f) { u->in += f; }
 ANN static inline void ugop_sub  (const UGen u, const m_float f) { u->in -= f; }
index 3f0e8ef49767237bad1a18aceb4e1eeb832cec40..00c9d747ed763288e959713c8bafe7045b7550c8 100644 (file)
@@ -7,7 +7,7 @@
 #include "instr.h"
 #include "object.h"
 #include "import.h"
-#include "sound.h"
+#include "driver.h"
 
 INSTR(VecCpy) {
   POP_REG(shred, instr->m_val2);
index d73e6f74ec0f8d327d72f73d296b56ebec6b0781..e025b7cb4eb09732f52c757df9503c76f0198cf8 100644 (file)
@@ -8,11 +8,31 @@
 #include "oo.h"
 #include "vm.h"
 #include "driver.h"
-#include "sound.h"
 
-ANN void bbq_alloc(struct BBQ_ *bbq) {
-  bbq->out = (m_float*)xcalloc(bbq->si->out, SZ_FLOAT);
-  bbq->in  = (m_float*)xcalloc(bbq->si->in, SZ_FLOAT);
+ANN Driver* new_driver(void) {
+  Driver* di = (Driver*)mp_alloc(BBQ);
+  di->func = dummy_driver;
+  di->run = vm_run;
+  di->driver = (DriverData*)mp_alloc(DriverData);
+  di->is_running = 1;
+  return di;
+}
+
+ANN void free_driver(Driver *d, VM *vm) {
+  if(d->in)
+    xfree(d->in);
+  if(d->out)
+    xfree(d->out);
+  mp_free(SoundInfo, d->si);
+  if(d->driver->del)
+    d->driver->del(vm, d);
+  mp_free(DriverData, d->driver);
+  mp_free(BBQ, d);
+}
+
+ANN void driver_alloc(Driver *d) {
+  d->out = (m_float*)xcalloc(d->si->out, SZ_FLOAT);
+  d->in  = (m_float*)xcalloc(d->si->in, SZ_FLOAT);
 }
 
 static DRVRUN(dummy_run) {
@@ -26,7 +46,7 @@ static DRVINI(dummy_ini) {
   return GW_OK;
 }
 
-void dummy_driver(DriverData* d) {
-  d->ini = dummy_ini;
-  d->run = dummy_run;
+void dummy_driver(DriverData* dd) {
+  dd->ini = dummy_ini;
+  dd->run = dummy_run;
 }
index 865f84577e4bd872ab8a0dd24702eeaf748ee534..025d7a5668a13905d6063cf56665bc2f10e46df4 100644 (file)
@@ -5,6 +5,7 @@
 #include "vm.h"
 #include "object.h"
 #include "shreduler_private.h"
+#include "driver.h"
 
 ANN void shreduler_set_loop(const Shreduler s, const m_bool loop) {
   s->loop = loop < 0 ? 0 : 1;
index 0aeb113ca84f0bdad64255aa680fac9ea5234b03..3dc1c68583e2f55918c3f4ce7b4b2bb17fad2240 100644 (file)
@@ -54,6 +54,7 @@ VM* new_vm(void) {
   vm->shreduler->vm = vm;
   vector_init(&vm->shreduler->shreds);
   vector_init(&vm->ugen);
+  vm->bbq = new_driver();
   gw_seed(vm->rand, (uint64_t)time(NULL));
   return vm;
 }
@@ -71,14 +72,8 @@ void vm_remove(const VM* vm, const m_uint index) {
 ANN void free_vm(VM* vm) {
   vector_release(&vm->shreduler->shreds);
   vector_release(&vm->ugen);
-  struct BBQ_* bbq = vm->bbq;
-  if(vm->bbq) {
-    if(vm->bbq->in)
-      xfree(vm->bbq->in);
-    if(vm->bbq->out)
-      xfree(vm->bbq->out);
-    free_driverinfo(vm->bbq, vm);
-  }
+  if(vm->bbq)
+    free_driver(vm->bbq, vm);
   xfree(vm->shreduler);
   free(vm);
 }