summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_array.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_array.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_array.c181
1 files changed, 179 insertions, 2 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_array.c b/apps/plugins/pdbox/PDa/src/g_array.c
index 3e2225637a..b6870b6117 100644
--- a/apps/plugins/pdbox/PDa/src/g_array.c
+++ b/apps/plugins/pdbox/PDa/src/g_array.c
@@ -2,12 +2,22 @@
2* For information on usage and redistribution, and for a DISCLAIMER OF ALL 2* For information on usage and redistribution, and for a DISCLAIMER OF ALL
3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ 3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
4 4
5#ifdef ROCKBOX
6#include "plugin.h"
7#include "pdbox.h"
8#include "m_pd.h"
9#include "g_canvas.h"
10#ifdef SIMULATOR
11int printf(const char *fmt, ...);
12#endif /* SIMULATOR */
13#else /* ROCKBOX */
5#include <stdlib.h> 14#include <stdlib.h>
6#include <string.h> 15#include <string.h>
7#include <stdio.h> /* for read/write to files */ 16#include <stdio.h> /* for read/write to files */
8#include "m_pd.h" 17#include "m_pd.h"
9#include "g_canvas.h" 18#include "g_canvas.h"
10#include <math.h> 19#include <math.h>
20#endif /* ROCKBOX */
11 21
12/* see also the "plot" object in g_scalar.c which deals with graphing 22/* see also the "plot" object in g_scalar.c which deals with graphing
13arrays which are fields in scalars. Someday we should unify the 23arrays which are fields in scalars. Someday we should unify the
@@ -40,7 +50,9 @@ t_array *array_new(t_symbol *templatesym, t_gpointer *parent)
40{ 50{
41 t_array *x = (t_array *)getbytes(sizeof (*x)); 51 t_array *x = (t_array *)getbytes(sizeof (*x));
42 t_template *template; 52 t_template *template;
53#ifndef ROCKBOX
43 t_gpointer *gp; 54 t_gpointer *gp;
55#endif
44 template = template_findbyname(templatesym); 56 template = template_findbyname(templatesym);
45 x->a_templatesym = templatesym; 57 x->a_templatesym = templatesym;
46 x->a_n = 1; 58 x->a_n = 1;
@@ -59,7 +71,9 @@ t_array *array_new(t_symbol *templatesym, t_gpointer *parent)
59void array_resize(t_array *x, t_template *template, int n) 71void array_resize(t_array *x, t_template *template, int n)
60{ 72{
61 int elemsize, oldn; 73 int elemsize, oldn;
74#ifndef ROCKBOX
62 t_gpointer *gp; 75 t_gpointer *gp;
76#endif
63 77
64 if (n < 1) 78 if (n < 1)
65 n = 1; 79 n = 1;
@@ -135,7 +149,11 @@ t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
135 if (s == &s_) 149 if (s == &s_)
136 { 150 {
137 char buf[40]; 151 char buf[40];
152#ifdef ROCKBOX
153 snprintf(buf, sizeof(buf)-1, "array%d", ++gcount);
154#else
138 sprintf(buf, "array%d", ++gcount); 155 sprintf(buf, "array%d", ++gcount);
156#endif
139 s = gensym(buf); 157 s = gensym(buf);
140 templatesym = &s_float; 158 templatesym = &s_float;
141 n = 100; 159 n = 100;
@@ -179,7 +197,7 @@ t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
179 x->x_glist = gl; 197 x->x_glist = gl;
180 x->x_usedindsp = 0; 198 x->x_usedindsp = 0;
181 x->x_saveit = (saveit != 0); 199 x->x_saveit = (saveit != 0);
182 if (x2 = pd_findbyclass(gensym("#A"), garray_class)) 200 if((x2 = pd_findbyclass(gensym("#A"), garray_class)))
183 pd_unbind(x2, gensym("#A")); 201 pd_unbind(x2, gensym("#A"));
184 202
185 pd_bind(&x->x_gobj.g_pd, gensym("#A")); 203 pd_bind(&x->x_gobj.g_pd, gensym("#A"));
@@ -190,16 +208,23 @@ t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
190 /* called from array menu item to create a new one */ 208 /* called from array menu item to create a new one */
191void canvas_menuarray(t_glist *canvas) 209void canvas_menuarray(t_glist *canvas)
192{ 210{
211#ifdef ROCKBOX
212 (void) canvas;
213#else /* ROCKBOX */
193 t_glist *x = (t_glist *)canvas; 214 t_glist *x = (t_glist *)canvas;
194 char cmdbuf[200]; 215 char cmdbuf[200];
195 sprintf(cmdbuf, "pdtk_array_dialog %%s array%d 100 1 1\n", 216 sprintf(cmdbuf, "pdtk_array_dialog %%s array%d 100 1 1\n",
196 ++gcount); 217 ++gcount);
197 gfxstub_new(&x->gl_pd, x, cmdbuf); 218 gfxstub_new(&x->gl_pd, x, cmdbuf);
219#endif /* ROCKBOX */
198} 220}
199 221
200 /* called from graph_dialog to set properties */ 222 /* called from graph_dialog to set properties */
201void garray_properties(t_garray *x) 223void garray_properties(t_garray *x)
202{ 224{
225#ifdef ROCKBOX
226 (void) x;
227#else /* ROCKBOX */
203 char cmdbuf[200]; 228 char cmdbuf[200];
204 gfxstub_deleteforkey(x); 229 gfxstub_deleteforkey(x);
205 /* create dialog window. LATER fix this to escape '$' 230 /* create dialog window. LATER fix this to escape '$'
@@ -211,6 +236,7 @@ void garray_properties(t_garray *x)
211 else sprintf(cmdbuf, "pdtk_array_dialog %%s %s %d %d 0\n", 236 else sprintf(cmdbuf, "pdtk_array_dialog %%s %s %d %d 0\n",
212 x->x_name->s_name, x->x_n, x->x_saveit); 237 x->x_name->s_name, x->x_n, x->x_saveit);
213 gfxstub_new(&x->x_gobj.g_pd, x, cmdbuf); 238 gfxstub_new(&x->x_gobj.g_pd, x, cmdbuf);
239#endif /* ROCKBOX */
214} 240}
215 241
216 /* this is called back from the dialog window to create a garray. 242 /* this is called back from the dialog window to create a garray.
@@ -260,10 +286,12 @@ void garray_arraydialog(t_garray *x, t_symbol *name, t_floatarg fsize,
260static void garray_free(t_garray *x) 286static void garray_free(t_garray *x)
261{ 287{
262 t_pd *x2; 288 t_pd *x2;
289#ifndef ROCKBOX
263 gfxstub_deleteforkey(x); 290 gfxstub_deleteforkey(x);
291#endif
264 pd_unbind(&x->x_gobj.g_pd, x->x_realname); 292 pd_unbind(&x->x_gobj.g_pd, x->x_realname);
265 /* LATER find a way to get #A unbound earlier (at end of load?) */ 293 /* LATER find a way to get #A unbound earlier (at end of load?) */
266 while (x2 = pd_findbyclass(gensym("#A"), garray_class)) 294 while((x2 = pd_findbyclass(gensym("#A"), garray_class)))
267 pd_unbind(x2, gensym("#A")); 295 pd_unbind(x2, gensym("#A"));
268 freebytes(x->x_vec, x->x_n * x->x_elemsize); 296 freebytes(x->x_vec, x->x_n * x->x_elemsize);
269} 297}
@@ -308,7 +336,9 @@ static t_word *array_motion_wp;
308static t_template *array_motion_template; 336static t_template *array_motion_template;
309static int array_motion_npoints; 337static int array_motion_npoints;
310static int array_motion_elemsize; 338static int array_motion_elemsize;
339#ifndef ROCKBOX
311static int array_motion_altkey; 340static int array_motion_altkey;
341#endif
312static float array_motion_initx; 342static float array_motion_initx;
313static float array_motion_xperpix; 343static float array_motion_xperpix;
314static float array_motion_yperpix; 344static float array_motion_yperpix;
@@ -320,6 +350,9 @@ static int array_motion_fatten;
320 350
321static void array_motion(void *z, t_floatarg dx, t_floatarg dy) 351static void array_motion(void *z, t_floatarg dx, t_floatarg dy)
322{ 352{
353#ifdef ROCKBOX
354 (void) z;
355#endif
323 array_motion_xcumulative += dx * array_motion_xperpix; 356 array_motion_xcumulative += dx * array_motion_xperpix;
324 array_motion_ycumulative += dy * array_motion_yperpix; 357 array_motion_ycumulative += dy * array_motion_yperpix;
325 if (*array_motion_xfield->s_name) 358 if (*array_motion_xfield->s_name)
@@ -402,6 +435,12 @@ int array_doclick(t_array *array, t_glist *glist, t_gobj *gobj,
402 t_template *elemtemplate; 435 t_template *elemtemplate;
403 int elemsize, yonset, wonset, xonset, i; 436 int elemsize, yonset, wonset, xonset, i;
404 437
438#ifdef ROCKBOX
439 (void) linewidth;
440 (void) shift;
441 (void) dbl;
442#endif
443
405 if (!array_getfields(elemtemplatesym, &elemtemplatecanvas, 444 if (!array_getfields(elemtemplatesym, &elemtemplatecanvas,
406 &elemtemplate, &elemsize, &xonset, &yonset, &wonset)) 445 &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
407 { 446 {
@@ -575,7 +614,11 @@ static void garray_getrect(t_gobj *z, t_glist *glist,
575 else incr = x->x_array.a_n / 300; 614 else incr = x->x_array.a_n / 300;
576 for (i = 0; i < x->x_array.a_n; i += incr) 615 for (i = 0; i < x->x_array.a_n; i += incr)
577 { 616 {
617#ifdef ROCKBOX
618 float pxpix, pypix, pwpix;
619#else /* ROCKBOX */
578 float pxpix, pypix, pwpix, dx, dy; 620 float pxpix, pypix, pwpix, dx, dy;
621#endif /* ROCKBOX */
579 array_getcoordinate(glist, (char *)(x->x_array.a_vec) + 622 array_getcoordinate(glist, (char *)(x->x_array.a_vec) +
580 i * elemsize, 623 i * elemsize,
581 xonset, yonset, wonset, i, 0, 0, 1, 624 xonset, yonset, wonset, i, 0, 0, 1,
@@ -600,21 +643,42 @@ static void garray_getrect(t_gobj *z, t_glist *glist,
600 643
601static void garray_displace(t_gobj *z, t_glist *glist, int dx, int dy) 644static void garray_displace(t_gobj *z, t_glist *glist, int dx, int dy)
602{ 645{
646#ifdef ROCKBOX
647 (void) z;
648 (void) glist;
649 (void) dx;
650 (void) dy;
651#endif
603 /* refuse */ 652 /* refuse */
604} 653}
605 654
606static void garray_select(t_gobj *z, t_glist *glist, int state) 655static void garray_select(t_gobj *z, t_glist *glist, int state)
607{ 656{
657#ifdef ROCKBOX
658 (void) z;
659 (void) glist;
660 (void) state;
661#else /* ROCKBOX */
608 t_garray *x = (t_garray *)z; 662 t_garray *x = (t_garray *)z;
663#endif /* ROCKBOX */
609 /* fill in later */ 664 /* fill in later */
610} 665}
611 666
612static void garray_activate(t_gobj *z, t_glist *glist, int state) 667static void garray_activate(t_gobj *z, t_glist *glist, int state)
613{ 668{
669#ifdef ROCKBOX
670 (void) z;
671 (void) glist;
672 (void) state;
673#endif
614} 674}
615 675
616static void garray_delete(t_gobj *z, t_glist *glist) 676static void garray_delete(t_gobj *z, t_glist *glist)
617{ 677{
678#ifdef ROCKBOX
679 (void) z;
680 (void) glist;
681#endif
618 /* nothing to do */ 682 /* nothing to do */
619} 683}
620 684
@@ -633,9 +697,11 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
633 { 697 {
634 error("%s: needs floating-point 'y' field", 698 error("%s: needs floating-point 'y' field",
635 x->x_templatesym->s_name); 699 x->x_templatesym->s_name);
700#ifndef ROCKBOX
636 sys_vgui(".x%x.c create text 50 50 -text foo\ 701 sys_vgui(".x%x.c create text 50 50 -text foo\
637 -tags .x%x.a%x\n", 702 -tags .x%x.a%x\n",
638 glist_getcanvas(glist), glist_getcanvas(glist), x); 703 glist_getcanvas(glist), glist_getcanvas(glist), x);
704#endif
639 } 705 }
640 else if (!template_find_field(template, gensym("x"), &xonset, &type, 706 else if (!template_find_field(template, gensym("x"), &xonset, &type,
641 &arraytype) || type != DT_FLOAT) 707 &arraytype) || type != DT_FLOAT)
@@ -644,7 +710,9 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
644 int lastpixel = -1, ndrawn = 0; 710 int lastpixel = -1, ndrawn = 0;
645 float yval = 0, xpix; 711 float yval = 0, xpix;
646 int ixpix = 0; 712 int ixpix = 0;
713#ifndef ROCKBOX
647 sys_vgui(".x%x.c create line \\\n", glist_getcanvas(glist)); 714 sys_vgui(".x%x.c create line \\\n", glist_getcanvas(glist));
715#endif
648 for (i = 0; i < x->x_n; i++) 716 for (i = 0; i < x->x_n; i++)
649 { 717 {
650 yval = fixtof(*(t_sample *)(x->x_vec + 718 yval = fixtof(*(t_sample *)(x->x_vec +
@@ -653,8 +721,10 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
653 ixpix = xpix + 0.5; 721 ixpix = xpix + 0.5;
654 if (ixpix != lastpixel) 722 if (ixpix != lastpixel)
655 { 723 {
724#ifndef ROCKBOX
656 sys_vgui("%d %f \\\n", ixpix, 725 sys_vgui("%d %f \\\n", ixpix,
657 glist_ytopixels(glist, yval)); 726 glist_ytopixels(glist, yval));
727#endif
658 ndrawn++; 728 ndrawn++;
659 } 729 }
660 lastpixel = ixpix; 730 lastpixel = ixpix;
@@ -662,11 +732,14 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
662 xcum += x->x_xinc; 732 xcum += x->x_xinc;
663 } 733 }
664 /* TK will complain if there aren't at least 2 points... */ 734 /* TK will complain if there aren't at least 2 points... */
735#ifndef ROCKBOX
665 if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n"); 736 if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n");
666 else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix, 737 else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix,
667 glist_ytopixels(glist, yval)); 738 glist_ytopixels(glist, yval));
668 sys_vgui("-tags .x%x.a%x\n", glist_getcanvas(glist), x); 739 sys_vgui("-tags .x%x.a%x\n", glist_getcanvas(glist), x);
740#endif
669 firsty = fixtof(*(t_sample *)(x->x_vec + yonset)); 741 firsty = fixtof(*(t_sample *)(x->x_vec + yonset));
742#ifndef ROCKBOX
670 sys_vgui(".x%x.c create text %f %f -text {%s} -anchor e\ 743 sys_vgui(".x%x.c create text %f %f -text {%s} -anchor e\
671 -font -*-courier-bold--normal--%d-* -tags .x%x.a%x\n", 744 -font -*-courier-bold--normal--%d-* -tags .x%x.a%x\n",
672 glist_getcanvas(glist), 745 glist_getcanvas(glist),
@@ -674,6 +747,7 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
674 glist_ytopixels(glist, firsty), 747 glist_ytopixels(glist, firsty),
675 x->x_name->s_name, glist_getfont(glist), 748 x->x_name->s_name, glist_getfont(glist),
676 glist_getcanvas(glist), x); 749 glist_getcanvas(glist), x);
750#endif
677 } 751 }
678 else 752 else
679 { 753 {
@@ -682,8 +756,10 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
682 } 756 }
683 else 757 else
684 { 758 {
759#ifndef ROCKBOX
685 sys_vgui(".x%x.c delete .x%x.a%x\n", 760 sys_vgui(".x%x.c delete .x%x.a%x\n",
686 glist_getcanvas(glist), glist_getcanvas(glist), x); 761 glist_getcanvas(glist), glist_getcanvas(glist), x);
762#endif
687 } 763 }
688} 764}
689 765
@@ -702,7 +778,13 @@ static void garray_save(t_gobj *z, t_binbuf *b)
702 t_garray *x = (t_garray *)z; 778 t_garray *x = (t_garray *)z;
703 binbuf_addv(b, "sssisi;", gensym("#X"), gensym("array"), 779 binbuf_addv(b, "sssisi;", gensym("#X"), gensym("array"),
704 x->x_name, x->x_n, x->x_templatesym, x->x_saveit); 780 x->x_name, x->x_n, x->x_templatesym, x->x_saveit);
781#ifdef ROCKBOX
782#ifdef SIMULATOR
783 printf("array save\n");
784#endif /* SIMULATOR */
785#else /* ROCKBOX */
705 fprintf(stderr,"array save\n"); 786 fprintf(stderr,"array save\n");
787#endif /* ROCKBOX */
706 if (x->x_saveit) 788 if (x->x_saveit)
707 { 789 {
708 int n = x->x_n, n2 = 0; 790 int n = x->x_n, n2 = 0;
@@ -877,7 +959,11 @@ static void garray_dofo(t_garray *x, int npoints, float dcval,
877 959
878static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) 960static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
879{ 961{
962#ifdef ROCKBOX
963 (void) s;
964#else
880 t_template *template = garray_template(x); 965 t_template *template = garray_template(x);
966#endif
881 967
882 t_float *svec = (t_float *)t_getbytes(sizeof(t_float) * argc); 968 t_float *svec = (t_float *)t_getbytes(sizeof(t_float) * argc);
883 int npoints, i; 969 int npoints, i;
@@ -902,7 +988,11 @@ static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
902 988
903static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) 989static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
904{ 990{
991#ifdef ROCKBOX
992 (void) s;
993#else
905 t_template *template = garray_template(x); 994 t_template *template = garray_template(x);
995#endif
906 996
907 t_float *svec = (t_float *)t_getbytes(sizeof(t_float) * argc); 997 t_float *svec = (t_float *)t_getbytes(sizeof(t_float) * argc);
908 int npoints, i; 998 int npoints, i;
@@ -928,7 +1018,11 @@ static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
928static void garray_normalize(t_garray *x, t_float f) 1018static void garray_normalize(t_garray *x, t_float f)
929{ 1019{
930 t_template *template = garray_template(x); 1020 t_template *template = garray_template(x);
1021#ifdef ROCKBOX
1022 int yonset, type, i;
1023#else
931 int yonset, type, npoints, i; 1024 int yonset, type, npoints, i;
1025#endif
932 double maxv, renormer; 1026 double maxv, renormer;
933 t_symbol *arraytype; 1027 t_symbol *arraytype;
934 1028
@@ -968,6 +1062,9 @@ static void garray_list(t_garray *x, t_symbol *s, int argc, t_atom *argv)
968 t_template *template = garray_template(x); 1062 t_template *template = garray_template(x);
969 int yonset, type, i; 1063 int yonset, type, i;
970 t_symbol *arraytype; 1064 t_symbol *arraytype;
1065#ifdef ROCKBOX
1066 (void) s;
1067#endif
971 if (!template_find_field(template, gensym("y"), &yonset, 1068 if (!template_find_field(template, gensym("y"), &yonset,
972 &type, &arraytype) || type != DT_FLOAT) 1069 &type, &arraytype) || type != DT_FLOAT)
973 error("%s: needs floating-point 'y' field", 1070 error("%s: needs floating-point 'y' field",
@@ -1038,7 +1135,11 @@ static void garray_rename(t_garray *x, t_symbol *s)
1038static void garray_read(t_garray *x, t_symbol *filename) 1135static void garray_read(t_garray *x, t_symbol *filename)
1039{ 1136{
1040 int nelem = x->x_n, filedesc; 1137 int nelem = x->x_n, filedesc;
1138#ifdef ROCKBOX
1139 int fd = 0;
1140#else
1041 FILE *fd; 1141 FILE *fd;
1142#endif
1042 char buf[MAXPDSTRING], *bufptr; 1143 char buf[MAXPDSTRING], *bufptr;
1043 t_template *template = garray_template(x); 1144 t_template *template = garray_template(x);
1044 int yonset, type, i; 1145 int yonset, type, i;
@@ -1052,15 +1153,23 @@ static void garray_read(t_garray *x, t_symbol *filename)
1052 if ((filedesc = open_via_path( 1153 if ((filedesc = open_via_path(
1053 canvas_getdir(glist_getcanvas(x->x_glist))->s_name, 1154 canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
1054 filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0 1155 filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0
1156#ifdef ROCKBOX
1157 )
1158#else
1055 || !(fd = fdopen(filedesc, "r"))) 1159 || !(fd = fdopen(filedesc, "r")))
1160#endif
1056 { 1161 {
1057 error("%s: can't open", filename->s_name); 1162 error("%s: can't open", filename->s_name);
1058 return; 1163 return;
1059 } 1164 }
1060 for (i = 0; i < nelem; i++) 1165 for (i = 0; i < nelem; i++)
1061 { 1166 {
1167#ifdef ROCKBOX
1168 if(rb_fscanf_f(fd, (float*)((x->x_vec + sizeof(t_word) * i) + yonset)))
1169#else
1062 if (!fscanf(fd, "%f", (float *)((x->x_vec + sizeof(t_word) * i) + 1170 if (!fscanf(fd, "%f", (float *)((x->x_vec + sizeof(t_word) * i) +
1063 yonset))) 1171 yonset)))
1172#endif
1064 { 1173 {
1065 post("%s: read %d elements into table of size %d", 1174 post("%s: read %d elements into table of size %d",
1066 filename->s_name, i, nelem); 1175 filename->s_name, i, nelem);
@@ -1069,7 +1178,11 @@ static void garray_read(t_garray *x, t_symbol *filename)
1069 } 1178 }
1070 while (i < nelem) 1179 while (i < nelem)
1071 *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = 0, i++; 1180 *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = 0, i++;
1181#ifdef ROCKBOX
1182 close(fd);
1183#else
1072 fclose(fd); 1184 fclose(fd);
1185#endif
1073 garray_redraw(x); 1186 garray_redraw(x);
1074} 1187}
1075 1188
@@ -1090,7 +1203,11 @@ static void garray_read16(t_garray *x, t_symbol *filename,
1090 int skip = fskip, filedesc; 1203 int skip = fskip, filedesc;
1091 int i, nelem; 1204 int i, nelem;
1092 t_sample *vec; 1205 t_sample *vec;
1206#ifdef ROCKBOX
1207 int fd = 0;
1208#else
1093 FILE *fd; 1209 FILE *fd;
1210#endif
1094 char buf[MAXPDSTRING], *bufptr; 1211 char buf[MAXPDSTRING], *bufptr;
1095 short s; 1212 short s;
1096 int cpubig = garray_ambigendian(), swap = 0; 1213 int cpubig = garray_ambigendian(), swap = 0;
@@ -1116,25 +1233,41 @@ static void garray_read16(t_garray *x, t_symbol *filename,
1116 if ((filedesc = open_via_path( 1233 if ((filedesc = open_via_path(
1117 canvas_getdir(glist_getcanvas(x->x_glist))->s_name, 1234 canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
1118 filename->s_name, "", buf, &bufptr, MAXPDSTRING, 1)) < 0 1235 filename->s_name, "", buf, &bufptr, MAXPDSTRING, 1)) < 0
1236#ifdef ROCKBOX
1237 )
1238#else
1119 || !(fd = fdopen(filedesc, BINREADMODE))) 1239 || !(fd = fdopen(filedesc, BINREADMODE)))
1240#endif
1120 { 1241 {
1121 error("%s: can't open", filename->s_name); 1242 error("%s: can't open", filename->s_name);
1122 return; 1243 return;
1123 } 1244 }
1124 if (skip) 1245 if (skip)
1125 { 1246 {
1247#ifdef ROCKBOX
1248 long pos = lseek(fd, (long)skip, SEEK_SET);
1249#else
1126 long pos = fseek(fd, (long)skip, SEEK_SET); 1250 long pos = fseek(fd, (long)skip, SEEK_SET);
1251#endif
1127 if (pos < 0) 1252 if (pos < 0)
1128 { 1253 {
1129 error("%s: can't seek to byte %d", buf, skip); 1254 error("%s: can't seek to byte %d", buf, skip);
1255#ifdef ROCKBOX
1256 close(fd);
1257#else
1130 fclose(fd); 1258 fclose(fd);
1259#endif
1131 return; 1260 return;
1132 } 1261 }
1133 } 1262 }
1134 1263
1135 for (i = 0; i < nelem; i++) 1264 for (i = 0; i < nelem; i++)
1136 { 1265 {
1266#ifdef ROCKBOX
1267 if(read(fd, &s, sizeof(s)) < 1)
1268#else
1137 if (fread(&s, sizeof(s), 1, fd) < 1) 1269 if (fread(&s, sizeof(s), 1, fd) < 1)
1270#endif
1138 { 1271 {
1139 post("%s: read %d elements into table of size %d", 1272 post("%s: read %d elements into table of size %d",
1140 filename->s_name, i, nelem); 1273 filename->s_name, i, nelem);
@@ -1144,13 +1277,21 @@ static void garray_read16(t_garray *x, t_symbol *filename,
1144 vec[i] = s * (1./32768.); 1277 vec[i] = s * (1./32768.);
1145 } 1278 }
1146 while (i < nelem) vec[i++] = 0; 1279 while (i < nelem) vec[i++] = 0;
1280#ifdef ROCKBOX
1281 close(fd);
1282#else
1147 fclose(fd); 1283 fclose(fd);
1284#endif
1148 garray_redraw(x); 1285 garray_redraw(x);
1149} 1286}
1150 1287
1151static void garray_write(t_garray *x, t_symbol *filename) 1288static void garray_write(t_garray *x, t_symbol *filename)
1152{ 1289{
1290#ifdef ROCKBOX
1291 int fd;
1292#else
1153 FILE *fd; 1293 FILE *fd;
1294#endif
1154 char buf[MAXPDSTRING]; 1295 char buf[MAXPDSTRING];
1155 t_template *template = garray_template(x); 1296 t_template *template = garray_template(x);
1156 int yonset, type, i; 1297 int yonset, type, i;
@@ -1164,21 +1305,33 @@ static void garray_write(t_garray *x, t_symbol *filename)
1164 canvas_makefilename(glist_getcanvas(x->x_glist), filename->s_name, 1305 canvas_makefilename(glist_getcanvas(x->x_glist), filename->s_name,
1165 buf, MAXPDSTRING); 1306 buf, MAXPDSTRING);
1166 sys_bashfilename(buf, buf); 1307 sys_bashfilename(buf, buf);
1308#ifdef ROCKBOX
1309 if(!(fd = open(buf, O_WRONLY|O_CREAT|O_TRUNC)))
1310#else
1167 if (!(fd = fopen(buf, "w"))) 1311 if (!(fd = fopen(buf, "w")))
1312#endif
1168 { 1313 {
1169 error("%s: can't create", buf); 1314 error("%s: can't create", buf);
1170 return; 1315 return;
1171 } 1316 }
1172 for (i = 0; i < x->x_n; i++) 1317 for (i = 0; i < x->x_n; i++)
1173 { 1318 {
1319#ifdef ROCKBOX
1320 if(rb_fprintf_f(fd,
1321#else /* ROCKBOX */
1174 if (fprintf(fd, "%g\n", 1322 if (fprintf(fd, "%g\n",
1323#endif /* ROCKBOX */
1175 *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)) < 1) 1324 *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)) < 1)
1176 { 1325 {
1177 post("%s: write error", filename->s_name); 1326 post("%s: write error", filename->s_name);
1178 break; 1327 break;
1179 } 1328 }
1180 } 1329 }
1330#ifdef ROCKBOX
1331 close(fd);
1332#else
1181 fclose(fd); 1333 fclose(fd);
1334#endif
1182} 1335}
1183 1336
1184static unsigned char waveheader[] = { 1337static unsigned char waveheader[] = {
@@ -1203,7 +1356,11 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
1203 t_template *template = garray_template(x); 1356 t_template *template = garray_template(x);
1204 int yonset, type, i; 1357 int yonset, type, i;
1205 t_symbol *arraytype; 1358 t_symbol *arraytype;
1359#ifdef ROCKBOX
1360 int fd;
1361#else
1206 FILE *fd; 1362 FILE *fd;
1363#endif
1207 int aiff = (format == gensym("aiff")); 1364 int aiff = (format == gensym("aiff"));
1208 char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; 1365 char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING];
1209 int swap = garray_ambigendian(); /* wave is only little endian */ 1366 int swap = garray_ambigendian(); /* wave is only little endian */
@@ -1230,7 +1387,11 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
1230 canvas_makefilename(glist_getcanvas(x->x_glist), filenamebuf, 1387 canvas_makefilename(glist_getcanvas(x->x_glist), filenamebuf,
1231 buf2, MAXPDSTRING); 1388 buf2, MAXPDSTRING);
1232 sys_bashfilename(buf2, buf2); 1389 sys_bashfilename(buf2, buf2);
1390#ifdef ROCKBOX
1391 if(!(fd = open(buf2, O_WRONLY|O_CREAT|O_TRUNC)))
1392#else
1233 if (!(fd = fopen(buf2, BINWRITEMODE))) 1393 if (!(fd = fopen(buf2, BINWRITEMODE)))
1394#endif
1234 { 1395 {
1235 error("%s: can't create", buf2); 1396 error("%s: can't create", buf2);
1236 return; 1397 return;
@@ -1251,7 +1412,11 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
1251 xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx; 1412 xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx;
1252 } 1413 }
1253 memcpy((void *)(waveheader + 40), (void *)(&intbuf), 4); 1414 memcpy((void *)(waveheader + 40), (void *)(&intbuf), 4);
1415#ifdef ROCKBOX
1416 if(write(fd, waveheader, sizeof(waveheader)) < 1)
1417#else
1254 if (fwrite(waveheader, sizeof(waveheader), 1, fd) < 1) 1418 if (fwrite(waveheader, sizeof(waveheader), 1, fd) < 1)
1419#endif
1255 { 1420 {
1256 post("%s: write error", buf2); 1421 post("%s: write error", buf2);
1257 goto closeit; 1422 goto closeit;
@@ -1268,21 +1433,31 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
1268 unsigned char *foo = (unsigned char *)&sh, xxx; 1433 unsigned char *foo = (unsigned char *)&sh, xxx;
1269 xxx = foo[0]; foo[0] = foo[1]; foo[1] = xxx; 1434 xxx = foo[0]; foo[0] = foo[1]; foo[1] = xxx;
1270 } 1435 }
1436#ifdef ROCKBOX
1437 if(write(fd, &sh, sizeof(sh)) < 1)
1438#else
1271 if (fwrite(&sh, sizeof(sh), 1, fd) < 1) 1439 if (fwrite(&sh, sizeof(sh), 1, fd) < 1)
1440#endif
1272 { 1441 {
1273 post("%s: write error", buf2); 1442 post("%s: write error", buf2);
1274 goto closeit; 1443 goto closeit;
1275 } 1444 }
1276 } 1445 }
1277closeit: 1446closeit:
1447#ifdef ROCKBOX
1448 close(fd);
1449#else
1278 fclose(fd); 1450 fclose(fd);
1451#endif
1279} 1452}
1280 1453
1281void garray_resize(t_garray *x, t_floatarg f) 1454void garray_resize(t_garray *x, t_floatarg f)
1282{ 1455{
1283 int was = x->x_n, elemsize; 1456 int was = x->x_n, elemsize;
1284 t_glist *gl; 1457 t_glist *gl;
1458#ifndef ROCKBOX
1285 int dspwas; 1459 int dspwas;
1460#endif
1286 int n = f; 1461 int n = f;
1287 char *nvec; 1462 char *nvec;
1288 1463
@@ -1309,7 +1484,9 @@ void garray_resize(t_garray *x, t_floatarg f)
1309 vmess(&gl->gl_pd, gensym("bounds"), "ffff", 1484 vmess(&gl->gl_pd, gensym("bounds"), "ffff",
1310 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2); 1485 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
1311 /* close any dialogs that might have the wrong info now... */ 1486 /* close any dialogs that might have the wrong info now... */
1487#ifndef ROCKBOX
1312 gfxstub_deleteforkey(gl); 1488 gfxstub_deleteforkey(gl);
1489#endif
1313 } 1490 }
1314 else garray_redraw(x); 1491 else garray_redraw(x);
1315 if (x->x_usedindsp) canvas_update_dsp(); 1492 if (x->x_usedindsp) canvas_update_dsp();