m_glob.c 8.4 KB
Newer Older
Miller Puckette's avatar
Miller Puckette committed
1 2 3 4 5 6 7 8 9 10
/* 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 "m_pd.h"
#include "m_imp.h"

t_class *glob_pdobject;
static t_class *maxclass;

Miller Puckette's avatar
Miller Puckette committed
11
int sys_perf;   /* true if we should query user on close and quit */
12
int pd_compatibilitylevel = 43;  /* e.g., 43 for pd 0.43 compatibility */
Miller Puckette's avatar
Miller Puckette committed
13

Miller Puckette's avatar
Miller Puckette committed
14 15 16
/* These "glob" routines, which implement messages to Pd, are from all
over.  Some others are prototyped in m_imp.h as well. */

Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
17
void glob_setfilename(void *dummy, t_symbol *filesym, t_symbol *dirsym);
Miller Puckette's avatar
Miller Puckette committed
18 19 20 21
void glob_verifyquit(void *dummy, t_floatarg f);
void glob_dsp(void *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_meters(void *dummy, t_floatarg f);
void glob_key(void *dummy, t_symbol *s, int ac, t_atom *av);
22
void glob_pastetext(void *dummy, t_symbol *s, int ac, t_atom *av);
Miller Puckette's avatar
Miller Puckette committed
23 24
void glob_audiostatus(void *dummy);
void glob_finderror(t_pd *dummy);
25
void glob_findinstance(t_pd *dummy, t_symbol*s);
Miller Puckette's avatar
Miller Puckette committed
26 27 28 29 30 31 32 33 34 35 36 37 38
void glob_audio_properties(t_pd *dummy, t_floatarg flongform);
void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_audio_setapi(t_pd *dummy, t_floatarg f);
void glob_midi_properties(t_pd *dummy, t_floatarg flongform);
void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_midi_setapi(t_pd *dummy, t_floatarg f);
void glob_start_path_dialog(t_pd *dummy, t_floatarg flongform);
void glob_path_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_start_startup_dialog(t_pd *dummy, t_floatarg flongform);
void glob_startup_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_ping(t_pd *dummy);
void glob_watchdog(t_pd *dummy);
void glob_savepreferences(t_pd *dummy);
39
void glob_forward_files_from_secondary_instance(void);
40 41 42
void glob_recent_files(t_pd *dummy);
void glob_add_recent_file(t_pd *dummy, t_symbol *s);
void glob_clear_recent_files(t_pd *dummy);
Miller Puckette's avatar
Miller Puckette committed
43 44 45

void alsa_resync( void);

46 47 48 49 50 51
static void glob_compatibility(t_pd *dummy, t_floatarg level)
{
    int dspwas = canvas_suspend_dsp();
    pd_compatibilitylevel = 0.5 + 100. * level;
    canvas_resume_dsp(dspwas);
}
Miller Puckette's avatar
Miller Puckette committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#ifdef MSW
void glob_audio(void *dummy, t_floatarg adc, t_floatarg dac);
#endif

/* a method you add for debugging printout */
void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv);

#if 0
void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    *(int *)1 = 3;
}
#endif

67 68 69 70 71 72
static void glob_version(t_pd *dummy, float f)
{
    if (f > 0)
        error("file format newer than this version of Pd (trying anyway...)");
}

Miller Puckette's avatar
Miller Puckette committed
73 74 75 76 77
static void glob_perf(t_pd *dummy, float f)
{
    sys_perf = (f != 0);
}

78 79
extern int sys_zoom, sys_browser_doc, sys_browser_path, sys_browser_init,
    sys_autopatch_yoffset;
80
extern t_symbol *sys_gui_preset;
81
static void glob_gui_prefs(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
82
{
83 84 85 86 87 88
    sys_gui_preset = atom_getsymbolarg(0, argc--, argv++);
    sys_zoom = !!atom_getintarg(0, argc--, argv++);
    sys_browser_doc = !!atom_getintarg(0, argc--, argv++);
    sys_browser_path = !!atom_getintarg(0, argc--, argv++);
    sys_browser_init = !!atom_getintarg(0, argc--, argv++);
    sys_autopatch_yoffset = atom_getintarg(0, argc--, argv++);
89 90
}

91
/* just the gui-preset, the save-zoom toggle and various help browser options for now */
92 93
static void glob_gui_properties(t_pd *dummy)
{
94 95 96 97 98 99 100 101
    gui_vmess("gui_gui_properties", "xsiiiii",
        dummy,
        sys_gui_preset->s_name,
        sys_zoom,
        sys_browser_doc,
        sys_browser_path,
        sys_browser_init,
        sys_autopatch_yoffset);
102 103
}

104 105 106
// ths one lives inside g_editor so that it can access the clipboard
extern void glob_clipboard_text(t_pd *dummy, float f);

Miller Puckette's avatar
Miller Puckette committed
107 108 109 110
void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv)
{
    int i;
    char str[80];
111
    startpost("%s: unknown message %s", class_getname(pd_class(x)),
Miller Puckette's avatar
Miller Puckette committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        s->s_name);
    for (i = 0; i < argc; i++)
    {
        atom_string(argv+i, str, 80);
        poststring(str);
    }
    endpost();
}

