Skip to content

Commit

Permalink
knob: number fixes and include number parameters in properties
Browse files Browse the repository at this point in the history
Update note.c
  • Loading branch information
porres committed Nov 20, 2024
1 parent 2a4ff10 commit f069920
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 391 deletions.
115 changes: 62 additions & 53 deletions Source/Control/knob.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ typedef struct _knob{
}t_knob;

// ---------------------- Helper functions ----------------------

static void knob_update_number(t_knob *x){
char nbuf[32];
sprintf(nbuf, "%#.5g", x->x_fval);
pdgui_vmess(0, "crs rs", glist_getcanvas(x->x_glist),
"itemconfigure", x->x_tag_number, "-text", nbuf);
}

// get value from motion/position
static t_float knob_getfval(t_knob *x){
double fval;
Expand Down Expand Up @@ -236,7 +244,7 @@ static void show_number(t_knob *x){ // show or hide number value
x->x_shownumber = 0;
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist)){
pdgui_vmess(0, "crs rs", x->x_cv, "itemconfigure", x->x_tag_number,
"-state", x->x_shownumber ? "normal" : "hidden");
"-state", x->x_shownumber ? "normal" : "hidden");
}
}

Expand Down Expand Up @@ -494,12 +502,7 @@ char *tags_center[] = {x->x_tag_center_circle, x->x_tag_obj};
knob_config_wcenter(x);
knob_config_number(x);
knob_update(x);
if(x->x_shownumber){
char buf[32]; // number buffer
sprintf(buf, "%#.5g", x->x_fval);
pdgui_vmess(0, "crs rs", glist_getcanvas(x->x_glist),
"itemconfigure", x->x_tag_number, "-text", buf);
}
knob_update_number(x);
show_number(x);
pdgui_vmess(0, "crs rs", x->x_cv, "itemconfigure", x->x_tag_sel,
"-outline", x->x_sel ? "blue" : "black"); // ??????
Expand Down Expand Up @@ -704,16 +707,7 @@ static void knob_set(t_knob *x, t_floatarg f){
if(x->x_pos != old){
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
knob_update(x);
}
}

static void knob_update_number(t_knob *x){
if(x->x_shownumber){
char buf[32];
sprintf(buf, "%#.5g", x->x_fval);
pdgui_vmess(0, "crs rs", glist_getcanvas(x->x_glist),
"itemconfigure", x->x_tag_number, "-text", buf);
post(buf, "number: %f / %g", x->x_fval, x->x_fval);
knob_update_number(x);
}
}

Expand All @@ -737,7 +731,6 @@ static void knob_bang(t_knob *x){
empty:
if(x->x_var != gensym("empty"))
value_setfloat(x->x_var, x->x_fval);
knob_update_number(x);
}

static void knob_float(t_knob *x, t_floatarg f){
Expand Down Expand Up @@ -1093,19 +1086,20 @@ static void knob_properties(t_gobj *z, t_glist *owner){
knob_get_var(x);
knob_get_rcv(x);
pdgui_stub_vnew(&x->x_obj.ob_pd, "knob_dialog",
owner, "ffffi ss ifi sss iiiiii fss iii",
owner, "ffffi ss ifi sss iiiiii fss iii iiii",
(float)(x->x_size / x->x_zoom), x->x_lower, x->x_upper, x->x_load, x->x_circular,
x->x_snd_raw->s_name, x->x_rcv_raw->s_name,
x->x_expmode, x->x_exp, x->x_jump,
x->x_bg->s_name, x->x_fg->s_name, x->x_mg->s_name,
x->x_discrete, x->x_steps, x->x_arc, x->x_range, x->x_offset, x->x_square,
x->x_start, x->x_param->s_name, x->x_var_raw->s_name,
x->x_savestate, x->x_loadbang, x->x_showticks);
x->x_savestate, x->x_loadbang, x->x_showticks,
x->x_fontsize, x->x_xpos, x->x_ypos, x->x_shownumber);
}

