Skip to content

Commit

Permalink
blunt: add an enumerator for different loadbang types
Browse files Browse the repository at this point in the history
  • Loading branch information
myQwil committed Mar 13, 2022
1 parent 99a9ed3 commit 2c53a43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion abstractions/tick.pd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#X obj 160 130 inlet;
#X obj 220 130 inlet reset;
#X obj 120 100 loadbang;
#X obj 150 270 ad 2 10;
#X obj 150 270 ad 1 10;
#X obj 80 240 noise~;
#X obj 80 270 *~;
#X obj 80 330 outlet~;
Expand Down
1 change: 0 additions & 1 deletion abstractions/timers/work-tracker.pd
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
#X connect 9 2 8 0;
#X connect 11 0 1 0;
#X restore 290 280 pd kde-notify;
#X obj 280 370 hms;
#X connect 0 0 31 0;
#X connect 1 0 3 0;
#X connect 2 0 7 1;
Expand Down
21 changes: 14 additions & 7 deletions src/blunt.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,30 @@ static t_symbol *s_load;
static t_symbol *s_init;
static t_symbol *s_close;

typedef enum {
LB_NONE = -1
,LB_LOAD = 0 // "loadbang" actions - 0 for original meaning
,LB_INIT = 1 // loaded but not yet connected to parent patch
,LB_CLOSE = 2 // about to close
} t_lbtype;

typedef struct {
t_object obj;
int loadbang;
t_lbtype action;
} t_blunt;

static void blunt_loadbang(t_blunt *x ,t_float action) {
if (x->loadbang == action) pd_bang((t_pd*)x);
if (x->action == action) pd_bang((t_pd*)x);
}

static void blunt_init(t_blunt *x ,int *ac ,t_atom *av) {
x->loadbang = -1;
x->action = LB_NONE;
if (*ac && av[*ac-1].a_type == A_SYMBOL)
{ t_symbol *lb = av[*ac-1].a_w.w_symbol;
if (lb == s_load) x->loadbang = 0;
else if (lb == s_init) x->loadbang = 1;
else if (lb == s_close) x->loadbang = 2;
if (x->loadbang >= 0) *ac--; }
if (lb == s_load) x->action = LB_LOAD;
else if (lb == s_init) x->action = LB_INIT;
else if (lb == s_close) x->action = LB_CLOSE;
*ac -= (x->action != LB_NONE); }
}

/* -------------------------- blunt binops -------------------------- */
Expand Down

0 comments on commit 2c53a43

Please sign in to comment.