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.
10 #include "../../pdbox.h"
20 /* ------------------------- print~ -------------------------- */
21 static t_class
*print_class
;
31 static t_int
*print_perform(t_int
*w
)
33 t_print
*x
= (t_print
*)(w
[1]);
34 t_float
*in
= (t_float
*)(w
[2]);
38 post("%s:", x
->x_sym
->s_name
);
39 if (n
== 1) post("%8g", in
[0]);
40 else if (n
== 2) post("%8g %8g", in
[0], in
[1]);
41 else if (n
== 4) post("%8g %8g %8g %8g",
42 in
[0], in
[1], in
[2], in
[3]);
45 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
46 in
[0], in
[1], in
[2], in
[3], in
[4], in
[5], in
[6], in
[7]);
55 static void print_dsp(t_print
*x
, t_signal
**sp
)
57 dsp_add(print_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
60 static void print_float(t_print
*x
, t_float f
)
66 static void print_bang(t_print
*x
)
71 static void *print_new(t_symbol
*s
)
73 t_print
*x
= (t_print
*)pd_new(print_class
);
74 x
->x_sym
= (s
->s_name
[0]? s
: gensym("print~"));
83 void print_setup(void)
85 print_class
= class_new(gensym("print~"), (t_newmethod
)print_new
, 0,
86 sizeof(t_print
), 0, A_DEFSYM
, 0);
87 CLASS_MAINSIGNALIN(print_class
, t_print
, x_f
);
88 class_addmethod(print_class
, (t_method
)print_dsp
, gensym("dsp"), 0);
89 class_addbang(print_class
, print_bang
);
90 class_addfloat(print_class
, print_float
);
93 /* ------------------------- scope~ -------------------------- */
94 /* this has been replaced by arrays; to be deleted later */
98 static t_class
*scope_class
;
100 #define SCOPESIZE 256
102 typedef struct _scope
105 t_sample x_samps
[SCOPESIZE
];
111 static t_int
*scope_perform(t_int
*w
)
113 t_scope
*x
= (t_scope
*)(w
[1]);
114 t_float
*in
= (t_float
*)(w
[2]);
115 int n
= (int)(w
[3]), phase
= x
->x_phase
;
118 x
->x_samps
[phase
] = *in
++;
119 phase
= (phase
+ 1) & (SCOPESIZE
-1);
125 static void scope_dsp(t_scope
*x
, t_signal
**sp
)
127 dsp_add(scope_perform
, 3, x
, sp
[0]->s_vec
, sp
[0]->s_n
);
130 static void scope_erase(t_scope
*x
)
135 if (x
->x_drawn
) sys_vgui(".x%x.c delete gumbo\n", x
->x_canvas
);
142 static void scope_bang(t_scope
*x
)
146 char hugebuf
[10000], *s
= hugebuf
;
148 sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x
->x_canvas
);
149 sprintf(s
, ".x%x.c create line ", (t_int
)x
->x_canvas
);
151 for (n
= 0, phase
= x
->x_phase
;
152 n
< SCOPESIZE
; phase
= ((phase
+1) & (SCOPESIZE
-1)), n
++)
154 sprintf(s
, "%fc %fc ", X1
+ (X2
- X1
) * (float)n
* (1./SCOPESIZE
),
155 YC
- 5 * x
->x_samps
[phase
]);
157 /* post("phase %d", phase); */
159 sprintf(s
, "-tags gumbo\n");
165 static void scope_free(t_scope
*x
)
170 static void *scope_new(t_symbol
*s
)
175 t_scope
*x
= (t_scope
*)pd_new(scope_class
);
176 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
179 x
->x_canvas
= canvas_getcurrent();
183 static void scope_setup(void)
185 scope_class
= class_new(gensym("scope~"), (t_newmethod
)scope_new
,
186 (t_method
)scope_free
, sizeof(t_scope
), 0, A_DEFSYM
, 0);
187 class_addmethod(scope_class
, nullfn
, gensym("signal"), 0);
188 class_addmethod(scope_class
, (t_method
)scope_dsp
, gensym("dsp"), 0);
189 class_addbang(scope_class
, scope_bang
);
192 /* ------------------------ bang~ -------------------------- */
194 static t_class
*bang_tilde_class
;
202 static t_int
*bang_tilde_perform(t_int
*w
)
204 t_bang
*x
= (t_bang
*)(w
[1]);
205 clock_delay(x
->x_clock
, 0);
209 static void bang_tilde_dsp(t_bang
*x
, t_signal
**sp
)
214 dsp_add(bang_tilde_perform
, 1, x
);
217 static void bang_tilde_tick(t_bang
*x
)
219 outlet_bang(x
->x_obj
.ob_outlet
);
222 static void bang_tilde_free(t_bang
*x
)
224 clock_free(x
->x_clock
);
227 static void *bang_tilde_new(t_symbol
*s
)
232 t_bang
*x
= (t_bang
*)pd_new(bang_tilde_class
);
233 x
->x_clock
= clock_new(x
, (t_method
)bang_tilde_tick
);
234 outlet_new(&x
->x_obj
, &s_bang
);
238 static void bang_tilde_setup(void)
240 bang_tilde_class
= class_new(gensym("bang~"), (t_newmethod
)bang_tilde_new
,
241 (t_method
)bang_tilde_free
, sizeof(t_bang
), 0, 0);
242 class_addmethod(bang_tilde_class
, (t_method
)bang_tilde_dsp
,
246 /* ------------------------ samplerate~~ -------------------------- */
248 static t_class
*samplerate_tilde_class
;
250 typedef struct _samplerate
255 static void samplerate_tilde_bang(t_samplerate
*x
)
257 outlet_float(x
->x_obj
.ob_outlet
, sys_getsr());
260 static void *samplerate_tilde_new(t_symbol
*s
)
265 t_samplerate
*x
= (t_samplerate
*)pd_new(samplerate_tilde_class
);
266 outlet_new(&x
->x_obj
, &s_float
);
270 static void samplerate_tilde_setup(void)
272 samplerate_tilde_class
= class_new(gensym("samplerate~"),
273 (t_newmethod
)samplerate_tilde_new
, 0, sizeof(t_samplerate
), 0, 0);
274 class_addbang(samplerate_tilde_class
, samplerate_tilde_bang
);
277 /* ------------------------ global setup routine ------------------------- */
279 void d_misc_setup(void)
286 samplerate_tilde_setup();