Newer
Older
/* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h> /* for read/write to files */
#include "m_pd.h"
#include "g_canvas.h"
#include <math.h>
Ivica Bukvic
committed
extern int glob_lmclick;
static void garray_select(t_gobj *z, t_glist *glist, int state);
static void garray_doredraw(t_gobj *client, t_glist *glist);
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* jsarlo { */
#define ARRAYPAGESIZE 1000 /* this should match the page size in u_main.tk */
/* } jsarlo */
/* see also the "plot" object in g_scalar.c which deals with graphing
arrays which are fields in scalars. Someday we should unify the
two, but how? */
/* aux routine to bash leading '#' to '$' for dialogs in u_main.tk
which can't send symbols starting with '$' (because the Pd message
interpreter would change them!) */
static t_symbol *sharptodollar(t_symbol *s)
{
if (*s->s_name == '#')
{
char buf[MAXPDSTRING];
strncpy(buf, s->s_name, MAXPDSTRING);
buf[MAXPDSTRING-1] = 0;
buf[0] = '$';
return (gensym(buf));
}
else return (s);
}
/* --------- "pure" arrays with scalars for elements. --------------- */
/* Pure arrays have no a priori graphical capabilities.
They are instantiated by "garrays" below or can be elements of other
scalars (g_scalar.c); their graphical behavior is defined accordingly. */
t_array *array_new(t_symbol *templatesym, t_gpointer *parent)
{
t_array *x = (t_array *)getbytes(sizeof (*x));
t_template *template;
template = template_findbyname(templatesym);
x->a_templatesym = templatesym;
x->a_n = 1;
x->a_elemsize = sizeof(t_word) * template->t_n;
x->a_vec = (char *)getbytes(x->a_elemsize);
/* note here we blithely copy a gpointer instead of "setting" a
new one; this gpointer isn't accounted for and needn't be since
we'll be deleted before the thing pointed to gets deleted anyway;
see array_free. */
x->a_gp = *parent;
x->a_stub = gstub_new(0, x);
word_init((t_word *)(x->a_vec), template, parent);
return (x);
}
/* jsarlo { */
void garray_arrayviewlist_close(t_garray *x);
/* } jsarlo */
void array_resize(t_array *x, int n)
{
Ivica Bukvic
committed
//fprintf(stderr,"array_resize %d\n", n);
int elemsize, oldn;
t_template *template = template_findbyname(x->a_templatesym);
if (n < 1)
n = 1;
oldn = x->a_n;
elemsize = sizeof(t_word) * template->t_n;
x->a_vec = (char *)resizebytes(x->a_vec, oldn * elemsize, n * elemsize);
x->a_n = n;
if (n > oldn)
{
char *cp = x->a_vec + elemsize * oldn;
int i = n - oldn;
for (; i--; cp += elemsize)
{
t_word *wp = (t_word *)cp;
word_init(wp, template, &x->a_gp);
}
}
x->a_valid = ++glist_valid;
}
static void array_resize_and_redraw(t_array *array, t_glist *glist, int n)
{
//fprintf(stderr,"array_resize_and_redraw\n");
t_array *a2 = array;
int vis = glist_isvisible(glist);
while (a2->a_gp.gp_stub->gs_which == GP_ARRAY)
a2 = a2->a_gp.gp_stub->gs_un.gs_array;
if (vis)
gobj_vis(a2->a_gp.gp_un.gp_gobj, glist, 0);
gobj_vis(a2->a_gp.gp_un.gp_gobj, glist, 1);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}
void word_free(t_word *wp, t_template *template);
void array_free(t_array *x)
{
int i;
t_template *scalartemplate = template_findbyname(x->a_templatesym);
gstub_cutoff(x->a_stub);
for (i = 0; i < x->a_n; i++)
{
t_word *wp = (t_word *)(x->a_vec + x->a_elemsize * i);
word_free(wp, scalartemplate);
}
freebytes(x->a_vec, x->a_elemsize * x->a_n);
freebytes(x, sizeof *x);
}
/* --------------------- graphical arrays (garrays) ------------------- */
t_class *garray_class;
static int gcount = 0;
struct _garray
{
t_gobj x_gobj;
t_scalar *x_scalar; /* scalar "containing" the array */
t_glist *x_glist; /* containing glist */
t_symbol *x_name; /* unexpanded name (possibly with leading '$') */
t_symbol *x_realname; /* expanded name (symbol we're bound to) */
char x_usedindsp; /* true if some DSP routine is using this */
char x_saveit; /* true if we should save this with parent */
Ivica Bukvic
committed
char x_joc; /* true if we should "jump on click" in a graph */
char x_listviewing; /* true if list view window is open */
char x_hidename; /* don't print name above graph */
Ivica Bukvic
committed
int x_style; /* so much simpler to keep it here */
t_symbol *x_send; /* send_changed hook */
t_symbol *x_fillcolor; /* color for filled area of the are */
t_symbol *x_outlinecolor; /* color of the outline around the element */
Ivica Bukvic
committed
t_pd *garray_arraytemplatecanvas;
t_pd *garray_floattemplatecanvas;
static char garray_arraytemplatefile[] = "\
#N canvas 0 0 458 153 10;\n\
#X obj 43 31 struct _float_array array z float float style\n\
Ivica Bukvic
committed
float linewidth float color symbol fillcolor symbol outlinecolor;\n\
Jonathan Wilkes
committed
#X obj 43 70 plot z color linewidth 0 0 1 style fillcolor outlinecolor;\n\
";
static char garray_floattemplatefile[] = "\
#N canvas 0 0 458 153 10;\n\
#X obj 39 26 struct float float y;\n\
";
/* create invisible, built-in canvases to determine the templates for floats
and float-arrays. */
void garray_init( void)
{
t_binbuf *b;
if (garray_arraytemplatecanvas)
return;
b = binbuf_new();
glob_setfilename(0, gensym("_float"), gensym("."));
binbuf_text(b, garray_floattemplatefile, strlen(garray_floattemplatefile));
binbuf_eval(b, 0, 0, 0);
Ivica Bukvic
committed
garray_floattemplatecanvas = s__X.s_thing;
vmess(s__X.s_thing, gensym("pop"), "i", 0);
glob_setfilename(0, gensym("_float_array"), gensym("."));
binbuf_text(b, garray_arraytemplatefile, strlen(garray_arraytemplatefile));
binbuf_eval(b, 0, 0, 0);
garray_arraytemplatecanvas = s__X.s_thing;
vmess(s__X.s_thing, gensym("pop"), "i", 0);
glob_setfilename(0, &s_, &s_);
Ivica Bukvic
committed
binbuf_free(b);
}
/* create a new scalar attached to a symbol. Used to make floating-point
arrays (the scalar will be of type "_float_array"). Currently this is
always called by graph_array() below; but when we make a more general way
to save and create arrays this might get called more directly. */
static t_garray *graph_scalar(t_glist *gl, t_symbol *s, t_symbol *templatesym,
Ivica Bukvic
committed
t_symbol *fill, t_symbol *outline, int saveit)
Ivica Bukvic
committed
if (!(template = template_findbyname(templatesym)))
return (0);
Loading
Loading full blame...