Skip to content

Commit

Permalink
added random node selector
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBatchelor committed Sep 9, 2021
1 parent 65f5da0 commit 85c7c34
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
22 changes: 19 additions & 3 deletions examples/metanode.lil
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ func sequence {} {
gest_begin 3 3
gest_target 0
gest_smallgliss
gest_inertia 0.3

gest_metanode 1 2
gest_metanode 1 3
gest_randnode
gest_target 7
gest_smallgliss
gest_mass -60

gest_polyramp 2
gest_target 2
gest_smallgliss
gest_mass 0
gest_target 4
gest_gliss
gest_polyramp 4
gest_target 4
gest_smallgliss
gest_mass 15
gest_target 7
gest_smallgliss
gest_monoramp 2
gest_target 9
gest_gliss

gest_target 14
gest_mediumgliss
gest_metabehavior 2
gest_randbehavior
gest_mediumgliss
gest_gliss

gest_end
gest_loopit
Expand All @@ -32,7 +48,7 @@ regset zz 1
regget 1
gestweight zz
mul zz 0.8
add zz 2
add zz 2.3

phasor zz 0
hold
Expand Down
40 changes: 40 additions & 0 deletions gest.org
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,29 @@ int gest_randbehavior(gest_d *g)
return 0;
}
#+END_SRC
** Randnode
The function =gest_randnode= configures the last
metanode to choose nodes randomly.

#+NAME: funcdefs
#+BEGIN_SRC c
int gest_randnode(gest_d *g);
#+END_SRC

#+NAME: funcs
#+BEGIN_SRC c
int gest_randnode(gest_d *g)
{
gest_metanode *mn;

if (g->mnpos <= 0) return 1;

mn = g->mnstack[g->mnpos - 1];

mn->parent->get = node_random;
return 0;
}
#+END_SRC
* Behavior Commands
Behaviors are the means by which one target gets to thep
next target.
Expand Down Expand Up @@ -3575,6 +3598,23 @@ static gest_node* node_seq(gest_d *g, gest_node *n)
return mn->nodes[mn->pos++];
}
#+END_SRC
*** Random Node Selector
#+NAME: static_funcdefs
#+BEGIN_SRC c
static gest_node* node_random(gest_d *g, gest_node *n);
#+END_SRC

#+NAME: funcs
#+BEGIN_SRC c
static gest_node* node_random(gest_d *g, gest_node *n)
{
gest_metanode *mn;

mn = n->meta;

return mn->nodes[gest_randi(g, mn->size)];
}
#+END_SRC
** Metaphrases
If you've been reading up to this point, you'll no
doubt know what to expect here. A =metaphrase=
Expand Down
24 changes: 24 additions & 0 deletions l_gest.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,29 @@ static lil_value_t l_gest_randbehavior(lil_t lil,
return NULL;
}

static lil_value_t l_gest_randnode(lil_t lil,
size_t argc,
lil_value_t *argv)
{
sk_core *core;
gest_d *g;
int rc;

core = lil_get_data(lil);
rc = sk_core_generic_pop(core, (void **)&g);
SKLIL_ERROR_CHECK(lil, rc, "couldn't get gest data.");

rc = gest_randnode(g);

if (rc) {
lil_set_error(lil, "Could not configure randnode.");
return NULL;
}

sk_core_generic_push(core, g);
return NULL;
}

void sklil_load_gest(lil_t lil)
{
lil_register(lil, "gest_new", gest_new);
Expand Down Expand Up @@ -568,4 +591,5 @@ void sklil_load_gest(lil_t lil)
lil_register(lil, "gest_metaphrase", l_gest_metaphrase);
lil_register(lil, "gest_randtarget", l_gest_randtarget);
lil_register(lil, "gest_randbehavior", l_gest_randbehavior);
lil_register(lil, "gest_randnode", l_gest_randnode);
}

0 comments on commit 85c7c34

Please sign in to comment.