Commit 3adf18af authored by Joel K. Pettersson's avatar Joel K. Pettersson
Browse files

Move some logic from parseconv to scriptconv.

Extend the v0.3.6 redesign another logical step,
making parseconv handling of operator sublists
generic, moving specifics to scriptconv:
 * Use a linked mod_lists list in script data.
 * Loop through the parse data nest_lists
   in parseconv, simply making a matching mod_lists.
 * Move logic to handle updates per type to scriptconv.

Increase version to v0.3.6b.

Change log:
 * 2019-12-30: Set version to v0.3.6b.
       Extend the v0.3.6 redesign another logical step,
       making parseconv handling of operator sublists
       generic, moving specifics to scriptconv.
parent 877e7ab5
......@@ -212,6 +212,7 @@ static uint32_t OpAlloc_update(OpAlloc *restrict oa,
od->op_id = op_id;
OAState *oas = &oa->a[op_id];
oas->last_sod = od;
oas->flags = 0;
// oas->duration_ms = od->time_ms;
return op_id;
}
......@@ -265,7 +266,7 @@ static void ScriptConv_convert_opdata(ScriptConv *restrict o,
*
* \return true given non-copied items or list clearing
*/
static inline bool need_new_oplist(const SAU_NodeList *restrict op_list,
static bool need_new_oplist(const SAU_NodeList *restrict op_list,
const SAU_ProgramOpList *restrict prev_pol) {
if (!prev_pol)
return true;
......@@ -275,6 +276,69 @@ static inline bool need_new_oplist(const SAU_NodeList *restrict op_list,
((prev_pol->count > 0) && !op_list->refs);
}
/*
* Replace program operator list.
*
* \return true, or false on allocation failure
*/
static inline bool update_oplist(const SAU_ProgramOpList **restrict dstp,
const SAU_NodeList *restrict src,
SAU_MemPool *restrict mem) {
const SAU_ProgramOpList *dst = create_ProgramOpList(src, mem);
if (!dst)
return false;
*dstp = dst;
return true;
}
/*
* Update program operator lists for updated lists in script data.
*
* \return true, or false on allocation failure
*/
static bool ScriptConv_update_modlists(ScriptConv *restrict o,
SAU_ProgramOpData *restrict od) {
OAState *oas = &o->oa.a[od->id];
SAU_ScriptOpData *sod = oas->last_sod;
const SAU_NodeList *fmod_list = NULL;
const SAU_NodeList *pmod_list = NULL;
const SAU_NodeList *amod_list = NULL;
for (const SAU_NodeList *list = sod->mod_lists;
list != NULL; list = list->next) {
switch (list->type) {
case SAU_SDLT_FMODS:
fmod_list = list;
break;
case SAU_SDLT_PMODS:
pmod_list = list;
break;
case SAU_SDLT_AMODS:
amod_list = list;
break;
}
}
VAState *vas = &o->va.a[o->ev->vo_id];
if (need_new_oplist(fmod_list, oas->fmods)) {
if (!update_oplist(&oas->fmods, fmod_list, o->mem))
return false;
vas->flags |= VA_OPLIST;
od->fmods = oas->fmods;
}
if (need_new_oplist(pmod_list, oas->pmods)) {
if (!update_oplist(&oas->pmods, pmod_list, o->mem))
return false;
vas->flags |= VA_OPLIST;
od->pmods = oas->pmods;
}
if (need_new_oplist(amod_list, oas->amods)) {
if (!update_oplist(&oas->amods, amod_list, o->mem))
return false;
vas->flags |= VA_OPLIST;
od->amods = oas->amods;
}
return true;
}
/*
* Convert the flat script operator data list in two stages,
* adding all the operator data nodes, then filling in
......@@ -290,24 +354,7 @@ static void ScriptConv_convert_ops(ScriptConv *restrict o,
}
for (size_t i = 0; i < o->ev_op_data.count; ++i) {
SAU_ProgramOpData *od = &o->ev_op_data.a[i];
VAState *vas = &o->va.a[o->ev->vo_id];
OAState *oas = &o->oa.a[od->id];
SAU_ScriptOpData *sod = oas->last_sod;
if (need_new_oplist(sod->fmods, oas->fmods)) {
vas->flags |= VA_OPLIST;
oas->fmods = create_ProgramOpList(sod->fmods, o->mem);
od->fmods = oas->fmods;
}
if (need_new_oplist(sod->pmods, oas->pmods)) {
vas->flags |= VA_OPLIST;
oas->pmods = create_ProgramOpList(sod->pmods, o->mem);
od->pmods = oas->pmods;
}
if (need_new_oplist(sod->amods, oas->amods)) {
vas->flags |= VA_OPLIST;
oas->amods = create_ProgramOpList(sod->amods, o->mem);
od->amods = oas->amods;
}
ScriptConv_update_modlists(o, od);
}
}
......
......@@ -231,10 +231,7 @@ typedef struct ParseConv {
*/
typedef struct OpContext {
SAU_ParseOpData *newest; // most recent in time-ordered events
/* current node adjacents in operator linkage graph */
SAU_NodeList *fmod_list;
SAU_NodeList *pmod_list;
SAU_NodeList *amod_list;
SAU_NodeList *last_mod_list;
} OpContext;
/*
......@@ -270,34 +267,7 @@ static OpContext *ParseConv_update_opcontext(ParseConv *restrict o,
od_prev->op_flags |= SAU_SDOP_LATER_USED;
}
oc->newest = pod;
oc->fmod_list = NULL;
oc->pmod_list = NULL;
oc->amod_list = NULL;
for (SAU_NodeList *list = pod->nest_lists;
list != NULL; list = list->next) {
switch (list->type) {
case SAU_SDLT_FMODS:
oc->fmod_list = list;
break;
case SAU_SDLT_PMODS:
oc->pmod_list = list;
break;
case SAU_SDLT_AMODS:
oc->amod_list = list;
break;
default:
break;
}
}
if (oc->fmod_list != NULL &&
!create_oplist(&od->fmods, SAU_SDLT_FMODS, o->mem))
return NULL;
if (oc->pmod_list != NULL &&
!create_oplist(&od->pmods, SAU_SDLT_PMODS, o->mem))
return NULL;
if (oc->amod_list != NULL &&
!create_oplist(&od->amods, SAU_SDLT_AMODS, o->mem))
return NULL;
oc->last_mod_list = NULL;
pod->op_context = oc;
return oc;
}
......@@ -367,10 +337,10 @@ static bool ParseConv_add_ops(ParseConv *restrict o,
if (pod->op_flags & SAU_PDOP_IGNORED) continue;
goto ERROR;
}
OpContext *oc = pod->op_context;
if (!ParseConv_add_ops(o, oc->fmod_list)) goto ERROR;
if (!ParseConv_add_ops(o, oc->pmod_list)) goto ERROR;
if (!ParseConv_add_ops(o, oc->amod_list)) goto ERROR;
for (SAU_NodeList *list = pod->nest_lists;
list != NULL; list = list->next) {
if (!ParseConv_add_ops(o, list)) goto ERROR;
}
}
return true;
......@@ -398,12 +368,18 @@ static bool ParseConv_link_ops(ParseConv *restrict o,
goto ERROR;
}
OpContext *oc = pod->op_context;
if (!ParseConv_link_ops(o, od->fmods, oc->fmod_list))
goto ERROR;
if (!ParseConv_link_ops(o, od->pmods, oc->pmod_list))
goto ERROR;
if (!ParseConv_link_ops(o, od->amods, oc->amod_list))
goto ERROR;
for (SAU_NodeList *list = pod->nest_lists;
list != NULL; list = list->next) {
SAU_NodeList *next_list;
if (!create_oplist(&next_list, list->type, o->mem))
goto ERROR;
if (!od->mod_lists)
od->mod_lists = next_list;
else
oc->last_mod_list->next = next_list;
oc->last_mod_list = next_list;
if (!ParseConv_link_ops(o, next_list, list)) goto ERROR;
}
}
return true;
......
......@@ -15,7 +15,7 @@
#include "ptrlist.h"
#include "program.h"
#define SAU_VERSION_STR "saugns v0.3.6-beta2"
#define SAU_VERSION_STR "saugns v0.3.6b"
size_t SAU_build(const SAU_PtrList *restrict script_args, bool are_paths,
SAU_PtrList *restrict prg_objs);
......
......@@ -57,10 +57,8 @@ typedef struct SAU_ScriptOpData {
SAU_Ramp amp, amp2;
float phase;
struct SAU_ScriptOpData *op_prev; /* preceding for same op(s) */
/* node adjacents in operator linkage graph */
SAU_NodeList *fmods;
SAU_NodeList *pmods;
SAU_NodeList *amods;
/* new node adjacents in operator linkage graph */
SAU_NodeList *mod_lists;
} SAU_ScriptOpData;
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment