A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 89 lines 2.2 kB view raw
1#include "../src/m_pd.h" 2/* ------------------ tabwrite: control ------------------------ */ 3 4static t_class *tabwrite_class; 5 6typedef struct _tabwrite 7{ 8 t_object x_obj; 9 t_symbol *x_arrayname; 10 t_clock *x_clock; 11 float x_ft1; 12 double x_updtime; 13 int x_set; 14} t_tabwrite; 15 16static void tabwrite_tick(t_tabwrite *x) 17{ 18 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); 19 if (!a) bug("tabwrite_tick"); 20 else garray_redraw(a); 21 x->x_set = 0; 22 x->x_updtime = clock_getsystime(); 23} 24 25static void tabwrite_float(t_tabwrite *x, t_float f) 26{ 27#ifdef ROCKBOX 28 int vecsize; 29#else 30 int i, vecsize; 31#endif 32 t_garray *a; 33 t_sample *vec; 34 35 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) 36 pd_error(x, "%s: no such array", x->x_arrayname->s_name); 37 else if (!garray_getfloatarray(a, &vecsize, &vec)) 38 pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name); 39 else 40 { 41 int n = x->x_ft1; 42 double timesince = clock_gettimesince(x->x_updtime); 43 if (n < 0) n = 0; 44 else if (n >= vecsize) n = vecsize-1; 45 vec[n] = ftofix(f); 46 if (timesince > 1000) 47 { 48 tabwrite_tick(x); 49 } 50 else 51 { 52 if (x->x_set == 0) 53 { 54 clock_delay(x->x_clock, 1000 - timesince); 55 x->x_set = 1; 56 } 57 } 58 } 59} 60 61static void tabwrite_set(t_tabwrite *x, t_symbol *s) 62{ 63 x->x_arrayname = s; 64} 65 66static void tabwrite_free(t_tabwrite *x) 67{ 68 clock_free(x->x_clock); 69} 70 71static void *tabwrite_new(t_symbol *s) 72{ 73 t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class); 74 x->x_ft1 = 0; 75 x->x_arrayname = s; 76 x->x_updtime = clock_getsystime(); 77 x->x_clock = clock_new(x, (t_method)tabwrite_tick); 78 floatinlet_new(&x->x_obj, &x->x_ft1); 79 return (x); 80} 81 82void tabwrite_setup(void) 83{ 84 tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new, 85 (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0); 86 class_addfloat(tabwrite_class, (t_method)tabwrite_float); 87 class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0); 88} 89