x_interface.c 47.7 KB
Newer Older
Miller Puckette's avatar
Miller Puckette committed
1
2
3
4
5
6
7
/* 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.  */

/* interface objects */

#include "m_pd.h"
8
#include "m_imp.h"
9
#include "g_canvas.h"
10
#include "s_stuff.h"
11
12
13
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Miller Puckette's avatar
Miller Puckette committed
14

15
#if PD_FLOATSIZE == 32
16
#define FLOAT_SPECIFIER "%.6g"
17
#elif PD_FLOATSIZE == 64
18
#define FLOAT_SPECIFIER "%.14g"
19
20
#endif

21
22
23
24
25
/* we need the following for [pdinfo] ... */

#define MAXNDEV 20
#define DEVDESCSIZE 80

26
27


Miller Puckette's avatar
Miller Puckette committed
28
/* -------------------------- print ------------------------------ */
29
t_class *print_class;
Miller Puckette's avatar
Miller Puckette committed
30
31
32
33
34
35
36

typedef struct _print
{
    t_object x_obj;
    t_symbol *x_sym;
} t_print;

37
static void *print_new(t_symbol *sel, int argc, t_atom *argv)
Miller Puckette's avatar
Miller Puckette committed
38
39
{
    t_print *x = (t_print *)pd_new(print_class);
40
41
42
43
44
45
46
47
48
49
    if (argc == 0)
        x->x_sym = gensym("print");
    else if (argc == 1 && argv->a_type == A_SYMBOL)
    {
        t_symbol *s = atom_getsymbolarg(0, argc, argv);
        if (!strcmp(s->s_name, "-n"))
            x->x_sym = &s_;
        else x->x_sym = s;
    }
    else
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
50
    {
51
52
        int bufsize;
        char *buf;
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
53
54
55
        t_binbuf *bb = binbuf_new();
        binbuf_add(bb, argc, argv);
        binbuf_gettext(bb, &buf, &bufsize);
56
        buf = resizebytes(buf, bufsize, bufsize+1);
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
57
58
        buf[bufsize] = 0;
        x->x_sym = gensym(buf);
59
        freebytes(buf, bufsize+1);
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
60
61
        binbuf_free(bb);
    }
Miller Puckette's avatar
Miller Puckette committed
62
63
64
65
66
    return (x);
}

static void print_bang(t_print *x)
{
67
    if (sys_nogui || sys_printhook)
68
69
70
71
72
73
74
75
76
        post("%s%sbang", x->x_sym->s_name, (*x->x_sym->s_name ? ": " : ""));
    else
    {
        gui_start_vmess("gui_print", "xs", x, x->x_sym->s_name);
        gui_start_array();
        gui_s(s_bang.s_name);
        gui_end_array();
        gui_end_vmess();
    }
Miller Puckette's avatar
Miller Puckette committed
77
78
79
80
}

static void print_pointer(t_print *x, t_gpointer *gp)
{
81
    if (sys_nogui || sys_printhook)
82
83
84
85
86
87
88
89
90
91
        post("%s%s(gpointer)", x->x_sym->s_name,
            (*x->x_sym->s_name ? ": " : ""));
    else
    {
        gui_start_vmess("gui_print", "xs", x, x->x_sym->s_name);
        gui_start_array();
        gui_s("(gpointer)");
        gui_end_array();
        gui_end_vmess();
    }
Miller Puckette's avatar
Miller Puckette committed
92
93
}

94
static void print_float(t_print *x, t_floatarg f)
Miller Puckette's avatar
Miller Puckette committed
95
{
96
    if (sys_nogui || sys_printhook)
97
98
        post("%s%s" FLOAT_SPECIFIER, x->x_sym->s_name,
            (*x->x_sym->s_name ? ": " : ""), f);
99
100
101
102
103
104
105
106
    else
    {
        gui_start_vmess("gui_print", "xs", x, x->x_sym->s_name);
        gui_start_array();
        gui_f(f);
        gui_end_array();
        gui_end_vmess();
    }
Miller Puckette's avatar
Miller Puckette committed
107
108
}

109
static void print_symbol(t_print *x, t_symbol *s)
Miller Puckette's avatar
Miller Puckette committed
110
{
111
    if (sys_nogui || sys_printhook)
112
113
114
115
116
117
118
119
120
121
122
        post("%s%s%s", x->x_sym->s_name, (*x->x_sym->s_name ? ": " : ""),
            s->s_name);
    else
    {
        gui_start_vmess("gui_print", "xs", x, x->x_sym->s_name);
        gui_start_array();
        gui_s(s_symbol.s_name);
        gui_s(s->s_name);
        gui_end_array();
        gui_end_vmess();
    }
Miller Puckette's avatar
Miller Puckette committed
123
124
125
126
}

static void print_anything(t_print *x, t_symbol *s, int argc, t_atom *argv)
{
127
    char buf[MAXPDSTRING];
128
    t_atom at;
129
    if (sys_nogui || sys_printhook)
130
131
132
133
134
135
136
137
138
139
140
    {
        startpost("%s%s", x->x_sym->s_name, (*x->x_sym->s_name ? ":" : ""));
        if (s && (s != &s_list || (argc && argv->a_type != A_FLOAT)))
        {
            SETSYMBOL(&at, s);
            postatom(1, &at);
        }
        postatom(argc, argv);
        endpost();
    }
    else
141
    {
142
143
144
145
146
147
148
149
150
151
152
        gui_start_vmess("gui_print", "xs", x, x->x_sym->s_name);
        gui_start_array();
        if (s && (s != &s_list || (argc && argv->a_type != A_FLOAT)))
            gui_s(s->s_name);
        for(; argc; argv++, argc--)
        {
            atom_string(argv, buf, MAXPDSTRING);
            gui_s(buf);
        }
        gui_end_array();
        gui_end_vmess();
153
    }
Miller Puckette's avatar
Miller Puckette committed
154
155
156
157
158
}

