19 #define MAX_LIST_LENGTH 100
21 typedef struct _route{
25 t_symbol *searchlist[MAX_LIST_LENGTH];
27 long searchpositions[MAX_LIST_LENGTH];
28 long searchpositionslen;
31 t_symbol *searchsymbol;
35 void *route_new(t_symbol *s,
long argc, t_atom *argv);
36 void route_assist(t_route *x,
void *b,
long msg,
long arg,
char *dst);
37 void route_symbol(t_route *x, t_symbol *msg,
long argc, t_atom *argv);
38 void route_list(t_route *x, t_symbol *msg,
long argc, t_atom *argv);
39 void route_bang(t_route *x);
40 char find_match(t_route *x, t_symbol *input,
short position);
48 int JAMOMA_EXPORT_MAXOBJ
main(
void)
54 common_symbols_init();
57 c = class_new(
"j.route",(method)route_new, (method)0L,
sizeof(t_route), (method)0L, A_GIMME, 0);
60 class_addmethod(c, (method)route_bang,
"bang", 0L);
61 class_addmethod(c, (method)route_list,
"list", A_GIMME, 0L);
62 class_addmethod(c, (method)route_symbol,
"anything", A_GIMME, 0L);
63 class_addmethod(c, (method)route_assist,
"assist", A_CANT, 0L);
64 class_addmethod(c, (method)object_obex_dumpout,
"dumpout", A_CANT,0);
67 attr = attr_offset_array_new(
"searchstring", _sym_symbol, MAX_LIST_LENGTH, attrflags,
68 (method)0, (method)0, calcoffset(t_route, searchlistlen), calcoffset(t_route, searchlist));
69 class_addattr(c, attr);
72 attr = attr_offset_array_new(
"searchpositions", _sym_long, MAX_LIST_LENGTH, attrflags,
73 (method)0, (method)0, calcoffset(t_route, searchpositionslen), calcoffset(t_route, searchpositions));
74 class_addattr(c, attr);
77 attr = attr_offset_new(
"partialmatch", _sym_long, attrflags,
78 (method)0, (method)0, calcoffset(t_route, partialmatch));
79 class_addattr(c, attr);
88 class_register(CLASS_BOX, c);
97 void *route_new(t_symbol *s,
long argc, t_atom *argv)
99 t_route *x = (t_route *)object_alloc(route_class);
101 object_obex_store((
void *)x, _sym_dumpout, (
object *)outlet_new(x,NULL));
104 x->my_outlet[1] = outlet_new(x, 0);
105 x->my_outlet[0] = outlet_new(x, 0);
108 x->searchlist[0] = gensym(
"default");
109 x->searchlistlen = 1;
110 x->searchpositions[0] = 1;
111 x->searchpositionslen = 1;
115 attr_args_process(x,argc,argv);
125 void route_assist(t_route *x,
void *b,
long msg,
long arg,
char *dst)
128 strcpy(dst,
"Input");
131 case 0: strcpy(dst,
"Matching Output");
break;
132 case 1: strcpy(dst,
"Unmatching Output");
break;
133 case 2: strcpy(dst,
"Dumpout");
break;
140 void route_bang(t_route *x)
146 for (i=0; i< (x->searchlistlen); i++) {
147 strcat(newstring, x->searchlist[i]->s_name);
148 strcat(newstring,
" ");
151 newstring[strlen(newstring) - 1] = 0;
153 x->searchsymbol = gensym(newstring);
158 char find_match(t_route *x, t_symbol *input,
short position)
164 for (i=0; i<MAX_LIST_LENGTH ;i++) {
165 matched += (x->searchpositions[i] == position);
169 if (x->partialmatch) {
170 len = strlen(x->searchsymbol->s_name);
171 for (i=0; i<len; i++) {
172 if (input->s_name[i] != x->searchsymbol->s_name[i])
178 return (input == x->searchsymbol);
186 void route_symbol(t_route *x, t_symbol *msg,
long argc, t_atom *argv)
197 matched += find_match(x, msg, 1);
200 for (i=0; i<argc; i++) {
201 switch(argv[i].a_type) {
203 snprintf(tempstring, 50,
"%ld", argv[i].a_w.w_long);
204 tempsym = gensym(tempstring);
207 snprintf(tempstring, 50,
"%f", argv[i].a_w.w_float);
208 tempsym = gensym(tempstring);
211 tempsym = argv[i].a_w.w_sym;
214 matched += find_match(x, tempsym, i+2);
219 outlet_anything(x->my_outlet[0], msg, argc , argv);
221 outlet_anything(x->my_outlet[1], msg, argc, argv);
227 void route_list(t_route *x, t_symbol *msg,
long argc, t_atom *argv)
238 for (i=0; i<argc; i++) {
239 switch(argv[i].a_type) {
241 snprintf(tempstring, 50,
"%ld", argv[i].a_w.w_long);
242 tempsym = gensym(tempstring);
245 snprintf(tempstring, 50,
"%f", argv[i].a_w.w_float);
246 tempsym = gensym(tempstring);
249 tempsym = argv[i].a_w.w_sym;
252 matched += find_match(x, tempsym, i+1);
257 outlet_anything(x->my_outlet[0], msg, argc , argv);
259 outlet_anything(x->my_outlet[1], msg, argc, argv);
int JAMOMA_EXPORT_MAXOBJ main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.