A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
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. */
4
5/* miscellaneous: print~; more to come.
6*/
7
8#ifdef ROCKBOX
9#include "plugin.h"
10#include "../../pdbox.h"
11#endif
12
13#include "m_pd.h"
14
15#ifndef ROCKBOX
16#include <stdio.h>
17#include <string.h>
18#endif
19
20/* ------------------------- print~ -------------------------- */
21static t_class *print_class;
22
23typedef struct _print
24{
25 t_object x_obj;
26 float x_f;
27 t_symbol *x_sym;
28 int x_count;
29} t_print;
30
31static t_int *print_perform(t_int *w)
32{
33 t_print *x = (t_print *)(w[1]);
34 t_float *in = (t_float *)(w[2]);
35 int n = (int)(w[3]);
36 if (x->x_count)
37 {
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]);
43 else while (n > 0)
44 {
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]);
47 n -= 8;
48 in += 8;
49 }
50 x->x_count--;
51 }
52 return (w+4);
53}
54
55static void print_dsp(t_print *x, t_signal **sp)
56{
57 dsp_add(print_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
58}
59
60static void print_float(t_print *x, t_float f)
61{
62 if (f < 0) f = 0;
63 x->x_count = f;
64}
65
66static void print_bang(t_print *x)
67{
68 x->x_count = 1;
69}
70
71static void *print_new(t_symbol *s)
72{
73 t_print *x = (t_print *)pd_new(print_class);
74 x->x_sym = (s->s_name[0]? s : gensym("print~"));
75 x->x_count = 0;
76 x->x_f = 0;
77 return (x);
78}
79
80#ifndef ROCKBOX
81static
82#endif
83void print_setup(void)
84{
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);
91}
92
93/* ------------------------- scope~ -------------------------- */
94/* this has been replaced by arrays; to be deleted later */
95
96#include "g_canvas.h"
97
98static t_class *scope_class;
99
100#define SCOPESIZE 256
101
102typedef struct _scope
103{
104 t_object x_obj;
105 t_sample x_samps[SCOPESIZE];
106 int x_phase;
107 int x_drawn;
108 void *x_canvas;
109} t_scope;
110
111static t_int *scope_perform(t_int *w)
112{
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;
116 while (n--)
117 {
118 x->x_samps[phase] = *in++;
119 phase = (phase + 1) & (SCOPESIZE-1);
120 }
121 x->x_phase = phase;
122 return (w+4);
123}
124
125static void scope_dsp(t_scope *x, t_signal **sp)
126{
127 dsp_add(scope_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
128}
129
130static void scope_erase(t_scope *x)
131{
132#ifdef ROCKBOX
133 (void) x;
134#else
135 if (x->x_drawn) sys_vgui(".x%x.c delete gumbo\n", x->x_canvas);
136#endif
137}
138
139#define X1 10.
140#define X2 20.
141#define YC 5.
142static void scope_bang(t_scope *x)
143{
144#ifndef ROCKBOX
145 int n, phase;
146 char hugebuf[10000], *s = hugebuf;
147 scope_erase(x);
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);
150 s += strlen(s);
151 for (n = 0, phase = x->x_phase;
152 n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
153 {
154 sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
155 YC - 5 * x->x_samps[phase]);
156 s += strlen(s);
157 /* post("phase %d", phase); */
158 }
159 sprintf(s, "-tags gumbo\n");
160 sys_gui(hugebuf);
161#endif
162 x->x_drawn = 1;
163}
164
165static void scope_free(t_scope *x)
166{
167 scope_erase(x);
168}
169
170static void *scope_new(t_symbol *s)
171{
172#ifdef ROCKBOX
173 (void) s;
174#endif
175 t_scope *x = (t_scope *)pd_new(scope_class);
176 error("scope: this is now obsolete; use arrays and tabwrite~ instead");
177 x->x_phase = 0;
178 x->x_drawn = 0;
179 x->x_canvas = canvas_getcurrent();
180 return (x);
181}
182
183static void scope_setup(void)
184{
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);
190}
191
192/* ------------------------ bang~ -------------------------- */
193
194static t_class *bang_tilde_class;
195
196typedef struct _bang
197{
198 t_object x_obj;
199 t_clock *x_clock;
200} t_bang;
201
202static t_int *bang_tilde_perform(t_int *w)
203{
204 t_bang *x = (t_bang *)(w[1]);
205 clock_delay(x->x_clock, 0);
206 return (w+2);
207}
208
209static void bang_tilde_dsp(t_bang *x, t_signal **sp)
210{
211#ifdef ROCKBOX
212 (void) sp;
213#endif
214 dsp_add(bang_tilde_perform, 1, x);
215}
216
217static void bang_tilde_tick(t_bang *x)
218{
219 outlet_bang(x->x_obj.ob_outlet);
220}
221
222static void bang_tilde_free(t_bang *x)
223{
224 clock_free(x->x_clock);
225}
226
227static void *bang_tilde_new(t_symbol *s)
228{
229#ifdef ROCKBOX
230 (void) s;
231#endif
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);
235 return (x);
236}
237
238static void bang_tilde_setup(void)
239{
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,
243 gensym("dsp"), 0);
244}
245
246/* ------------------------ samplerate~~ -------------------------- */
247
248static t_class *samplerate_tilde_class;
249
250typedef struct _samplerate
251{
252 t_object x_obj;
253} t_samplerate;
254
255static void samplerate_tilde_bang(t_samplerate *x)
256{
257 outlet_float(x->x_obj.ob_outlet, sys_getsr());
258}
259
260static void *samplerate_tilde_new(t_symbol *s)
261{
262#ifdef ROCKBOX
263 (void) s;
264#endif
265 t_samplerate *x = (t_samplerate *)pd_new(samplerate_tilde_class);
266 outlet_new(&x->x_obj, &s_float);
267 return (x);
268}
269
270static void samplerate_tilde_setup(void)
271{
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);
275}
276
277/* ------------------------ global setup routine ------------------------- */
278
279void d_misc_setup(void)
280{
281#ifndef FIXEDPOINT
282 print_setup();
283#endif
284 scope_setup();
285 bang_tilde_setup();
286 samplerate_tilde_setup();
287}
288