summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/print~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/print~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/print~.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/print~.c b/apps/plugins/pdbox/PDa/intern/print~.c
new file mode 100644
index 0000000000..3051ca37be
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/print~.c
@@ -0,0 +1,156 @@
1#include <m_pd.h>
2#include <m_fixed.h>
3
4static t_class *print_class;
5
6typedef struct _print
7{
8 t_object x_obj;
9 float x_f;
10 t_symbol *x_sym;
11 int x_count;
12} t_print;
13
14static t_int *print_perform(t_int *w)
15{
16 t_print *x = (t_print *)(w[1]);
17 t_sample *in = (t_sample *)(w[2]);
18 int n = (int)(w[3]);
19 if (x->x_count)
20 {
21 post("%s:", x->x_sym->s_name);
22 if (n == 1) post("%8g", in[0]);
23 else if (n == 2) post("%8g %8g", in[0], in[1]);
24 else if (n == 4) post("%8g %8g %8g %8g",
25 in[0], in[1], in[2], in[3]);
26 else while (n > 0)
27 {
28 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
29 fixtof(in[0]),
30 fixtof(in[1]),
31 fixtof(in[2]),
32 fixtof(in[3]),
33 fixtof(in[4]),
34 fixtof(in[5]),
35 fixtof(in[6]),
36 fixtof(in[7]));
37 n -= 8;
38 in += 8;
39 }
40 x->x_count--;
41 }
42 return (w+4);
43}
44
45static void print_dsp(t_print *x, t_signal **sp)
46{
47 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
48}
49
50static void print_float(t_print *x, t_float f)
51{
52 if (f < 0) f = 0;
53 x->x_count = f;
54}
55
56static void print_bang(t_print *x)
57{
58 x->x_count = 1;
59}
60
61static void *print_new(t_symbol *s)
62{
63 t_print *x = (t_print *)pd_new(print_class);
64 x->x_sym = (s->s_name[0]? s : gensym("print~"));
65 x->x_count = 0;
66 x->x_f = 0;
67 return (x);
68}
69
70void print_tilde_setup(void)
71{
72 print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
73 sizeof(t_print), 0, A_DEFSYM, 0);
74 CLASS_MAINSIGNALIN(print_class, t_print, x_f);
75 class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
76 class_addbang(print_class, print_bang);
77 class_addfloat(print_class, print_float);
78}
79#include <m_pd.h>
80#include <m_fixed.h>
81
82static t_class *print_class;
83
84typedef struct _print
85{
86 t_object x_obj;
87 float x_f;
88 t_symbol *x_sym;
89 int x_count;
90} t_print;
91
92static t_int *print_perform(t_int *w)
93{
94 t_print *x = (t_print *)(w[1]);
95 t_sample *in = (t_sample *)(w[2]);
96 int n = (int)(w[3]);
97 if (x->x_count)
98 {
99 post("%s:", x->x_sym->s_name);
100 if (n == 1) post("%8g", in[0]);
101 else if (n == 2) post("%8g %8g", in[0], in[1]);
102 else if (n == 4) post("%8g %8g %8g %8g",
103 in[0], in[1], in[2], in[3]);
104 else while (n > 0)
105 {
106 post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
107 fixtof(in[0]),
108 fixtof(in[1]),
109 fixtof(in[2]),
110 fixtof(in[3]),
111 fixtof(in[4]),
112 fixtof(in[5]),
113 fixtof(in[6]),
114 fixtof(in[7]));
115 n -= 8;
116 in += 8;
117 }
118 x->x_count--;
119 }
120 return (w+4);
121}
122
123static void print_dsp(t_print *x, t_signal **sp)
124{
125 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
126}
127
128static void print_float(t_print *x, t_float f)
129{
130 if (f < 0) f = 0;
131 x->x_count = f;
132}
133
134static void print_bang(t_print *x)
135{
136 x->x_count = 1;
137}
138
139static void *print_new(t_symbol *s)
140{
141 t_print *x = (t_print *)pd_new(print_class);
142 x->x_sym = (s->s_name[0]? s : gensym("print~"));
143 x->x_count = 0;
144 x->x_f = 0;
145 return (x);
146}
147
148void print_tilde_setup(void)
149{
150 print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
151 sizeof(t_print), 0, A_DEFSYM, 0);
152 CLASS_MAINSIGNALIN(print_class, t_print, x_f);
153 class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
154 class_addbang(print_class, print_bang);
155 class_addfloat(print_class, print_float);
156}