static void print_setup(void)
{
    print_class = class_new(gensym("print"), (t_newmethod)print_new, 0,
159
        sizeof(t_print), 0, A_GIMME, 0);
Miller Puckette's avatar
Miller Puckette committed
160
161
162
    class_addbang(print_class, print_bang);
    class_addfloat(print_class, print_float);
    class_addpointer(print_class, print_pointer);
163
    class_addsymbol(print_class, print_symbol);
Miller Puckette's avatar
Miller Puckette committed
164
165
166
    class_addanything(print_class, print_anything);
}

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* -------------------------- unpost ------------------------------ */

#define NEWBUFSIZE MAXPDSTRING * 2
static t_class *unpost_class;

typedef struct _unpost {
    t_object x_obj;
    t_outlet *x_out0;
    t_outlet *x_out1;
    int x_all;
} t_unpost;

typedef struct _unpost_frame {
    t_unpost *u_self;
    char *u_buf;
    unsigned int u_bufsize;
    unsigned int u_index;
} t_unpost_frame;

static t_unpost_frame *current_unpost;

static void *unpost_frame_new(t_unpost *x)
{
    t_unpost_frame *u = (t_unpost_frame *)t_getbytes(sizeof(t_unpost_frame));
    u->u_self = x;
    u->u_buf = (char *)t_getbytes(sizeof(char) * NEWBUFSIZE);
    u->u_buf[0] = '\0';
    u->u_bufsize = NEWBUFSIZE;
    u->u_index = 0;
    return u;
}

static void unpost_frame_resize(t_unpost_frame *u, int newsize)
{
    u->u_buf = (char *)t_resizebytes(u->u_buf, sizeof(*u->u_buf) * u->u_bufsize,
       sizeof(*u->u_buf) * newsize);
    u->u_bufsize = newsize;
}

static void unpost_frame_free(t_unpost_frame* u)
{
    t_freebytes(u->u_buf, sizeof(*u->u_buf));
209
    u->u_buf = NULL;
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
}

static void *unpost_new(t_symbol *s)
{
    t_unpost *x = (t_unpost *)pd_new(unpost_class);
    x->x_all = s != gensym("error");
    x->x_out0 = outlet_new(&x->x_obj, &s_symbol);
    x->x_out1 = outlet_new(&x->x_obj, &s_symbol);
    return x;
}

extern t_printhook sys_printhook;
extern t_printhook sys_printhook_error;
static void unpost_printhook(const char *s) {
    t_unpost *x = current_unpost->u_self;
    /* does strlen include terminator? can't remember... */
    unsigned int needbytes = strlen(current_unpost->u_buf) + strlen(s) + 1;
    if (needbytes >= current_unpost->u_bufsize)
    {
        /* Raise the bufsize to NEWBUFSIZE * n where n is a power of two that
           will fit the number of bytes we need) */
        unsigned int n = ((needbytes / NEWBUFSIZE) >> 1) +
            (needbytes % NEWBUFSIZE != 0);
        unpost_frame_resize(current_unpost,
            current_unpost->u_bufsize * (1 << n));
    }
236

237
238
239
    else if (strlen(current_unpost->u_buf) + strlen(s) <
        current_unpost->u_bufsize / 4)
    {
240
241
242
243
244
        /* Pretty sure I prematurely optimized here. There's no good reason to
           shrink the buffer in the midst of receiving some enormous number of
           posts from an object chain. Besides, we free the buffer once the
           object chain downstream from the [unpost] outlet finishes computing.
           Anyhow, here we are. */
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
        unpost_frame_resize(current_unpost,
            (current_unpost->u_bufsize / 4 < NEWBUFSIZE) ?
                NEWBUFSIZE :
                current_unpost->u_bufsize / 4);
    }
    strcat(current_unpost->u_buf, s);
    const char *p;
    const char *d = current_unpost->u_buf, *dd = d;
    for (;;) {
        p = strchr(d, '\n');
        if (!p) break;
        /* To avoid infinite recursion, let's reset our hooks before we
           send to the right outlet. */
        t_printhook print_backup = sys_printhook,
                    error_backup = sys_printhook_error;
        sys_printhook = NULL;
        sys_printhook_error = NULL;
        outlet_symbol(x->x_out0, gensym(d));
        sys_printhook = print_backup;
        sys_printhook_error = error_backup;
        d = p + 1;
    }
    if (d != dd)
    {
        char *q = strdup(d);
        strcpy(current_unpost->u_buf, q);
        t_freebytes(q, sizeof(*q) * strlen(q));
    }
}

static void unpost_anything(t_unpost *x, t_symbol *s, int argc, t_atom *argv)
{
    t_printhook *myhook = x->x_all ? &sys_printhook : &sys_printhook_error;
    t_printhook backup1 = *myhook;
    t_unpost_frame *backup2 = current_unpost;
    *myhook = unpost_printhook;
    current_unpost = unpost_frame_new(x);
    outlet_anything(x->x_out1, s, argc, argv);
    *myhook = backup1;
    unpost_frame_free(current_unpost);
    current_unpost = backup2;
}

static void unpost_setup(void)
{
    unpost_class = class_new(gensym("unpost"), (t_newmethod)unpost_new, 0,
        sizeof(t_unpost), 0, A_DEFSYM, 0);
    class_addanything(unpost_class, unpost_anything);
}

295
/* --------------pdinfo, canvasinfo, classinfo, objectinfo --------------- */
296
static t_class *canvasinfo_class;
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
typedef struct _canvasinfo {
    t_object x_obj;
    t_canvas *x_canvas;
    t_float   x_depth;
} t_canvasinfo;

static t_class *pdinfo_class;

typedef struct _pdinfo {
    t_object x_obj;
} t_pdinfo;

static t_class *classinfo_class;

typedef struct _classinfo {
    t_object x_obj;
314
315
    t_outlet *x_out2;
    t_symbol *x_name;
316
317
} t_classinfo;

318
319
320
321
322
static t_class *objectinfo_class;

typedef struct _objectinfo {
    t_object x_obj;
    t_outlet *x_out2;
323
    t_gpointer x_gp;
324
325
326
    t_canvas *x_canvas;
} t_objectinfo;

327
/* used by all the *info objects */
328

329
static int info_to_console = 0;
330
331

void info_out(t_text *te, t_symbol *s, int argc, t_atom *argv)
332
{
333
    if (info_to_console)
334
335
336
337
338
339
    {
        startpost("%s:", s->s_name);
        if (argc > 0)
            postatom(argc, argv);
        endpost();
    }
340
341
    else
    {
342
343
344
345
346
        outlet_list(te->ob_outlet,
            &s_list, argc, argv);
    }
}

347
348
349
350
351
352
353
354
355
356
357
358
359
360
void info_print(t_text *te)
{
    t_class *c = classtable_findbyname(te->ob_pd->c_name);
    if(c == NULL)
    {
        pd_error(te, "s: can't find entry in classtable");
        return;
    }
    info_to_console = 1;
    t_int i;
    t_methodentry *m;
    for(i = c->c_nmethod, m = c->c_methods; i; i--, m++)
        if(m->me_name != gensym("print"))
            (m->me_fun)(te, m->me_name, 0, 0);
361
362
    /* not sure why this doesn't work... */
    /* pd_forwardmess(te->te_pd, 0, 0); */
363
364
365
    info_to_console = 0;
}

366
/* -------------------------- canvasinfo ------------------------------ */
367
368
/* climb up to a parent canvas */
t_canvas *canvas_climb(t_canvas *c, int level)
369
{
370
371
372
373
374
375
376
377
378
379
  if(level <= 0)
      return c;
  else
  {
      t_canvas *ret = c;
      while(level && ret->gl_owner)
      {
        ret = ret->gl_owner;
        level--;
      }
380
      return ret;
381
382
383
  }
}

384
385
void canvas_getargs_after_creation(t_canvas *c, int *argcp, t_atom **argvp);

386
void canvasinfo_args(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
387
{
388
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
389
390
391
392
393
394
395
    int n = 0;
    t_atom *a = 0;
    t_binbuf *b;
    if(!c) return;
    if (s == gensym("args")) c = canvas_getrootfor(c);
    b = c->gl_obj.te_binbuf;
    if(!b)
396
    {
397
        info_out((t_text *)x, s, 0, 0);
398
    }
399
    else
400
    {
401
        if (s == gensym("args"))
402
403
404
405
        {
            canvas_getargs_after_creation(c, &n, &a);
            info_out((t_text *)x, s, n, a);
        }
406
        else
407
        {
408
409
410
411
412
413
414
415
416
417
            /* For "boxtext" we have to convert semi, comma, dollar, and
               dollsym atoms to symbol atoms. Otherwise we could end up
               outputting a message containing stray semis/commas/etc. which
               might cause trouble.

               We sent the atoms through binbuf_addbinbuf which does the
               conversion to symbols for us. That way the user will get
               expected output-- e.g., special characters will be properly
               escaped when printing.
            */
418
419
420
421
            t_binbuf *escaped = binbuf_new();
            binbuf_addbinbuf(escaped, b);
            n = binbuf_getnatom(escaped);
            a = binbuf_getvec(escaped);
422
            info_out((t_text *)x, s, n, a);
423
424
            binbuf_free(escaped);
        }
425
    }
426
427
428
429
}

void canvasinfo_coords(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
430
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
    t_int gop = c->gl_isgraph + c->gl_hidetext;
    t_atom at[9];
    SETFLOAT(at, (c->gl_isgraph) ? c->gl_x1 : 0);
    SETFLOAT(at+1, (c->gl_isgraph) ? c->gl_y1 : 0);
    SETFLOAT(at+2, (c->gl_isgraph) ? c->gl_x2 : 0);
    SETFLOAT(at+3, (c->gl_isgraph) ? c->gl_y2 : 0);
    SETFLOAT(at+4, (c->gl_isgraph) ? c->gl_pixwidth : 0);
    SETFLOAT(at+5, (c->gl_isgraph) ? c->gl_pixheight : 0);
    SETFLOAT(at+6, (c->gl_isgraph) ? gop : 0);
    SETFLOAT(at+7, (c->gl_isgraph) ? c->gl_xmargin : 0);
    SETFLOAT(at+8, (c->gl_isgraph) ? c->gl_ymargin : 0);
    info_out((t_text *)x, s, 9, at);
}

void canvasinfo_dir(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
447
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
448
449
450
451
452
453
454
455
    c = canvas_getrootfor(c);
    t_atom at[1];
    SETSYMBOL(at, canvas_getdir(c));
    info_out((t_text *)x, s, 1, at);
}

void canvasinfo_dirty(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
456
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
457
458
459
460
461
462
463
    t_atom at[1];
    SETFLOAT(at, c->gl_dirty);
    info_out((t_text *)x, s, 1, at);
}

void canvasinfo_dollarzero(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
464
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
465
466
467
468
469
470
471
472
473
474
475
    c = canvas_getrootfor(c);
    t_symbol *d = gensym("$0");
    t_symbol *ret = canvas_realizedollar(c, d);
    float f = (float)strtod(ret->s_name,NULL);
    t_atom at[1];
    SETFLOAT(at, f);
    info_out((t_text *)x, s, 1, at);
}

void canvasinfo_editmode(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
476
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
477
478
479
480
481
482
483
    t_atom at[1];
    SETFLOAT(at, c->gl_edit);
    info_out((t_text *)x, s, 1, at);
}

void canvasinfo_filename(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
484
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
485
486
487
488
489
490
    c = canvas_getrootfor(c);
    t_atom at[1];
    SETSYMBOL(at, c->gl_name);
    info_out((t_text *)x, s, 1, at);
}

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf, int wholeword);

