This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spigot.c
95 lines (76 loc) · 2.09 KB
/
spigot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdlib.h>
#include <soundpipe.h>
#include <sporth.h>
#include "spigot.h"
static void null_fun(void *ud)
{
}
static void null_drawfun(spigot_graphics *gfx, void *ud)
{
}
static void null_keyfun(spigot_graphics *gfx, void *ud,
int a, int b, int c, int d)
{
}
static void null_constant(void *ud, SPFLOAT val)
{
}
void spigot_state_init(spigot_state *state)
{
state->up = null_fun;
state->down = null_fun;
state->left = null_fun;
state->right = null_fun;
state->toggle = null_fun;
state->reset = null_fun;
state->free = null_fun;
state->step = null_fun;
state->init = null_fun;
state->compute = null_constant;
state->key = null_keyfun;
state->constant = null_constant;
state->draw = null_drawfun;
state->gfx_init= null_drawfun;
state->type = SPIGOT_NONE;
}
int sporth_spigot_wrapper(plumber_data *pd, sporth_stack *stack, void **ud)
{
SPFLOAT in;
spigot_state *state;
switch(pd->mode) {
case PLUMBER_CREATE:
if(sporth_check_args(stack, "f") != SPORTH_OK) {
fprintf(stderr,"Not enough arguments for spigot wrapper\n");
stack->error++;
return PLUMBER_NOTOK;
}
sporth_stack_pop_float(stack);
break;
case PLUMBER_INIT:
state = *ud;
sporth_stack_pop_float(stack);
state->init(state->ud);
break;
case PLUMBER_COMPUTE:
state = *ud;
in = sporth_stack_pop_float(stack);
if(in != 0) {
state->step(state->ud);
}
state->compute(state->ud, in);
break;
case PLUMBER_DESTROY:
state = *ud;
if(runt_is_alive(state->vm) == RUNT_OK) {
state->free(state->ud);
}
break;
}
return PLUMBER_OK;
}
void spigot_add_ugen(plumber_data *pd, const char *name, spigot_state *state)
{
plumber_ftmap_delete(pd, 0);
plumber_ftmap_add_function(pd, "spigot", sporth_spigot_wrapper, state);
plumber_ftmap_delete(pd, 1);
}