1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 209 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 236 237 238 239 240 241 242 243 244 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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
/*
* Pure Data Packet system implementation: setup code
* Copyright (c) by Tom Schouten <tom@zwizwa.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include "pdp_config.h"
#include "pdp_post.h"
#include "m_imp.h"
#include <fcntl.h>
#include "s_stuff.h"
static int initialized = 0;
/* all symbols are C style */
#ifdef __cplusplus
extern "C"
{
#endif
/* module setup declarations (all C-style) */
/* pdp system / internal stuff */
void pdp_debug_setup(void);
void pdp_list_setup(void);
void pdp_pdsym_setup(void);
void pdp_forth_setup(void);
void pdp_forth_def_setup(void);
void pdp_symbol_setup(void);
void pdp_type_setup(void);
void pdp_packet_setup(void);
void pdp_ut_setup(void);
void pdp_queue_setup(void);
void pdp_control_setup(void);
void pdp_image_setup(void);
void pdp_bitmap_setup(void);
void pdp_matrix_setup(void);
/* pdp modules */
void pdp_xv_setup(void);
void pdp_add_setup(void);
void pdp_mul_setup(void);
void pdp_mix_setup(void);
void pdp_randmix_setup(void);
void pdp_qt_setup(void);
void pdp_v4l_setup(void);
void pdp_reg_setup(void);
void pdp_conv_setup(void);
void pdp_bq_setup(void);
void pdp_del_setup(void);
void pdp_snap_setup(void);
void pdp_trigger_setup(void);
void pdp_route_setup(void);
void pdp_noise_setup(void);
void pdp_gain_setup(void);
void pdp_chrot_setup(void);
void pdp_scope_setup(void);
void pdp_scale_setup(void);
void pdp_zoom_setup(void);
void pdp_scan_setup(void);
void pdp_scanxy_setup(void);
void pdp_sdl_setup(void);
void pdp_cheby_setup(void);
void pdp_grey2mask_setup(void);
void pdp_constant_setup(void);
void pdp_logic_setup(void);
void pdp_glx_setup(void);
void pdp_loop_setup(void);
void pdp_description_setup(void);
void pdp_convert_setup(void);
void pdp_stateless_setup(void);
void pdp_mat_mul_setup(void);
void pdp_mat_lu_setup(void);
void pdp_mat_vec_setup(void);
void pdp_plasma_setup(void);
void pdp_cog_setup(void);
void pdp_histo_setup(void);
void pdp_array_setup(void);
void pdp_udp_send_setup(void);
void pdp_udp_receive_setup(void);
void pdp_rawin_setup(void);
void pdp_rawout_setup(void);
void pdp_metro_setup(void);
/* hacks */
void pdp_inspect_setup(void);
/* testing */
void pdp_dpd_test_setup(void);
static t_class *pdp_class;
static void*pdp_class_new(void)
{
t_pd*x=pd_new(pdp_class);
return (x);
}
/* check whether we can find the pdp-abstractions
* (because they are already in Pd's path)
*/
#if PD_MAJOR_VERSION>0 || PD_MINOR_VERSION>47
/* gone from the headers, but still present for binary compat */
extern t_namelist *sys_searchpath;
#endif
static int _add_search_path(const char*libpath){
int major, minor, bugfix;
sys_getversion(&major, &minor, &bugfix);
if((major==0 && minor < 48)) {
sys_searchpath = namelist_append(sys_searchpath, libpath, 0);
} else {
char encoded[MAXPDSTRING];
char *inptr = libpath, *outptr = encoded;
t_atom ap[2];
*outptr++='+';
while(inptr && ((outptr+2) < (encoded+MAXPDSTRING))) {
*outptr++ = *inptr++;
if ('+'==inptr[-1])
*outptr++='+';
}
*outptr=0;
SETSYMBOL(ap+0, gensym(encoded));
SETFLOAT(ap+1, 0.f);
pd_typedmess(gensym("pd")->s_thing, gensym("add-to-path"), 2, ap);
}
return 1;
}
void pdp_class_setup(void) {
const char*absname="pdp_tag.pd";
char buf[MAXPDSTRING];
char*bufptr=NULL;
const char*libpath=NULL;
int fd=-1;
/* create a [pdp] objectclass */
pdp_class = class_new(gensym("pdp"), pdp_class_new, 0, sizeof(t_object), CLASS_NOINLET, 0);
/* check whether we can find a pdp-abstraction */
if ((fd=canvas_open(NULL, absname, "", buf, &bufptr, MAXPDSTRING, 1))>=0){
sys_close(fd);
return;
}
/* couldn't find pdp-abstraction, print-warning */
libpath=pdp_class->c_externdir->s_name;
/* check whether we can find the abstractions in pdp's own path */
snprintf(buf, MAXPDSTRING-1, "%s/%s", libpath, absname);
buf[MAXPDSTRING-1]=0;
if ((fd=sys_open(buf, O_RDONLY))>=0){
sys_close(fd);
logpost(NULL, 3, "PDP: adding '%s' to your search-path", libpath);
if(!_add_search_path(libpath))
fd=-1;
} else {
// can't find this abstraction...giving up
logpost(NULL, 1, "PDP: cannot find pdp-abstractions");
}
if (fd<0) {
logpost(NULL, 3, "PDP: please add path to '%s' to your search-path!", absname);
}
}
/* library setup routine */
void pdp_setup(void){
if (initialized) return;
/* babble */
#ifdef PDP_VERSION
# if PD_MAJOR_VERSION==0 && PD_MINOR_VERSION<43
pdp_post("PDP: pure data packet version " PDP_VERSION );
# else
logpost(NULL, 3, "PDP: pure data packet version " PDP_VERSION );
# endif
#else
pdp_post ("PDP: pure data packet");
#endif
/* setup pdp system */
pdp_class_setup();
/* kernel */
pdp_pdsym_setup();
pdp_debug_setup();
pdp_symbol_setup();
pdp_list_setup();
pdp_type_setup();
pdp_packet_setup();
pdp_control_setup();
/* types */
pdp_image_setup();
pdp_bitmap_setup();
#ifdef HAVE_PDP_GSL
pdp_matrix_setup();
#endif
pdp_queue_setup();
/* setup utility toolkit */
pdp_ut_setup();
/* setup pdp pd modules*/
pdp_add_setup();
pdp_mul_setup();
pdp_mix_setup();
pdp_randmix_setup();
pdp_reg_setup();
pdp_conv_setup();
pdp_bq_setup();
pdp_del_setup();
pdp_snap_setup();
pdp_trigger_setup();
pdp_route_setup();
pdp_noise_setup();
pdp_plasma_setup();
pdp_gain_setup();
pdp_chrot_setup();
pdp_scope_setup();
pdp_scale_setup();
pdp_zoom_setup();
pdp_scan_setup();
pdp_scanxy_setup();
pdp_grey2mask_setup();
pdp_constant_setup();
pdp_logic_setup();
pdp_loop_setup();
pdp_description_setup();
pdp_convert_setup();
pdp_stateless_setup();
pdp_cog_setup();
pdp_array_setup();
pdp_rawin_setup();
pdp_rawout_setup();
pdp_metro_setup();
/* experimental stuff */
pdp_inspect_setup();
pdp_udp_send_setup();
pdp_udp_receive_setup();
/* testing */
//pdp_dpd_test_setup();
/* optional stuff */
#ifdef HAVE_PDP_READLINE
pdp_forthconsole_setup();
#endif
#ifdef HAVE_PDP_GSL
pdp_histo_setup();
pdp_cheby_setup();
pdp_mat_mul_setup();
pdp_mat_lu_setup();
pdp_mat_vec_setup();
#endif
#ifdef HAVE_PDP_QT
pdp_qt_setup();
#endif
#ifdef HAVE_PDP_XV
pdp_xv_setup();
#endif
#ifdef HAVE_PDP_SDL
pdp_sdl_setup();
#endif
#ifdef HAVE_PDP_V4L
pdp_v4l_setup();
#endif
#ifdef HAVE_PDP_GLX
pdp_glx_setup();
#endif
initialized++;
}
#ifdef __cplusplus
}
#endif
|