void canvasinfo_find(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
    int i, match = 0;
    t_atom at[1], *ap;
    t_gpointer *gp = (t_gpointer *)t_getbytes(500 * sizeof(*gp));
    t_gobj *y;
    t_binbuf *searchbuf = binbuf_new();
    t_binbuf *outbuf = binbuf_new();
    binbuf_add(searchbuf, argc, argv);
    for (y = c->gl_list; y && match < 500; y = y->g_next)
    {
        t_binbuf *objbuf;
        /* if it's not t_object (e.g., a scalar), or if it is but
           does not have any binbuf content, send a bang... */
        if (pd_checkobject(&y->g_pd) &&
            (objbuf = ((t_text *)y)->te_binbuf) &&
            binbuf_match(objbuf, searchbuf, 1))
        {
            match++;
            gpointer_init(gp+match-1);
            gpointer_setglist(gp+match-1, c, y);
            SETPOINTER(at, gp+match-1);
            binbuf_add(outbuf, 1, at); 
        }
    }
    if (match >= 500)
        post("canvasinfo: warning: find is currently limited to 500 results. "
             "Truncating the output to 500 elements...");
    info_out((t_text *)x, s, binbuf_getnatom(outbuf), binbuf_getvec(outbuf));
    for (i = 0, ap = binbuf_getvec(outbuf); i < binbuf_getnatom(outbuf); i++)
    {
        t_gpointer *gp = (ap+i)->a_w.w_gpointer;
        gpointer_unset(gp);
    }
    binbuf_free(outbuf);
    binbuf_free(searchbuf);
    freebytes(gp, 500 * sizeof(*gp));
}

void canvasinfo_gobjs(t_canvasinfo *x, t_float xpos, t_float ypos,
    int all)
535
{
536
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
537
    int x1, y1, x2, y2, i, atom_count = 0;
538
539
540
541
542
    /* hack to avoid memory allocation. Maybe there's a way to use the
       XLIST_ATOMS_ALLOCA macro? */
    t_atom at[500];
    t_gpointer *gp, *gvec;
    gp = gvec = (t_gpointer *)t_getbytes(500 * sizeof (*gvec));
543
544
    t_gobj *y;
    for (y = c->gl_list, i = 0; y && atom_count < 500; y = y->g_next, i++)
545
    {
546
        if (all || canvas_hitbox(c, y, xpos, ypos, &x1, &y1, &x2, &y2))
547
        {
548
549
550
            gpointer_init(gp);
            gpointer_setglist(gp, c, y);
            SETPOINTER(at+atom_count, gp);
551
            atom_count++;
552
            gp++;
553
        }
554
    }
555
556
    if (atom_count >= 500)
        post("canvasinfo: warning: hitbox is currently limited to 500 objects. "
557
             "Truncating the output to 500 elements...");
558
    info_out((t_text *)x, gensym("hitbox"), atom_count, at);
559
560
561
562
563
564
565
566
567
568
569
570
571
    for (i = 0, gp = gvec; i < atom_count; i++, gp++)
        gpointer_unset(gp);
    freebytes(gvec, 500 * sizeof(*gvec));
}

void canvasinfo_bang(t_canvasinfo *x)
{
    canvasinfo_gobjs(x, 0, 0, 1);
}

void canvasinfo_hitbox(t_canvasinfo *x, t_floatarg xpos, t_floatarg ypos)
{
    canvasinfo_gobjs(x, xpos, ypos, 0);
572
573
}

