diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/OSC-client.h | 189 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/OSC.pd | 14 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/OSCroute.c | 628 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/bandpass-help.pd | 18 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/dumpOSC.c | 1000 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/fatom.h | 486 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/gcanvas-help.pd | 9 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/makefile | 34 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/sendOSC.c | 1461 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/sformat.h | 56 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/shell.c | 312 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/slider.c | 54 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/sliderh.c | 64 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/test-clip.pd | 14 | ||||
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/test-vcf.pd | 19 |
15 files changed, 0 insertions, 4358 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/OSC-client.h b/apps/plugins/pdbox/PDa/extra/OSC-client.h deleted file mode 100644 index fe2c37b5cb..0000000000 --- a/apps/plugins/pdbox/PDa/extra/OSC-client.h +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* | ||
2 | Written by Matt Wright, The Center for New Music and Audio Technologies, | ||
3 | University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03 | ||
4 | The Regents of the University of California (Regents). | ||
5 | |||
6 | Permission to use, copy, modify, distribute, and distribute modified versions | ||
7 | of this software and its documentation without fee and without a signed | ||
8 | licensing agreement, is hereby granted, provided that the above copyright | ||
9 | notice, this paragraph and the following two paragraphs appear in all copies, | ||
10 | modifications, and distributions. | ||
11 | |||
12 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
13 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING | ||
14 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS | ||
15 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
16 | |||
17 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
18 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
19 | PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
20 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
21 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | |||
26 | OSC-client.h: library for constructing OpenSoundControl messages. | ||
27 | Derived from SynthControl.h | ||
28 | Author: Matt Wright | ||
29 | Version 0.1: 6/13/97 | ||
30 | Version 0.2: 7/21/2000: Support for type-tagged messages | ||
31 | |||
32 | |||
33 | General notes: | ||
34 | |||
35 | This library abstracts away the data format for the OpenSoundControl | ||
36 | protocol. Users of this library can construct OpenSoundControl packets | ||
37 | with a function call interface instead of knowing how to lay out the bits. | ||
38 | |||
39 | All issues of memory allocation are deferred to the user of this library. | ||
40 | There are two data structures that the user must allocate. The first | ||
41 | is the actual buffer that the message will be written into. This buffer | ||
42 | can be any size, but if it's too small there's a possibility that it | ||
43 | will become overfull. The other data structure is called an OSCbuf, | ||
44 | and it holds all the state used by the library as it's constructing | ||
45 | a buffer. | ||
46 | |||
47 | All procedures that have the possibility of an error condition return int, | ||
48 | with 0 indicating no error and nonzero indicating an error. The variable | ||
49 | OSC_errorMessage will be set to point to a string containing an error | ||
50 | message explaining what the problem is. | ||
51 | |||
52 | */ | ||
53 | |||
54 | |||
55 | |||
56 | /* The int4byte type has to be a 4-byte integer. You may have to | ||
57 | change this to long or something else on your system. */ | ||
58 | #ifdef __MWERKS__ | ||
59 | /* In Metrowerks you can set ints to be 2 or 4 bytes on 68K, but long is | ||
60 | always 4 bytes */ | ||
61 | typedef long int4byte; | ||
62 | #else | ||
63 | typedef int int4byte; | ||
64 | #endif | ||
65 | |||
66 | /* OSC_timetag.h */ | ||
67 | |||
68 | typedef struct { | ||
69 | int seconds; | ||
70 | int fraction; | ||
71 | } OSCTimeTag; | ||
72 | |||
73 | OSCTimeTag OSCTT_Immediately(void); | ||
74 | OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset); | ||
75 | OSCTimeTag OSCTT_CurrentTime(void); | ||
76 | |||
77 | |||
78 | |||
79 | /* The maximum depth of bundles within bundles within bundles within... | ||
80 | This is the size of a static array. If you exceed this limit you'll | ||
81 | get an error message. */ | ||
82 | #define MAX_BUNDLE_NESTING 32 | ||
83 | |||
84 | |||
85 | /* Don't ever manipulate the data in the OSCbuf struct directly. (It's | ||
86 | declared here in the header file only so your program will be able to | ||
87 | declare variables of type OSCbuf and have the right amount of memory | ||
88 | be allocated.) */ | ||
89 | |||
90 | typedef struct OSCbuf_struct { | ||
91 | char *buffer; /* The buffer to hold the OSC packet */ | ||
92 | int size; /* Size of the buffer */ | ||
93 | char *bufptr; /* Current position as we fill the buffer */ | ||
94 | int state; /* State of partially-constructed message */ | ||
95 | int4byte *thisMsgSize; /* Pointer to count field before | ||
96 | currently-being-written message */ | ||
97 | int4byte *prevCounts[MAX_BUNDLE_NESTING]; | ||
98 | /* Pointers to count field before each currently | ||
99 | open bundle */ | ||
100 | int bundleDepth; /* How many sub-sub-bundles are we in now? */ | ||
101 | char *typeStringPtr; /* This pointer advances through the type | ||
102 | tag string as you add arguments. */ | ||
103 | int gettingFirstUntypedArg; /* nonzero if this message doesn't have | ||
104 | a type tag and we're waiting for the 1st arg */ | ||
105 | } OSCbuf; | ||
106 | |||
107 | |||
108 | |||
109 | /* Initialize the given OSCbuf. The user of this module must pass in the | ||
110 | block of memory that this OSCbuf will use for a buffer, and the number of | ||
111 | bytes in that block. (It's the user's job to allocate the memory because | ||
112 | you do it differently in different systems.) */ | ||
113 | void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray); | ||
114 | |||
115 | |||
116 | /* Reset the given OSCbuf. Do this after you send out the contents of | ||
117 | the buffer and want to start writing new data into it. */ | ||
118 | void OSC_resetBuffer(OSCbuf *buf); | ||
119 | |||
120 | |||
121 | /* Is the buffer empty? (I.e., would it be stupid to send the buffer | ||
122 | contents to the synth?) */ | ||
123 | int OSC_isBufferEmpty(OSCbuf *buf); | ||
124 | |||
125 | |||
126 | /* How much space is left in the buffer? */ | ||
127 | int OSC_freeSpaceInBuffer(OSCbuf *buf); | ||
128 | |||
129 | /* Does the buffer contain a valid OSC packet? (Returns nonzero if yes.) */ | ||
130 | int OSC_isBufferDone(OSCbuf *buf); | ||
131 | |||
132 | /* When you're ready to send out the buffer (i.e., when OSC_isBufferDone() | ||
133 | returns true), call these two procedures to get the OSC packet that's been | ||
134 | assembled and its size in bytes. (And then call OSC_resetBuffer() if you | ||
135 | want to re-use this OSCbuf for the next packet.) */ | ||
136 | char *OSC_getPacket(OSCbuf *buf); | ||
137 | int OSC_packetSize(OSCbuf *buf); | ||
138 | |||
139 | |||
140 | |||
141 | /* Here's the basic model for building up OSC messages in an OSCbuf: | ||
142 | |||
143 | - Make sure the OSCbuf has been initialized with OSC_initBuffer(). | ||
144 | |||
145 | - To open a bundle, call OSC_openBundle(). You can then write | ||
146 | messages or open new bundles within the bundle you opened. | ||
147 | Call OSC_closeBundle() to close the bundle. Note that a packet | ||
148 | does not have to have a bundle; it can instead consist of just a | ||
149 | single message. | ||
150 | |||
151 | |||
152 | - For each message you want to send: | ||
153 | |||
154 | - Call OSC_writeAddress() with the name of your message. (In | ||
155 | addition to writing your message name into the buffer, this | ||
156 | procedure will also leave space for the size count of this message.) | ||
157 | |||
158 | - Alternately, call OSC_writeAddressAndTypes() with the name of | ||
159 | your message and with a type string listing the types of all the | ||
160 | arguments you will be putting in this message. | ||
161 | |||
162 | - Now write each of the arguments into the buffer, by calling one of: | ||
163 | OSC_writeFloatArg() | ||
164 | OSC_writeFloatArgs() | ||
165 | OSC_writeIntArg() | ||
166 | OSC_writeStringArg() | ||
167 | |||
168 | - Now your message is complete; you can send out the buffer or you can | ||
169 | add another message to it. | ||
170 | */ | ||
171 | |||
172 | int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt); | ||
173 | int OSC_closeBundle(OSCbuf *buf); | ||
174 | int OSC_closeAllBundles(OSCbuf *buf); | ||
175 | |||
176 | int OSC_writeAddress(OSCbuf *buf, char *name); | ||
177 | int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types); | ||
178 | int OSC_writeFloatArg(OSCbuf *buf, float arg); | ||
179 | int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args); | ||
180 | int OSC_writeIntArg(OSCbuf *buf, int4byte arg); | ||
181 | int OSC_writeStringArg(OSCbuf *buf, char *arg); | ||
182 | |||
183 | extern char *OSC_errorMessage; | ||
184 | |||
185 | /* How many bytes will be needed in the OSC format to hold the given | ||
186 | string? The length of the string, plus the null char, plus any padding | ||
187 | needed for 4-byte alignment. */ | ||
188 | int OSC_effectiveStringLength(char *string); | ||
189 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/OSC.pd b/apps/plugins/pdbox/PDa/extra/OSC.pd deleted file mode 100644 index 37841ef17a..0000000000 --- a/apps/plugins/pdbox/PDa/extra/OSC.pd +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #N canvas 0 0 240 300 10; | ||
2 | #X obj 32 185 dumpOSC 5550; | ||
3 | #X obj 32 217 OSCroute /hello; | ||
4 | #X obj 32 239 print; | ||
5 | #X obj 133 238 print; | ||
6 | #X obj 26 87 sendOSC; | ||
7 | #X msg 50 43 connect localhost 5550; | ||
8 | #X msg 21 13 send /hello PDa; | ||
9 | #X connect 0 0 1 0; | ||
10 | #X connect 1 0 2 0; | ||
11 | #X connect 1 1 3 0; | ||
12 | #X connect 5 0 4 0; | ||
13 | #X connect 6 0 4 0; | ||
14 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/OSCroute.c b/apps/plugins/pdbox/PDa/extra/OSCroute.c deleted file mode 100644 index 64edbc777f..0000000000 --- a/apps/plugins/pdbox/PDa/extra/OSCroute.c +++ /dev/null | |||
@@ -1,628 +0,0 @@ | |||
1 | /* | ||
2 | Written by Adrian Freed, The Center for New Music and Audio Technologies, | ||
3 | University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04 | ||
4 | The Regents of the University of California (Regents). | ||
5 | |||
6 | Permission to use, copy, modify, distribute, and distribute modified versions | ||
7 | of this software and its documentation without fee and without a signed | ||
8 | licensing agreement, is hereby granted, provided that the above copyright | ||
9 | notice, this paragraph and the following two paragraphs appear in all copies, | ||
10 | modifications, and distributions. | ||
11 | |||
12 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
13 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING | ||
14 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS | ||
15 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
16 | |||
17 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
18 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
19 | PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
20 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
21 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
22 | |||
23 | |||
24 | The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl | ||
25 | */ | ||
26 | |||
27 | /* OSC-route.c | ||
28 | Max object for OSC-style dispatching | ||
29 | |||
30 | To-do: | ||
31 | |||
32 | Match a pattern against a pattern? | ||
33 | Declare outlet types / distinguish leaf nodes from other children | ||
34 | More sophisticated (2-pass?) allmessages scheme | ||
35 | set message? | ||
36 | |||
37 | |||
38 | pd | ||
39 | ------------- | ||
40 | -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 | ||
41 | |||
42 | |||
43 | */ | ||
44 | |||
45 | #ifdef ROCKBOX | ||
46 | #include "plugin.h" | ||
47 | #include "../../pdbox.h" | ||
48 | #else /* ROCKBOX */ | ||
49 | #ifdef WIN32 | ||
50 | #include <stdlib.h> | ||
51 | #include <string.h> | ||
52 | #endif | ||
53 | #ifdef __APPLE__ | ||
54 | #include <stdio.h> | ||
55 | #endif | ||
56 | #ifdef UNIX | ||
57 | #include <stdio.h> | ||
58 | #endif | ||
59 | #endif /* ROCKBOX */ | ||
60 | |||
61 | /* structure definition of your object */ | ||
62 | |||
63 | #define MAX_NUM 20 | ||
64 | #define OSC_ROUTE_VERSION "1.05" | ||
65 | #define OSCWarning(x...) post(x) | ||
66 | |||
67 | /* the required include files */ | ||
68 | #include "../src/m_pd.h" | ||
69 | |||
70 | |||
71 | #ifndef TRUE | ||
72 | typedef int Boolean; | ||
73 | #define TRUE 1 | ||
74 | #define FALSE 0 | ||
75 | #endif | ||
76 | |||
77 | |||
78 | /* Fixed byte width types */ | ||
79 | typedef int int4; /* 4 byte int */ | ||
80 | |||
81 | Boolean PatternMatch (const char *pattern, const char *test); | ||
82 | |||
83 | |||
84 | |||
85 | /* Version 1.04: Allows #1 thru #9 as typed-in arguments | ||
86 | Version 1.05: Allows "list" messages as well as "message" messages. | ||
87 | */ | ||
88 | |||
89 | static t_class *OSCroute_class; | ||
90 | |||
91 | typedef struct _OSCroute | ||
92 | { | ||
93 | t_object x_obj; // required header | ||
94 | t_int x_num; // Number of address prefixes we store | ||
95 | t_int x_complainmode; // Do we print a message if no match? | ||
96 | t_int x_sendmode; // use pd internal sends instead of outlets | ||
97 | char *x_prefixes[MAX_NUM]; | ||
98 | void *x_outlets[MAX_NUM+1]; | ||
99 | } t_OSCroute; | ||
100 | |||
101 | t_symbol *ps_list, *ps_complain, *ps_emptySymbol; | ||
102 | |||
103 | /* prototypes */ | ||
104 | |||
105 | void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); | ||
106 | void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); | ||
107 | void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); | ||
108 | /* //void *OSCroute_new(t_symbol *s, int argc, atom *argv); */ | ||
109 | void *OSCroute_new(t_symbol *s, int argc, t_atom *argv); | ||
110 | void OSCroute_version (t_OSCroute *x); | ||
111 | /* void OSCroute_assist (OSCroute *x, void *box, long msg, long arg, */ | ||
112 | /* char *dstString); */ | ||
113 | void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv); | ||
114 | |||
115 | static char *NextSlashOrNull(char *p); | ||
116 | static void StrCopyUntilSlash(char *target, const char *source); | ||
117 | |||
118 | |||
119 | // free | ||
120 | static void OSCroute_free(t_OSCroute *x) | ||
121 | { | ||
122 | #ifdef ROCKBOX | ||
123 | (void) x; | ||
124 | #endif | ||
125 | // freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec)); | ||
126 | } | ||
127 | |||
128 | /* initialization routine */ | ||
129 | |||
130 | // setup | ||
131 | #ifdef WIN32 | ||
132 | OSC_API void OSCroute_setup(void) { | ||
133 | #else | ||
134 | void OSCroute_setup(void) { | ||
135 | #endif | ||
136 | OSCroute_class = class_new(gensym("OSCroute"), (t_newmethod)OSCroute_new, | ||
137 | (t_method)OSCroute_free,sizeof(t_OSCroute), 0, A_GIMME, 0); | ||
138 | class_addlist(OSCroute_class, OSCroute_list); | ||
139 | class_addanything(OSCroute_class, OSCroute_anything); | ||
140 | class_addmethod(OSCroute_class, (t_method)OSCroute_version, gensym("version"), A_NULL, 0, 0); | ||
141 | class_sethelpsymbol(OSCroute_class, gensym("OSCroute-help.pd")); | ||
142 | |||
143 | /* | ||
144 | class_addmethod(OSCroute_class, (t_method)OSCroute_connect, | ||
145 | gensym("connect"), A_SYMBOL, A_FLOAT, 0); | ||
146 | class_addmethod(OSCroute_class, (t_method)OSCroute_disconnect, | ||
147 | gensym("disconnect"), 0); | ||
148 | class_addmethod(OSCroute_class, (t_method)OSCroute_send, gensym("send"), | ||
149 | A_GIMME, 0); | ||
150 | */ | ||
151 | /* ps_list = gensym("list"); */ | ||
152 | /* ps_complain = gensym("complain"); */ | ||
153 | ps_emptySymbol = gensym(""); | ||
154 | |||
155 | post("OSCroute object version " OSC_ROUTE_VERSION " by Matt Wright. pd: jdl Win32 raf."); | ||
156 | post("OSCroute Copyright © 1999 Regents of the University of California. All Rights Reserved."); | ||
157 | } | ||
158 | |||
159 | |||
160 | |||
161 | /* instance creation routine */ | ||
162 | |||
163 | void *OSCroute_new(t_symbol *s, int argc, t_atom *argv) | ||
164 | { | ||
165 | #ifdef ROCKBOX | ||
166 | (void) s; | ||
167 | #endif | ||
168 | t_OSCroute *x = (t_OSCroute *)pd_new(OSCroute_class); // get memory for a new object & initialize | ||
169 | |||
170 | int i; //{{raf}} n not used | ||
171 | |||
172 | // EnterCallback(); | ||
173 | |||
174 | if (argc > MAX_NUM) { | ||
175 | post("* OSC-route: too many arguments: %ld (max %ld)", argc, MAX_NUM); | ||
176 | // ExitCallback(); | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | x->x_complainmode = 0; | ||
181 | x->x_num = 0; | ||
182 | for (i = 0; i < argc; ++i) { | ||
183 | if (argv[i].a_type == A_SYMBOL) { | ||
184 | if (argv[i].a_w.w_symbol->s_name[0] == '/') { | ||
185 | /* Now that's a nice prefix */ | ||
186 | x->x_prefixes[i] = argv[i].a_w.w_symbol->s_name; | ||
187 | ++(x->x_num); | ||
188 | } else if (argv[i].a_w.w_symbol->s_name[0] == '#' && | ||
189 | argv[i].a_w.w_symbol->s_name[1] >= '1' && | ||
190 | argv[i].a_w.w_symbol->s_name[1] <= '9') { | ||
191 | /* The Max programmer is trying to make a patch that will be | ||
192 | a subpatch with arguments. We have to make an outlet for this | ||
193 | argument. */ | ||
194 | x->x_prefixes[i] = "dummy"; | ||
195 | ++(x->x_num); | ||
196 | } else { | ||
197 | /* Maybe this is an option we support */ | ||
198 | |||
199 | /* if (argv[i].a_w.w_sym == ps_complain) { */ | ||
200 | /* x->x_complainmode = 1; */ | ||
201 | /* } else { */ | ||
202 | /* post("* OSC-route: Unrecognized argument %s", argv[i].a_w.w_sym->s_name); */ | ||
203 | /* } */ | ||
204 | |||
205 | } | ||
206 | |||
207 | // no LONG | ||
208 | |||
209 | /* } else if (argv[i].a_type == A_FLOAD) { */ | ||
210 | /* // Convert to a numeral. Max ints are -2147483648 to 2147483647 */ | ||
211 | /* char *string = getbytes(12); */ | ||
212 | /* // I can't be bothered to plug this 12 byte memory leak */ | ||
213 | /* if (string == 0) { */ | ||
214 | /* post("* OSC-route: out of memory!"); */ | ||
215 | /* // ExitCallback(); */ | ||
216 | /* return 0; */ | ||
217 | /* } */ | ||
218 | /* sprintf(string, "%d", argv[i].a_w.w_long); */ | ||
219 | /* x->x_prefixes[i] = string; */ | ||
220 | /* ++(x->x_num); */ | ||
221 | |||
222 | } else if (argv[i].a_type == A_FLOAT) { | ||
223 | post("* OSC-route: float arguments are not OK."); | ||
224 | // ExitCallback(); | ||
225 | return 0; | ||
226 | } else { | ||
227 | post("* OSC-route: unrecognized argument type!"); | ||
228 | // ExitCallback(); | ||
229 | return 0; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | |||
234 | /* Have to create the outlets in reverse order */ | ||
235 | /* well, not in pd ? */ | ||
236 | // for (i = x->x_num-1; i >= 0; --i) { | ||
237 | // for (i = 0; i <= x->x_num-1; i++) { | ||
238 | for (i = 0; i <= x->x_num; i++) { | ||
239 | // x->x_outlets[i] = listout(x); | ||
240 | x->x_outlets[i] = outlet_new(&x->x_obj, &s_list); | ||
241 | } | ||
242 | |||
243 | // ExitCallback(); | ||
244 | return (x); | ||
245 | } | ||
246 | |||
247 | |||
248 | void OSCroute_version (t_OSCroute *x) { | ||
249 | #ifdef ROCKBOX | ||
250 | (void) x; | ||
251 | #endif | ||
252 | // EnterCallback(); | ||
253 | post("OSCroute Version " OSC_ROUTE_VERSION | ||
254 | ", by Matt Wright. pd jdl, win32: raf.\nOSCroute Compiled " __TIME__ " " __DATE__); | ||
255 | // ExitCallback(); | ||
256 | } | ||
257 | |||
258 | /* I don't know why these aren't defined in some Max #include file. */ | ||
259 | #define ASSIST_INLET 1 | ||
260 | #define ASSIST_OUTLET 2 | ||
261 | |||
262 | void OSCroute_assist (t_OSCroute *x, void *box, long msg, long arg, | ||
263 | char *dstString) { | ||
264 | #ifdef ROCKBOX | ||
265 | (void) box; | ||
266 | #endif | ||
267 | // EnterCallback(); | ||
268 | |||
269 | if (msg==ASSIST_INLET) { | ||
270 | #ifdef ROCKBOX | ||
271 | strcpy(dstString, "Incoming OSC messages"); | ||
272 | #else | ||
273 | sprintf(dstString, "Incoming OSC messages"); | ||
274 | #endif | ||
275 | } else if (msg==ASSIST_OUTLET) { | ||
276 | if (arg < 0 || arg >= x->x_num) { | ||
277 | post("* OSCroute_assist: No outlet corresponds to arg %ld!", arg); | ||
278 | } else { | ||
279 | #ifdef ROCKBOX | ||
280 | strcpy(dstString, "subaddress + args for prefix "); | ||
281 | strcat(dstString, x->x_prefixes[arg]); | ||
282 | #else | ||
283 | sprintf(dstString, "subaddress + args for prefix %s", x->x_prefixes[arg]); | ||
284 | #endif | ||
285 | } | ||
286 | } else { | ||
287 | post("* OSCroute_assist: unrecognized message %ld", msg); | ||
288 | } | ||
289 | |||
290 | // ExitCallback(); | ||
291 | } | ||
292 | |||
293 | void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { | ||
294 | #ifdef ROCKBOX | ||
295 | (void) s; | ||
296 | #endif | ||
297 | // EnterCallback(); | ||
298 | if (argc > 0 && argv[0].a_type == A_SYMBOL) { | ||
299 | /* Ignore the fact that this is a "list" */ | ||
300 | OSCroute_doanything(x, argv[0].a_w.w_symbol, argc-1, argv+1); | ||
301 | } else { | ||
302 | // post("* OSC-route: invalid list beginning with a number"); | ||
303 | // output on unmatched outlet jdl 20020908 | ||
304 | if (argv[0].a_type == A_FLOAT) { | ||
305 | outlet_float(x->x_outlets[x->x_num], argv[0].a_w.w_float); | ||
306 | } else { | ||
307 | post("* OSC-route: unrecognized atom type!"); | ||
308 | } | ||
309 | } | ||
310 | // ExitCallback(); | ||
311 | } | ||
312 | |||
313 | |||
314 | void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { | ||
315 | // EnterCallback(); | ||
316 | OSCroute_doanything(x, s, argc, argv); | ||
317 | // ExitCallback(); | ||
318 | } | ||
319 | |||
320 | |||
321 | |||
322 | |||
323 | void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { | ||
324 | char *pattern, *nextSlash; | ||
325 | int i; | ||
326 | int matchedAnything; | ||
327 | // post("*** OSCroute_anything(s %s, argc %ld)", s->s_name, (long) argc); | ||
328 | |||
329 | pattern = s->s_name; | ||
330 | if (pattern[0] != '/') { | ||
331 | post("* OSC-route: invalid message pattern %s does not begin with /", s->s_name); | ||
332 | outlet_anything(x->x_outlets[x->x_num], s, argc, argv); | ||
333 | return; | ||
334 | } | ||
335 | |||
336 | matchedAnything = 0; | ||
337 | |||
338 | nextSlash = NextSlashOrNull(pattern+1); | ||
339 | if (*nextSlash == '\0') { | ||
340 | /* last level of the address, so we'll output the argument list */ | ||
341 | |||
342 | |||
343 | #ifdef NULL_IS_DIFFERENT_FROM_BANG | ||
344 | if (argc==0) { | ||
345 | post("* OSC-route: why are you matching one level pattern %s with no args?", | ||
346 | pattern); | ||
347 | return; | ||
348 | } | ||
349 | #endif | ||
350 | |||
351 | for (i = 0; i < x->x_num; ++i) { | ||
352 | if (PatternMatch(pattern+1, x->x_prefixes[i]+1)) { | ||
353 | ++matchedAnything; | ||
354 | |||
355 | // I hate stupid Max lists with a special first element | ||
356 | if (argc == 0) { | ||
357 | outlet_bang(x->x_outlets[i]); | ||
358 | } else if (argv[0].a_type == A_SYMBOL) { | ||
359 | // Promote the symbol that was argv[0] to the special symbol | ||
360 | outlet_anything(x->x_outlets[i], argv[0].a_w.w_symbol, argc-1, argv+1); | ||
361 | } else if (argc > 1) { | ||
362 | // Multiple arguments starting with a number, so naturally we have | ||
363 | // to use a special function to output this "list", since it's what | ||
364 | // Max originally meant by "list". | ||
365 | outlet_list(x->x_outlets[i], 0L, argc, argv); | ||
366 | } else { | ||
367 | // There was only one argument, and it was a number, so we output it | ||
368 | // not as a list | ||
369 | /* if (argv[0].a_type == A_LONG) { */ | ||
370 | |||
371 | /* outlet_int(x->x_outlets[i], argv[0].a_w.w_long); */ | ||
372 | // } else | ||
373 | if (argv[0].a_type == A_FLOAT) { | ||
374 | |||
375 | outlet_float(x->x_outlets[i], argv[0].a_w.w_float); | ||
376 | } else { | ||
377 | post("* OSC-route: unrecognized atom type!"); | ||
378 | } | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | } else { | ||
383 | /* There's more address after this part, so our output list will begin with | ||
384 | the next slash. */ | ||
385 | t_symbol *restOfPattern = 0; /* avoid the gensym unless we have to output */ | ||
386 | char patternBegin[1000]; | ||
387 | |||
388 | |||
389 | /* Get the first level of the incoming pattern to match against all our prefixes */ | ||
390 | StrCopyUntilSlash(patternBegin, pattern+1); | ||
391 | |||
392 | for (i = 0; i < x->x_num; ++i) { | ||
393 | if (PatternMatch(patternBegin, x->x_prefixes[i]+1)) { | ||
394 | ++matchedAnything; | ||
395 | if (restOfPattern == 0) { | ||
396 | restOfPattern = gensym(nextSlash); | ||
397 | } | ||
398 | outlet_anything(x->x_outlets[i], restOfPattern, argc, argv); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | if (x->x_complainmode) { | ||
404 | if (!matchedAnything) { | ||
405 | post("* OSC-route: pattern %s did not match any prefixes", pattern); | ||
406 | } | ||
407 | } | ||
408 | |||
409 | // output unmatched data on rightmost outlet a la normal 'route' object, jdl 20020908 | ||
410 | if (!matchedAnything) { | ||
411 | outlet_anything(x->x_outlets[x->x_num], s, argc, argv); | ||
412 | } | ||
413 | |||
414 | |||
415 | } | ||
416 | |||
417 | static char *NextSlashOrNull(char *p) { | ||
418 | while (*p != '/' && *p != '\0') { | ||
419 | p++; | ||
420 | } | ||
421 | return p; | ||
422 | } | ||
423 | |||
424 | static void StrCopyUntilSlash(char *target, const char *source) { | ||
425 | while (*source != '/' && *source != '\0') { | ||
426 | *target = *source; | ||
427 | ++target; | ||
428 | ++source; | ||
429 | } | ||
430 | *target = 0; | ||
431 | } | ||
432 | |||
433 | static int MyStrCopy(char *target, const char *source) { | ||
434 | int i = 0; | ||
435 | while (*source != '\0') { | ||
436 | *target = *source; | ||
437 | ++target; | ||
438 | ++source; | ||
439 | ++i; | ||
440 | } | ||
441 | *target = 0; | ||
442 | return i; | ||
443 | } | ||
444 | |||
445 | |||
446 | |||
447 | void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) { | ||
448 | int i; | ||
449 | t_symbol *prefixSymbol = 0; | ||
450 | char prefixBuf[1000]; | ||
451 | char *endOfPrefix; | ||
452 | t_atom a[1]; | ||
453 | |||
454 | if (argc >= 1 && argv[0].a_type == A_SYMBOL) { | ||
455 | prefixSymbol = argv[0].a_w.w_symbol; | ||
456 | endOfPrefix = prefixBuf + MyStrCopy(prefixBuf, | ||
457 | prefixSymbol->s_name); | ||
458 | } else { | ||
459 | prefixSymbol = ps_emptySymbol; | ||
460 | prefixBuf[0] = '\0'; | ||
461 | endOfPrefix = prefixBuf; | ||
462 | } | ||
463 | |||
464 | |||
465 | for (i = 0; i < x->x_num; ++i) { | ||
466 | post("OSC: %s%s", prefixSymbol->s_name, x->x_prefixes[i]); | ||
467 | MyStrCopy(endOfPrefix, x->x_prefixes[i]); | ||
468 | SETSYMBOL(a, gensym(prefixBuf)); | ||
469 | outlet_anything(x->x_outlets[i], s, 1, a); | ||
470 | } | ||
471 | } | ||
472 | |||
473 | |||
474 | /* --------------------------------------------------- */ | ||
475 | |||
476 | |||
477 | |||
478 | static const char *theWholePattern; /* Just for warning messages */ | ||
479 | |||
480 | static Boolean MatchBrackets (const char *pattern, const char *test); | ||
481 | static Boolean MatchList (const char *pattern, const char *test); | ||
482 | |||
483 | Boolean PatternMatch (const char * pattern, const char * test) { | ||
484 | theWholePattern = pattern; | ||
485 | |||
486 | if (pattern == 0 || pattern[0] == 0) { | ||
487 | return test[0] == 0; | ||
488 | } | ||
489 | |||
490 | if (test[0] == 0) { | ||
491 | if (pattern[0] == '*') | ||
492 | return PatternMatch (pattern+1,test); | ||
493 | else | ||
494 | return FALSE; | ||
495 | } | ||
496 | |||
497 | switch (pattern[0]) { | ||
498 | case 0 : return test[0] == 0; | ||
499 | case '?' : return PatternMatch (pattern + 1, test + 1); | ||
500 | case '*' : | ||
501 | if (PatternMatch (pattern+1, test)) { | ||
502 | return TRUE; | ||
503 | } else { | ||
504 | return PatternMatch (pattern, test+1); | ||
505 | } | ||
506 | case ']' : | ||
507 | case '}' : | ||
508 | OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern); | ||
509 | return FALSE; | ||
510 | case '[' : | ||
511 | return MatchBrackets (pattern,test); | ||
512 | case '{' : | ||
513 | return MatchList (pattern,test); | ||
514 | case '\\' : | ||
515 | if (pattern[1] == 0) { | ||
516 | return test[0] == 0; | ||
517 | } else if (pattern[1] == test[0]) { | ||
518 | return PatternMatch (pattern+2,test+1); | ||
519 | } else { | ||
520 | return FALSE; | ||
521 | } | ||
522 | default : | ||
523 | if (pattern[0] == test[0]) { | ||
524 | return PatternMatch (pattern+1,test+1); | ||
525 | } else { | ||
526 | return FALSE; | ||
527 | } | ||
528 | } | ||
529 | } | ||
530 | |||
531 | |||
532 | /* we know that pattern[0] == '[' and test[0] != 0 */ | ||
533 | |||
534 | static Boolean MatchBrackets (const char *pattern, const char *test) { | ||
535 | Boolean result; | ||
536 | Boolean negated = FALSE; | ||
537 | const char *p = pattern; | ||
538 | |||
539 | if (pattern[1] == 0) { | ||
540 | OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern); | ||
541 | return FALSE; | ||
542 | } | ||
543 | |||
544 | if (pattern[1] == '!') { | ||
545 | negated = TRUE; | ||
546 | p++; | ||
547 | } | ||
548 | |||
549 | while (*p != ']') { | ||
550 | if (*p == 0) { | ||
551 | OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern); | ||
552 | return FALSE; | ||
553 | } | ||
554 | if (p[1] == '-' && p[2] != 0) { | ||
555 | if (test[0] >= p[0] && test[0] <= p[2]) { | ||
556 | result = !negated; | ||
557 | goto advance; | ||
558 | } | ||
559 | } | ||
560 | if (p[0] == test[0]) { | ||
561 | result = !negated; | ||
562 | goto advance; | ||
563 | } | ||
564 | p++; | ||
565 | } | ||
566 | |||
567 | result = negated; | ||
568 | |||
569 | advance: | ||
570 | |||
571 | if (!result) | ||
572 | return FALSE; | ||
573 | |||
574 | while (*p != ']') { | ||
575 | if (*p == 0) { | ||
576 | OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern); | ||
577 | return FALSE; | ||
578 | } | ||
579 | p++; | ||
580 | } | ||
581 | |||
582 | return PatternMatch (p+1,test+1); | ||
583 | } | ||
584 | |||
585 | static Boolean MatchList (const char *pattern, const char *test) { | ||
586 | |||
587 | const char *restOfPattern, *tp = test; | ||
588 | |||
589 | |||
590 | for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) { | ||
591 | if (*restOfPattern == 0) { | ||
592 | OSCWarning("Unterminated { in pattern \".../%s/...\"", theWholePattern); | ||
593 | return FALSE; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | restOfPattern++; /* skip close curly brace */ | ||
598 | |||
599 | |||
600 | pattern++; /* skip open curly brace */ | ||
601 | |||
602 | while (1) { | ||
603 | |||
604 | if (*pattern == ',') { | ||
605 | if (PatternMatch (restOfPattern, tp)) { | ||
606 | return TRUE; | ||
607 | } else { | ||
608 | tp = test; | ||
609 | ++pattern; | ||
610 | } | ||
611 | } else if (*pattern == '}') { | ||
612 | return PatternMatch (restOfPattern, tp); | ||
613 | } else if (*pattern == *tp) { | ||
614 | ++pattern; | ||
615 | ++tp; | ||
616 | } else { | ||
617 | tp = test; | ||
618 | while (*pattern != ',' && *pattern != '}') { | ||
619 | pattern++; | ||
620 | } | ||
621 | if (*pattern == ',') { | ||
622 | pattern++; | ||
623 | } | ||
624 | } | ||
625 | } | ||
626 | |||
627 | } | ||
628 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/bandpass-help.pd b/apps/plugins/pdbox/PDa/extra/bandpass-help.pd deleted file mode 100644 index 52feeb16c2..0000000000 --- a/apps/plugins/pdbox/PDa/extra/bandpass-help.pd +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #N canvas 428 285 240 300 8; | ||
2 | #X obj 24 78 noise~; | ||
3 | #X obj 15 215 dac~; | ||
4 | #X obj 24 167 biquad~; | ||
5 | #X floatatom 67 76 5 0 0 0 - - -; | ||
6 | #X floatatom 83 111 5 0 0 0 - - -; | ||
7 | #X obj 67 138 bandpass 600 10; | ||
8 | #X text 77 97 bandwidth: 100 = 1 octave; | ||
9 | #X text 67 58 frequency; | ||
10 | #X text 8 11 Calculation of biquad coefficients; | ||
11 | #X text 7 21 ==================================; | ||
12 | #X connect 0 0 2 0; | ||
13 | #X connect 2 0 1 0; | ||
14 | #X connect 2 0 1 1; | ||
15 | #X connect 3 0 5 0; | ||
16 | #X connect 4 0 5 1; | ||
17 | #X connect 5 0 2 0; | ||
18 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/dumpOSC.c b/apps/plugins/pdbox/PDa/extra/dumpOSC.c deleted file mode 100644 index b4ef97d7d1..0000000000 --- a/apps/plugins/pdbox/PDa/extra/dumpOSC.c +++ /dev/null | |||
@@ -1,1000 +0,0 @@ | |||
1 | /* | ||
2 | Written by Matt Wright and Adrian Freed, The Center for New Music and | ||
3 | Audio Technologies, University of California, Berkeley. Copyright (c) | ||
4 | 1992,93,94,95,96,97,98,99,2000,01,02,03,04 The Regents of the University of | ||
5 | California (Regents). | ||
6 | |||
7 | Permission to use, copy, modify, distribute, and distribute modified versions | ||
8 | of this software and its documentation without fee and without a signed | ||
9 | licensing agreement, is hereby granted, provided that the above copyright | ||
10 | notice, this paragraph and the following two paragraphs appear in all copies, | ||
11 | modifications, and distributions. | ||
12 | |||
13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
14 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING | ||
15 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS | ||
16 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
17 | |||
18 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
19 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
21 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
22 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
23 | |||
24 | |||
25 | The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl | ||
26 | */ | ||
27 | |||
28 | |||
29 | /* | ||
30 | |||
31 | dumpOSC.c | ||
32 | server that displays OpenSoundControl messages sent to it | ||
33 | for debugging client udp and UNIX protocol | ||
34 | |||
35 | by Matt Wright, 6/3/97 | ||
36 | modified from dumpSC.c, by Matt Wright and Adrian Freed | ||
37 | |||
38 | version 0.2: Added "-silent" option a.k.a. "-quiet" | ||
39 | |||
40 | version 0.3: Incorporated patches from Nicola Bernardini to make | ||
41 | things Linux-friendly. Also added ntohl() in the right places | ||
42 | to support little-endian architectures. | ||
43 | |||
44 | |||
45 | |||
46 | compile: | ||
47 | cc -o dumpOSC dumpOSC.c | ||
48 | |||
49 | to-do: | ||
50 | |||
51 | More robustness in saying exactly what's wrong with ill-formed | ||
52 | messages. (If they don't make sense, show exactly what was | ||
53 | received.) | ||
54 | |||
55 | Time-based features: print time-received for each packet | ||
56 | |||
57 | Clean up to separate OSC parsing code from socket/select stuff | ||
58 | |||
59 | pd: branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/dumpOSC/dumpOSC.c | ||
60 | ------------- | ||
61 | -- added pd functions | ||
62 | -- socket is made differently than original via pd mechanisms | ||
63 | -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 | ||
64 | -- the OSX changes from cnmat didnt make it here yet but this compiles | ||
65 | on OSX anyway. | ||
66 | |||
67 | */ | ||
68 | |||
69 | #if HAVE_CONFIG_H | ||
70 | #include <config.h> | ||
71 | #endif | ||
72 | |||
73 | #include "../src/m_pd.h" | ||
74 | //#include "m_imp.h" | ||
75 | #include "s_stuff.h" | ||
76 | |||
77 | /* declarations */ | ||
78 | |||
79 | // typedef void (*t_fdpollfn)(void *ptr, int fd); | ||
80 | void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr); | ||
81 | |||
82 | |||
83 | #if defined(__sgi) || defined(__linux) || defined(WIN32) || defined(__APPLE__) | ||
84 | |||
85 | #ifdef WIN32 | ||
86 | #include "OSC-common.h" | ||
87 | #include <winsock2.h> | ||
88 | #include <string.h> | ||
89 | #include <stdlib.h> | ||
90 | #include <fcntl.h> | ||
91 | #include <sys/types.h> | ||
92 | #include <sys/stat.h> | ||
93 | #include <ctype.h> | ||
94 | #include <signal.h> | ||
95 | #else | ||
96 | #include <stdio.h> | ||
97 | #include <string.h> | ||
98 | #include <stdlib.h> | ||
99 | #include <unistd.h> | ||
100 | #include <fcntl.h> | ||
101 | #include <sys/types.h> | ||
102 | #include <sys/stat.h> | ||
103 | #include <netinet/in.h> | ||
104 | #include <rpc/rpc.h> | ||
105 | #include <sys/socket.h> | ||
106 | #include <sys/un.h> | ||
107 | #include <sys/times.h> | ||
108 | #include <sys/param.h> | ||
109 | #include <sys/time.h> | ||
110 | #include <sys/ioctl.h> | ||
111 | #include <ctype.h> | ||
112 | #include <arpa/inet.h> | ||
113 | #include <netdb.h> | ||
114 | #include <pwd.h> | ||
115 | #include <signal.h> | ||
116 | #include <grp.h> | ||
117 | #include <sys/file.h> | ||
118 | //#include <sys/prctl.h> | ||
119 | |||
120 | #ifdef NEED_SCHEDCTL_AND_LOCK | ||
121 | #include <sys/schedctl.h> | ||
122 | #include <sys/lock.h> | ||
123 | #endif | ||
124 | #endif | ||
125 | |||
126 | |||
127 | char *htm_error_string; | ||
128 | typedef int Boolean; | ||
129 | typedef void *OBJ; | ||
130 | |||
131 | typedef struct ClientAddressStruct { | ||
132 | struct sockaddr_in cl_addr; | ||
133 | int clilen; | ||
134 | int sockfd; | ||
135 | } *ClientAddr; | ||
136 | |||
137 | typedef unsigned long long osc_time_t; | ||
138 | |||
139 | Boolean ShowBytes = FALSE; | ||
140 | Boolean Silent = FALSE; | ||
141 | |||
142 | /* Declarations */ | ||
143 | #ifndef WIN32 | ||
144 | static int unixinitudp(int chan); | ||
145 | #endif | ||
146 | |||
147 | static int initudp(int chan); | ||
148 | static void closeudp(int sockfd); | ||
149 | Boolean ClientReply(int packetsize, void *packet, int socketfd, | ||
150 | void *clientaddresspointer, int clientaddressbufferlength); | ||
151 | void sgi_CleanExit(void); | ||
152 | Boolean sgi_HaveToQuit(void); | ||
153 | int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy); | ||
154 | static void catch_sigint(); | ||
155 | static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd) ; | ||
156 | char *DataAfterAlignedString(char *string, char *boundary) ; | ||
157 | Boolean IsNiceString(char *string, char *boundary) ; | ||
158 | void complain(char *s, ...); | ||
159 | |||
160 | #define MAXMESG 32768 | ||
161 | static char mbuf[MAXMESG]; | ||
162 | |||
163 | /* ----------------------------- dumpOSC ------------------------- */ | ||
164 | |||
165 | #define MAXOUTAT 50 | ||
166 | |||
167 | static t_class *dumpOSC_class; | ||
168 | |||
169 | typedef struct _dumpOSC | ||
170 | { | ||
171 | t_object x_obj; | ||
172 | t_outlet *x_msgout; | ||
173 | t_outlet *x_connectout; | ||
174 | t_atom x_outat[MAXOUTAT]; | ||
175 | int x_outatc; | ||
176 | t_binbuf *x_b; | ||
177 | int x_connectsocket; | ||
178 | int x_nconnections; | ||
179 | int x_udp; | ||
180 | struct sockaddr_in x_server; | ||
181 | int x_clilen; | ||
182 | } t_dumpOSC; | ||
183 | |||
184 | void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr); | ||
185 | Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd); | ||
186 | static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr); | ||
187 | static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n); | ||
188 | static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma); | ||
189 | |||
190 | static void dumpOSC_read(t_dumpOSC *x, int sockfd) { | ||
191 | int clilen = x->x_clilen; | ||
192 | int n; | ||
193 | struct ClientAddressStruct ras; | ||
194 | ClientAddr ra = &ras; | ||
195 | |||
196 | //catchupflag= FALSE; | ||
197 | |||
198 | /* if (ShowBytes) { */ | ||
199 | /* int i; */ | ||
200 | /* printf("%d byte message:\n", n); */ | ||
201 | /* for (i = 0; i < n; ++i) { */ | ||
202 | /* printf(" %x (%c)\t", m[i], m[i]); */ | ||
203 | /* if (i%4 == 3) printf("\n"); */ | ||
204 | /* } */ | ||
205 | /* printf("\n"); */ | ||
206 | /* } */ | ||
207 | |||
208 | // return catchupflag; | ||
209 | //struct sockaddr_in x->x_server; | ||
210 | //while( (n = recvfrom(sockfd, mbuf, MAXMESG, 0, &cl_addr, &clilen)) >0) | ||
211 | // while(( | ||
212 | |||
213 | #ifdef WIN32 | ||
214 | if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0) | ||
215 | #else | ||
216 | if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0) | ||
217 | #endif | ||
218 | { | ||
219 | //int r; | ||
220 | ras.cl_addr = *((struct sockaddr_in *) &x->x_server); | ||
221 | ras.clilen = x->x_clilen; | ||
222 | ras.sockfd = x->x_connectsocket; | ||
223 | |||
224 | #ifdef DEBUG | ||
225 | printf("dumpOSC_read: received UDP packet of length %d\n", n); | ||
226 | #endif | ||
227 | |||
228 | if(!dumpOSC_SendReply(mbuf, n, &x->x_server, clilen, sockfd)) | ||
229 | { | ||
230 | dumpOSC_ParsePacket(x, mbuf, n, ra); | ||
231 | } | ||
232 | //r = Synthmessage(mbuf, n, &x->x_server, clilen, sockfd); | ||
233 | //post ("%d", r); | ||
234 | //outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, | ||
235 | // emsg-msg-1, at + msg + 1); | ||
236 | // outlet_list(x->x_msgout, 0, n, mbuf); | ||
237 | //if( sgi_HaveToQuit()) goto out; | ||
238 | //if(r>0) goto back; | ||
239 | //clilen = maxclilen; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | static void *dumpOSC_new(t_symbol *compatflag, | ||
244 | t_floatarg fportno) { | ||
245 | t_dumpOSC *x; | ||
246 | struct sockaddr_in server; | ||
247 | int clilen=sizeof(server); | ||
248 | int sockfd; | ||
249 | int portno=fportno; | ||
250 | int udp = 1; | ||
251 | |||
252 | //x->x_b = binbuf_new(); | ||
253 | //x->x_outat = binbuf_getvec(x->x_b); | ||
254 | |||
255 | //{{raf}} pointer not valid yet...moving this down | ||
256 | //x->x_outatc = 0; {{raf}} | ||
257 | |||
258 | /* create a socket */ | ||
259 | if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1) | ||
260 | { | ||
261 | sys_sockerror("socket"); | ||
262 | return (0); | ||
263 | } | ||
264 | |||
265 | server.sin_family = AF_INET; | ||
266 | server.sin_addr.s_addr = INADDR_ANY; | ||
267 | /* assign server port number */ | ||
268 | server.sin_port = htons((u_short)portno); | ||
269 | /* name the socket */ | ||
270 | if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) | ||
271 | { | ||
272 | sys_sockerror("bind"); | ||
273 | sys_closesocket(sockfd); | ||
274 | return (0); | ||
275 | } | ||
276 | |||
277 | x = (t_dumpOSC *)pd_new(dumpOSC_class); | ||
278 | x->x_outatc = 0; // {{raf}} now pointer is valid (less invalid) | ||
279 | |||
280 | x->x_msgout = outlet_new(&x->x_obj, &s_anything); | ||
281 | |||
282 | // if (udp) /* datagram protocol */ | ||
283 | { | ||
284 | |||
285 | sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x); | ||
286 | x->x_connectout = 0; | ||
287 | } | ||
288 | // else /* streaming protocol */ | ||
289 | /* { */ | ||
290 | /* if (listen(sockfd, 5) < 0) */ | ||
291 | /* { */ | ||
292 | /* sys_sockerror("listen"); */ | ||
293 | /* sys_closesocket(sockfd); */ | ||
294 | /* sockfd = -1; */ | ||
295 | /* } */ | ||
296 | /* else */ | ||
297 | /* { */ | ||
298 | /* sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_connectpoll, x); */ | ||
299 | /* x->x_connectout = outlet_new(&x->x_obj, &s_float); */ | ||
300 | /* } */ | ||
301 | /* } */ | ||
302 | |||
303 | x->x_connectsocket = sockfd; | ||
304 | x->x_server = server; | ||
305 | x->x_clilen = clilen; | ||
306 | x->x_nconnections = 0; | ||
307 | x->x_udp = udp; | ||
308 | |||
309 | return (x); | ||
310 | } | ||
311 | |||
312 | static void dumpOSC_free(t_dumpOSC *x) | ||
313 | { | ||
314 | /* LATER make me clean up open connections */ | ||
315 | if (x->x_connectsocket >= 0) | ||
316 | { | ||
317 | sys_rmpollfn(x->x_connectsocket); | ||
318 | sys_closesocket(x->x_connectsocket); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | #ifdef WIN32 | ||
323 | OSC_API void dumpOSC_setup(void) | ||
324 | #else | ||
325 | void dumpOSC_setup(void) | ||
326 | #endif | ||
327 | { | ||
328 | dumpOSC_class = class_new(gensym("dumpOSC"), | ||
329 | (t_newmethod)dumpOSC_new, (t_method)dumpOSC_free, | ||
330 | sizeof(t_dumpOSC), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT, | ||
331 | A_DEFSYM, 0); | ||
332 | class_sethelpsymbol(dumpOSC_class, gensym("dumpOSC-help.pd")); | ||
333 | } | ||
334 | |||
335 | |||
336 | #ifndef WIN32 | ||
337 | #define UNIXDG_PATH "/tmp/htm" | ||
338 | #define UNIXDG_TMP "/tmp/htm.XXXXXX" | ||
339 | static int unixinitudp(int chan) | ||
340 | { | ||
341 | struct sockaddr_un serv_addr; | ||
342 | int sockfd; | ||
343 | |||
344 | if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) | ||
345 | return sockfd; | ||
346 | |||
347 | bzero((char *)&serv_addr, sizeof(serv_addr)); | ||
348 | serv_addr.sun_family = AF_UNIX; | ||
349 | strcpy(serv_addr.sun_path, UNIXDG_PATH); | ||
350 | sprintf(serv_addr.sun_path+strlen(serv_addr.sun_path), "%d", chan); | ||
351 | unlink(serv_addr.sun_path); | ||
352 | if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path)) < 0) | ||
353 | { | ||
354 | perror("unable to bind\n"); | ||
355 | return -1; | ||
356 | } | ||
357 | |||
358 | fcntl(sockfd, F_SETFL, FNDELAY); | ||
359 | return sockfd; | ||
360 | } | ||
361 | #endif // #ifndef WIN32 | ||
362 | |||
363 | |||
364 | |||
365 | static int initudp(int chan) | ||
366 | { | ||
367 | |||
368 | #ifdef WIN32 | ||
369 | struct sockaddr_in serv_addr; | ||
370 | unsigned int sockfd; | ||
371 | ULONG nonBlocking = (ULONG) TRUE; | ||
372 | |||
373 | if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET ) { | ||
374 | ZeroMemory((char *)&serv_addr, sizeof(serv_addr)); | ||
375 | serv_addr.sin_family = AF_INET; | ||
376 | serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
377 | serv_addr.sin_port = htons(chan); | ||
378 | if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) { | ||
379 | // set for non-blocking mode | ||
380 | if(ioctlsocket(sockfd, FIONBIO, &nonBlocking) == SOCKET_ERROR) { | ||
381 | perror("unable to set non-blocking\n"); | ||
382 | return -1; | ||
383 | } | ||
384 | } | ||
385 | else { perror("unable to bind\n"); return -1; } | ||
386 | } | ||
387 | return (sockfd == INVALID_SOCKET ? -1 : (int)sockfd); | ||
388 | #else | ||
389 | struct sockaddr_in serv_addr; | ||
390 | int sockfd; | ||
391 | |||
392 | if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) | ||
393 | return sockfd; | ||
394 | |||
395 | bzero((char *)&serv_addr, sizeof(serv_addr)); | ||
396 | serv_addr.sin_family = AF_INET; | ||
397 | serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
398 | serv_addr.sin_port = htons(chan); | ||
399 | |||
400 | if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) | ||
401 | { | ||
402 | perror("unable to bind\n"); | ||
403 | return -1; | ||
404 | } | ||
405 | |||
406 | fcntl(sockfd, F_SETFL, FNDELAY); | ||
407 | return sockfd; | ||
408 | #endif | ||
409 | } | ||
410 | |||
411 | |||
412 | |||
413 | |||
414 | |||
415 | |||
416 | |||
417 | |||
418 | static void closeudp(int sockfd) { | ||
419 | #ifdef WIN32 | ||
420 | closesocket(sockfd); | ||
421 | #else | ||
422 | close(sockfd); | ||
423 | #endif | ||
424 | } | ||
425 | |||
426 | static Boolean catchupflag=FALSE; | ||
427 | Boolean ClientReply(int packetsize, void *packet, int socketfd, | ||
428 | void *clientaddresspointer, int clientaddressbufferlength) | ||
429 | { | ||
430 | if(!clientaddresspointer) return FALSE; | ||
431 | catchupflag= TRUE; | ||
432 | return packetsize==sendto(socketfd, packet, packetsize, 0, clientaddresspointer, clientaddressbufferlength); | ||
433 | } | ||
434 | |||
435 | static Boolean exitflag= FALSE; | ||
436 | void sgi_CleanExit(void) { | ||
437 | exitflag = TRUE; | ||
438 | } | ||
439 | |||
440 | Boolean sgi_HaveToQuit(void) { | ||
441 | return exitflag; | ||
442 | } | ||
443 | |||
444 | |||
445 | /* file descriptor poll table */ | ||
446 | static int npolldevs =0; | ||
447 | typedef struct polldev | ||
448 | { | ||
449 | int fd; | ||
450 | void (*callbackfunction)(int , void *); | ||
451 | void *dummy; | ||
452 | } polldev; | ||
453 | #define TABMAX 8 | ||
454 | static polldev polldevs[TABMAX]; | ||
455 | |||
456 | |||
457 | /* Register a device (referred to by a file descriptor that the caller | ||
458 | should have already successfully obtained from a system call) to be | ||
459 | polled as real-time constraints allowed. | ||
460 | |||
461 | When a select(2) call indicates activity on the file descriptor, the | ||
462 | callback function is called with the file descripter as first | ||
463 | argument and the given dummy argument (presumably a pointer to the | ||
464 | instance variables associated with the device). | ||
465 | */ | ||
466 | int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy) | ||
467 | { | ||
468 | if(npolldevs<TABMAX) | ||
469 | { | ||
470 | polldevs[npolldevs].fd = fd; | ||
471 | polldevs[npolldevs].callbackfunction = callbackfunction; | ||
472 | polldevs[npolldevs].dummy = dummy; | ||
473 | } | ||
474 | else return -1; | ||
475 | return npolldevs++; | ||
476 | } | ||
477 | |||
478 | static int caught_sigint; | ||
479 | |||
480 | static void catch_sigint() { | ||
481 | caught_sigint = 1; | ||
482 | } | ||
483 | static int sockfd, usockfd; | ||
484 | |||
485 | |||
486 | void PrintClientAddr(ClientAddr CA) { | ||
487 | unsigned long addr = CA->cl_addr.sin_addr.s_addr; | ||
488 | printf("Client address %p:\n", CA); | ||
489 | printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd); | ||
490 | printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family, | ||
491 | CA->cl_addr.sin_port); | ||
492 | printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr)); | ||
493 | |||
494 | printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n", | ||
495 | CA->cl_addr.sin_zero[0], | ||
496 | CA->cl_addr.sin_zero[1], | ||
497 | CA->cl_addr.sin_zero[2], | ||
498 | CA->cl_addr.sin_zero[3], | ||
499 | CA->cl_addr.sin_zero[4], | ||
500 | CA->cl_addr.sin_zero[5], | ||
501 | CA->cl_addr.sin_zero[6], | ||
502 | CA->cl_addr.sin_zero[7]); | ||
503 | |||
504 | printf("\n"); | ||
505 | } | ||
506 | |||
507 | //******************* | ||
508 | |||
509 | void WriteTime(char* dst, osc_time_t osctime) | ||
510 | { | ||
511 | *(int32_t*)dst = htonl((int32_t)(osctime >> 32)); | ||
512 | *(int32_t*)(dst+4) = htonl((int32_t)osctime); | ||
513 | } | ||
514 | |||
515 | void WriteMode(char* dst) | ||
516 | { | ||
517 | *(int32_t*)dst = htonl(0); | ||
518 | } | ||
519 | |||
520 | osc_time_t ReadTime(const char* src) | ||
521 | { | ||
522 | osc_time_t osctime = ntohl(*(int32_t*)src); | ||
523 | return (osctime << 32) + ntohl(*(int32_t*)(src+4)); | ||
524 | } | ||
525 | |||
526 | double TimeToSeconds(osc_time_t osctime) | ||
527 | { | ||
528 | return (double)osctime * 2.3283064365386962890625e-10 /* 1/2^32 */; | ||
529 | } | ||
530 | |||
531 | int timeRound(double x) | ||
532 | { | ||
533 | return x >= 0.0 ? x+0.5 : x-0.5; | ||
534 | } | ||
535 | /* | ||
536 | void WriteLogicalTime(char* dst) | ||
537 | { | ||
538 | static double startTime = -1.0; | ||
539 | double sTime; | ||
540 | |||
541 | // Initialisierung der Startzeit. | ||
542 | // Knnte effizienter (ohne 'if') auch irgendwo vorher passieren. | ||
543 | // Knnte wahrscheinlich auch 0.0 sein. | ||
544 | if (startTime < 0.0) { | ||
545 | startTime = clock_getlogicaltime(); | ||
546 | } | ||
547 | |||
548 | sTime = clock_gettimesince(startTime) * 0.001; | ||
549 | *(int32_t*)dst = hton'K l((int32_t)sTime); | ||
550 | *(int32_t*)(dst+4) = htonl((int32_t)(4294967296.0 * sTime)); | ||
551 | } | ||
552 | */ | ||
553 | |||
554 | void WriteLogicalTime(char* dst) | ||
555 | { | ||
556 | double sTime = clock_gettimesince(19230720) / 1000.0; | ||
557 | double tau = sTime - timeRound(sTime); | ||
558 | |||
559 | //fprintf(stderr, "sSec = %f tau = %f\n", sTime, tau); | ||
560 | |||
561 | *(int32_t*)dst = htonl((int32_t)(sTime)); | ||
562 | *(int32_t*)(dst+4) = htonl((int32_t)(4294967296 * tau)); | ||
563 | } | ||
564 | |||
565 | Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd) | ||
566 | { | ||
567 | if((n == 24) && (strcmp(buf, "#time") == 0)) | ||
568 | { | ||
569 | osc_time_t t0, t1, t2; | ||
570 | double dt0, dt1, dt2; | ||
571 | |||
572 | WriteMode(buf+6); | ||
573 | |||
574 | t0 = ReadTime(buf+8); | ||
575 | |||
576 | WriteLogicalTime(buf+16); | ||
577 | t1 = ReadTime(buf+16); // reverse | ||
578 | dt0 = TimeToSeconds(t0); // client time | ||
579 | dt1 = TimeToSeconds(t1); // server time | ||
580 | |||
581 | // fprintf(stderr, "%f\t%f\t%f\n", dt0, dt1, dt0 - dt1); | ||
582 | |||
583 | sendto(fd, buf, n, 0, (struct sockaddr *)clientDesc, clientDescLenght); | ||
584 | return TRUE; | ||
585 | } | ||
586 | else | ||
587 | { | ||
588 | return FALSE; | ||
589 | } | ||
590 | } | ||
591 | |||
592 | //********************** | ||
593 | |||
594 | void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr) { | ||
595 | // t_dumpOSC *x; | ||
596 | int size, messageLen, i; | ||
597 | char *messageName; | ||
598 | char *args; | ||
599 | |||
600 | //#ifdef PRINTADDRS | ||
601 | #ifdef DEBUG | ||
602 | //PrintClientAddr(returnAddr); | ||
603 | #endif | ||
604 | |||
605 | |||
606 | if ((n%4) != 0) { | ||
607 | complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping", n); | ||
608 | return; | ||
609 | } | ||
610 | |||
611 | if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) { | ||
612 | /* This is a bundle message. */ | ||
613 | #ifdef DEBUG | ||
614 | printf("dumpOSC_ParsePacket: bundle msg: bundles not yet supported\n"); | ||
615 | #endif | ||
616 | |||
617 | if (n < 16) { | ||
618 | complain("Bundle message too small (%d bytes) for time tag", n); | ||
619 | return; | ||
620 | } | ||
621 | |||
622 | /* Print the time tag */ | ||
623 | #ifdef DEBUG | ||
624 | printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))), ntohl(*((unsigned long *)(buf+12)))); | ||
625 | #endif | ||
626 | |||
627 | /* Note: if we wanted to actually use the time tag as a little-endian | ||
628 | 64-bit int, we'd have to word-swap the two 32-bit halves of it */ | ||
629 | |||
630 | i = 16; /* Skip "#group\0" and time tag */ | ||
631 | |||
632 | while(i<n) { | ||
633 | size = ntohl(*((int *) (buf + i))); | ||
634 | if ((size % 4) != 0) { | ||
635 | complain("Bad size count %d in bundle (not a multiple of 4)", size); | ||
636 | return; | ||
637 | } | ||
638 | if ((size + i + 4) > n) { | ||
639 | complain("Bad size count %d in bundle (only %d bytes left in entire bundle)", | ||
640 | size, n-i-4); | ||
641 | return; | ||
642 | } | ||
643 | |||
644 | /* Recursively handle element of bundle */ | ||
645 | dumpOSC_ParsePacket(x, buf+i+4, size, returnAddr); | ||
646 | i += 4 + size; | ||
647 | } | ||
648 | |||
649 | if (i != n) { | ||
650 | complain("This can't happen"); | ||
651 | } | ||
652 | #ifdef DEBUG | ||
653 | printf("]\n"); | ||
654 | #endif | ||
655 | |||
656 | } | ||
657 | else if ((n == 24) && (strcmp(buf, "#time") == 0)) | ||
658 | { | ||
659 | complain("Time message: %s\n :).\n", htm_error_string); | ||
660 | return; | ||
661 | |||
662 | } | ||
663 | else | ||
664 | { | ||
665 | /* This is not a bundle message */ | ||
666 | |||
667 | messageName = buf; | ||
668 | args = DataAfterAlignedString(messageName, buf+n); | ||
669 | if (args == 0) { | ||
670 | complain("Bad message name string: %s\nDropping entire message.\n", | ||
671 | htm_error_string); | ||
672 | return; | ||
673 | } | ||
674 | messageLen = args-messageName; | ||
675 | dumpOSC_Smessage(x, messageName, (void *)args, n-messageLen, returnAddr); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | #define SMALLEST_POSITIVE_FLOAT 0.000001f | ||
680 | |||
681 | static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr) { | ||
682 | char *chars = v; | ||
683 | t_atom at; | ||
684 | //t_atom myargv[50]; | ||
685 | |||
686 | int myargc = x->x_outatc; | ||
687 | t_atom* mya = x->x_outat; | ||
688 | int myi; | ||
689 | |||
690 | #ifdef DEBUG | ||
691 | printf("%s ", address); | ||
692 | #endif | ||
693 | |||
694 | // ztoln+cvt from envgen.c, ggee-0.18 .. | ||
695 | // outlet_anything's 'symbol' gets set to address | ||
696 | // so we dont need to append address to the atomlist | ||
697 | /* | ||
698 | SETSYMBOL(mya,gensym(address));myargc++; | ||
699 | x->x_outatc = myargc; | ||
700 | */ | ||
701 | |||
702 | if (n != 0) { | ||
703 | if (chars[0] == ',') { | ||
704 | if (chars[1] != ',') { | ||
705 | /* This message begins with a type-tag string */ | ||
706 | dumpOSC_PrintTypeTaggedArgs(x, v, n); | ||
707 | } else { | ||
708 | /* Double comma means an escaped real comma, not a type string */ | ||
709 | dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1); | ||
710 | } | ||
711 | } else { | ||
712 | dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0); | ||
713 | } | ||
714 | } | ||
715 | |||
716 | outlet_anything(x->x_msgout,gensym(address),x->x_outatc,(t_atom*)&x->x_outat); | ||
717 | x->x_outatc = 0; | ||
718 | #ifdef DEBUG | ||
719 | printf("\n"); | ||
720 | #endif | ||
721 | fflush(stdout); /* Added for Sami 5/21/98 */ | ||
722 | } | ||
723 | |||
724 | static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n) { | ||
725 | char *typeTags, *thisType; | ||
726 | char *p; | ||
727 | |||
728 | int myargc = x->x_outatc; | ||
729 | t_atom* mya = x->x_outat; | ||
730 | int myi; | ||
731 | |||
732 | typeTags = v; | ||
733 | |||
734 | if (!IsNiceString(typeTags, typeTags+n)) { | ||
735 | /* No null-termination, so maybe it wasn't a type tag | ||
736 | string after all */ | ||
737 | dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0); | ||
738 | return; | ||
739 | } | ||
740 | |||
741 | p = DataAfterAlignedString(typeTags, typeTags+n); | ||
742 | |||
743 | |||
744 | for (thisType = typeTags + 1; *thisType != 0; ++thisType) { | ||
745 | switch (*thisType) { | ||
746 | case 'i': case 'r': case 'm': case 'c': | ||
747 | #ifdef DEBUG | ||
748 | //post("integer: %d", ntohl(*((int *) p))); | ||
749 | #endif | ||
750 | /* Martin Peach fix for negative floats: | ||
751 | * was: SETFLOAT(mya+myargc,ntohl(*((int *) p))); | ||
752 | * now is: | ||
753 | */ | ||
754 | SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p))); | ||
755 | myargc++; | ||
756 | |||
757 | p += 4; | ||
758 | break; | ||
759 | |||
760 | case 'f': { | ||
761 | int i = ntohl(*((int *) p)); | ||
762 | float *floatp = ((float *) (&i)); | ||
763 | #ifdef DEBUG | ||
764 | post("float: %f", *floatp); | ||
765 | #endif | ||
766 | SETFLOAT(mya+myargc,*floatp); | ||
767 | myargc++; | ||
768 | |||
769 | p += 4; | ||
770 | } | ||
771 | break; | ||
772 | |||
773 | case 'h': case 't': | ||
774 | #ifdef DEBUG | ||
775 | printf("[A 64-bit int] "); | ||
776 | #endif | ||
777 | post("[A 64-bit int] not implemented"); | ||
778 | |||
779 | p += 8; | ||
780 | break; | ||
781 | |||
782 | case 'd': | ||
783 | #ifdef DEBUG | ||
784 | printf("[A 64-bit float] "); | ||
785 | #endif | ||
786 | post("[A 64-bit float] not implemented"); | ||
787 | |||
788 | p += 8; | ||
789 | break; | ||
790 | |||
791 | case 's': case 'S': | ||
792 | if (!IsNiceString(p, typeTags+n)) { | ||
793 | post("Type tag said this arg is a string but it's not!\n"); | ||
794 | return; | ||
795 | } else { | ||
796 | #ifdef DEBUG | ||
797 | post("string: \"%s\"", p); | ||
798 | #endif | ||
799 | SETSYMBOL(mya+myargc,gensym(p)); | ||
800 | myargc++; | ||
801 | //outlet_list(x->x_msgout, 0,sizeof(p), p); | ||
802 | //outlet_anything(x->x_msgout, 0, sizeof(p), p); | ||
803 | p = DataAfterAlignedString(p, typeTags+n); | ||
804 | // append to output vector .. | ||
805 | } | ||
806 | break; | ||
807 | |||
808 | case 'T': | ||
809 | #ifdef DEBUG | ||
810 | printf("[True] "); | ||
811 | #endif | ||
812 | SETFLOAT(mya+myargc,1.); | ||
813 | myargc++; | ||
814 | break; | ||
815 | case 'F': | ||
816 | #ifdef DEBUG | ||
817 | printf("[False] "); | ||
818 | #endif | ||
819 | SETFLOAT(mya+myargc,0.); | ||
820 | myargc++; | ||
821 | break; | ||
822 | case 'N': | ||
823 | #ifdef DEBUG | ||
824 | printf("[Nil]"); | ||
825 | #endif | ||
826 | post("sendOSC: [Nil] not implemented"); | ||
827 | break; | ||
828 | case 'I': | ||
829 | #ifdef DEBUG | ||
830 | printf("[Infinitum]"); | ||
831 | #endif | ||
832 | post("sendOSC: [Infinitum] not implemented"); | ||
833 | break; | ||
834 | |||
835 | default: | ||
836 | post("sendOSC: [Unrecognized type tag %c]", *thisType); | ||
837 | // return; | ||
838 | } | ||
839 | } | ||
840 | x->x_outatc = myargc; | ||
841 | } | ||
842 | |||
843 | static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma) { | ||
844 | int i, thisi; | ||
845 | float thisf; | ||
846 | int *ints; | ||
847 | char *chars; | ||
848 | char *string, *nextString; | ||
849 | |||
850 | int myargc= x->x_outatc; | ||
851 | t_atom* mya = x->x_outat; | ||
852 | int myi; | ||
853 | |||
854 | |||
855 | /* Go through the arguments 32 bits at a time */ | ||
856 | ints = v; | ||
857 | chars = v; | ||
858 | |||
859 | for (i = 0; i<n/4; ) { | ||
860 | string = &chars[i*4]; | ||
861 | thisi = ntohl(ints[i]); | ||
862 | /* Reinterpret the (potentially byte-reversed) thisi as a float */ | ||
863 | thisf = *(((float *) (&thisi))); | ||
864 | |||
865 | if (thisi >= -1000 && thisi <= 1000000) { | ||
866 | #ifdef DEBUG | ||
867 | printf("%d ", thisi); | ||
868 | #endif | ||
869 | // append to output vector .. | ||
870 | SETFLOAT(mya+myargc,(t_float) (thisi)); | ||
871 | myargc++; | ||
872 | // outlet_float(x->x_msgout, thisi); | ||
873 | i++; | ||
874 | } else if (thisf >= -1000.f && thisf <= 1000000.f && | ||
875 | (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) { | ||
876 | #ifdef DEBUG | ||
877 | printf("%f ", thisf); | ||
878 | #endif | ||
879 | // append to output vector .. | ||
880 | SETFLOAT(mya+myargc,thisf); | ||
881 | myargc++; | ||
882 | //outlet_float(x->x_msgout, thisf); | ||
883 | i++; | ||
884 | } else if (IsNiceString(string, chars+n)) { | ||
885 | nextString = DataAfterAlignedString(string, chars+n); | ||
886 | #ifdef DEBUG | ||
887 | printf("\"%s\" ", (i == 0 && skipComma) ? string +1 : string); | ||
888 | #endif | ||
889 | // append to output vector .. | ||
890 | SETSYMBOL(mya+myargc,gensym(string)); | ||
891 | myargc++; | ||
892 | //outlet_symbol(x->x_msgout, gensym((i == 0 && skipComma) ? string +1 : string)); | ||
893 | i += (nextString-string) / 4; | ||
894 | } else { | ||
895 | // unhandled .. ;) | ||
896 | #ifdef DEBUG | ||
897 | printf("0x%x xx", ints[i]); | ||
898 | #endif | ||
899 | i++; | ||
900 | } | ||
901 | x->x_outatc = myargc; | ||
902 | } | ||
903 | } | ||
904 | |||
905 | |||
906 | #define STRING_ALIGN_PAD 4 | ||
907 | |||
908 | char *DataAfterAlignedString(char *string, char *boundary) | ||
909 | { | ||
910 | /* The argument is a block of data beginning with a string. The | ||
911 | string has (presumably) been padded with extra null characters | ||
912 | so that the overall length is a multiple of STRING_ALIGN_PAD | ||
913 | bytes. Return a pointer to the next byte after the null | ||
914 | byte(s). The boundary argument points to the character after | ||
915 | the last valid character in the buffer---if the string hasn't | ||
916 | ended by there, something's wrong. | ||
917 | |||
918 | If the data looks wrong, return 0, and set htm_error_string */ | ||
919 | |||
920 | int i; | ||
921 | |||
922 | if ((boundary - string) %4 != 0) { | ||
923 | fprintf(stderr, "Internal error: DataAfterAlignedString: bad boundary\n"); | ||
924 | return 0; | ||
925 | } | ||
926 | |||
927 | for (i = 0; string[i] != '\0'; i++) { | ||
928 | if (string + i >= boundary) { | ||
929 | htm_error_string = "DataAfterAlignedString: Unreasonably long string"; | ||
930 | return 0; | ||
931 | } | ||
932 | } | ||
933 | |||
934 | /* Now string[i] is the first null character */ | ||
935 | i++; | ||
936 | |||
937 | for (; (i % STRING_ALIGN_PAD) != 0; i++) { | ||
938 | if (string + i >= boundary) { | ||
939 | htm_error_string = "DataAfterAlignedString: Unreasonably long string"; | ||
940 | return 0; | ||
941 | } | ||
942 | if (string[i] != '\0') { | ||
943 | htm_error_string = "DataAfterAlignedString: Incorrectly padded string."; | ||
944 | return 0; | ||
945 | } | ||
946 | } | ||
947 | |||
948 | return string+i; | ||
949 | } | ||
950 | |||
951 | Boolean IsNiceString(char *string, char *boundary) | ||
952 | { | ||
953 | /* Arguments same as DataAfterAlignedString(). Is the given "string" | ||
954 | really a string? I.e., is it a sequence of isprint() characters | ||
955 | terminated with 1-4 null characters to align on a 4-byte boundary? */ | ||
956 | |||
957 | int i; | ||
958 | |||
959 | if ((boundary - string) %4 != 0) { | ||
960 | fprintf(stderr, "Internal error: IsNiceString: bad boundary\n"); | ||
961 | return 0; | ||
962 | } | ||
963 | |||
964 | for (i = 0; string[i] != '\0'; i++) { | ||
965 | if (!isprint(string[i])) return FALSE; | ||
966 | if (string + i >= boundary) return FALSE; | ||
967 | } | ||
968 | |||
969 | /* If we made it this far, it's a null-terminated sequence of printing characters | ||
970 | in the given boundary. Now we just make sure it's null padded... */ | ||
971 | |||
972 | /* Now string[i] is the first null character */ | ||
973 | i++; | ||
974 | for (; (i % STRING_ALIGN_PAD) != 0; i++) { | ||
975 | if (string[i] != '\0') return FALSE; | ||
976 | } | ||
977 | |||
978 | return TRUE; | ||
979 | } | ||
980 | |||
981 | |||
982 | |||
983 | |||
984 | |||
985 | |||
986 | |||
987 | |||
988 | |||
989 | #include <stdarg.h> | ||
990 | void complain(char *s, ...) { | ||
991 | va_list ap; | ||
992 | va_start(ap, s); | ||
993 | fprintf(stderr, "*** ERROR: "); | ||
994 | vfprintf(stderr, s, ap); | ||
995 | fprintf(stderr, "\n"); | ||
996 | va_end(ap); | ||
997 | } | ||
998 | |||
999 | #endif /* __sgi or LINUX or WIN32 */ | ||
1000 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/fatom.h b/apps/plugins/pdbox/PDa/extra/fatom.h deleted file mode 100644 index a7a153fad3..0000000000 --- a/apps/plugins/pdbox/PDa/extra/fatom.h +++ /dev/null | |||
@@ -1,486 +0,0 @@ | |||
1 | /* ------------------------ fatom ----------------------------- */ | ||
2 | |||
3 | #define x_val a_pos.a_w.w_float | ||
4 | #define DEBUG(x) | ||
5 | |||
6 | #include <string.h> | ||
7 | #include <stdio.h> | ||
8 | |||
9 | typedef struct _fatom | ||
10 | { | ||
11 | t_object x_obj; | ||
12 | t_atom a_pos; /* the value of the fatom */ | ||
13 | |||
14 | t_symbol* x_send; | ||
15 | t_symbol* x_receive; | ||
16 | t_glist * x_glist; /* value of the current canvas, intialized in _new */ | ||
17 | int x_rect_width; /* width of the widget */ | ||
18 | int x_rect_height; /* height of the widget */ | ||
19 | t_symbol* x_sym; /* symbol for receiving callbacks from GUI */ | ||
20 | t_symbol* x_type; /* type of fatom (vslider, hslider, checkbutton) */ | ||
21 | |||
22 | t_symbol* x_text; /* associated widget text */ | ||
23 | int x_max; /* maximum value of a_pos (x_val) */ | ||
24 | int x_min; /* minimum value of a_pos (x_val) */ | ||
25 | int x_width; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */ | ||
26 | t_symbol* x_color; | ||
27 | t_symbol* x_bgcolor; | ||
28 | } t_fatom; | ||
29 | |||
30 | /* widget helper functions */ | ||
31 | |||
32 | |||
33 | |||
34 | |||
35 | static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout) | ||
36 | { | ||
37 | int n = nin; | ||
38 | int nplus, i; | ||
39 | nplus = (n == 1 ? 1 : n-1); | ||
40 | DEBUG(post("draw inlet");) | ||
41 | for (i = 0; i < n; i++) | ||
42 | { | ||
43 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
44 | if (firsttime) | ||
45 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n", | ||
46 | glist_getcanvas(glist), | ||
47 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, | ||
48 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height, | ||
49 | x, i); | ||
50 | else | ||
51 | sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n", | ||
52 | glist_getcanvas(glist), x, i, | ||
53 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, | ||
54 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height); | ||
55 | } | ||
56 | n = nout; | ||
57 | nplus = (n == 1 ? 1 : n-1); | ||
58 | for (i = 0; i < n; i++) | ||
59 | { | ||
60 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
61 | if (firsttime) | ||
62 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n", | ||
63 | glist_getcanvas(glist), | ||
64 | onset, text_ypix(&x->x_obj, glist), | ||
65 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1, | ||
66 | x, i); | ||
67 | else | ||
68 | sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n", | ||
69 | glist_getcanvas(glist), x, i, | ||
70 | onset, text_ypix(&x->x_obj, glist), | ||
71 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1); | ||
72 | |||
73 | } | ||
74 | DEBUG(post("draw inlet end");) | ||
75 | } | ||
76 | |||
77 | |||
78 | static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) { | ||
79 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2); | ||
80 | |||
81 | if (firsttime) | ||
82 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n", | ||
83 | glist_getcanvas(glist), | ||
84 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12, | ||
85 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4, | ||
86 | x); | ||
87 | else | ||
88 | sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n", | ||
89 | glist_getcanvas(glist), x, | ||
90 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12, | ||
91 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4); | ||
92 | } | ||
93 | |||
94 | static void create_widget(t_fatom *x, t_glist *glist) | ||
95 | { | ||
96 | t_canvas *canvas=glist_getcanvas(glist); | ||
97 | |||
98 | if (!strcmp(x->x_type->s_name,"vslider")) { | ||
99 | x->x_rect_width = x->x_width+15; | ||
100 | x->x_rect_height = x->x_max-x->x_min+26; | ||
101 | |||
102 | sys_vgui("scale .x%x.c.s%x \ | ||
103 | -sliderlength 10 \ | ||
104 | -showvalue 0 \ | ||
105 | -length %d \ | ||
106 | -resolution 0.01 \ | ||
107 | -repeatinterval 20 \ | ||
108 | -from %d -to %d \ | ||
109 | -width %d \ | ||
110 | -bg %s \ | ||
111 | -activebackground %s \ | ||
112 | -troughcolor %s \ | ||
113 | -command fatom_cb%x\n",canvas,x, | ||
114 | x->x_max-x->x_min+14, | ||
115 | x->x_max, | ||
116 | x->x_min, | ||
117 | x->x_width, | ||
118 | x->x_color->s_name, | ||
119 | x->x_color->s_name, | ||
120 | x->x_bgcolor->s_name, | ||
121 | x); | ||
122 | } else if (!strcmp(x->x_type->s_name,"hslider")) { | ||
123 | x->x_rect_width = x->x_max-x->x_min + 24; | ||
124 | x->x_rect_height = x->x_width + 15; | ||
125 | sys_vgui("scale .x%x.c.s%x \ | ||
126 | -sliderlength 10 \ | ||
127 | -showvalue 0 \ | ||
128 | -length %d \ | ||
129 | -resolution 0.01 \ | ||
130 | -orient horizontal \ | ||
131 | -repeatinterval 20 \ | ||
132 | -from %d -to %d \ | ||
133 | -width %d \ | ||
134 | -bg %s \ | ||
135 | -activebackground %s \ | ||
136 | -troughcolor %s \ | ||
137 | -command fatom_cb%x\n",canvas,x, | ||
138 | x->x_max-x->x_min+14, | ||
139 | x->x_min, | ||
140 | x->x_max, | ||
141 | x->x_width, | ||
142 | x->x_color->s_name, | ||
143 | x->x_color->s_name, | ||
144 | x->x_bgcolor->s_name, | ||
145 | x); | ||
146 | } else if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
147 | x->x_rect_width = 32; | ||
148 | x->x_rect_height = 28; | ||
149 | sys_vgui("checkbutton .x%x.c.s%x \ | ||
150 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \ | ||
151 | -bg %s \ | ||
152 | -activebackground %s \ | ||
153 | \n",canvas,x,x,x,x, | ||
154 | x->x_text->s_name, | ||
155 | x->x_color->s_name, | ||
156 | x->x_bgcolor->s_name); | ||
157 | } else if (!strcmp(x->x_type->s_name,"hradio")) { | ||
158 | int i; | ||
159 | x->x_rect_width = 8*20; | ||
160 | x->x_rect_height = 25; | ||
161 | for (i=0;i<8;i++) { | ||
162 | sys_vgui("radiobutton .x%x.c.s%x%d \ | ||
163 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i); | ||
164 | } | ||
165 | /* TODO pack them */ | ||
166 | } else if (!strcmp(x->x_type->s_name,"vradio")) { | ||
167 | int i; | ||
168 | x->x_rect_width = 30; | ||
169 | x->x_rect_height = 20*8+5; | ||
170 | for (i=0;i<8;i++) { | ||
171 | sys_vgui("radiobutton .x%x.c.s%x%d \ | ||
172 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i); | ||
173 | } | ||
174 | /* TODO pack them */ | ||
175 | } else { | ||
176 | x->x_rect_width = 32; | ||
177 | x->x_rect_height = 140; | ||
178 | sys_vgui("scale .x%x.c.s%x \ | ||
179 | -sliderlength 10 \ | ||
180 | -showvalue 0 \ | ||
181 | -length 131 \ | ||
182 | -from 127 -to 0 \ | ||
183 | -command fatom_cb%x\n",canvas,x,x); | ||
184 | } | ||
185 | |||
186 | /* set the start value */ | ||
187 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
188 | if (x->x_val) | ||
189 | sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val); | ||
190 | else | ||
191 | sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val); | ||
192 | } else | ||
193 | sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val); | ||
194 | |||
195 | } | ||
196 | |||
197 | |||
198 | |||
199 | |||
200 | |||
201 | static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime) | ||
202 | { | ||
203 | t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist); | ||
204 | DEBUG(post("drawme %d",firsttime);) | ||
205 | if (firsttime) { | ||
206 | DEBUG(post("glist %x canvas %x",x->x_glist,canvas)); | ||
207 | create_widget(x,glist); | ||
208 | x->x_glist = canvas; | ||
209 | sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n", | ||
210 | canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x); | ||
211 | |||
212 | } | ||
213 | else { | ||
214 | sys_vgui(".x%x.c coords %xS \ | ||
215 | %d %d\n", | ||
216 | canvas, x, | ||
217 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2); | ||
218 | } | ||
219 | draw_inlets(x, glist, firsttime, 1,1); | ||
220 | // draw_handle(x, glist, firsttime); | ||
221 | |||
222 | } | ||
223 | |||
224 | |||
225 | static void fatom_erase(t_fatom* x,t_glist* glist) | ||
226 | { | ||
227 | int n; | ||
228 | |||
229 | DEBUG(post("erase");) | ||
230 | sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x); | ||
231 | |||
232 | sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x); | ||
233 | |||
234 | /* inlets and outlets */ | ||
235 | |||
236 | sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0); | ||
237 | sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0); | ||
238 | sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0); | ||
239 | } | ||
240 | |||
241 | |||
242 | |||
243 | /* ------------------------ fatom widgetbehaviour----------------------------- */ | ||
244 | |||
245 | |||
246 | static void fatom_getrect(t_gobj *z, t_glist *owner, | ||
247 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
248 | { | ||
249 | int width, height; | ||
250 | t_fatom* s = (t_fatom*)z; | ||
251 | |||
252 | width = s->x_rect_width; | ||
253 | height = s->x_rect_height; | ||
254 | *xp1 = text_xpix(&s->x_obj, owner); | ||
255 | *yp1 = text_ypix(&s->x_obj, owner); | ||
256 | *xp2 = text_xpix(&s->x_obj, owner) + width; | ||
257 | *yp2 = text_ypix(&s->x_obj, owner) + height; | ||
258 | } | ||
259 | |||
260 | static void fatom_displace(t_gobj *z, t_glist *glist, | ||
261 | int dx, int dy) | ||
262 | { | ||
263 | t_fatom *x = (t_fatom *)z; | ||
264 | DEBUG(post("displace");) | ||
265 | x->x_obj.te_xpix += dx; | ||
266 | x->x_obj.te_ypix += dy; | ||
267 | if (glist_isvisible(glist)) | ||
268 | { | ||
269 | sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n", | ||
270 | glist_getcanvas(glist), x, | ||
271 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), | ||
272 | text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height); | ||
273 | |||
274 | fatom_drawme(x, glist, 0); | ||
275 | canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); | ||
276 | } | ||
277 | DEBUG(post("displace end");) | ||
278 | } | ||
279 | |||
280 | static void fatom_select(t_gobj *z, t_glist *glist, int state) | ||
281 | { | ||
282 | t_fatom *x = (t_fatom *)z; | ||
283 | if (state) { | ||
284 | sys_vgui(".x%x.c create rectangle \ | ||
285 | %d %d %d %d -tags %xSEL -outline blue\n", | ||
286 | glist_getcanvas(glist), | ||
287 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), | ||
288 | text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height, | ||
289 | x); | ||
290 | } | ||
291 | else { | ||
292 | sys_vgui(".x%x.c delete %xSEL\n", | ||
293 | glist_getcanvas(glist), x); | ||
294 | } | ||
295 | |||
296 | |||
297 | |||
298 | } | ||
299 | |||
300 | |||
301 | static void fatom_activate(t_gobj *z, t_glist *glist, int state) | ||
302 | { | ||
303 | /* t_text *x = (t_text *)z; | ||
304 | t_rtext *y = glist_findrtext(glist, x); | ||
305 | if (z->g_pd != gatom_class) rtext_activate(y, state);*/ | ||
306 | } | ||
307 | |||
308 | static void fatom_delete(t_gobj *z, t_glist *glist) | ||
309 | { | ||
310 | t_text *x = (t_text *)z; | ||
311 | canvas_deletelinesfor(glist_getcanvas(glist), x); | ||
312 | } | ||
313 | |||
314 | |||
315 | static void fatom_vis(t_gobj *z, t_glist *glist, int vis) | ||
316 | { | ||
317 | t_fatom* s = (t_fatom*)z; | ||
318 | t_rtext *y; | ||
319 | DEBUG(post("vis: %d",vis);) | ||
320 | if (vis) { | ||
321 | #ifdef PD_MINOR_VERSION | ||
322 | y = (t_rtext *) rtext_new(glist, (t_text *)z); | ||
323 | #else | ||
324 | y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0); | ||
325 | #endif | ||
326 | fatom_drawme(s, glist, 1); | ||
327 | } | ||
328 | else { | ||
329 | y = glist_findrtext(glist, (t_text *)z); | ||
330 | fatom_erase(s,glist); | ||
331 | rtext_free(y); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | static void fatom_save(t_gobj *z, t_binbuf *b); | ||
336 | |||
337 | t_widgetbehavior fatom_widgetbehavior; | ||
338 | |||
339 | |||
340 | |||
341 | |||
342 | static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) { | ||
343 | x->x_rect_width = w; | ||
344 | x->x_rect_height = h; | ||
345 | } | ||
346 | |||
347 | static void fatom_color(t_fatom* x,t_symbol* col) | ||
348 | { | ||
349 | |||
350 | } | ||
351 | |||
352 | |||
353 | static void fatom_f(t_fatom* x,t_floatarg f) | ||
354 | { | ||
355 | x->x_val = f; | ||
356 | if (x->x_send == &s_) | ||
357 | outlet_float(x->x_obj.ob_outlet,f); | ||
358 | else | ||
359 | if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f); | ||
360 | } | ||
361 | |||
362 | |||
363 | static void fatom_float(t_fatom* x,t_floatarg f) | ||
364 | { | ||
365 | if (glist_isvisible(x->x_glist)) { | ||
366 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
367 | if (x->x_val) | ||
368 | sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f); | ||
369 | else | ||
370 | sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f); | ||
371 | } else | ||
372 | sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f); | ||
373 | } | ||
374 | fatom_f(x,f); | ||
375 | } | ||
376 | |||
377 | |||
378 | static void fatom_bang(t_fatom* x,t_floatarg f) | ||
379 | { | ||
380 | outlet_float(x->x_obj.ob_outlet,x->x_val); | ||
381 | } | ||
382 | |||
383 | |||
384 | static void fatom_properties(t_gobj *z, t_glist *owner) | ||
385 | { | ||
386 | post("N/I"); | ||
387 | } | ||
388 | |||
389 | |||
390 | static void fatom_save(t_gobj *z, t_binbuf *b) | ||
391 | { | ||
392 | |||
393 | t_fatom *x = (t_fatom *)z; | ||
394 | |||
395 | binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"), | ||
396 | x->x_obj.te_xpix, x->x_obj.te_ypix , | ||
397 | gensym("fatom"),x->x_type); | ||
398 | binbuf_addv(b, ";"); | ||
399 | } | ||
400 | |||
401 | |||
402 | static void *fatom_new(t_fatom* x,int argc,t_atom* argv) | ||
403 | { | ||
404 | char buf[256]; | ||
405 | int n = 0; | ||
406 | x->x_glist = canvas_getcurrent(); | ||
407 | |||
408 | x->x_text = gensym(""); | ||
409 | x->x_max = 127; | ||
410 | x->x_min = 0; | ||
411 | x->x_width = 15; | ||
412 | x->x_color = gensym("grey"); | ||
413 | x->x_bgcolor = gensym("grey"); | ||
414 | x->x_send = &s_; | ||
415 | |||
416 | while (argc) { | ||
417 | if (argv->a_type == A_FLOAT) { | ||
418 | if (n==0) x->x_max = atom_getfloat(argv); | ||
419 | if (n==1) x->x_min = atom_getfloat(argv); | ||
420 | if (n==2) x->x_width = atom_getfloat(argv); | ||
421 | } | ||
422 | |||
423 | if (argv->a_type == A_SYMBOL) { | ||
424 | post("%d: symbol value %s",n,atom_getsymbol(argv)->s_name); | ||
425 | if (n==3) x->x_send = atom_getsymbol(argv); | ||
426 | if (n==4) x->x_color = atom_getsymbol(argv); | ||
427 | if (n==5) x->x_bgcolor = atom_getsymbol(argv); | ||
428 | } | ||
429 | argv++; | ||
430 | argc--; | ||
431 | n++; | ||
432 | } | ||
433 | |||
434 | /* bind to a symbol for slider callback (later make this based on the | ||
435 | filepath ??) */ | ||
436 | |||
437 | sprintf(buf,"fatom%x",(t_int)x); | ||
438 | x->x_sym = gensym(buf); | ||
439 | pd_bind(&x->x_obj.ob_pd, x->x_sym); | ||
440 | |||
441 | /* pipe startup code to tk */ | ||
442 | |||
443 | sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x); | ||
444 | |||
445 | outlet_new(&x->x_obj, &s_float); | ||
446 | return (x); | ||
447 | } | ||
448 | |||
449 | static void fatom_setup_common(t_class* class) | ||
450 | { | ||
451 | |||
452 | fatom_widgetbehavior.w_getrectfn = fatom_getrect; | ||
453 | fatom_widgetbehavior.w_displacefn = fatom_displace; | ||
454 | fatom_widgetbehavior.w_selectfn = fatom_select; | ||
455 | fatom_widgetbehavior.w_activatefn = fatom_activate; | ||
456 | fatom_widgetbehavior.w_deletefn = fatom_delete; | ||
457 | fatom_widgetbehavior.w_visfn = fatom_vis; | ||
458 | #if PD_MINOR_VERSION < 37 | ||
459 | fatom_widgetbehavior.w_savefn = fatom_save; | ||
460 | fatom_widgetbehavior.w_propertiesfn = NULL; | ||
461 | #endif | ||
462 | fatom_widgetbehavior.w_clickfn = NULL; | ||
463 | |||
464 | class_addfloat(class, (t_method)fatom_float); | ||
465 | class_addbang(class, (t_method)fatom_bang); | ||
466 | class_addmethod(class, (t_method)fatom_f, gensym("f"), | ||
467 | A_FLOAT, 0); | ||
468 | |||
469 | /* | ||
470 | class_addmethod(class, (t_method)fatom_size, gensym("size"), | ||
471 | A_FLOAT, A_FLOAT, 0); | ||
472 | |||
473 | class_addmethod(class, (t_method)fatom_color, gensym("color"), | ||
474 | A_SYMBOL, 0); | ||
475 | */ | ||
476 | /* | ||
477 | class_addmethod(class, (t_method)fatom_open, gensym("open"), | ||
478 | A_SYMBOL, 0); | ||
479 | */ | ||
480 | |||
481 | class_setwidget(class,&fatom_widgetbehavior); | ||
482 | #if PD_MINOR_VERSION >= 37 | ||
483 | class_setsavefn(class,&fatom_save); | ||
484 | #endif | ||
485 | } | ||
486 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd b/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd deleted file mode 100644 index 2844911261..0000000000 --- a/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | #N canvas 0 0 240 300 8; | ||
2 | #X obj 21 61 gcanvas 80 80; | ||
3 | #X text 14 9 gcanvas .. mouse coordinate enabled canvas; | ||
4 | #X text 13 22 ==========================================; | ||
5 | #X floatatom 21 148 5 0 0 0 - - -; | ||
6 | #X floatatom 94 147 5 0 0 0 - - -; | ||
7 | #X connect 0 0 3 0; | ||
8 | #X connect 0 1 4 0; | ||
9 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/makefile b/apps/plugins/pdbox/PDa/extra/makefile deleted file mode 100644 index 4bd6ed0960..0000000000 --- a/apps/plugins/pdbox/PDa/extra/makefile +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | |||
2 | VERSION = 0.2 | ||
3 | SOURCE = $(shell ls *.c) | ||
4 | TARGETS = $(SOURCE:.c=.pd_linux) | ||
5 | |||
6 | EXT= pd_linux | ||
7 | |||
8 | AFLAGS = -g -O2 -I./ -DFIXEDPOINT | ||
9 | EFLAGS = -shared -Wl,-export-dynamic | ||
10 | PREFIX = /usr | ||
11 | |||
12 | |||
13 | all: $(TARGETS) | ||
14 | |||
15 | clean: | ||
16 | -rm $(TARGETS) | ||
17 | -rm *.o *~ | ||
18 | |||
19 | tar: clean | ||
20 | cd ..;tar czvf PDa-externals-$(VERSION).tgz PDa-externals | ||
21 | |||
22 | upload: tar | ||
23 | scp ../PDa-externals-$(VERSION).tgz gige@xdv.org:~/www/pda/release | ||
24 | |||
25 | install: | ||
26 | install -d $(DESTDIR)/$(PREFIX)/lib/pd/extra | ||
27 | cp $(TARGETS) $(DESTDIR)/$(PREFIX)/lib/pd/extra | ||
28 | |||
29 | %.$(EXT) : %.o | ||
30 | $(CC) -o $@ $(EFLAGS) $+ | ||
31 | |||
32 | %.o : %.c | ||
33 | $(CC) -c $(AFLAGS) $(CFLAGS) $+ | ||
34 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/sendOSC.c b/apps/plugins/pdbox/PDa/extra/sendOSC.c deleted file mode 100644 index 6bb809d68f..0000000000 --- a/apps/plugins/pdbox/PDa/extra/sendOSC.c +++ /dev/null | |||
@@ -1,1461 +0,0 @@ | |||
1 | /* | ||
2 | Written by Matt Wright, The Center for New Music and Audio Technologies, | ||
3 | University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03 | ||
4 | The Regents of the University of California (Regents). | ||
5 | |||
6 | Permission to use, copy, modify, distribute, and distribute modified versions | ||
7 | of this software and its documentation without fee and without a signed | ||
8 | licensing agreement, is hereby granted, provided that the above copyright | ||
9 | notice, this paragraph and the following two paragraphs appear in all copies, | ||
10 | modifications, and distributions. | ||
11 | |||
12 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
13 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING | ||
14 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS | ||
15 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
16 | |||
17 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
18 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
19 | PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
20 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
21 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
22 | |||
23 | |||
24 | The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl | ||
25 | */ | ||
26 | |||
27 | |||
28 | /* sendOSC.c | ||
29 | |||
30 | Matt Wright, 6/3/97 | ||
31 | based on sendOSC.c, which was based on a version by Adrian Freed | ||
32 | |||
33 | Text-based OpenSoundControl client. User can enter messages via command | ||
34 | line arguments or standard input. | ||
35 | |||
36 | Version 0.1: "play" feature | ||
37 | Version 0.2: Message type tags. | ||
38 | |||
39 | pd version branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/sendOSC/sendOSC.c | ||
40 | ------------- | ||
41 | -- added bundle stuff to send. jdl 20020416 | ||
42 | -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 | ||
43 | -- ost_at_test.at + i22_at_test.at, 2000-2002 | ||
44 | modified to compile as pd externel | ||
45 | */ | ||
46 | |||
47 | #define MAX_ARGS 2000 | ||
48 | #define SC_BUFFER_SIZE 64000 | ||
49 | |||
50 | #include "../src/m_pd.h" | ||
51 | #include "OSC-client.h" | ||
52 | |||
53 | #include <string.h> | ||
54 | #include <sys/types.h> | ||
55 | #include <stdlib.h> | ||
56 | #include <stdio.h> | ||
57 | #include <sys/stat.h> | ||
58 | #include <sys/types.h> | ||
59 | |||
60 | #ifdef WIN32 | ||
61 | #include <winsock2.h> | ||
62 | #include <io.h> | ||
63 | #include <errno.h> | ||
64 | #include <fcntl.h> | ||
65 | #include <winsock2.h> | ||
66 | #include <ctype.h> | ||
67 | #include <signal.h> | ||
68 | #else | ||
69 | #include <sys/socket.h> | ||
70 | #include <netinet/in.h> | ||
71 | #include <rpc/rpc.h> | ||
72 | #include <sys/times.h> | ||
73 | #include <sys/param.h> | ||
74 | #include <sys/time.h> | ||
75 | #include <sys/ioctl.h> | ||
76 | #include <netdb.h> | ||
77 | #endif | ||
78 | |||
79 | #ifdef __APPLE__ | ||
80 | #include <string.h> | ||
81 | #endif | ||
82 | |||
83 | #define UNIXDG_PATH "/tmp/htm" | ||
84 | #define UNIXDG_TMP "/tmp/htm.XXXXXX" | ||
85 | |||
86 | |||
87 | |||
88 | OSCTimeTag OSCTT_Immediately(void) { | ||
89 | OSCTimeTag result; | ||
90 | result.seconds = 0; | ||
91 | result.fraction = 1; | ||
92 | return result; | ||
93 | } | ||
94 | |||
95 | |||
96 | OSCTimeTag OSCTT_CurrentTime(void) { | ||
97 | OSCTimeTag result; | ||
98 | result.seconds = 0; | ||
99 | result.fraction = 1; | ||
100 | return result; | ||
101 | } | ||
102 | |||
103 | OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) { | ||
104 | OSCTimeTag result; | ||
105 | result.seconds = 0; | ||
106 | result.fraction = 1; | ||
107 | return result; | ||
108 | } | ||
109 | |||
110 | |||
111 | typedef int bool; | ||
112 | |||
113 | typedef struct | ||
114 | { | ||
115 | float srate; | ||
116 | |||
117 | struct sockaddr_in serv_addr; /* udp socket */ | ||
118 | #ifndef WIN32 | ||
119 | struct sockaddr_un userv_addr; /* UNIX socket */ | ||
120 | #endif | ||
121 | int sockfd; /* socket file descriptor */ | ||
122 | int index, len,uservlen; | ||
123 | void *addr; | ||
124 | int id; | ||
125 | } desc; | ||
126 | |||
127 | |||
128 | /* open a socket for HTM communication to given host on given portnumber */ | ||
129 | /* if host is 0 then UNIX protocol is used (i.e. local communication */ | ||
130 | void *OpenHTMSocket(char *host, int portnumber) | ||
131 | { | ||
132 | struct sockaddr_in cl_addr; | ||
133 | #ifndef WIN32 | ||
134 | int sockfd; | ||
135 | struct sockaddr_un ucl_addr; | ||
136 | #else | ||
137 | unsigned int sockfd; | ||
138 | #endif | ||
139 | |||
140 | desc *o; | ||
141 | int oval = 1; | ||
142 | o = malloc(sizeof(*o)); | ||
143 | if(!o) return 0; | ||
144 | |||
145 | #ifndef WIN32 | ||
146 | |||
147 | if(!host) | ||
148 | { | ||
149 | char *mktemp(char *); | ||
150 | int clilen; | ||
151 | o->len = sizeof(ucl_addr); | ||
152 | /* | ||
153 | * Fill in the structure "userv_addr" with the address of the | ||
154 | * server that we want to send to. | ||
155 | */ | ||
156 | |||
157 | bzero((char *) &o->userv_addr, sizeof(o->userv_addr)); | ||
158 | o->userv_addr.sun_family = AF_UNIX; | ||
159 | strcpy(o->userv_addr.sun_path, UNIXDG_PATH); | ||
160 | sprintf(o->userv_addr.sun_path+strlen(o->userv_addr.sun_path), "%d", portnumber); | ||
161 | o->uservlen = sizeof(o->userv_addr.sun_family) + strlen(o->userv_addr.sun_path); | ||
162 | o->addr = &(o->userv_addr); | ||
163 | /* | ||
164 | * Open a socket (a UNIX domain datagram socket). | ||
165 | */ | ||
166 | |||
167 | if ( (sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0) | ||
168 | { | ||
169 | /* | ||
170 | * Bind a local address for us. | ||
171 | * In the UNIX domain we have to choose our own name (that | ||
172 | * should be unique). We'll use mktemp() to create a unique | ||
173 | * pathname, based on our process id. | ||
174 | */ | ||
175 | |||
176 | bzero((char *) &ucl_addr, sizeof(ucl_addr)); /* zero out */ | ||
177 | ucl_addr.sun_family = AF_UNIX; | ||
178 | strcpy(ucl_addr.sun_path, UNIXDG_TMP); | ||
179 | |||
180 | mktemp(ucl_addr.sun_path); | ||
181 | clilen = sizeof(ucl_addr.sun_family) + strlen(ucl_addr.sun_path); | ||
182 | |||
183 | if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0) | ||
184 | { | ||
185 | perror("client: can't bind local address"); | ||
186 | close(sockfd); | ||
187 | sockfd = -1; | ||
188 | } | ||
189 | } | ||
190 | else | ||
191 | perror("unable to make socket\n"); | ||
192 | |||
193 | }else | ||
194 | |||
195 | #endif | ||
196 | |||
197 | { | ||
198 | /* | ||
199 | * Fill in the structure "serv_addr" with the address of the | ||
200 | * server that we want to send to. | ||
201 | */ | ||
202 | o->len = sizeof(cl_addr); | ||
203 | |||
204 | #ifdef WIN32 | ||
205 | ZeroMemory((char *)&o->serv_addr, sizeof(o->serv_addr)); | ||
206 | #else | ||
207 | bzero((char *)&o->serv_addr, sizeof(o->serv_addr)); | ||
208 | #endif | ||
209 | |||
210 | o->serv_addr.sin_family = AF_INET; | ||
211 | |||
212 | /* MW 6/6/96: Call gethostbyname() instead of inet_addr(), | ||
213 | so that host can be either an Internet host name (e.g., | ||
214 | "les") or an Internet address in standard dot notation | ||
215 | (e.g., "128.32.122.13") */ | ||
216 | { | ||
217 | struct hostent *hostsEntry; | ||
218 | unsigned long address; | ||
219 | |||
220 | hostsEntry = gethostbyname(host); | ||
221 | if (hostsEntry == NULL) { | ||
222 | fprintf(stderr, "Couldn't decipher host name \"%s\"\n", host); | ||
223 | #ifndef WIN32 | ||
224 | herror(NULL); | ||
225 | #endif | ||
226 | return 0; | ||
227 | } | ||
228 | address = *((unsigned long *) hostsEntry->h_addr_list[0]); | ||
229 | o->serv_addr.sin_addr.s_addr = address; | ||
230 | } | ||
231 | |||
232 | /* was: o->serv_addr.sin_addr.s_addr = inet_addr(host); */ | ||
233 | |||
234 | /* End MW changes */ | ||
235 | |||
236 | /* | ||
237 | * Open a socket (a UDP domain datagram socket). | ||
238 | */ | ||
239 | |||
240 | |||
241 | #ifdef WIN32 | ||
242 | o->serv_addr.sin_port = htons((USHORT)portnumber); | ||
243 | o->addr = &(o->serv_addr); | ||
244 | if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET) { | ||
245 | ZeroMemory((char *)&cl_addr, sizeof(cl_addr)); | ||
246 | cl_addr.sin_family = AF_INET; | ||
247 | cl_addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
248 | cl_addr.sin_port = htons(0); | ||
249 | |||
250 | // enable broadcast: jdl ~2003 | ||
251 | if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) { | ||
252 | perror("setsockopt"); | ||
253 | } | ||
254 | |||
255 | if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) { | ||
256 | perror("could not bind\n"); | ||
257 | closesocket(sockfd); | ||
258 | sockfd = -1; | ||
259 | } | ||
260 | } | ||
261 | else { perror("unable to make socket\n");} | ||
262 | #else | ||
263 | o->serv_addr.sin_port = htons(portnumber); | ||
264 | o->addr = &(o->serv_addr); | ||
265 | if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { | ||
266 | bzero((char *)&cl_addr, sizeof(cl_addr)); | ||
267 | cl_addr.sin_family = AF_INET; | ||
268 | cl_addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
269 | cl_addr.sin_port = htons(0); | ||
270 | |||
271 | // enable broadcast: jdl ~2003 | ||
272 | if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) { | ||
273 | perror("setsockopt"); | ||
274 | } | ||
275 | |||
276 | if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) { | ||
277 | perror("could not bind\n"); | ||
278 | close(sockfd); | ||
279 | sockfd = -1; | ||
280 | } | ||
281 | } | ||
282 | else { perror("unable to make socket\n");} | ||
283 | #endif | ||
284 | } | ||
285 | #ifdef WIN32 | ||
286 | if(sockfd == INVALID_SOCKET) { | ||
287 | #else | ||
288 | if(sockfd < 0) { | ||
289 | #endif | ||
290 | free(o); | ||
291 | o = 0; | ||
292 | } | ||
293 | else | ||
294 | o->sockfd = sockfd; | ||
295 | return o; | ||
296 | } | ||
297 | |||
298 | static bool sendudp(const struct sockaddr *sp, int sockfd,int length, int count, void *b) | ||
299 | { | ||
300 | int rcount; | ||
301 | if((rcount=sendto(sockfd, b, count, 0, sp, length)) != count) | ||
302 | { | ||
303 | printf("sockfd %d count %d rcount %dlength %d\n", sockfd,count,rcount,length); | ||
304 | return FALSE; | ||
305 | } | ||
306 | return TRUE; | ||
307 | } | ||
308 | |||
309 | bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer) | ||
310 | { | ||
311 | desc *o = (desc *)htmsendhandle; | ||
312 | return sendudp(o->addr, o->sockfd, o->len, length_in_bytes, buffer); | ||
313 | } | ||
314 | void CloseHTMSocket(void *htmsendhandle) | ||
315 | { | ||
316 | desc *o = (desc *)htmsendhandle; | ||
317 | #ifdef WIN32 | ||
318 | if(SOCKET_ERROR == closesocket(o->sockfd)) { | ||
319 | perror("CloseHTMSocket::closesocket failed\n"); | ||
320 | return; | ||
321 | } | ||
322 | #else | ||
323 | if(close(o->sockfd) == -1) | ||
324 | { | ||
325 | perror("CloseHTMSocket::closesocket failed"); | ||
326 | return; | ||
327 | } | ||
328 | #endif | ||
329 | |||
330 | free(o); | ||
331 | } | ||
332 | |||
333 | |||
334 | /////////////////////// | ||
335 | // from sendOSC | ||
336 | |||
337 | typedef struct { | ||
338 | //enum {INT, FLOAT, STRING} type; | ||
339 | enum {INT_osc, FLOAT_osc, STRING_osc} type; | ||
340 | union { | ||
341 | int i; | ||
342 | float f; | ||
343 | char *s; | ||
344 | } datum; | ||
345 | } typedArg; | ||
346 | |||
347 | void CommandLineMode(int argc, char *argv[], void *htmsocket); | ||
348 | OSCTimeTag ParseTimeTag(char *s); | ||
349 | void ParseInteractiveLine(OSCbuf *buf, char *mesg); | ||
350 | typedArg ParseToken(char *token); | ||
351 | int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args); | ||
352 | void SendBuffer(void *htmsocket, OSCbuf *buf); | ||
353 | void SendData(void *htmsocket, int size, char *data); | ||
354 | /* defined in OSC-system-dependent.c now */ | ||
355 | |||
356 | //static void *htmsocket; | ||
357 | static int exitStatus = 0; | ||
358 | static int useTypeTags = 0; | ||
359 | |||
360 | static char bufferForOSCbuf[SC_BUFFER_SIZE]; | ||
361 | |||
362 | |||
363 | ///////// | ||
364 | // end from sendOSC | ||
365 | |||
366 | static t_class *sendOSC_class; | ||
367 | |||
368 | typedef struct _sendOSC | ||
369 | { | ||
370 | t_object x_obj; | ||
371 | int x_protocol; // UDP/TCP (udp only atm) | ||
372 | t_int x_typetags; // typetag flag | ||
373 | void *x_htmsocket; // sending socket | ||
374 | int x_bundle; // bundle open flag | ||
375 | OSCbuf x_oscbuf[1]; // OSCbuffer | ||
376 | t_outlet *x_bdpthout;// bundle-depth floatoutlet | ||
377 | } t_sendOSC; | ||
378 | |||
379 | static void *sendOSC_new(t_floatarg udpflag) | ||
380 | { | ||
381 | t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class); | ||
382 | outlet_new(&x->x_obj, &s_float); | ||
383 | x->x_htmsocket = 0; // {{raf}} | ||
384 | // set udp | ||
385 | x->x_protocol = SOCK_STREAM; | ||
386 | // set typetags to 1 by default | ||
387 | x->x_typetags = 1; | ||
388 | // bunlde is closed | ||
389 | x->x_bundle = 0; | ||
390 | OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); | ||
391 | x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float(); | ||
392 | //x->x_oscbuf = | ||
393 | return (x); | ||
394 | } | ||
395 | |||
396 | |||
397 | void sendOSC_openbundle(t_sendOSC *x) | ||
398 | { | ||
399 | if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING || | ||
400 | OSC_openBundle(x->x_oscbuf, OSCTT_Immediately())) | ||
401 | { | ||
402 | post("Problem opening bundle: %s\n", OSC_errorMessage); | ||
403 | return; | ||
404 | } | ||
405 | x->x_bundle = 1; | ||
406 | outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); | ||
407 | } | ||
408 | |||
409 | static void sendOSC_closebundle(t_sendOSC *x) | ||
410 | { | ||
411 | if (OSC_closeBundle(x->x_oscbuf)) { | ||
412 | post("Problem closing bundle: %s\n", OSC_errorMessage); | ||
413 | return; | ||
414 | } | ||
415 | outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); | ||
416 | // in bundle mode we send when bundle is closed? | ||
417 | if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) { | ||
418 | // post("x_oscbuf: something inside me?"); | ||
419 | if (x->x_htmsocket) { | ||
420 | SendBuffer(x->x_htmsocket, x->x_oscbuf); | ||
421 | } else { | ||
422 | post("sendOSC: not connected"); | ||
423 | } | ||
424 | OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); | ||
425 | x->x_bundle = 0; | ||
426 | return; | ||
427 | } | ||
428 | // post("x_oscbuf: something went wrong"); | ||
429 | } | ||
430 | |||
431 | static void sendOSC_settypetags(t_sendOSC *x, t_float *f) | ||
432 | { | ||
433 | x->x_typetags = (int)f; | ||
434 | post("sendOSC.c: setting typetags %d",x->x_typetags); | ||
435 | } | ||
436 | |||
437 | |||
438 | static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname, | ||
439 | t_floatarg fportno) | ||
440 | { | ||
441 | int portno = fportno; | ||
442 | /* create a socket */ | ||
443 | |||
444 | // make sure handle is available | ||
445 | if(x->x_htmsocket == 0) { | ||
446 | // | ||
447 | x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno); | ||
448 | if (!x->x_htmsocket) | ||
449 | post("Couldn't open socket: "); | ||
450 | else { | ||
451 | post("connected to port %s:%d (hSock=%d)", hostname->s_name, portno, x->x_htmsocket); | ||
452 | outlet_float(x->x_obj.ob_outlet, 1); | ||
453 | } | ||
454 | } | ||
455 | else | ||
456 | perror("call to sendOSC_connect() against UNavailable socket handle"); | ||
457 | } | ||
458 | |||
459 | void sendOSC_disconnect(t_sendOSC *x) | ||
460 | { | ||
461 | if (x->x_htmsocket) | ||
462 | { | ||
463 | post("disconnecting htmsock (hSock=%d)...", x->x_htmsocket); | ||
464 | CloseHTMSocket(x->x_htmsocket); | ||
465 | x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this | ||
466 | outlet_float(x->x_obj.ob_outlet, 0); | ||
467 | } | ||
468 | else { | ||
469 | perror("call to sendOSC_disconnect() against unused socket handle"); | ||
470 | } | ||
471 | } | ||
472 | |||
473 | void sendOSC_senduntyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) | ||
474 | { | ||
475 | char* targv[MAXPDARG]; | ||
476 | char tmparg[MAXPDSTRING]; | ||
477 | char* tmp = tmparg; | ||
478 | //char testarg[MAXPDSTRING]; | ||
479 | int c; | ||
480 | |||
481 | post("sendOSC: use typetags 0/1 message and plain send method so send untypetagged..."); | ||
482 | return; | ||
483 | |||
484 | //atom_string(argv,testarg, MAXPDSTRING); | ||
485 | for (c=0;c<argc;c++) { | ||
486 | atom_string(argv+c,tmp, 80); | ||
487 | targv[c] = tmp; | ||
488 | tmp += strlen(tmp)+1; | ||
489 | } | ||
490 | |||
491 | // this sock needs to be larger than 0, not >= .. | ||
492 | if (x->x_htmsocket) | ||
493 | { | ||
494 | CommandLineMode(argc, targv, x->x_htmsocket); | ||
495 | // post("test %d", c); | ||
496 | } | ||
497 | else { | ||
498 | post("sendOSC: not connected"); | ||
499 | } | ||
500 | } | ||
501 | |||
502 | ////////////////////////////////////////////////////////////////////// | ||
503 | // this is the real and only sending routine now, for both typed and | ||
504 | // undtyped mode. | ||
505 | |||
506 | static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) | ||
507 | { | ||
508 | char* targv[MAX_ARGS]; | ||
509 | char tmparg[MAXPDSTRING]; | ||
510 | char* tmp = tmparg; | ||
511 | int c; | ||
512 | |||
513 | char *messageName; | ||
514 | char *token; | ||
515 | typedArg args[MAX_ARGS]; | ||
516 | int i,j; | ||
517 | int numArgs = 0; | ||
518 | |||
519 | messageName = ""; | ||
520 | #ifdef DEBUG | ||
521 | post ("sendOSC: messageName: %s", messageName); | ||
522 | #endif | ||
523 | |||
524 | |||
525 | |||
526 | for (c=0;c<argc;c++) { | ||
527 | atom_string(argv+c,tmp, 80); | ||
528 | |||
529 | #ifdef DEBUG | ||
530 | // post ("sendOSC: %d, %s",c, tmp); | ||
531 | #endif | ||
532 | |||
533 | targv[c] = tmp; | ||
534 | tmp += strlen(tmp)+1; | ||
535 | |||
536 | #ifdef DEBUG | ||
537 | // post ("sendOSC: %d, %s",c, targv[c]); | ||
538 | #endif | ||
539 | } | ||
540 | |||
541 | // this sock needs to be larger than 0, not >= .. | ||
542 | if (x->x_htmsocket > 0) | ||
543 | { | ||
544 | #ifdef DEBUG | ||
545 | post ("sendOSC: type tags? %d", useTypeTags); | ||
546 | #endif | ||
547 | |||
548 | messageName = strtok(targv[0], ","); | ||
549 | j = 1; | ||
550 | for (i = j; i < argc; i++) { | ||
551 | token = strtok(targv[i],","); | ||
552 | args[i-j] = ParseToken(token); | ||
553 | #ifdef DEBUG | ||
554 | printf("cell-cont: %s\n", targv[i]); | ||
555 | printf(" type-id: %d\n", args[i-j]); | ||
556 | #endif | ||
557 | numArgs = i; | ||
558 | } | ||
559 | |||
560 | |||
561 | if(WriteMessage(x->x_oscbuf, messageName, numArgs, args)) { | ||
562 | post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage); | ||
563 | return; | ||
564 | } | ||
565 | |||
566 | if(!x->x_bundle) { | ||
567 | SendBuffer(x->x_htmsocket, x->x_oscbuf); | ||
568 | OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); | ||
569 | } | ||
570 | |||
571 | //CommandLineMode(argc, targv, x->x_htmsocket); | ||
572 | //useTypeTags = 0; | ||
573 | } | ||
574 | else { | ||
575 | post("sendOSC: not connected"); | ||
576 | } | ||
577 | } | ||
578 | |||
579 | void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) | ||
580 | { | ||
581 | if(!argc) { | ||
582 | post("not sending empty message."); | ||
583 | return; | ||
584 | } | ||
585 | if(x->x_typetags) { | ||
586 | useTypeTags = 1; | ||
587 | sendOSC_sendtyped(x,s,argc,argv); | ||
588 | useTypeTags = 0; | ||
589 | } else { | ||
590 | sendOSC_sendtyped(x,s,argc,argv); | ||
591 | } | ||
592 | } | ||
593 | |||
594 | static void sendOSC_free(t_sendOSC *x) | ||
595 | { | ||
596 | sendOSC_disconnect(x); | ||
597 | } | ||
598 | |||
599 | #ifdef WIN32 | ||
600 | OSC_API void sendOSC_setup(void) { | ||
601 | #else | ||
602 | void sendOSC_setup(void) { | ||
603 | #endif | ||
604 | sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new, | ||
605 | (t_method)sendOSC_free, | ||
606 | sizeof(t_sendOSC), 0, A_DEFFLOAT, 0); | ||
607 | class_addmethod(sendOSC_class, (t_method)sendOSC_connect, | ||
608 | gensym("connect"), A_SYMBOL, A_FLOAT, 0); | ||
609 | class_addmethod(sendOSC_class, (t_method)sendOSC_disconnect, | ||
610 | gensym("disconnect"), 0); | ||
611 | class_addmethod(sendOSC_class, (t_method)sendOSC_settypetags, | ||
612 | gensym("typetags"), | ||
613 | A_FLOAT, 0); | ||
614 | class_addmethod(sendOSC_class, (t_method)sendOSC_send, | ||
615 | gensym("send"), | ||
616 | A_GIMME, 0); | ||
617 | class_addmethod(sendOSC_class, (t_method)sendOSC_send, | ||
618 | gensym("senduntyped"), | ||
619 | A_GIMME, 0); | ||
620 | class_addmethod(sendOSC_class, (t_method)sendOSC_send, | ||
621 | gensym("sendtyped"), | ||
622 | A_GIMME, 0); | ||
623 | class_addmethod(sendOSC_class, (t_method)sendOSC_openbundle, | ||
624 | gensym("["), | ||
625 | 0, 0); | ||
626 | class_addmethod(sendOSC_class, (t_method)sendOSC_closebundle, | ||
627 | gensym("]"), | ||
628 | 0, 0); | ||
629 | class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd")); | ||
630 | } | ||
631 | |||
632 | |||
633 | |||
634 | |||
635 | |||
636 | /* Exit status codes: | ||
637 | 0: successful | ||
638 | 2: Message(s) dropped because of buffer overflow | ||
639 | 3: Socket error | ||
640 | 4: Usage error | ||
641 | 5: Internal error | ||
642 | */ | ||
643 | |||
644 | void CommandLineMode(int argc, char *argv[], void *htmsocket) { | ||
645 | char *messageName; | ||
646 | char *token; | ||
647 | typedArg args[MAX_ARGS]; | ||
648 | int i,j, numArgs; | ||
649 | OSCbuf buf[1]; | ||
650 | |||
651 | OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf); | ||
652 | |||
653 | if (argc > 1) { | ||
654 | post("argc (%d) > 1", argc); | ||
655 | } | ||
656 | |||
657 | // ParseInteractiveLine(buf, argv); | ||
658 | messageName = strtok(argv[0], ","); | ||
659 | |||
660 | j = 1; | ||
661 | for (i = j; i < argc; i++) { | ||
662 | token = strtok(argv[i],","); | ||
663 | args[i-j] = ParseToken(token); | ||
664 | #ifdef DEBUG | ||
665 | printf("cell-cont: %s\n", argv[i]); | ||
666 | printf(" type-id: %d\n", args[i-j]); | ||
667 | #endif | ||
668 | numArgs = i; | ||
669 | } | ||
670 | |||
671 | if(WriteMessage(buf, messageName, numArgs, args)) { | ||
672 | post("sendOSC: usage error. write-msg failed: %s", OSC_errorMessage); | ||
673 | return; | ||
674 | } | ||
675 | |||
676 | SendBuffer(htmsocket, buf); | ||
677 | } | ||
678 | |||
679 | #define MAXMESG 2048 | ||
680 | |||
681 | void InteractiveMode(void *htmsocket) { | ||
682 | char mesg[MAXMESG]; | ||
683 | OSCbuf buf[1]; | ||
684 | int bundleDepth = 0; /* At first, we haven't seen "[". */ | ||
685 | |||
686 | OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf); | ||
687 | |||
688 | while (fgets(mesg, MAXMESG, stdin) != NULL) { | ||
689 | if (mesg[0] == '\n') { | ||
690 | if (bundleDepth > 0) { | ||
691 | /* Ignore blank lines inside a group. */ | ||
692 | } else { | ||
693 | /* blank line => repeat previous send */ | ||
694 | SendBuffer(htmsocket, buf); | ||
695 | } | ||
696 | continue; | ||
697 | } | ||
698 | |||
699 | if (bundleDepth == 0) { | ||
700 | OSC_resetBuffer(buf); | ||
701 | } | ||
702 | |||
703 | if (mesg[0] == '[') { | ||
704 | OSCTimeTag tt = ParseTimeTag(mesg+1); | ||
705 | if (OSC_openBundle(buf, tt)) { | ||
706 | post("Problem opening bundle: %s\n", OSC_errorMessage); | ||
707 | OSC_resetBuffer(buf); | ||
708 | bundleDepth = 0; | ||
709 | continue; | ||
710 | } | ||
711 | bundleDepth++; | ||
712 | } else if (mesg[0] == ']' && mesg[1] == '\n' && mesg[2] == '\0') { | ||
713 | if (bundleDepth == 0) { | ||
714 | post("Unexpected ']': not currently in a bundle.\n"); | ||
715 | } else { | ||
716 | if (OSC_closeBundle(buf)) { | ||
717 | post("Problem closing bundle: %s\n", OSC_errorMessage); | ||
718 | OSC_resetBuffer(buf); | ||
719 | bundleDepth = 0; | ||
720 | continue; | ||
721 | } | ||
722 | |||
723 | bundleDepth--; | ||
724 | if (bundleDepth == 0) { | ||
725 | SendBuffer(htmsocket, buf); | ||
726 | } | ||
727 | } | ||
728 | } else { | ||
729 | ParseInteractiveLine(buf, mesg); | ||
730 | if (bundleDepth != 0) { | ||
731 | /* Don't send anything until we close all bundles */ | ||
732 | } else { | ||
733 | SendBuffer(htmsocket, buf); | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | } | ||
738 | |||
739 | OSCTimeTag ParseTimeTag(char *s) { | ||
740 | char *p, *newline; | ||
741 | typedArg arg; | ||
742 | |||
743 | p = s; | ||
744 | while (isspace(*p)) p++; | ||
745 | if (*p == '\0') return OSCTT_Immediately(); | ||
746 | |||
747 | if (*p == '+') { | ||
748 | /* Time tag is for some time in the future. It should be a | ||
749 | number of seconds as an int or float */ | ||
750 | |||
751 | newline = strchr(s, '\n'); | ||
752 | if (newline != NULL) *newline = '\0'; | ||
753 | |||
754 | p++; /* Skip '+' */ | ||
755 | while (isspace(*p)) p++; | ||
756 | |||
757 | arg = ParseToken(p); | ||
758 | if (arg.type == STRING_osc) { | ||
759 | post("warning: inscrutable time tag request: %s\n", s); | ||
760 | return OSCTT_Immediately(); | ||
761 | } else if (arg.type == INT_osc) { | ||
762 | return OSCTT_PlusSeconds(OSCTT_CurrentTime(), | ||
763 | (float) arg.datum.i); | ||
764 | } else if (arg.type == FLOAT_osc) { | ||
765 | return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f); | ||
766 | } else { | ||
767 | error("This can't happen!"); | ||
768 | } | ||
769 | } | ||
770 | |||
771 | if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) { | ||
772 | /* They specified the 8-byte tag in hex */ | ||
773 | OSCTimeTag tt; | ||
774 | if (sscanf(p, "%llx", &tt) != 1) { | ||
775 | post("warning: couldn't parse time tag %s\n", s); | ||
776 | return OSCTT_Immediately(); | ||
777 | } | ||
778 | #ifndef HAS8BYTEINT | ||
779 | if (ntohl(1) != 1) { | ||
780 | /* tt is a struct of seconds and fractional part, | ||
781 | and this machine is little-endian, so sscanf | ||
782 | wrote each half of the time tag in the wrong half | ||
783 | of the struct. */ | ||
784 | int temp; | ||
785 | temp = tt.seconds; | ||
786 | tt.seconds = tt.fraction ; | ||
787 | tt.fraction = temp; | ||
788 | } | ||
789 | #endif | ||
790 | return tt; | ||
791 | } | ||
792 | |||
793 | post("warning: invalid time tag: %s\n", s); | ||
794 | return OSCTT_Immediately(); | ||
795 | } | ||
796 | |||
797 | |||
798 | void ParseInteractiveLine(OSCbuf *buf, char *mesg) { | ||
799 | char *messageName, *token, *p; | ||
800 | typedArg args[MAX_ARGS]; | ||
801 | int thisArg; | ||
802 | |||
803 | p = mesg; | ||
804 | while (isspace(*p)) p++; | ||
805 | if (*p == '\0') return; | ||
806 | |||
807 | messageName = p; | ||
808 | |||
809 | if (strcmp(messageName, "play\n") == 0) { | ||
810 | /* Special kludge feature to save typing */ | ||
811 | typedArg arg; | ||
812 | |||
813 | if (OSC_openBundle(buf, OSCTT_Immediately())) { | ||
814 | post("Problem opening bundle: %s\n", OSC_errorMessage); | ||
815 | return; | ||
816 | } | ||
817 | |||
818 | arg.type = INT_osc; | ||
819 | arg.datum.i = 0; | ||
820 | WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg); | ||
821 | |||
822 | arg.type = FLOAT_osc; | ||
823 | arg.datum.i = 0.0f; | ||
824 | WriteMessage(buf, "/voices/0/tm/goto", 1, &arg); | ||
825 | |||
826 | if (OSC_closeBundle(buf)) { | ||
827 | post("Problem closing bundle: %s\n", OSC_errorMessage); | ||
828 | } | ||
829 | |||
830 | return; | ||
831 | } | ||
832 | |||
833 | while (!isspace(*p) && *p != '\0') p++; | ||
834 | if (isspace(*p)) { | ||
835 | *p = '\0'; | ||
836 | p++; | ||
837 | } | ||
838 | |||
839 | thisArg = 0; | ||
840 | while (*p != '\0') { | ||
841 | /* flush leading whitespace */ | ||
842 | while (isspace(*p)) p++; | ||
843 | if (*p == '\0') break; | ||
844 | |||
845 | if (*p == '"') { | ||
846 | /* A string argument: scan for close quotes */ | ||
847 | p++; | ||
848 | args[thisArg].type = STRING_osc; | ||
849 | args[thisArg].datum.s = p; | ||
850 | |||
851 | while (*p != '"') { | ||
852 | if (*p == '\0') { | ||
853 | post("Unterminated quote mark: ignoring line\n"); | ||
854 | return; | ||
855 | } | ||
856 | p++; | ||
857 | } | ||
858 | *p = '\0'; | ||
859 | p++; | ||
860 | } else { | ||
861 | token = p; | ||
862 | while (!isspace(*p) && (*p != '\0')) p++; | ||
863 | if (isspace(*p)) { | ||
864 | *p = '\0'; | ||
865 | p++; | ||
866 | } | ||
867 | args[thisArg] = ParseToken(token); | ||
868 | } | ||
869 | thisArg++; | ||
870 | if (thisArg >= MAX_ARGS) { | ||
871 | post("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", | ||
872 | MAX_ARGS); | ||
873 | break; | ||
874 | } | ||
875 | } | ||
876 | |||
877 | if (WriteMessage(buf, messageName, thisArg, args) != 0) { | ||
878 | post("Problem sending message: %s\n", OSC_errorMessage); | ||
879 | } | ||
880 | } | ||
881 | |||
882 | typedArg ParseToken(char *token) { | ||
883 | char *p = token; | ||
884 | typedArg returnVal; | ||
885 | |||
886 | /* It might be an int, a float, or a string */ | ||
887 | |||
888 | if (*p == '-') p++; | ||
889 | |||
890 | if (isdigit(*p) || *p == '.') { | ||
891 | while (isdigit(*p)) p++; | ||
892 | if (*p == '\0') { | ||
893 | returnVal.type = INT_osc; | ||
894 | returnVal.datum.i = atoi(token); | ||
895 | return returnVal; | ||
896 | } | ||
897 | if (*p == '.') { | ||
898 | p++; | ||
899 | while (isdigit(*p)) p++; | ||
900 | if (*p == '\0') { | ||
901 | returnVal.type = FLOAT_osc; | ||
902 | returnVal.datum.f = atof(token); | ||
903 | return returnVal; | ||
904 | } | ||
905 | } | ||
906 | } | ||
907 | |||
908 | returnVal.type = STRING_osc; | ||
909 | returnVal.datum.s = token; | ||
910 | return returnVal; | ||
911 | } | ||
912 | |||
913 | int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) { | ||
914 | int j, returnVal; | ||
915 | const int wmERROR = -1; | ||
916 | |||
917 | returnVal = 0; | ||
918 | |||
919 | #ifdef DEBUG | ||
920 | printf("WriteMessage: %s ", messageName); | ||
921 | |||
922 | for (j = 0; j < numArgs; j++) { | ||
923 | switch (args[j].type) { | ||
924 | case INT_osc: | ||
925 | printf("%d ", args[j].datum.i); | ||
926 | break; | ||
927 | |||
928 | case FLOAT_osc: | ||
929 | printf("%f ", args[j].datum.f); | ||
930 | break; | ||
931 | |||
932 | case STRING_osc: | ||
933 | printf("%s ", args[j].datum.s); | ||
934 | break; | ||
935 | |||
936 | default: | ||
937 | error("Unrecognized arg type, (not exiting)"); | ||
938 | return(wmERROR); | ||
939 | } | ||
940 | } | ||
941 | printf("\n"); | ||
942 | #endif | ||
943 | |||
944 | if (!useTypeTags) { | ||
945 | returnVal = OSC_writeAddress(buf, messageName); | ||
946 | if (returnVal) { | ||
947 | post("Problem writing address: %s\n", OSC_errorMessage); | ||
948 | } | ||
949 | } else { | ||
950 | /* First figure out the type tags */ | ||
951 | char typeTags[MAX_ARGS+2]; | ||
952 | int i; | ||
953 | |||
954 | typeTags[0] = ','; | ||
955 | |||
956 | for (i = 0; i < numArgs; ++i) { | ||
957 | switch (args[i].type) { | ||
958 | case INT_osc: | ||
959 | typeTags[i+1] = 'i'; | ||
960 | break; | ||
961 | |||
962 | case FLOAT_osc: | ||
963 | typeTags[i+1] = 'f'; | ||
964 | break; | ||
965 | |||
966 | case STRING_osc: | ||
967 | typeTags[i+1] = 's'; | ||
968 | break; | ||
969 | |||
970 | default: | ||
971 | error("Unrecognized arg type (not exiting)"); | ||
972 | return(wmERROR); | ||
973 | } | ||
974 | } | ||
975 | typeTags[i+1] = '\0'; | ||
976 | |||
977 | returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags); | ||
978 | if (returnVal) { | ||
979 | post("Problem writing address: %s\n", OSC_errorMessage); | ||
980 | } | ||
981 | } | ||
982 | |||
983 | for (j = 0; j < numArgs; j++) { | ||
984 | switch (args[j].type) { | ||
985 | case INT_osc: | ||
986 | if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) { | ||
987 | return returnVal; | ||
988 | } | ||
989 | break; | ||
990 | |||
991 | case FLOAT_osc: | ||
992 | if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) { | ||
993 | return returnVal; | ||
994 | } | ||
995 | break; | ||
996 | |||
997 | case STRING_osc: | ||
998 | if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) { | ||
999 | return returnVal; | ||
1000 | } | ||
1001 | break; | ||
1002 | |||
1003 | default: | ||
1004 | error("Unrecognized arg type (not exiting)"); | ||
1005 | returnVal = wmERROR; | ||
1006 | } | ||
1007 | } | ||
1008 | return returnVal; | ||
1009 | } | ||
1010 | |||
1011 | void SendBuffer(void *htmsocket, OSCbuf *buf) { | ||
1012 | #ifdef DEBUG | ||
1013 | printf("Sending buffer...\n"); | ||
1014 | #endif | ||
1015 | if (OSC_isBufferEmpty(buf)) { | ||
1016 | post("SendBuffer() called but buffer empty"); | ||
1017 | return; | ||
1018 | } | ||
1019 | if (!OSC_isBufferDone(buf)) { | ||
1020 | error("SendBuffer() called but buffer not ready!, not exiting"); | ||
1021 | return; //{{raf}} | ||
1022 | } | ||
1023 | SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf)); | ||
1024 | } | ||
1025 | |||
1026 | void SendData(void *htmsocket, int size, char *data) { | ||
1027 | if (!SendHTMSocket(htmsocket, size, data)) { | ||
1028 | post("SendData::SendHTMSocket()failure -- not connected"); | ||
1029 | CloseHTMSocket(htmsocket); | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | |||
1034 | |||
1035 | /* ---------------------- | ||
1036 | OSC-client code | ||
1037 | |||
1038 | */ | ||
1039 | |||
1040 | /* Here are the possible values of the state field: */ | ||
1041 | |||
1042 | #define EMPTY 0 /* Nothing written to packet yet */ | ||
1043 | #define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */ | ||
1044 | #define NEED_COUNT 2 /* Just opened a bundle; must write message name or | ||
1045 | open another bundle */ | ||
1046 | #define GET_ARGS 3 /* Getting arguments to a message. If we see a message | ||
1047 | name or a bundle open/close then the current message | ||
1048 | will end. */ | ||
1049 | #define DONE 4 /* All open bundles have been closed, so can't write | ||
1050 | anything else */ | ||
1051 | |||
1052 | #ifdef WIN32 | ||
1053 | #include <winsock2.h> | ||
1054 | #include <io.h> | ||
1055 | #include <stdio.h> | ||
1056 | #include <errno.h> | ||
1057 | #include <fcntl.h> | ||
1058 | #include <sys/types.h> | ||
1059 | #include <sys/stat.h> | ||
1060 | #endif | ||
1061 | |||
1062 | #ifdef __APPLE__ | ||
1063 | #include <sys/types.h> | ||
1064 | #endif | ||
1065 | |||
1066 | #ifdef unix | ||
1067 | #include <netinet/in.h> | ||
1068 | #include <stdio.h> | ||
1069 | #endif | ||
1070 | |||
1071 | |||
1072 | char *OSC_errorMessage; | ||
1073 | |||
1074 | static int OSC_padString(char *dest, char *str); | ||
1075 | static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str); | ||
1076 | static int OSC_WritePadding(char *dest, int i); | ||
1077 | static int CheckTypeTag(OSCbuf *buf, char expectedType); | ||
1078 | |||
1079 | void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) { | ||
1080 | buf->buffer = byteArray; | ||
1081 | buf->size = size; | ||
1082 | OSC_resetBuffer(buf); | ||
1083 | } | ||
1084 | |||
1085 | void OSC_resetBuffer(OSCbuf *buf) { | ||
1086 | buf->bufptr = buf->buffer; | ||
1087 | buf->state = EMPTY; | ||
1088 | buf->bundleDepth = 0; | ||
1089 | buf->prevCounts[0] = 0; | ||
1090 | buf->gettingFirstUntypedArg = 0; | ||
1091 | buf->typeStringPtr = 0; | ||
1092 | } | ||
1093 | |||
1094 | int OSC_isBufferEmpty(OSCbuf *buf) { | ||
1095 | return buf->bufptr == buf->buffer; | ||
1096 | } | ||
1097 | |||
1098 | int OSC_freeSpaceInBuffer(OSCbuf *buf) { | ||
1099 | return buf->size - (buf->bufptr - buf->buffer); | ||
1100 | } | ||
1101 | |||
1102 | int OSC_isBufferDone(OSCbuf *buf) { | ||
1103 | return (buf->state == DONE || buf->state == ONE_MSG_ARGS); | ||
1104 | } | ||
1105 | |||
1106 | char *OSC_getPacket(OSCbuf *buf) { | ||
1107 | #ifdef ERROR_CHECK_GETPACKET | ||
1108 | if (buf->state == DONE || buf->state == ONE_MSG_ARGS) { | ||
1109 | return buf->buffer; | ||
1110 | } else { | ||
1111 | OSC_errorMessage = "Packet has unterminated bundles"; | ||
1112 | return 0; | ||
1113 | } | ||
1114 | #else | ||
1115 | return buf->buffer; | ||
1116 | #endif | ||
1117 | } | ||
1118 | |||
1119 | int OSC_packetSize(OSCbuf *buf) { | ||
1120 | #ifdef ERROR_CHECK_PACKETSIZE | ||
1121 | if (buf->state == DONE || buf->state == ONE_MSG_ARGS) { | ||
1122 | return (buf->bufptr - buf->buffer); | ||
1123 | } else { | ||
1124 | OSC_errorMessage = "Packet has unterminated bundles"; | ||
1125 | return 0; | ||
1126 | } | ||
1127 | #else | ||
1128 | return (buf->bufptr - buf->buffer); | ||
1129 | #endif | ||
1130 | } | ||
1131 | |||
1132 | #define CheckOverflow(buf, bytesNeeded) { if ((bytesNeeded) > OSC_freeSpaceInBuffer(buf)) {OSC_errorMessage = "buffer overflow"; return 1;}} | ||
1133 | |||
1134 | static void PatchMessageSize(OSCbuf *buf) { | ||
1135 | int4byte size; | ||
1136 | size = buf->bufptr - ((char *) buf->thisMsgSize) - 4; | ||
1137 | *(buf->thisMsgSize) = htonl(size); | ||
1138 | } | ||
1139 | |||
1140 | int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) { | ||
1141 | if (buf->state == ONE_MSG_ARGS) { | ||
1142 | OSC_errorMessage = "Can't open a bundle in a one-message packet"; | ||
1143 | return 3; | ||
1144 | } | ||
1145 | |||
1146 | if (buf->state == DONE) { | ||
1147 | OSC_errorMessage = "This packet is finished; can't open a new bundle"; | ||
1148 | return 4; | ||
1149 | } | ||
1150 | |||
1151 | if (++(buf->bundleDepth) >= MAX_BUNDLE_NESTING) { | ||
1152 | OSC_errorMessage = "Bundles nested too deeply; change MAX_BUNDLE_NESTING in OpenSoundControl.h"; | ||
1153 | return 2; | ||
1154 | } | ||
1155 | |||
1156 | if (CheckTypeTag(buf, '\0')) return 9; | ||
1157 | |||
1158 | if (buf->state == GET_ARGS) { | ||
1159 | PatchMessageSize(buf); | ||
1160 | } | ||
1161 | |||
1162 | if (buf->state == EMPTY) { | ||
1163 | /* Need 16 bytes for "#bundle" and time tag */ | ||
1164 | CheckOverflow(buf, 16); | ||
1165 | } else { | ||
1166 | /* This bundle is inside another bundle, so we need to leave | ||
1167 | a blank size count for the size of this current bundle. */ | ||
1168 | CheckOverflow(buf, 20); | ||
1169 | *((int4byte *)buf->bufptr) = 0xaaaaaaaa; | ||
1170 | buf->prevCounts[buf->bundleDepth] = (int4byte *)buf->bufptr; | ||
1171 | |||
1172 | buf->bufptr += 4; | ||
1173 | } | ||
1174 | |||
1175 | buf->bufptr += OSC_padString(buf->bufptr, "#bundle"); | ||
1176 | |||
1177 | |||
1178 | *((OSCTimeTag *) buf->bufptr) = tt; | ||
1179 | |||
1180 | if (htonl(1) != 1) { | ||
1181 | /* Byte swap the 8-byte integer time tag */ | ||
1182 | int4byte *intp = (int4byte *)buf->bufptr; | ||
1183 | intp[0] = htonl(intp[0]); | ||
1184 | intp[1] = htonl(intp[1]); | ||
1185 | |||
1186 | #ifdef HAS8BYTEINT | ||
1187 | { /* tt is a 64-bit int so we have to swap the two 32-bit words. | ||
1188 | (Otherwise tt is a struct of two 32-bit words, and even though | ||
1189 | each word was wrong-endian, they were in the right order | ||
1190 | in the struct.) */ | ||
1191 | int4byte temp = intp[0]; | ||
1192 | intp[0] = intp[1]; | ||
1193 | intp[1] = temp; | ||
1194 | } | ||
1195 | #endif | ||
1196 | } | ||
1197 | |||
1198 | buf->bufptr += sizeof(OSCTimeTag); | ||
1199 | |||
1200 | buf->state = NEED_COUNT; | ||
1201 | |||
1202 | buf->gettingFirstUntypedArg = 0; | ||
1203 | buf->typeStringPtr = 0; | ||
1204 | return 0; | ||
1205 | } | ||
1206 | |||
1207 | |||
1208 | int OSC_closeBundle(OSCbuf *buf) { | ||
1209 | if (buf->bundleDepth == 0) { | ||
1210 | /* This handles EMPTY, ONE_MSG, ARGS, and DONE */ | ||
1211 | OSC_errorMessage = "Can't close bundle; no bundle is open!"; | ||
1212 | return 5; | ||
1213 | } | ||
1214 | |||
1215 | if (CheckTypeTag(buf, '\0')) return 9; | ||
1216 | |||
1217 | if (buf->state == GET_ARGS) { | ||
1218 | PatchMessageSize(buf); | ||
1219 | } | ||
1220 | |||
1221 | if (buf->bundleDepth == 1) { | ||
1222 | /* Closing the last bundle: No bundle size to patch */ | ||
1223 | buf->state = DONE; | ||
1224 | } else { | ||
1225 | /* Closing a sub-bundle: patch bundle size */ | ||
1226 | int size = buf->bufptr - ((char *) buf->prevCounts[buf->bundleDepth]) - 4; | ||
1227 | *(buf->prevCounts[buf->bundleDepth]) = htonl(size); | ||
1228 | buf->state = NEED_COUNT; | ||
1229 | } | ||
1230 | |||
1231 | --buf->bundleDepth; | ||
1232 | buf->gettingFirstUntypedArg = 0; | ||
1233 | buf->typeStringPtr = 0; | ||
1234 | return 0; | ||
1235 | } | ||
1236 | |||
1237 | |||
1238 | int OSC_closeAllBundles(OSCbuf *buf) { | ||
1239 | if (buf->bundleDepth == 0) { | ||
1240 | /* This handles EMPTY, ONE_MSG, ARGS, and DONE */ | ||
1241 | OSC_errorMessage = "Can't close all bundles; no bundle is open!"; | ||
1242 | return 6; | ||
1243 | } | ||
1244 | |||
1245 | if (CheckTypeTag(buf, '\0')) return 9; | ||
1246 | |||
1247 | while (buf->bundleDepth > 0) { | ||
1248 | OSC_closeBundle(buf); | ||
1249 | } | ||
1250 | buf->typeStringPtr = 0; | ||
1251 | return 0; | ||
1252 | } | ||
1253 | |||
1254 | int OSC_writeAddress(OSCbuf *buf, char *name) { | ||
1255 | int4byte paddedLength; | ||
1256 | |||
1257 | if (buf->state == ONE_MSG_ARGS) { | ||
1258 | OSC_errorMessage = "This packet is not a bundle, so you can't write another address"; | ||
1259 | return 7; | ||
1260 | } | ||
1261 | |||
1262 | if (buf->state == DONE) { | ||
1263 | OSC_errorMessage = "This packet is finished; can't write another address"; | ||
1264 | return 8; | ||
1265 | } | ||
1266 | |||
1267 | if (CheckTypeTag(buf, '\0')) return 9; | ||
1268 | |||
1269 | paddedLength = OSC_effectiveStringLength(name); | ||
1270 | |||
1271 | if (buf->state == EMPTY) { | ||
1272 | /* This will be a one-message packet, so no sizes to worry about */ | ||
1273 | CheckOverflow(buf, paddedLength); | ||
1274 | buf->state = ONE_MSG_ARGS; | ||
1275 | } else { | ||
1276 | /* GET_ARGS or NEED_COUNT */ | ||
1277 | CheckOverflow(buf, 4+paddedLength); | ||
1278 | if (buf->state == GET_ARGS) { | ||
1279 | /* Close the old message */ | ||
1280 | PatchMessageSize(buf); | ||
1281 | } | ||
1282 | buf->thisMsgSize = (int4byte *)buf->bufptr; | ||
1283 | *(buf->thisMsgSize) = 0xbbbbbbbb; | ||
1284 | buf->bufptr += 4; | ||
1285 | buf->state = GET_ARGS; | ||
1286 | } | ||
1287 | |||
1288 | /* Now write the name */ | ||
1289 | buf->bufptr += OSC_padString(buf->bufptr, name); | ||
1290 | buf->typeStringPtr = 0; | ||
1291 | buf->gettingFirstUntypedArg = 1; | ||
1292 | |||
1293 | return 0; | ||
1294 | } | ||
1295 | |||
1296 | int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) { | ||
1297 | int result; | ||
1298 | int4byte paddedLength; | ||
1299 | |||
1300 | if (CheckTypeTag(buf, '\0')) return 9; | ||
1301 | |||
1302 | result = OSC_writeAddress(buf, name); | ||
1303 | |||
1304 | if (result) return result; | ||
1305 | |||
1306 | paddedLength = OSC_effectiveStringLength(types); | ||
1307 | |||
1308 | CheckOverflow(buf, paddedLength); | ||
1309 | |||
1310 | buf->typeStringPtr = buf->bufptr + 1; /* skip comma */ | ||
1311 | buf->bufptr += OSC_padString(buf->bufptr, types); | ||
1312 | |||
1313 | buf->gettingFirstUntypedArg = 0; | ||
1314 | return 0; | ||
1315 | } | ||
1316 | |||
1317 | static int CheckTypeTag(OSCbuf *buf, char expectedType) { | ||
1318 | if (buf->typeStringPtr) { | ||
1319 | if (*(buf->typeStringPtr) != expectedType) { | ||
1320 | if (expectedType == '\0') { | ||
1321 | OSC_errorMessage = | ||
1322 | "According to the type tag I expected more arguments."; | ||
1323 | } else if (*(buf->typeStringPtr) == '\0') { | ||
1324 | OSC_errorMessage = | ||
1325 | "According to the type tag I didn't expect any more arguments."; | ||
1326 | } else { | ||
1327 | OSC_errorMessage = | ||
1328 | "According to the type tag I expected an argument of a different type."; | ||
1329 | printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr); | ||
1330 | } | ||
1331 | return 9; | ||
1332 | } | ||
1333 | ++(buf->typeStringPtr); | ||
1334 | } | ||
1335 | return 0; | ||
1336 | } | ||
1337 | |||
1338 | |||
1339 | int OSC_writeFloatArg(OSCbuf *buf, float arg) { | ||
1340 | int4byte *intp; | ||
1341 | //int result; | ||
1342 | |||
1343 | CheckOverflow(buf, 4); | ||
1344 | |||
1345 | if (CheckTypeTag(buf, 'f')) return 9; | ||
1346 | |||
1347 | /* Pretend arg is a long int so we can use htonl() */ | ||
1348 | intp = ((int4byte *) &arg); | ||
1349 | *((int4byte *) buf->bufptr) = htonl(*intp); | ||
1350 | |||
1351 | buf->bufptr += 4; | ||
1352 | |||
1353 | buf->gettingFirstUntypedArg = 0; | ||
1354 | return 0; | ||
1355 | } | ||
1356 | |||
1357 | |||
1358 | |||
1359 | int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args) { | ||
1360 | int i; | ||
1361 | int4byte *intp; | ||
1362 | |||
1363 | CheckOverflow(buf, 4 * numFloats); | ||
1364 | |||
1365 | /* Pretend args are long ints so we can use htonl() */ | ||
1366 | intp = ((int4byte *) args); | ||
1367 | |||
1368 | for (i = 0; i < numFloats; i++) { | ||
1369 | if (CheckTypeTag(buf, 'f')) return 9; | ||
1370 | *((int4byte *) buf->bufptr) = htonl(intp[i]); | ||
1371 | buf->bufptr += 4; | ||
1372 | } | ||
1373 | |||
1374 | buf->gettingFirstUntypedArg = 0; | ||
1375 | return 0; | ||
1376 | } | ||
1377 | |||
1378 | int OSC_writeIntArg(OSCbuf *buf, int4byte arg) { | ||
1379 | CheckOverflow(buf, 4); | ||
1380 | if (CheckTypeTag(buf, 'i')) return 9; | ||
1381 | |||
1382 | *((int4byte *) buf->bufptr) = htonl(arg); | ||
1383 | buf->bufptr += 4; | ||
1384 | |||
1385 | buf->gettingFirstUntypedArg = 0; | ||
1386 | return 0; | ||
1387 | } | ||
1388 | |||
1389 | int OSC_writeStringArg(OSCbuf *buf, char *arg) { | ||
1390 | int len; | ||
1391 | |||
1392 | if (CheckTypeTag(buf, 's')) return 9; | ||
1393 | |||
1394 | len = OSC_effectiveStringLength(arg); | ||
1395 | |||
1396 | if (buf->gettingFirstUntypedArg && arg[0] == ',') { | ||
1397 | /* This un-type-tagged message starts with a string | ||
1398 | that starts with a comma, so we have to escape it | ||
1399 | (with a double comma) so it won't look like a type | ||
1400 | tag string. */ | ||
1401 | |||
1402 | CheckOverflow(buf, len+4); /* Too conservative */ | ||
1403 | buf->bufptr += | ||
1404 | OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg); | ||
1405 | |||
1406 | } else { | ||
1407 | CheckOverflow(buf, len); | ||
1408 | buf->bufptr += OSC_padString(buf->bufptr, arg); | ||
1409 | } | ||
1410 | |||
1411 | buf->gettingFirstUntypedArg = 0; | ||
1412 | return 0; | ||
1413 | |||
1414 | } | ||
1415 | |||
1416 | /* String utilities */ | ||
1417 | |||
1418 | #define STRING_ALIGN_PAD 4 | ||
1419 | int OSC_effectiveStringLength(char *string) { | ||
1420 | int len = strlen(string) + 1; /* We need space for the null char. */ | ||
1421 | |||
1422 | /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ | ||
1423 | if ((len % STRING_ALIGN_PAD) != 0) { | ||
1424 | len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD); | ||
1425 | } | ||
1426 | return len; | ||
1427 | } | ||
1428 | |||
1429 | static int OSC_padString(char *dest, char *str) { | ||
1430 | int i; | ||
1431 | |||
1432 | for (i = 0; str[i] != '\0'; i++) { | ||
1433 | dest[i] = str[i]; | ||
1434 | } | ||
1435 | |||
1436 | return OSC_WritePadding(dest, i); | ||
1437 | } | ||
1438 | |||
1439 | static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) { | ||
1440 | int i; | ||
1441 | |||
1442 | dest[0] = ','; | ||
1443 | for (i = 0; str[i] != '\0'; i++) { | ||
1444 | dest[i+1] = str[i]; | ||
1445 | } | ||
1446 | |||
1447 | return OSC_WritePadding(dest, i+1); | ||
1448 | } | ||
1449 | |||
1450 | static int OSC_WritePadding(char *dest, int i) { | ||
1451 | dest[i] = '\0'; | ||
1452 | i++; | ||
1453 | |||
1454 | for (; (i % STRING_ALIGN_PAD) != 0; i++) { | ||
1455 | dest[i] = '\0'; | ||
1456 | } | ||
1457 | |||
1458 | return i; | ||
1459 | } | ||
1460 | |||
1461 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/sformat.h b/apps/plugins/pdbox/PDa/extra/sformat.h deleted file mode 100644 index 93d353785b..0000000000 --- a/apps/plugins/pdbox/PDa/extra/sformat.h +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | |||
2 | #ifndef SFORMAT_H__ | ||
3 | #define SFORMAT_H__ | ||
4 | |||
5 | typedef unsigned short uint16; | ||
6 | typedef unsigned long uint32; | ||
7 | |||
8 | #define FORMAT_WAVE 0 | ||
9 | #define FORMAT_AIFF 1 | ||
10 | #define FORMAT_NEXT 2 | ||
11 | |||
12 | /* the NeXTStep sound header structure; can be big or little endian */ | ||
13 | |||
14 | typedef struct _nextstep | ||
15 | { | ||
16 | char ns_fileid[4]; /* magic number '.snd' if file is big-endian */ | ||
17 | uint32 ns_onset; /* byte offset of first sample */ | ||
18 | uint32 ns_length; /* length of sound in bytes */ | ||
19 | uint32 ns_format; /* format; see below */ | ||
20 | uint32 ns_sr; /* sample rate */ | ||
21 | uint32 ns_nchans; /* number of channels */ | ||
22 | char ns_info[4]; /* comment */ | ||
23 | } t_nextstep; | ||
24 | |||
25 | #define NS_FORMAT_LINEAR_16 3 | ||
26 | #define NS_FORMAT_LINEAR_24 4 | ||
27 | #define NS_FORMAT_FLOAT 6 | ||
28 | #define SCALE (1./(1024. * 1024. * 1024. * 2.)) | ||
29 | |||
30 | /* the WAVE header. All Wave files are little endian. We assume | ||
31 | the "fmt" chunk comes first which is usually the case but perhaps not | ||
32 | always; same for AIFF and the "COMM" chunk. */ | ||
33 | |||
34 | typedef unsigned word; | ||
35 | typedef unsigned long dword; | ||
36 | |||
37 | typedef struct _wave | ||
38 | { | ||
39 | char w_fileid[4]; /* chunk id 'RIFF' */ | ||
40 | uint32 w_chunksize; /* chunk size */ | ||
41 | char w_waveid[4]; /* wave chunk id 'WAVE' */ | ||
42 | char w_fmtid[4]; /* format chunk id 'fmt ' */ | ||
43 | uint32 w_fmtchunksize; /* format chunk size */ | ||
44 | uint16 w_fmttag; /* format tag, 1 for PCM */ | ||
45 | uint16 w_nchannels; /* number of channels */ | ||
46 | uint32 w_samplespersec; /* sample rate in hz */ | ||
47 | uint32 w_navgbytespersec; /* average bytes per second */ | ||
48 | uint16 w_nblockalign; /* number of bytes per sample */ | ||
49 | uint16 w_nbitspersample; /* number of bits in a sample */ | ||
50 | char w_datachunkid[4]; /* data chunk id 'data' */ | ||
51 | uint32 w_datachunksize; /* length of data chunk */ | ||
52 | } t_wave; | ||
53 | |||
54 | |||
55 | #endif | ||
56 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/shell.c b/apps/plugins/pdbox/PDa/extra/shell.c deleted file mode 100644 index 8653c63ff4..0000000000 --- a/apps/plugins/pdbox/PDa/extra/shell.c +++ /dev/null | |||
@@ -1,312 +0,0 @@ | |||
1 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | ||
2 | |||
3 | #include "../src/m_pd.h" | ||
4 | #ifdef NT | ||
5 | #pragma warning( disable : 4244 ) | ||
6 | #pragma warning( disable : 4305 ) | ||
7 | #endif | ||
8 | |||
9 | #include <unistd.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | #include <stdio.h> | ||
13 | #include <sys/types.h> | ||
14 | #include <sys/wait.h> | ||
15 | #include <signal.h> | ||
16 | #include <sched.h> | ||
17 | |||
18 | void sys_rmpollfn(int fd); | ||
19 | void sys_addpollfn(int fd, void* fn, void *ptr); | ||
20 | |||
21 | /* ------------------------ shell ----------------------------- */ | ||
22 | |||
23 | #define INBUFSIZE 1024 | ||
24 | |||
25 | static t_class *shell_class; | ||
26 | |||
27 | |||
28 | static void drop_priority(void) | ||
29 | { | ||
30 | #ifdef _POSIX_PRIORITY_SCHEDULING | ||
31 | struct sched_param par; | ||
32 | int p1 ,p2, p3; | ||
33 | par.sched_priority = 0; | ||
34 | sched_setscheduler(0,SCHED_OTHER,&par); | ||
35 | #endif | ||
36 | } | ||
37 | |||
38 | |||
39 | typedef struct _shell | ||
40 | { | ||
41 | t_object x_obj; | ||
42 | int x_echo; | ||
43 | char *sr_inbuf; | ||
44 | int sr_inhead; | ||
45 | int sr_intail; | ||
46 | void* x_binbuf; | ||
47 | int fdpipe[2]; | ||
48 | int fdinpipe[2]; | ||
49 | int pid; | ||
50 | int x_del; | ||
51 | t_outlet* x_done; | ||
52 | t_clock* x_clock; | ||
53 | } t_shell; | ||
54 | |||
55 | static int shell_pid; | ||
56 | |||
57 | |||
58 | void shell_cleanup(t_shell* x) | ||
59 | { | ||
60 | sys_rmpollfn(x->fdpipe[0]); | ||
61 | |||
62 | if (x->fdpipe[0]>0) close(x->fdpipe[0]); | ||
63 | if (x->fdpipe[1]>0) close(x->fdpipe[1]); | ||
64 | if (x->fdinpipe[0]>0) close(x->fdinpipe[0]); | ||
65 | if (x->fdinpipe[1]>0) close(x->fdinpipe[1]); | ||
66 | |||
67 | x->fdpipe[0] = -1; | ||
68 | x->fdpipe[1] = -1; | ||
69 | x->fdinpipe[0] = -1; | ||
70 | x->fdinpipe[1] = -1; | ||
71 | clock_unset(x->x_clock); | ||
72 | } | ||
73 | |||
74 | void shell_check(t_shell* x) | ||
75 | { | ||
76 | int ret; | ||
77 | int status; | ||
78 | ret = waitpid(x->pid,&status,WNOHANG); | ||
79 | if (ret == x->pid) { | ||
80 | shell_cleanup(x); | ||
81 | if (WIFEXITED(status)) { | ||
82 | outlet_float(x->x_done,WEXITSTATUS(status)); | ||
83 | } | ||
84 | else outlet_float(x->x_done,0); | ||
85 | } | ||
86 | else { | ||
87 | if (x->x_del < 100) x->x_del+=2; /* increment poll times */ | ||
88 | clock_delay(x->x_clock,x->x_del); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | |||
93 | void shell_bang(t_shell *x) | ||
94 | { | ||
95 | post("bang"); | ||
96 | } | ||
97 | |||
98 | /* snippet from pd's code */ | ||
99 | static void shell_doit(void *z, t_binbuf *b) | ||
100 | { | ||
101 | t_shell *x = (t_shell *)z; | ||
102 | int msg, natom = binbuf_getnatom(b); | ||
103 | t_atom *at = binbuf_getvec(b); | ||
104 | |||
105 | for (msg = 0; msg < natom;) | ||
106 | { | ||
107 | int emsg; | ||
108 | for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA | ||
109 | && at[emsg].a_type != A_SEMI; emsg++) | ||
110 | ; | ||
111 | if (emsg > msg) | ||
112 | { | ||
113 | int i; | ||
114 | for (i = msg; i < emsg; i++) | ||
115 | if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) | ||
116 | { | ||
117 | pd_error(x, "netreceive: got dollar sign in message"); | ||
118 | goto nodice; | ||
119 | } | ||
120 | if (at[msg].a_type == A_FLOAT) | ||
121 | { | ||
122 | if (emsg > msg + 1) | ||
123 | outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg); | ||
124 | else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float); | ||
125 | } | ||
126 | else if (at[msg].a_type == A_SYMBOL) | ||
127 | outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol, | ||
128 | emsg-msg-1, at + msg + 1); | ||
129 | } | ||
130 | nodice: | ||
131 | msg = emsg + 1; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | |||
136 | void shell_read(t_shell *x, int fd) | ||
137 | { | ||
138 | char buf[INBUFSIZE]; | ||
139 | t_binbuf* bbuf = binbuf_new(); | ||
140 | int i; | ||
141 | int readto = | ||
142 | (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1); | ||
143 | int ret; | ||
144 | |||
145 | ret = read(fd, buf,INBUFSIZE-1); | ||
146 | buf[ret] = '\0'; | ||
147 | |||
148 | for (i=0;i<ret;i++) | ||
149 | if (buf[i] == '\n') buf[i] = ';'; | ||
150 | if (ret < 0) | ||
151 | { | ||
152 | error("shell: pipe read error"); | ||
153 | sys_rmpollfn(fd); | ||
154 | x->fdpipe[0] = -1; | ||
155 | close(fd); | ||
156 | return; | ||
157 | } | ||
158 | else if (ret == 0) | ||
159 | { | ||
160 | post("EOF on socket %d\n", fd); | ||
161 | sys_rmpollfn(fd); | ||
162 | x->fdpipe[0] = -1; | ||
163 | close(fd); | ||
164 | return; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | int natom; | ||
169 | t_atom *at; | ||
170 | binbuf_text(bbuf, buf, strlen(buf)); | ||
171 | |||
172 | natom = binbuf_getnatom(bbuf); | ||
173 | at = binbuf_getvec(bbuf); | ||
174 | shell_doit(x,bbuf); | ||
175 | } | ||
176 | binbuf_free(bbuf); | ||
177 | } | ||
178 | |||
179 | |||
180 | static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at) | ||
181 | { | ||
182 | int i; | ||
183 | char tmp[MAXPDSTRING]; | ||
184 | int size = 0; | ||
185 | |||
186 | if (x->fdinpipe[0] == -1) return; /* nothing to send to */ | ||
187 | |||
188 | for (i=0;i<ac;i++) { | ||
189 | atom_string(at,tmp+size,MAXPDSTRING - size); | ||
190 | at++; | ||
191 | size=strlen(tmp); | ||
192 | tmp[size++] = ' '; | ||
193 | } | ||
194 | tmp[size-1] = '\0'; | ||
195 | post("sending %s",tmp); | ||
196 | write(x->fdinpipe[0],tmp,strlen(tmp)); | ||
197 | } | ||
198 | |||
199 | static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at) | ||
200 | { | ||
201 | int i; | ||
202 | char* argv[20]; | ||
203 | t_symbol* sym; | ||
204 | |||
205 | if (!strcmp(s->s_name,"send")) { | ||
206 | post("send"); | ||
207 | shell_send(x,s,ac,at); | ||
208 | return; | ||
209 | } | ||
210 | |||
211 | argv[0] = s->s_name; | ||
212 | |||
213 | if (x->fdpipe[0] != -1) { | ||
214 | post("shell: old process still running"); | ||
215 | kill(x->pid,SIGKILL); | ||
216 | shell_cleanup(x); | ||
217 | } | ||
218 | |||
219 | |||
220 | if (pipe(x->fdpipe) < 0) { | ||
221 | error("unable to create pipe"); | ||
222 | return; | ||
223 | } | ||
224 | |||
225 | if (pipe(x->fdinpipe) < 0) { | ||
226 | error("unable to create input pipe"); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | |||
231 | sys_addpollfn(x->fdpipe[0],shell_read,x); | ||
232 | |||
233 | if (!(x->pid = fork())) { | ||
234 | int status; | ||
235 | char* cmd = getbytes(1024); | ||
236 | char* tcmd = getbytes(1024); | ||
237 | strcpy(cmd,s->s_name); | ||
238 | |||
239 | #if 0 | ||
240 | for (i=1;i<=ac;i++) { | ||
241 | argv[i] = getbytes(255); | ||
242 | atom_string(at,argv[i],255); | ||
243 | /* post("argument %s",argv[i]); */ | ||
244 | at++; | ||
245 | } | ||
246 | argv[i] = 0; | ||
247 | #endif | ||
248 | for (i=1;i<=ac;i++) { | ||
249 | atom_string(at,tcmd,255); | ||
250 | strcat(cmd," "); | ||
251 | strcat(cmd,tcmd); | ||
252 | at++; | ||
253 | } | ||
254 | |||
255 | |||
256 | /* reassign stdout */ | ||
257 | dup2(x->fdpipe[1],1); | ||
258 | dup2(x->fdinpipe[1],0); | ||
259 | |||
260 | /* drop privileges */ | ||
261 | drop_priority(); | ||
262 | seteuid(getuid()); /* lose setuid priveliges */ | ||
263 | |||
264 | post("executing %s",cmd); | ||
265 | system(cmd); | ||
266 | // execvp(s->s_name,argv); | ||
267 | exit(0); | ||
268 | } | ||
269 | x->x_del = 4; | ||
270 | clock_delay(x->x_clock,x->x_del); | ||
271 | |||
272 | if (x->x_echo) | ||
273 | outlet_anything(x->x_obj.ob_outlet, s, ac, at); | ||
274 | } | ||
275 | |||
276 | |||
277 | |||
278 | void shell_free(t_shell* x) | ||
279 | { | ||
280 | binbuf_free(x->x_binbuf); | ||
281 | } | ||
282 | |||
283 | static void *shell_new(void) | ||
284 | { | ||
285 | t_shell *x = (t_shell *)pd_new(shell_class); | ||
286 | |||
287 | x->x_echo = 0; | ||
288 | x->fdpipe[0] = -1; | ||
289 | x->fdpipe[1] = -1; | ||
290 | x->fdinpipe[0] = -1; | ||
291 | x->fdinpipe[1] = -1; | ||
292 | |||
293 | x->sr_inhead = x->sr_intail = 0; | ||
294 | if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");; | ||
295 | |||
296 | x->x_binbuf = binbuf_new(); | ||
297 | |||
298 | outlet_new(&x->x_obj, &s_list); | ||
299 | x->x_done = outlet_new(&x->x_obj, &s_bang); | ||
300 | x->x_clock = clock_new(x, (t_method) shell_check); | ||
301 | return (x); | ||
302 | } | ||
303 | |||
304 | void shell_setup(void) | ||
305 | { | ||
306 | shell_class = class_new(gensym("shell"), (t_newmethod)shell_new, | ||
307 | (t_method)shell_free,sizeof(t_shell), 0,0); | ||
308 | class_addbang(shell_class,shell_bang); | ||
309 | class_addanything(shell_class, shell_anything); | ||
310 | } | ||
311 | |||
312 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/slider.c b/apps/plugins/pdbox/PDa/extra/slider.c deleted file mode 100644 index 9c49eeb17a..0000000000 --- a/apps/plugins/pdbox/PDa/extra/slider.c +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "../src/m_pd.h" | ||
3 | #include "g_canvas.h" /* for widgetbehaviour */ | ||
4 | #include "fatom.h" | ||
5 | |||
6 | static t_class *slider_class; | ||
7 | |||
8 | static void slider_save(t_gobj *z, t_binbuf *b) | ||
9 | { | ||
10 | t_fatom *x = (t_fatom *)z; | ||
11 | |||
12 | binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"), | ||
13 | x->x_obj.te_xpix, x->x_obj.te_ypix , | ||
14 | gensym("slider"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor); | ||
15 | binbuf_addv(b, ";"); | ||
16 | } | ||
17 | |||
18 | |||
19 | static void *slider_new(t_symbol* s,t_int argc, t_atom* argv) | ||
20 | { | ||
21 | t_fatom *x = (t_fatom *)pd_new(slider_class); | ||
22 | x->x_type = gensym("vslider"); | ||
23 | return fatom_new(x,argc,argv); | ||
24 | } | ||
25 | |||
26 | |||
27 | t_widgetbehavior slider_widgetbehavior; | ||
28 | |||
29 | |||
30 | void slider_setup(void) { | ||
31 | slider_class = class_new(gensym("slider"), (t_newmethod)slider_new, 0, | ||
32 | sizeof(t_fatom),0,A_GIMME,0); | ||
33 | |||
34 | slider_widgetbehavior.w_getrectfn = fatom_getrect; | ||
35 | slider_widgetbehavior.w_displacefn = fatom_displace; | ||
36 | slider_widgetbehavior.w_selectfn = fatom_select; | ||
37 | slider_widgetbehavior.w_activatefn = fatom_activate; | ||
38 | slider_widgetbehavior.w_deletefn = fatom_delete; | ||
39 | slider_widgetbehavior.w_visfn= fatom_vis; | ||
40 | slider_widgetbehavior.w_clickfn = NULL; | ||
41 | |||
42 | fatom_setup_common(slider_class); | ||
43 | class_setwidget(slider_class,&slider_widgetbehavior); | ||
44 | |||
45 | #if PD_MINOR_VERSION < 37 | ||
46 | slider_widgetbehavior.w_savefn = slider_save; | ||
47 | slider_widgetbehavior.w_propertiesfn = NULL; | ||
48 | #else | ||
49 | class_setsavefn(slider_class,&slider_save); | ||
50 | class_setpropertiesfn(slider_class,&fatom_properties); | ||
51 | #endif | ||
52 | |||
53 | } | ||
54 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/sliderh.c b/apps/plugins/pdbox/PDa/extra/sliderh.c deleted file mode 100644 index ef3d096cf6..0000000000 --- a/apps/plugins/pdbox/PDa/extra/sliderh.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | #include "../src/m_pd.h" | ||
2 | #include "g_canvas.h" | ||
3 | |||
4 | |||
5 | #ifdef NT | ||
6 | #pragma warning( disable : 4244 ) | ||
7 | #pragma warning( disable : 4305 ) | ||
8 | #endif | ||
9 | |||
10 | #include "fatom.h" | ||
11 | |||
12 | /* can we use the normal text save function ?? */ | ||
13 | |||
14 | static t_class *sliderh_class; | ||
15 | |||
16 | static void sliderh_save(t_gobj *z, t_binbuf *b) | ||
17 | { | ||
18 | |||
19 | t_fatom *x = (t_fatom *)z; | ||
20 | |||
21 | binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"), | ||
22 | x->x_obj.te_xpix, x->x_obj.te_ypix , | ||
23 | gensym("sliderh"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor); | ||
24 | binbuf_addv(b, ";"); | ||
25 | } | ||
26 | |||
27 | |||
28 | static void *sliderh_new(t_symbol* s, int argc, t_atom* argv) | ||
29 | { | ||
30 | t_fatom *x = (t_fatom *)pd_new(sliderh_class); | ||
31 | x->x_type = gensym("hslider"); | ||
32 | return fatom_new(x,argc,argv); | ||
33 | } | ||
34 | |||
35 | |||
36 | t_widgetbehavior sliderh_widgetbehavior; | ||
37 | |||
38 | |||
39 | |||
40 | |||
41 | void sliderh_setup(void) { | ||
42 | sliderh_class = class_new(gensym("sliderh"), (t_newmethod)sliderh_new, 0, | ||
43 | sizeof(t_fatom),0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); | ||
44 | |||
45 | fatom_setup_common(sliderh_class); | ||
46 | |||
47 | sliderh_widgetbehavior.w_getrectfn = fatom_getrect; | ||
48 | sliderh_widgetbehavior.w_displacefn= fatom_displace; | ||
49 | sliderh_widgetbehavior.w_selectfn= fatom_select; | ||
50 | sliderh_widgetbehavior.w_activatefn=fatom_activate; | ||
51 | sliderh_widgetbehavior.w_deletefn= fatom_delete; | ||
52 | sliderh_widgetbehavior.w_visfn= fatom_vis; | ||
53 | #if PD_MINOR_VERSION < 37 | ||
54 | sliderh_widgetbehavior.w_savefn= sliderh_save; | ||
55 | sliderh_widgetbehavior.w_propertiesfn= NULL; | ||
56 | #endif | ||
57 | sliderh_widgetbehavior.w_clickfn= NULL; | ||
58 | |||
59 | class_setwidget(sliderh_class,&sliderh_widgetbehavior); | ||
60 | #if PD_MINOR_VERSION >= 37 | ||
61 | class_setsavefn(sliderh_class,&sliderh_save); | ||
62 | #endif | ||
63 | } | ||
64 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/test-clip.pd b/apps/plugins/pdbox/PDa/extra/test-clip.pd deleted file mode 100644 index ed6c0c8396..0000000000 --- a/apps/plugins/pdbox/PDa/extra/test-clip.pd +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #N canvas 0 0 240 300 10; | ||
2 | #X obj 57 84 clip~ -0.1 0.1; | ||
3 | #X obj 58 61 sig~; | ||
4 | #X obj 57 111 snapshot~; | ||
5 | #X floatatom 58 19 5 0 0 0 - - -; | ||
6 | #X floatatom 57 144 5 0 0 0 - - -; | ||
7 | #X obj 58 37 t f b; | ||
8 | #X connect 0 0 2 0; | ||
9 | #X connect 1 0 0 0; | ||
10 | #X connect 2 0 4 0; | ||
11 | #X connect 3 0 5 0; | ||
12 | #X connect 5 0 1 0; | ||
13 | #X connect 5 1 2 0; | ||
14 | |||
diff --git a/apps/plugins/pdbox/PDa/extra/test-vcf.pd b/apps/plugins/pdbox/PDa/extra/test-vcf.pd deleted file mode 100644 index 5f1b29381a..0000000000 --- a/apps/plugins/pdbox/PDa/extra/test-vcf.pd +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #N canvas 0 0 240 300 10; | ||
2 | #X obj 38 93 noise~; | ||
3 | #X obj 44 161 vcf~; | ||
4 | #X obj 48 191 dac~; | ||
5 | #X floatatom 138 33 5 0 0 0 - - -; | ||
6 | #X obj 44 18 osc~ 1; | ||
7 | #X obj 46 75 *~ 800; | ||
8 | #X obj 48 48 +~ 2; | ||
9 | #X obj 106 125 sig~; | ||
10 | #X floatatom 132 77 5 0 0 0 - - -; | ||
11 | #X connect 0 0 1 0; | ||
12 | #X connect 1 0 2 0; | ||
13 | #X connect 1 0 2 1; | ||
14 | #X connect 3 0 1 2; | ||
15 | #X connect 4 0 6 0; | ||
16 | #X connect 6 0 5 0; | ||
17 | #X connect 7 0 1 1; | ||
18 | #X connect 8 0 7 0; | ||
19 | |||