void glob_init(void)
{
    maxclass = class_new(gensym("max"), 0, 0, sizeof(t_pd),
        CLASS_DEFAULT, A_NULL);
    class_addanything(maxclass, max_default);
    pd_bind(&maxclass, gensym("max"));

    glob_pdobject = class_new(gensym("pd"), 0, 0, sizeof(t_pd),
        CLASS_DEFAULT, A_NULL);
    class_addmethod(glob_pdobject, (t_method)glob_initfromgui, gensym("init"),
        A_GIMME, 0);
132 133 134
    class_addmethod(glob_pdobject,
        (t_method)glob_forward_files_from_secondary_instance,
        gensym("forward_files_from_secondary_instance"), 0);
Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
135 136
    class_addmethod(glob_pdobject, (t_method)glob_setfilename, 
        gensym("filename"), A_SYMBOL, A_SYMBOL, 0);
Miller Puckette's avatar
Miller Puckette committed
137 138
    class_addmethod(glob_pdobject, (t_method)glob_evalfile, gensym("open"),
        A_SYMBOL, A_SYMBOL, 0);
139 140
    class_addmethod(glob_pdobject, (t_method)glob_quit, gensym("quit"),
        A_DEFFLOAT, 0);
Miller Puckette's avatar
Miller Puckette committed
141 142 143 144 145 146 147
    class_addmethod(glob_pdobject, (t_method)glob_verifyquit,
        gensym("verifyquit"), A_DEFFLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_foo, gensym("foo"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_dsp, gensym("dsp"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_meters, gensym("meters"),
        A_FLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_key, gensym("key"), A_GIMME, 0);
148
    class_addmethod(glob_pdobject, (t_method)glob_pastetext, gensym("pastetext"), A_GIMME, 0);
Miller Puckette's avatar
Miller Puckette committed
149 150 151 152
    class_addmethod(glob_pdobject, (t_method)glob_audiostatus,
        gensym("audiostatus"), 0);
    class_addmethod(glob_pdobject, (t_method)glob_finderror,
        gensym("finderror"), 0);
153 154
    class_addmethod(glob_pdobject, (t_method)glob_findinstance,
          gensym("findinstance"), A_SYMBOL, 0);
Miller Puckette's avatar
Miller Puckette committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    class_addmethod(glob_pdobject, (t_method)glob_audio_properties,
        gensym("audio-properties"), A_DEFFLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_audio_dialog,
        gensym("audio-dialog"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_audio_setapi,
        gensym("audio-setapi"), A_FLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_midi_setapi,
        gensym("midi-setapi"), A_FLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_midi_properties,
        gensym("midi-properties"), A_DEFFLOAT, 0);
    class_addmethod(glob_pdobject, (t_method)glob_midi_dialog,
        gensym("midi-dialog"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_start_path_dialog,
        gensym("start-path-dialog"), 0);
    class_addmethod(glob_pdobject, (t_method)glob_path_dialog,
        gensym("path-dialog"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_start_startup_dialog,
        gensym("start-startup-dialog"), 0);
    class_addmethod(glob_pdobject, (t_method)glob_startup_dialog,
        gensym("startup-dialog"), A_GIMME, 0);
    class_addmethod(glob_pdobject, (t_method)glob_ping, gensym("ping"), 0);
    class_addmethod(glob_pdobject, (t_method)glob_savepreferences,
        gensym("save-preferences"), 0);
178 179
    class_addmethod(glob_pdobject, (t_method)glob_version,
        gensym("version"), A_FLOAT, 0);
Miller Puckette's avatar
Miller Puckette committed
180 181
    class_addmethod(glob_pdobject, (t_method)glob_perf,
        gensym("perf"), A_FLOAT, 0);
182 183
    class_addmethod(glob_pdobject, (t_method)glob_compatibility,
        gensym("compatibility"), A_FLOAT, 0);
184 185
    class_addmethod(glob_pdobject, (t_method)glob_clipboard_text,
        gensym("clipboardtext"), A_FLOAT, 0);
186
    class_addmethod(glob_pdobject, (t_method)glob_gui_prefs,
187
        gensym("gui-prefs"), A_GIMME, 0);
188 189
    class_addmethod(glob_pdobject, (t_method)glob_gui_properties,
        gensym("gui-properties"), 0);
190 191 192 193 194 195
    class_addmethod(glob_pdobject, (t_method)glob_recent_files,
        gensym("recent-files"), 0);
    class_addmethod(glob_pdobject, (t_method)glob_add_recent_file,
        gensym("add-recent-file"), A_SYMBOL, 0);
    class_addmethod(glob_pdobject, (t_method)glob_clear_recent_files,
        gensym("clear-recent-files"), 0);
Miller Puckette's avatar
Miller Puckette committed
196 197 198 199 200 201 202
#ifdef UNIX
    class_addmethod(glob_pdobject, (t_method)glob_watchdog,
        gensym("watchdog"), 0);
#endif
    class_addanything(glob_pdobject, max_default);
    pd_bind(&glob_pdobject, gensym("pd"));
}
Miller Puckette's avatar
test7  
Miller Puckette committed
203 204 205 206 207 208 209 210 211 212 213 214 215

    /* function to return version number at run time.  Any of the
    calling pointers may be zero in case you don't need all of them. */
void sys_getversion(int *major, int *minor, int *bugfix)
{
    if (major)
        *major = PD_MAJOR_VERSION;
    if (minor)
        *minor = PD_MINOR_VERSION;
    if (bugfix)
        *bugfix = PD_BUGFIX_VERSION;
}