574
void canvasinfo_name(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
575
{
576
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
577
    char buf[MAXPDSTRING];
578
    snprintf(buf, MAXPDSTRING, "x%lx", (long unsigned int)c);
579
580
581
    t_atom at[1];
    SETSYMBOL(at, gensym(buf));
    info_out((t_text *)x, s, 1, at);
582
583
}

584
void canvasinfo_pointer(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
585
{
586
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
587
588
589
590
591
592
593
    t_atom at[1];
    t_gpointer gp;
    gpointer_init(&gp);
    gpointer_setglist(&gp, c, 0);
    SETPOINTER(at, &gp);
    info_out((t_text *)x, s, 1, at);
    gpointer_unset(&gp);
594
595
}

596
597
void canvasinfo_posonparent(t_canvasinfo *x, t_symbol *s,
    int argc, t_atom *argv)
598
{
599
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
600
601
602
603
    t_atom at[2];
    SETFLOAT(at, c->gl_obj.te_xpix);
    SETFLOAT(at+1, c->gl_obj.te_ypix);
    info_out((t_text *)x, s, 2, at);
604
605
}

606
void canvasinfo_screenpos(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
607
{
608
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
609
610
611
612
613
614
    t_atom at[4];
    SETFLOAT(at, c->gl_screenx1);
    SETFLOAT(at+1, c->gl_screeny1);
    SETFLOAT(at+2, c->gl_screenx2);
    SETFLOAT(at+3, c->gl_screeny2);
    info_out((t_text *)x, s, 4, at);
615
616
}

617
void canvasinfo_toplevel(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
618
{
619
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
620
621
622
623
    t_float f = c->gl_owner ? 0 : 1;
    t_atom at[1];
    SETFLOAT(at, f);
    info_out((t_text *)x, s, 1, at);
624
625
}

626
void canvasinfo_vis(t_canvasinfo *x, t_symbol *s, int argc, t_atom *argv)
627
{
628
    t_canvas *c = canvas_climb(x->x_canvas, x->x_depth);
629
630
631
632
633
634
635
636
    t_atom at[1];
    SETFLOAT(at, glist_isvisible(c));
    info_out((t_text *)x, s, 1, at);
}

void canvasinfo_print(t_canvasinfo *x)
{
    info_print((t_text *)x);
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
}

void *canvasinfo_new(t_floatarg f)
{
    t_canvasinfo *x = (t_canvasinfo *)pd_new(canvasinfo_class);
    t_glist *glist = (t_glist *)canvas_getcurrent();
    t_canvas *c = (t_canvas*)glist_getcanvas(glist);
    x->x_canvas = c;
    floatinlet_new(&x->x_obj, &x->x_depth);
    outlet_new(&x->x_obj, &s_list);
    x->x_depth = f;
    return (void *)x;
}

void canvasinfo_setup(void)
{
    canvasinfo_class = class_new(gensym("canvasinfo"),
        (t_newmethod)canvasinfo_new, 0,
        sizeof(t_canvasinfo),
        CLASS_DEFAULT, A_DEFFLOAT, 0);

658
    class_addbang(canvasinfo_class, canvasinfo_bang);
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_args,
        gensym("args"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_args,
        gensym("boxtext"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_coords,
        gensym("coords"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_dir,
        gensym("dir"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_dirty,
        gensym("dirty"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_dollarzero,
        gensym("dollarzero"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_editmode,
        gensym("editmode"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_filename,
        gensym("filename"), A_GIMME, 0);
675
676
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_find,
        gensym("find"), A_GIMME, 0);
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_hitbox,
        gensym("hitbox"), A_DEFFLOAT, A_DEFFLOAT, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_name,
        gensym("name"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_pointer,
        gensym("pointer"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_posonparent,
        gensym("posonparent"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_screenpos,
        gensym("screenpos"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_toplevel,
        gensym("toplevel"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_vis,
        gensym("vis"), A_GIMME, 0);
    class_addmethod(canvasinfo_class, (t_method)canvasinfo_print,
        gensym("print"), 0);

    post("canvasinfo: v0.1");
    post("stable canvasinfo methods: args dir dirty editmode vis");

697
698
699
700
701
}

/* -------------------------- pdinfo ------------------------------ */
static t_class *pdinfo_class;

702
t_symbol *getapiname(int id)
703
{
704
705
    t_symbol *s = 0;
    switch (id)
706
    {
707
708
709
710
711
712
713
714
715
716
        case API_NONE: s = gensym("none"); break;
        case API_ALSA: s = gensym("ALSA"); break;
        case API_OSS: s = gensym("OSS"); break;
        case API_MMIO: s = gensym("MMIO"); break;
        case API_PORTAUDIO: s = gensym("PortAudio"); break;
        case API_JACK: s = gensym("JACK"); break;
        case API_SGI: s = gensym("SGI"); break;
        //case API_AUDIOUNIT: s = gensym("AudioUnit"); break;
        //case API_ESD: s = gensym("ESD"); break;
        //case API_DUMMY: s = gensym("dummy"); break;
717
    }
718
719
720
721
722
723
724
725
    return s;
}

void pdinfo_dir(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
    t_symbol *dir = pd_getdirname();
    if (!dir)
726
    {
727
728
        pd_error(x, "pdinfo: can't find pd's directory");
        return;
729
    }
730
731
    SETSYMBOL(at, dir);
    info_out((t_text *)x, s, 1, at);
732
733
}

734
735
736
/* Instead of reporting the actual value for dsp when it's temporarily
   suspended, we report what it will be when dsp is resumed. This way the
   user can get a meaningful value at load time. */
737
void pdinfo_dsp(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
738
{
739
    t_atom at[1];
740
    SETFLOAT(at, (t_float)(pd_this->pd_dspstate_user));
741
    info_out((t_text *)x, s, 1, at);
742
743
}

744
745
746
747
748
749
750
void pdinfo_floatsize(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
    SETFLOAT(at, (t_float)PD_FLOATSIZE);
    info_out((t_text *)x, s, 1, at);
}

751
void pdinfo_audio_api(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
752
{
753
754
755
756
    t_atom at[1];
    t_symbol *api = getapiname(sys_audioapi);
    SETSYMBOL(at, api);
    info_out((t_text *)x, s, 1, at);
757
758
}

759
760
761
762
763
764
void pdinfo_canvaslist(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_canvas *c;
    int j, i = 0;
    t_binbuf *outbuf = binbuf_new();
    t_atom at[1];
765
    for (c = pd_this->pd_canvaslist; c; c = c->gl_next)
766
767
        i++;
    t_gpointer *gp = (t_gpointer *)t_getbytes(i * sizeof(*gp));
768
    for (c = pd_this->pd_canvaslist, i = 0; c; c = c->gl_next, i++)
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
    {
        gpointer_init(gp+i);
        gpointer_setglist(gp+i, c, 0);
        SETPOINTER(at, gp+i);
        binbuf_add(outbuf, 1, at); 
    }
    info_out((t_text *)x, s, binbuf_getnatom(outbuf), binbuf_getvec(outbuf));
    binbuf_free(outbuf);
    for (j = 0; j < i; j++)
        gpointer_unset(gp+j);
    freebytes(gp, i * sizeof(*gp));
}

/* maybe this should be the bang method? */
void pdinfo_classlist(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
784
785
{
    int size = classtable_size();
786
787
788
789
790
791
792
793
794
795
796
797
798
799
    if (info_to_console)
    {
        t_atom at[2];
        SETFLOAT(at, size);
        SETSYMBOL(at+1, gensym("classes loaded (\"classtable\" outputs "
                               "the full list)"));
        info_out((t_text *)x, s, 2, at);
    }
    else
    {
        t_atom at[size];
        classtable_tovec(size, at);
        info_out((t_text *)x, s, size, at);
    }
800
801
}

802
void pdinfo_audioin(t_pdinfo *x, t_symbol *s, int argc, t_atom *arg)
803
{
804
805
806
//        char i
}

807
void pdinfo_audio_api_list_all(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
808
809
810
811
812
813
814
815
{
    t_atom at[7];
    int i;
    for(i = 0; i < 7; i++)
        SETSYMBOL(at+i, getapiname(i));
    info_out((t_text *)x, s, i, at);
}

816
void pdinfo_audio_apilist(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
{
    t_atom at[8];
    int n = 0;
#ifdef USEAPI_OSS
    SETSYMBOL(at+n, getapiname(API_OSS)); n++;
#endif
#ifdef USEAPI_MMIO
    SETSYMBOL(at+n, getapiname(API_MMIO)); n++;
#endif
#ifdef USEAPI_ALSA
    SETSYMBOL(at+n, getapiname(API_ALSA)); n++;
#endif
#ifdef USEAPI_PORTAUDIO
#ifdef MSW
    SETSYMBOL(at+n, getapiname(API_PORTAUDIO));
#else
#ifdef OSX
    SETSYMBOL(at+n, getapiname(API_PORTAUDIO));
#else
    SETSYMBOL(at+n, getapiname(API_PORTAUDIO));
#endif
#endif
    n++;
#endif
#ifdef USEAPI_JACK
    SETSYMBOL(at+n, getapiname(API_JACK)); n++;
#endif
#ifdef USEAPI_AUDIOUNIT
    SETSYMBOL(at+n, getapiname(API_AUDIOUNIT)); n++;
#endif
#ifdef USEAPI_ESD
    SETSYMBOL(at+n, getapiname(API_ESD)); n++;
#endif
#ifdef USEAPI_DUMMY
    SETSYMBOL(at+n, getapiname(API_DUMMY)); n++;
#endif
    info_out((t_text *)x, s, n, at);
}

void pdinfo_audio_listdevs(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
    int nindevs = 0, noutdevs = 0, i, canmulti = 0, cancallback = 0;
    sys_get_audio_devs(indevlist, &nindevs,
            outdevlist, &noutdevs,
            &canmulti, &cancallback,
            MAXNDEV, DEVDESCSIZE);
Jonathan Wilkes's avatar
Jonathan Wilkes committed
864
    t_atom at[MAXNDEV];
865
    if (s == gensym("audio-multidev-support"))
866
    {
867
868
        SETFLOAT(at, canmulti);
        info_out((t_text *)x, s, 1, at); 
869
    }
870
    else if (s == gensym("audio-indevlist"))
871
    {
872
873
874
875
876
877
878
879
880
881
882
883
        for (i = 0; i < nindevs; i++)
           SETSYMBOL(at+i, gensym(indevlist + i * DEVDESCSIZE));
        info_out((t_text *)x, s, i, at);
    }
    else if (s == gensym("audio-outdevlist"))
    {
        for (i = 0; i < noutdevs; i++)
           SETSYMBOL(at+i, gensym(outdevlist + i * DEVDESCSIZE));
        info_out((t_text *)x, s, i, at);
    }
}

884
void pdinfo_audio_dev(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
885
886
{
    int devno;
887
    if (argc) devno = (int)atom_getfloatarg(0, argc, argv);
888
889
890
    else devno = 0;
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
891
    int rate, advance, callback, blocksize;
892
    sys_get_audio_params(&naudioindev, audioindev, chindev,
893
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback, &blocksize);
894
895
896
897
898
899
900
901
902
903
904
    int *dev, *chan, ndev;
    if (s == gensym("audio-indev"))
        dev = audioindev, chan = chindev, ndev = naudioindev;
    else
        dev = audiooutdev, chan = choutdev, ndev = naudiooutdev;
    if (devno >= 0 && devno < ndev)
    {
        t_atom at[2];
        SETFLOAT(at, (t_float)dev[devno]);
        SETFLOAT(at+1, (t_float)chan[devno]);
        info_out((t_text *)x, s, 2, at);
905
    }
906
907
908
909
    else
        info_out((t_text *)x, s, 0, 0);
}

910
void pdinfo_midi_api(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
911
912
913
914
915
916
917
918
919
920
921
{
    t_atom at[1];
    t_symbol *api, *def = gensym("DEFAULT");
#ifdef USEAPI_OSS
    def = gensym("OSS");
#endif
    api = sys_midiapi ? gensym("ALSA") : def;
    SETSYMBOL(at, api);
    info_out((t_text *)x, s, 1, at);
}

922
void pdinfo_midi_apilist(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
{
    t_atom at[8];
    int n = 0;
    SETSYMBOL(at+n, gensym("DEFAULT"));
#ifdef USEAPI_OSS
    SETSYMBOL(at+n, gensym("OSS"));
#endif
    n++;
#ifdef USEAPI_ALSA
    SETSYMBOL(at+n, getapiname(API_ALSA)); n++;
#endif
    info_out((t_text *)x, s, n, at);
}

void pdinfo_midi_listdevs(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    char indevlist[MAXMIDIINDEV*DEVDESCSIZE],
        outdevlist[MAXMIDIOUTDEV*DEVDESCSIZE];
    int nindevs = 0, noutdevs = 0, i;
    sys_get_midi_devs(indevlist, &nindevs,
            outdevlist, &noutdevs,
            MAXNDEV, DEVDESCSIZE);
Jonathan Wilkes's avatar
Jonathan Wilkes committed
945
    t_atom at[MAXNDEV];
946
947
948
949
950
951
952
953
954
955
956
957
958
959
    if (s == gensym("midi-indevlist"))
    {
        for (i = 0; i < nindevs; i++)
           SETSYMBOL(at+i, gensym(indevlist + i * DEVDESCSIZE));
        info_out((t_text *)x, s, i, at);
    }
    else if (s == gensym("midi-outdevlist"))
    {
        for (i = 0; i < noutdevs; i++)
           SETSYMBOL(at+i, gensym(outdevlist + i * DEVDESCSIZE));
        info_out((t_text *)x, s, i, at);
    }
}

960
void pdinfo_midi_dev(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
961
962
963
{
    int devno, nmidiindev, midiindev[MAXMIDIINDEV],
        nmidioutdev, midioutdev[MAXMIDIOUTDEV];
Mathieu L Bouchard's avatar
Mathieu L Bouchard committed
964
    int *dev, ndev;
965
    if (argc) devno = (int)atom_getfloatarg(0, argc, argv);
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
    else devno = 0;
    sys_get_midi_params(&nmidiindev, midiindev, &nmidioutdev, midioutdev);
    if (s == gensym("midi-indev"))
        dev = midiindev, ndev = nmidiindev;
    else
        dev = midioutdev, ndev = nmidioutdev;
    if (devno >= 0 && devno < ndev)
    {
        t_atom at[1];
        SETFLOAT(at, (t_float)dev[devno]);
        info_out((t_text *)x, s, 1, at);
    }
    else
        info_out((t_text *)x, s, 0, 0);
}

982
void pdinfo_audio_outdev(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
983
984
{
    int devno;
985
    if (argc) devno = (int)atom_getfloatarg(0, argc, argv);
986
987
988
    else devno = 0;
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
989
    int rate, advance, callback, blocksize;
990
    sys_get_audio_params(&naudioindev, audioindev, chindev,
991
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback, &blocksize);
992
993
994
995
996
997
998
999
1000
1001
1002
    if (devno >= 0 && devno < naudioindev)
    {
        t_atom at[2];
        SETFLOAT(at, (t_float)audioindev[devno]);
        SETFLOAT(at+1, (t_float)chindev[devno]);
        info_out((t_text *)x, s, 2, at);
    }
    else
        info_out((t_text *)x, s, 0, 0);
}

1003
void pdinfo_audio_inchannels(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
1004
1005
1006
1007
1008
1009
{
    t_atom at[1];
    SETFLOAT(at, (t_float)sys_get_inchannels());
    info_out((t_text *)x, s, 1, at);
}

1010
void pdinfo_audio_outchannels(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
1011
1012
1013
1014
1015
1016
1017
{
    t_atom at[1];
    SETFLOAT(at, (t_float)sys_get_outchannels());
    info_out((t_text *)x, s, 1, at);
}


1018
void pdinfo_audio_samplerate(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
1019
1020
1021
1022
1023
1024
{
    t_atom at[1];
    SETFLOAT(at, (t_float)sys_getsr());
    info_out((t_text *)x, s, 1, at);
}

1025
void pdinfo_audio_blocksize(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
1026
1027
{
    t_atom at[1];
1028
    SETFLOAT(at, (t_float)sys_audio_get_blocksize());
1029
1030
1031
    info_out((t_text *)x, s, 1, at);
}

1032
1033
1034
1035
1036
1037
1038
void pdinfo_gui(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
    SETFLOAT(at, (t_float)(!sys_nogui));
    info_out((t_text *)x, s, 1, at);
}

1039
1040
1041
/* directory where extra and doc are found. Might also want to add
   another method to return a list of all paths searched for libs-- i.e.,
   "extrapath". */
1042
1043
1044
void pdinfo_libdir(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
1045
    SETSYMBOL(at, sys_libdir);
1046
1047
1048
    info_out((t_text *)x, s, 1, at);
}

1049
t_symbol* pd_getplatform(void)
1050
1051
{
#ifdef __APPLE__
1052
    return gensym("darwin");
1053
1054
#endif
#ifdef __FreeBSD__
1055
    return gensym("freebsd");
1056
1057
#endif
#ifdef _WIN32
1058
    return gensym("win32");
1059
1060
#endif
#ifdef __linux__
1061
    return gensym("linux");
1062
#endif
1063
1064
1065
1066
1067
1068
1069
1070
    /* don't know the platform... */
    return gensym("unknown");
}

void pdinfo_platform(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
    SETSYMBOL(at, pd_getplatform());
1071
1072
1073
    info_out((t_text *)x, s, 1, at);
}

1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
void pdinfo_arch(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_atom at[1];
    t_symbol *a = gensym("unknown");
#ifdef __i386__
    a = gensym("ia32");
#endif
#ifdef __x86_64__
    a = gensym("x64");
#endif
#ifdef __arm__
    a = gensym("arm");
#endif
    SETSYMBOL(at, a);
    info_out((t_text *)x, s, 1, at);
}

1091
void pdinfo_version(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
{
    int major=0, minor=0, bugfix=0;
    sys_getversion(&major, &minor, &bugfix);
    t_atom at[3];
    SETFLOAT(at, (t_float)major);
    SETFLOAT(at+1, (t_float)minor);
    SETFLOAT(at+2, (t_float)bugfix);
    info_out((t_text *)x, s, 3, at);
}

1102
1103
1104
1105
1106
1107
1108
1109
1110
void pdinfo_l2ork_version(t_pdinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    char buf[MAXPDSTRING];
    t_atom at[1];
    sprintf(buf, PD_L2ORK_VERSION " " PD_BUILD_VERSION);
    SETSYMBOL(at, gensym(buf));
    info_out((t_text *)x, s, 1, at);
}

1111
1112
1113
void pdinfo_print(t_pdinfo *x)
{
    info_print((t_text *)x);
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
}

void *pdinfo_new(t_symbol *s, t_int argc, t_atom *argv)
{
    t_pdinfo *x = (t_pdinfo *)pd_new(pdinfo_class);
    outlet_new(&x->x_obj, &s_list);    
    return (void *)x;
}

void pdinfo_setup(void)
{
    pdinfo_class = class_new(gensym("pdinfo"),
        (t_newmethod)pdinfo_new, 0,
        sizeof(t_pdinfo),
        CLASS_DEFAULT, 0);

1130
1131
    class_addmethod(pdinfo_class, (t_method)pdinfo_arch,
        gensym("arch"), A_GIMME, 0);
1132
1133
1134
1135
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_api,
        gensym("audio-api"), A_DEFFLOAT, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_apilist,
        gensym("audio-apilist"), A_GIMME, 0);
1136
1137
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_api_list_all,
        gensym("audio-apilist-all"), A_GIMME, 0);
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_inchannels,
        gensym("audio-inchannels"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_dev,
        gensym("audio-indev"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_listdevs,
        gensym("audio-indevlist"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_listdevs,
        gensym("audio-multidev-support"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_outchannels,
        gensym("audio-outchannels"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_dev,
        gensym("audio-outdev"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_listdevs,
        gensym("audio-outdevlist"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_blocksize,
        gensym("blocksize"), A_GIMME, 0);
1154
1155
    /* this needs a better name-- the user doesn't have to know the
       name used in the implementation */
1156
1157
1158
1159
    class_addmethod(pdinfo_class, (t_method)pdinfo_canvaslist,
        gensym("canvaslist"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_classlist,
        gensym("classlist"), A_GIMME, 0);
1160
1161
1162
1163
    class_addmethod(pdinfo_class, (t_method)pdinfo_dir,
        gensym("dir"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_dsp,
        gensym("dsp-status"), A_GIMME, 0);
1164
1165
    class_addmethod(pdinfo_class, (t_method)pdinfo_floatsize,
        gensym("floatsize"), A_GIMME, 0);
1166
1167
    class_addmethod(pdinfo_class, (t_method)pdinfo_gui,
        gensym("gui"), A_GIMME, 0);
1168
1169
    class_addmethod(pdinfo_class, (t_method)pdinfo_libdir,
        gensym("libdir"), A_GIMME, 0);
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_api,
        gensym("midi-api"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_apilist,
        gensym("midi-apilist"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_dev,
        gensym("midi-indev"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_listdevs,
        gensym("midi-indevlist"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_dev,
        gensym("midi-outdev"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_midi_listdevs,
        gensym("midi-outdevlist"), A_GIMME, 0);
1182
1183
    class_addmethod(pdinfo_class, (t_method)pdinfo_platform,
        gensym("platform"), A_GIMME, 0);
1184
1185
1186
1187
    class_addmethod(pdinfo_class, (t_method)pdinfo_audio_samplerate,
        gensym("samplerate"), A_GIMME, 0);
    class_addmethod(pdinfo_class, (t_method)pdinfo_version,
        gensym("version"), A_GIMME, 0);
1188
1189
    class_addmethod(pdinfo_class, (t_method)pdinfo_l2ork_version,
        gensym("l2ork_version"), A_GIMME, 0);
1190
1191
1192
1193
1194
1195

    class_addmethod(pdinfo_class, (t_method)pdinfo_print,
        gensym("print"), 0);

    post("pdinfo: v.0.1");
    post("stable pdinfo methods: dir dsp version");
1196
1197
1198
}

/* -------------------------- classinfo ------------------------------ */
1199
t_symbol *attosym(t_atomtype at)
1200
{
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
    t_symbol *s;
    switch (at)
    {
        case A_FLOAT: s = gensym("A_FLOAT"); break;
        case A_SYMBOL: s = gensym("A_SYMBOL"); break;
        case A_POINTER: s = gensym("A_POINTER"); break;
        case A_DEFFLOAT: s = gensym("A_DEFFLOAT"); break;
        case A_DEFSYM: s = gensym("A_DEFSYM"); break;
        case A_GIMME: s = gensym("A_GIMME"); break;
        case A_CANT: s = gensym("A_CANT"); break;
        default: s = 0;
    }
    return s;
1214
1215
}

1216
void classinfo_args(t_classinfo *x, t_symbol *s, int argc, t_atom *argv)
1217
{
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
    t_class *c;
    if(!(c = classtable_findbyname(x->x_name)))
    {
        outlet_bang(x->x_out2);
        return;
    }
    c = classtable_findbyname(gensym("objectmaker"));
    if (!c)
    {
        pd_error(x, "classinfo: no objectmaker.");
        return;
    }
    t_atom ap[MAXPDARG];
    t_int i;
    t_methodentry *m;
    for(i = c->c_nmethod, m = c->c_methods; i; i--, m++)
    {
        if(m->me_name == x->x_name)
            break;
    }
    /* We have to check if there was a match-- while the class
       table holds all classes, the objectmaker only creates a
       new method entry if the class has a t_newmethod defined
       in its setup routine. This misses a few objects such as 
       gatom which can't be typed into a box. Consequently I'm
       sending a bang to the reject outlet for those objects--
       unfortunately that means a "reject" bang could mean the
       object either doesn't exist, or it doesn't have its own
       t_newmethod. However, one can use the other [classinfo]
       methods to unambiguously check the class for existence.
    */
    if (i)
    {
        t_atomtype arg, *args = m->me_arg;
        for(i = 0; arg = *args; args++, i++)
        {
            t_symbol *sym = attosym(arg);
            if (!sym)
            {
                pd_error(x, "classinfo: %s: bad argtype", x->x_name->s_name);
                return;
            }
            SETSYMBOL(ap+i, sym);
        }
        info_out((t_text *)x, s, i, ap);
    }
    else
        outlet_bang(x->x_out2);
1266
1267
}

1268
void classinfo_externdir(t_classinfo *x, t_symbol *s, int argc, t_atom *argv)
1269
{
1270
1271
1272
1273
1274
1275
1276
1277
1278
    t_class *c;
    if(!(c = classtable_findbyname(x->x_name)))
    {
        outlet_bang(x->x_out2);
        return;
    }
    t_atom at[1];
    SETSYMBOL(at, c->c_externdir);
    info_out((t_text *)x, s, 1, at);
1279
1280
}

1281
void classinfo_methods(t_classinfo *x, t_symbol *s, int argc, t_atom *argv)
1282
{
1283
1284
    t_class *c;
    if(!(c = classtable_findbyname(x->x_name)))
1285
    {
1286
        outlet_bang(x->x_out2);
1287
1288
        return;
    }
1289
1290
1291
1292
1293
1294
1295
1296
1297
    t_atom at[1];
    SETFLOAT(at, c->c_nmethod);
    info_out((t_text *)x, s, 1, at);
}

void classinfo_size(t_classinfo *x, t_symbol *s, int argc, t_atom *argv)
{
    t_class *c;
    if(!(c = classtable_findbyname(x->x_name)))
1298
    {
1299
        outlet_bang(x->x_out2);
1300
1301
        return;
    }
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
    t_atom at[1];
    SETFLOAT(at, (t_float)c->c_size);
    info_out