1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* miscellaneous: print~; more to come.
12 /* ------------------------- print~ -------------------------- */
13 static t_class
*print_class
;
23 static t_int
*print_perform(t_int
*w
)
25 t_print
*x
= (t_print
*)(w
[1]);
26 t_float
*in
= (t_float
*)(w
[2]);
30 post("%s:", x
->x_sym
->s_name
);
31 if (n
== 1) post("%8g", in
[0]);
32 else if (n
== 2) post("%8g %8g", in
[0], in
[1]);
33 else if (n
== 4) post("%8g %8g %8g %8g",
34 in
[0], in
[1], in
[2], in
[3]);
37 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
38 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6], in
[7]);
47 static void print_dsp(t_print
*x
, t_signal
**sp
)
49 dsp_add(print_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
52 static void print_float(t_print
*x
, t_float f
)
58 static void print_bang(t_print
*x
)
63 static void *print_new(t_symbol
*s
)
65 t_print
*x
= (t_print
*)pd_new(print_class
);
66 x
->x_sym
= (s
->s_name
[0]? s
: gensym("print~"));
72 static void print_setup(void)
74 print_class
= class_new(gensym("print~"), (t_newmethod
)print_new
, 0,
75 sizeof(t_print
), 0, A_DEFSYM
, 0);
76 CLASS_MAINSIGNALIN(print_class
, t_print
, x_f
);
77 class_addmethod(print_class
, (t_method
)print_dsp
, gensym("dsp"), 0);
78 class_addbang(print_class
, print_bang
);
79 class_addfloat(print_class
, print_float
);
82 /* ------------------------- scope~ -------------------------- */
83 /* this has been replaced by arrays; to be deleted later */
87 static t_class
*scope_class
;
94 t_sample x_samps
[SCOPESIZE
];
100 static t_int
*scope_perform(t_int
*w
)
102 t_scope
*x
= (t_scope
*)(w
[1]);
103 t_float
*in
= (t_float
*)(w
[2]);
104 int n
= (int)(w
[3]), phase
= x
->x_phase
;
107 x
->x_samps
[phase
] = *in
++;
108 phase
= (phase
+ 1) & (SCOPESIZE
-1);
114 static void scope_dsp(t_scope
*x
, t_signal
**sp
)
116 dsp_add(scope_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
119 static void scope_erase(t_scope
*x
)
121 if (x
->x_drawn
) sys_vgui(".x%x.c delete gumbo\n", x
->x_canvas
);
127 static void scope_bang(t_scope
*x
)
130 char hugebuf
[10000], *s
= hugebuf
;
132 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x
->x_canvas
);
133 sprintf(s
, ".x%x.c create line ", (t_int
)x
->x_canvas
);
135 for (n
= 0, phase
= x
->x_phase
;
136 n
< SCOPESIZE
; phase
= ((phase
+1) & (SCOPESIZE
-1)), n
++)
138 sprintf(s
, "%fc %fc ", X1
+ (X2
- X1
) * (float)n
* (1./SCOPESIZE
),
139 YC
- 5 * x
->x_samps
[phase
]);
141 /* post("phase %d", phase); */
143 sprintf(s
, "-tags gumbo\n");
148 static void scope_free(t_scope
*x
)
153 static void *scope_new(t_symbol
*s
)
155 t_scope
*x
= (t_scope
*)pd_new(scope_class
);
156 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
159 x
->x_canvas
= canvas_getcurrent();
163 static void scope_setup(void)
165 scope_class
= class_new(gensym("scope~"), (t_newmethod
)scope_new
,
166 (t_method
)scope_free
, sizeof(t_scope
), 0, A_DEFSYM
, 0);
167 class_addmethod(scope_class
, nullfn
, gensym("signal"), 0);
168 class_addmethod(scope_class
, (t_method
)scope_dsp
, gensym("dsp"), 0);
169 class_addbang(scope_class
, scope_bang
);
172 /* ------------------------ bang~ -------------------------- */
174 static t_class
*bang_tilde_class
;
182 static t_int
*bang_tilde_perform(t_int
*w
)
184 t_bang
*x
= (t_bang
*)(w
[1]);
185 clock_delay(x
->x_clock
, 0);
189 static void bang_tilde_dsp(t_bang
*x
, t_signal
**sp
)
191 dsp_add(bang_tilde_perform
, 1, x
);
194 static void bang_tilde_tick(t_bang
*x
)
196 outlet_bang(x
->x_obj
.ob_outlet
);
199 static void bang_tilde_free(t_bang
*x
)
201 clock_free(x
->x_clock
);
204 static void *bang_tilde_new(t_symbol
*s
)
206 t_bang
*x
= (t_bang
*)pd_new(bang_tilde_class
);
207 x
->x_clock
= clock_new(x
, (t_method
)bang_tilde_tick
);
208 outlet_new(&x
->x_obj
, &s_bang
);
212 static void bang_tilde_setup(void)
214 bang_tilde_class
= class_new(gensym("bang~"), (t_newmethod
)bang_tilde_new
,
215 (t_method
)bang_tilde_free
, sizeof(t_bang
), 0, 0);
216 class_addmethod(bang_tilde_class
, (t_method
)bang_tilde_dsp
,
220 /* ------------------------ samplerate~~ -------------------------- */
222 static t_class
*samplerate_tilde_class
;
224 typedef struct _samplerate
229 static void samplerate_tilde_bang(t_samplerate
*x
)
231 outlet_float(x
->x_obj
.ob_outlet
, sys_getsr());
234 static void *samplerate_tilde_new(t_symbol
*s
)
236 t_samplerate
*x
= (t_samplerate
*)pd_new(samplerate_tilde_class
);
237 outlet_new(&x
->x_obj
, &s_float
);
241 static void samplerate_tilde_setup(void)
243 samplerate_tilde_class
= class_new(gensym("samplerate~"),
244 (t_newmethod
)samplerate_tilde_new
, 0, sizeof(t_samplerate
), 0, 0);
245 class_addbang(samplerate_tilde_class
, samplerate_tilde_bang
);
248 /* ------------------------ global setup routine ------------------------- */
250 void d_misc_setup(void)
257 samplerate_tilde_setup();
263 /* Copyright (c) 1997-1999 Miller Puckette.
264 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
265 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
267 /* miscellaneous: print~; more to come.
274 /* ------------------------- print~ -------------------------- */
275 static t_class
*print_class
;
277 typedef struct _print
285 static t_int
*print_perform(t_int
*w
)
287 t_print
*x
= (t_print
*)(w
[1]);
288 t_float
*in
= (t_float
*)(w
[2]);
292 post("%s:", x
->x_sym
->s_name
);
293 if (n
== 1) post("%8g", in
[0]);
294 else if (n
== 2) post("%8g %8g", in
[0], in
[1]);
295 else if (n
== 4) post("%8g %8g %8g %8g",
296 in
[0], in
[1], in
[2], in
[3]);
299 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
300 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6], in
[7]);
309 static void print_dsp(t_print
*x
, t_signal
**sp
)
311 dsp_add(print_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
314 static void print_float(t_print
*x
, t_float f
)
320 static void print_bang(t_print
*x
)
325 static void *print_new(t_symbol
*s
)
327 t_print
*x
= (t_print
*)pd_new(print_class
);
328 x
->x_sym
= (s
->s_name
[0]? s
: gensym("print~"));
334 static void print_setup(void)
336 print_class
= class_new(gensym("print~"), (t_newmethod
)print_new
, 0,
337 sizeof(t_print
), 0, A_DEFSYM
, 0);
338 CLASS_MAINSIGNALIN(print_class
, t_print
, x_f
);
339 class_addmethod(print_class
, (t_method
)print_dsp
, gensym("dsp"), 0);
340 class_addbang(print_class
, print_bang
);
341 class_addfloat(print_class
, print_float
);
344 /* ------------------------- scope~ -------------------------- */
345 /* this has been replaced by arrays; to be deleted later */
347 #include "g_canvas.h"
349 static t_class
*scope_class
;
351 #define SCOPESIZE 256
353 typedef struct _scope
356 t_sample x_samps
[SCOPESIZE
];
362 static t_int
*scope_perform(t_int
*w
)
364 t_scope
*x
= (t_scope
*)(w
[1]);
365 t_float
*in
= (t_float
*)(w
[2]);
366 int n
= (int)(w
[3]), phase
= x
->x_phase
;
369 x
->x_samps
[phase
] = *in
++;
370 phase
= (phase
+ 1) & (SCOPESIZE
-1);
376 static void scope_dsp(t_scope
*x
, t_signal
**sp
)
378 dsp_add(scope_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
381 static void scope_erase(t_scope
*x
)
383 if (x
->x_drawn
) sys_vgui(".x%x.c delete gumbo\n", x
->x_canvas
);
389 static void scope_bang(t_scope
*x
)
392 char hugebuf
[10000], *s
= hugebuf
;
394 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x
->x_canvas
);
395 sprintf(s
, ".x%x.c create line ", (t_int
)x
->x_canvas
);
397 for (n
= 0, phase
= x
->x_phase
;
398 n
< SCOPESIZE
; phase
= ((phase
+1) & (SCOPESIZE
-1)), n
++)
400 sprintf(s
, "%fc %fc ", X1
+ (X2
- X1
) * (float)n
* (1./SCOPESIZE
),
401 YC
- 5 * x
->x_samps
[phase
]);
403 /* post("phase %d", phase); */
405 sprintf(s
, "-tags gumbo\n");
410 static void scope_free(t_scope
*x
)
415 static void *scope_new(t_symbol
*s
)
417 t_scope
*x
= (t_scope
*)pd_new(scope_class
);
418 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
421 x
->x_canvas
= canvas_getcurrent();
425 static void scope_setup(void)
427 scope_class
= class_new(gensym("scope~"), (t_newmethod
)scope_new
,
428 (t_method
)scope_free
, sizeof(t_scope
), 0, A_DEFSYM
, 0);
429 class_addmethod(scope_class
, nullfn
, gensym("signal"), 0);
430 class_addmethod(scope_class
, (t_method
)scope_dsp
, gensym("dsp"), 0);
431 class_addbang(scope_class
, scope_bang
);
434 /* ------------------------ bang~ -------------------------- */
436 static t_class
*bang_tilde_class
;
444 static t_int
*bang_tilde_perform(t_int
*w
)
446 t_bang
*x
= (t_bang
*)(w
[1]);
447 clock_delay(x
->x_clock
, 0);
451 static void bang_tilde_dsp(t_bang
*x
, t_signal
**sp
)
453 dsp_add(bang_tilde_perform
, 1, x
);
456 static void bang_tilde_tick(t_bang
*x
)
458 outlet_bang(x
->x_obj
.ob_outlet
);
461 static void bang_tilde_free(t_bang
*x
)
463 clock_free(x
->x_clock
);
466 static void *bang_tilde_new(t_symbol
*s
)
468 t_bang
*x
= (t_bang
*)pd_new(bang_tilde_class
);
469 x
->x_clock
= clock_new(x
, (t_method
)bang_tilde_tick
);
470 outlet_new(&x
->x_obj
, &s_bang
);
474 static void bang_tilde_setup(void)
476 bang_tilde_class
= class_new(gensym("bang~"), (t_newmethod
)bang_tilde_new
,
477 (t_method
)bang_tilde_free
, sizeof(t_bang
), 0, 0);
478 class_addmethod(bang_tilde_class
, (t_method
)bang_tilde_dsp
,
482 /* ------------------------ samplerate~~ -------------------------- */
484 static t_class
*samplerate_tilde_class
;
486 typedef struct _samplerate
491 static void samplerate_tilde_bang(t_samplerate
*x
)
493 outlet_float(x
->x_obj
.ob_outlet
, sys_getsr());
496 static void *samplerate_tilde_new(t_symbol
*s
)
498 t_samplerate
*x
= (t_samplerate
*)pd_new(samplerate_tilde_class
);
499 outlet_new(&x
->x_obj
, &s_float
);
503 static void samplerate_tilde_setup(void)
505 samplerate_tilde_class
= class_new(gensym("samplerate~"),
506 (t_newmethod
)samplerate_tilde_new
, 0, sizeof(t_samplerate
), 0, 0);
507 class_addbang(samplerate_tilde_class
, samplerate_tilde_bang
);
510 /* ------------------------ global setup routine ------------------------- */
512 void d_misc_setup(void)
519 samplerate_tilde_setup();