static void knob_apply(t_knob *x, t_symbol *s, int ac, t_atom *av){
x->x_ignore = s;
t_atom undo[25];
t_atom undo[29];
SETFLOAT(undo+0, x->x_size);
SETFLOAT(undo+1, x->x_lower);
SETFLOAT(undo+2, x->x_upper);
Expand All @@ -1131,7 +1125,11 @@ static void knob_apply(t_knob *x, t_symbol *s, int ac, t_atom *av){
SETFLOAT(undo+22, x->x_savestate);
SETFLOAT(undo+23, x->x_loadbang);
SETFLOAT(undo+24, x->x_showticks);
pd_undo_set_objectstate(x->x_glist, (t_pd*)x, gensym("dialog"), 25, undo, ac, av);
SETFLOAT(undo+25, x->x_fontsize);
SETFLOAT(undo+26, x->x_xpos);
SETFLOAT(undo+27, x->x_ypos);
SETFLOAT(undo+28, x->x_shownumber);
pd_undo_set_objectstate(x->x_glist, (t_pd*)x, gensym("dialog"), 29, undo, ac, av);
int size = (int)atom_getintarg(0, ac, av);
float min = atom_getfloatarg(1, ac, av);
float max = atom_getfloatarg(2, ac, av);
Expand All @@ -1157,6 +1155,10 @@ static void knob_apply(t_knob *x, t_symbol *s, int ac, t_atom *av){
x->x_savestate = atom_getintarg(22, ac, av);
x->x_loadbang = atom_getintarg(23, ac, av);
int ticks = atom_getintarg(24, ac, av);
int fontsize = atom_getintarg(25, ac, av);
int xpos = atom_getintarg(26, ac, av);
int ypos = atom_getintarg(27, ac, av);
int shownumber = atom_getintarg(28, ac, av);
knob_config_io(x); // for outline/square
if(expmode == 0){
knob_log(x, 0);
Expand Down Expand Up @@ -1193,6 +1195,9 @@ static void knob_apply(t_knob *x, t_symbol *s, int ac, t_atom *av){
}
knob_param(x, param);
knob_var(x, var);
knob_numbersize(x, fontsize);
knob_numberpos(x, xpos, ypos);
knob_number(x, shownumber);
}

// --------------- click + motion stuff --------------------
Expand Down Expand Up @@ -1224,43 +1229,16 @@ static void knob_arrow_motion(t_knob *x, t_floatarg dir){
x->x_pos = pos;
t_float fval = x->x_fval;
x->x_fval = knob_getfval(x);
if(fval != x->x_fval)
if(fval != x->x_fval){
knob_bang(x);
knob_update_number(x);
}
if(old != x->x_pos){
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
knob_update(x);
}
}

static void knob_list(t_knob *x, t_symbol *sym, int ac, t_atom *av){ // get key events
if(!ac){
knob_bang(x);
return;
}
if(ac == 1 && av->a_type == A_FLOAT){
knob_float(x, atom_getfloat(av));
return;
}
if(ac != 2 || x->x_edit)
return;
int flag = (int)atom_getfloat(av); // 1 for press, 0 for release
sym = atom_getsymbol(av+1); // get key name
if(sym == gensym("Meta_L")){
x->x_ctrl = flag;
return;
}
if(!x->x_clicked)
return;
int dir = 0;
if(flag && (sym == gensym("Up") || (sym == gensym("Right"))))
dir = 1;
else if(flag && (sym == gensym("Down") || (sym == gensym("Left"))))
dir = -1;
else
return;
knob_arrow_motion(x, dir);
}

static void knob_motion(t_knob *x, t_floatarg dx, t_floatarg dy){
if(dx == 0 && dy == 0)
return;
Expand All @@ -1286,14 +1264,45 @@ static void knob_motion(t_knob *x, t_floatarg dx, t_floatarg dy){
x->x_pos = pos > 1 ? 1 : pos < 0 ? 0 : pos; // should go up in non circular (to do)
t_float fval = x->x_fval;
x->x_fval = knob_getfval(x);
if(fval != x->x_fval)
if(fval != x->x_fval){
knob_bang(x);
knob_update_number(x);
}
if(old != x->x_pos){
if(glist_isvisible(x->x_glist) && gobj_shouldvis((t_gobj *)x, x->x_glist))
knob_update(x);
}
}

static void knob_list(t_knob *x, t_symbol *sym, int ac, t_atom *av){ // get key events
if(!ac){
knob_bang(x);
return;
}
if(ac == 1 && av->a_type == A_FLOAT){
knob_float(x, atom_getfloat(av));
return;
}
if(ac != 2 || x->x_edit)
return;
int flag = (int)atom_getfloat(av); // 1 for press, 0 for release
sym = atom_getsymbol(av+1); // get key name
if(sym == gensym("Meta_L")){
x->x_ctrl = flag;
return;
}
if(!x->x_clicked)
return;
int dir = 0;
if(flag && (sym == gensym("Up") || (sym == gensym("Right"))))
dir = 1;
else if(flag && (sym == gensym("Down") || (sym == gensym("Left"))))
dir = -1;
else
return;
knob_arrow_motion(x, dir);
}

static void knob_key(void *z, t_symbol *keysym, t_floatarg fkey){
t_knob *x = z;
x->x_ignore = keysym;
Expand Down
2 changes: 1 addition & 1 deletion Source/Control/note.c
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ void note_setup(void){
" label $id.justification.oll -text \"Outline:\"\n"
" tk_optionMenu $id.justification.just $var_just Left Center Right\n"
" label $id.justification.lbj -text \"Justification:\"\n"
" pack $id.justification.oll $id.justification.ol $id.justification.lbj $id.justification.just $id.justification.lbj $id.justification.just -side left\n"
" pack $id.justification.oll $id.justification.ol $id.justification.lbj $id.justification.just -side left\n"
"\n"
" frame $id.ul_bg\n"
" pack $id.ul_bg -side top\n"
Expand Down
Loading

0 comments on commit f069920

Please sign in to comment.