static void tab_set(t_tab *x, t_symbol *s, int argc, t_atom *argv) { int i; t_symbol* item; if(argc && argv && atom_gettype(argv) == A_FLOAT) { ebox_parameter_setvalue((t_ebox *)x, 1, atom_getfloat(argv), 0); ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); } else if(argc && argv && atom_gettype(argv) == A_SYMBOL) { item = tab_gensym(NULL, argc, argv); if(item) { for(i = 0; i < x->f_nitems; i++) { if(x->f_items[i] == item) { ebox_parameter_setvalue((t_ebox *)x, 1, (float)i, 0); ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); return; } } } } }
static void knob_mousedrag(t_knob *x, t_object *patcherview, t_pt pt, long modifiers) { t_rect rect; ebox_get_rect_for_view((t_ebox *)x, &rect); if(x->f_circular) { const float size = rect.width * 0.5f; const float angle = pd_angle(pt.x - size, -(size - pt.y)); if(x->f_endless) { const float value = pd_wrap((angle - EPD_PI2) / EPD_2PI, 0.f, 1.f); if(ebox_parameter_isinverted((t_ebox *)x, 1)) { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, 1.f - value, 1); } else { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, value, 1); } } else { const float value = (pd_clip(pd_wrap((angle - EPD_PI2) / EPD_2PI, 0.f, 1.f), 0.125f, 0.875f) - 0.125f) / 0.75f; if(ebox_parameter_isinverted((t_ebox *)x, 1)) { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, 1.f - value, 1); } else { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, value, 1); } } knob_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_needle_layer); ebox_redraw((t_ebox *)x); } else { const float current = ebox_parameter_getvalue_normalized((t_ebox *)x, 1); const float diff = (x->f_reference - pt.y) / (rect.width) * (ebox_parameter_isinverted((t_ebox *)x, 1) ? -1.f : 1.f); if(x->f_endless) { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, pd_wrap(current + diff, 0.f, 1.f), 1); } else { ebox_parameter_setvalue_normalized((t_ebox *)x, 1, pd_clip(current + diff, 0.f, 1.f), 1); } x->f_reference = pt.y; } knob_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_needle_layer); ebox_redraw((t_ebox *)x); }
static void blackboard_image(t_blackboard *x, t_symbol *s, int argc, t_atom *argv) { int fd; char path[MAXPDSTRING]; char name[MAXPDSTRING]; char *nameptr; if(x->f_ninstructions >= _blackboard::maxcmd) { pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name); return; } if(argc > 2 && argv) { if(atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT && atom_gettype(argv+2) == A_SYMBOL) { sprintf(path, "%s",atom_getsymbol(argv+2)->s_name); if(access(path, O_RDONLY) != -1) { sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path); x->f_ninstructions++; ebox_redraw((t_ebox *)x); return; } sprintf(path, "%s/%s", canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, atom_getsymbol(argv+2)->s_name); if(access(path, O_RDONLY) != -1) { sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path); x->f_ninstructions++; ebox_redraw((t_ebox *)x); return; } sprintf(name, "%s", atom_getsymbol(argv+2)->s_name); if(!strncmp(name+strlen(name)-4, ".gif", 4)) { strncpy(name+strlen(name)-4, "\0", 4); } fd = open_via_path(canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, name, ".gif", path, &nameptr, MAXPDSTRING, 0); if(fd >= 0) { sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s/%s.gif]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path, name); x->f_ninstructions++; ebox_redraw((t_ebox *)x); return; } } } }
static void plane_float(t_plane *x, float f) { ebox_parameter_setvalue((t_ebox *)x, 1, f, eobj_getproxy(x) + 1); plane_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_points_layer); ebox_redraw((t_ebox *)x); }
t_pd_err hoa_space_coefficients_set(t_hoa_space *x, t_object *attr, long ac, t_atom *av) { if (ac && av) { if(atom_gettype(av) == A_FLOAT) { if(x->f_mode == 0 || x->f_mode == 2) { for (int i = 0; i < ac && i < x->f_number_of_microphones; i++) { if(atom_gettype(av+i) == A_FLOAT) x->f_microphonesValues[i] = Tools::clip((double)atom_getfloat(av + i), 0., 1.); } } else { for (int i = 0; i < ac && i < x->f_number_of_microphones; i++) { x->f_microphonesValues[i] = atom_getfloat(av + i); } } } } x->f_recomposer->processFixe(x->f_microphonesValues, x->f_harmonicsValues); x->f_viewer->processContribAndRep(x->f_harmonicsValues); ebox_invalidate_layer((t_ebox *)x, gensym("microphones_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("harmonics_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("center_layer")); ebox_redraw((t_ebox *)x); return 0; }
void hoa_space_mouse_drag(t_hoa_space *x, t_object *patcherview, t_pt pt, long modifiers) { double mapped_x = (pt.x - x->f_center) / x->f_center; double mapped_y = (pt.y - x->f_center) / x->f_center * -1.; double radius = Tools::radius(mapped_x, mapped_y); double angle = Tools::angle(mapped_x, mapped_y) - CICM_PI2; x->f_mousepos.x = radius; x->f_mousepos.y = angle; if(x->f_mode == 0) { hoa_space_draw_points(x, patcherview, pt, modifiers); } else if(x->f_mode == 1) { hoa_space_rotate_points(x, patcherview, pt, modifiers); } else if(x->f_mode == 2) { hoa_space_retract_points(x, patcherview, pt, modifiers); } ebox_redraw((t_ebox *)x); }
t_pd_err hoa_space_notify(t_hoa_space *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { if (msg == gensym("attr_modified")) { if(s == gensym("miccolor")) { ebox_invalidate_layer((t_ebox *)x, gensym("microphones_layer")); } else if(s == gensym("harmocolor")) { ebox_invalidate_layer((t_ebox *)x, gensym("microphones_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("harmonics_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("center_layer")); } else if(s == gensym("circolor")) { ebox_invalidate_layer((t_ebox *)x, gensym("microphones_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("harmonics_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("center_layer")); } ebox_redraw((t_ebox *)x); } return 0; }
static void blackboard_text(t_blackboard *x, t_symbol *s, int argc, t_atom *argv) { int i; char buffer[MAXPDSTRING]; size_t length; if(x->f_ninstructions >= _blackboard::maxcmd) { pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name); return; } if(argc > 2 && argv) { if (atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT) { sprintf(x->f_instructions[x->f_ninstructions], "create text %d %d -anchor nw -text {", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1)); for(i = 2; i < argc; i++) { atom_string(argv+i, buffer, MAXPDSTRING); length = strlen(buffer); strncat(x->f_instructions[x->f_ninstructions], " ", 1); strncat(x->f_instructions[x->f_ninstructions], buffer, length); } sprintf(buffer, "} -font {%s %d %s} -fill %s", x->j_box.b_font.c_family->s_name, (int)x->j_box.b_font.c_size, x->j_box.b_font.c_weight->s_name, x->f_color->s_name); length = strlen(buffer); strncat(x->f_instructions[x->f_ninstructions], buffer, length); x->f_ninstructions++; ebox_redraw((t_ebox *)x); } } }
void hoa_meter_tick(t_hoa_meter *x) { if(x->f_vector_type == hoa_sym_both) x->f_vector->process(x->f_signals, x->f_vector_coords); else if(x->f_vector_type == hoa_sym_velocity) x->f_vector->processVelocity(x->f_signals, x->f_vector_coords); else if(x->f_vector_type == hoa_sym_energy) x->f_vector->processEnergy(x->f_signals, x->f_vector_coords + 2); double peak; for (int i = 0; i < x->f_meter->getNumberOfChannels(); i++) { peak = x->f_meter->getChannelEnergy(i); if(peak >= 0.) x->f_over_leds[i] = 1000; else x->f_over_leds[i] -= x->f_interval; if(x->f_over_leds[i] < 0) x->f_over_leds[i] = 0; } ebox_invalidate_layer((t_ebox *)x, hoa_sym_leds_layer); ebox_invalidate_layer((t_ebox *)x, hoa_sym_vector_layer); ebox_redraw((t_ebox *)x); if (sys_getdspstate()) clock_delay(x->f_clock, x->f_interval); }
void carray_output(t_carray *x, t_symbol* s, long argc, t_atom* argv) { post("Array : %s, Size : %i", x->f_name->s_name, x->f_buffer_size); ebox_invalidate_layer((t_ebox*)x, gensym("buffer_layer")); ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_redraw((t_ebox *)x); }
void breakpoints_mousemove(t_breakpoints *x, t_object *patcherview, t_pt pt, long modifiers) { int i; float abs, ord; float height = sys_fontheight(ebox_getfontsize((t_ebox *)x)) + 2; float distx = (3. / (x->f_size.x - 4.)) * (x->f_range_abscissa[1] - x->f_range_abscissa[0]); float disty = (3. / (x->f_size.y - 4. - height)) * (x->f_range_ordinate[1] - x->f_range_ordinate[0]); abs = ((pt.x - 3.) / (x->f_size.x - 4.)) * (x->f_range_abscissa[1] - x->f_range_abscissa[0]) + x->f_range_abscissa[0]; ord = ((x->f_size.y - (pt.y - 4.) - 4.) / (x->f_size.y - 4. - height)) * (x->f_range_ordinate[1] - x->f_range_ordinate[0]) + x->f_range_ordinate[0]; x->f_point_hover = -1; x->f_mouse.x = abs; x->f_mouse.y = ord; for(i = 0; i < x->f_number_of_points; i++) { if(abs > x->f_point_abscissa[i] - distx && abs < x->f_point_abscissa[i] + distx && ord > x->f_point_ordinate[i] - disty && ord < x->f_point_ordinate[i] + disty) { x->f_point_hover = i; } } ebox_invalidate_layer((t_ebox *)x, gensym("points_layer")); ebox_invalidate_layer((t_ebox *)x, cream_sym_text_layer); ebox_redraw((t_ebox *)x); }
static void tab_float(t_tab *x, t_floatarg f) { ebox_parameter_setvalue((t_ebox *)x, 1, f, 1); tab_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_selection_layer); ebox_redraw((t_ebox *)x); }
void radio_set(t_radio *x, t_symbol* s, long argc, t_atom* argv) { int i; if(argc && argv) { if(x->f_mode) { for(i = 0; i < argc && i < x->f_nitems; i++) { if(atom_gettype(argv+i) == A_FLOAT && atom_getfloat(argv+i) == 0) x->f_items[i] = 0; else x->f_items[i] = 1; } } else if(atom_gettype(argv) == A_FLOAT && atom_getfloat(argv) >= 0 && atom_getfloat(argv) < x->f_nitems) { for(i = 0; i < x->f_nitems; i++) x->f_items[(i)] = 0; x->f_items[(int)atom_getfloat(argv)] = 1; } ebox_invalidate_layer((t_ebox *)x, gensym("items_layer")); ebox_redraw((t_ebox *)x); } }
t_pd_err carray_buffer_set(t_carray *x, t_eattr *attr, long argc, t_atom* argv) { int i; x->f_array = NULL; if(argc && argv && atom_gettype(argv) == A_SYM) { x->f_name = atom_getsym(argv); if(!(x->f_array = (t_garray *)pd_findbyclass(x->f_name, garray_class))) { x->f_array = NULL; x->f_name = gensym("(null)"); x->f_buffer_size = 0; x->f_buffer = NULL; } else if(!garray_getfloatarray(x->f_array, &x->f_buffer_size, &x->f_buffer)) { x->f_array = NULL; x->f_name = gensym("(null)"); x->f_buffer_size = 0; x->f_buffer = NULL; } else { for(i = 0; i < x->f_buffer_size; i++) post("%f", x->f_buffer[i]); ebox_invalidate_layer((t_ebox*)x, gensym("buffer_layer")); ebox_redraw((t_ebox*)x); } } return 0; }
void breakpoints_remove(t_breakpoints *x, t_symbol* s, int argc, t_atom* argv) { int index, i; if(x->f_number_of_points == MAXPOINTS) return; if(argc && argv) { if(argc == 1 && atom_gettype(argv) == A_FLOAT) { index = atom_getfloat(argv); if(index >= x->f_number_of_points || index < 0) return; for(i = index; i < x->f_number_of_points; i++) { x->f_point_abscissa[i] = x->f_point_abscissa[i+1]; x->f_point_ordinate[i] = x->f_point_ordinate[i+1]; } x->f_number_of_points--; ebox_invalidate_layer((t_ebox *)x, gensym("points_layer")); ebox_redraw((t_ebox *)x); } } }
t_pd_err angles_set(t_hoa_meter *x, void *attr, long argc, t_atom *argv) { double angles[MAX_SPEAKER]; if(argc > MAX_SPEAKER) argc = MAX_SPEAKER; if(argc && argv) { for(int i = 0; i < argc; i++) { if(atom_gettype(argv+i) == A_FLOAT) { angles[i] = atom_getfloat(argv+i) / 360. * HOA_2PI; } } x->f_meter->setChannelsAzimuth(angles); x->f_vector->setChannelsAzimuth(angles); } ebox_invalidate_layer((t_ebox *)x, hoa_sym_background_layer); ebox_invalidate_layer((t_ebox *)x, hoa_sym_leds_layer); ebox_invalidate_layer((t_ebox *)x, hoa_sym_vector_layer); ebox_redraw((t_ebox *)x); return 0; }
static void dsp_tilde_stop(t_dsp_tilde *x) { canvas_suspend_dsp(); x->f_state = 0; ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); }
static void dsp_tilde_start(t_dsp_tilde *x) { canvas_resume_dsp(1); x->f_state = 1; ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); }
void radio_mousedown(t_radio *x, t_object *patcherview, t_pt pt, long modifiers) { int i, index; if(x->f_direction) { index = (pt.x - 2) / x->j_box.b_rect.width * x->f_nitems; } else { index = (pt.y - 2) / x->j_box.b_rect.height * x->f_nitems; } if(index >= 0 && index < x->f_nitems) { if(x->f_mode) { if(x->f_items[index] == 0) x->f_items[index] = 1; else x->f_items[index] = 0; } else { for(i = 0; i < x->f_nitems; i++) x->f_items[i] = 0; x->f_items[index] = 1; } } ebox_invalidate_layer((t_ebox *)x, gensym("items_layer")); ebox_redraw((t_ebox *)x); radio_output(x); }
static t_pd_err tab_notify(t_tab *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { if (msg == cream_sym_attr_modified) { if(s == cream_sym_bgcolor || s == cream_sym_bdcolor || s == cream_sym_textcolor || s == cream_sym_hocolor || s == cream_sym_secolor || s == cream_sym_orientation || s == cream_sym_font) { ebox_invalidate_layer((t_ebox *)x, cream_sym_selection_layer); ebox_invalidate_layer((t_ebox *)x, cream_sym_text_layer); ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); } else if(s == cream_sym_orientation || s == cream_sym_items) { ebox_notify((t_ebox *)x, s_cream_size, cream_sym_attr_modified, NULL, NULL); } } else if(msg == cream_sym_value_changed) { tab_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); } return 0; }
static void incdec_mouseup(t_incdec *x, t_object *patcherview, t_pt pt, long modifiers) { x->f_mouse_down = 0; clock_unset(x->f_clock); ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer); ebox_redraw((t_ebox *)x); }
void filterview_set(t_filterview *x, t_symbol *s, long ac, t_atom *av) { if(ac && av) { ebox_invalidate_layer((t_ebox *)x, gensym("point_layer")); ebox_redraw((t_ebox *)x); } }
static void tab_prev(t_tab *x) { const float index = ebox_parameter_getvalue((t_ebox *)x, 1); ebox_parameter_setvalue((t_ebox *)x, 1, index-1, 1); tab_output(x); ebox_invalidate_layer((t_ebox *)x, cream_sym_selection_layer); ebox_redraw((t_ebox *)x); }
void toggle_output(t_toggle *x) { ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_redraw((t_ebox *)x); outlet_float((t_outlet*)x->f_out, (float)x->f_active); if(ebox_getsender((t_ebox *) x)) pd_float(ebox_getsender((t_ebox *) x), (float)x->f_active); }
static t_pd_err blackboard_notify(t_blackboard *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { if(msg == cream_sym_attr_modified) { ebox_redraw((t_ebox *)x); } return 0; }
t_pd_err matrixctrl_notify(t_matrixctrl *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { if (msg == cream_sym_attr_modified) { ebox_redraw((t_ebox *)x); } return 0; }
void hoa_scope_tick(t_hoa_scope *x) { x->f_scope->process(x->f_signals + x->f_index * x->f_scope->getNumberOfHarmonics()); ebox_invalidate_layer((t_ebox *)x, hoa_sym_harmonics_layer); ebox_redraw((t_ebox *)x); if(sys_getdspstate()) clock_delay(x->f_clock, x->f_interval); }
void toggle_set(t_toggle *x, float f) { if(f == 0) x->f_active = 0; else x->f_active = 1; ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_redraw((t_ebox *)x); }
void bang_mousedown(t_bang *x, t_object *patcherview, t_pt pt, long modifiers) { x->f_active = 1; ebox_invalidate_layer((t_ebox *)x, gensym("background_layer")); ebox_redraw((t_ebox *)x); outlet_bang(x->f_out); if(ebox_getsender((t_ebox *) x)) pd_bang(ebox_getsender((t_ebox *) x)); }
void number_tilde_tick(t_number_tilde *x) { number_tilde_output(x); ebox_invalidate_layer((t_ebox *)x, gensym("value_layer")); ebox_redraw((t_ebox *)x); if(sys_getdspstate()) clock_delay(x->f_clock, x->f_interval); }