Commit 063d78e4 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

refactored files

parent 333f6061
......@@ -18,7 +18,7 @@ void magicGlass_clearText(t_magicGlass *x);
void magicGlass_bind(t_magicGlass *x, t_object *obj, int outno)
{
//fprintf(stderr,"magicglass_bind %lx\n", (t_int)x);
//fprintf(stderr,"magicglass_bind %lx\n", (t_int)x);
if (x->x_connectedObj != obj)
{
if (x->x_connectedObj)
......@@ -30,15 +30,15 @@ void magicGlass_bind(t_magicGlass *x, t_object *obj, int outno)
}
x->x_connectedObj = obj;
x->x_connectedOutno = outno;
x->x_maxSize = 1;
magicGlass_clearText(x);
x->x_maxSize = 1;
magicGlass_clearText(x);
obj_connect(obj, outno, &x->x_obj, 0);
}
}
void magicGlass_unbind(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_unbind %lx\n", (t_int)x);
//fprintf(stderr,"magicglass_unbind %lx\n", (t_int)x);
if (x->x_connectedObj)
{
obj_disconnect(x->x_connectedObj,
......@@ -51,43 +51,53 @@ void magicGlass_unbind(t_magicGlass *x)
x->x_sampleCount = 0;
x->x_connectedObj = NULL;
x->x_connectedOutno = 0;
x->x_maxSize = 1;
x->x_maxSize = 1;
}
void magicGlass_updateText(t_magicGlass *x, int moved)
{
//fprintf(stderr,"magicglass_updateText\n");
//fprintf(stderr,"magicglass_updateText\n");
int bgSize;
x->x_display_font = sys_hostfontsize(glist_getfont(x->x_c));
x->x_display_font = sys_hostfontsize(glist_getfont(x->x_c));
if (x->x_visible)
{
if (!moved) {
char *color;
if (x->x_issignal || strcmp(x->x_old_string, x->x_string)) {
color = "$pd_colors(magic_glass_text)";
}
else {
color = "$pd_colors(magic_glass_flash)";
clock_delay(x->x_flashClock, MG_CLOCK_FLASH_DELAY);
}
sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s} -fill %s -font {{%s} -%d %s}\n",
x->x_c,
x->x_string,
color,
sys_font, x->x_display_font, sys_fontweight);
} else {
sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s}\n",
x->x_c,
x->x_string);
}
if (!moved)
{
char *color;
if (x->x_issignal || strcmp(x->x_old_string, x->x_string))
{
color = "$pd_colors(magic_glass_text)";
}
else
{
color = "$pd_colors(magic_glass_flash)";
clock_delay(x->x_flashClock, MG_CLOCK_FLASH_DELAY);
}
sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s} "
"-fill %s -font {{%s} -%d %s}\n",
x->x_c,
x->x_string,
color,
sys_font, x->x_display_font, sys_fontweight);
}
else
{
sys_vgui(".x%x.c itemconfigure magicGlassText -text {%s}\n",
x->x_c,
x->x_string);
}
if (strlen(x->x_string) > 0)
{
if (strlen(x->x_string) > x->x_maxSize) x->x_maxSize = strlen(x->x_string);
if (strlen(x->x_string) > x->x_maxSize)
x->x_maxSize = strlen(x->x_string);
}
bgSize = x->x_x + (sys_fontwidth(x->x_display_font) * x->x_maxSize) + 26;
//fprintf(stderr,"%d %d %d : %d %d\n", sys_fontheight(x->x_display_font), sys_fontwidth(x->x_display_font), x->x_maxSize, x->x_x, bgSize);
bgSize = x->x_x +
(sys_fontwidth(x->x_display_font) * x->x_maxSize) + 26;
//fprintf(stderr,"%d %d %d : %d %d\n",
// sys_fontheight(x->x_display_font),
// sys_fontwidth(x->x_display_font), x->x_maxSize, x->x_x, bgSize);
sys_vgui(".x%x.c coords magicGlassText %d %d\n",
x->x_c,
x->x_x + 20,
......@@ -111,24 +121,29 @@ void magicGlass_updateText(t_magicGlass *x, int moved)
void magicGlass_drawNew(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_drawNew\n");
sys_vgui(".x%x.c create prect 0 0 0 0 -stroke $pd_colors(magic_glass_bg) -fill $pd_colors(magic_glass_bg) -tags magicGlassBg\n",
//fprintf(stderr,"magicglass_drawNew\n");
sys_vgui(".x%x.c create prect 0 0 0 0 -stroke $pd_colors(magic_glass_bg) "
"-fill $pd_colors(magic_glass_bg) -tags magicGlassBg\n",
x->x_c);
sys_vgui(".x%x.c create ppolygon 0 0 0 0 0 0 -fill $pd_colors(magic_glass_bd) -strokewidth 1 -tags magicGlassLine\n",
sys_vgui(".x%x.c create ppolygon 0 0 0 0 0 0 "
"-fill $pd_colors(magic_glass_bd) -strokewidth 1 "
"-tags magicGlassLine\n",
x->x_c);
sys_vgui(".x%x.c create text 0 0 -text {} -anchor w -fill $pd_colors(magic_glass_flash) -font {{%s} -%d %s} -tags magicGlassText\n",
sys_vgui(".x%x.c create text 0 0 -text {} -anchor w "
"-fill $pd_colors(magic_glass_flash) "
"-font {{%s} -%d %s} -tags magicGlassText\n",
x->x_c, sys_font, x->x_display_font, sys_fontweight);
sys_vgui(".x%x.c raise magicGlassBg\n",
x->x_c);
sys_vgui(".x%x.c raise magicGlassText\n",
x->x_c);
magicGlass_updateText(x, 0);
clock_delay(x->x_flashClock, MG_CLOCK_FLASH_DELAY);
clock_delay(x->x_flashClock, MG_CLOCK_FLASH_DELAY);
}
void magicGlass_undraw(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_undraw\n");
//fprintf(stderr,"magicglass_undraw\n");
sys_vgui(".x%x.c delete magicGlassBg\n", x->x_c);
sys_vgui(".x%x.c delete magicGlassLine\n", x->x_c);
sys_vgui(".x%x.c delete magicGlassText\n", x->x_c);
......@@ -136,23 +151,24 @@ void magicGlass_undraw(t_magicGlass *x)
void magicGlass_flashText(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_flashText\n");
sys_vgui(".x%x.c itemconfigure magicGlassText -fill $pd_colors(magic_glass_text)\n",
//fprintf(stderr,"magicglass_flashText\n");
sys_vgui(".x%x.c itemconfigure magicGlassText "
"-fill $pd_colors(magic_glass_text)\n",
x->x_c);
}
void magicGlass_clearText(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_clearText\n");
strcpy(x->x_old_string, x->x_string);
//fprintf(stderr,"magicglass_clearText\n");
strcpy(x->x_old_string, x->x_string);
x->x_string[0] = 0;
magicGlass_updateText(x, 0);
}
void magicGlass_bang(t_magicGlass *x)
{
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
strcpy(x->x_string, "bang");
magicGlass_updateText(x, 0);
clock_delay(x->x_clearClock, MG_CLOCK_CLEAR_DELAY);
......@@ -160,8 +176,8 @@ void magicGlass_bang(t_magicGlass *x)
void magicGlass_float(t_magicGlass *x, t_float f)
{
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
sprintf(x->x_string, "%g", f);
magicGlass_updateText(x, 0);
clock_delay(x->x_clearClock, MG_CLOCK_CLEAR_DELAY);
......@@ -169,8 +185,8 @@ void magicGlass_float(t_magicGlass *x, t_float f)
void magicGlass_symbol(t_magicGlass *x, t_symbol *sym)
{
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
sprintf(x->x_string, "symbol %s", sym->s_name);
magicGlass_updateText(x, 0);
clock_delay(x->x_clearClock, MG_CLOCK_CLEAR_DELAY);
......@@ -182,9 +198,9 @@ void magicGlass_anything(t_magicGlass *x, t_symbol *sym, int argc, t_atom *argv)
char valueString[4096];
int i;
x->x_issignal = 0;
x->x_issignal = 0;
strcpy(x->x_old_string, x->x_string);
strcpy(x->x_old_string, x->x_string);
strcpy(aString, sym->s_name);
valueString[0] = 0;
for (i = 0; i < argc; i++)
......@@ -211,13 +227,13 @@ void magicGlass_list(t_magicGlass *x, t_symbol *sym, int argc, t_atom *argv)
char valueString[4096];
int i;
x->x_issignal = 0;
x->x_issignal = 0;
aString[0] = 0;
valueString[0] = 0;
strcpy(x->x_old_string, x->x_string);
strcpy(aString, sym->s_name);
strcpy(x->x_old_string, x->x_string);
strcpy(aString, sym->s_name);
for (i = 0; i < argc; i++)
{
if (argv[i].a_type == A_SYMBOL)
......@@ -243,12 +259,13 @@ void magicGlass_setCanvas(t_magicGlass *x, t_glist *c)
void magicGlass_show(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_show\n");
if (!x->x_visible) {
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
x->x_string[0] = 0;
//fprintf(stderr,"magicglass_show\n");
if (!x->x_visible)
{
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
x->x_string[0] = 0;
x->x_visible = 1;
magicGlass_drawNew(x);
}
......@@ -256,20 +273,21 @@ void magicGlass_show(t_magicGlass *x)
void magicGlass_hide(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_hide\n");
if (x->x_visible) {
//fprintf(stderr,"magicglass_hide\n");
if (x->x_visible)
{
magicGlass_undraw(x);
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
x->x_string[0] = 0;
x->x_visible = 0;
}
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
x->x_string[0] = 0;
x->x_visible = 0;
}
}
void magicGlass_moveText(t_magicGlass *x, int pX, int pY)
{
//fprintf(stderr,"magicglass_moveText\n");
//fprintf(stderr,"magicglass_moveText\n");
int bgSize;
x->x_x = pX;
......@@ -279,7 +297,7 @@ void magicGlass_moveText(t_magicGlass *x, int pX, int pY)
int magicGlass_bound(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_bound\n");
//fprintf(stderr,"magicglass_bound\n");
if (x->x_connectedObj != NULL)
return 1;
else
......@@ -288,7 +306,7 @@ int magicGlass_bound(t_magicGlass *x)
int magicGlass_isOn(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_isOn\n");
//fprintf(stderr,"magicglass_isOn\n");
if (x->x_viewOn)
return 1;
else
......@@ -297,7 +315,7 @@ int magicGlass_isOn(t_magicGlass *x)
void magicGlass_setOn(t_magicGlass *x, int i)
{
//fprintf(stderr,"magicglass_setOn\n");
//fprintf(stderr,"magicglass_setOn\n");
if (i)
{
x->x_viewOn = 1;
......@@ -310,20 +328,21 @@ void magicGlass_setOn(t_magicGlass *x, int i)
void magicGlass_setDsp(t_magicGlass *x, int i)
{
//fprintf(stderr,"magicglass_setDsp\n");
if (i != x->x_dspOn) {
if (i)
{
x->x_dspOn = 1;
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
}
else
{
x->x_dspOn = 0;
}
}
//fprintf(stderr,"magicglass_setDsp\n");
if (i != x->x_dspOn)
{
if (i)
{
x->x_dspOn = 1;
x->x_sampleCount = 0;
x->x_minSample = 999999;
x->x_maxSample = -999999;
}
else
{
x->x_dspOn = 0;
}
}
}
t_int *magicGlass_perform(t_int *w)
......@@ -331,29 +350,31 @@ t_int *magicGlass_perform(t_int *w)
t_magicGlass *x = (t_magicGlass *)(w[1]);
if (x->x_dspOn && x->x_connectedObj)
{
//fprintf(stderr,"magicglass_perform\n");
float *in = (float *)(w[2]);
int N = (int)(w[3]);
int i;
//fprintf(stderr,"magicglass_perform\n");
float *in = (float *)(w[2]);
int N = (int)(w[3]);
int i;
for (i = 0; i < N; i++)
{
if (in[i] > x->x_maxSample)
x->x_maxSample = in[i];
if (in[i] < x->x_minSample)
x->x_minSample = in[i];
x->x_minSample = in[i];
x->x_sampleCount++;
if (x->x_sampleCount >= MG_SAMPLE_COUNT)
{
char l[64], m[64], h[64];
sprintf(l, "%s%#g", (x->x_minSample < 0.0f ? "" : " "), x->x_minSample);
l[6] = '\0';
sprintf(m, "%s%#g", (in[i] < 0.0f ? "" : " "), in[i]);
m[6] = '\0';
sprintf(h, "%s%#g", (x->x_maxSample < 0.0f ? "" : " "), x->x_maxSample);
h[6] = '\0';
char l[64], m[64], h[64];
sprintf(l, "%s%#g", (x->x_minSample < 0.0f ? "" : " "),
x->x_minSample);
l[6] = '\0';
sprintf(m, "%s%#g", (in[i] < 0.0f ? "" : " "), in[i]);
m[6] = '\0';
sprintf(h, "%s%#g", (x->x_maxSample < 0.0f ? "" : " "),
x->x_maxSample);
h[6] = '\0';
sprintf(x->x_string, "~ %s %s %s", l, m, h);
magicGlass_updateText(x, 0);
//x->x_minSample = 999999;
//x->x_minSample = 999999;
//x->x_maxSample = -999999;
x->x_sampleCount = 0;
}
......@@ -364,14 +385,14 @@ t_int *magicGlass_perform(t_int *w)
void magicGlass_dsp(t_magicGlass *x, t_signal **sp)
{
//fprintf(stderr,"magicglass_dsp\n");
//fprintf(stderr,"magicglass_dsp\n");
dsp_add(magicGlass_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
x->x_issignal = 1;
x->x_issignal = 1;
}
void *magicGlass_new(t_glist *c)
{
//fprintf(stderr,"magicglass_new\n");
//fprintf(stderr,"magicglass_new\n");
t_magicGlass *x = (t_magicGlass *)pd_new(magicGlass_class);
x->x_connectedObj = NULL;
x->x_connectedOutno = 0;
......@@ -384,19 +405,19 @@ void *magicGlass_new(t_glist *c)
x->x_sampleCount = 0;
x->x_clearClock = clock_new(x, (t_method)magicGlass_clearText);
x->x_flashClock = clock_new(x, (t_method)magicGlass_flashText);
x->x_maxSize = 1;
x->x_issignal = 0;
x->x_display_font = 9;
x->x_maxSize = 1;
x->x_issignal = 0;
x->x_display_font = 9;
return x;
}
void magicGlass_free(t_magicGlass *x)
{
//fprintf(stderr,"magicglass_free %lx\n", (t_int)x);
magicGlass_unbind(x);
//fprintf(stderr,"magicglass_free %lx\n", (t_int)x);
magicGlass_unbind(x);
x->x_dspOn = 0;
clock_free(x->x_clearClock);
clock_free(x->x_flashClock);
clock_free(x->x_flashClock);
}
void magicGlass_setup(void)
......@@ -410,9 +431,9 @@ void magicGlass_setup(void)
0);
CLASS_MAINSIGNALIN(magicGlass_class, t_magicGlass, x_sigF);
class_addmethod(magicGlass_class,
(t_method)magicGlass_dsp,
gensym("dsp"),
0);
(t_method)magicGlass_dsp,
gensym("dsp"),
0);
class_addbang(magicGlass_class, (t_method)magicGlass_bang);
class_addfloat(magicGlass_class, (t_method)magicGlass_float);
class_addsymbol(magicGlass_class, (t_method)magicGlass_symbol);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
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