From 1eb02097e4ebff7203ee4b39cd90b3259e9c756c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 10 Apr 2022 23:24:03 +0200 Subject: [PATCH] :art: Inital *virtual time* commit --- include/ugen.h | 1 + include/vm.h | 1 + src/gwion.c | 16 +++++++++++++++- src/lib/shred.c | 17 ++++++++++++++++- src/lib/ugen.c | 5 +++-- src/vm/vm.c | 2 +- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/ugen.h b/include/ugen.h index afa2adbd..8214f27e 100644 --- a/include/ugen.h +++ b/include/ugen.h @@ -46,4 +46,5 @@ ANN void ugen_gen(const struct Gwion_ *, const UGen, const f_tick, void *, const m_bool); ANN void ugen_connect(const UGen lhs, const UGen rhs); ANN void ugen_disconnect(const UGen lhs, const UGen rhs); +ANN void compute_mono(const UGen u); #endif diff --git a/include/vm.h b/include/vm.h index 869559ec..515e2b67 100644 --- a/include/vm.h +++ b/include/vm.h @@ -127,6 +127,7 @@ void vm_prepare(const VM *vm, m_bit*) __attribute__((hot)); ANN static inline void vm_run(const VM *vm) { vm_prepare(vm, NULL); } +ANN void vm_run_audio(const VM *vm); ANEW VM * new_vm(MemPool, const bool); ANN void vm_lock(VM const *); ANN void vm_unlock(VM const *); diff --git a/src/gwion.c b/src/gwion.c index b45ba76f..9fca9311 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -17,6 +17,7 @@ #include "object.h" // fork_clean #include "pass.h" // fork_clean #include "shreduler_private.h" +#include "ugen.h" ANN m_bool gwion_audio(const Gwion gwion) { Driver *const di = gwion->vm->bbq; @@ -35,9 +36,18 @@ ANN static VM_Shred gwion_cleaner(const Gwion gwion) { return shred; } +ANN void gwion_cpy_blackhole(const Gwion gwion) { + dummy_driver(gwion->vm->bbq->driver); + const M_Object o = new_M_UGen(gwion); + const UGen u = UGEN(o); + ugen_ini(gwion, u, 1, 1); + ugen_gen(gwion, u, compute_mono, o, 0); + vector_add(&gwion->vm->ugen, (vtype)u); +} + ANN VM *gwion_cpy(const VM *src) { const Gwion gwion = mp_calloc(src->gwion->mp, Gwion); - gwion->vm = new_vm(src->gwion->mp, false); + gwion->vm = new_vm(src->gwion->mp, true); gwion->vm->gwion = gwion; gwion->vm->bbq->si = soundinfo_cpy(src->gwion->mp, src->bbq->si); gwion->emit = src->gwion->emit; @@ -46,6 +56,7 @@ ANN VM *gwion_cpy(const VM *src) { gwion->st = src->gwion->st; gwion->mp = src->gwion->mp; gwion->type = src->gwion->type; + gwion_cpy_blackhole(gwion); return gwion->vm; } @@ -118,6 +129,9 @@ ANN void gwion_run(const Gwion gwion) { ANN static inline void free_gwion_cpy(const Gwion gwion, const VM_Shred shred) { gwion_end_child(shred, gwion); + const UGen u = (UGen)vector_front(&gwion->vm->ugen); + M_Object blackhole = u->module.gen.data; + release(blackhole, shred); free_vm(gwion->vm); free_gwiondata_cpy(gwion->mp, gwion->data); mp_free(gwion->mp, Gwion, gwion); diff --git a/src/lib/shred.c b/src/lib/shred.c index 441d421c..0d3f5100 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -13,6 +13,7 @@ #include "emit.h" #include "specialid.h" #include "gwi.h" +#include "ugen.h" static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev; @@ -245,6 +246,15 @@ static MFUN(shred_now) { MUTEX_UNLOCK(vm->shreduler->mutex); } +static MFUN(shred_blackhole) { + VM *vm = ME(o)->info->vm; + const UGen u = (UGen)vector_front(&vm->ugen); + M_Object blackhole = u->module.gen.data; + // adding ref for the moment + blackhole->ref++; + *(void**)RETURN = u->module.gen.data; +} + struct ThreadLauncher { MUTEX_TYPE mutex; THREAD_COND_TYPE cond; @@ -273,7 +283,7 @@ static ANN THREAD_FUNC(fork_run) { // THREAD_COND_CLEANUP(tl->cond); // MUTEX_CLEANUP(tl->mutex); while (fork_running(vm, me)) { - vm_run(vm); + vm_run_audio(vm); ++vm->bbq->pos; } gwion_end_child(ME(me), vm->gwion); @@ -395,6 +405,11 @@ GWION_IMPORT(shred) { GWI_BB(gwi_func_end(gwi, shred_unlock, ae_flag_none)) gwi_func_ini(gwi, "float", "get_now"); GWI_BB(gwi_func_end(gwi, shred_now, ae_flag_none)) + + gwi_func_ini(gwi, "UGen", "get_blackhole"); + GWI_BB(gwi_func_end(gwi, shred_blackhole, ae_flag_none)) + + GWI_BB(gwi_class_end(gwi)) SET_FLAG(t_shred, abstract | ae_flag_final); gwi->gwion->type[et_shred] = t_shred; diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 417e693a..4c256e4c 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -281,7 +281,7 @@ describe_connect_instr(Ugen, Connect, UGEN(rhs), ) describe_connect_instr( UGEN(rhs)->module.gen.trig, TRIG_EX) - static CTOR(ugen_ctor) { +static CTOR(ugen_ctor) { UGEN(o) = new_UGen(shred->info->mp); vector_add(&shred->info->vm->ugen, (vtype)UGEN(o)); } @@ -365,7 +365,8 @@ ANN static UGen add_ugen(const Gwi gwi, struct ugen_importer *imp) { const M_Object o = new_M_UGen(gwi->gwion); const UGen u = UGEN(o); ugen_ini(vm->gwion, u, imp->nchan, imp->nchan); - ugen_gen(vm->gwion, u, imp->tick, (void *)imp->vm, 0); +// ugen_gen(vm->gwion, u, imp->tick, (void *)imp->vm, 0); + ugen_gen(vm->gwion, u, imp->tick, o, 0); vector_add(&vm->ugen, (vtype)u); gwi_item_ini(gwi, "UGen", imp->name); gwi_item_end(gwi, ae_flag_const, obj, o); diff --git a/src/vm/vm.c b/src/vm/vm.c index 5ec758f9..deb2b8eb 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -1600,7 +1600,7 @@ ANN void next_bbq_pos(const VM *vm) { MUTEX_UNLOCK(vm->shreduler->mutex); } -static void vm_run_audio(const VM *vm) { +ANN void vm_run_audio(const VM *vm) { vm_run(vm); vm_ugen_init(vm); } -- 2.43.0