summaryrefslogtreecommitdiffstats
path: root/apps/plugins/pdbox
diff options
context:
space:
mode:
authorWincent Balin <wincent@rockbox.org>2010-06-03 00:39:13 +0000
committerWincent Balin <wincent@rockbox.org>2010-06-03 00:39:13 +0000
commitc1ae4414d4ac6504992434b949b252c30daf0c48 (patch)
tree696c5781e9a00cea694117eb3ef404d37f10930e /apps/plugins/pdbox
parent5edd8cf736232a240e2f4f47eb847e1901d18379 (diff)
downloadrockbox-c1ae4414d4ac6504992434b949b252c30daf0c48.tar.gz
rockbox-c1ae4414d4ac6504992434b949b252c30daf0c48.tar.bz2
rockbox-c1ae4414d4ac6504992434b949b252c30daf0c48.zip
pdbox: Source cleanup. Removed unneeded files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26497 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox')
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSC-client.h189
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSC.pd14
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSCroute.c628
-rw-r--r--apps/plugins/pdbox/PDa/extra/bandpass-help.pd18
-rw-r--r--apps/plugins/pdbox/PDa/extra/dumpOSC.c1000
-rw-r--r--apps/plugins/pdbox/PDa/extra/fatom.h486
-rw-r--r--apps/plugins/pdbox/PDa/extra/gcanvas-help.pd9
-rw-r--r--apps/plugins/pdbox/PDa/extra/makefile34
-rw-r--r--apps/plugins/pdbox/PDa/extra/sendOSC.c1461
-rw-r--r--apps/plugins/pdbox/PDa/extra/sformat.h56
-rw-r--r--apps/plugins/pdbox/PDa/extra/shell.c312
-rw-r--r--apps/plugins/pdbox/PDa/extra/slider.c54
-rw-r--r--apps/plugins/pdbox/PDa/extra/sliderh.c64
-rw-r--r--apps/plugins/pdbox/PDa/extra/test-clip.pd14
-rw-r--r--apps/plugins/pdbox/PDa/extra/test-vcf.pd19
-rw-r--r--apps/plugins/pdbox/PDa/intern/sig~.c68
-rw-r--r--apps/plugins/pdbox/PDa/src/build.ipod6
-rw-r--r--apps/plugins/pdbox/PDa/src/d_array.c1074
-rw-r--r--apps/plugins/pdbox/PDa/src/d_delay.c319
-rw-r--r--apps/plugins/pdbox/PDa/src/d_filter.c548
-rw-r--r--apps/plugins/pdbox/PDa/src/d_math.c573
-rw-r--r--apps/plugins/pdbox/PDa/src/d_osc.c535
-rw-r--r--apps/plugins/pdbox/PDa/src/delme.pd9
-rw-r--r--apps/plugins/pdbox/PDa/src/makefile176
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_alsa.c946
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_mmio.c795
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_oss.c845
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_pa.c293
-rw-r--r--apps/plugins/pdbox/PDa/src/s_entry.c52
-rw-r--r--apps/plugins/pdbox/PDa/src/s_inter.c1000
-rw-r--r--apps/plugins/pdbox/PDa/src/s_main.c839
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi.c642
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_oss.c360
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_pm.c167
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_sgi.c189
-rw-r--r--apps/plugins/pdbox/PDa/src/s_watchdog.c48
-rw-r--r--apps/plugins/pdbox/PDa/src/t_main.c121
-rw-r--r--apps/plugins/pdbox/PDa/src/t_tkcmd.c398
-rw-r--r--apps/plugins/pdbox/PDa/src/u_main.tk3368
-rw-r--r--apps/plugins/pdbox/PDa/src/u_pdreceive.c326
-rw-r--r--apps/plugins/pdbox/PDa/src/u_pdsend.c158
-rw-r--r--apps/plugins/pdbox/PDa/src/x_gui.c378
-rw-r--r--apps/plugins/pdbox/PDa/src/x_midi.c1314
-rw-r--r--apps/plugins/pdbox/SOURCES61
44 files changed, 17 insertions, 19949 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 @@
-/*
-Written by Matt Wright, The Center for New Music and Audio Technologies,
-University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
-The Regents of the University of California (Regents).
-
-Permission to use, copy, modify, distribute, and distribute modified versions
-of this software and its documentation without fee and without a signed
-licensing agreement, is hereby granted, provided that the above copyright
-notice, this paragraph and the following two paragraphs appear in all copies,
-modifications, and distributions.
-
-IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
-OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
-BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
-HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
-MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-*/
-
-/*
-
- OSC-client.h: library for constructing OpenSoundControl messages.
- Derived from SynthControl.h
- Author: Matt Wright
- Version 0.1: 6/13/97
- Version 0.2: 7/21/2000: Support for type-tagged messages
-
-
- General notes:
-
- This library abstracts away the data format for the OpenSoundControl
- protocol. Users of this library can construct OpenSoundControl packets
- with a function call interface instead of knowing how to lay out the bits.
-
- All issues of memory allocation are deferred to the user of this library.
- There are two data structures that the user must allocate. The first
- is the actual buffer that the message will be written into. This buffer
- can be any size, but if it's too small there's a possibility that it
- will become overfull. The other data structure is called an OSCbuf,
- and it holds all the state used by the library as it's constructing
- a buffer.
-
- All procedures that have the possibility of an error condition return int,
- with 0 indicating no error and nonzero indicating an error. The variable
- OSC_errorMessage will be set to point to a string containing an error
- message explaining what the problem is.
-
-*/
-
-
-
-/* The int4byte type has to be a 4-byte integer. You may have to
- change this to long or something else on your system. */
-#ifdef __MWERKS__
- /* In Metrowerks you can set ints to be 2 or 4 bytes on 68K, but long is
- always 4 bytes */
- typedef long int4byte;
-#else
- typedef int int4byte;
-#endif
-
-/* OSC_timetag.h */
-
- typedef struct {
- int seconds;
- int fraction;
- } OSCTimeTag;
-
-OSCTimeTag OSCTT_Immediately(void);
-OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset);
-OSCTimeTag OSCTT_CurrentTime(void);
-
-
-
-/* The maximum depth of bundles within bundles within bundles within...
- This is the size of a static array. If you exceed this limit you'll
- get an error message. */
-#define MAX_BUNDLE_NESTING 32
-
-
-/* Don't ever manipulate the data in the OSCbuf struct directly. (It's
- declared here in the header file only so your program will be able to
- declare variables of type OSCbuf and have the right amount of memory
- be allocated.) */
-
-typedef struct OSCbuf_struct {
- char *buffer; /* The buffer to hold the OSC packet */
- int size; /* Size of the buffer */
- char *bufptr; /* Current position as we fill the buffer */
- int state; /* State of partially-constructed message */
- int4byte *thisMsgSize; /* Pointer to count field before
- currently-being-written message */
- int4byte *prevCounts[MAX_BUNDLE_NESTING];
- /* Pointers to count field before each currently
- open bundle */
- int bundleDepth; /* How many sub-sub-bundles are we in now? */
- char *typeStringPtr; /* This pointer advances through the type
- tag string as you add arguments. */
- int gettingFirstUntypedArg; /* nonzero if this message doesn't have
- a type tag and we're waiting for the 1st arg */
-} OSCbuf;
-
-
-
-/* Initialize the given OSCbuf. The user of this module must pass in the
- block of memory that this OSCbuf will use for a buffer, and the number of
- bytes in that block. (It's the user's job to allocate the memory because
- you do it differently in different systems.) */
-void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray);
-
-
-/* Reset the given OSCbuf. Do this after you send out the contents of
- the buffer and want to start writing new data into it. */
-void OSC_resetBuffer(OSCbuf *buf);
-
-
-/* Is the buffer empty? (I.e., would it be stupid to send the buffer
- contents to the synth?) */
-int OSC_isBufferEmpty(OSCbuf *buf);
-
-
-/* How much space is left in the buffer? */
-int OSC_freeSpaceInBuffer(OSCbuf *buf);
-
-/* Does the buffer contain a valid OSC packet? (Returns nonzero if yes.) */
-int OSC_isBufferDone(OSCbuf *buf);
-
-/* When you're ready to send out the buffer (i.e., when OSC_isBufferDone()
- returns true), call these two procedures to get the OSC packet that's been
- assembled and its size in bytes. (And then call OSC_resetBuffer() if you
- want to re-use this OSCbuf for the next packet.) */
-char *OSC_getPacket(OSCbuf *buf);
-int OSC_packetSize(OSCbuf *buf);
-
-
-
-/* Here's the basic model for building up OSC messages in an OSCbuf:
-
- - Make sure the OSCbuf has been initialized with OSC_initBuffer().
-
- - To open a bundle, call OSC_openBundle(). You can then write
- messages or open new bundles within the bundle you opened.
- Call OSC_closeBundle() to close the bundle. Note that a packet
- does not have to have a bundle; it can instead consist of just a
- single message.
-
-
- - For each message you want to send:
-
- - Call OSC_writeAddress() with the name of your message. (In
- addition to writing your message name into the buffer, this
- procedure will also leave space for the size count of this message.)
-
- - Alternately, call OSC_writeAddressAndTypes() with the name of
- your message and with a type string listing the types of all the
- arguments you will be putting in this message.
-
- - Now write each of the arguments into the buffer, by calling one of:
- OSC_writeFloatArg()
- OSC_writeFloatArgs()
- OSC_writeIntArg()
- OSC_writeStringArg()
-
- - Now your message is complete; you can send out the buffer or you can
- add another message to it.
-*/
-
-int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt);
-int OSC_closeBundle(OSCbuf *buf);
-int OSC_closeAllBundles(OSCbuf *buf);
-
-int OSC_writeAddress(OSCbuf *buf, char *name);
-int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types);
-int OSC_writeFloatArg(OSCbuf *buf, float arg);
-int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args);
-int OSC_writeIntArg(OSCbuf *buf, int4byte arg);
-int OSC_writeStringArg(OSCbuf *buf, char *arg);
-
-extern char *OSC_errorMessage;
-
-/* How many bytes will be needed in the OSC format to hold the given
- string? The length of the string, plus the null char, plus any padding
- needed for 4-byte alignment. */
-int OSC_effectiveStringLength(char *string);
-
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 @@
-#N canvas 0 0 240 300 10;
-#X obj 32 185 dumpOSC 5550;
-#X obj 32 217 OSCroute /hello;
-#X obj 32 239 print;
-#X obj 133 238 print;
-#X obj 26 87 sendOSC;
-#X msg 50 43 connect localhost 5550;
-#X msg 21 13 send /hello PDa;
-#X connect 0 0 1 0;
-#X connect 1 0 2 0;
-#X connect 1 1 3 0;
-#X connect 5 0 4 0;
-#X connect 6 0 4 0;
-
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 @@
-/*
-Written by Adrian Freed, The Center for New Music and Audio Technologies,
-University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04
-The Regents of the University of California (Regents).
-
-Permission to use, copy, modify, distribute, and distribute modified versions
-of this software and its documentation without fee and without a signed
-licensing agreement, is hereby granted, provided that the above copyright
-notice, this paragraph and the following two paragraphs appear in all copies,
-modifications, and distributions.
-
-IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
-OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
-BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
-HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
-MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-
-
-The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
-*/
-
- /* OSC-route.c
- Max object for OSC-style dispatching
-
- To-do:
-
- Match a pattern against a pattern?
- Declare outlet types / distinguish leaf nodes from other children
- More sophisticated (2-pass?) allmessages scheme
- set message?
-
-
- pd
- -------------
- -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
-
-
- */
-
-#ifdef ROCKBOX
-#include "plugin.h"
-#include "../../pdbox.h"
-#else /* ROCKBOX */
-#ifdef WIN32
- #include <stdlib.h>
- #include <string.h>
-#endif
-#ifdef __APPLE__
- #include <stdio.h>
-#endif
-#ifdef UNIX
- #include <stdio.h>
-#endif
-#endif /* ROCKBOX */
-
-/* structure definition of your object */
-
-#define MAX_NUM 20
-#define OSC_ROUTE_VERSION "1.05"
-#define OSCWarning(x...) post(x)
-
-/* the required include files */
-#include "../src/m_pd.h"
-
-
-#ifndef TRUE
-typedef int Boolean;
-#define TRUE 1
-#define FALSE 0
-#endif
-
-
-/* Fixed byte width types */
-typedef int int4; /* 4 byte int */
-
-Boolean PatternMatch (const char *pattern, const char *test);
-
-
-
-/* Version 1.04: Allows #1 thru #9 as typed-in arguments
- Version 1.05: Allows "list" messages as well as "message" messages.
-*/
-
-static t_class *OSCroute_class;
-
-typedef struct _OSCroute
-{
- t_object x_obj; // required header
- t_int x_num; // Number of address prefixes we store
- t_int x_complainmode; // Do we print a message if no match?
- t_int x_sendmode; // use pd internal sends instead of outlets
- char *x_prefixes[MAX_NUM];
- void *x_outlets[MAX_NUM+1];
-} t_OSCroute;
-
-t_symbol *ps_list, *ps_complain, *ps_emptySymbol;
-
-/* prototypes */
-
-void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
-void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
-void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
-/* //void *OSCroute_new(t_symbol *s, int argc, atom *argv); */
-void *OSCroute_new(t_symbol *s, int argc, t_atom *argv);
-void OSCroute_version (t_OSCroute *x);
-/* void OSCroute_assist (OSCroute *x, void *box, long msg, long arg, */
-/* char *dstString); */
-void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
-
-static char *NextSlashOrNull(char *p);
-static void StrCopyUntilSlash(char *target, const char *source);
-
-
-// free
-static void OSCroute_free(t_OSCroute *x)
-{
-#ifdef ROCKBOX
- (void) x;
-#endif
- // freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec));
-}
-
-/* initialization routine */
-
-// setup
-#ifdef WIN32
- OSC_API void OSCroute_setup(void) {
-#else
-void OSCroute_setup(void) {
-#endif
- OSCroute_class = class_new(gensym("OSCroute"), (t_newmethod)OSCroute_new,
- (t_method)OSCroute_free,sizeof(t_OSCroute), 0, A_GIMME, 0);
- class_addlist(OSCroute_class, OSCroute_list);
- class_addanything(OSCroute_class, OSCroute_anything);
- class_addmethod(OSCroute_class, (t_method)OSCroute_version, gensym("version"), A_NULL, 0, 0);
- class_sethelpsymbol(OSCroute_class, gensym("OSCroute-help.pd"));
-
- /*
- class_addmethod(OSCroute_class, (t_method)OSCroute_connect,
- gensym("connect"), A_SYMBOL, A_FLOAT, 0);
- class_addmethod(OSCroute_class, (t_method)OSCroute_disconnect,
- gensym("disconnect"), 0);
- class_addmethod(OSCroute_class, (t_method)OSCroute_send, gensym("send"),
- A_GIMME, 0);
- */
-/* ps_list = gensym("list"); */
-/* ps_complain = gensym("complain"); */
- ps_emptySymbol = gensym("");
-
- post("OSCroute object version " OSC_ROUTE_VERSION " by Matt Wright. pd: jdl Win32 raf.");
- post("OSCroute Copyright © 1999 Regents of the University of California. All Rights Reserved.");
-}
-
-
-
-/* instance creation routine */
-
-void *OSCroute_new(t_symbol *s, int argc, t_atom *argv)
-{
-#ifdef ROCKBOX
- (void) s;
-#endif
- t_OSCroute *x = (t_OSCroute *)pd_new(OSCroute_class); // get memory for a new object & initialize
-
- int i; //{{raf}} n not used
-
- // EnterCallback();
-
- if (argc > MAX_NUM) {
- post("* OSC-route: too many arguments: %ld (max %ld)", argc, MAX_NUM);
- // ExitCallback();
- return 0;
- }
-
- x->x_complainmode = 0;
- x->x_num = 0;
- for (i = 0; i < argc; ++i) {
- if (argv[i].a_type == A_SYMBOL) {
- if (argv[i].a_w.w_symbol->s_name[0] == '/') {
- /* Now that's a nice prefix */
- x->x_prefixes[i] = argv[i].a_w.w_symbol->s_name;
- ++(x->x_num);
- } else if (argv[i].a_w.w_symbol->s_name[0] == '#' &&
- argv[i].a_w.w_symbol->s_name[1] >= '1' &&
- argv[i].a_w.w_symbol->s_name[1] <= '9') {
- /* The Max programmer is trying to make a patch that will be
- a subpatch with arguments. We have to make an outlet for this
- argument. */
- x->x_prefixes[i] = "dummy";
- ++(x->x_num);
- } else {
- /* Maybe this is an option we support */
-
-/* if (argv[i].a_w.w_sym == ps_complain) { */
-/* x->x_complainmode = 1; */
-/* } else { */
-/* post("* OSC-route: Unrecognized argument %s", argv[i].a_w.w_sym->s_name); */
-/* } */
-
- }
-
- // no LONG
-
-/* } else if (argv[i].a_type == A_FLOAD) { */
-/* // Convert to a numeral. Max ints are -2147483648 to 2147483647 */
-/* char *string = getbytes(12); */
-/* // I can't be bothered to plug this 12 byte memory leak */
-/* if (string == 0) { */
-/* post("* OSC-route: out of memory!"); */
-/* // ExitCallback(); */
-/* return 0; */
-/* } */
-/* sprintf(string, "%d", argv[i].a_w.w_long); */
-/* x->x_prefixes[i] = string; */
-/* ++(x->x_num); */
-
- } else if (argv[i].a_type == A_FLOAT) {
- post("* OSC-route: float arguments are not OK.");
- // ExitCallback();
- return 0;
- } else {
- post("* OSC-route: unrecognized argument type!");
- // ExitCallback();
- return 0;
- }
- }
-
-
- /* Have to create the outlets in reverse order */
- /* well, not in pd ? */
- // for (i = x->x_num-1; i >= 0; --i) {
- // for (i = 0; i <= x->x_num-1; i++) {
- for (i = 0; i <= x->x_num; i++) {
- // x->x_outlets[i] = listout(x);
- x->x_outlets[i] = outlet_new(&x->x_obj, &s_list);
- }
-
- // ExitCallback();
- return (x);
-}
-
-
-void OSCroute_version (t_OSCroute *x) {
-#ifdef ROCKBOX
- (void) x;
-#endif
- // EnterCallback();
- post("OSCroute Version " OSC_ROUTE_VERSION
- ", by Matt Wright. pd jdl, win32: raf.\nOSCroute Compiled " __TIME__ " " __DATE__);
- // ExitCallback();
-}
-
-/* I don't know why these aren't defined in some Max #include file. */
-#define ASSIST_INLET 1
-#define ASSIST_OUTLET 2
-
-void OSCroute_assist (t_OSCroute *x, void *box, long msg, long arg,
- char *dstString) {
-#ifdef ROCKBOX
- (void) box;
-#endif
- // EnterCallback();
-
- if (msg==ASSIST_INLET) {
-#ifdef ROCKBOX
- strcpy(dstString, "Incoming OSC messages");
-#else
- sprintf(dstString, "Incoming OSC messages");
-#endif
- } else if (msg==ASSIST_OUTLET) {
- if (arg < 0 || arg >= x->x_num) {
- post("* OSCroute_assist: No outlet corresponds to arg %ld!", arg);
- } else {
-#ifdef ROCKBOX
- strcpy(dstString, "subaddress + args for prefix ");
- strcat(dstString, x->x_prefixes[arg]);
-#else
- sprintf(dstString, "subaddress + args for prefix %s", x->x_prefixes[arg]);
-#endif
- }
- } else {
- post("* OSCroute_assist: unrecognized message %ld", msg);
- }
-
- // ExitCallback();
-}
-
-void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
-#ifdef ROCKBOX
- (void) s;
-#endif
- // EnterCallback();
- if (argc > 0 && argv[0].a_type == A_SYMBOL) {
- /* Ignore the fact that this is a "list" */
- OSCroute_doanything(x, argv[0].a_w.w_symbol, argc-1, argv+1);
- } else {
- // post("* OSC-route: invalid list beginning with a number");
- // output on unmatched outlet jdl 20020908
- if (argv[0].a_type == A_FLOAT) {
- outlet_float(x->x_outlets[x->x_num], argv[0].a_w.w_float);
- } else {
- post("* OSC-route: unrecognized atom type!");
- }
- }
- // ExitCallback();
-}
-
-
-void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
- // EnterCallback();
- OSCroute_doanything(x, s, argc, argv);
- // ExitCallback();
-}
-
-
-
-
-void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
- char *pattern, *nextSlash;
- int i;
- int matchedAnything;
- // post("*** OSCroute_anything(s %s, argc %ld)", s->s_name, (long) argc);
-
- pattern = s->s_name;
- if (pattern[0] != '/') {
- post("* OSC-route: invalid message pattern %s does not begin with /", s->s_name);
- outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
- return;
- }
-
- matchedAnything = 0;
-
- nextSlash = NextSlashOrNull(pattern+1);
- if (*nextSlash == '\0') {
- /* last level of the address, so we'll output the argument list */
-
-
-#ifdef NULL_IS_DIFFERENT_FROM_BANG
- if (argc==0) {
- post("* OSC-route: why are you matching one level pattern %s with no args?",
- pattern);
- return;
- }
-#endif
-
- for (i = 0; i < x->x_num; ++i) {
- if (PatternMatch(pattern+1, x->x_prefixes[i]+1)) {
- ++matchedAnything;
-
- // I hate stupid Max lists with a special first element
- if (argc == 0) {
- outlet_bang(x->x_outlets[i]);
- } else if (argv[0].a_type == A_SYMBOL) {
- // Promote the symbol that was argv[0] to the special symbol
- outlet_anything(x->x_outlets[i], argv[0].a_w.w_symbol, argc-1, argv+1);
- } else if (argc > 1) {
- // Multiple arguments starting with a number, so naturally we have
- // to use a special function to output this "list", since it's what
- // Max originally meant by "list".
- outlet_list(x->x_outlets[i], 0L, argc, argv);
- } else {
- // There was only one argument, and it was a number, so we output it
- // not as a list
-/* if (argv[0].a_type == A_LONG) { */
-
-/* outlet_int(x->x_outlets[i], argv[0].a_w.w_long); */
- // } else
- if (argv[0].a_type == A_FLOAT) {
-
- outlet_float(x->x_outlets[i], argv[0].a_w.w_float);
- } else {
- post("* OSC-route: unrecognized atom type!");
- }
- }
- }
- }
- } else {
- /* There's more address after this part, so our output list will begin with
- the next slash. */
- t_symbol *restOfPattern = 0; /* avoid the gensym unless we have to output */
- char patternBegin[1000];
-
-
- /* Get the first level of the incoming pattern to match against all our prefixes */
- StrCopyUntilSlash(patternBegin, pattern+1);
-
- for (i = 0; i < x->x_num; ++i) {
- if (PatternMatch(patternBegin, x->x_prefixes[i]+1)) {
- ++matchedAnything;
- if (restOfPattern == 0) {
- restOfPattern = gensym(nextSlash);
- }
- outlet_anything(x->x_outlets[i], restOfPattern, argc, argv);
- }
- }
- }
-
- if (x->x_complainmode) {
- if (!matchedAnything) {
- post("* OSC-route: pattern %s did not match any prefixes", pattern);
- }
- }
-
- // output unmatched data on rightmost outlet a la normal 'route' object, jdl 20020908
- if (!matchedAnything) {
- outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
- }
-
-
-}
-
-static char *NextSlashOrNull(char *p) {
- while (*p != '/' && *p != '\0') {
- p++;
- }
- return p;
-}
-
-static void StrCopyUntilSlash(char *target, const char *source) {
- while (*source != '/' && *source != '\0') {
- *target = *source;
- ++target;
- ++source;
- }
- *target = 0;
-}
-
-static int MyStrCopy(char *target, const char *source) {
- int i = 0;
- while (*source != '\0') {
- *target = *source;
- ++target;
- ++source;
- ++i;
- }
- *target = 0;
- return i;
-}
-
-
-
-void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
- int i;
- t_symbol *prefixSymbol = 0;
- char prefixBuf[1000];
- char *endOfPrefix;
- t_atom a[1];
-
- if (argc >= 1 && argv[0].a_type == A_SYMBOL) {
- prefixSymbol = argv[0].a_w.w_symbol;
- endOfPrefix = prefixBuf + MyStrCopy(prefixBuf,
- prefixSymbol->s_name);
- } else {
- prefixSymbol = ps_emptySymbol;
- prefixBuf[0] = '\0';
- endOfPrefix = prefixBuf;
- }
-
-
- for (i = 0; i < x->x_num; ++i) {
- post("OSC: %s%s", prefixSymbol->s_name, x->x_prefixes[i]);
- MyStrCopy(endOfPrefix, x->x_prefixes[i]);
- SETSYMBOL(a, gensym(prefixBuf));
- outlet_anything(x->x_outlets[i], s, 1, a);
- }
-}
-
-
-/* --------------------------------------------------- */
-
-
-
-static const char *theWholePattern; /* Just for warning messages */
-
-static Boolean MatchBrackets (const char *pattern, const char *test);
-static Boolean MatchList (const char *pattern, const char *test);
-
-Boolean PatternMatch (const char * pattern, const char * test) {
- theWholePattern = pattern;
-
- if (pattern == 0 || pattern[0] == 0) {
- return test[0] == 0;
- }
-
- if (test[0] == 0) {
- if (pattern[0] == '*')
- return PatternMatch (pattern+1,test);
- else
- return FALSE;
- }
-
- switch (pattern[0]) {
- case 0 : return test[0] == 0;
- case '?' : return PatternMatch (pattern + 1, test + 1);
- case '*' :
- if (PatternMatch (pattern+1, test)) {
- return TRUE;
- } else {
- return PatternMatch (pattern, test+1);
- }
- case ']' :
- case '}' :
- OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
- return FALSE;
- case '[' :
- return MatchBrackets (pattern,test);
- case '{' :
- return MatchList (pattern,test);
- case '\\' :
- if (pattern[1] == 0) {
- return test[0] == 0;
- } else if (pattern[1] == test[0]) {
- return PatternMatch (pattern+2,test+1);
- } else {
- return FALSE;
- }
- default :
- if (pattern[0] == test[0]) {
- return PatternMatch (pattern+1,test+1);
- } else {
- return FALSE;
- }
- }
-}
-
-
-/* we know that pattern[0] == '[' and test[0] != 0 */
-
-static Boolean MatchBrackets (const char *pattern, const char *test) {
- Boolean result;
- Boolean negated = FALSE;
- const char *p = pattern;
-
- if (pattern[1] == 0) {
- OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
- return FALSE;
- }
-
- if (pattern[1] == '!') {
- negated = TRUE;
- p++;
- }
-
- while (*p != ']') {
- if (*p == 0) {
- OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
- return FALSE;
- }
- if (p[1] == '-' && p[2] != 0) {
- if (test[0] >= p[0] && test[0] <= p[2]) {
- result = !negated;
- goto advance;
- }
- }
- if (p[0] == test[0]) {
- result = !negated;
- goto advance;
- }
- p++;
- }
-
- result = negated;
-
-advance:
-
- if (!result)
- return FALSE;
-
- while (*p != ']') {
- if (*p == 0) {
- OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
- return FALSE;
- }
- p++;
- }
-
- return PatternMatch (p+1,test+1);
-}
-
-static Boolean MatchList (const char *pattern, const char *test) {
-
- const char *restOfPattern, *tp = test;
-
-
- for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) {
- if (*restOfPattern == 0) {
- OSCWarning("Unterminated { in pattern \".../%s/...\"", theWholePattern);
- return FALSE;
- }
- }
-
- restOfPattern++; /* skip close curly brace */
-
-
- pattern++; /* skip open curly brace */
-
- while (1) {
-
- if (*pattern == ',') {
- if (PatternMatch (restOfPattern, tp)) {
- return TRUE;
- } else {
- tp = test;
- ++pattern;
- }
- } else if (*pattern == '}') {
- return PatternMatch (restOfPattern, tp);
- } else if (*pattern == *tp) {
- ++pattern;
- ++tp;
- } else {
- tp = test;
- while (*pattern != ',' && *pattern != '}') {
- pattern++;
- }
- if (*pattern == ',') {
- pattern++;
- }
- }
- }
-
-}
-
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 @@
-#N canvas 428 285 240 300 8;
-#X obj 24 78 noise~;
-#X obj 15 215 dac~;
-#X obj 24 167 biquad~;
-#X floatatom 67 76 5 0 0 0 - - -;
-#X floatatom 83 111 5 0 0 0 - - -;
-#X obj 67 138 bandpass 600 10;
-#X text 77 97 bandwidth: 100 = 1 octave;
-#X text 67 58 frequency;
-#X text 8 11 Calculation of biquad coefficients;
-#X text 7 21 ==================================;
-#X connect 0 0 2 0;
-#X connect 2 0 1 0;
-#X connect 2 0 1 1;
-#X connect 3 0 5 0;
-#X connect 4 0 5 1;
-#X connect 5 0 2 0;
-
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 @@
-/*
-Written by Matt Wright and Adrian Freed, The Center for New Music and
-Audio Technologies, University of California, Berkeley. Copyright (c)
-1992,93,94,95,96,97,98,99,2000,01,02,03,04 The Regents of the University of
-California (Regents).
-
-Permission to use, copy, modify, distribute, and distribute modified versions
-of this software and its documentation without fee and without a signed
-licensing agreement, is hereby granted, provided that the above copyright
-notice, this paragraph and the following two paragraphs appear in all copies,
-modifications, and distributions.
-
-IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
-OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
-BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
-HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
-MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-
-
-The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
-*/
-
-
- /*
-
- dumpOSC.c
- server that displays OpenSoundControl messages sent to it
- for debugging client udp and UNIX protocol
-
- by Matt Wright, 6/3/97
- modified from dumpSC.c, by Matt Wright and Adrian Freed
-
- version 0.2: Added "-silent" option a.k.a. "-quiet"
-
- version 0.3: Incorporated patches from Nicola Bernardini to make
- things Linux-friendly. Also added ntohl() in the right places
- to support little-endian architectures.
-
-
-
- compile:
- cc -o dumpOSC dumpOSC.c
-
- to-do:
-
- More robustness in saying exactly what's wrong with ill-formed
- messages. (If they don't make sense, show exactly what was
- received.)
-
- Time-based features: print time-received for each packet
-
- Clean up to separate OSC parsing code from socket/select stuff
-
- pd: branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/dumpOSC/dumpOSC.c
- -------------
- -- added pd functions
- -- socket is made differently than original via pd mechanisms
- -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
- -- the OSX changes from cnmat didnt make it here yet but this compiles
- on OSX anyway.
-
-*/
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "../src/m_pd.h"
-//#include "m_imp.h"
-#include "s_stuff.h"
-
-/* declarations */
-
-// typedef void (*t_fdpollfn)(void *ptr, int fd);
-void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
-
-
-#if defined(__sgi) || defined(__linux) || defined(WIN32) || defined(__APPLE__)
-
-#ifdef WIN32
- #include "OSC-common.h"
- #include <winsock2.h>
- #include <string.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <ctype.h>
- #include <signal.h>
-#else
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <netinet/in.h>
- #include <rpc/rpc.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <sys/times.h>
- #include <sys/param.h>
- #include <sys/time.h>
- #include <sys/ioctl.h>
- #include <ctype.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <pwd.h>
- #include <signal.h>
- #include <grp.h>
- #include <sys/file.h>
- //#include <sys/prctl.h>
-
- #ifdef NEED_SCHEDCTL_AND_LOCK
- #include <sys/schedctl.h>
- #include <sys/lock.h>
- #endif
-#endif
-
-
-char *htm_error_string;
-typedef int Boolean;
-typedef void *OBJ;
-
-typedef struct ClientAddressStruct {
- struct sockaddr_in cl_addr;
- int clilen;
- int sockfd;
-} *ClientAddr;
-
-typedef unsigned long long osc_time_t;
-
-Boolean ShowBytes = FALSE;
-Boolean Silent = FALSE;
-
-/* Declarations */
-#ifndef WIN32
-static int unixinitudp(int chan);
-#endif
-
-static int initudp(int chan);
-static void closeudp(int sockfd);
-Boolean ClientReply(int packetsize, void *packet, int socketfd,
- void *clientaddresspointer, int clientaddressbufferlength);
-void sgi_CleanExit(void);
-Boolean sgi_HaveToQuit(void);
-int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy);
-static void catch_sigint();
-static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd) ;
-char *DataAfterAlignedString(char *string, char *boundary) ;
-Boolean IsNiceString(char *string, char *boundary) ;
-void complain(char *s, ...);
-
-#define MAXMESG 32768
-static char mbuf[MAXMESG];
-
-/* ----------------------------- dumpOSC ------------------------- */
-
-#define MAXOUTAT 50
-
-static t_class *dumpOSC_class;
-
-typedef struct _dumpOSC
-{
- t_object x_obj;
- t_outlet *x_msgout;
- t_outlet *x_connectout;
- t_atom x_outat[MAXOUTAT];
- int x_outatc;
- t_binbuf *x_b;
- int x_connectsocket;
- int x_nconnections;
- int x_udp;
- struct sockaddr_in x_server;
- int x_clilen;
-} t_dumpOSC;
-
-void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr);
-Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd);
-static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr);
-static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n);
-static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma);
-
-static void dumpOSC_read(t_dumpOSC *x, int sockfd) {
- int clilen = x->x_clilen;
- int n;
- struct ClientAddressStruct ras;
- ClientAddr ra = &ras;
-
- //catchupflag= FALSE;
-
-/* if (ShowBytes) { */
-/* int i; */
-/* printf("%d byte message:\n", n); */
-/* for (i = 0; i < n; ++i) { */
-/* printf(" %x (%c)\t", m[i], m[i]); */
-/* if (i%4 == 3) printf("\n"); */
-/* } */
-/* printf("\n"); */
-/* } */
-
- // return catchupflag;
- //struct sockaddr_in x->x_server;
- //while( (n = recvfrom(sockfd, mbuf, MAXMESG, 0, &cl_addr, &clilen)) >0)
- // while((
-
- #ifdef WIN32
- if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0)
- #else
- if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0)
- #endif
- {
- //int r;
- ras.cl_addr = *((struct sockaddr_in *) &x->x_server);
- ras.clilen = x->x_clilen;
- ras.sockfd = x->x_connectsocket;
-
- #ifdef DEBUG
- printf("dumpOSC_read: received UDP packet of length %d\n", n);
- #endif
-
- if(!dumpOSC_SendReply(mbuf, n, &x->x_server, clilen, sockfd))
- {
- dumpOSC_ParsePacket(x, mbuf, n, ra);
- }
- //r = Synthmessage(mbuf, n, &x->x_server, clilen, sockfd);
- //post ("%d", r);
- //outlet_anything(x->x_msgout, at[msg].a_w.w_symbol,
- // emsg-msg-1, at + msg + 1);
- // outlet_list(x->x_msgout, 0, n, mbuf);
- //if( sgi_HaveToQuit()) goto out;
- //if(r>0) goto back;
- //clilen = maxclilen;
- }
-}
-
-static void *dumpOSC_new(t_symbol *compatflag,
- t_floatarg fportno) {
- t_dumpOSC *x;
- struct sockaddr_in server;
- int clilen=sizeof(server);
- int sockfd;
- int portno=fportno;
- int udp = 1;
-
- //x->x_b = binbuf_new();
- //x->x_outat = binbuf_getvec(x->x_b);
-
- //{{raf}} pointer not valid yet...moving this down
- //x->x_outatc = 0; {{raf}}
-
- /* create a socket */
- if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1)
- {
- sys_sockerror("socket");
- return (0);
- }
-
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = INADDR_ANY;
- /* assign server port number */
- server.sin_port = htons((u_short)portno);
- /* name the socket */
- if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
- {
- sys_sockerror("bind");
- sys_closesocket(sockfd);
- return (0);
- }
-
- x = (t_dumpOSC *)pd_new(dumpOSC_class);
- x->x_outatc = 0; // {{raf}} now pointer is valid (less invalid)
-
- x->x_msgout = outlet_new(&x->x_obj, &s_anything);
-
- // if (udp) /* datagram protocol */
- {
-
- sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x);
- x->x_connectout = 0;
- }
- // else /* streaming protocol */
- /* { */
- /* if (listen(sockfd, 5) < 0) */
- /* { */
- /* sys_sockerror("listen"); */
- /* sys_closesocket(sockfd); */
- /* sockfd = -1; */
- /* } */
- /* else */
- /* { */
- /* sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_connectpoll, x); */
- /* x->x_connectout = outlet_new(&x->x_obj, &s_float); */
- /* } */
- /* } */
-
- x->x_connectsocket = sockfd;
- x->x_server = server;
- x->x_clilen = clilen;
- x->x_nconnections = 0;
- x->x_udp = udp;
-
- return (x);
-}
-
-static void dumpOSC_free(t_dumpOSC *x)
-{
- /* LATER make me clean up open connections */
- if (x->x_connectsocket >= 0)
- {
- sys_rmpollfn(x->x_connectsocket);
- sys_closesocket(x->x_connectsocket);
- }
-}
-
-#ifdef WIN32
-OSC_API void dumpOSC_setup(void)
-#else
-void dumpOSC_setup(void)
-#endif
-{
- dumpOSC_class = class_new(gensym("dumpOSC"),
- (t_newmethod)dumpOSC_new, (t_method)dumpOSC_free,
- sizeof(t_dumpOSC), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT,
- A_DEFSYM, 0);
- class_sethelpsymbol(dumpOSC_class, gensym("dumpOSC-help.pd"));
-}
-
-
-#ifndef WIN32
- #define UNIXDG_PATH "/tmp/htm"
- #define UNIXDG_TMP "/tmp/htm.XXXXXX"
- static int unixinitudp(int chan)
- {
- struct sockaddr_un serv_addr;
- int sockfd;
-
- if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
- return sockfd;
-
- bzero((char *)&serv_addr, sizeof(serv_addr));
- serv_addr.sun_family = AF_UNIX;
- strcpy(serv_addr.sun_path, UNIXDG_PATH);
- sprintf(serv_addr.sun_path+strlen(serv_addr.sun_path), "%d", chan);
- unlink(serv_addr.sun_path);
- if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path)) < 0)
- {
- perror("unable to bind\n");
- return -1;
- }
-
- fcntl(sockfd, F_SETFL, FNDELAY);
- return sockfd;
- }
-#endif // #ifndef WIN32
-
-
-
-static int initudp(int chan)
-{
-
-#ifdef WIN32
- struct sockaddr_in serv_addr;
- unsigned int sockfd;
- ULONG nonBlocking = (ULONG) TRUE;
-
- if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET ) {
- ZeroMemory((char *)&serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(chan);
- if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) {
- // set for non-blocking mode
- if(ioctlsocket(sockfd, FIONBIO, &nonBlocking) == SOCKET_ERROR) {
- perror("unable to set non-blocking\n");
- return -1;
- }
- }
- else { perror("unable to bind\n"); return -1; }
- }
- return (sockfd == INVALID_SOCKET ? -1 : (int)sockfd);
-#else
- struct sockaddr_in serv_addr;
- int sockfd;
-
- if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- return sockfd;
-
- bzero((char *)&serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(chan);
-
- if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
- {
- perror("unable to bind\n");
- return -1;
- }
-
- fcntl(sockfd, F_SETFL, FNDELAY);
- return sockfd;
-#endif
-}
-
-
-
-
-
-
-
-
-static void closeudp(int sockfd) {
- #ifdef WIN32
- closesocket(sockfd);
- #else
- close(sockfd);
- #endif
-}
-
-static Boolean catchupflag=FALSE;
-Boolean ClientReply(int packetsize, void *packet, int socketfd,
- void *clientaddresspointer, int clientaddressbufferlength)
-{
- if(!clientaddresspointer) return FALSE;
- catchupflag= TRUE;
- return packetsize==sendto(socketfd, packet, packetsize, 0, clientaddresspointer, clientaddressbufferlength);
-}
-
-static Boolean exitflag= FALSE;
-void sgi_CleanExit(void) {
- exitflag = TRUE;
-}
-
-Boolean sgi_HaveToQuit(void) {
- return exitflag;
-}
-
-
-/* file descriptor poll table */
-static int npolldevs =0;
-typedef struct polldev
-{
- int fd;
- void (*callbackfunction)(int , void *);
- void *dummy;
-} polldev;
-#define TABMAX 8
-static polldev polldevs[TABMAX];
-
-
-/* Register a device (referred to by a file descriptor that the caller
- should have already successfully obtained from a system call) to be
- polled as real-time constraints allowed.
-
- When a select(2) call indicates activity on the file descriptor, the
- callback function is called with the file descripter as first
- argument and the given dummy argument (presumably a pointer to the
- instance variables associated with the device).
-*/
-int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy)
-{
- if(npolldevs<TABMAX)
- {
- polldevs[npolldevs].fd = fd;
- polldevs[npolldevs].callbackfunction = callbackfunction;
- polldevs[npolldevs].dummy = dummy;
- }
- else return -1;
- return npolldevs++;
-}
-
-static int caught_sigint;
-
-static void catch_sigint() {
- caught_sigint = 1;
-}
-static int sockfd, usockfd;
-
-
-void PrintClientAddr(ClientAddr CA) {
- unsigned long addr = CA->cl_addr.sin_addr.s_addr;
- printf("Client address %p:\n", CA);
- printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd);
- printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family,
- CA->cl_addr.sin_port);
- printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr));
-
- printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n",
- CA->cl_addr.sin_zero[0],
- CA->cl_addr.sin_zero[1],
- CA->cl_addr.sin_zero[2],
- CA->cl_addr.sin_zero[3],
- CA->cl_addr.sin_zero[4],
- CA->cl_addr.sin_zero[5],
- CA->cl_addr.sin_zero[6],
- CA->cl_addr.sin_zero[7]);
-
- printf("\n");
-}
-
-//*******************
-
-void WriteTime(char* dst, osc_time_t osctime)
-{
- *(int32_t*)dst = htonl((int32_t)(osctime >> 32));
- *(int32_t*)(dst+4) = htonl((int32_t)osctime);
-}
-
-void WriteMode(char* dst)
-{
- *(int32_t*)dst = htonl(0);
-}
-
-osc_time_t ReadTime(const char* src)
-{
- osc_time_t osctime = ntohl(*(int32_t*)src);
- return (osctime << 32) + ntohl(*(int32_t*)(src+4));
-}
-
-double TimeToSeconds(osc_time_t osctime)
-{
- return (double)osctime * 2.3283064365386962890625e-10 /* 1/2^32 */;
-}
-
-int timeRound(double x)
-{
- return x >= 0.0 ? x+0.5 : x-0.5;
-}
-/*
-void WriteLogicalTime(char* dst)
-{
- static double startTime = -1.0;
- double sTime;
-
- // Initialisierung der Startzeit.
- // Knnte effizienter (ohne 'if') auch irgendwo vorher passieren.
- // Knnte wahrscheinlich auch 0.0 sein.
- if (startTime < 0.0) {
- startTime = clock_getlogicaltime();
- }
-
- sTime = clock_gettimesince(startTime) * 0.001;
- *(int32_t*)dst = hton'K l((int32_t)sTime);
- *(int32_t*)(dst+4) = htonl((int32_t)(4294967296.0 * sTime));
-}
-*/
-
-void WriteLogicalTime(char* dst)
-{
- double sTime = clock_gettimesince(19230720) / 1000.0;
- double tau = sTime - timeRound(sTime);
-
- //fprintf(stderr, "sSec = %f tau = %f\n", sTime, tau);
-
- *(int32_t*)dst = htonl((int32_t)(sTime));
- *(int32_t*)(dst+4) = htonl((int32_t)(4294967296 * tau));
-}
-
-Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd)
-{
- if((n == 24) && (strcmp(buf, "#time") == 0))
- {
- osc_time_t t0, t1, t2;
- double dt0, dt1, dt2;
-
- WriteMode(buf+6);
-
- t0 = ReadTime(buf+8);
-
- WriteLogicalTime(buf+16);
- t1 = ReadTime(buf+16); // reverse
- dt0 = TimeToSeconds(t0); // client time
- dt1 = TimeToSeconds(t1); // server time
-
- // fprintf(stderr, "%f\t%f\t%f\n", dt0, dt1, dt0 - dt1);
-
- sendto(fd, buf, n, 0, (struct sockaddr *)clientDesc, clientDescLenght);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-//**********************
-
-void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr) {
- // t_dumpOSC *x;
- int size, messageLen, i;
- char *messageName;
- char *args;
-
- //#ifdef PRINTADDRS
- #ifdef DEBUG
- //PrintClientAddr(returnAddr);
- #endif
-
-
- if ((n%4) != 0) {
- complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping", n);
- return;
- }
-
- if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) {
- /* This is a bundle message. */
- #ifdef DEBUG
- printf("dumpOSC_ParsePacket: bundle msg: bundles not yet supported\n");
- #endif
-
- if (n < 16) {
- complain("Bundle message too small (%d bytes) for time tag", n);
- return;
- }
-
- /* Print the time tag */
- #ifdef DEBUG
- printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))), ntohl(*((unsigned long *)(buf+12))));
- #endif
-
- /* Note: if we wanted to actually use the time tag as a little-endian
- 64-bit int, we'd have to word-swap the two 32-bit halves of it */
-
- i = 16; /* Skip "#group\0" and time tag */
-
- while(i<n) {
- size = ntohl(*((int *) (buf + i)));
- if ((size % 4) != 0) {
- complain("Bad size count %d in bundle (not a multiple of 4)", size);
- return;
- }
- if ((size + i + 4) > n) {
- complain("Bad size count %d in bundle (only %d bytes left in entire bundle)",
- size, n-i-4);
- return;
- }
-
- /* Recursively handle element of bundle */
- dumpOSC_ParsePacket(x, buf+i+4, size, returnAddr);
- i += 4 + size;
- }
-
- if (i != n) {
- complain("This can't happen");
- }
- #ifdef DEBUG
- printf("]\n");
- #endif
-
- }
- else if ((n == 24) && (strcmp(buf, "#time") == 0))
- {
- complain("Time message: %s\n :).\n", htm_error_string);
- return;
-
- }
- else
- {
- /* This is not a bundle message */
-
- messageName = buf;
- args = DataAfterAlignedString(messageName, buf+n);
- if (args == 0) {
- complain("Bad message name string: %s\nDropping entire message.\n",
- htm_error_string);
- return;
- }
- messageLen = args-messageName;
- dumpOSC_Smessage(x, messageName, (void *)args, n-messageLen, returnAddr);
- }
-}
-
-#define SMALLEST_POSITIVE_FLOAT 0.000001f
-
-static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr) {
- char *chars = v;
- t_atom at;
- //t_atom myargv[50];
-
- int myargc = x->x_outatc;
- t_atom* mya = x->x_outat;
- int myi;
-
-#ifdef DEBUG
- printf("%s ", address);
-#endif
-
- // ztoln+cvt from envgen.c, ggee-0.18 ..
- // outlet_anything's 'symbol' gets set to address
- // so we dont need to append address to the atomlist
- /*
- SETSYMBOL(mya,gensym(address));myargc++;
- x->x_outatc = myargc;
- */
-
- if (n != 0) {
- if (chars[0] == ',') {
- if (chars[1] != ',') {
- /* This message begins with a type-tag string */
- dumpOSC_PrintTypeTaggedArgs(x, v, n);
- } else {
- /* Double comma means an escaped real comma, not a type string */
- dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1);
- }
- } else {
- dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
- }
- }
-
- outlet_anything(x->x_msgout,gensym(address),x->x_outatc,(t_atom*)&x->x_outat);
- x->x_outatc = 0;
-#ifdef DEBUG
- printf("\n");
-#endif
- fflush(stdout); /* Added for Sami 5/21/98 */
-}
-
-static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n) {
- char *typeTags, *thisType;
- char *p;
-
- int myargc = x->x_outatc;
- t_atom* mya = x->x_outat;
- int myi;
-
- typeTags = v;
-
- if (!IsNiceString(typeTags, typeTags+n)) {
- /* No null-termination, so maybe it wasn't a type tag
- string after all */
- dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
- return;
- }
-
- p = DataAfterAlignedString(typeTags, typeTags+n);
-
-
- for (thisType = typeTags + 1; *thisType != 0; ++thisType) {
- switch (*thisType) {
- case 'i': case 'r': case 'm': case 'c':
-#ifdef DEBUG
- //post("integer: %d", ntohl(*((int *) p)));
-#endif
- /* Martin Peach fix for negative floats:
- * was: SETFLOAT(mya+myargc,ntohl(*((int *) p)));
- * now is:
- */
- SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p)));
- myargc++;
-
- p += 4;
- break;
-
- case 'f': {
- int i = ntohl(*((int *) p));
- float *floatp = ((float *) (&i));
-#ifdef DEBUG
- post("float: %f", *floatp);
-#endif
- SETFLOAT(mya+myargc,*floatp);
- myargc++;
-
- p += 4;
- }
- break;
-
- case 'h': case 't':
-#ifdef DEBUG
- printf("[A 64-bit int] ");
-#endif
- post("[A 64-bit int] not implemented");
-
- p += 8;
- break;
-
- case 'd':
-#ifdef DEBUG
- printf("[A 64-bit float] ");
-#endif
- post("[A 64-bit float] not implemented");
-
- p += 8;
- break;
-
- case 's': case 'S':
- if (!IsNiceString(p, typeTags+n)) {
- post("Type tag said this arg is a string but it's not!\n");
- return;
- } else {
-#ifdef DEBUG
- post("string: \"%s\"", p);
-#endif
- SETSYMBOL(mya+myargc,gensym(p));
- myargc++;
- //outlet_list(x->x_msgout, 0,sizeof(p), p);
- //outlet_anything(x->x_msgout, 0, sizeof(p), p);
- p = DataAfterAlignedString(p, typeTags+n);
- // append to output vector ..
- }
- break;
-
- case 'T':
-#ifdef DEBUG
- printf("[True] ");
-#endif
- SETFLOAT(mya+myargc,1.);
- myargc++;
- break;
- case 'F':
-#ifdef DEBUG
- printf("[False] ");
-#endif
- SETFLOAT(mya+myargc,0.);
- myargc++;
- break;
- case 'N':
-#ifdef DEBUG
- printf("[Nil]");
-#endif
- post("sendOSC: [Nil] not implemented");
- break;
- case 'I':
-#ifdef DEBUG
- printf("[Infinitum]");
-#endif
- post("sendOSC: [Infinitum] not implemented");
- break;
-
- default:
- post("sendOSC: [Unrecognized type tag %c]", *thisType);
- // return;
- }
- }
- x->x_outatc = myargc;
-}
-
-static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma) {
- int i, thisi;
- float thisf;
- int *ints;
- char *chars;
- char *string, *nextString;
-
- int myargc= x->x_outatc;
- t_atom* mya = x->x_outat;
- int myi;
-
-
- /* Go through the arguments 32 bits at a time */
- ints = v;
- chars = v;
-
- for (i = 0; i<n/4; ) {
- string = &chars[i*4];
- thisi = ntohl(ints[i]);
- /* Reinterpret the (potentially byte-reversed) thisi as a float */
- thisf = *(((float *) (&thisi)));
-
- if (thisi >= -1000 && thisi <= 1000000) {
-#ifdef DEBUG
- printf("%d ", thisi);
-#endif
- // append to output vector ..
- SETFLOAT(mya+myargc,(t_float) (thisi));
- myargc++;
- // outlet_float(x->x_msgout, thisi);
- i++;
- } else if (thisf >= -1000.f && thisf <= 1000000.f &&
- (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) {
-#ifdef DEBUG
- printf("%f ", thisf);
-#endif
- // append to output vector ..
- SETFLOAT(mya+myargc,thisf);
- myargc++;
- //outlet_float(x->x_msgout, thisf);
- i++;
- } else if (IsNiceString(string, chars+n)) {
- nextString = DataAfterAlignedString(string, chars+n);
-#ifdef DEBUG
- printf("\"%s\" ", (i == 0 && skipComma) ? string +1 : string);
-#endif
- // append to output vector ..
- SETSYMBOL(mya+myargc,gensym(string));
- myargc++;
- //outlet_symbol(x->x_msgout, gensym((i == 0 && skipComma) ? string +1 : string));
- i += (nextString-string) / 4;
- } else {
- // unhandled .. ;)
-#ifdef DEBUG
- printf("0x%x xx", ints[i]);
-#endif
- i++;
- }
- x->x_outatc = myargc;
- }
-}
-
-
-#define STRING_ALIGN_PAD 4
-
-char *DataAfterAlignedString(char *string, char *boundary)
-{
- /* The argument is a block of data beginning with a string. The
- string has (presumably) been padded with extra null characters
- so that the overall length is a multiple of STRING_ALIGN_PAD
- bytes. Return a pointer to the next byte after the null
- byte(s). The boundary argument points to the character after
- the last valid character in the buffer---if the string hasn't
- ended by there, something's wrong.
-
- If the data looks wrong, return 0, and set htm_error_string */
-
- int i;
-
- if ((boundary - string) %4 != 0) {
- fprintf(stderr, "Internal error: DataAfterAlignedString: bad boundary\n");
- return 0;
- }
-
- for (i = 0; string[i] != '\0'; i++) {
- if (string + i >= boundary) {
- htm_error_string = "DataAfterAlignedString: Unreasonably long string";
- return 0;
- }
- }
-
- /* Now string[i] is the first null character */
- i++;
-
- for (; (i % STRING_ALIGN_PAD) != 0; i++) {
- if (string + i >= boundary) {
- htm_error_string = "DataAfterAlignedString: Unreasonably long string";
- return 0;
- }
- if (string[i] != '\0') {
- htm_error_string = "DataAfterAlignedString: Incorrectly padded string.";
- return 0;
- }
- }
-
- return string+i;
-}
-
-Boolean IsNiceString(char *string, char *boundary)
-{
- /* Arguments same as DataAfterAlignedString(). Is the given "string"
- really a string? I.e., is it a sequence of isprint() characters
- terminated with 1-4 null characters to align on a 4-byte boundary? */
-
- int i;
-
- if ((boundary - string) %4 != 0) {
- fprintf(stderr, "Internal error: IsNiceString: bad boundary\n");
- return 0;
- }
-
- for (i = 0; string[i] != '\0'; i++) {
- if (!isprint(string[i])) return FALSE;
- if (string + i >= boundary) return FALSE;
- }
-
- /* If we made it this far, it's a null-terminated sequence of printing characters
- in the given boundary. Now we just make sure it's null padded... */
-
- /* Now string[i] is the first null character */
- i++;
- for (; (i % STRING_ALIGN_PAD) != 0; i++) {
- if (string[i] != '\0') return FALSE;
- }
-
- return TRUE;
-}
-
-
-
-
-
-
-
-
-
-#include <stdarg.h>
-void complain(char *s, ...) {
- va_list ap;
- va_start(ap, s);
- fprintf(stderr, "*** ERROR: ");
- vfprintf(stderr, s, ap);
- fprintf(stderr, "\n");
- va_end(ap);
-}
-
-#endif /* __sgi or LINUX or WIN32 */
-
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 @@
-/* ------------------------ fatom ----------------------------- */
-
-#define x_val a_pos.a_w.w_float
-#define DEBUG(x)
-
-#include <string.h>
-#include <stdio.h>
-
-typedef struct _fatom
-{
- t_object x_obj;
- t_atom a_pos; /* the value of the fatom */
-
- t_symbol* x_send;
- t_symbol* x_receive;
- t_glist * x_glist; /* value of the current canvas, intialized in _new */
- int x_rect_width; /* width of the widget */
- int x_rect_height; /* height of the widget */
- t_symbol* x_sym; /* symbol for receiving callbacks from GUI */
- t_symbol* x_type; /* type of fatom (vslider, hslider, checkbutton) */
-
- t_symbol* x_text; /* associated widget text */
- int x_max; /* maximum value of a_pos (x_val) */
- int x_min; /* minimum value of a_pos (x_val) */
- int x_width; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */
- t_symbol* x_color;
- t_symbol* x_bgcolor;
-} t_fatom;
-
-/* widget helper functions */
-
-
-
-
-static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout)
-{
- int n = nin;
- int nplus, i;
- nplus = (n == 1 ? 1 : n-1);
- DEBUG(post("draw inlet");)
- for (i = 0; i < n; i++)
- {
- int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
- if (firsttime)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
- glist_getcanvas(glist),
- onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
- x, i);
- else
- sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
- glist_getcanvas(glist), x, i,
- onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
- }
- n = nout;
- nplus = (n == 1 ? 1 : n-1);
- for (i = 0; i < n; i++)
- {
- int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
- if (firsttime)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
- glist_getcanvas(glist),
- onset, text_ypix(&x->x_obj, glist),
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1,
- x, i);
- else
- sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
- glist_getcanvas(glist), x, i,
- onset, text_ypix(&x->x_obj, glist),
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1);
-
- }
- DEBUG(post("draw inlet end");)
-}
-
-
-static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) {
- int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2);
-
- if (firsttime)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
- glist_getcanvas(glist),
- onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
- x);
- else
- sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
- glist_getcanvas(glist), x,
- onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
-}
-
-static void create_widget(t_fatom *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
-
- if (!strcmp(x->x_type->s_name,"vslider")) {
- x->x_rect_width = x->x_width+15;
- x->x_rect_height = x->x_max-x->x_min+26;
-
- sys_vgui("scale .x%x.c.s%x \
- -sliderlength 10 \
- -showvalue 0 \
- -length %d \
- -resolution 0.01 \
- -repeatinterval 20 \
- -from %d -to %d \
- -width %d \
- -bg %s \
- -activebackground %s \
- -troughcolor %s \
- -command fatom_cb%x\n",canvas,x,
- x->x_max-x->x_min+14,
- x->x_max,
- x->x_min,
- x->x_width,
- x->x_color->s_name,
- x->x_color->s_name,
- x->x_bgcolor->s_name,
- x);
- } else if (!strcmp(x->x_type->s_name,"hslider")) {
- x->x_rect_width = x->x_max-x->x_min + 24;
- x->x_rect_height = x->x_width + 15;
- sys_vgui("scale .x%x.c.s%x \
- -sliderlength 10 \
- -showvalue 0 \
- -length %d \
- -resolution 0.01 \
- -orient horizontal \
- -repeatinterval 20 \
- -from %d -to %d \
- -width %d \
- -bg %s \
- -activebackground %s \
- -troughcolor %s \
- -command fatom_cb%x\n",canvas,x,
- x->x_max-x->x_min+14,
- x->x_min,
- x->x_max,
- x->x_width,
- x->x_color->s_name,
- x->x_color->s_name,
- x->x_bgcolor->s_name,
- x);
- } else if (!strcmp(x->x_type->s_name,"checkbutton")) {
- x->x_rect_width = 32;
- x->x_rect_height = 28;
- sys_vgui("checkbutton .x%x.c.s%x \
- -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \
- -bg %s \
- -activebackground %s \
- \n",canvas,x,x,x,x,
- x->x_text->s_name,
- x->x_color->s_name,
- x->x_bgcolor->s_name);
- } else if (!strcmp(x->x_type->s_name,"hradio")) {
- int i;
- x->x_rect_width = 8*20;
- x->x_rect_height = 25;
- for (i=0;i<8;i++) {
- sys_vgui("radiobutton .x%x.c.s%x%d \
- -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
- }
- /* TODO pack them */
- } else if (!strcmp(x->x_type->s_name,"vradio")) {
- int i;
- x->x_rect_width = 30;
- x->x_rect_height = 20*8+5;
- for (i=0;i<8;i++) {
- sys_vgui("radiobutton .x%x.c.s%x%d \
- -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
- }
- /* TODO pack them */
- } else {
- x->x_rect_width = 32;
- x->x_rect_height = 140;
- sys_vgui("scale .x%x.c.s%x \
- -sliderlength 10 \
- -showvalue 0 \
- -length 131 \
- -from 127 -to 0 \
- -command fatom_cb%x\n",canvas,x,x);
- }
-
- /* set the start value */
- if (!strcmp(x->x_type->s_name,"checkbutton")) {
- if (x->x_val)
- sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val);
- else
- sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val);
- } else
- sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val);
-
-}
-
-
-
-
-
-static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime)
-{
- t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist);
- DEBUG(post("drawme %d",firsttime);)
- if (firsttime) {
- DEBUG(post("glist %x canvas %x",x->x_glist,canvas));
- create_widget(x,glist);
- x->x_glist = canvas;
- sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n",
- canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x);
-
- }
- else {
- sys_vgui(".x%x.c coords %xS \
-%d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2);
- }
- draw_inlets(x, glist, firsttime, 1,1);
- // draw_handle(x, glist, firsttime);
-
-}
-
-
-static void fatom_erase(t_fatom* x,t_glist* glist)
-{
- int n;
-
- DEBUG(post("erase");)
- sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x);
-
- sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x);
-
- /* inlets and outlets */
-
- sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0);
- sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0);
- sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0);
-}
-
-
-
-/* ------------------------ fatom widgetbehaviour----------------------------- */
-
-
-static void fatom_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
-{
- int width, height;
- t_fatom* s = (t_fatom*)z;
-
- width = s->x_rect_width;
- height = s->x_rect_height;
- *xp1 = text_xpix(&s->x_obj, owner);
- *yp1 = text_ypix(&s->x_obj, owner);
- *xp2 = text_xpix(&s->x_obj, owner) + width;
- *yp2 = text_ypix(&s->x_obj, owner) + height;
-}
-
-static void fatom_displace(t_gobj *z, t_glist *glist,
- int dx, int dy)
-{
- t_fatom *x = (t_fatom *)z;
- DEBUG(post("displace");)
- x->x_obj.te_xpix += dx;
- x->x_obj.te_ypix += dy;
- if (glist_isvisible(glist))
- {
- sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
- glist_getcanvas(glist), x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height);
-
- fatom_drawme(x, glist, 0);
- canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
- }
- DEBUG(post("displace end");)
-}
-
-static void fatom_select(t_gobj *z, t_glist *glist, int state)
-{
- t_fatom *x = (t_fatom *)z;
- if (state) {
- sys_vgui(".x%x.c create rectangle \
-%d %d %d %d -tags %xSEL -outline blue\n",
- glist_getcanvas(glist),
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height,
- x);
- }
- else {
- sys_vgui(".x%x.c delete %xSEL\n",
- glist_getcanvas(glist), x);
- }
-
-
-
-}
-
-
-static void fatom_activate(t_gobj *z, t_glist *glist, int state)
-{
-/* t_text *x = (t_text *)z;
- t_rtext *y = glist_findrtext(glist, x);
- if (z->g_pd != gatom_class) rtext_activate(y, state);*/
-}
-
-static void fatom_delete(t_gobj *z, t_glist *glist)
-{
- t_text *x = (t_text *)z;
- canvas_deletelinesfor(glist_getcanvas(glist), x);
-}
-
-
-static void fatom_vis(t_gobj *z, t_glist *glist, int vis)
-{
- t_fatom* s = (t_fatom*)z;
- t_rtext *y;
- DEBUG(post("vis: %d",vis);)
- if (vis) {
-#ifdef PD_MINOR_VERSION
- y = (t_rtext *) rtext_new(glist, (t_text *)z);
-#else
- y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0);
-#endif
- fatom_drawme(s, glist, 1);
- }
- else {
- y = glist_findrtext(glist, (t_text *)z);
- fatom_erase(s,glist);
- rtext_free(y);
- }
-}
-
-static void fatom_save(t_gobj *z, t_binbuf *b);
-
-t_widgetbehavior fatom_widgetbehavior;
-
-
-
-
-static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) {
- x->x_rect_width = w;
- x->x_rect_height = h;
-}
-
-static void fatom_color(t_fatom* x,t_symbol* col)
-{
-
-}
-
-
-static void fatom_f(t_fatom* x,t_floatarg f)
-{
- x->x_val = f;
- if (x->x_send == &s_)
- outlet_float(x->x_obj.ob_outlet,f);
- else
- if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f);
-}
-
-
-static void fatom_float(t_fatom* x,t_floatarg f)
-{
- if (glist_isvisible(x->x_glist)) {
- if (!strcmp(x->x_type->s_name,"checkbutton")) {
- if (x->x_val)
- sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f);
- else
- sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f);
- } else
- sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f);
- }
- fatom_f(x,f);
-}
-
-
-static void fatom_bang(t_fatom* x,t_floatarg f)
-{
- outlet_float(x->x_obj.ob_outlet,x->x_val);
-}
-
-
-static void fatom_properties(t_gobj *z, t_glist *owner)
-{
- post("N/I");
-}
-
-
-static void fatom_save(t_gobj *z, t_binbuf *b)
-{
-
- t_fatom *x = (t_fatom *)z;
-
- binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
- x->x_obj.te_xpix, x->x_obj.te_ypix ,
- gensym("fatom"),x->x_type);
- binbuf_addv(b, ";");
-}
-
-
-static void *fatom_new(t_fatom* x,int argc,t_atom* argv)
-{
- char buf[256];
- int n = 0;
- x->x_glist = canvas_getcurrent();
-
- x->x_text = gensym("");
- x->x_max = 127;
- x->x_min = 0;
- x->x_width = 15;
- x->x_color = gensym("grey");
- x->x_bgcolor = gensym("grey");
- x->x_send = &s_;
-
- while (argc) {
- if (argv->a_type == A_FLOAT) {
- if (n==0) x->x_max = atom_getfloat(argv);
- if (n==1) x->x_min = atom_getfloat(argv);
- if (n==2) x->x_width = atom_getfloat(argv);
- }
-
- if (argv->a_type == A_SYMBOL) {
- post("%d: symbol value %s",n,atom_getsymbol(argv)->s_name);
- if (n==3) x->x_send = atom_getsymbol(argv);
- if (n==4) x->x_color = atom_getsymbol(argv);
- if (n==5) x->x_bgcolor = atom_getsymbol(argv);
- }
- argv++;
- argc--;
- n++;
- }
-
- /* bind to a symbol for slider callback (later make this based on the
- filepath ??) */
-
- sprintf(buf,"fatom%x",(t_int)x);
- x->x_sym = gensym(buf);
- pd_bind(&x->x_obj.ob_pd, x->x_sym);
-
- /* pipe startup code to tk */
-
- sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x);
-
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-static void fatom_setup_common(t_class* class)
-{
-
- fatom_widgetbehavior.w_getrectfn = fatom_getrect;
- fatom_widgetbehavior.w_displacefn = fatom_displace;
- fatom_widgetbehavior.w_selectfn = fatom_select;
- fatom_widgetbehavior.w_activatefn = fatom_activate;
- fatom_widgetbehavior.w_deletefn = fatom_delete;
- fatom_widgetbehavior.w_visfn = fatom_vis;
-#if PD_MINOR_VERSION < 37
- fatom_widgetbehavior.w_savefn = fatom_save;
- fatom_widgetbehavior.w_propertiesfn = NULL;
-#endif
- fatom_widgetbehavior.w_clickfn = NULL;
-
- class_addfloat(class, (t_method)fatom_float);
- class_addbang(class, (t_method)fatom_bang);
- class_addmethod(class, (t_method)fatom_f, gensym("f"),
- A_FLOAT, 0);
-
-/*
- class_addmethod(class, (t_method)fatom_size, gensym("size"),
- A_FLOAT, A_FLOAT, 0);
-
- class_addmethod(class, (t_method)fatom_color, gensym("color"),
- A_SYMBOL, 0);
-*/
-/*
- class_addmethod(class, (t_method)fatom_open, gensym("open"),
- A_SYMBOL, 0);
-*/
-
- class_setwidget(class,&fatom_widgetbehavior);
-#if PD_MINOR_VERSION >= 37
- class_setsavefn(class,&fatom_save);
-#endif
-}
-
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 @@
-#N canvas 0 0 240 300 8;
-#X obj 21 61 gcanvas 80 80;
-#X text 14 9 gcanvas .. mouse coordinate enabled canvas;
-#X text 13 22 ==========================================;
-#X floatatom 21 148 5 0 0 0 - - -;
-#X floatatom 94 147 5 0 0 0 - - -;
-#X connect 0 0 3 0;
-#X connect 0 1 4 0;
-
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 @@
-
-VERSION = 0.2
-SOURCE = $(shell ls *.c)
-TARGETS = $(SOURCE:.c=.pd_linux)
-
-EXT= pd_linux
-
-AFLAGS = -g -O2 -I./ -DFIXEDPOINT
-EFLAGS = -shared -Wl,-export-dynamic
-PREFIX = /usr
-
-
-all: $(TARGETS)
-
-clean:
- -rm $(TARGETS)
- -rm *.o *~
-
-tar: clean
- cd ..;tar czvf PDa-externals-$(VERSION).tgz PDa-externals
-
-upload: tar
- scp ../PDa-externals-$(VERSION).tgz gige@xdv.org:~/www/pda/release
-
-install:
- install -d $(DESTDIR)/$(PREFIX)/lib/pd/extra
- cp $(TARGETS) $(DESTDIR)/$(PREFIX)/lib/pd/extra
-
-%.$(EXT) : %.o
- $(CC) -o $@ $(EFLAGS) $+
-
-%.o : %.c
- $(CC) -c $(AFLAGS) $(CFLAGS) $+
-
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 @@
-/*
-Written by Matt Wright, The Center for New Music and Audio Technologies,
-University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
-The Regents of the University of California (Regents).
-
-Permission to use, copy, modify, distribute, and distribute modified versions
-of this software and its documentation without fee and without a signed
-licensing agreement, is hereby granted, provided that the above copyright
-notice, this paragraph and the following two paragraphs appear in all copies,
-modifications, and distributions.
-
-IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
-OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
-BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
-HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
-MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-
-
-The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
-*/
-
-
-/* sendOSC.c
-
- Matt Wright, 6/3/97
- based on sendOSC.c, which was based on a version by Adrian Freed
-
- Text-based OpenSoundControl client. User can enter messages via command
- line arguments or standard input.
-
- Version 0.1: "play" feature
- Version 0.2: Message type tags.
-
- pd version branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/sendOSC/sendOSC.c
- -------------
- -- added bundle stuff to send. jdl 20020416
- -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
- -- ost_at_test.at + i22_at_test.at, 2000-2002
- modified to compile as pd externel
-*/
-
-#define MAX_ARGS 2000
-#define SC_BUFFER_SIZE 64000
-
-#include "../src/m_pd.h"
-#include "OSC-client.h"
-
-#include <string.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#ifdef WIN32
-#include <winsock2.h>
-#include <io.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <winsock2.h>
-#include <ctype.h>
-#include <signal.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <rpc/rpc.h>
-#include <sys/times.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <netdb.h>
-#endif
-
-#ifdef __APPLE__
- #include <string.h>
-#endif
-
-#define UNIXDG_PATH "/tmp/htm"
-#define UNIXDG_TMP "/tmp/htm.XXXXXX"
-
-
-
-OSCTimeTag OSCTT_Immediately(void) {
- OSCTimeTag result;
- result.seconds = 0;
- result.fraction = 1;
- return result;
-}
-
-
-OSCTimeTag OSCTT_CurrentTime(void) {
- OSCTimeTag result;
- result.seconds = 0;
- result.fraction = 1;
- return result;
-}
-
-OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) {
- OSCTimeTag result;
- result.seconds = 0;
- result.fraction = 1;
- return result;
-}
-
-
-typedef int bool;
-
-typedef struct
-{
- float srate;
-
- struct sockaddr_in serv_addr; /* udp socket */
- #ifndef WIN32
- struct sockaddr_un userv_addr; /* UNIX socket */
- #endif
- int sockfd; /* socket file descriptor */
- int index, len,uservlen;
- void *addr;
- int id;
-} desc;
-
-
-/* open a socket for HTM communication to given host on given portnumber */
-/* if host is 0 then UNIX protocol is used (i.e. local communication */
-void *OpenHTMSocket(char *host, int portnumber)
-{
- struct sockaddr_in cl_addr;
- #ifndef WIN32
- int sockfd;
- struct sockaddr_un ucl_addr;
- #else
- unsigned int sockfd;
- #endif
-
- desc *o;
- int oval = 1;
- o = malloc(sizeof(*o));
- if(!o) return 0;
-
- #ifndef WIN32
-
- if(!host)
- {
- char *mktemp(char *);
- int clilen;
- o->len = sizeof(ucl_addr);
- /*
- * Fill in the structure "userv_addr" with the address of the
- * server that we want to send to.
- */
-
- bzero((char *) &o->userv_addr, sizeof(o->userv_addr));
- o->userv_addr.sun_family = AF_UNIX;
- strcpy(o->userv_addr.sun_path, UNIXDG_PATH);
- sprintf(o->userv_addr.sun_path+strlen(o->userv_addr.sun_path), "%d", portnumber);
- o->uservlen = sizeof(o->userv_addr.sun_family) + strlen(o->userv_addr.sun_path);
- o->addr = &(o->userv_addr);
- /*
- * Open a socket (a UNIX domain datagram socket).
- */
-
- if ( (sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0)
- {
- /*
- * Bind a local address for us.
- * In the UNIX domain we have to choose our own name (that
- * should be unique). We'll use mktemp() to create a unique
- * pathname, based on our process id.
- */
-
- bzero((char *) &ucl_addr, sizeof(ucl_addr)); /* zero out */
- ucl_addr.sun_family = AF_UNIX;
- strcpy(ucl_addr.sun_path, UNIXDG_TMP);
-
- mktemp(ucl_addr.sun_path);
- clilen = sizeof(ucl_addr.sun_family) + strlen(ucl_addr.sun_path);
-
- if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0)
- {
- perror("client: can't bind local address");
- close(sockfd);
- sockfd = -1;
- }
- }
- else
- perror("unable to make socket\n");
-
- }else
-
- #endif
-
- {
- /*
- * Fill in the structure "serv_addr" with the address of the
- * server that we want to send to.
- */
- o->len = sizeof(cl_addr);
-
- #ifdef WIN32
- ZeroMemory((char *)&o->serv_addr, sizeof(o->serv_addr));
- #else
- bzero((char *)&o->serv_addr, sizeof(o->serv_addr));
- #endif
-
- o->serv_addr.sin_family = AF_INET;
-
- /* MW 6/6/96: Call gethostbyname() instead of inet_addr(),
- so that host can be either an Internet host name (e.g.,
- "les") or an Internet address in standard dot notation
- (e.g., "128.32.122.13") */
- {
- struct hostent *hostsEntry;
- unsigned long address;
-
- hostsEntry = gethostbyname(host);
- if (hostsEntry == NULL) {
- fprintf(stderr, "Couldn't decipher host name \"%s\"\n", host);
- #ifndef WIN32
- herror(NULL);
- #endif
- return 0;
- }
- address = *((unsigned long *) hostsEntry->h_addr_list[0]);
- o->serv_addr.sin_addr.s_addr = address;
- }
-
- /* was: o->serv_addr.sin_addr.s_addr = inet_addr(host); */
-
- /* End MW changes */
-
- /*
- * Open a socket (a UDP domain datagram socket).
- */
-
-
- #ifdef WIN32
- o->serv_addr.sin_port = htons((USHORT)portnumber);
- o->addr = &(o->serv_addr);
- if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET) {
- ZeroMemory((char *)&cl_addr, sizeof(cl_addr));
- cl_addr.sin_family = AF_INET;
- cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- cl_addr.sin_port = htons(0);
-
- // enable broadcast: jdl ~2003
- if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
- perror("setsockopt");
- }
-
- if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
- perror("could not bind\n");
- closesocket(sockfd);
- sockfd = -1;
- }
- }
- else { perror("unable to make socket\n");}
- #else
- o->serv_addr.sin_port = htons(portnumber);
- o->addr = &(o->serv_addr);
- if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
- bzero((char *)&cl_addr, sizeof(cl_addr));
- cl_addr.sin_family = AF_INET;
- cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- cl_addr.sin_port = htons(0);
-
- // enable broadcast: jdl ~2003
- if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
- perror("setsockopt");
- }
-
- if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
- perror("could not bind\n");
- close(sockfd);
- sockfd = -1;
- }
- }
- else { perror("unable to make socket\n");}
- #endif
- }
- #ifdef WIN32
- if(sockfd == INVALID_SOCKET) {
- #else
- if(sockfd < 0) {
- #endif
- free(o);
- o = 0;
- }
- else
- o->sockfd = sockfd;
- return o;
-}
-
-static bool sendudp(const struct sockaddr *sp, int sockfd,int length, int count, void *b)
-{
- int rcount;
- if((rcount=sendto(sockfd, b, count, 0, sp, length)) != count)
- {
- printf("sockfd %d count %d rcount %dlength %d\n", sockfd,count,rcount,length);
- return FALSE;
- }
- return TRUE;
-}
-
-bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer)
-{
- desc *o = (desc *)htmsendhandle;
- return sendudp(o->addr, o->sockfd, o->len, length_in_bytes, buffer);
-}
-void CloseHTMSocket(void *htmsendhandle)
-{
- desc *o = (desc *)htmsendhandle;
- #ifdef WIN32
- if(SOCKET_ERROR == closesocket(o->sockfd)) {
- perror("CloseHTMSocket::closesocket failed\n");
- return;
- }
- #else
- if(close(o->sockfd) == -1)
- {
- perror("CloseHTMSocket::closesocket failed");
- return;
- }
- #endif
-
- free(o);
-}
-
-
-///////////////////////
-// from sendOSC
-
-typedef struct {
- //enum {INT, FLOAT, STRING} type;
- enum {INT_osc, FLOAT_osc, STRING_osc} type;
- union {
- int i;
- float f;
- char *s;
- } datum;
-} typedArg;
-
-void CommandLineMode(int argc, char *argv[], void *htmsocket);
-OSCTimeTag ParseTimeTag(char *s);
-void ParseInteractiveLine(OSCbuf *buf, char *mesg);
-typedArg ParseToken(char *token);
-int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args);
-void SendBuffer(void *htmsocket, OSCbuf *buf);
-void SendData(void *htmsocket, int size, char *data);
-/* defined in OSC-system-dependent.c now */
-
-//static void *htmsocket;
-static int exitStatus = 0;
-static int useTypeTags = 0;
-
-static char bufferForOSCbuf[SC_BUFFER_SIZE];
-
-
-/////////
-// end from sendOSC
-
-static t_class *sendOSC_class;
-
-typedef struct _sendOSC
-{
- t_object x_obj;
- int x_protocol; // UDP/TCP (udp only atm)
- t_int x_typetags; // typetag flag
- void *x_htmsocket; // sending socket
- int x_bundle; // bundle open flag
- OSCbuf x_oscbuf[1]; // OSCbuffer
- t_outlet *x_bdpthout;// bundle-depth floatoutlet
-} t_sendOSC;
-
-static void *sendOSC_new(t_floatarg udpflag)
-{
- t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class);
- outlet_new(&x->x_obj, &s_float);
- x->x_htmsocket = 0; // {{raf}}
- // set udp
- x->x_protocol = SOCK_STREAM;
- // set typetags to 1 by default
- x->x_typetags = 1;
- // bunlde is closed
- x->x_bundle = 0;
- OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
- x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float();
- //x->x_oscbuf =
- return (x);
-}
-
-
-void sendOSC_openbundle(t_sendOSC *x)
-{
- if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING ||
- OSC_openBundle(x->x_oscbuf, OSCTT_Immediately()))
- {
- post("Problem opening bundle: %s\n", OSC_errorMessage);
- return;
- }
- x->x_bundle = 1;
- outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
-}
-
-static void sendOSC_closebundle(t_sendOSC *x)
-{
- if (OSC_closeBundle(x->x_oscbuf)) {
- post("Problem closing bundle: %s\n", OSC_errorMessage);
- return;
- }
- outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
- // in bundle mode we send when bundle is closed?
- if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) {
- // post("x_oscbuf: something inside me?");
- if (x->x_htmsocket) {
- SendBuffer(x->x_htmsocket, x->x_oscbuf);
- } else {
- post("sendOSC: not connected");
- }
- OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
- x->x_bundle = 0;
- return;
- }
- // post("x_oscbuf: something went wrong");
-}
-
-static void sendOSC_settypetags(t_sendOSC *x, t_float *f)
- {
- x->x_typetags = (int)f;
- post("sendOSC.c: setting typetags %d",x->x_typetags);
- }
-
-
-static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname,
- t_floatarg fportno)
-{
- int portno = fportno;
- /* create a socket */
-
- // make sure handle is available
- if(x->x_htmsocket == 0) {
- //
- x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno);
- if (!x->x_htmsocket)
- post("Couldn't open socket: ");
- else {
- post("connected to port %s:%d (hSock=%d)", hostname->s_name, portno, x->x_htmsocket);
- outlet_float(x->x_obj.ob_outlet, 1);
- }
- }
- else
- perror("call to sendOSC_connect() against UNavailable socket handle");
-}
-
-void sendOSC_disconnect(t_sendOSC *x)
-{
- if (x->x_htmsocket)
- {
- post("disconnecting htmsock (hSock=%d)...", x->x_htmsocket);
- CloseHTMSocket(x->x_htmsocket);
- x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this
- outlet_float(x->x_obj.ob_outlet, 0);
- }
- else {
- perror("call to sendOSC_disconnect() against unused socket handle");
- }
-}
-
-void sendOSC_senduntyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
-{
- char* targv[MAXPDARG];
- char tmparg[MAXPDSTRING];
- char* tmp = tmparg;
- //char testarg[MAXPDSTRING];
- int c;
-
- post("sendOSC: use typetags 0/1 message and plain send method so send untypetagged...");
- return;
-
- //atom_string(argv,testarg, MAXPDSTRING);
- for (c=0;c<argc;c++) {
- atom_string(argv+c,tmp, 80);
- targv[c] = tmp;
- tmp += strlen(tmp)+1;
- }
-
- // this sock needs to be larger than 0, not >= ..
- if (x->x_htmsocket)
- {
- CommandLineMode(argc, targv, x->x_htmsocket);
- // post("test %d", c);
- }
- else {
- post("sendOSC: not connected");
- }
-}
-
-//////////////////////////////////////////////////////////////////////
-// this is the real and only sending routine now, for both typed and
-// undtyped mode.
-
-static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
-{
- char* targv[MAX_ARGS];
- char tmparg[MAXPDSTRING];
- char* tmp = tmparg;
- int c;
-
- char *messageName;
- char *token;
- typedArg args[MAX_ARGS];
- int i,j;
- int numArgs = 0;
-
- messageName = "";
-#ifdef DEBUG
- post ("sendOSC: messageName: %s", messageName);
-#endif
-
-
-
- for (c=0;c<argc;c++) {
- atom_string(argv+c,tmp, 80);
-
-#ifdef DEBUG
- // post ("sendOSC: %d, %s",c, tmp);
-#endif
-
- targv[c] = tmp;
- tmp += strlen(tmp)+1;
-
-#ifdef DEBUG
- // post ("sendOSC: %d, %s",c, targv[c]);
-#endif
- }
-
- // this sock needs to be larger than 0, not >= ..
- if (x->x_htmsocket > 0)
- {
-#ifdef DEBUG
- post ("sendOSC: type tags? %d", useTypeTags);
-#endif
-
- messageName = strtok(targv[0], ",");
- j = 1;
- for (i = j; i < argc; i++) {
- token = strtok(targv[i],",");
- args[i-j] = ParseToken(token);
-#ifdef DEBUG
- printf("cell-cont: %s\n", targv[i]);
- printf(" type-id: %d\n", args[i-j]);
-#endif
- numArgs = i;
- }
-
-
- if(WriteMessage(x->x_oscbuf, messageName, numArgs, args)) {
- post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage);
- return;
- }
-
- if(!x->x_bundle) {
- SendBuffer(x->x_htmsocket, x->x_oscbuf);
- OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
- }
-
- //CommandLineMode(argc, targv, x->x_htmsocket);
- //useTypeTags = 0;
- }
- else {
- post("sendOSC: not connected");
- }
-}
-
-void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
-{
- if(!argc) {
- post("not sending empty message.");
- return;
- }
- if(x->x_typetags) {
- useTypeTags = 1;
- sendOSC_sendtyped(x,s,argc,argv);
- useTypeTags = 0;
- } else {
- sendOSC_sendtyped(x,s,argc,argv);
- }
-}
-
-static void sendOSC_free(t_sendOSC *x)
-{
- sendOSC_disconnect(x);
-}
-
-#ifdef WIN32
- OSC_API void sendOSC_setup(void) {
-#else
- void sendOSC_setup(void) {
-#endif
- sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new,
- (t_method)sendOSC_free,
- sizeof(t_sendOSC), 0, A_DEFFLOAT, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_connect,
- gensym("connect"), A_SYMBOL, A_FLOAT, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_disconnect,
- gensym("disconnect"), 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_settypetags,
- gensym("typetags"),
- A_FLOAT, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_send,
- gensym("send"),
- A_GIMME, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_send,
- gensym("senduntyped"),
- A_GIMME, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_send,
- gensym("sendtyped"),
- A_GIMME, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_openbundle,
- gensym("["),
- 0, 0);
- class_addmethod(sendOSC_class, (t_method)sendOSC_closebundle,
- gensym("]"),
- 0, 0);
- class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd"));
-}
-
-
-
-
-
-/* Exit status codes:
- 0: successful
- 2: Message(s) dropped because of buffer overflow
- 3: Socket error
- 4: Usage error
- 5: Internal error
-*/
-
-void CommandLineMode(int argc, char *argv[], void *htmsocket) {
- char *messageName;
- char *token;
- typedArg args[MAX_ARGS];
- int i,j, numArgs;
- OSCbuf buf[1];
-
- OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
-
- if (argc > 1) {
- post("argc (%d) > 1", argc);
- }
-
- // ParseInteractiveLine(buf, argv);
- messageName = strtok(argv[0], ",");
-
- j = 1;
- for (i = j; i < argc; i++) {
- token = strtok(argv[i],",");
- args[i-j] = ParseToken(token);
-#ifdef DEBUG
- printf("cell-cont: %s\n", argv[i]);
- printf(" type-id: %d\n", args[i-j]);
-#endif
- numArgs = i;
- }
-
- if(WriteMessage(buf, messageName, numArgs, args)) {
- post("sendOSC: usage error. write-msg failed: %s", OSC_errorMessage);
- return;
- }
-
- SendBuffer(htmsocket, buf);
-}
-
-#define MAXMESG 2048
-
-void InteractiveMode(void *htmsocket) {
- char mesg[MAXMESG];
- OSCbuf buf[1];
- int bundleDepth = 0; /* At first, we haven't seen "[". */
-
- OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
-
- while (fgets(mesg, MAXMESG, stdin) != NULL) {
- if (mesg[0] == '\n') {
- if (bundleDepth > 0) {
- /* Ignore blank lines inside a group. */
- } else {
- /* blank line => repeat previous send */
- SendBuffer(htmsocket, buf);
- }
- continue;
- }
-
- if (bundleDepth == 0) {
- OSC_resetBuffer(buf);
- }
-
- if (mesg[0] == '[') {
- OSCTimeTag tt = ParseTimeTag(mesg+1);
- if (OSC_openBundle(buf, tt)) {
- post("Problem opening bundle: %s\n", OSC_errorMessage);
- OSC_resetBuffer(buf);
- bundleDepth = 0;
- continue;
- }
- bundleDepth++;
- } else if (mesg[0] == ']' && mesg[1] == '\n' && mesg[2] == '\0') {
- if (bundleDepth == 0) {
- post("Unexpected ']': not currently in a bundle.\n");
- } else {
- if (OSC_closeBundle(buf)) {
- post("Problem closing bundle: %s\n", OSC_errorMessage);
- OSC_resetBuffer(buf);
- bundleDepth = 0;
- continue;
- }
-
- bundleDepth--;
- if (bundleDepth == 0) {
- SendBuffer(htmsocket, buf);
- }
- }
- } else {
- ParseInteractiveLine(buf, mesg);
- if (bundleDepth != 0) {
- /* Don't send anything until we close all bundles */
- } else {
- SendBuffer(htmsocket, buf);
- }
- }
- }
-}
-
-OSCTimeTag ParseTimeTag(char *s) {
- char *p, *newline;
- typedArg arg;
-
- p = s;
- while (isspace(*p)) p++;
- if (*p == '\0') return OSCTT_Immediately();
-
- if (*p == '+') {
- /* Time tag is for some time in the future. It should be a
- number of seconds as an int or float */
-
- newline = strchr(s, '\n');
- if (newline != NULL) *newline = '\0';
-
- p++; /* Skip '+' */
- while (isspace(*p)) p++;
-
- arg = ParseToken(p);
- if (arg.type == STRING_osc) {
- post("warning: inscrutable time tag request: %s\n", s);
- return OSCTT_Immediately();
- } else if (arg.type == INT_osc) {
- return OSCTT_PlusSeconds(OSCTT_CurrentTime(),
- (float) arg.datum.i);
- } else if (arg.type == FLOAT_osc) {
- return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f);
- } else {
- error("This can't happen!");
- }
- }
-
- if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) {
- /* They specified the 8-byte tag in hex */
- OSCTimeTag tt;
- if (sscanf(p, "%llx", &tt) != 1) {
- post("warning: couldn't parse time tag %s\n", s);
- return OSCTT_Immediately();
- }
-#ifndef HAS8BYTEINT
- if (ntohl(1) != 1) {
- /* tt is a struct of seconds and fractional part,
- and this machine is little-endian, so sscanf
- wrote each half of the time tag in the wrong half
- of the struct. */
- int temp;
- temp = tt.seconds;
- tt.seconds = tt.fraction ;
- tt.fraction = temp;
- }
-#endif
- return tt;
- }
-
- post("warning: invalid time tag: %s\n", s);
- return OSCTT_Immediately();
-}
-
-
-void ParseInteractiveLine(OSCbuf *buf, char *mesg) {
- char *messageName, *token, *p;
- typedArg args[MAX_ARGS];
- int thisArg;
-
- p = mesg;
- while (isspace(*p)) p++;
- if (*p == '\0') return;
-
- messageName = p;
-
- if (strcmp(messageName, "play\n") == 0) {
- /* Special kludge feature to save typing */
- typedArg arg;
-
- if (OSC_openBundle(buf, OSCTT_Immediately())) {
- post("Problem opening bundle: %s\n", OSC_errorMessage);
- return;
- }
-
- arg.type = INT_osc;
- arg.datum.i = 0;
- WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg);
-
- arg.type = FLOAT_osc;
- arg.datum.i = 0.0f;
- WriteMessage(buf, "/voices/0/tm/goto", 1, &arg);
-
- if (OSC_closeBundle(buf)) {
- post("Problem closing bundle: %s\n", OSC_errorMessage);
- }
-
- return;
- }
-
- while (!isspace(*p) && *p != '\0') p++;
- if (isspace(*p)) {
- *p = '\0';
- p++;
- }
-
- thisArg = 0;
- while (*p != '\0') {
- /* flush leading whitespace */
- while (isspace(*p)) p++;
- if (*p == '\0') break;
-
- if (*p == '"') {
- /* A string argument: scan for close quotes */
- p++;
- args[thisArg].type = STRING_osc;
- args[thisArg].datum.s = p;
-
- while (*p != '"') {
- if (*p == '\0') {
- post("Unterminated quote mark: ignoring line\n");
- return;
- }
- p++;
- }
- *p = '\0';
- p++;
- } else {
- token = p;
- while (!isspace(*p) && (*p != '\0')) p++;
- if (isspace(*p)) {
- *p = '\0';
- p++;
- }
- args[thisArg] = ParseToken(token);
- }
- thisArg++;
- if (thisArg >= MAX_ARGS) {
- post("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n",
- MAX_ARGS);
- break;
- }
- }
-
- if (WriteMessage(buf, messageName, thisArg, args) != 0) {
- post("Problem sending message: %s\n", OSC_errorMessage);
- }
-}
-
-typedArg ParseToken(char *token) {
- char *p = token;
- typedArg returnVal;
-
- /* It might be an int, a float, or a string */
-
- if (*p == '-') p++;
-
- if (isdigit(*p) || *p == '.') {
- while (isdigit(*p)) p++;
- if (*p == '\0') {
- returnVal.type = INT_osc;
- returnVal.datum.i = atoi(token);
- return returnVal;
- }
- if (*p == '.') {
- p++;
- while (isdigit(*p)) p++;
- if (*p == '\0') {
- returnVal.type = FLOAT_osc;
- returnVal.datum.f = atof(token);
- return returnVal;
- }
- }
- }
-
- returnVal.type = STRING_osc;
- returnVal.datum.s = token;
- return returnVal;
-}
-
-int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) {
- int j, returnVal;
- const int wmERROR = -1;
-
- returnVal = 0;
-
-#ifdef DEBUG
- printf("WriteMessage: %s ", messageName);
-
- for (j = 0; j < numArgs; j++) {
- switch (args[j].type) {
- case INT_osc:
- printf("%d ", args[j].datum.i);
- break;
-
- case FLOAT_osc:
- printf("%f ", args[j].datum.f);
- break;
-
- case STRING_osc:
- printf("%s ", args[j].datum.s);
- break;
-
- default:
- error("Unrecognized arg type, (not exiting)");
- return(wmERROR);
- }
- }
- printf("\n");
-#endif
-
- if (!useTypeTags) {
- returnVal = OSC_writeAddress(buf, messageName);
- if (returnVal) {
- post("Problem writing address: %s\n", OSC_errorMessage);
- }
- } else {
- /* First figure out the type tags */
- char typeTags[MAX_ARGS+2];
- int i;
-
- typeTags[0] = ',';
-
- for (i = 0; i < numArgs; ++i) {
- switch (args[i].type) {
- case INT_osc:
- typeTags[i+1] = 'i';
- break;
-
- case FLOAT_osc:
- typeTags[i+1] = 'f';
- break;
-
- case STRING_osc:
- typeTags[i+1] = 's';
- break;
-
- default:
- error("Unrecognized arg type (not exiting)");
- return(wmERROR);
- }
- }
- typeTags[i+1] = '\0';
-
- returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
- if (returnVal) {
- post("Problem writing address: %s\n", OSC_errorMessage);
- }
- }
-
- for (j = 0; j < numArgs; j++) {
- switch (args[j].type) {
- case INT_osc:
- if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) {
- return returnVal;
- }
- break;
-
- case FLOAT_osc:
- if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) {
- return returnVal;
- }
- break;
-
- case STRING_osc:
- if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) {
- return returnVal;
- }
- break;
-
- default:
- error("Unrecognized arg type (not exiting)");
- returnVal = wmERROR;
- }
- }
- return returnVal;
-}
-
-void SendBuffer(void *htmsocket, OSCbuf *buf) {
-#ifdef DEBUG
- printf("Sending buffer...\n");
-#endif
- if (OSC_isBufferEmpty(buf)) {
- post("SendBuffer() called but buffer empty");
- return;
- }
- if (!OSC_isBufferDone(buf)) {
- error("SendBuffer() called but buffer not ready!, not exiting");
- return; //{{raf}}
- }
- SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf));
-}
-
-void SendData(void *htmsocket, int size, char *data) {
- if (!SendHTMSocket(htmsocket, size, data)) {
- post("SendData::SendHTMSocket()failure -- not connected");
- CloseHTMSocket(htmsocket);
- }
-}
-
-
-
-/* ----------------------
- OSC-client code
-
- */
-
-/* Here are the possible values of the state field: */
-
-#define EMPTY 0 /* Nothing written to packet yet */
-#define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */
-#define NEED_COUNT 2 /* Just opened a bundle; must write message name or
- open another bundle */
-#define GET_ARGS 3 /* Getting arguments to a message. If we see a message
- name or a bundle open/close then the current message
- will end. */
-#define DONE 4 /* All open bundles have been closed, so can't write
- anything else */
-
-#ifdef WIN32
- #include <winsock2.h>
- #include <io.h>
- #include <stdio.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-#endif
-
-#ifdef __APPLE__
- #include <sys/types.h>
-#endif
-
-#ifdef unix
- #include <netinet/in.h>
- #include <stdio.h>
-#endif
-
-
-char *OSC_errorMessage;
-
-static int OSC_padString(char *dest, char *str);
-static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str);
-static int OSC_WritePadding(char *dest, int i);
-static int CheckTypeTag(OSCbuf *buf, char expectedType);
-
-void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) {
- buf->buffer = byteArray;
- buf->size = size;
- OSC_resetBuffer(buf);
-}
-
-void OSC_resetBuffer(OSCbuf *buf) {
- buf->bufptr = buf->buffer;
- buf->state = EMPTY;
- buf->bundleDepth = 0;
- buf->prevCounts[0] = 0;
- buf->gettingFirstUntypedArg = 0;
- buf->typeStringPtr = 0;
-}
-
-int OSC_isBufferEmpty(OSCbuf *buf) {
- return buf->bufptr == buf->buffer;
-}
-
-int OSC_freeSpaceInBuffer(OSCbuf *buf) {
- return buf->size - (buf->bufptr - buf->buffer);
-}
-
-int OSC_isBufferDone(OSCbuf *buf) {
- return (buf->state == DONE || buf->state == ONE_MSG_ARGS);
-}
-
-char *OSC_getPacket(OSCbuf *buf) {
-#ifdef ERROR_CHECK_GETPACKET
- if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
- return buf->buffer;
- } else {
- OSC_errorMessage = "Packet has unterminated bundles";
- return 0;
- }
-#else
- return buf->buffer;
-#endif
-}
-
-int OSC_packetSize(OSCbuf *buf) {
-#ifdef ERROR_CHECK_PACKETSIZE
- if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
- return (buf->bufptr - buf->buffer);
- } else {
- OSC_errorMessage = "Packet has unterminated bundles";
- return 0;
- }
-#else
- return (buf->bufptr - buf->buffer);
-#endif
-}
-
-#define CheckOverflow(buf, bytesNeeded) { if ((bytesNeeded) > OSC_freeSpaceInBuffer(buf)) {OSC_errorMessage = "buffer overflow"; return 1;}}
-
-static void PatchMessageSize(OSCbuf *buf) {
- int4byte size;
- size = buf->bufptr - ((char *) buf->thisMsgSize) - 4;
- *(buf->thisMsgSize) = htonl(size);
-}
-
-int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) {
- if (buf->state == ONE_MSG_ARGS) {
- OSC_errorMessage = "Can't open a bundle in a one-message packet";
- return 3;
- }
-
- if (buf->state == DONE) {
- OSC_errorMessage = "This packet is finished; can't open a new bundle";
- return 4;
- }
-
- if (++(buf->bundleDepth) >= MAX_BUNDLE_NESTING) {
- OSC_errorMessage = "Bundles nested too deeply; change MAX_BUNDLE_NESTING in OpenSoundControl.h";
- return 2;
- }
-
- if (CheckTypeTag(buf, '\0')) return 9;
-
- if (buf->state == GET_ARGS) {
- PatchMessageSize(buf);
- }
-
- if (buf->state == EMPTY) {
- /* Need 16 bytes for "#bundle" and time tag */
- CheckOverflow(buf, 16);
- } else {
- /* This bundle is inside another bundle, so we need to leave
- a blank size count for the size of this current bundle. */
- CheckOverflow(buf, 20);
- *((int4byte *)buf->bufptr) = 0xaaaaaaaa;
- buf->prevCounts[buf->bundleDepth] = (int4byte *)buf->bufptr;
-
- buf->bufptr += 4;
- }
-
- buf->bufptr += OSC_padString(buf->bufptr, "#bundle");
-
-
- *((OSCTimeTag *) buf->bufptr) = tt;
-
- if (htonl(1) != 1) {
- /* Byte swap the 8-byte integer time tag */
- int4byte *intp = (int4byte *)buf->bufptr;
- intp[0] = htonl(intp[0]);
- intp[1] = htonl(intp[1]);
-
-#ifdef HAS8BYTEINT
- { /* tt is a 64-bit int so we have to swap the two 32-bit words.
- (Otherwise tt is a struct of two 32-bit words, and even though
- each word was wrong-endian, they were in the right order
- in the struct.) */
- int4byte temp = intp[0];
- intp[0] = intp[1];
- intp[1] = temp;
- }
-#endif
- }
-
- buf->bufptr += sizeof(OSCTimeTag);
-
- buf->state = NEED_COUNT;
-
- buf->gettingFirstUntypedArg = 0;
- buf->typeStringPtr = 0;
- return 0;
-}
-
-
-int OSC_closeBundle(OSCbuf *buf) {
- if (buf->bundleDepth == 0) {
- /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
- OSC_errorMessage = "Can't close bundle; no bundle is open!";
- return 5;
- }
-
- if (CheckTypeTag(buf, '\0')) return 9;
-
- if (buf->state == GET_ARGS) {
- PatchMessageSize(buf);
- }
-
- if (buf->bundleDepth == 1) {
- /* Closing the last bundle: No bundle size to patch */
- buf->state = DONE;
- } else {
- /* Closing a sub-bundle: patch bundle size */
- int size = buf->bufptr - ((char *) buf->prevCounts[buf->bundleDepth]) - 4;
- *(buf->prevCounts[buf->bundleDepth]) = htonl(size);
- buf->state = NEED_COUNT;
- }
-
- --buf->bundleDepth;
- buf->gettingFirstUntypedArg = 0;
- buf->typeStringPtr = 0;
- return 0;
-}
-
-
-int OSC_closeAllBundles(OSCbuf *buf) {
- if (buf->bundleDepth == 0) {
- /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
- OSC_errorMessage = "Can't close all bundles; no bundle is open!";
- return 6;
- }
-
- if (CheckTypeTag(buf, '\0')) return 9;
-
- while (buf->bundleDepth > 0) {
- OSC_closeBundle(buf);
- }
- buf->typeStringPtr = 0;
- return 0;
-}
-
-int OSC_writeAddress(OSCbuf *buf, char *name) {
- int4byte paddedLength;
-
- if (buf->state == ONE_MSG_ARGS) {
- OSC_errorMessage = "This packet is not a bundle, so you can't write another address";
- return 7;
- }
-
- if (buf->state == DONE) {
- OSC_errorMessage = "This packet is finished; can't write another address";
- return 8;
- }
-
- if (CheckTypeTag(buf, '\0')) return 9;
-
- paddedLength = OSC_effectiveStringLength(name);
-
- if (buf->state == EMPTY) {
- /* This will be a one-message packet, so no sizes to worry about */
- CheckOverflow(buf, paddedLength);
- buf->state = ONE_MSG_ARGS;
- } else {
- /* GET_ARGS or NEED_COUNT */
- CheckOverflow(buf, 4+paddedLength);
- if (buf->state == GET_ARGS) {
- /* Close the old message */
- PatchMessageSize(buf);
- }
- buf->thisMsgSize = (int4byte *)buf->bufptr;
- *(buf->thisMsgSize) = 0xbbbbbbbb;
- buf->bufptr += 4;
- buf->state = GET_ARGS;
- }
-
- /* Now write the name */
- buf->bufptr += OSC_padString(buf->bufptr, name);
- buf->typeStringPtr = 0;
- buf->gettingFirstUntypedArg = 1;
-
- return 0;
-}
-
-int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) {
- int result;
- int4byte paddedLength;
-
- if (CheckTypeTag(buf, '\0')) return 9;
-
- result = OSC_writeAddress(buf, name);
-
- if (result) return result;
-
- paddedLength = OSC_effectiveStringLength(types);
-
- CheckOverflow(buf, paddedLength);
-
- buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
- buf->bufptr += OSC_padString(buf->bufptr, types);
-
- buf->gettingFirstUntypedArg = 0;
- return 0;
-}
-
-static int CheckTypeTag(OSCbuf *buf, char expectedType) {
- if (buf->typeStringPtr) {
- if (*(buf->typeStringPtr) != expectedType) {
- if (expectedType == '\0') {
- OSC_errorMessage =
- "According to the type tag I expected more arguments.";
- } else if (*(buf->typeStringPtr) == '\0') {
- OSC_errorMessage =
- "According to the type tag I didn't expect any more arguments.";
- } else {
- OSC_errorMessage =
- "According to the type tag I expected an argument of a different type.";
- printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr);
- }
- return 9;
- }
- ++(buf->typeStringPtr);
- }
- return 0;
-}
-
-
-int OSC_writeFloatArg(OSCbuf *buf, float arg) {
- int4byte *intp;
- //int result;
-
- CheckOverflow(buf, 4);
-
- if (CheckTypeTag(buf, 'f')) return 9;
-
- /* Pretend arg is a long int so we can use htonl() */
- intp = ((int4byte *) &arg);
- *((int4byte *) buf->bufptr) = htonl(*intp);
-
- buf->bufptr += 4;
-
- buf->gettingFirstUntypedArg = 0;
- return 0;
-}
-
-
-
-int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args) {
- int i;
- int4byte *intp;
-
- CheckOverflow(buf, 4 * numFloats);
-
- /* Pretend args are long ints so we can use htonl() */
- intp = ((int4byte *) args);
-
- for (i = 0; i < numFloats; i++) {
- if (CheckTypeTag(buf, 'f')) return 9;
- *((int4byte *) buf->bufptr) = htonl(intp[i]);
- buf->bufptr += 4;
- }
-
- buf->gettingFirstUntypedArg = 0;
- return 0;
-}
-
-int OSC_writeIntArg(OSCbuf *buf, int4byte arg) {
- CheckOverflow(buf, 4);
- if (CheckTypeTag(buf, 'i')) return 9;
-
- *((int4byte *) buf->bufptr) = htonl(arg);
- buf->bufptr += 4;
-
- buf->gettingFirstUntypedArg = 0;
- return 0;
-}
-
-int OSC_writeStringArg(OSCbuf *buf, char *arg) {
- int len;
-
- if (CheckTypeTag(buf, 's')) return 9;
-
- len = OSC_effectiveStringLength(arg);
-
- if (buf->gettingFirstUntypedArg && arg[0] == ',') {
- /* This un-type-tagged message starts with a string
- that starts with a comma, so we have to escape it
- (with a double comma) so it won't look like a type
- tag string. */
-
- CheckOverflow(buf, len+4); /* Too conservative */
- buf->bufptr +=
- OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg);
-
- } else {
- CheckOverflow(buf, len);
- buf->bufptr += OSC_padString(buf->bufptr, arg);
- }
-
- buf->gettingFirstUntypedArg = 0;
- return 0;
-
-}
-
-/* String utilities */
-
-#define STRING_ALIGN_PAD 4
-int OSC_effectiveStringLength(char *string) {
- int len = strlen(string) + 1; /* We need space for the null char. */
-
- /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */
- if ((len % STRING_ALIGN_PAD) != 0) {
- len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD);
- }
- return len;
-}
-
-static int OSC_padString(char *dest, char *str) {
- int i;
-
- for (i = 0; str[i] != '\0'; i++) {
- dest[i] = str[i];
- }
-
- return OSC_WritePadding(dest, i);
-}
-
-static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) {
- int i;
-
- dest[0] = ',';
- for (i = 0; str[i] != '\0'; i++) {
- dest[i+1] = str[i];
- }
-
- return OSC_WritePadding(dest, i+1);
-}
-
-static int OSC_WritePadding(char *dest, int i) {
- dest[i] = '\0';
- i++;
-
- for (; (i % STRING_ALIGN_PAD) != 0; i++) {
- dest[i] = '\0';
- }
-
- return i;
-}
-
-
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 @@
-
-#ifndef SFORMAT_H__
-#define SFORMAT_H__
-
-typedef unsigned short uint16;
-typedef unsigned long uint32;
-
-#define FORMAT_WAVE 0
-#define FORMAT_AIFF 1
-#define FORMAT_NEXT 2
-
-/* the NeXTStep sound header structure; can be big or little endian */
-
-typedef struct _nextstep
-{
- char ns_fileid[4]; /* magic number '.snd' if file is big-endian */
- uint32 ns_onset; /* byte offset of first sample */
- uint32 ns_length; /* length of sound in bytes */
- uint32 ns_format; /* format; see below */
- uint32 ns_sr; /* sample rate */
- uint32 ns_nchans; /* number of channels */
- char ns_info[4]; /* comment */
-} t_nextstep;
-
-#define NS_FORMAT_LINEAR_16 3
-#define NS_FORMAT_LINEAR_24 4
-#define NS_FORMAT_FLOAT 6
-#define SCALE (1./(1024. * 1024. * 1024. * 2.))
-
-/* the WAVE header. All Wave files are little endian. We assume
- the "fmt" chunk comes first which is usually the case but perhaps not
- always; same for AIFF and the "COMM" chunk. */
-
-typedef unsigned word;
-typedef unsigned long dword;
-
-typedef struct _wave
-{
- char w_fileid[4]; /* chunk id 'RIFF' */
- uint32 w_chunksize; /* chunk size */
- char w_waveid[4]; /* wave chunk id 'WAVE' */
- char w_fmtid[4]; /* format chunk id 'fmt ' */
- uint32 w_fmtchunksize; /* format chunk size */
- uint16 w_fmttag; /* format tag, 1 for PCM */
- uint16 w_nchannels; /* number of channels */
- uint32 w_samplespersec; /* sample rate in hz */
- uint32 w_navgbytespersec; /* average bytes per second */
- uint16 w_nblockalign; /* number of bytes per sample */
- uint16 w_nbitspersample; /* number of bits in a sample */
- char w_datachunkid[4]; /* data chunk id 'data' */
- uint32 w_datachunksize; /* length of data chunk */
-} t_wave;
-
-
-#endif
-
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 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-#include "../src/m_pd.h"
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <sched.h>
-
-void sys_rmpollfn(int fd);
-void sys_addpollfn(int fd, void* fn, void *ptr);
-
-/* ------------------------ shell ----------------------------- */
-
-#define INBUFSIZE 1024
-
-static t_class *shell_class;
-
-
-static void drop_priority(void)
-{
-#ifdef _POSIX_PRIORITY_SCHEDULING
- struct sched_param par;
- int p1 ,p2, p3;
- par.sched_priority = 0;
- sched_setscheduler(0,SCHED_OTHER,&par);
-#endif
-}
-
-
-typedef struct _shell
-{
- t_object x_obj;
- int x_echo;
- char *sr_inbuf;
- int sr_inhead;
- int sr_intail;
- void* x_binbuf;
- int fdpipe[2];
- int fdinpipe[2];
- int pid;
- int x_del;
- t_outlet* x_done;
- t_clock* x_clock;
-} t_shell;
-
-static int shell_pid;
-
-
-void shell_cleanup(t_shell* x)
-{
- sys_rmpollfn(x->fdpipe[0]);
-
- if (x->fdpipe[0]>0) close(x->fdpipe[0]);
- if (x->fdpipe[1]>0) close(x->fdpipe[1]);
- if (x->fdinpipe[0]>0) close(x->fdinpipe[0]);
- if (x->fdinpipe[1]>0) close(x->fdinpipe[1]);
-
- x->fdpipe[0] = -1;
- x->fdpipe[1] = -1;
- x->fdinpipe[0] = -1;
- x->fdinpipe[1] = -1;
- clock_unset(x->x_clock);
-}
-
-void shell_check(t_shell* x)
-{
- int ret;
- int status;
- ret = waitpid(x->pid,&status,WNOHANG);
- if (ret == x->pid) {
- shell_cleanup(x);
- if (WIFEXITED(status)) {
- outlet_float(x->x_done,WEXITSTATUS(status));
- }
- else outlet_float(x->x_done,0);
- }
- else {
- if (x->x_del < 100) x->x_del+=2; /* increment poll times */
- clock_delay(x->x_clock,x->x_del);
- }
-}
-
-
-void shell_bang(t_shell *x)
-{
- post("bang");
-}
-
-/* snippet from pd's code */
-static void shell_doit(void *z, t_binbuf *b)
-{
- t_shell *x = (t_shell *)z;
- int msg, natom = binbuf_getnatom(b);
- t_atom *at = binbuf_getvec(b);
-
- for (msg = 0; msg < natom;)
- {
- int emsg;
- for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA
- && at[emsg].a_type != A_SEMI; emsg++)
- ;
- if (emsg > msg)
- {
- int i;
- for (i = msg; i < emsg; i++)
- if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM)
- {
- pd_error(x, "netreceive: got dollar sign in message");
- goto nodice;
- }
- if (at[msg].a_type == A_FLOAT)
- {
- if (emsg > msg + 1)
- outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg);
- else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float);
- }
- else if (at[msg].a_type == A_SYMBOL)
- outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol,
- emsg-msg-1, at + msg + 1);
- }
- nodice:
- msg = emsg + 1;
- }
-}
-
-
-void shell_read(t_shell *x, int fd)
-{
- char buf[INBUFSIZE];
- t_binbuf* bbuf = binbuf_new();
- int i;
- int readto =
- (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
- int ret;
-
- ret = read(fd, buf,INBUFSIZE-1);
- buf[ret] = '\0';
-
- for (i=0;i<ret;i++)
- if (buf[i] == '\n') buf[i] = ';';
- if (ret < 0)
- {
- error("shell: pipe read error");
- sys_rmpollfn(fd);
- x->fdpipe[0] = -1;
- close(fd);
- return;
- }
- else if (ret == 0)
- {
- post("EOF on socket %d\n", fd);
- sys_rmpollfn(fd);
- x->fdpipe[0] = -1;
- close(fd);
- return;
- }
- else
- {
- int natom;
- t_atom *at;
- binbuf_text(bbuf, buf, strlen(buf));
-
- natom = binbuf_getnatom(bbuf);
- at = binbuf_getvec(bbuf);
- shell_doit(x,bbuf);
- }
- binbuf_free(bbuf);
-}
-
-
-static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at)
-{
- int i;
- char tmp[MAXPDSTRING];
- int size = 0;
-
- if (x->fdinpipe[0] == -1) return; /* nothing to send to */
-
- for (i=0;i<ac;i++) {
- atom_string(at,tmp+size,MAXPDSTRING - size);
- at++;
- size=strlen(tmp);
- tmp[size++] = ' ';
- }
- tmp[size-1] = '\0';
- post("sending %s",tmp);
- write(x->fdinpipe[0],tmp,strlen(tmp));
-}
-
-static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at)
-{
- int i;
- char* argv[20];
- t_symbol* sym;
-
- if (!strcmp(s->s_name,"send")) {
- post("send");
- shell_send(x,s,ac,at);
- return;
- }
-
- argv[0] = s->s_name;
-
- if (x->fdpipe[0] != -1) {
- post("shell: old process still running");
- kill(x->pid,SIGKILL);
- shell_cleanup(x);
- }
-
-
- if (pipe(x->fdpipe) < 0) {
- error("unable to create pipe");
- return;
- }
-
- if (pipe(x->fdinpipe) < 0) {
- error("unable to create input pipe");
- return;
- }
-
-
- sys_addpollfn(x->fdpipe[0],shell_read,x);
-
- if (!(x->pid = fork())) {
- int status;
- char* cmd = getbytes(1024);
- char* tcmd = getbytes(1024);
- strcpy(cmd,s->s_name);
-
-#if 0
- for (i=1;i<=ac;i++) {
- argv[i] = getbytes(255);
- atom_string(at,argv[i],255);
-/* post("argument %s",argv[i]); */
- at++;
- }
- argv[i] = 0;
-#endif
- for (i=1;i<=ac;i++) {
- atom_string(at,tcmd,255);
- strcat(cmd," ");
- strcat(cmd,tcmd);
- at++;
- }
-
-
- /* reassign stdout */
- dup2(x->fdpipe[1],1);
- dup2(x->fdinpipe[1],0);
-
- /* drop privileges */
- drop_priority();
- seteuid(getuid()); /* lose setuid priveliges */
-
- post("executing %s",cmd);
- system(cmd);
-// execvp(s->s_name,argv);
- exit(0);
- }
- x->x_del = 4;
- clock_delay(x->x_clock,x->x_del);
-
- if (x->x_echo)
- outlet_anything(x->x_obj.ob_outlet, s, ac, at);
-}
-
-
-
-void shell_free(t_shell* x)
-{
- binbuf_free(x->x_binbuf);
-}
-
-static void *shell_new(void)
-{
- t_shell *x = (t_shell *)pd_new(shell_class);
-
- x->x_echo = 0;
- x->fdpipe[0] = -1;
- x->fdpipe[1] = -1;
- x->fdinpipe[0] = -1;
- x->fdinpipe[1] = -1;
-
- x->sr_inhead = x->sr_intail = 0;
- if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");;
-
- x->x_binbuf = binbuf_new();
-
- outlet_new(&x->x_obj, &s_list);
- x->x_done = outlet_new(&x->x_obj, &s_bang);
- x->x_clock = clock_new(x, (t_method) shell_check);
- return (x);
-}
-
-void shell_setup(void)
-{
- shell_class = class_new(gensym("shell"), (t_newmethod)shell_new,
- (t_method)shell_free,sizeof(t_shell), 0,0);
- class_addbang(shell_class,shell_bang);
- class_addanything(shell_class, shell_anything);
-}
-
-
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 @@
-#include <stdio.h>
-#include "../src/m_pd.h"
-#include "g_canvas.h" /* for widgetbehaviour */
-#include "fatom.h"
-
-static t_class *slider_class;
-
-static void slider_save(t_gobj *z, t_binbuf *b)
-{
- t_fatom *x = (t_fatom *)z;
-
- binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
- x->x_obj.te_xpix, x->x_obj.te_ypix ,
- gensym("slider"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
- binbuf_addv(b, ";");
-}
-
-
-static void *slider_new(t_symbol* s,t_int argc, t_atom* argv)
-{
- t_fatom *x = (t_fatom *)pd_new(slider_class);
- x->x_type = gensym("vslider");
- return fatom_new(x,argc,argv);
-}
-
-
-t_widgetbehavior slider_widgetbehavior;
-
-
-void slider_setup(void) {
- slider_class = class_new(gensym("slider"), (t_newmethod)slider_new, 0,
- sizeof(t_fatom),0,A_GIMME,0);
-
- slider_widgetbehavior.w_getrectfn = fatom_getrect;
- slider_widgetbehavior.w_displacefn = fatom_displace;
- slider_widgetbehavior.w_selectfn = fatom_select;
- slider_widgetbehavior.w_activatefn = fatom_activate;
- slider_widgetbehavior.w_deletefn = fatom_delete;
- slider_widgetbehavior.w_visfn= fatom_vis;
- slider_widgetbehavior.w_clickfn = NULL;
-
- fatom_setup_common(slider_class);
- class_setwidget(slider_class,&slider_widgetbehavior);
-
-#if PD_MINOR_VERSION < 37
- slider_widgetbehavior.w_savefn = slider_save;
- slider_widgetbehavior.w_propertiesfn = NULL;
-#else
- class_setsavefn(slider_class,&slider_save);
- class_setpropertiesfn(slider_class,&fatom_properties);
-#endif
-
-}
-
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 @@
-#include "../src/m_pd.h"
-#include "g_canvas.h"
-
-
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-#include "fatom.h"
-
-/* can we use the normal text save function ?? */
-
-static t_class *sliderh_class;
-
-static void sliderh_save(t_gobj *z, t_binbuf *b)
-{
-
- t_fatom *x = (t_fatom *)z;
-
- binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
- x->x_obj.te_xpix, x->x_obj.te_ypix ,
- gensym("sliderh"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
- binbuf_addv(b, ";");
-}
-
-
-static void *sliderh_new(t_symbol* s, int argc, t_atom* argv)
-{
- t_fatom *x = (t_fatom *)pd_new(sliderh_class);
- x->x_type = gensym("hslider");
- return fatom_new(x,argc,argv);
-}
-
-
-t_widgetbehavior sliderh_widgetbehavior;
-
-
-
-
-void sliderh_setup(void) {
- sliderh_class = class_new(gensym("sliderh"), (t_newmethod)sliderh_new, 0,
- sizeof(t_fatom),0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
-
- fatom_setup_common(sliderh_class);
-
- sliderh_widgetbehavior.w_getrectfn = fatom_getrect;
- sliderh_widgetbehavior.w_displacefn= fatom_displace;
- sliderh_widgetbehavior.w_selectfn= fatom_select;
- sliderh_widgetbehavior.w_activatefn=fatom_activate;
- sliderh_widgetbehavior.w_deletefn= fatom_delete;
- sliderh_widgetbehavior.w_visfn= fatom_vis;
-#if PD_MINOR_VERSION < 37
- sliderh_widgetbehavior.w_savefn= sliderh_save;
- sliderh_widgetbehavior.w_propertiesfn= NULL;
-#endif
- sliderh_widgetbehavior.w_clickfn= NULL;
-
- class_setwidget(sliderh_class,&sliderh_widgetbehavior);
-#if PD_MINOR_VERSION >= 37
- class_setsavefn(sliderh_class,&sliderh_save);
-#endif
-}
-
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 @@
-#N canvas 0 0 240 300 10;
-#X obj 57 84 clip~ -0.1 0.1;
-#X obj 58 61 sig~;
-#X obj 57 111 snapshot~;
-#X floatatom 58 19 5 0 0 0 - - -;
-#X floatatom 57 144 5 0 0 0 - - -;
-#X obj 58 37 t f b;
-#X connect 0 0 2 0;
-#X connect 1 0 0 0;
-#X connect 2 0 4 0;
-#X connect 3 0 5 0;
-#X connect 5 0 1 0;
-#X connect 5 1 2 0;
-
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 @@
-#N canvas 0 0 240 300 10;
-#X obj 38 93 noise~;
-#X obj 44 161 vcf~;
-#X obj 48 191 dac~;
-#X floatatom 138 33 5 0 0 0 - - -;
-#X obj 44 18 osc~ 1;
-#X obj 46 75 *~ 800;
-#X obj 48 48 +~ 2;
-#X obj 106 125 sig~;
-#X floatatom 132 77 5 0 0 0 - - -;
-#X connect 0 0 1 0;
-#X connect 1 0 2 0;
-#X connect 1 0 2 1;
-#X connect 3 0 1 2;
-#X connect 4 0 6 0;
-#X connect 6 0 5 0;
-#X connect 7 0 1 1;
-#X connect 8 0 7 0;
-
diff --git a/apps/plugins/pdbox/PDa/intern/sig~.c b/apps/plugins/pdbox/PDa/intern/sig~.c
deleted file mode 100644
index 1cff614f7c..0000000000
--- a/apps/plugins/pdbox/PDa/intern/sig~.c
+++ /dev/null
@@ -1,68 +0,0 @@
-#include "../src/m_pd.h"
-#include <../src/m_fixed.h>
-
-static t_class *sig_tilde_class;
-
-typedef struct _sig
-{
- t_object x_obj;
- t_sample x_f;
-} t_sig;
-
-static t_int *sig_tilde_perform(t_int *w)
-{
- t_sample f = *(t_sample *)(w[1]);
- t_sample *out = (t_sample *)(w[2]);
- int n = (int)(w[3]);
- while (n--)
- *out++ = f;
- return (w+4);
-}
-
-static t_int *sig_tilde_perf8(t_int *w)
-{
- t_sample f = *(t_sample *)(w[1]);
- t_sample *out = (t_sample *)(w[2]);
- int n = (int)(w[3]);
-
- for (; n; n -= 8, out += 8)
- {
- out[0] = f;
- out[1] = f;
- out[2] = f;
- out[3] = f;
- out[4] = f;
- out[5] = f;
- out[6] = f;
- out[7] = f;
- }
- return (w+4);
-}
-
-
-static void sig_tilde_float(t_sig *x, t_float f)
-{
- x->x_f = ftofix(f);
-}
-
-static void sig_tilde_dsp(t_sig *x, t_signal **sp)
-{
- dsp_add(sig_tilde_perform, 3, &x->x_f, sp[0]->s_vec, sp[0]->s_n);
-}
-
-static void *sig_tilde_new(t_floatarg f)
-{
- t_sig *x = (t_sig *)pd_new(sig_tilde_class);
- x->x_f = ftofix(f);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-void sig_tilde_setup(void)
-{
- sig_tilde_class = class_new(gensym("sig~"), (t_newmethod)sig_tilde_new, 0,
- sizeof(t_sig), 0, A_DEFFLOAT, 0);
- class_addfloat(sig_tilde_class, (t_method)sig_tilde_float);
- class_addmethod(sig_tilde_class, (t_method)sig_tilde_dsp, gensym("dsp"), 0);
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/build.ipod b/apps/plugins/pdbox/PDa/src/build.ipod
deleted file mode 100644
index 5d940bf56e..0000000000
--- a/apps/plugins/pdbox/PDa/src/build.ipod
+++ /dev/null
@@ -1,6 +0,0 @@
-
-# The compiler for iPod has a bug with -O6, thats why we try to compile twice
-
-make CFLAGS="-O6 -ffast-math -fexpensive-optimizations -mcpu=arm7tdmi " -k ipod
-make CFLAGS="-O2 -ffast-math -fexpensive-optimizations -mcpu=arm7tdmi" ipod
-
diff --git a/apps/plugins/pdbox/PDa/src/d_array.c b/apps/plugins/pdbox/PDa/src/d_array.c
deleted file mode 100644
index 7139e4dc3d..0000000000
--- a/apps/plugins/pdbox/PDa/src/d_array.c
+++ /dev/null
@@ -1,1074 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* sampling */
-
-/* LATER make tabread4 and tabread~ */
-
-#include "m_pd.h"
-
-
-/* ------------------------- tabwrite~ -------------------------- */
-
-static t_class *tabwrite_tilde_class;
-
-typedef struct _tabwrite_tilde
-{
- t_object x_obj;
- int x_phase;
- int x_nsampsintab;
- float *x_vec;
- t_symbol *x_arrayname;
- t_clock *x_clock;
- float x_f;
-} t_tabwrite_tilde;
-
-static void tabwrite_tilde_tick(t_tabwrite_tilde *x);
-
-static void *tabwrite_tilde_new(t_symbol *s)
-{
- t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class);
- x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick);
- x->x_phase = 0x7fffffff;
- x->x_arrayname = s;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tabwrite_tilde_perform(t_int *w)
-{
- t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
- if (!x->x_vec) goto bad;
-
- if (endphase > phase)
- {
- int nxfer = endphase - phase;
- float *fp = x->x_vec + phase;
- if (nxfer > n) nxfer = n;
- phase += nxfer;
- while (nxfer--)
- {
- float f = *in++;
- if (PD_BIGORSMALL(f))
- f = 0;
- *fp++ = f;
- }
- if (phase >= endphase)
- {
- clock_delay(x->x_clock, 0);
- phase = 0x7fffffff;
- }
- x->x_phase = phase;
- }
-bad:
- return (w+4);
-}
-
-void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
-{
- t_garray *a;
-
- x->x_arrayname = s;
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
- {
- pd_error(x, "%s: bad template for tabwrite~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else garray_usedindsp(a);
-}
-
-static void tabwrite_tilde_dsp(t_tabwrite_tilde *x, t_signal **sp)
-{
- tabwrite_tilde_set(x, x->x_arrayname);
- dsp_add(tabwrite_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
-}
-
-static void tabwrite_tilde_bang(t_tabwrite_tilde *x)
-{
- x->x_phase = 0;
-}
-
-static void tabwrite_tilde_stop(t_tabwrite_tilde *x)
-{
- if (x->x_phase != 0x7fffffff)
- {
- tabwrite_tilde_tick(x);
- x->x_phase = 0x7fffffff;
- }
-}
-
-static void tabwrite_tilde_tick(t_tabwrite_tilde *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabwrite_tilde_tick");
- else garray_redraw(a);
-}
-
-static void tabwrite_tilde_free(t_tabwrite_tilde *x)
-{
- clock_free(x->x_clock);
-}
-
-static void tabwrite_tilde_setup(void)
-{
- tabwrite_tilde_class = class_new(gensym("tabwrite~"),
- (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free,
- sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f);
- class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set,
- gensym("set"), A_SYMBOL, 0);
- class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop,
- gensym("stop"), 0);
- class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang);
-}
-
-/* ------------ tabplay~ - non-transposing sample playback --------------- */
-
-static t_class *tabplay_tilde_class;
-
-typedef struct _tabplay_tilde
-{
- t_object x_obj;
- t_outlet *x_bangout;
- int x_phase;
- int x_nsampsintab;
- int x_limit;
- float *x_vec;
- t_symbol *x_arrayname;
- t_clock *x_clock;
-} t_tabplay_tilde;
-
-static void tabplay_tilde_tick(t_tabplay_tilde *x);
-
-static void *tabplay_tilde_new(t_symbol *s)
-{
- t_tabplay_tilde *x = (t_tabplay_tilde *)pd_new(tabplay_tilde_class);
- x->x_clock = clock_new(x, (t_method)tabplay_tilde_tick);
- x->x_phase = 0x7fffffff;
- x->x_limit = 0;
- x->x_arrayname = s;
- outlet_new(&x->x_obj, &s_signal);
- x->x_bangout = outlet_new(&x->x_obj, &s_bang);
- return (x);
-}
-
-static t_int *tabplay_tilde_perform(t_int *w)
-{
- t_tabplay_tilde *x = (t_tabplay_tilde *)(w[1]);
- t_float *out = (t_float *)(w[2]), *fp;
- int n = (int)(w[3]), phase = x->x_phase,
- endphase = (x->x_nsampsintab < x->x_limit ?
- x->x_nsampsintab : x->x_limit), nxfer, n3;
- if (!x->x_vec || phase >= endphase)
- goto zero;
-
- nxfer = endphase - phase;
- fp = x->x_vec + phase;
- if (nxfer > n)
- nxfer = n;
- n3 = n - nxfer;
- phase += nxfer;
- while (nxfer--)
- *out++ = *fp++;
- if (phase >= endphase)
- {
- clock_delay(x->x_clock, 0);
- x->x_phase = 0x7fffffff;
- while (n3--)
- *out++ = 0;
- }
- else x->x_phase = phase;
-
- return (w+4);
-zero:
- while (n--) *out++ = 0;
- return (w+4);
-}
-
-void tabplay_tilde_set(t_tabplay_tilde *x, t_symbol *s)
-{
- t_garray *a;
-
- x->x_arrayname = s;
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*s->s_name) pd_error(x, "tabplay~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
- {
- pd_error(x, "%s: bad template for tabplay~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else garray_usedindsp(a);
-}
-
-static void tabplay_tilde_dsp(t_tabplay_tilde *x, t_signal **sp)
-{
- tabplay_tilde_set(x, x->x_arrayname);
- dsp_add(tabplay_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
-}
-
-static void tabplay_tilde_list(t_tabplay_tilde *x, t_symbol *s,
- int argc, t_atom *argv)
-{
- long start = atom_getfloatarg(0, argc, argv);
- long length = atom_getfloatarg(1, argc, argv);
- if (start < 0) start = 0;
- if (length <= 0)
- x->x_limit = 0x7fffffff;
- else
- x->x_limit = start + length;
- x->x_phase = start;
-}
-
-static void tabplay_tilde_stop(t_tabplay_tilde *x)
-{
- x->x_phase = 0x7fffffff;
-}
-
-static void tabplay_tilde_tick(t_tabplay_tilde *x)
-{
- outlet_bang(x->x_bangout);
-}
-
-static void tabplay_tilde_free(t_tabplay_tilde *x)
-{
- clock_free(x->x_clock);
-}
-
-static void tabplay_tilde_setup(void)
-{
- tabplay_tilde_class = class_new(gensym("tabplay~"),
- (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free,
- sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0);
- class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_stop,
- gensym("stop"), 0);
- class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_set,
- gensym("set"), A_DEFSYM, 0);
- class_addlist(tabplay_tilde_class, tabplay_tilde_list);
-}
-
-/******************** tabread~ ***********************/
-
-static t_class *tabread_tilde_class;
-
-typedef struct _tabread_tilde
-{
- t_object x_obj;
- int x_npoints;
- float *x_vec;
- t_symbol *x_arrayname;
- float x_f;
-} t_tabread_tilde;
-
-static void *tabread_tilde_new(t_symbol *s)
-{
- t_tabread_tilde *x = (t_tabread_tilde *)pd_new(tabread_tilde_class);
- x->x_arrayname = s;
- x->x_vec = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tabread_tilde_perform(t_int *w)
-{
- t_tabread_tilde *x = (t_tabread_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int maxindex;
- float *buf = x->x_vec, *fp;
- int i;
-
- maxindex = x->x_npoints - 1;
- if (!buf) goto zero;
-
- for (i = 0; i < n; i++)
- {
- int index = *in++;
- if (index < 0)
- index = 0;
- else if (index > maxindex)
- index = maxindex;
- *out++ = buf[index];
- }
- return (w+5);
- zero:
- while (n--) *out++ = 0;
-
- return (w+5);
-}
-
-void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s)
-{
- t_garray *a;
-
- x->x_arrayname = s;
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*s->s_name)
- pd_error(x, "tabread~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
- {
- pd_error(x, "%s: bad template for tabread~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else garray_usedindsp(a);
-}
-
-static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp)
-{
- tabread_tilde_set(x, x->x_arrayname);
-
- dsp_add(tabread_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-
-}
-
-static void tabread_tilde_free(t_tabread_tilde *x)
-{
-}
-
-static void tabread_tilde_setup(void)
-{
- tabread_tilde_class = class_new(gensym("tabread~"),
- (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free,
- sizeof(t_tabread_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f);
- class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set,
- gensym("set"), A_SYMBOL, 0);
-}
-
-/******************** tabread4~ ***********************/
-
-static t_class *tabread4_tilde_class;
-
-typedef struct _tabread4_tilde
-{
- t_object x_obj;
- int x_npoints;
- float *x_vec;
- t_symbol *x_arrayname;
- float x_f;
-} t_tabread4_tilde;
-
-static void *tabread4_tilde_new(t_symbol *s)
-{
- t_tabread4_tilde *x = (t_tabread4_tilde *)pd_new(tabread4_tilde_class);
- x->x_arrayname = s;
- x->x_vec = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tabread4_tilde_perform(t_int *w)
-{
- t_tabread4_tilde *x = (t_tabread4_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int maxindex;
- float *buf = x->x_vec, *fp;
- int i;
-
- maxindex = x->x_npoints - 3;
-
- if (!buf) goto zero;
-
-#if 0 /* test for spam -- I'm not ready to deal with this */
- for (i = 0, xmax = 0, xmin = maxindex, fp = in1; i < n; i++, fp++)
- {
- float f = *in1;
- if (f < xmin) xmin = f;
- else if (f > xmax) xmax = f;
- }
- if (xmax < xmin + x->c_maxextent) xmax = xmin + x->c_maxextent;
- for (i = 0, splitlo = xmin+ x->c_maxextent, splithi = xmax - x->c_maxextent,
- fp = in1; i < n; i++, fp++)
- {
- float f = *in1;
- if (f > splitlo && f < splithi) goto zero;
- }
-#endif
-
- for (i = 0; i < n; i++)
- {
- float findex = *in++;
- int index = findex;
- float frac, a, b, c, d, cminusb;
- static int count;
- if (index < 1)
- index = 1, frac = 0;
- else if (index > maxindex)
- index = maxindex, frac = 1;
- else frac = findex - index;
- fp = buf + index;
- a = fp[-1];
- b = fp[0];
- c = fp[1];
- d = fp[2];
- /* if (!i && !(count++ & 1023))
- post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
- }
- return (w+5);
- zero:
- while (n--) *out++ = 0;
-
- return (w+5);
-}
-
-void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s)
-{
- t_garray *a;
-
- x->x_arrayname = s;
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*s->s_name)
- pd_error(x, "tabread4~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
- {
- pd_error(x, "%s: bad template for tabread4~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else garray_usedindsp(a);
-}
-
-static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp)
-{
- tabread4_tilde_set(x, x->x_arrayname);
-
- dsp_add(tabread4_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-
-}
-
-static void tabread4_tilde_free(t_tabread4_tilde *x)
-{
-}
-
-static void tabread4_tilde_setup(void)
-{
- tabread4_tilde_class = class_new(gensym("tabread4~"),
- (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free,
- sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f);
- class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set,
- gensym("set"), A_SYMBOL, 0);
-}
-
-/******************** tabosc4~ ***********************/
-
-/* this is all copied from d_osc.c... what include file could this go in? */
-#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
-
- /* machine-dependent definitions. These ifdefs really
- should have been by CPU type and not by operating system! */
-#ifdef IRIX
- /* big-endian. Most significant byte is at low address in memory */
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#define int32 long /* a data type that has 32 bits */
-#else
-#ifdef MSW
- /* little-endian; most significant byte is at highest address */
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#define int32 long
-#else
-#ifdef __FreeBSD__
-#include <machine/endian.h>
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#else
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#endif /* BYTE_ORDER */
-#include <sys/types.h>
-#define int32 int32_t
-#endif
-
-#ifdef __linux__
-#include <endian.h>
-#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
-#error No byte order defined
-#endif
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#else
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#endif /* __BYTE_ORDER */
-
-#include <sys/types.h>
-#define int32 int32_t
-
-#else
-#ifdef MACOSX
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#define int32 int /* a data type that has 32 bits */
-
-#endif /* MACOSX */
-#endif /* __linux__ */
-#endif /* MSW */
-#endif /* SGI */
-
-union tabfudge
-{
- double tf_d;
- int32 tf_i[2];
-};
-
-static t_class *tabosc4_tilde_class;
-
-typedef struct _tabosc4_tilde
-{
- t_object x_obj;
- float x_fnpoints;
- float x_finvnpoints;
- float *x_vec;
- t_symbol *x_arrayname;
- float x_f;
- double x_phase;
- float x_conv;
-} t_tabosc4_tilde;
-
-static void *tabosc4_tilde_new(t_symbol *s)
-{
- t_tabosc4_tilde *x = (t_tabosc4_tilde *)pd_new(tabosc4_tilde_class);
- x->x_arrayname = s;
- x->x_vec = 0;
- x->x_fnpoints = 512.;
- x->x_finvnpoints = (1./512.);
- outlet_new(&x->x_obj, gensym("signal"));
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tabosc4_tilde_perform(t_int *w)
-{
- t_tabosc4_tilde *x = (t_tabosc4_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int normhipart;
- union tabfudge tf;
- float fnpoints = x->x_fnpoints;
- int mask = fnpoints - 1;
- float conv = fnpoints * x->x_conv;
- int maxindex;
- float *tab = x->x_vec, *addr;
- int i;
- double dphase = fnpoints * x->x_phase + UNITBIT32;
-
- if (!tab) goto zero;
- tf.tf_d = UNITBIT32;
- normhipart = tf.tf_i[HIOFFSET];
-
-#if 1
- while (n--)
- {
- float frac, a, b, c, d, cminusb;
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & mask);
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- a = addr[0];
- b = addr[1];
- c = addr[2];
- d = addr[3];
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
- }
-#endif
-
- tf.tf_d = UNITBIT32 * fnpoints;
- normhipart = tf.tf_i[HIOFFSET];
- tf.tf_d = dphase + (UNITBIT32 * fnpoints - UNITBIT32);
- tf.tf_i[HIOFFSET] = normhipart;
- x->x_phase = (tf.tf_d - UNITBIT32 * fnpoints) * x->x_finvnpoints;
- return (w+5);
- zero:
- while (n--) *out++ = 0;
-
- return (w+5);
-}
-
-void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s)
-{
- t_garray *a;
- int npoints, pointsinarray;
-
- x->x_arrayname = s;
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*s->s_name)
- pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec))
- {
- pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if ((npoints = pointsinarray - 3) != (1 << ilog2(pointsinarray - 3)))
- {
- pd_error(x, "%s: number of points (%d) not a power of 2 plus three",
- x->x_arrayname->s_name, pointsinarray);
- x->x_vec = 0;
- garray_usedindsp(a);
- }
- else
- {
- x->x_fnpoints = npoints;
- x->x_finvnpoints = 1./npoints;
- garray_usedindsp(a);
- }
-}
-
-static void tabosc4_tilde_ft1(t_tabosc4_tilde *x, t_float f)
-{
- x->x_phase = f;
-}
-
-static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp)
-{
- x->x_conv = 1. / sp[0]->s_sr;
- tabosc4_tilde_set(x, x->x_arrayname);
-
- dsp_add(tabosc4_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-static void tabosc4_tilde_setup(void)
-{
- tabosc4_tilde_class = class_new(gensym("tabosc4~"),
- (t_newmethod)tabosc4_tilde_new, 0,
- sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f);
- class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set,
- gensym("set"), A_SYMBOL, 0);
- class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1,
- gensym("ft1"), A_FLOAT, 0);
-}
-
-/* ------------------------ tabsend~ ------------------------- */
-
-static t_class *tabsend_class;
-
-typedef struct _tabsend
-{
- t_object x_obj;
- float *x_vec;
- int x_graphperiod;
- int x_graphcount;
- t_symbol *x_arrayname;
- t_clock *x_clock;
- float x_f;
-} t_tabsend;
-
-static void tabsend_tick(t_tabsend *x);
-
-static void *tabsend_new(t_symbol *s)
-{
- t_tabsend *x = (t_tabsend *)pd_new(tabsend_class);
- x->x_graphcount = 0;
- x->x_arrayname = s;
- x->x_clock = clock_new(x, (t_method)tabsend_tick);
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tabsend_perform(t_int *w)
-{
- t_tabsend *x = (t_tabsend *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- int n = w[3];
- t_float *dest = x->x_vec;
- int i = x->x_graphcount;
- if (!x->x_vec) goto bad;
-
- while (n--)
- {
- float f = *in++;
- if (PD_BIGORSMALL(f))
- f = 0;
- *dest++ = f;
- }
- if (!i--)
- {
- clock_delay(x->x_clock, 0);
- i = x->x_graphperiod;
- }
- x->x_graphcount = i;
-bad:
- return (w+4);
-}
-
-static void tabsend_dsp(t_tabsend *x, t_signal **sp)
-{
- int i, vecsize;
- t_garray *a;
-
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*x->x_arrayname->s_name)
- pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
- }
- else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
- pd_error(x, "%s: bad template for tabsend~", x->x_arrayname->s_name);
- else
- {
- int n = sp[0]->s_n;
- int ticksper = sp[0]->s_sr/n;
- if (ticksper < 1) ticksper = 1;
- x->x_graphperiod = ticksper;
- if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
- if (n < vecsize) vecsize = n;
- garray_usedindsp(a);
- dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize);
- }
-}
-
-static void tabsend_tick(t_tabsend *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabsend_tick");
- else garray_redraw(a);
-}
-
-static void tabsend_free(t_tabsend *x)
-{
- clock_free(x->x_clock);
-}
-
-static void tabsend_setup(void)
-{
- tabsend_class = class_new(gensym("tabsend~"), (t_newmethod)tabsend_new,
- (t_method)tabsend_free, sizeof(t_tabsend), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tabsend_class, t_tabsend, x_f);
- class_addmethod(tabsend_class, (t_method)tabsend_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------ tabreceive~ ------------------------- */
-
-static t_class *tabreceive_class;
-
-typedef struct _tabreceive
-{
- t_object x_obj;
- float *x_vec;
- t_symbol *x_arrayname;
-} t_tabreceive;
-
-static t_int *tabreceive_perform(t_int *w)
-{
- t_tabreceive *x = (t_tabreceive *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- int n = w[3];
- t_float *from = x->x_vec;
- if (from) while (n--) *out++ = *from++;
- else while (n--) *out++ = 0;
- return (w+4);
-}
-
-static void tabreceive_dsp(t_tabreceive *x, t_signal **sp)
-{
- t_garray *a;
- int vecsize;
-
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- {
- if (*x->x_arrayname->s_name)
- pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
- }
- else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
- pd_error(x, "%s: bad template for tabreceive~", x->x_arrayname->s_name);
- else
- {
- int n = sp[0]->s_n;
- if (n < vecsize) vecsize = n;
- garray_usedindsp(a);
- dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize);
- }
-}
-
-static void *tabreceive_new(t_symbol *s)
-{
- t_tabreceive *x = (t_tabreceive *)pd_new(tabreceive_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, &s_signal);
- return (x);
-}
-
-static void tabreceive_setup(void)
-{
- tabreceive_class = class_new(gensym("tabreceive~"),
- (t_newmethod)tabreceive_new, 0,
- sizeof(t_tabreceive), 0, A_DEFSYM, 0);
- class_addmethod(tabreceive_class, (t_method)tabreceive_dsp,
- gensym("dsp"), 0);
-}
-
-
-/* ---------- tabread: control, non-interpolating ------------------------ */
-
-static t_class *tabread_class;
-
-typedef struct _tabread
-{
- t_object x_obj;
- t_symbol *x_arrayname;
-} t_tabread;
-
-static void tabread_float(t_tabread *x, t_float f)
-{
- t_garray *a;
- int npoints;
- t_float *vec;
-
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
- else if (!garray_getfloatarray(a, &npoints, &vec))
- pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name);
- else
- {
- int n = f;
- if (n < 0) n = 0;
- else if (n >= npoints) n = npoints - 1;
- outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0));
- }
-}
-
-static void tabread_set(t_tabread *x, t_symbol *s)
-{
- x->x_arrayname = s;
-}
-
-static void *tabread_new(t_symbol *s)
-{
- t_tabread *x = (t_tabread *)pd_new(tabread_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-static void tabread_setup(void)
-{
- tabread_class = class_new(gensym("tabread"), (t_newmethod)tabread_new,
- 0, sizeof(t_tabread), 0, A_DEFSYM, 0);
- class_addfloat(tabread_class, (t_method)tabread_float);
- class_addmethod(tabread_class, (t_method)tabread_set, gensym("set"),
- A_SYMBOL, 0);
-}
-
-/* ---------- tabread4: control, non-interpolating ------------------------ */
-
-static t_class *tabread4_class;
-
-typedef struct _tabread4
-{
- t_object x_obj;
- t_symbol *x_arrayname;
-} t_tabread4;
-
-static void tabread4_float(t_tabread4 *x, t_float f)
-{
- t_garray *a;
- int npoints;
- t_float *vec;
-
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
- else if (!garray_getfloatarray(a, &npoints, &vec))
- pd_error(x, "%s: bad template for tabread4", x->x_arrayname->s_name);
- else if (npoints < 4)
- outlet_float(x->x_obj.ob_outlet, 0);
- else if (f <= 1)
- outlet_float(x->x_obj.ob_outlet, vec[1]);
- else if (f >= npoints - 2)
- outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]);
- else
- {
- int n = f;
- float a, b, c, d, cminusb, frac, *fp;
- if (n >= npoints - 2)
- n = npoints - 3;
- fp = vec + n;
- frac = f - n;
- a = fp[-1];
- b = fp[0];
- c = fp[1];
- d = fp[2];
- cminusb = c-b;
- outlet_float(x->x_obj.ob_outlet, b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b))));
- }
-}
-
-static void tabread4_set(t_tabread4 *x, t_symbol *s)
-{
- x->x_arrayname = s;
-}
-
-static void *tabread4_new(t_symbol *s)
-{
- t_tabread4 *x = (t_tabread4 *)pd_new(tabread4_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-static void tabread4_setup(void)
-{
- tabread4_class = class_new(gensym("tabread4"), (t_newmethod)tabread4_new,
- 0, sizeof(t_tabread4), 0, A_DEFSYM, 0);
- class_addfloat(tabread4_class, (t_method)tabread4_float);
- class_addmethod(tabread4_class, (t_method)tabread4_set, gensym("set"),
- A_SYMBOL, 0);
-}
-
-/* ------------------ tabwrite: control ------------------------ */
-
-static t_class *tabwrite_class;
-
-typedef struct _tabwrite
-{
- t_object x_obj;
- t_symbol *x_arrayname;
- t_clock *x_clock;
- float x_ft1;
- double x_updtime;
- int x_set;
-} t_tabwrite;
-
-static void tabwrite_tick(t_tabwrite *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabwrite_tick");
- else garray_redraw(a);
- x->x_set = 0;
- x->x_updtime = clock_getsystime();
-}
-
-static void tabwrite_float(t_tabwrite *x, t_float f)
-{
- int i, vecsize;
- t_garray *a;
- t_float *vec;
-
- if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
- else if (!garray_getfloatarray(a, &vecsize, &vec))
- pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name);
- else
- {
- int n = x->x_ft1;
- double timesince = clock_gettimesince(x->x_updtime);
- if (n < 0) n = 0;
- else if (n >= vecsize) n = vecsize-1;
- vec[n] = f;
- if (timesince > 1000)
- {
- tabwrite_tick(x);
- }
- else
- {
- if (x->x_set == 0)
- {
- clock_delay(x->x_clock, 1000 - timesince);
- x->x_set = 1;
- }
- }
- }
-}
-
-static void tabwrite_set(t_tabwrite *x, t_symbol *s)
-{
- x->x_arrayname = s;
-}
-
-static void tabwrite_free(t_tabwrite *x)
-{
- clock_free(x->x_clock);
-}
-
-static void *tabwrite_new(t_symbol *s)
-{
- t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class);
- x->x_ft1 = 0;
- x->x_arrayname = s;
- x->x_updtime = clock_getsystime();
- x->x_clock = clock_new(x, (t_method)tabwrite_tick);
- floatinlet_new(&x->x_obj, &x->x_ft1);
- return (x);
-}
-
-void tabwrite_setup(void)
-{
- tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new,
- (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0);
- class_addfloat(tabwrite_class, (t_method)tabwrite_float);
- class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0);
-}
-
-/* ------------------------ global setup routine ------------------------- */
-
-void d_array_setup(void)
-{
- tabwrite_tilde_setup();
- tabplay_tilde_setup();
- tabread_tilde_setup();
- tabread4_tilde_setup();
- tabosc4_tilde_setup();
- tabsend_setup();
- tabreceive_setup();
- tabread_setup();
- tabread4_setup();
- tabwrite_setup();
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/d_delay.c b/apps/plugins/pdbox/PDa/src/d_delay.c
deleted file mode 100644
index d04ded9e90..0000000000
--- a/apps/plugins/pdbox/PDa/src/d_delay.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* send~, delread~, throw~, catch~ */
-
-#include "m_pd.h"
-extern int ugen_getsortno(void);
-
-#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
-static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */
-
-/* ----------------------------- delwrite~ ----------------------------- */
-static t_class *sigdelwrite_class;
-
-typedef struct delwritectl
-{
- int c_n;
- float *c_vec;
- int c_phase;
-} t_delwritectl;
-
-typedef struct _sigdelwrite
-{
- t_object x_obj;
- t_symbol *x_sym;
- t_delwritectl x_cspace;
- int x_sortno; /* DSP sort number at which this was last put on chain */
- int x_rsortno; /* DSP sort # for first delread or write in chain */
- int x_vecsize; /* vector size for delread~ to use */
- float x_f;
-} t_sigdelwrite;
-
-#define XTRASAMPS 4
-#define SAMPBLK 4
-
- /* routine to check that all delwrites/delreads/vds have same vecsize */
-static void sigdelwrite_checkvecsize(t_sigdelwrite *x, int vecsize)
-{
- /*
- LATER this should really check sample rate and blocking, once that is
- supported. Probably we don't actually care about vecsize.
- For now just suppress this check... */
-#if 0
- if (x->x_rsortno != ugen_getsortno())
- {
- x->x_vecsize = vecsize;
- x->x_rsortno = ugen_getsortno();
- }
- else if (vecsize != x->x_vecsize)
- pd_error(x, "delread/delwrite/vd vector size mismatch");
-#endif
-}
-
-static void *sigdelwrite_new(t_symbol *s, t_floatarg msec)
-{
- int nsamps;
- t_sigdelwrite *x = (t_sigdelwrite *)pd_new(sigdelwrite_class);
- if (!*s->s_name) s = gensym("delwrite~");
- pd_bind(&x->x_obj.ob_pd, s);
- x->x_sym = s;
- nsamps = msec * sys_getsr() * (float)(0.001f);
- if (nsamps < 1) nsamps = 1;
- nsamps += ((- nsamps) & (SAMPBLK - 1));
- nsamps += DEFDELVS;
- x->x_cspace.c_n = nsamps;
- x->x_cspace.c_vec =
- (float *)getbytes((nsamps + XTRASAMPS) * sizeof(float));
- x->x_cspace.c_phase = XTRASAMPS;
- x->x_sortno = 0;
- x->x_vecsize = 0;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigdelwrite_perform(t_int *w)
-{
- t_float *in = (t_float *)(w[1]);
- t_delwritectl *c = (t_delwritectl *)(w[2]);
- int n = (int)(w[3]);
- int phase = c->c_phase, nsamps = c->c_n;
- float *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS);
- phase += n;
- while (n--)
- {
- float f = *in++;
- if (PD_BIGORSMALL(f))
- f = 0;
- *bp++ = f;
- if (bp == ep)
- {
- vp[0] = ep[-4];
- vp[1] = ep[-3];
- vp[2] = ep[-2];
- vp[3] = ep[-1];
- bp = vp + XTRASAMPS;
- phase -= nsamps;
- }
- }
- c->c_phase = phase;
- return (w+4);
-}
-
-static void sigdelwrite_dsp(t_sigdelwrite *x, t_signal **sp)
-{
- dsp_add(sigdelwrite_perform, 3, sp[0]->s_vec, &x->x_cspace, sp[0]->s_n);
- x->x_sortno = ugen_getsortno();
- sigdelwrite_checkvecsize(x, sp[0]->s_n);
-}
-
-static void sigdelwrite_free(t_sigdelwrite *x)
-{
- pd_unbind(&x->x_obj.ob_pd, x->x_sym);
- freebytes(x->x_cspace.c_vec,
- (x->x_cspace.c_n + XTRASAMPS) * sizeof(float));
-}
-
-static void sigdelwrite_setup(void)
-{
- sigdelwrite_class = class_new(gensym("delwrite~"),
- (t_newmethod)sigdelwrite_new, (t_method)sigdelwrite_free,
- sizeof(t_sigdelwrite), 0, A_DEFSYM, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(sigdelwrite_class, t_sigdelwrite, x_f);
- class_addmethod(sigdelwrite_class, (t_method)sigdelwrite_dsp,
- gensym("dsp"), 0);
-}
-
-/* ----------------------------- delread~ ----------------------------- */
-static t_class *sigdelread_class;
-
-typedef struct _sigdelread
-{
- t_object x_obj;
- t_symbol *x_sym;
- t_float x_deltime; /* delay in msec */
- int x_delsamps; /* delay in samples */
- t_float x_sr; /* samples per msec */
- t_float x_n; /* vector size */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
-} t_sigdelread;
-
-static void sigdelread_float(t_sigdelread *x, t_float f);
-
-static void *sigdelread_new(t_symbol *s, t_floatarg f)
-{
- t_sigdelread *x = (t_sigdelread *)pd_new(sigdelread_class);
- x->x_sym = s;
- x->x_sr = 1;
- x->x_n = 1;
- x->x_zerodel = 0;
- sigdelread_float(x, f);
- outlet_new(&x->x_obj, &s_signal);
- return (x);
-}
-
-static void sigdelread_float(t_sigdelread *x, t_float f)
-{
- int samps;
- t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
- x->x_deltime = f;
- if (delwriter)
- {
- int delsize = delwriter->x_cspace.c_n;
- x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime)
- + x->x_n - x->x_zerodel;
- if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n;
- else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS)
- x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS;
- }
-}
-
-static t_int *sigdelread_perform(t_int *w)
-{
- t_float *out = (t_float *)(w[1]);
- t_delwritectl *c = (t_delwritectl *)(w[2]);
- int delsamps = *(int *)(w[3]);
- int n = (int)(w[4]);
- int phase = c->c_phase - delsamps, nsamps = c->c_n;
- float *vp = c->c_vec, *bp, *ep = vp + (c->c_n + XTRASAMPS);
-
- if (phase < 0) phase += nsamps;
- bp = vp + phase;
- while (n--)
- {
- *out++ = *bp++;
- if (bp == ep) bp -= nsamps;
- }
- return (w+5);
-}
-
-static void sigdelread_dsp(t_sigdelread *x, t_signal **sp)
-{
- t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
- x->x_sr = sp[0]->s_sr * 0.001;
- x->x_n = sp[0]->s_n;
- if (delwriter)
- {
- sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- sigdelread_float(x, x->x_deltime);
- dsp_add(sigdelread_perform, 4,
- sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n);
- }
- else if (*x->x_sym->s_name)
- error("delread~: %s: no such delwrite~",x->x_sym->s_name);
-}
-
-static void sigdelread_setup(void)
-{
- sigdelread_class = class_new(gensym("delread~"),
- (t_newmethod)sigdelread_new, 0,
- sizeof(t_sigdelread), 0, A_DEFSYM, A_DEFFLOAT, 0);
- class_addmethod(sigdelread_class, (t_method)sigdelread_dsp,
- gensym("dsp"), 0);
- class_addfloat(sigdelread_class, (t_method)sigdelread_float);
-}
-
-
-/* ----------------------------- vd~ ----------------------------- */
-static t_class *sigvd_class;
-
-typedef struct _sigvd
-{
- t_object x_obj;
- t_symbol *x_sym;
- t_float x_sr; /* samples per msec */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
- float x_f;
-} t_sigvd;
-
-static void *sigvd_new(t_symbol *s)
-{
- t_sigvd *x = (t_sigvd *)pd_new(sigvd_class);
- if (!*s->s_name) s = gensym("vd~");
- x->x_sym = s;
- x->x_sr = 1;
- x->x_zerodel = 0;
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigvd_perform(t_int *w)
-{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_delwritectl *ctl = (t_delwritectl *)(w[3]);
- t_sigvd *x = (t_sigvd *)(w[4]);
- int n = (int)(w[5]);
-
- int nsamps = ctl->c_n;
- float limit = nsamps - n - 1;
- float fn = n-1;
- float *vp = ctl->c_vec, *bp, *wp = vp + ctl->c_phase;
- float zerodel = x->x_zerodel;
- while (n--)
- {
- float delsamps = x->x_sr * *in++ - zerodel, frac;
- int idelsamps;
- float a, b, c, d, cminusb;
- if (delsamps < 1.00001f) delsamps = 1.00001f;
- if (delsamps > limit) delsamps = limit;
- delsamps += fn;
- fn = fn - 1.0f;
- idelsamps = delsamps;
- frac = delsamps - (float)idelsamps;
- bp = wp - idelsamps;
- if (bp < vp + 4) bp += nsamps;
- d = bp[-3];
- c = bp[-2];
- b = bp[-1];
- a = bp[0];
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
- }
- return (w+6);
-}
-
-static void sigvd_dsp(t_sigvd *x, t_signal **sp)
-{
- t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
- x->x_sr = sp[0]->s_sr * 0.001;
- if (delwriter)
- {
- sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- dsp_add(sigvd_perform, 5,
- sp[0]->s_vec, sp[1]->s_vec,
- &delwriter->x_cspace, x, sp[0]->s_n);
- }
- else error("vd~: %s: no such delwrite~",x->x_sym->s_name);
-}
-
-static void sigvd_setup(void)
-{
- sigvd_class = class_new(gensym("vd~"), (t_newmethod)sigvd_new, 0,
- sizeof(t_sigvd), 0, A_DEFSYM, 0);
- class_addmethod(sigvd_class, (t_method)sigvd_dsp, gensym("dsp"), 0);
- CLASS_MAINSIGNALIN(sigvd_class, t_sigvd, x_f);
-}
-
-/* ----------------------- global setup routine ---------------- */
-
-void d_delay_setup(void)
-{
- sigdelwrite_setup();
- sigdelread_setup();
- sigvd_setup();
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/d_filter.c b/apps/plugins/pdbox/PDa/src/d_filter.c
deleted file mode 100644
index 8b81a3a0d3..0000000000
--- a/apps/plugins/pdbox/PDa/src/d_filter.c
+++ /dev/null
@@ -1,548 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* "filters", both linear and nonlinear.
-*/
-#include "m_pd.h"
-#include <math.h>
-
-/* ---------------- hip~ - 1-pole 1-zero hipass filter. ----------------- */
-
-typedef struct hipctl
-{
- float c_x;
- float c_coef;
-} t_hipctl;
-
-typedef struct sighip
-{
- t_object x_obj;
- float x_sr;
- float x_hz;
- t_hipctl x_cspace;
- t_hipctl *x_ctl;
- float x_f;
-} t_sighip;
-
-t_class *sighip_class;
-static void sighip_ft1(t_sighip *x, t_floatarg f);
-
-static void *sighip_new(t_floatarg f)
-{
- t_sighip *x = (t_sighip *)pd_new(sighip_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_sr = 44100;
- x->x_ctl = &x->x_cspace;
- x->x_cspace.c_x = 0;
- sighip_ft1(x, f);
- x->x_f = 0;
- return (x);
-}
-
-static void sighip_ft1(t_sighip *x, t_floatarg f)
-{
- if (f < 0) f = 0;
- x->x_hz = f;
- x->x_ctl->c_coef = 1 - f * (2 * 3.14159) / x->x_sr;
- if (x->x_ctl->c_coef < 0)
- x->x_ctl->c_coef = 0;
- else if (x->x_ctl->c_coef > 1)
- x->x_ctl->c_coef = 1;
-}
-
-static t_int *sighip_perform(t_int *w)
-{
- float *in = (float *)(w[1]);
- float *out = (float *)(w[2]);
- t_hipctl *c = (t_hipctl *)(w[3]);
- int n = (t_int)(w[4]);
- int i;
- float last = c->c_x;
- float coef = c->c_coef;
- if (coef < 1)
- {
- for (i = 0; i < n; i++)
- {
- float new = *in++ + coef * last;
- *out++ = new - last;
- last = new;
- }
- if (PD_BIGORSMALL(last))
- last = 0;
- c->c_x = last;
- }
- else
- {
- for (i = 0; i < n; i++)
- *out++ = *in++;
- c->c_x = 0;
- }
- return (w+5);
-}
-
-static void sighip_dsp(t_sighip *x, t_signal **sp)
-{
- x->x_sr = sp[0]->s_sr;
- sighip_ft1(x, x->x_hz);
- dsp_add(sighip_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
-
-}
-
-static void sighip_clear(t_sighip *x, t_floatarg q)
-{
- x->x_cspace.c_x = 0;
-}
-
-void sighip_setup(void)
-{
- sighip_class = class_new(gensym("hip~"), (t_newmethod)sighip_new, 0,
- sizeof(t_sighip), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(sighip_class, t_sighip, x_f);
- class_addmethod(sighip_class, (t_method)sighip_dsp, gensym("dsp"), 0);
- class_addmethod(sighip_class, (t_method)sighip_ft1,
- gensym("ft1"), A_FLOAT, 0);
- class_addmethod(sighip_class, (t_method)sighip_clear, gensym("clear"), 0);
-}
-
-/* ---------------- lop~ - 1-pole lopass filter. ----------------- */
-
-typedef struct lopctl
-{
- float c_x;
- float c_coef;
-} t_lopctl;
-
-typedef struct siglop
-{
- t_object x_obj;
- float x_sr;
- float x_hz;
- t_lopctl x_cspace;
- t_lopctl *x_ctl;
- float x_f;
-} t_siglop;
-
-t_class *siglop_class;
-
-static void siglop_ft1(t_siglop *x, t_floatarg f);
-
-static void *siglop_new(t_floatarg f)
-{
- t_siglop *x = (t_siglop *)pd_new(siglop_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_sr = 44100;
- x->x_ctl = &x->x_cspace;
- x->x_cspace.c_x = 0;
- siglop_ft1(x, f);
- x->x_f = 0;
- return (x);
-}
-
-static void siglop_ft1(t_siglop *x, t_floatarg f)
-{
- if (f < 0) f = 0;
- x->x_hz = f;
- x->x_ctl->c_coef = f * (2 * 3.14159) / x->x_sr;
- if (x->x_ctl->c_coef > 1)
- x->x_ctl->c_coef = 1;
- else if (x->x_ctl->c_coef < 0)
- x->x_ctl->c_coef = 0;
-}
-
-static void siglop_clear(t_siglop *x, t_floatarg q)
-{
- x->x_cspace.c_x = 0;
-}
-
-static t_int *siglop_perform(t_int *w)
-{
- float *in = (float *)(w[1]);
- float *out = (float *)(w[2]);
- t_lopctl *c = (t_lopctl *)(w[3]);
- int n = (t_int)(w[4]);
- int i;
- float last = c->c_x;
- float coef = c->c_coef;
- float feedback = 1 - coef;
- for (i = 0; i < n; i++)
- last = *out++ = coef * *in++ + feedback * last;
- if (PD_BIGORSMALL(last))
- last = 0;
- c->c_x = last;
- return (w+5);
-}
-
-static void siglop_dsp(t_siglop *x, t_signal **sp)
-{
- x->x_sr = sp[0]->s_sr;
- siglop_ft1(x, x->x_hz);
- dsp_add(siglop_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
-
-}
-
-void siglop_setup(void)
-{
- siglop_class = class_new(gensym("lop~"), (t_newmethod)siglop_new, 0,
- sizeof(t_siglop), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(siglop_class, t_siglop, x_f);
- class_addmethod(siglop_class, (t_method)siglop_dsp, gensym("dsp"), 0);
- class_addmethod(siglop_class, (t_method)siglop_ft1,
- gensym("ft1"), A_FLOAT, 0);
- class_addmethod(siglop_class, (t_method)siglop_clear, gensym("clear"), 0);
-}
-
-/* ---------------- bp~ - 2-pole bandpass filter. ----------------- */
-
-typedef struct bpctl
-{
- float c_x1;
- float c_x2;
- float c_coef1;
- float c_coef2;
- float c_gain;
-} t_bpctl;
-
-typedef struct sigbp
-{
- t_object x_obj;
- float x_sr;
- float x_freq;
- float x_q;
- t_bpctl x_cspace;
- t_bpctl *x_ctl;
- float x_f;
-} t_sigbp;
-
-t_class *sigbp_class;
-
-static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q);
-
-static void *sigbp_new(t_floatarg f, t_floatarg q)
-{
- t_sigbp *x = (t_sigbp *)pd_new(sigbp_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft2"));
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_sr = 44100;
- x->x_ctl = &x->x_cspace;
- x->x_cspace.c_x1 = 0;
- x->x_cspace.c_x2 = 0;
- sigbp_docoef(x, f, q);
- x->x_f = 0;
- return (x);
-}
-
-static float sigbp_qcos(float f)
-{
- if (f >= -(0.5f*3.14159f) && f <= 0.5f*3.14159f)
- {
- float g = f*f;
- return (((g*g*g * (-1.0f/720.0f) + g*g*(1.0f/24.0f)) - g*0.5) + 1);
- }
- else return (0);
-}
-
-static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q)
-{
- float r, oneminusr, omega;
- if (f < 0.001) f = 10;
- if (q < 0) q = 0;
- x->x_freq = f;
- x->x_q = q;
- omega = f * (2.0f * 3.14159f) / x->x_sr;
- if (q < 0.001) oneminusr = 1.0f;
- else oneminusr = omega/q;
- if (oneminusr > 1.0f) oneminusr = 1.0f;
- r = 1.0f - oneminusr;
- x->x_ctl->c_coef1 = 2.0f * sigbp_qcos(omega) * r;
- x->x_ctl->c_coef2 = - r * r;
- x->x_ctl->c_gain = 2 * oneminusr * (oneminusr + r * omega);
- /* post("r %f, omega %f, coef1 %f, coef2 %f",
- r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
-}
-
-static void sigbp_ft1(t_sigbp *x, t_floatarg f)
-{
- sigbp_docoef(x, f, x->x_q);
-}
-
-static void sigbp_ft2(t_sigbp *x, t_floatarg q)
-{
- sigbp_docoef(x, x->x_freq, q);
-}
-
-static void sigbp_clear(t_sigbp *x, t_floatarg q)
-{
- x->x_ctl->c_x1 = x->x_ctl->c_x2 = 0;
-}
-
-static t_int *sigbp_perform(t_int *w)
-{
- float *in = (float *)(w[1]);
- float *out = (float *)(w[2]);
- t_bpctl *c = (t_bpctl *)(w[3]);
- int n = (t_int)(w[4]);
- int i;
- float last = c->c_x1;
- float prev = c->c_x2;
- float coef1 = c->c_coef1;
- float coef2 = c->c_coef2;
- float gain = c->c_gain;
- for (i = 0; i < n; i++)
- {
- float output = *in++ + coef1 * last + coef2 * prev;
- *out++ = gain * output;
- prev = last;
- last = output;
- }
- if (PD_BIGORSMALL(last))
- last = 0;
- if (PD_BIGORSMALL(prev))
- prev = 0;
- c->c_x1 = last;
- c->c_x2 = prev;
- return (w+5);
-}
-
-static void sigbp_dsp(t_sigbp *x, t_signal **sp)
-{
- x->x_sr = sp[0]->s_sr;
- sigbp_docoef(x, x->x_freq, x->x_q);
- dsp_add(sigbp_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
-
-}
-
-void sigbp_setup(void)
-{
- sigbp_class = class_new(gensym("bp~"), (t_newmethod)sigbp_new, 0,
- sizeof(t_sigbp), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(sigbp_class, t_sigbp, x_f);
- class_addmethod(sigbp_class, (t_method)sigbp_dsp, gensym("dsp"), 0);
- class_addmethod(sigbp_class, (t_method)sigbp_ft1,
- gensym("ft1"), A_FLOAT, 0);
- class_addmethod(sigbp_class, (t_method)sigbp_ft2,
- gensym("ft2"), A_FLOAT, 0);
- class_addmethod(sigbp_class, (t_method)sigbp_clear, gensym("clear"), 0);
-}
-
-/* ---------------- biquad~ - raw biquad filter ----------------- */
-
-typedef struct biquadctl
-{
- float c_x1;
- float c_x2;
- float c_fb1;
- float c_fb2;
- float c_ff1;
- float c_ff2;
- float c_ff3;
-} t_biquadctl;
-
-typedef struct sigbiquad
-{
- t_object x_obj;
- float x_f;
- t_biquadctl x_cspace;
- t_biquadctl *x_ctl;
-} t_sigbiquad;
-
-t_class *sigbiquad_class;
-
-static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv);
-
-static void *sigbiquad_new(t_symbol *s, int argc, t_atom *argv)
-{
- t_sigbiquad *x = (t_sigbiquad *)pd_new(sigbiquad_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_ctl = &x->x_cspace;
- x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0;
- sigbiquad_list(x, s, argc, argv);
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigbiquad_perform(t_int *w)
-{
- float *in = (float *)(w[1]);
- float *out = (float *)(w[2]);
- t_biquadctl *c = (t_biquadctl *)(w[3]);
- int n = (t_int)(w[4]);
- int i;
- float last = c->c_x1;
- float prev = c->c_x2;
- float fb1 = c->c_fb1;
- float fb2 = c->c_fb2;
- float ff1 = c->c_ff1;
- float ff2 = c->c_ff2;
- float ff3 = c->c_ff3;
- for (i = 0; i < n; i++)
- {
- float output = *in++ + fb1 * last + fb2 * prev;
- if (PD_BIGORSMALL(output))
- output = 0;
- *out++ = ff1 * output + ff2 * last + ff3 * prev;
- prev = last;
- last = output;
- }
- c->c_x1 = last;
- c->c_x2 = prev;
- return (w+5);
-}
-
-static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
-{
- float fb1 = atom_getfloatarg(0, argc, argv);
- float fb2 = atom_getfloatarg(1, argc, argv);
- float ff1 = atom_getfloatarg(2, argc, argv);
- float ff2 = atom_getfloatarg(3, argc, argv);
- float ff3 = atom_getfloatarg(4, argc, argv);
- float discriminant = fb1 * fb1 + 4 * fb2;
- t_biquadctl *c = x->x_ctl;
- if (discriminant < 0) /* imaginary roots -- resonant filter */
- {
- /* they're conjugates so we just check that the product
- is less than one */
- if (fb2 >= -1.0f) goto stable;
- }
- else /* real roots */
- {
- /* check that the parabola 1 - fb1 x - fb2 x^2 has a
- vertex between -1 and 1, and that it's nonnegative
- at both ends, which implies both roots are in [1-,1]. */
- if (fb1 <= 2.0f && fb1 >= -2.0f &&
- 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
- goto stable;
- }
- /* if unstable, just bash to zero */
- fb1 = fb2 = ff1 = ff2 = ff3 = 0;
-stable:
- c->c_fb1 = fb1;
- c->c_fb2 = fb2;
- c->c_ff1 = ff1;
- c->c_ff2 = ff2;
- c->c_ff3 = ff3;
-}
-
-static void sigbiquad_set(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_biquadctl *c = x->x_ctl;
- c->c_x1 = atom_getfloatarg(0, argc, argv);
- c->c_x2 = atom_getfloatarg(1, argc, argv);
-}
-
-static void sigbiquad_dsp(t_sigbiquad *x, t_signal **sp)
-{
- dsp_add(sigbiquad_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
-
-}
-
-void sigbiquad_setup(void)
-{
- sigbiquad_class = class_new(gensym("biquad~"), (t_newmethod)sigbiquad_new,
- 0, sizeof(t_sigbiquad), 0, A_GIMME, 0);
- CLASS_MAINSIGNALIN(sigbiquad_class, t_sigbiquad, x_f);
- class_addmethod(sigbiquad_class, (t_method)sigbiquad_dsp, gensym("dsp"), 0);
- class_addlist(sigbiquad_class, sigbiquad_list);
- class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("set"),
- A_GIMME, 0);
- class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("clear"),
- A_GIMME, 0);
-}
-
-/* ---------------- samphold~ - sample and hold ----------------- */
-
-typedef struct sigsamphold
-{
- t_object x_obj;
- float x_f;
- float x_lastin;
- float x_lastout;
-} t_sigsamphold;
-
-t_class *sigsamphold_class;
-
-static void *sigsamphold_new(void)
-{
- t_sigsamphold *x = (t_sigsamphold *)pd_new(sigsamphold_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_lastin = 0;
- x->x_lastout = 0;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigsamphold_perform(t_int *w)
-{
- float *in1 = (float *)(w[1]);
- float *in2 = (float *)(w[2]);
- float *out = (float *)(w[3]);
- t_sigsamphold *x = (t_sigsamphold *)(w[4]);
- int n = (t_int)(w[5]);
- int i;
- float lastin = x->x_lastin;
- float lastout = x->x_lastout;
- for (i = 0; i < n; i++, *in1++)
- {
- float next = *in2++;
- if (next < lastin) lastout = *in1;
- *out++ = lastout;
- lastin = next;
- }
- x->x_lastin = lastin;
- x->x_lastout = lastout;
- return (w+6);
-}
-
-static void sigsamphold_dsp(t_sigsamphold *x, t_signal **sp)
-{
- dsp_add(sigsamphold_perform, 5,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
- x, sp[0]->s_n);
-}
-
-static void sigsamphold_reset(t_sigsamphold *x)
-{
- x->x_lastin = 1e20;
-}
-
-static void sigsamphold_set(t_sigsamphold *x, t_float f)
-{
- x->x_lastout = f;
-}
-
-void sigsamphold_setup(void)
-{
- sigsamphold_class = class_new(gensym("samphold~"),
- (t_newmethod)sigsamphold_new, 0, sizeof(t_sigsamphold), 0, 0);
- CLASS_MAINSIGNALIN(sigsamphold_class, t_sigsamphold, x_f);
- class_addmethod(sigsamphold_class, (t_method)sigsamphold_set,
- gensym("set"), A_FLOAT, 0);
- class_addmethod(sigsamphold_class, (t_method)sigsamphold_reset,
- gensym("reset"), 0);
- class_addmethod(sigsamphold_class, (t_method)sigsamphold_dsp,
- gensym("dsp"), 0);
-}
-
-/* ------------------------ setup routine ------------------------- */
-
-void d_filter_setup(void)
-{
- sighip_setup();
- siglop_setup();
- sigbp_setup();
- sigbiquad_setup();
- sigsamphold_setup();
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/d_math.c b/apps/plugins/pdbox/PDa/src/d_math.c
deleted file mode 100644
index d64e2e3483..0000000000
--- a/apps/plugins/pdbox/PDa/src/d_math.c
+++ /dev/null
@@ -1,573 +0,0 @@
-/* Copyright (c) 1997-2001 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* mathematical functions and other transfer functions, including tilde
- versions of stuff from x_acoustics.c.
-*/
-
-#include "m_pd.h"
-#include <math.h>
-#define LOGTEN 2.302585092994
-
-/* ------------------------- clip~ -------------------------- */
-static t_class *clip_class;
-
-typedef struct _clip
-{
- t_object x_obj;
- float x_f;
- t_sample x_lo;
- t_sample x_hi;
-} t_clip;
-
-static void *clip_new(t_floatarg lo, t_floatarg hi)
-{
- t_clip *x = (t_clip *)pd_new(clip_class);
- x->x_lo = lo;
- x->x_hi = hi;
- outlet_new(&x->x_obj, gensym("signal"));
- floatinlet_new(&x->x_obj, &x->x_lo);
- floatinlet_new(&x->x_obj, &x->x_hi);
- x->x_f = 0;
- return (x);
-}
-
-static t_int *clip_perform(t_int *w)
-{
- t_clip *x = (t_clip *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- while (n--)
- {
- float f = *in++;
- if (f < x->x_lo) f = x->x_lo;
- if (f > x->x_hi) f = x->x_hi;
- *out++ = f;
- }
- return (w+5);
-}
-
-static void clip_dsp(t_clip *x, t_signal **sp)
-{
- dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-static void clip_setup(void)
-{
- clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0,
- sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(clip_class, t_clip, x_f);
- class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0);
-}
-
-/* sigrsqrt - reciprocal square root good to 8 mantissa bits */
-
-#define DUMTAB1SIZE 256
-#define DUMTAB2SIZE 1024
-
-static float rsqrt_exptab[DUMTAB1SIZE], rsqrt_mantissatab[DUMTAB2SIZE];
-
-static void init_rsqrt(void)
-{
- int i;
- for (i = 0; i < DUMTAB1SIZE; i++)
- {
- float f;
- long l = (i ? (i == DUMTAB1SIZE-1 ? DUMTAB1SIZE-2 : i) : 1)<< 23;
- *(long *)(&f) = l;
- rsqrt_exptab[i] = 1./sqrt(f);
- }
- for (i = 0; i < DUMTAB2SIZE; i++)
- {
- float f = 1 + (1./DUMTAB2SIZE) * i;
- rsqrt_mantissatab[i] = 1./sqrt(f);
- }
-}
-
- /* these are used in externs like "bonk" */
-
-float q8_rsqrt(float f)
-{
- long l = *(long *)(&f);
- if (f < 0) return (0);
- else return (rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff]);
-}
-
-float q8_sqrt(float f)
-{
- long l = *(long *)(&f);
- if (f < 0) return (0);
- else return (f * rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff]);
-}
-
- /* the old names are OK unless we're in IRIX N32 */
-
-#ifndef N32
-float qsqrt(float f) {return (q8_sqrt(f)); }
-float qrsqrt(float f) {return (q8_rsqrt(f)); }
-#endif
-
-
-
-typedef struct sigrsqrt
-{
- t_object x_obj;
- float x_f;
-} t_sigrsqrt;
-
-static t_class *sigrsqrt_class;
-
-static void *sigrsqrt_new(void)
-{
- t_sigrsqrt *x = (t_sigrsqrt *)pd_new(sigrsqrt_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigrsqrt_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- while (n--)
- {
- float f = *in;
- long l = *(long *)(in++);
- if (f < 0) *out++ = 0;
- else
- {
- float g = rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff];
- *out++ = 1.5 * g - 0.5 * g * g * g * f;
- }
- }
- return (w + 4);
-}
-
-static void sigrsqrt_dsp(t_sigrsqrt *x, t_signal **sp)
-{
- dsp_add(sigrsqrt_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void sigrsqrt_setup(void)
-{
- init_rsqrt();
- sigrsqrt_class = class_new(gensym("rsqrt~"), (t_newmethod)sigrsqrt_new, 0,
- sizeof(t_sigrsqrt), 0, 0);
- /* an old name for it: */
- class_addcreator(sigrsqrt_new, gensym("q8_rsqrt~"), 0);
- CLASS_MAINSIGNALIN(sigrsqrt_class, t_sigrsqrt, x_f);
- class_addmethod(sigrsqrt_class, (t_method)sigrsqrt_dsp, gensym("dsp"), 0);
-}
-
-
-/* sigsqrt - square root good to 8 mantissa bits */
-
-typedef struct sigsqrt
-{
- t_object x_obj;
- float x_f;
-} t_sigsqrt;
-
-static t_class *sigsqrt_class;
-
-static void *sigsqrt_new(void)
-{
- t_sigsqrt *x = (t_sigsqrt *)pd_new(sigsqrt_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-t_int *sigsqrt_perform(t_int *w) /* not static; also used in d_fft.c */
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- while (n--)
- {
- float f = *in;
- long l = *(long *)(in++);
- if (f < 0) *out++ = 0;
- else
- {
- float g = rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff];
- *out++ = f * (1.5 * g - 0.5 * g * g * g * f);
- }
- }
- return (w + 4);
-}
-
-static void sigsqrt_dsp(t_sigsqrt *x, t_signal **sp)
-{
- dsp_add(sigsqrt_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void sigsqrt_setup(void)
-{
- sigsqrt_class = class_new(gensym("sqrt~"), (t_newmethod)sigsqrt_new, 0,
- sizeof(t_sigsqrt), 0, 0);
- class_addcreator(sigsqrt_new, gensym("q8_sqrt~"), 0); /* old name */
- CLASS_MAINSIGNALIN(sigsqrt_class, t_sigsqrt, x_f);
- class_addmethod(sigsqrt_class, (t_method)sigsqrt_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ wrap~ -------------------------- */
-
-typedef struct wrap
-{
- t_object x_obj;
- float x_f;
-} t_sigwrap;
-
-t_class *sigwrap_class;
-
-static void *sigwrap_new(void)
-{
- t_sigwrap *x = (t_sigwrap *)pd_new(sigwrap_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigwrap_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- while (n--)
- {
- float f = *in++;
- int k = f;
- if (f > 0) *out++ = f-k;
- else *out++ = f - (k-1);
- }
- return (w + 4);
-}
-
-static void sigwrap_dsp(t_sigwrap *x, t_signal **sp)
-{
- dsp_add(sigwrap_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void sigwrap_setup(void)
-{
- sigwrap_class = class_new(gensym("wrap~"), (t_newmethod)sigwrap_new, 0,
- sizeof(t_sigwrap), 0, 0);
- CLASS_MAINSIGNALIN(sigwrap_class, t_sigwrap, x_f);
- class_addmethod(sigwrap_class, (t_method)sigwrap_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ mtof_tilde~ -------------------------- */
-
-typedef struct mtof_tilde
-{
- t_object x_obj;
- float x_f;
-} t_mtof_tilde;
-
-t_class *mtof_tilde_class;
-
-static void *mtof_tilde_new(void)
-{
- t_mtof_tilde *x = (t_mtof_tilde *)pd_new(mtof_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *mtof_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; in++, out++)
- {
- float f = *in;
- if (f <= -1500) *out = 0;
- else
- {
- if (f > 1499) f = 1499;
- *out = 8.17579891564 * exp(.0577622650 * f);
- }
- }
- return (w + 4);
-}
-
-static void mtof_tilde_dsp(t_mtof_tilde *x, t_signal **sp)
-{
- dsp_add(mtof_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void mtof_tilde_setup(void)
-{
- mtof_tilde_class = class_new(gensym("mtof~"), (t_newmethod)mtof_tilde_new, 0,
- sizeof(t_mtof_tilde), 0, 0);
- CLASS_MAINSIGNALIN(mtof_tilde_class, t_mtof_tilde, x_f);
- class_addmethod(mtof_tilde_class, (t_method)mtof_tilde_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ ftom_tilde~ -------------------------- */
-
-typedef struct ftom_tilde
-{
- t_object x_obj;
- float x_f;
-} t_ftom_tilde;
-
-t_class *ftom_tilde_class;
-
-static void *ftom_tilde_new(void)
-{
- t_ftom_tilde *x = (t_ftom_tilde *)pd_new(ftom_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *ftom_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; *in++, out++)
- {
- float f = *in;
- *out = (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500);
- }
- return (w + 4);
-}
-
-static void ftom_tilde_dsp(t_ftom_tilde *x, t_signal **sp)
-{
- dsp_add(ftom_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void ftom_tilde_setup(void)
-{
- ftom_tilde_class = class_new(gensym("ftom~"), (t_newmethod)ftom_tilde_new, 0,
- sizeof(t_ftom_tilde), 0, 0);
- CLASS_MAINSIGNALIN(ftom_tilde_class, t_ftom_tilde, x_f);
- class_addmethod(ftom_tilde_class, (t_method)ftom_tilde_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ dbtorms~ -------------------------- */
-
-typedef struct dbtorms_tilde
-{
- t_object x_obj;
- float x_f;
-} t_dbtorms_tilde;
-
-t_class *dbtorms_tilde_class;
-
-static void *dbtorms_tilde_new(void)
-{
- t_dbtorms_tilde *x = (t_dbtorms_tilde *)pd_new(dbtorms_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *dbtorms_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; in++, out++)
- {
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- if (f > 485)
- f = 485;
- *out = exp((LOGTEN * 0.05) * (f-100.));
- }
- }
- return (w + 4);
-}
-
-static void dbtorms_tilde_dsp(t_dbtorms_tilde *x, t_signal **sp)
-{
- dsp_add(dbtorms_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void dbtorms_tilde_setup(void)
-{
- dbtorms_tilde_class = class_new(gensym("dbtorms~"), (t_newmethod)dbtorms_tilde_new, 0,
- sizeof(t_dbtorms_tilde), 0, 0);
- CLASS_MAINSIGNALIN(dbtorms_tilde_class, t_dbtorms_tilde, x_f);
- class_addmethod(dbtorms_tilde_class, (t_method)dbtorms_tilde_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ rmstodb~ -------------------------- */
-
-typedef struct rmstodb_tilde
-{
- t_object x_obj;
- float x_f;
-} t_rmstodb_tilde;
-
-t_class *rmstodb_tilde_class;
-
-static void *rmstodb_tilde_new(void)
-{
- t_rmstodb_tilde *x = (t_rmstodb_tilde *)pd_new(rmstodb_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *rmstodb_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; in++, out++)
- {
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- float g = 100 + 20./LOGTEN * log(f);
- *out = (g < 0 ? 0 : g);
- }
- }
- return (w + 4);
-}
-
-static void rmstodb_tilde_dsp(t_rmstodb_tilde *x, t_signal **sp)
-{
- dsp_add(rmstodb_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void rmstodb_tilde_setup(void)
-{
- rmstodb_tilde_class = class_new(gensym("rmstodb~"), (t_newmethod)rmstodb_tilde_new, 0,
- sizeof(t_rmstodb_tilde), 0, 0);
- CLASS_MAINSIGNALIN(rmstodb_tilde_class, t_rmstodb_tilde, x_f);
- class_addmethod(rmstodb_tilde_class, (t_method)rmstodb_tilde_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ dbtopow~ -------------------------- */
-
-typedef struct dbtopow_tilde
-{
- t_object x_obj;
- float x_f;
-} t_dbtopow_tilde;
-
-t_class *dbtopow_tilde_class;
-
-static void *dbtopow_tilde_new(void)
-{
- t_dbtopow_tilde *x = (t_dbtopow_tilde *)pd_new(dbtopow_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *dbtopow_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; in++, out++)
- {
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- if (f > 870)
- f = 870;
- *out = exp((LOGTEN * 0.1) * (f-100.));
- }
- }
- return (w + 4);
-}
-
-static void dbtopow_tilde_dsp(t_dbtopow_tilde *x, t_signal **sp)
-{
- dsp_add(dbtopow_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void dbtopow_tilde_setup(void)
-{
- dbtopow_tilde_class = class_new(gensym("dbtopow~"), (t_newmethod)dbtopow_tilde_new, 0,
- sizeof(t_dbtopow_tilde), 0, 0);
- CLASS_MAINSIGNALIN(dbtopow_tilde_class, t_dbtopow_tilde, x_f);
- class_addmethod(dbtopow_tilde_class, (t_method)dbtopow_tilde_dsp, gensym("dsp"), 0);
-}
-
-/* ------------------------------ powtodb~ -------------------------- */
-
-typedef struct powtodb_tilde
-{
- t_object x_obj;
- float x_f;
-} t_powtodb_tilde;
-
-t_class *powtodb_tilde_class;
-
-static void *powtodb_tilde_new(void)
-{
- t_powtodb_tilde *x = (t_powtodb_tilde *)pd_new(powtodb_tilde_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *powtodb_tilde_perform(t_int *w)
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- for (; n--; in++, out++)
- {
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- float g = 100 + 10./LOGTEN * log(f);
- *out = (g < 0 ? 0 : g);
- }
- }
- return (w + 4);
-}
-
-static void powtodb_tilde_dsp(t_powtodb_tilde *x, t_signal **sp)
-{
- dsp_add(powtodb_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void powtodb_tilde_setup(void)
-{
- powtodb_tilde_class = class_new(gensym("powtodb~"), (t_newmethod)powtodb_tilde_new, 0,
- sizeof(t_powtodb_tilde), 0, 0);
- CLASS_MAINSIGNALIN(powtodb_tilde_class, t_powtodb_tilde, x_f);
- class_addmethod(powtodb_tilde_class, (t_method)powtodb_tilde_dsp, gensym("dsp"), 0);
-}
-
-
-/* ------------------------ global setup routine ------------------------- */
-
-void d_math_setup(void)
-{
- t_symbol *s = gensym("acoustics~.pd");
- clip_setup();
- sigrsqrt_setup();
- sigsqrt_setup();
- sigwrap_setup();
- mtof_tilde_setup();
- ftom_tilde_setup();
- dbtorms_tilde_setup();
- rmstodb_tilde_setup();
- dbtopow_tilde_setup();
- powtodb_tilde_setup();
-
- class_sethelpsymbol(mtof_tilde_class, s);
- class_sethelpsymbol(ftom_tilde_class, s);
- class_sethelpsymbol(dbtorms_tilde_class, s);
- class_sethelpsymbol(rmstodb_tilde_class, s);
- class_sethelpsymbol(dbtopow_tilde_class, s);
- class_sethelpsymbol(powtodb_tilde_class, s);
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/d_osc.c b/apps/plugins/pdbox/PDa/src/d_osc.c
deleted file mode 100644
index 35b43b82c6..0000000000
--- a/apps/plugins/pdbox/PDa/src/d_osc.c
+++ /dev/null
@@ -1,535 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* sinusoidal oscillator and table lookup; see also tabosc4~ in d_array.c.
-*/
-
-#include "m_pd.h"
-#include "math.h"
-
-#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
-
- /* machine-dependent definitions. These ifdefs really
- should have been by CPU type and not by operating system! */
-#ifdef IRIX
- /* big-endian. Most significant byte is at low address in memory */
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#define int32 long /* a data type that has 32 bits */
-#else
-#ifdef MSW
- /* little-endian; most significant byte is at highest address */
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#define int32 long
-#else
-#ifdef __FreeBSD__
-#include <machine/endian.h>
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#else
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#endif /* BYTE_ORDER */
-#include <sys/types.h>
-#define int32 int32_t
-#endif
-#ifdef __linux__
-
-#include <endian.h>
-
-#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
-#error No byte order defined
-#endif
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define HIOFFSET 1
-#define LOWOFFSET 0
-#else
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#endif /* __BYTE_ORDER */
-
-#include <sys/types.h>
-#define int32 int32_t
-
-#else
-#ifdef MACOSX
-#define HIOFFSET 0 /* word offset to find MSB */
-#define LOWOFFSET 1 /* word offset to find LSB */
-#define int32 int /* a data type that has 32 bits */
-
-#endif /* MACOSX */
-#endif /* __linux__ */
-#endif /* MSW */
-#endif /* SGI */
-
-union tabfudge
-{
- double tf_d;
- int32 tf_i[2];
-};
-
-
-/* -------------------------- phasor~ ------------------------------ */
-static t_class *phasor_class, *scalarphasor_class;
-
-#if 1 /* in the style of R. Hoeldrich (ICMC 1995 Banff) */
-
-typedef struct _phasor
-{
- t_object x_obj;
- double x_phase;
- float x_conv;
- float x_f; /* scalar frequency */
-} t_phasor;
-
-static void *phasor_new(t_floatarg f)
-{
- t_phasor *x = (t_phasor *)pd_new(phasor_class);
- x->x_f = f;
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
- x->x_phase = 0;
- x->x_conv = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-static t_int *phasor_perform(t_int *w)
-{
- t_phasor *x = (t_phasor *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- double dphase = x->x_phase + UNITBIT32;
- union tabfudge tf;
- int normhipart;
- float conv = x->x_conv;
-
- tf.tf_d = UNITBIT32;
- normhipart = tf.tf_i[HIOFFSET];
- tf.tf_d = dphase;
-
- while (n--)
- {
- tf.tf_i[HIOFFSET] = normhipart;
- dphase += *in++ * conv;
- *out++ = tf.tf_d - UNITBIT32;
- tf.tf_d = dphase;
- }
- tf.tf_i[HIOFFSET] = normhipart;
- x->x_phase = tf.tf_d - UNITBIT32;
- return (w+5);
-}
-
-static void phasor_dsp(t_phasor *x, t_signal **sp)
-{
- x->x_conv = 1./sp[0]->s_sr;
- dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-static void phasor_ft1(t_phasor *x, t_float f)
-{
- x->x_phase = f;
-}
-
-static void phasor_setup(void)
-{
- phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
- sizeof(t_phasor), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
- class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
- class_addmethod(phasor_class, (t_method)phasor_ft1,
- gensym("ft1"), A_FLOAT, 0);
-}
-
-#endif /* Hoeldrich version */
-
-/* ------------------------ cos~ ----------------------------- */
-
-float *cos_table;
-
-static t_class *cos_class;
-
-typedef struct _cos
-{
- t_object x_obj;
- float x_f;
-} t_cos;
-
-static void *cos_new(void)
-{
- t_cos *x = (t_cos *)pd_new(cos_class);
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *cos_perform(t_int *w)
-{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- int n = (int)(w[3]);
- float *tab = cos_table, *addr, f1, f2, frac;
- double dphase;
- int normhipart;
- union tabfudge tf;
-
- tf.tf_d = UNITBIT32;
- normhipart = tf.tf_i[HIOFFSET];
-
-#if 0 /* this is the readable version of the code. */
- while (n--)
- {
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- tf.tf_d = dphase;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
- }
-#endif
-#if 1 /* this is the same, unwrapped by hand. */
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- tf.tf_d = dphase;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- while (--n)
- {
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- frac = tf.tf_d - UNITBIT32;
- tf.tf_d = dphase;
- f1 = addr[0];
- f2 = addr[1];
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- *out++ = f1 + frac * (f2 - f1);
- tf.tf_i[HIOFFSET] = normhipart;
- }
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
-#endif
- return (w+4);
-}
-
-static void cos_dsp(t_cos *x, t_signal **sp)
-{
- dsp_add(cos_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-static void cos_maketable(void)
-{
- int i;
- float *fp, phase, phsinc = (2. * 3.14159) / COSTABSIZE;
- union tabfudge tf;
-
- if (cos_table) return;
- cos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
- for (i = COSTABSIZE + 1, fp = cos_table, phase = 0; i--;
- fp++, phase += phsinc)
- *fp = cos(phase);
-
- /* here we check at startup whether the byte alignment
- is as we declared it. If not, the code has to be
- recompiled the other way. */
- tf.tf_d = UNITBIT32 + 0.5;
- if ((unsigned)tf.tf_i[LOWOFFSET] != 0x80000000)
- bug("cos~: unexpected machine alignment");
-}
-
-static void cos_setup(void)
-{
- cos_class = class_new(gensym("cos~"), (t_newmethod)cos_new, 0,
- sizeof(t_cos), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(cos_class, t_cos, x_f);
- class_addmethod(cos_class, (t_method)cos_dsp, gensym("dsp"), 0);
- cos_maketable();
-}
-
-/* ------------------------ osc~ ----------------------------- */
-
-static t_class *osc_class, *scalarosc_class;
-
-typedef struct _osc
-{
- t_object x_obj;
- double x_phase;
- float x_conv;
- float x_f; /* frequency if scalar */
-} t_osc;
-
-static void *osc_new(t_floatarg f)
-{
- t_osc *x = (t_osc *)pd_new(osc_class);
- x->x_f = f;
- outlet_new(&x->x_obj, gensym("signal"));
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
- x->x_phase = 0;
- x->x_conv = 0;
- return (x);
-}
-
-static t_int *osc_perform(t_int *w)
-{
- t_osc *x = (t_osc *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- float *tab = cos_table, *addr, f1, f2, frac;
- double dphase = x->x_phase + UNITBIT32;
- int normhipart;
- union tabfudge tf;
- float conv = x->x_conv;
-
- tf.tf_d = UNITBIT32;
- normhipart = tf.tf_i[HIOFFSET];
-#if 0
- while (n--)
- {
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
- }
-#endif
-#if 1
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- while (--n)
- {
- tf.tf_d = dphase;
- f1 = addr[0];
- dphase += *in++ * conv;
- f2 = addr[1];
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- *out++ = f1 + frac * (f2 - f1);
- frac = tf.tf_d - UNITBIT32;
- }
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
-#endif
-
- tf.tf_d = UNITBIT32 * COSTABSIZE;
- normhipart = tf.tf_i[HIOFFSET];
- tf.tf_d = dphase + (UNITBIT32 * COSTABSIZE - UNITBIT32);
- tf.tf_i[HIOFFSET] = normhipart;
- x->x_phase = tf.tf_d - UNITBIT32 * COSTABSIZE;
- return (w+5);
-}
-
-static void osc_dsp(t_osc *x, t_signal **sp)
-{
- x->x_conv = COSTABSIZE/sp[0]->s_sr;
- dsp_add(osc_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-static void osc_ft1(t_osc *x, t_float f)
-{
- x->x_phase = COSTABSIZE * f;
-}
-
-static void osc_setup(void)
-{
- osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0,
- sizeof(t_osc), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(osc_class, t_osc, x_f);
- class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0);
- class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0);
-
- cos_maketable();
-}
-
-/* ---------------- vcf~ - 2-pole bandpass filter. ----------------- */
-
-typedef struct vcfctl
-{
- float c_re;
- float c_im;
- float c_q;
- float c_isr;
-} t_vcfctl;
-
-typedef struct sigvcf
-{
- t_object x_obj;
- t_vcfctl x_cspace;
- t_vcfctl *x_ctl;
- float x_f;
-} t_sigvcf;
-
-t_class *sigvcf_class;
-
-static void *sigvcf_new(t_floatarg q)
-{
- t_sigvcf *x = (t_sigvcf *)pd_new(sigvcf_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- outlet_new(&x->x_obj, gensym("signal"));
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_ctl = &x->x_cspace;
- x->x_cspace.c_re = 0;
- x->x_cspace.c_im = 0;
- x->x_cspace.c_q = q;
- x->x_cspace.c_isr = 0;
- x->x_f = 0;
- return (x);
-}
-
-static void sigvcf_ft1(t_sigvcf *x, t_floatarg f)
-{
- x->x_ctl->c_q = (f > 0 ? f : 0.f);
-}
-
-static t_int *sigvcf_perform(t_int *w)
-{
- float *in1 = (float *)(w[1]);
- float *in2 = (float *)(w[2]);
- float *out1 = (float *)(w[3]);
- float *out2 = (float *)(w[4]);
- t_vcfctl *c = (t_vcfctl *)(w[5]);
- int n = (t_int)(w[6]);
- int i;
- float re = c->c_re, re2;
- float im = c->c_im;
- float q = c->c_q;
- float qinv = (q > 0? 1.0f/q : 0);
- float ampcorrect = 2.0f - 2.0f / (q + 2.0f);
- float isr = c->c_isr;
- float coefr, coefi;
- float *tab = cos_table, *addr, f1, f2, frac;
- double dphase;
- int normhipart, tabindex;
- union tabfudge tf;
-
- tf.tf_d = UNITBIT32;
- normhipart = tf.tf_i[HIOFFSET];
-
- for (i = 0; i < n; i++)
- {
- float cf, cfindx, r, oneminusr;
- cf = *in2++ * isr;
- if (cf < 0) cf = 0;
- cfindx = cf * (float)(COSTABSIZE/6.28318f);
- r = (qinv > 0 ? 1 - cf * qinv : 0);
- if (r < 0) r = 0;
- oneminusr = 1.0f - r;
- dphase = ((double)(cfindx)) + UNITBIT32;
- tf.tf_d = dphase;
- tabindex = tf.tf_i[HIOFFSET] & (COSTABSIZE-1);
- addr = tab + tabindex;
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- coefr = r * (f1 + frac * (f2 - f1));
-
- addr = tab + ((tabindex - (COSTABSIZE/4)) & (COSTABSIZE-1));
- f1 = addr[0];
- f2 = addr[1];
- coefi = r * (f1 + frac * (f2 - f1));
-
- f1 = *in1++;
- re2 = re;
- *out1++ = re = ampcorrect * oneminusr * f1
- + coefr * re2 - coefi * im;
- *out2++ = im = coefi * re2 + coefr * im;
- }
- if (PD_BIGORSMALL(re))
- re = 0;
- if (PD_BIGORSMALL(im))
- im = 0;
- c->c_re = re;
- c->c_im = im;
- return (w+7);
-}
-
-static void sigvcf_dsp(t_sigvcf *x, t_signal **sp)
-{
- x->x_ctl->c_isr = 6.28318f/sp[0]->s_sr;
- dsp_add(sigvcf_perform, 6,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
- x->x_ctl, sp[0]->s_n);
-
-}
-
-void sigvcf_setup(void)
-{
- sigvcf_class = class_new(gensym("vcf~"), (t_newmethod)sigvcf_new, 0,
- sizeof(t_sigvcf), 0, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(sigvcf_class, t_sigvcf, x_f);
- class_addmethod(sigvcf_class, (t_method)sigvcf_dsp, gensym("dsp"), 0);
- class_addmethod(sigvcf_class, (t_method)sigvcf_ft1,
- gensym("ft1"), A_FLOAT, 0);
-}
-
-/* -------------------------- noise~ ------------------------------ */
-static t_class *noise_class;
-
-typedef struct _noise
-{
- t_object x_obj;
- int x_val;
-} t_noise;
-
-static void *noise_new(void)
-{
- t_noise *x = (t_noise *)pd_new(noise_class);
- static int init = 307;
- x->x_val = (init *= 1319);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-static t_int *noise_perform(t_int *w)
-{
- t_float *out = (t_float *)(w[1]);
- int *vp = (int *)(w[2]);
- int n = (int)(w[3]);
- int val = *vp;
- while (n--)
- {
- *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) *
- (float)(1.0 / 0x40000000);
- val = val * 435898247 + 382842987;
- }
- *vp = val;
- return (w+4);
-}
-
-static void noise_dsp(t_noise *x, t_signal **sp)
-{
- dsp_add(noise_perform, 3, sp[0]->s_vec, &x->x_val, sp[0]->s_n);
-}
-
-static void noise_setup(void)
-{
- noise_class = class_new(gensym("noise~"), (t_newmethod)noise_new, 0,
- sizeof(t_noise), 0, 0);
- class_addmethod(noise_class, (t_method)noise_dsp, gensym("dsp"), 0);
-}
-
-
-/* ----------------------- global setup routine ---------------- */
-void d_osc_setup(void)
-{
- phasor_setup();
- cos_setup();
- osc_setup();
- sigvcf_setup();
- noise_setup();
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/delme.pd b/apps/plugins/pdbox/PDa/src/delme.pd
deleted file mode 100644
index 1d4b9fa031..0000000000
--- a/apps/plugins/pdbox/PDa/src/delme.pd
+++ /dev/null
@@ -1,9 +0,0 @@
-#N canvas 0 0 236 296 10;
-#X obj 79 77 gcanvas 80 80 0 0;
-#X floatatom 42 209 5 0 0 0 - - -;
-#X floatatom 107 205 5 0 0 0 - - -;
-#X floatatom 149 210 5 0 0 0 - - -;
-#X connect 0 0 1 0;
-#X connect 0 1 2 0;
-#X connect 0 2 3 0;
-
diff --git a/apps/plugins/pdbox/PDa/src/makefile b/apps/plugins/pdbox/PDa/src/makefile
deleted file mode 100644
index 3f074c4a74..0000000000
--- a/apps/plugins/pdbox/PDa/src/makefile
+++ /dev/null
@@ -1,176 +0,0 @@
-PREFIX = /usr/
-EXT = pd_linux
-
-# pd specific
-
-VPATH = ../obj:./
-OBJ_DIR = ../obj
-BIN_DIR = ../bin
-
-BROOT=/usr
-X11LIB = $(BROOT)/X11R6/lib
-
-DEFINES = -DPD -DUNIX
-
-pd-gui_INCLUDES = -I$(BROOT)/include/tcl8.4 -I$(BROOT)/X11R6/include
-pd-gui_LIBS = -ltk8.4 -ltcl8.4 -lX11 -ldl
-pd-gui_LDFLAGS = -L$(X11LIB)
-pd-gui_DEFINES = $(DEFINES)
-
-pd_LIBS = -lm -lpthread -ldl
-pd_LDFLAGS = -Wl,-export-dynamic
-pd_DEFINES = $(DEFINES) -DINSTALL_PREFIX=\"$(PREFIX)\" \
- -DFIXEDPOINT -DUSEAPI_OSS -DDL_OPEN
-
-extra_DEFINES = $(DEFINES) -DFIXEDPOINT
-extra_INCLUDES = -I../src
-extra_LDFLAGS = -shared
-
-# IPOD toolchain
-
-ifeq ($(CC), arm-elf-gcc)
-pd_LDFLAGS += -elf2flt
-pd_LIBS = -lm -lpthread
-pd_DEFINES = $(DEFINES) -DINSTALL_PREFIX=\"$(PREFIX)\" \
- -DFIXEDPOINT -DUSEAPI_OSS -D__linux__ -Dfork=getpid
-extra_DEFINES += -D__linux__ -Dfork=getpid
-endif
-
-# BLACKFIN toolchain
-
-ifeq ($(CC), bfin-uclinux-gcc)
-pd_LIBS = -lm -lpthread
-pd_DEFINES = $(DEFINES) -DINSTALL_PREFIX=\"$(PREFIX)\" \
- -DFIXEDPOINT -DUSEAPI_OSS -D__linux__
-extra_DEFINES += -D__linux__
-endif
-
-# the sources
-
-pd_SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \
- g_scalar.c g_traversal.c g_guiconnect.c g_readwrite.c g_editor.c \
- g_all_guis.c g_bang.c g_hdial.c g_hslider.c g_mycanvas.c g_numbox.c \
- g_toggle.c g_vdial.c g_vslider.c g_vumeter.c \
- m_pd.c m_class.c m_obj.c m_atom.c m_memory.c m_binbuf.c \
- m_conf.c m_glob.c m_sched.c \
- s_main.c s_inter.c s_file.c s_print.c \
- s_loader.c s_path.c s_entry.c s_audio.c s_midi.c \
- d_ugen.c d_arithmetic.c d_dac.c d_misc.c \
- d_fft.c d_mayer_fft.c d_fftroutine.c d_global.c \
- d_resample.c d_ctl.c d_soundfile.c \
- x_arithmetic.c x_connective.c x_interface.c x_midi.c x_misc.c \
- x_time.c x_acoustics.c x_net.c x_qlist.c x_gui.c \
- s_midi_oss.c s_audio_oss.c
-
-pd_SRC += d_imayer_fft.c m_fixed.c
-
-pd_OBJ = $(pd_SRC:.c=.o)
-
-pd-gui_SRC = t_main.c t_tkcmd.c
-pd-gui_OBJ = $(pd-gui_SRC:.c=.o)
-
-extra_SRC = $(shell ls ../intern/*.c) $(shell ls ../extra/*.c)
-extra_OBJ = $(extra_SRC:.c=.o)
-extra_EXT = $(extra_SRC:.c=.pd_linux)
-
-#
-# ------------------ targets ------------------------------------
-#
-
-all: $(BIN_DIR)/pd \
- $(BIN_DIR)/pd-gui \
- $(BIN_DIR)/pd-watchdog \
- $(BIN_DIR)/pdsend \
- $(BIN_DIR)/pdreceive \
- $(BIN_DIR)/pd.tk \
- extra
-
-pd: $(BIN_DIR)/pd
-pd-gui: $(BIN_DIR)/pd-gui
-pd-watchdog: $(BIN_DIR)/pd-watchdog
-
-static:
- make pd_SRC="$(pd_SRC) $(extra_SRC)" DEFINES="-DPD -DUNIX -DSTATIC" \
- pd pd-gui pd-watchdog $(BIN_DIR)/pdsend \
- $(BIN_DIR)/pdreceive $(BIN_DIR)/pd.tk
-
-extra: $(extra_EXT)
-
-ipod:
- make CC=arm-elf-gcc static
-
-blackfin:
- make CC=bfin-uclinux-gcc static
-
-$(pd_OBJ) : %.o : %.c
- $(CC) $(CFLAGS) $(pd_DEFINES) $(pd_INCLUDES) -c -o $(OBJ_DIR)/$@ $+
-
-$(pd-gui_OBJ) : %.o : %.c
- $(CC) $(CFLAGS) $(pd-gui_DEFINES) $(pd-gui_INCLUDES) -c -o $(OBJ_DIR)/$@ $+
-
-$(extra_OBJ) : %.o : %.c
- $(CC) $(CFLAGS) $(extra_DEFINES) $(extra_INCLUDES) -c -o $@ $*.c
-
-$(extra_EXT) : %.$(EXT) : %.o
- $(CC) -o $@ $(extra_LDFLAGS) $+
-
-$(BIN_DIR)/pd-watchdog: s_watchdog.c
- $(CC) $(CFLAGS) $(DEFINES) -o $@ s_watchdog.c
-
-$(BIN_DIR)/pdsend: u_pdsend.c
- $(CC) $(CFLAGS) $(DEFINES) -o $@ u_pdsend.c
-
-$(BIN_DIR)/pdreceive: u_pdreceive.c
- $(CC) $(CFLAGS) $(DEFINES) -o $@ u_pdreceive.c
-
-$(BIN_DIR)/pd: $(pd_OBJ)
- cd ../obj; $(CC) $(pd_LDFLAGS) -o $@ $(pd_OBJ) $(pd_LIBS)
-
-$(BIN_DIR)/pd-gui: $(pd-gui_OBJ)
- cd ../obj; $(CC) -o $@ $(pd-gui_OBJ) $(pd-gui_LDFLAGS) $(pd-gui_LIBS)
-
-$(BIN_DIR)/pd.tk: u_main.tk
- echo set pd_nt 0 > $(BIN_DIR)/pd.tk
- grep -v "set pd_nt" < u_main.tk >> $@
-
-INSTDIR = $(DESTDIR)/$(PREFIX)
-
-install: all
-# Create the directory structure
-
- install -d $(INSTDIR)/lib/pd/bin
- install -d $(INSTDIR)/lib/pd/extra
- install -d $(INSTDIR)/lib/pd/intern
- install -d $(INSTDIR)/lib/pd/doc
- install -d $(INSTDIR)/bin
- install -d $(INSTDIR)/include
-
- install $(BIN_DIR)/pd-gui $(INSTDIR)/lib/pd/bin/
- install $(BIN_DIR)/pd-watchdog $(INSTDIR)/lib/pd/bin/
- install -m 644 $(BIN_DIR)/pd.tk $(INSTDIR)/lib/pd/bin/
- install -m 755 $(BIN_DIR)/pd $(INSTDIR)/bin/
- install -m 755 $(BIN_DIR)/pdsend $(INSTDIR)/bin/pdsend
- install -m 755 $(BIN_DIR)/pdreceive $(INSTDIR)/bin/pdreceive
- cp -r ../doc/7.stuff $(INSTDIR)/lib/pd/doc
- cp -r ../doc/5.reference $(INSTDIR)/lib/pd/doc
- install -m 644 m_pd.h $(INSTDIR)/include/m_pd.h
-
-# Install the externals if possible
- cp ../extra/*.pd_linux $(INSTDIR)/lib/pd/extra
- cp ../intern/*.pd_linux $(INSTDIR)/lib/pd/intern
-
-# Install the ICON and desktop file
- install -d $(INSTDIR)/share/pixmaps
- install -d $(INSTDIR)/share/applications
- cp ../ipkg/pd-icon.png $(INSTDIR)/share/pixmaps
- cp ../ipkg/pd.desktop $(INSTDIR)/share/applications/
-
-
-
-clean:
- -rm -f `find ../extra/ -name "*.pd_*"`
- -rm -f tags
- -rm -f ../obj/* $(BIN_DIR)/* ../extra/*.{o,$(EXT)} ../intern/*.{o,$(EXT)}
- -rm -f *~
- -rm -f $(BIN_DIR)/pdsend $(BIN_DIR)/pdreceive
-
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_alsa.c b/apps/plugins/pdbox/PDa/src/s_audio_alsa.c
deleted file mode 100644
index b8e8535dc9..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_audio_alsa.c
+++ /dev/null
@@ -1,946 +0,0 @@
-/* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler,
-* Winfried Ritsch, Karl MacMillan, and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* this file inputs and outputs audio using the ALSA API available on linux. */
-
-#include <alsa/asoundlib.h>
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include <errno.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sched.h>
-#include <sys/mman.h>
-
-typedef int16_t t_alsa_sample16;
-typedef int32_t t_alsa_sample32;
-#define ALSA_SAMPLEWIDTH_16 sizeof(t_alsa_sample16)
-#define ALSA_SAMPLEWIDTH_32 sizeof(t_alsa_sample32)
-#define ALSA_XFERSIZE16 (signed int)(sizeof(t_alsa_sample16) * DEFDACBLKSIZE)
-#define ALSA_XFERSIZE32 (signed int)(sizeof(t_alsa_sample32) * DEFDACBLKSIZE)
-#define ALSA_MAXDEV 1
-#define ALSA_JITTER 1024
-#define ALSA_EXTRABUFFER 2048
-#define ALSA_DEFFRAGSIZE 64
-#define ALSA_DEFNFRAG 12
-
-#ifndef INT32_MAX
-#define INT32_MAX 0x7fffffff
-#endif
-
-#if (SND_LIB_MAJOR < 1)
-#define ALSAAPI9
-#endif
-
-typedef struct _alsa_dev
-{
- snd_pcm_t *inhandle;
- snd_pcm_t *outhandle;
- int innoninterleave; /* true if we're set for noninterleaved read */
- int outnoninterleave; /* same for write */
-} t_alsa_dev;
-
-t_alsa_dev alsa_device;
-static void *alsa_snd_buf = 0;
-static void **alsa_buf_ptrs;
-static int alsa_samplewidth;
-static snd_pcm_status_t* in_status;
-static snd_pcm_status_t* out_status;
-
-static int alsa_mode;
-static int alsa_buf_samps; /* believed actual ALSA bufsize in sample frames */
-static int alsa_inchannels;
-static int alsa_outchannels;
-
-/* Defines */
-#define DEBUG(x) x
-#define DEBUG2(x) {x;}
-
-static void alsa_checkiosync( void);
-static void alsa_numbertoname(int devno, char *devname, int nchar);
-
- /* don't assume we can turn all 31 bits when doing float-to-fix;
- otherwise some audio drivers (e.g. Midiman/ALSA) wrap around. */
-#define FMAX 0x7ffff000
-#define CLIP32(x) (((x)>FMAX)?FMAX:((x) < -FMAX)?-FMAX:(x))
-
-/* support for ALSA pcmv2 api by Karl MacMillan<karlmac@peabody.jhu.edu> */
-
-static void check_error(int err, const char *why)
-{
- if (err < 0)
- fprintf(stderr, "%s: %s\n", why, snd_strerror(err));
-}
-
-/* was: alsa_open_audio(int wantinchans, int wantoutchans, int srate) */
-
-int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
- int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
- int *choutdev, int rate)
-{
- int err, inchans = 0, outchans = 0, subunitdir;
- char devname[512];
- snd_pcm_hw_params_t* hw_params;
- snd_pcm_sw_params_t* sw_params;
- snd_output_t* out;
- int frag_size = (sys_blocksize ? sys_blocksize : ALSA_DEFFRAGSIZE);
- int nfrags, i;
- short* tmp_buf;
- unsigned int tmp_uint;
- snd_pcm_uframes_t tmp_snd_pcm_uframes;
- int wantinchans, wantoutchans, devno;
-
- if (naudioindev >= 2 || naudiooutdev >= 2)
- post("alsa: only one input and output device allowed (extras ignored");
- if (naudioindev >= 1 && naudiooutdev >= 1 &&
- audioindev[0] != audiooutdev[0])
- post("alsa: changing output device to agree with input device");
- if (nchindev)
- wantinchans = chindev[0];
- else wantinchans = (naudioindev ? 2 : 0);
- if (nchoutdev)
- wantoutchans = choutdev[0];
- else wantoutchans = (naudiooutdev ? 2 : 0);
- devno = (naudioindev > 0 ? audioindev[0] :
- (naudiooutdev > 0 ? audiooutdev[0] : 0));
-
- alsa_numbertoname(devno, devname, 512);
-
- if (sys_verbose)
- post("device name %s; channels in %d, out %d", devname, wantinchans,
- wantoutchans);
-
- nfrags = sys_schedadvance * (float)rate / (1e6 * frag_size);
- /* save our belief as to ALSA's buffer size for later */
- alsa_buf_samps = nfrags * frag_size;
-
- if (sys_verbose)
- post("audio buffer set to %d", (int)(0.001 * sys_schedadvance));
-
- alsa_device.innoninterleave = alsa_device.outnoninterleave = 0;
- if (wantinchans)
- {
- err = snd_pcm_open(&alsa_device.inhandle, devname,
- SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
-
- check_error(err, "snd_pcm_open (input)");
- if (err < 0)
- inchans = 0;
- else
- {
- inchans = wantinchans;
- snd_pcm_nonblock(alsa_device.inhandle, 1);
- }
- }
- if (wantoutchans)
- {
- err = snd_pcm_open(&alsa_device.outhandle, devname,
- SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
-
- check_error(err, "snd_pcm_open (output)");
- if (err < 0)
- outchans = 0;
- else
- {
- outchans = wantoutchans;
- snd_pcm_nonblock(alsa_device.outhandle, 1);
- }
- }
- if (inchans)
- {
- if (sys_verbose)
- post("opening sound input...");
- err = snd_pcm_hw_params_malloc(&hw_params);
- check_error(err, "snd_pcm_hw_params_malloc (input)");
-
- // get the default params
- err = snd_pcm_hw_params_any(alsa_device.inhandle, hw_params);
- check_error(err, "snd_pcm_hw_params_any (input)");
-
- /* try to set interleaved access */
- err = snd_pcm_hw_params_set_access(alsa_device.inhandle,
- hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
- if (err < 0)
- {
- /* OK, so try non-interleaved */
- err = snd_pcm_hw_params_set_access(alsa_device.inhandle,
- hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
- if (err >= 0)
- {
- post("using non-interleaved audio input");
- alsa_device.innoninterleave = 1;
- }
- }
- check_error(err, "snd_pcm_hw_params_set_access (input)");
- // Try to set 32 bit format first
- err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params,
- SND_PCM_FORMAT_S32);
- if (err < 0)
- {
- /* fprintf(stderr,
- "PD-ALSA: 32 bit format not available - using 16\n"); */
- err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params,
- SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format (input)");
- alsa_samplewidth = 2;
- }
- else
- {
- alsa_samplewidth = 4;
- }
- post("Sample width set to %d bytes", alsa_samplewidth);
- // set the subformat
- err = snd_pcm_hw_params_set_subformat(alsa_device.inhandle, hw_params,
- SND_PCM_SUBFORMAT_STD);
- check_error(err, "snd_pcm_hw_params_set_subformat (input)");
- // set the number of channels
- tmp_uint = inchans;
- err = snd_pcm_hw_params_set_channels_min(alsa_device.inhandle,
- hw_params, &tmp_uint);
- check_error(err, "snd_pcm_hw_params_set_channels (input)");
- if (tmp_uint != (unsigned)inchans)
- post("ALSA: set input channels to %d", tmp_uint);
- inchans = tmp_uint;
- // set the sampling rate
- err = snd_pcm_hw_params_set_rate_min(alsa_device.inhandle, hw_params,
- &rate, 0);
- check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
-#if 0
- err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
- post("input sample rate %d", err);
-#endif
- // set the period - ie frag size
- // post("fragsize a %d", frag_size);
-
- /* LATER try this to get a recommended period size...
- right now, it trips an assertion failure in ALSA lib */
-#if 0
- post("input period was %d, min %d, max %d\n",
- snd_pcm_hw_params_get_period_size(hw_params, 0),
- snd_pcm_hw_params_get_period_size_min(hw_params, 0),
- snd_pcm_hw_params_get_period_size_max(hw_params, 0));
-#endif
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle,
- hw_params,
- (snd_pcm_uframes_t)
- frag_size, 0);
-#else
- tmp_snd_pcm_uframes = frag_size;
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle,
- hw_params, &tmp_snd_pcm_uframes, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
- // post("fragsize b %d", frag_size);
- // set the number of periods - ie numfrags
- // post("nfrags a %d", nfrags);
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle,
- hw_params, nfrags, 0);
-#else
- tmp_uint = nfrags;
- err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle,
- hw_params, &tmp_uint, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_periods_near (input)");
- // set the buffer size
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle,
- hw_params, nfrags * frag_size);
-#else
- tmp_snd_pcm_uframes = nfrags * frag_size;
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle,
- hw_params, &tmp_snd_pcm_uframes);
-#endif
- check_error(err, "snd_pcm_hw_params_set_buffer_size_near (input)");
-
- err = snd_pcm_hw_params(alsa_device.inhandle, hw_params);
- check_error(err, "snd_pcm_hw_params (input)");
-
- snd_pcm_hw_params_free(hw_params);
-
- err = snd_pcm_sw_params_malloc(&sw_params);
- check_error(err, "snd_pcm_sw_params_malloc (input)");
- err = snd_pcm_sw_params_current(alsa_device.inhandle, sw_params);
- check_error(err, "snd_pcm_sw_params_current (input)");
- err = snd_pcm_sw_params_set_start_threshold(alsa_device.inhandle,
- sw_params, nfrags * frag_size);
- check_error(err, "snd_pcm_sw_params_set_start_threshold (input)");
- err = snd_pcm_sw_params_set_stop_threshold(alsa_device.inhandle,
- sw_params, 0x7fffffff);
- check_error(err, "snd_pcm_sw_params_set_stop_threshold (input)");
- err = snd_pcm_sw_params_set_avail_min(alsa_device.inhandle, sw_params,
- frag_size);
- check_error(err, "snd_pcm_sw_params_set_avail_min (input)");
- err = snd_pcm_sw_params(alsa_device.inhandle, sw_params);
- check_error(err, "snd_pcm_sw_params (input)");
-
- snd_pcm_sw_params_free(sw_params);
-
- snd_output_stdio_attach(&out, stderr, 0);
-#if 0
- if (sys_verbose)
- {
- snd_pcm_dump_hw_setup(alsa_device.inhandle, out);
- snd_pcm_dump_sw_setup(alsa_device.inhandle, out);
- }
-#endif
- }
-
- if (outchans)
- {
- int foo;
- if (sys_verbose)
- post("opening sound output...");
- err = snd_pcm_hw_params_malloc(&hw_params);
- check_error(err, "snd_pcm_sw_params (output)");
-
- // get the default params
- err = snd_pcm_hw_params_any(alsa_device.outhandle, hw_params);
- check_error(err, "snd_pcm_hw_params_any (output)");
- // set interleaved access - FIXME deal with other access types
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle, hw_params,
- SND_PCM_ACCESS_RW_INTERLEAVED);
- check_error(err, "snd_pcm_hw_params_set_access (output)");
-
- /* try to set interleaved access */
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle,
- hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
- if (err < 0)
- {
- /* OK, so try non-interleaved */
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle,
- hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
- if (err >= 0)
- {
- post("using non-interleaved audio");
- alsa_device.outnoninterleave = 1;
- }
- }
- check_error(err, "snd_pcm_hw_params_set_access (output)");
-
-
- // Try to set 32 bit format first
- err = snd_pcm_hw_params_set_format(alsa_device.outhandle, hw_params,
- SND_PCM_FORMAT_S32);
- if (err < 0)
- {
- err = snd_pcm_hw_params_set_format(alsa_device.outhandle,
- hw_params,SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format (output)");
- /* fprintf(stderr,
- "PD-ALSA: 32 bit format not available - using 16\n"); */
- alsa_samplewidth = 2;
- }
- else
- {
- alsa_samplewidth = 4;
- }
- // set the subformat
- err = snd_pcm_hw_params_set_subformat(alsa_device.outhandle, hw_params,
- SND_PCM_SUBFORMAT_STD);
- check_error(err, "snd_pcm_hw_params_set_subformat (output)");
- // set the number of channels
- tmp_uint = outchans;
- err = snd_pcm_hw_params_set_channels_min(alsa_device.outhandle,
- hw_params, &tmp_uint);
- check_error(err, "snd_pcm_hw_params_set_channels (output)");
- if (tmp_uint != (unsigned)outchans)
- post("alsa: set output channels to %d", tmp_uint);
- outchans = tmp_uint;
- // set the sampling rate
- err = snd_pcm_hw_params_set_rate_min(alsa_device.outhandle, hw_params,
- &rate, 0);
- check_error(err, "snd_pcm_hw_params_set_rate_min (output)");
-#if 0
- err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
- post("output sample rate %d", err);
-#endif
- // set the period - ie frag size
-#if 0
- post("output period was %d, min %d, max %d\n",
- snd_pcm_hw_params_get_period_size(hw_params, 0),
- snd_pcm_hw_params_get_period_size_min(hw_params, 0),
- snd_pcm_hw_params_get_period_size_max(hw_params, 0));
-#endif
- // post("fragsize c %d", frag_size);
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle,
- hw_params,
- (snd_pcm_uframes_t)
- frag_size, 0);
-#else
- tmp_snd_pcm_uframes = frag_size;
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle,
- hw_params, &tmp_snd_pcm_uframes, 0);
-#endif
- // post("fragsize d %d", frag_size);
- check_error(err, "snd_pcm_hw_params_set_period_size_near (output)");
- // set the number of periods - ie numfrags
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle,
- hw_params, nfrags, 0);
-#else
- tmp_uint = nfrags;
- err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle,
- hw_params, &tmp_uint, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_periods_near (output)");
- // set the buffer size
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle,
- hw_params, nfrags * frag_size);
-#else
- tmp_snd_pcm_uframes = nfrags * frag_size;
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle,
- hw_params, &tmp_snd_pcm_uframes);
-#endif
- check_error(err, "snd_pcm_hw_params_set_buffer_size_near (output)");
-
- err = snd_pcm_hw_params(alsa_device.outhandle, hw_params);
- check_error(err, "snd_pcm_hw_params (output)");
-
- snd_pcm_hw_params_free(hw_params);
-
- err = snd_pcm_sw_params_malloc(&sw_params);
- check_error(err, "snd_pcm_sw_params_malloc (output)");
- err = snd_pcm_sw_params_current(alsa_device.outhandle, sw_params);
- check_error(err, "snd_pcm_sw_params_current (output)");
- err = snd_pcm_sw_params_set_start_threshold(alsa_device.outhandle,
- sw_params, nfrags * frag_size);
- check_error(err, "snd_pcm_sw_params_set_start_threshold (output)");
- err = snd_pcm_sw_params_set_stop_threshold(alsa_device.outhandle,
- sw_params, 0x7fffffff);
- check_error(err, "snd_pcm_sw_params_set_stop_threshold (output)");
- err = snd_pcm_sw_params_set_avail_min(alsa_device.outhandle, sw_params,
- frag_size);
- check_error(err, "snd_pcm_sw_params_set_avail_min (output)");
- err = snd_pcm_sw_params(alsa_device.outhandle, sw_params);
- check_error(err, "snd_pcm_sw_params (output)");
- snd_pcm_sw_params_free(sw_params);
-
- snd_output_stdio_attach(&out, stderr, 0);
-#if 0
- if (sys_verbose)
- {
- snd_pcm_dump_hw_setup(alsa_device.outhandle, out);
- snd_pcm_dump_sw_setup(alsa_device.outhandle, out);
- }
-#endif
- }
-
- if (inchans)
- snd_pcm_prepare(alsa_device.inhandle);
- if (outchans)
- snd_pcm_prepare(alsa_device.outhandle);
-
- // if duplex we can link the channels so they start together
- if (inchans && outchans)
- snd_pcm_link(alsa_device.inhandle, alsa_device.outhandle);
-
- // set up the status variables
- err = snd_pcm_status_malloc(&in_status);
- check_error(err, "snd_pcm_status_malloc");
- err = snd_pcm_status_malloc(&out_status);
- check_error(err, "snd_pcm_status_malloc");
-
- // set up the buffer
- if (alsa_snd_buf)
- free(alsa_snd_buf);
- alsa_snd_buf = (void *)malloc(
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE *
- (outchans > inchans ? outchans : inchans));
- memset(alsa_snd_buf, 0, sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE *
- (outchans > inchans ? outchans : inchans));
- /* make an array of pointers too in case we need them */
- if (alsa_buf_ptrs)
- free(alsa_buf_ptrs);
- alsa_buf_ptrs = (void **)malloc(
- sizeof(void *) * (outchans > inchans ? outchans : inchans));
- for (i = 0; i < (outchans > inchans ? outchans : inchans); i++)
- alsa_buf_ptrs[i] = (t_alsa_sample32 *)alsa_snd_buf + i * DEFDACBLKSIZE;
-
- // fill the buffer with silence
- if (outchans)
- {
- i = (frag_size * nfrags)/DEFDACBLKSIZE + 1;
- while (i--)
- {
- if (alsa_device.outnoninterleave)
- snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
- }
- /* confused about this: */
- /* if ((err = snd_pcm_start(alsa_device.outhandle) < 0))
- check_error(err, "output start failed\n"); */
- }
- else if (inchans)
- {
- if (snd_pcm_start(alsa_device.inhandle) < 0)
- check_error(err, "input start failed\n");
- }
- alsa_outchannels = outchans;
- alsa_inchannels = inchans;
-
- return (!(inchans || outchans));
-}
-
-void alsa_close_audio(void)
-{
- int err;
- if (alsa_inchannels)
- {
- err = snd_pcm_close(alsa_device.inhandle);
- check_error(err, "snd_pcm_close (input)");
- }
- if (alsa_outchannels)
- {
- err = snd_pcm_close(alsa_device.outhandle);
- check_error(err, "snd_pcm_close (output)");
- }
-}
-
-// #define DEBUG_ALSA_XFER
-
-int alsa_send_dacs(void)
-{
- static int16_t *sp;
- static int xferno = 0;
- static int callno = 0;
- static double timenow;
- double timelast;
- t_sample *fp, *fp1, *fp2;
- int i, j, k, err, devno = 0;
- int inputcount = 0, outputcount = 0, inputlate = 0, outputlate = 0;
- int result;
- int inchannels = (sys_inchannels > alsa_inchannels ?
- alsa_inchannels : sys_inchannels);
- int outchannels = (sys_outchannels > alsa_outchannels ?
- alsa_outchannels : sys_outchannels);
- unsigned int intransfersize = DEFDACBLKSIZE;
- unsigned int outtransfersize = DEFDACBLKSIZE;
-
- // get the status
- if (!inchannels && !outchannels)
- {
- return SENDDACS_NO;
- }
-
- timelast = timenow;
- timenow = sys_getrealtime();
-
-#ifdef DEBUG_ALSA_XFER
- if (timenow - timelast > 0.050)
- fprintf(stderr, "(%d)",
- (int)(1000 * (timenow - timelast))), fflush(stderr);
-#endif
-
- callno++;
-
- alsa_checkiosync(); /* check I/O are in sync and data not late */
-
- if (alsa_inchannels)
- {
- snd_pcm_status(alsa_device.inhandle, in_status);
- if (snd_pcm_status_get_avail(in_status) < intransfersize)
- return SENDDACS_NO;
- }
- if (alsa_outchannels)
- {
- snd_pcm_status(alsa_device.outhandle, out_status);
- if (snd_pcm_status_get_avail(out_status) < outtransfersize)
- return SENDDACS_NO;
- }
-
- /* do output */
- if (alsa_outchannels)
- {
- fp = sys_soundout;
- if (alsa_samplewidth == 4)
- {
- if (alsa_device.outnoninterleave)
- {
- int n = outchannels * DEFDACBLKSIZE;
- for (i = 0, fp1 = fp; i < n; i++)
- {
- float s1 = *fp1 * INT32_MAX;
- ((t_alsa_sample32 *)alsa_snd_buf)[i] = CLIP32(s1);
- }
- n = alsa_outchannels * DEFDACBLKSIZE;
- for (; i < n; i++)
- ((t_alsa_sample32 *)alsa_snd_buf)[i] = 0;
- }
- else
- {
- for (i = 0, fp1 = fp; i < outchannels; i++,
- fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_outchannels, fp2++)
- {
- float s1 = *fp2 * INT32_MAX;
- ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(s1);
- }
- }
- }
- }
- else
- {
- for (i = 0, fp1 = fp; i < outchannels; i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_outchannels, fp2++)
- {
- int s = *fp2 * 32767.;
- if (s > 32767)
- s = 32767;
- else if (s < -32767)
- s = -32767;
- ((t_alsa_sample16 *)alsa_snd_buf)[j] = s;
- }
- }
- }
-
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- outtransfersize);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- outtransfersize);
-
- if (result != (int)outtransfersize)
- {
- #ifdef DEBUG_ALSA_XFER
- if (result >= 0 || errno == EAGAIN)
- fprintf(stderr, "ALSA: write returned %d of %d\n",
- result, outtransfersize);
- else fprintf(stderr, "ALSA: write: %s\n",
- snd_strerror(errno));
- fprintf(stderr,
- "inputcount %d, outputcount %d, outbufsize %d\n",
- inputcount, outputcount,
- (ALSA_EXTRABUFFER + sys_advance_samples)
- * alsa_samplewidth * outchannels);
- #endif
- sys_log_error(ERR_DACSLEPT);
- return (SENDDACS_NO);
- }
-
- /* zero out the output buffer */
- memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(*sys_soundout) *
- sys_outchannels);
- if (sys_getrealtime() - timenow > 0.002)
- {
- #ifdef DEBUG_ALSA_XFER
- fprintf(stderr, "output %d took %d msec\n",
- callno, (int)(1000 * (timenow - timelast))), fflush(stderr);
- #endif
- timenow = sys_getrealtime();
- sys_log_error(ERR_DACSLEPT);
- }
- }
- /* do input */
- if (alsa_inchannels)
- {
- if (alsa_device.innoninterleave)
- result = snd_pcm_readn(alsa_device.inhandle, alsa_buf_ptrs,
- intransfersize);
- else result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf,
- intransfersize);
- if (result < (int)intransfersize)
- {
-#ifdef DEBUG_ALSA_XFER
- if (result < 0)
- fprintf(stderr,
- "snd_pcm_read %d %d: %s\n",
- callno, xferno, snd_strerror(errno));
- else fprintf(stderr,
- "snd_pcm_read %d %d returned only %d\n",
- callno, xferno, result);
- fprintf(stderr,
- "inputcount %d, outputcount %d, inbufsize %d\n",
- inputcount, outputcount,
- (ALSA_EXTRABUFFER + sys_advance_samples)
- * alsa_samplewidth * inchannels);
-#endif
- sys_log_error(ERR_ADCSLEPT);
- return (SENDDACS_NO);
- }
- fp = sys_soundin;
- if (alsa_samplewidth == 4)
- {
- if (alsa_device.innoninterleave)
- {
- int n = inchannels * DEFDACBLKSIZE;
- for (i = 0, fp1 = fp; i < n; i++)
- *fp1 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[i]
- * (1./ INT32_MAX);
- }
- else
- {
- for (i = 0, fp1 = fp; i < inchannels;
- i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_inchannels, fp2++)
- *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j]
- * (1./ INT32_MAX);
- }
- }
- }
- else
- {
- for (i = 0, fp1 = fp; i < inchannels; i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_inchannels, fp2++)
- *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j]
- * 3.051850e-05;
- }
- }
- }
- xferno++;
- if (sys_getrealtime() - timenow > 0.002)
- {
-#ifdef DEBUG_ALSA_XFER
- fprintf(stderr, "routine took %d msec\n",
- (int)(1000 * (sys_getrealtime() - timenow)));
-#endif
- sys_log_error(ERR_ADCSLEPT);
- }
- return SENDDACS_YES;
-}
-
-void alsa_printstate( void)
-{
- int i, result;
- snd_pcm_sframes_t indelay, outdelay;
- if (sys_audioapi != API_ALSA)
- {
- error("restart-audio: implemented for ALSA only.");
- return;
- }
- if (sys_inchannels)
- {
- result = snd_pcm_delay(alsa_device.inhandle, &indelay);
- if (result < 0)
- post("snd_pcm_delay 1 failed");
- else post("in delay %d", indelay);
- }
- if (sys_outchannels)
- {
- result = snd_pcm_delay(alsa_device.outhandle, &outdelay);
- if (result < 0)
- post("snd_pcm_delay 2 failed");
- else post("out delay %d", outdelay);
- }
- post("sum %d (%d mod 64)\n", indelay + outdelay, (indelay+outdelay)%64);
-
- post("buf samples %d", alsa_buf_samps);
-}
-
-
-void alsa_resync( void)
-{
- int i, result;
- if (sys_audioapi != API_ALSA)
- {
- error("restart-audio: implemented for ALSA only.");
- return;
- }
- memset(alsa_snd_buf, 0,
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * sys_outchannels);
- for (i = 0; i < 1000000; i++)
- {
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
- if (result != (int)DEFDACBLKSIZE)
- break;
- }
- post("%d written", i);
-}
-
-void alsa_putzeros(int n)
-{
- int i, result;
- memset(alsa_snd_buf, 0,
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * alsa_outchannels);
- for (i = 0; i < n; i++)
- {
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
-#if 0
- if (result != DEFDACBLKSIZE)
- post("result %d", result);
-#endif
- }
- /* post ("putzeros %d", n); */
-}
-
-void alsa_getzeros(int n)
-{
- int i, result;
- for (i = 0; i < n; i++)
- {
- result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
-#if 0
- if (result != DEFDACBLKSIZE)
- post("result %d", result);
-#endif
- }
- /* post ("getzeros %d", n); */
-}
-
- /* call this only if both input and output are open */
-static void alsa_checkiosync( void)
-{
- int i, result, checkit = 1, giveup = 1000, alreadylogged = 0;
- snd_pcm_sframes_t indelay, outdelay, defect;
-
- if (!(alsa_outchannels && alsa_inchannels))
- return;
- while (checkit)
- {
- checkit = 0;
- if (giveup-- <= 0)
- return;
- result = snd_pcm_delay(alsa_device.outhandle, &outdelay);
- if (result < 0)
- {
- post("output snd_pcm_delay failed: %s", snd_strerror(result));
- if (snd_pcm_status(alsa_device.outhandle, out_status) < 0)
- post("output snd_pcm_status failed");
- else post("astate %d",
- snd_pcm_status_get_state(out_status));
- return;
- }
- if (outdelay < 0)
- sys_log_error(ERR_DATALATE), alreadylogged = 1;
-
- if (sys_inchannels)
- {
- result = snd_pcm_delay(alsa_device.inhandle, &indelay);
- if (result < 0)
- {
- post("input snd_pcm_delay failed");
- return;
- }
- defect = indelay + outdelay - alsa_buf_samps;
- if (defect < -(3 * DEFDACBLKSIZE / 2) )
- {
- checkit = 1;
- alsa_putzeros(1);
- if (!alreadylogged)
- sys_log_error(ERR_RESYNC), alreadylogged = 1;
- }
- else if (defect > 0)
- {
- checkit = 1;
- alsa_getzeros(1);
- if (!alreadylogged)
- sys_log_error(ERR_RESYNC), alreadylogged = 1;
- }
- /* if (alreadylogged)
- post("in %d out %d defect %d", indelay, outdelay, defect); */
- }
- }
-}
-
-static int alsa_nnames = 0;
-static char **alsa_names = 0;
-
-void alsa_adddev(char *name)
-{
- if (alsa_nnames)
- alsa_names = (char **)t_resizebytes(alsa_names,
- alsa_nnames * sizeof(char *),
- (alsa_nnames+1) * sizeof(char *));
- else alsa_names = (char **)t_getbytes(sizeof(char *));
- alsa_names[alsa_nnames] = gensym(name)->s_name;
- alsa_nnames++;
-}
-
-static void alsa_numbertoname(int devno, char *devname, int nchar)
-{
- int ndev = 0, cardno = -1;
- while (!snd_card_next(&cardno) && cardno >= 0)
- ndev++;
- if (devno < 2*ndev)
- {
- if (devno & 1)
- snprintf(devname, nchar, "plughw:%d", devno/2);
- else snprintf(devname, nchar, "hw:%d", devno/2);
- }
- else if (devno <2*ndev + alsa_nnames)
- snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]);
- else snprintf(devname, nchar, "???");
-}
-
- /* For each hardware card found, we list two devices, the "hard" and
- "plug" one. The card scan is derived from portaudio code. */
-void alsa_getdevs(char *indevlist, int *nindevs,
- char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
-{
- int ndev = 0, cardno = -1, i, j;
- *canmulti = 0; /* only one device; must be the same for input&output */
- while (!snd_card_next(&cardno) && cardno >= 0)
- {
- snd_ctl_t *ctl;
- snd_ctl_card_info_t *info;
- char devname[80];
- const char *desc;
- if (2 * ndev + 2 > maxndev)
- break;
- /* apparently, "cardno" is just a counter; but check that here */
- if (ndev != cardno)
- fprintf(stderr, "oops: ALSA cards not reported in order?\n");
- sprintf(devname, "hw:%d", cardno );
- /* fprintf(stderr, "\ntry %s...\n", devname); */
- if (snd_ctl_open(&ctl, devname, 0) >= 0)
- {
- snd_ctl_card_info_malloc(&info);
- snd_ctl_card_info(ctl, info);
- desc = snd_ctl_card_info_get_name(info);
- snd_ctl_card_info_free(info);
- }
- else
- {
- fprintf(stderr, "ALSA card scan error\n");
- desc = "???";
- }
- /* fprintf(stderr, "name: %s\n", snd_ctl_card_info_get_name(info)); */
- sprintf(indevlist + 2*ndev * devdescsize, "%s (hardware)", desc);
- sprintf(indevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc);
- sprintf(outdevlist + 2*ndev * devdescsize, "%s (hardware)", desc);
- sprintf(outdevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc);
- ndev++;
- }
- for (i = 0, j = 2*ndev; i < alsa_nnames; i++, j++)
- {
- if (j >= maxndev)
- break;
- snprintf(indevlist + j * devdescsize, devdescsize, "%s",
- alsa_names[i]);
- }
- *nindevs = *noutdevs = j;
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_mmio.c b/apps/plugins/pdbox/PDa/src/s_audio_mmio.c
deleted file mode 100644
index 4a4a8f7354..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_audio_mmio.c
+++ /dev/null
@@ -1,795 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* modified 2/98 by Winfried Ritsch to deal with up to 4 synchronized
-"wave" devices, which is how ADAT boards appear to the WAVE API. */
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include <stdio.h>
-
-#include <windows.h>
-
-#include <MMSYSTEM.H>
-
-/* ------------------------- audio -------------------------- */
-
-static void nt_close_midiin(void);
-static void nt_noresync( void);
-
-static void postflags(void);
-
-#define NAPORTS 16 /* wini hack for multiple ADDA devices */
-#define CHANNELS_PER_DEVICE 2
-#define DEFAULTCHANS 2
-#define DEFAULTSRATE 44100
-#define SAMPSIZE 2
-
-int nt_realdacblksize;
-#define DEFREALDACBLKSIZE (4 * DEFDACBLKSIZE) /* larger underlying bufsize */
-
-#define MAXBUFFER 100 /* number of buffers in use at maximum advance */
-#define DEFBUFFER 30 /* default is about 30x6 = 180 msec! */
-static int nt_naudiobuffer = DEFBUFFER;
-float sys_dacsr = DEFAULTSRATE;
-
-static int nt_whichapi = API_MMIO;
-static int nt_meters; /* true if we're metering */
-static float nt_inmax; /* max input amplitude */
-static float nt_outmax; /* max output amplitude */
-static int nt_nwavein, nt_nwaveout; /* number of WAVE devices in and out */
-
-typedef struct _sbuf
-{
- HANDLE hData;
- HPSTR lpData; // pointer to waveform data memory
- HANDLE hWaveHdr;
- WAVEHDR *lpWaveHdr; // pointer to header structure
-} t_sbuf;
-
-t_sbuf ntsnd_outvec[NAPORTS][MAXBUFFER]; /* circular buffer array */
-HWAVEOUT ntsnd_outdev[NAPORTS]; /* output device */
-static int ntsnd_outphase[NAPORTS]; /* index of next buffer to send */
-
-t_sbuf ntsnd_invec[NAPORTS][MAXBUFFER]; /* circular buffer array */
-HWAVEIN ntsnd_indev[NAPORTS]; /* input device */
-static int ntsnd_inphase[NAPORTS]; /* index of next buffer to read */
-
-static void nt_waveinerror(char *s, int err)
-{
- char t[256];
- waveInGetErrorText(err, t, 256);
- fprintf(stderr, s, t);
-}
-
-static void nt_waveouterror(char *s, int err)
-{
- char t[256];
- waveOutGetErrorText(err, t, 256);
- fprintf(stderr, s, t);
-}
-
-static void wave_prep(t_sbuf *bp, int setdone)
-{
- WAVEHDR *wh;
- short *sp;
- int i;
- /*
- * Allocate and lock memory for the waveform data. The memory
- * for waveform data must be globally allocated with
- * GMEM_MOVEABLE and GMEM_SHARE flags.
- */
-
- if (!(bp->hData =
- GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
- (DWORD) (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize))))
- printf("alloc 1 failed\n");
-
- if (!(bp->lpData =
- (HPSTR) GlobalLock(bp->hData)))
- printf("lock 1 failed\n");
-
- /* Allocate and lock memory for the header. */
-
- if (!(bp->hWaveHdr =
- GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (DWORD) sizeof(WAVEHDR))))
- printf("alloc 2 failed\n");
-
- if (!(wh = bp->lpWaveHdr =
- (WAVEHDR *) GlobalLock(bp->hWaveHdr)))
- printf("lock 2 failed\n");
-
- for (i = CHANNELS_PER_DEVICE * nt_realdacblksize,
- sp = (short *)bp->lpData; i--; )
- *sp++ = 0;
-
- wh->lpData = bp->lpData;
- wh->dwBufferLength = (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize);
- wh->dwFlags = 0;
- wh->dwLoops = 0L;
- wh->lpNext = 0;
- wh->reserved = 0;
- /* optionally (for writing) set DONE flag as if we had queued them */
- if (setdone)
- wh->dwFlags = WHDR_DONE;
-}
-
-static UINT nt_whichdac = WAVE_MAPPER, nt_whichadc = WAVE_MAPPER;
-
-int mmio_do_open_audio(void)
-{
- PCMWAVEFORMAT form;
- int i, j;
- UINT mmresult;
- int nad, nda;
- static int naudioprepped = 0, nindevsprepped = 0, noutdevsprepped = 0;
- if (sys_verbose)
- post("%d devices in, %d devices out",
- nt_nwavein, nt_nwaveout);
-
- form.wf.wFormatTag = WAVE_FORMAT_PCM;
- form.wf.nChannels = CHANNELS_PER_DEVICE;
- form.wf.nSamplesPerSec = sys_dacsr;
- form.wf.nAvgBytesPerSec = sys_dacsr * (CHANNELS_PER_DEVICE * SAMPSIZE);
- form.wf.nBlockAlign = CHANNELS_PER_DEVICE * SAMPSIZE;
- form.wBitsPerSample = 8 * SAMPSIZE;
-
- if (nt_nwavein <= 1 && nt_nwaveout <= 1)
- nt_noresync();
-
- if (nindevsprepped < nt_nwavein)
- {
- for (i = nindevsprepped; i < nt_nwavein; i++)
- for (j = 0; j < naudioprepped; j++)
- wave_prep(&ntsnd_invec[i][j], 0);
- nindevsprepped = nt_nwavein;
- }
- if (noutdevsprepped < nt_nwaveout)
- {
- for (i = noutdevsprepped; i < nt_nwaveout; i++)
- for (j = 0; j < naudioprepped; j++)
- wave_prep(&ntsnd_outvec[i][j], 1);
- noutdevsprepped = nt_nwaveout;
- }
- if (naudioprepped < nt_naudiobuffer)
- {
- for (j = naudioprepped; j < nt_naudiobuffer; j++)
- {
- for (i = 0; i < nt_nwavein; i++)
- wave_prep(&ntsnd_invec[i][j], 0);
- for (i = 0; i < nt_nwaveout; i++)
- wave_prep(&ntsnd_outvec[i][j], 1);
- }
- naudioprepped = nt_naudiobuffer;
- }
- for (nad=0; nad < nt_nwavein; nad++)
- {
- /* Open waveform device(s), sucessively numbered, for input */
-
- mmresult = waveInOpen(&ntsnd_indev[nad], nt_whichadc+nad,
- (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
-
- if (sys_verbose)
- printf("opened adc device %d with return %d\n",
- nt_whichadc+nad,mmresult);
-
- if (mmresult != MMSYSERR_NOERROR)
- {
- nt_waveinerror("waveInOpen: %s\n", mmresult);
- nt_nwavein = nad; /* nt_nwavein = 0 wini */
- }
- else
- {
- for (i = 0; i < nt_naudiobuffer; i++)
- {
- mmresult = waveInPrepareHeader(ntsnd_indev[nad],
- ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveinprepareheader: %s\n", mmresult);
- mmresult = waveInAddBuffer(ntsnd_indev[nad],
- ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- }
- }
- }
- /* quickly start them all together */
- for (nad = 0; nad < nt_nwavein; nad++)
- waveInStart(ntsnd_indev[nad]);
-
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- /* Open a waveform device for output in sucessiv device numbering*/
- mmresult = waveOutOpen(&ntsnd_outdev[nda], nt_whichdac + nda,
- (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
-
- if (sys_verbose)
- fprintf(stderr,"opened dac device %d, with return %d\n",
- nt_whichdac +nda, mmresult);
-
- if (mmresult != MMSYSERR_NOERROR)
- {
- fprintf(stderr,"Wave out open device %d + %d\n",nt_whichdac,nda);
- nt_waveouterror("waveOutOpen device: %s\n", mmresult);
- nt_nwaveout = nda;
- }
- }
-
- return (0);
-}
-
-void mmio_close_audio( void)
-{
- int errcode;
- int nda, nad;
- if (sys_verbose)
- post("closing audio...");
-
- for (nda=0; nda < nt_nwaveout; nda++) /*if (nt_nwaveout) wini */
- {
- errcode = waveOutReset(ntsnd_outdev[nda]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error resetting output %d: %d\n", nda, errcode);
- errcode = waveOutClose(ntsnd_outdev[nda]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error closing output %d: %d\n",nda , errcode);
- }
- nt_nwaveout = 0;
-
- for(nad=0; nad < nt_nwavein;nad++) /* if (nt_nwavein) wini */
- {
- errcode = waveInReset(ntsnd_indev[nad]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error resetting input: %d\n", errcode);
- errcode = waveInClose(ntsnd_indev[nad]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error closing input: %d\n", errcode);
- }
- nt_nwavein = 0;
-}
-
-
-#define ADCJITTER 10 /* We tolerate X buffers of jitter by default */
-#define DACJITTER 10
-
-static int nt_adcjitterbufsallowed = ADCJITTER;
-static int nt_dacjitterbufsallowed = DACJITTER;
-
- /* ------------- MIDI time stamping from audio clock ------------ */
-
-#ifdef MIDI_TIMESTAMP
-
-static double nt_hibuftime;
-static double initsystime = -1;
-
- /* call this whenever we reset audio */
-static void nt_resetmidisync(void)
-{
- initsystime = clock_getsystime();
- nt_hibuftime = sys_getrealtime();
-}
-
- /* call this whenever we're idled waiting for audio to be ready.
- The routine maintains a high and low water point for the difference
- between real and DAC time. */
-
-static void nt_midisync(void)
-{
- double jittersec, diff;
-
- if (initsystime == -1) nt_resetmidisync();
- jittersec = (nt_dacjitterbufsallowed > nt_adcjitterbufsallowed ?
- nt_dacjitterbufsallowed : nt_adcjitterbufsallowed)
- * nt_realdacblksize / sys_getsr();
- diff = sys_getrealtime() - 0.001 * clock_gettimesince(initsystime);
- if (diff > nt_hibuftime) nt_hibuftime = diff;
- if (diff < nt_hibuftime - jittersec)
- {
- post("jitter excess %d %f", dac, diff);
- nt_resetmidisync();
- }
-}
-
-static double nt_midigettimefor(LARGE_INTEGER timestamp)
-{
- /* this is broken now... used to work when "timestamp" was derived from
- QueryPerformanceCounter() instead of the gates approved
- timeGetSystemTime() call in the MIDI callback routine below. */
- return (nt_tixtotime(timestamp) - nt_hibuftime);
-}
-#endif /* MIDI_TIMESTAMP */
-
-
-static int nt_fill = 0;
-#define WRAPFWD(x) ((x) >= nt_naudiobuffer ? (x) - nt_naudiobuffer: (x))
-#define WRAPBACK(x) ((x) < 0 ? (x) + nt_naudiobuffer: (x))
-#define MAXRESYNC 500
-
-#if 0 /* this is used for debugging */
-static void nt_printaudiostatus(void)
-{
- int nad, nda;
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
- int firstphasedone = -1, firstphasebusy = -1;
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- int donethis =
- (ntsnd_invec[nad][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
- int donenext =
- (ntsnd_invec[nad][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
- if (donethis && !donenext)
- {
- if (firstphasebusy >= 0) goto multipleadc;
- firstphasebusy = count;
- }
- if (!donethis && donenext)
- {
- if (firstphasedone >= 0) goto multipleadc;
- firstphasedone = count;
- }
- phase2 = phase3;
- phase3 = WRAPFWD(phase2 + 1);
- }
- post("nad %d phase %d busy %d done %d", nad, phase, firstphasebusy,
- firstphasedone);
- continue;
- multipleadc:
- startpost("nad %d phase %d: oops:", nad, phase);
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- char buf[80];
- sprintf(buf, " %d",
- (ntsnd_invec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
- poststring(buf);
- }
- endpost();
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nad];
- int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
- int firstphasedone = -1, firstphasebusy = -1;
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- int donethis =
- (ntsnd_outvec[nda][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
- int donenext =
- (ntsnd_outvec[nda][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
- if (donethis && !donenext)
- {
- if (firstphasebusy >= 0) goto multipledac;
- firstphasebusy = count;
- }
- if (!donethis && donenext)
- {
- if (firstphasedone >= 0) goto multipledac;
- firstphasedone = count;
- }
- phase2 = phase3;
- phase3 = WRAPFWD(phase2 + 1);
- }
- if (firstphasebusy < 0) post("nda %d phase %d all %d",
- nda, phase, (ntsnd_outvec[nad][0].lpWaveHdr->dwFlags & WHDR_DONE));
- else post("nda %d phase %d busy %d done %d", nda, phase, firstphasebusy,
- firstphasedone);
- continue;
- multipledac:
- startpost("nda %d phase %d: oops:", nda, phase);
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- char buf[80];
- sprintf(buf, " %d",
- (ntsnd_outvec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
- poststring(buf);
- }
- endpost();
- }
-}
-#endif /* 0 */
-
-/* this is a hack to avoid ever resyncing audio pointers in case for whatever
-reason the sync testing below gives false positives. */
-
-static int nt_resync_cancelled;
-
-static void nt_noresync( void)
-{
- nt_resync_cancelled = 1;
-}
-
-static void nt_resyncaudio(void)
-{
- UINT mmresult;
- int nad, nda, count;
- if (nt_resync_cancelled)
- return;
- /* for each open input device, eat all buffers which are marked
- ready. The next one will thus be "busy". */
- post("resyncing audio");
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- for (count = 0; count < MAXRESYNC; count++)
- {
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (!(inwavehdr->dwFlags & WHDR_DONE)) break;
- if (inwavehdr->dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(ntsnd_indev[nad],
- inwavehdr, sizeof(WAVEHDR));
- inwavehdr->dwFlags = 0L;
- waveInPrepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR));
- mmresult = waveInAddBuffer(ntsnd_indev[nad], inwavehdr,
- sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- ntsnd_inphase[nad] = phase = WRAPFWD(phase + 1);
- }
- if (count == MAXRESYNC) post("resync error 1");
- }
- /* Each output buffer which is "ready" is filled with zeros and
- queued. */
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- for (count = 0; count < MAXRESYNC; count++)
- {
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (!(outwavehdr->dwFlags & WHDR_DONE)) break;
- if (outwavehdr->dwFlags & WHDR_PREPARED)
- waveOutUnprepareHeader(ntsnd_outdev[nda],
- outwavehdr, sizeof(WAVEHDR));
- outwavehdr->dwFlags = 0L;
- memset((char *)(ntsnd_outvec[nda][phase].lpData),
- 0, (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize));
- waveOutPrepareHeader(ntsnd_outdev[nda], outwavehdr,
- sizeof(WAVEHDR));
- mmresult = waveOutWrite(ntsnd_outdev[nda], outwavehdr,
- sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveouterror("waveOutAddBuffer: %s\n", mmresult);
- ntsnd_outphase[nda] = phase = WRAPFWD(phase + 1);
- }
- if (count == MAXRESYNC) post("resync error 2");
- }
-
-#ifdef MIDI_TIMESTAMP
- nt_resetmidisync();
-#endif
-
-}
-
-#define LATE 0
-#define RESYNC 1
-#define NOTHING 2
-static int nt_errorcount;
-static int nt_resynccount;
-static double nt_nextreporttime = -1;
-
-void nt_logerror(int which)
-{
-#if 0
- post("error %d %d", count, which);
- if (which < NOTHING) nt_errorcount++;
- if (which == RESYNC) nt_resynccount++;
- if (sys_getrealtime() > nt_nextreporttime)
- {
- post("%d audio I/O error%s", nt_errorcount,
- (nt_errorcount > 1 ? "s" : ""));
- if (nt_resynccount) post("DAC/ADC sync error");
- nt_errorcount = nt_resynccount = 0;
- nt_nextreporttime = sys_getrealtime() - 5;
- }
-#endif
-}
-
-/* system buffer with t_sample types for one tick */
-t_sample *sys_soundout;
-t_sample *sys_soundin;
-float sys_dacsr;
-
-int mmio_send_dacs(void)
-{
- HMMIO hmmio;
- UINT mmresult;
- HANDLE hFormat;
- int i, j;
- short *sp1, *sp2;
- float *fp1, *fp2;
- int nextfill, doxfer = 0;
- int nda, nad;
- if (!nt_nwavein && !nt_nwaveout) return (0);
-
-
- if (nt_meters)
- {
- int i, n;
- float maxsamp;
- for (i = 0, n = 2 * nt_nwavein * DEFDACBLKSIZE, maxsamp = nt_inmax;
- i < n; i++)
- {
- float f = sys_soundin[i];
- if (f > maxsamp) maxsamp = f;
- else if (-f > maxsamp) maxsamp = -f;
- }
- nt_inmax = maxsamp;
- for (i = 0, n = 2 * nt_nwaveout * DEFDACBLKSIZE, maxsamp = nt_outmax;
- i < n; i++)
- {
- float f = sys_soundout[i];
- if (f > maxsamp) maxsamp = f;
- else if (-f > maxsamp) maxsamp = -f;
- }
- nt_outmax = maxsamp;
- }
-
- /* the "fill pointer" nt_fill controls where in the next
- I/O buffers we will write and/or read. If it's zero, we
- first check whether the buffers are marked "done". */
-
- if (!nt_fill)
- {
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (!(inwavehdr->dwFlags & WHDR_DONE)) goto idle;
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr =
- ntsnd_outvec[nda][phase].lpWaveHdr;
- if (!(outwavehdr->dwFlags & WHDR_DONE)) goto idle;
- }
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr =
- ntsnd_invec[nad][phase].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(ntsnd_indev[nad],
- inwavehdr, sizeof(WAVEHDR));
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_PREPARED)
- waveOutUnprepareHeader(ntsnd_outdev[nda],
- outwavehdr, sizeof(WAVEHDR));
- }
- }
-
- /* Convert audio output to fixed-point and put it in the output
- buffer. */
- for (nda = 0, fp1 = sys_soundout; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
-
- for (i = 0, sp1 = (short *)(ntsnd_outvec[nda][phase].lpData) +
- CHANNELS_PER_DEVICE * nt_fill;
- i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
- {
- for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
- j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
- {
- int x1 = 32767.f * *fp2;
- if (x1 > 32767) x1 = 32767;
- else if (x1 < -32767) x1 = -32767;
- *sp2 = x1;
- }
- }
- }
- memset(sys_soundout, 0,
- (DEFDACBLKSIZE *sizeof(t_sample)*CHANNELS_PER_DEVICE)*nt_nwaveout);
-
- /* vice versa for the input buffer */
-
- for (nad = 0, fp1 = sys_soundin; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
-
- for (i = 0, sp1 = (short *)(ntsnd_invec[nad][phase].lpData) +
- CHANNELS_PER_DEVICE * nt_fill;
- i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
- {
- for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
- j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
- {
- *fp2 = ((float)(1./32767.)) * (float)(*sp2);
- }
- }
- }
-
- nt_fill = nt_fill + DEFDACBLKSIZE;
- if (nt_fill == nt_realdacblksize)
- {
- nt_fill = 0;
-
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- HWAVEIN device = ntsnd_indev[nad];
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- waveInPrepareHeader(device, inwavehdr, sizeof(WAVEHDR));
- mmresult = waveInAddBuffer(device, inwavehdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- ntsnd_inphase[nad] = WRAPFWD(phase + 1);
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- HWAVEOUT device = ntsnd_outdev[nda];
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- waveOutPrepareHeader(device, outwavehdr, sizeof(WAVEHDR));
- mmresult = waveOutWrite(device, outwavehdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveouterror("waveOutWrite: %s\n", mmresult);
- ntsnd_outphase[nda] = WRAPFWD(phase + 1);
- }
-
- /* check for DAC underflow or ADC overflow. */
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = WRAPBACK(ntsnd_inphase[nad] - 2);
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_DONE) goto late;
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = WRAPBACK(ntsnd_outphase[nda] - 2);
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_DONE) goto late;
- }
- }
- return (1);
-
-late:
-
- nt_logerror(LATE);
- nt_resyncaudio();
- return (1);
-
-idle:
-
- /* If more than nt_adcjitterbufsallowed ADC buffers are ready
- on any input device, resynchronize */
-
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr =
- ntsnd_invec[nad]
- [WRAPFWD(phase + nt_adcjitterbufsallowed)].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_DONE)
- {
- nt_resyncaudio();
- return (0);
- }
- }
-
- /* test dac sync the same way */
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr =
- ntsnd_outvec[nda]
- [WRAPFWD(phase + nt_dacjitterbufsallowed)].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_DONE)
- {
- nt_resyncaudio();
- return (0);
- }
- }
-#ifdef MIDI_TIMESTAMP
- nt_midisync();
-#endif
- return (0);
-}
-
-/* ------------------- public routines -------------------------- */
-
-void mmio_open_audio(int naudioindev, int *audioindev,
- int nchindev, int *chindev, int naudiooutdev, int *audiooutdev,
- int nchoutdev, int *choutdev, int rate) /* IOhannes */
-{
- int nbuf;
-
- nt_realdacblksize = (sys_blocksize ? sys_blocksize : DEFREALDACBLKSIZE);
- nbuf = sys_advance_samples/nt_realdacblksize;
- if (nbuf >= MAXBUFFER)
- {
- fprintf(stderr, "pd: audio buffering maxed out to %d\n",
- (int)(MAXBUFFER * ((nt_realdacblksize * 1000.)/44100.)));
- nbuf = MAXBUFFER;
- }
- else if (nbuf < 4) nbuf = 4;
- fprintf(stderr, "%d audio buffers\n", nbuf);
- nt_naudiobuffer = nbuf;
- if (nt_adcjitterbufsallowed > nbuf - 2)
- nt_adcjitterbufsallowed = nbuf - 2;
- if (nt_dacjitterbufsallowed > nbuf - 2)
- nt_dacjitterbufsallowed = nbuf - 2;
-
- nt_nwavein = sys_inchannels / 2;
- nt_nwaveout = sys_outchannels / 2;
- nt_whichadc = (naudioindev < 1 ?
- (nt_nwavein > 1 ? WAVE_MAPPER : -1) : audioindev[0]);
- nt_whichdac = (naudiooutdev < 1 ?
- (nt_nwaveout > 1 ? WAVE_MAPPER : -1) : audiooutdev[0]);
- if (naudiooutdev > 1 || naudioindev > 1)
- post("separate audio device choice not supported; using sequential devices.");
- mmio_do_open_audio();
-}
-
-
-void mmio_reportidle(void)
-{
-}
-
-#if 0
-/* list the audio and MIDI device names */
-void mmio_listdevs(void)
-{
- UINT wRtn, ndevices;
- unsigned int i;
-
- ndevices = waveInGetNumDevs();
- for (i = 0; i < ndevices; i++)
- {
- WAVEINCAPS wicap;
- wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap,
- sizeof(wicap));
- if (wRtn) nt_waveinerror("waveInGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "audio input device #%d: %s\n", i+1, wicap.szPname);
- }
-
- ndevices = waveOutGetNumDevs();
- for (i = 0; i < ndevices; i++)
- {
- WAVEOUTCAPS wocap;
- wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap,
- sizeof(wocap));
- if (wRtn) nt_waveouterror("waveOutGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "audio output device #%d: %s\n", i+1, wocap.szPname);
- }
-}
-#endif
-
-void mmio_getdevs(char *indevlist, int *nindevs,
- char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
-{
- int wRtn, ndev, i;
-
- *canmulti = 2; /* supports multiple devices */
- ndev = waveInGetNumDevs();
- if (ndev > maxndev)
- ndev = maxndev;
- *nindevs = ndev;
- for (i = 0; i < ndev; i++)
- {
- WAVEINCAPS wicap;
- wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap, sizeof(wicap));
- sprintf(indevlist + i * devdescsize, (wRtn ? "???" : wicap.szPname));
- }
-
- ndev = waveOutGetNumDevs();
- if (ndev > maxndev)
- ndev = maxndev;
- *noutdevs = ndev;
- for (i = 0; i < ndev; i++)
- {
- WAVEOUTCAPS wocap;
- wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap, sizeof(wocap));
- sprintf(outdevlist + i * devdescsize, (wRtn ? "???" : wocap.szPname));
- }
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_oss.c b/apps/plugins/pdbox/PDa/src/s_audio_oss.c
deleted file mode 100644
index de11f66243..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_audio_oss.c
+++ /dev/null
@@ -1,845 +0,0 @@
-/* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler,
-* Winfried Ritsch, Karl MacMillan, and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* this file inputs and outputs audio using the OSS API available on linux. */
-
-#ifdef USEAPI_OSS
-
-#include <linux/soundcard.h>
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include <errno.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sched.h>
-#include <sys/mman.h>
-
-
-/* Defines */
-#define DEBUG(x) x
-#define DEBUG2(x) {x;}
-
-#define OSS_MAXCHPERDEV 32 /* max channels per OSS device */
-#define OSS_MAXDEV 4 /* maximum number of input or output devices */
-#define OSS_DEFFRAGSIZE 256 /* default log fragment size (frames) */
-#define OSS_DEFAUDIOBUF 40000 /* default audiobuffer, microseconds */
-#define OSS_DEFAULTCH 2
-#define RME_DEFAULTCH 8 /* need this even if RME undefined */
-typedef int16_t t_oss_int16;
-typedef int32_t t_oss_int32;
-#define OSS_MAXSAMPLEWIDTH sizeof(t_oss_int32)
-#define OSS_BYTESPERCHAN(width) (DEFDACBLKSIZE * (width))
-#define OSS_XFERSAMPS(chans) (DEFDACBLKSIZE* (chans))
-#define OSS_XFERSIZE(chans, width) (DEFDACBLKSIZE * (chans) * (width))
-
-/* GLOBALS */
-static int linux_meters; /* true if we're metering */
-static float linux_inmax; /* max input amplitude */
-static float linux_outmax; /* max output amplitude */
-static int linux_fragsize = 0; /* for block mode; block size (sample frames) */
-
-/* our device handles */
-
-typedef struct _oss_dev
-{
- int d_fd;
- unsigned int d_space; /* bytes available for writing/reading */
- int d_bufsize; /* total buffer size in blocks for this device */
- int d_dropcount; /* # of buffers to drop for resync (output only) */
- unsigned int d_nchannels; /* number of channels for this device */
- unsigned int d_bytespersamp; /* bytes per sample (2 for 16 bit, 4 for 32) */
-} t_oss_dev;
-
-static t_oss_dev linux_dacs[OSS_MAXDEV];
-static t_oss_dev linux_adcs[OSS_MAXDEV];
-static int linux_noutdevs = 0;
-static int linux_nindevs = 0;
-
- /* exported variables */
-float sys_dacsr;
-t_sample *sys_soundout;
-t_sample *sys_soundin;
-
- /* OSS-specific private variables */
-static int oss_blockmode = 1; /* flag to use "blockmode" */
-static int oss_32bit = 0; /* allow 23 bit transfers in OSS */
-static char ossdsp[] = "/dev/dsp%d";
-
- /* don't assume we can turn all 31 bits when doing float-to-fix;
- otherwise some audio drivers (e.g. Midiman/ALSA) wrap around. */
-#define FMAX 0x7ffff000
-#define CLIP32(x) (((x)>FMAX)?FMAX:((x) < -FMAX)?-FMAX:(x))
-
-
-/* ------------- private routines for all APIS ------------------- */
-
-static void linux_flush_all_underflows_to_zero(void)
-{
-/*
- TODO: Implement similar thing for linux (GGeiger)
-
- One day we will figure this out, I hope, because it
- costs CPU time dearly on Intel - LT
- */
- /* union fpc_csr f;
- f.fc_word = get_fpc_csr();
- f.fc_struct.flush = 1;
- set_fpc_csr(f.fc_word);
- */
-}
-
-static int oss_ndev = 0;
-
- /* find out how many OSS devices we have. Since this has to
- open the devices to find out if they're there, we have
- to be called before audio is actually started up. So we
- cache the results, which in effect are the number of available
- devices. */
-void oss_init(void)
-{
- int fd, i;
- static int countedthem = 0;
- if (countedthem)
- return;
- for (i = 0; i < 10; i++)
- {
- char devname[100];
- if (i == 0)
- strcpy(devname, "/dev/dsp");
- else sprintf(devname, "/dev/dsp%d", i);
- if ( (fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1)
- {
- oss_ndev++;
- close(fd);
- }
- else break;
- }
- countedthem = 1;
-}
-
-
-void oss_set32bit( void)
-{
- oss_32bit = 1;
-}
-
-
-typedef struct _multidev {
- int fd;
- int channels;
- int format;
-} t_multidev;
-
-int oss_reset(int fd) {
- int err;
- if ((err = ioctl(fd,SNDCTL_DSP_RESET)) < 0)
- error("OSS: Could not reset");
- return err;
-}
-
- /* The AFMT_S32_BLOCKED format is not defined in standard linux kernels
- but is proposed by Guenter Geiger to support extending OSS to handle
- 32 bit sample. This is user in Geiger's OSS driver for RME Hammerfall.
- I'm not clear why this isn't called AFMT_S32_[SLN]E... */
-
-#ifndef AFMT_S32_BLOCKED
-#define AFMT_S32_BLOCKED 0x0000400
-#endif
-
-void oss_configure(t_oss_dev *dev, int srate, int dac, int skipblocksize)
-{ /* IOhannes */
- int orig, param, nblk, fd = dev->d_fd, wantformat;
- int nchannels = dev->d_nchannels;
- int advwas = sys_schedadvance;
-
- audio_buf_info ainfo;
-
- /* IOhannes :
- * pd is very likely to crash if different formats are used on
- multiple soundcards
- */
-
- /* set resolution - first try 4 byte samples */
- if (oss_32bit && (ioctl(fd,SNDCTL_DSP_GETFMTS,&param) >= 0) &&
- (param & AFMT_S32_BLOCKED))
- {
- wantformat = AFMT_S32_BLOCKED;
- dev->d_bytespersamp = 4;
- }
- else
- {
- wantformat = AFMT_S16_NE;
- dev->d_bytespersamp = 2;
- }
- param = wantformat;
-
- if (sys_verbose)
- post("bytes per sample = %d", dev->d_bytespersamp);
- if (ioctl(fd, SNDCTL_DSP_SETFMT, &param) == -1)
- fprintf(stderr,"OSS: Could not set DSP format\n");
- else if (wantformat != param)
- fprintf(stderr,"OSS: DSP format: wanted %d, got %d\n",
- wantformat, param);
-
- /* sample rate */
- orig = param = srate;
- if (ioctl(fd, SNDCTL_DSP_SPEED, &param) == -1)
- fprintf(stderr,"OSS: Could not set sampling rate for device\n");
- else if( orig != param )
- fprintf(stderr,"OSS: sampling rate: wanted %d, got %d\n",
- orig, param );
-
- if (oss_blockmode && !skipblocksize)
- {
- int fragbytes, logfragsize, nfragment;
- /* setting fragment count and size. */
- if (!linux_fragsize)
- {
- linux_fragsize = OSS_DEFFRAGSIZE;
- while (linux_fragsize > DEFDACBLKSIZE
- && linux_fragsize * 4 > sys_advance_samples)
- linux_fragsize = linux_fragsize/2;
- }
-
- /* post("adv_samples %d", sys_advance_samples); */
- nfragment = (sys_schedadvance * (44100. * 1.e-6)) / linux_fragsize;
-
- fragbytes = linux_fragsize * (dev->d_bytespersamp * nchannels);
- logfragsize = ilog2(fragbytes);
-
- if (fragbytes != (1 << logfragsize))
- post("warning: OSS takes only power of 2 blocksize; using %d",
- (1 << logfragsize)/(dev->d_bytespersamp * nchannels));
- if (sys_verbose)
- post("setting nfrags = %d, fragsize %d\n", nfragment, fragbytes);
-
- param = orig = (nfragment<<16) + logfragsize;
- if (ioctl(fd,SNDCTL_DSP_SETFRAGMENT, &param) == -1)
- error("OSS: Could not set or read fragment size\n");
- if (param != orig)
- {
- nfragment = ((param >> 16) & 0xffff);
- logfragsize = (param & 0xffff);
- post("warning: actual fragments %d, blocksize %d",
- nfragment, (1 << logfragsize));
- }
- if (sys_verbose)
- post("audiobuffer set to %d msec", (int)(0.001 * sys_schedadvance));
- }
- if (dac)
- {
- /* use "free space" to learn the buffer size. Normally you
- should set this to your own desired value; but this seems not
- to be implemented uniformly across different sound cards. LATER
- we should figure out what to do if the requested scheduler advance
- is greater than this buffer size; for now, we just print something
- out. */
-
- int defect;
- if (ioctl(fd, SOUND_PCM_GETOSPACE,&ainfo) < 0)
- fprintf(stderr,"OSS: ioctl on output device failed");
- dev->d_bufsize = ainfo.bytes;
-
- defect = sys_advance_samples * (dev->d_bytespersamp * nchannels)
- - dev->d_bufsize - OSS_XFERSIZE(nchannels, dev->d_bytespersamp);
- if (defect > 0)
- {
- if (sys_verbose || defect > (dev->d_bufsize >> 2))
- fprintf(stderr,
- "OSS: requested audio buffer size %d limited to %d\n",
- sys_advance_samples * (dev->d_bytespersamp * nchannels),
- dev->d_bufsize);
- sys_advance_samples =
- (dev->d_bufsize - OSS_XFERSAMPS(nchannels)) /
- (dev->d_bytespersamp *nchannels);
- }
- }
-}
-
-static int oss_setchannels(int fd, int wantchannels, char *devname)
-{ /* IOhannes */
- int param = wantchannels;
-
- while (param>1) {
- int save = param;
- if (ioctl(fd, SNDCTL_DSP_CHANNELS, &param) == -1) {
- error("OSS: SNDCTL_DSP_CHANNELS failed %s",devname);
- } else {
- if (param == save) return (param);
- }
- param=save-1;
- }
-
- return (0);
-}
-
-#define O_AUDIOFLAG 0 /* O_NDELAY */
-
-int oss_open_audio(int nindev, int *indev, int nchin, int *chin,
- int noutdev, int *outdev, int nchout, int *chout, int rate)
-{ /* IOhannes */
- int capabilities = 0;
- int inchannels = 0, outchannels = 0;
- char devname[20];
- int n, i, fd;
- char buf[OSS_MAXSAMPLEWIDTH * DEFDACBLKSIZE * OSS_MAXCHPERDEV];
- int num_devs = 0;
- int wantmore=0;
- int spread = 0;
- audio_buf_info ainfo;
-
- linux_nindevs = linux_noutdevs = 0;
-
-
- /* mark input devices unopened */
- for (i = 0; i < OSS_MAXDEV; i++)
- linux_adcs[i].d_fd = -1;
-
- /* open output devices */
- wantmore=0;
- if (noutdev < 0 || nindev < 0)
- bug("linux_open_audio");
-
- for (n = 0; n < noutdev; n++)
- {
- int gotchans, j, inindex = -1;
- int thisdevice = (outdev[n] >= 0 ? outdev[n] : n-1);
- int wantchannels = (nchout>n) ? chout[n] : wantmore;
- fd = -1;
- if (!wantchannels)
- goto end_out_loop;
-
- if (thisdevice > 1)
- sprintf(devname, "/dev/dsp%d", thisdevice-1);
- else sprintf(devname, "/dev/dsp");
-
- /* search for input request for same device. Succeed only
- if the number of channels matches. */
- for (j = 0; j < nindev; j++)
- if (indev[j] == thisdevice && chin[j] == wantchannels)
- inindex = j;
-
- /* if the same device is requested for input and output,
- try to open it read/write */
- if (inindex >= 0)
- {
- sys_setalarm(1000000);
- if ((fd = open(devname, O_RDWR | O_AUDIOFLAG)) == -1)
- {
- post("%s (read/write): %s", devname, strerror(errno));
- post("(now will try write-only...)");
- }
- else
- {
- if (sys_verbose)
- post("opened %s for reading and writing\n", devname);
- linux_adcs[inindex].d_fd = fd;
- }
- }
- /* if that didn't happen or if it failed, try write-only */
- if (fd == -1)
- {
- sys_setalarm(1000000);
- if ((fd = open(devname, O_WRONLY | O_AUDIOFLAG)) == -1)
- {
- post("%s (writeonly): %s",
- devname, strerror(errno));
- break;
- }
- if (sys_verbose)
- post("opened %s for writing only\n", devname);
- }
- if (ioctl(fd, SNDCTL_DSP_GETCAPS, &capabilities) == -1)
- error("OSS: SNDCTL_DSP_GETCAPS failed %s", devname);
-
- gotchans = oss_setchannels(fd,
- (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
- devname);
-
- if (sys_verbose)
- post("opened audio output on %s; got %d channels",
- devname, gotchans);
-
- if (gotchans < 2)
- {
- /* can't even do stereo? just give up. */
- close(fd);
- }
- else
- {
- linux_dacs[linux_noutdevs].d_nchannels = gotchans;
- linux_dacs[linux_noutdevs].d_fd = fd;
- oss_configure(linux_dacs+linux_noutdevs, rate, 1, 0);
-
- linux_noutdevs++;
- outchannels += gotchans;
- if (inindex >= 0)
- {
- linux_adcs[inindex].d_nchannels = gotchans;
- chin[inindex] = gotchans;
- }
- }
- /* LATER think about spreading large numbers of channels over
- various dsp's and vice-versa */
- wantmore = wantchannels - gotchans;
- end_out_loop: ;
- }
-
- /* open input devices */
- wantmore = 0;
- for (n = 0; n < nindev; n++)
- {
- int gotchans=0;
- int thisdevice = (indev[n] >= 0 ? indev[n] : n-1);
- int wantchannels = (nchin>n)?chin[n]:wantmore;
- int alreadyopened = 0;
- if (!wantchannels)
- goto end_in_loop;
-
- if (thisdevice > 1)
- sprintf(devname, "/dev/dsp%d", thisdevice - 1);
- else sprintf(devname, "/dev/dsp");
-
- sys_setalarm(1000000);
-
- /* perhaps it's already open from the above? */
- if (linux_dacs[n].d_fd >= 0)
- {
- fd = linux_dacs[n].d_fd;
- alreadyopened = 1;
- }
- else
- {
- /* otherwise try to open it here. */
- if ((fd = open(devname, O_RDONLY | O_AUDIOFLAG)) == -1)
- {
- post("%s (readonly): %s", devname, strerror(errno));
- goto end_in_loop;
- }
- if (sys_verbose)
- post("opened %s for reading only\n", devname);
- }
- linux_adcs[linux_nindevs].d_fd = fd;
- gotchans = oss_setchannels(fd,
- (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
- devname);
- if (sys_verbose)
- post("opened audio input device %s; got %d channels",
- devname, gotchans);
-
- if (gotchans < 1)
- {
- close(fd);
- goto end_in_loop;
- }
-
- linux_adcs[linux_nindevs].d_nchannels = gotchans;
-
- oss_configure(linux_adcs+linux_nindevs, rate, 0, alreadyopened);
-
- inchannels += gotchans;
- linux_nindevs++;
-
- wantmore = wantchannels-gotchans;
- /* LATER think about spreading large numbers of channels over
- various dsp's and vice-versa */
- end_in_loop: ;
- }
-
- /* We have to do a read to start the engine. This is
- necessary because sys_send_dacs waits until the input
- buffer is filled and only reads on a filled buffer.
- This is good, because it's a way to make sure that we
- will not block. But I wonder why we only have to read
- from one of the devices and not all of them??? */
-
- if (linux_nindevs)
- {
- if (sys_verbose)
- fprintf(stderr,("OSS: issuing first ADC 'read' ... "));
- read(linux_adcs[0].d_fd, buf,
- linux_adcs[0].d_bytespersamp *
- linux_adcs[0].d_nchannels * DEFDACBLKSIZE);
- if (sys_verbose)
- fprintf(stderr, "...done.\n");
- }
- sys_setalarm(0);
- return (0);
-}
-
-void oss_close_audio( void)
-{
- int i;
- for (i=0;i<linux_nindevs;i++)
- close(linux_adcs[i].d_fd);
-
- for (i=0;i<linux_noutdevs;i++)
- close(linux_dacs[i].d_fd);
-
- linux_nindevs = linux_noutdevs = 0;
-}
-
-static int linux_dacs_write(int fd,void* buf,long bytes)
-{
- return write(fd, buf, bytes);
-}
-
-static int linux_adcs_read(int fd,void* buf,long bytes)
-{
- return read(fd, buf, bytes);
-}
-
- /* query audio devices for "available" data size. */
-static void oss_calcspace(void)
-{
- int dev;
- audio_buf_info ainfo;
- for (dev=0; dev < linux_noutdevs; dev++)
- {
- if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
- fprintf(stderr,"OSS: ioctl on output device %d failed",dev);
- linux_dacs[dev].d_space = ainfo.bytes;
- }
-
- for (dev = 0; dev < linux_nindevs; dev++)
- {
- if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE,&ainfo) < 0)
- fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
- dev, linux_adcs[dev].d_fd);
- linux_adcs[dev].d_space = ainfo.bytes;
- }
-}
-
-void linux_audiostatus(void)
-{
- int dev;
- if (!oss_blockmode)
- {
- oss_calcspace();
- for (dev=0; dev < linux_noutdevs; dev++)
- fprintf(stderr, "dac %d space %d\n", dev, linux_dacs[dev].d_space);
-
- for (dev = 0; dev < linux_nindevs; dev++)
- fprintf(stderr, "adc %d space %d\n", dev, linux_adcs[dev].d_space);
-
- }
-}
-
-/* this call resyncs audio output and input which will cause discontinuities
-in audio output and/or input. */
-
-static void oss_doresync( void)
-{
- int dev, zeroed = 0, wantsize;
- char buf[OSS_MAXSAMPLEWIDTH * DEFDACBLKSIZE * OSS_MAXCHPERDEV];
- audio_buf_info ainfo;
-
- /* 1. if any input devices are ahead (have more than 1 buffer stored),
- drop one or more buffers worth */
- for (dev = 0; dev < linux_nindevs; dev++)
- {
- if (linux_adcs[dev].d_space == 0)
- {
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp));
- }
- else while (linux_adcs[dev].d_space >
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- {
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp));
- if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE, &ainfo) < 0)
- {
- fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
- dev, linux_adcs[dev].d_fd);
- break;
- }
- linux_adcs[dev].d_space = ainfo.bytes;
- }
- }
-
- /* 2. if any output devices are behind, feed them zeros to catch them
- up */
- for (dev = 0; dev < linux_noutdevs; dev++)
- {
- while (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
- sys_advance_samples * (linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp))
- {
- if (!zeroed)
- {
- unsigned int i;
- for (i = 0; i < OSS_XFERSAMPS(linux_dacs[dev].d_nchannels);
- i++)
- buf[i] = 0;
- zeroed = 1;
- }
- linux_dacs_write(linux_dacs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_dacs[dev].d_nchannels,
- linux_dacs[dev].d_bytespersamp));
- if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
- {
- fprintf(stderr, "OSS: ioctl on output device %d, fd %d failed",
- dev, linux_dacs[dev].d_fd);
- break;
- }
- linux_dacs[dev].d_space = ainfo.bytes;
- }
- }
- /* 3. if any DAC devices are too far ahead, plan to drop the
- number of frames which will let the others catch up. */
- for (dev = 0; dev < linux_noutdevs; dev++)
- {
- if (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
- (sys_advance_samples - 1) * linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp)
- {
- linux_dacs[dev].d_dropcount = sys_advance_samples - 1 -
- (linux_dacs[dev].d_space - linux_dacs[dev].d_bufsize) /
- (linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp) ;
- }
- else linux_dacs[dev].d_dropcount = 0;
- }
-}
-
-int oss_send_dacs(void)
-{
- t_sample *fp1, *fp2;
- long fill;
- int i, j, dev, rtnval = SENDDACS_YES;
- char buf[OSS_MAXSAMPLEWIDTH * DEFDACBLKSIZE * OSS_MAXCHPERDEV];
- t_oss_int16 *sp;
- t_oss_int32 *lp;
- /* the maximum number of samples we should have in the ADC buffer */
- int idle = 0;
- int thischan;
- t_time timeref, timenow;
-
- if (!linux_nindevs && !linux_noutdevs)
- return (SENDDACS_NO);
-
- if (!oss_blockmode)
- {
- /* determine whether we're idle. This is true if either (1)
- some input device has less than one buffer to read or (2) some
- output device has fewer than (sys_advance_samples) blocks buffered
- already. */
- oss_calcspace();
-
- for (dev=0; dev < linux_noutdevs; dev++)
- if (linux_dacs[dev].d_dropcount ||
- (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space >
- sys_advance_samples * linux_dacs[dev].d_bytespersamp *
- linux_dacs[dev].d_nchannels))
- idle = 1;
- for (dev=0; dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space <
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- idle = 1;
- }
-
- if (idle && !oss_blockmode)
- {
- /* sometimes---rarely---when the ADC available-byte-count is
- zero, it's genuine, but usually it's because we're so
- late that the ADC has overrun its entire kernel buffer. We
- distinguish between the two by waiting 2 msec and asking again.
- There should be an error flag we could check instead; look for this
- someday... */
- for (dev = 0;dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space == 0)
- {
- audio_buf_info ainfo;
- sys_microsleep(2000);
- oss_calcspace();
- if (linux_adcs[dev].d_space != 0) continue;
-
- /* here's the bad case. Give up and resync. */
- sys_log_error(ERR_DATALATE);
- oss_doresync();
- return (SENDDACS_NO);
- }
- /* check for slippage between devices, either because
- data got lost in the driver from a previous late condition, or
- because the devices aren't synced. When we're idle, no
- input device should have more than one buffer readable and
- no output device should have less than sys_advance_samples-1
- */
-
- for (dev=0; dev < linux_noutdevs; dev++)
- if (!linux_dacs[dev].d_dropcount &&
- (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space <
- (sys_advance_samples - 2) *
- (linux_dacs[dev].d_bytespersamp *
- linux_dacs[dev].d_nchannels)))
- goto badsync;
- for (dev=0; dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space > 3 *
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- goto badsync;
-
- /* return zero to tell the scheduler we're idle. */
- return (SENDDACS_NO);
- badsync:
- sys_log_error(ERR_RESYNC);
- oss_doresync();
- return (SENDDACS_NO);
-
- }
-
-
- /* do output */
-
- timeref = sys_getrealtime();
- for (dev=0, thischan = 0; dev < linux_noutdevs; dev++)
- {
- int nchannels = linux_dacs[dev].d_nchannels;
- if (linux_dacs[dev].d_dropcount)
- linux_dacs[dev].d_dropcount--;
- else
- {
- if (linux_dacs[dev].d_bytespersamp == 4)
- {
- for (i = DEFDACBLKSIZE * nchannels, fp1 = sys_soundout +
- DEFDACBLKSIZE*thischan,
- lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
- {
- t_sample f = SCALE32(*fp1);
- *lp = (f >= 2147483647 ? 2147483647 :
- (f < -2147483647 ? -2147483647 : f));
- }
- }
- else
- {
- for (i = DEFDACBLKSIZE, fp1 = sys_soundout +
- DEFDACBLKSIZE*thischan,
- sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
- {
- for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += DEFDACBLKSIZE)
- {
- int s = SCALE16(*fp2);
- if (s > 32767) s = 32767;
- else if (s < -32767) s = -32767;
- sp[j] = s;
- }
- }
- }
-
-
-#if 0
-#define PR_S "%8d"
- {
- int nm = 64;
- int* sp1 = buf;
- post("dac:");
- while (nm > 0)
- {
- post(PR_S PR_S PR_S PR_S PR_S PR_S PR_S PR_S,
- sp1[0], sp1[1], sp1[2], sp1[3], sp1[4], sp1[5], sp1[6], sp1[7]);
- nm -= 8;
- sp1 += 8;
- }
- }
-#endif
- linux_dacs_write(linux_dacs[dev].d_fd, buf,
- OSS_XFERSIZE(nchannels, linux_dacs[dev].d_bytespersamp));
-
-#if 0
- if ((timenow = sys_getrealtime()) - timeref > 200)
- {
- post("dacslept %d",sys_getrealtime() - timeref);
- if (!oss_blockmode)
- sys_log_error(ERR_DACSLEPT);
- else rtnval = SENDDACS_SLEPT;
- }
-#endif
- timeref = timenow;
- }
- thischan += nchannels;
- }
- memset(sys_soundout, 0,
- sys_outchannels * (sizeof(float) * DEFDACBLKSIZE));
-
- /* do input */
-
- for (dev = 0, thischan = 0; dev < linux_nindevs; dev++)
- {
- int nchannels = linux_adcs[dev].d_nchannels;
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(nchannels, linux_adcs[dev].d_bytespersamp));
-
-#if 0
- if ((timenow = sys_getrealtime()) - timeref > 200)
- {
- if (!oss_blockmode)
- sys_log_error(ERR_ADCSLEPT);
- else
- rtnval = SENDDACS_SLEPT;
- }
-#endif
- timeref = timenow;
-
- if (linux_adcs[dev].d_bytespersamp == 4)
- {
- for (i = DEFDACBLKSIZE*nchannels,
- fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
- lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
- {
- *fp1 = ((t_sample)(*lp))*(t_sample)(1./2147483648.);
- }
- }
- else
- {
- for (i = DEFDACBLKSIZE,fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
- sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
- {
- for (j=0;j<sys_inchannels;j++)
- fp1[j*DEFDACBLKSIZE] = INVSCALE16(sp[j]);
- }
- }
- thischan += nchannels;
- }
- if (thischan != sys_inchannels)
- bug("inchannels");
- return (rtnval);
-}
-
-void oss_listdevs( void)
-{
- post("device listing not implemented in OSS yet\n");
-}
-
-void oss_getdevs(char *indevlist, int *nindevs,
- char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
-{
- int i, ndev;
- *canmulti = 2; /* supports multiple devices */
- if ((ndev = oss_ndev) > maxndev)
- ndev = maxndev;
- for (i = 0; i < ndev; i++)
- {
- sprintf(indevlist + i * devdescsize, "OSS device #%d", i+1);
- sprintf(outdevlist + i * devdescsize, "OSS device #%d", i+1);
- }
- *nindevs = *noutdevs = ndev;
-}
-
-#endif
-
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_pa.c b/apps/plugins/pdbox/PDa/src/s_audio_pa.c
deleted file mode 100644
index 943b57e212..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_audio_pa.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/* Copyright (c) 2001 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* this file calls Ross Bencina's and Phil Burk's Portaudio package. It's
- the main way in for Mac OS and, with Michael Casey's help, also into
- ASIO in Windows. */
-
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include "portaudio.h"
-#include "pablio_pd.h"
-
- /* LATER try to figure out how to handle default devices in portaudio;
- the way s_audio.c handles them isn't going to work here. */
-
-#if defined(MACOSX) || defined(MSW)
-#define Pa_GetDefaultInputDevice Pa_GetDefaultInputDeviceID
-#define Pa_GetDefaultOutputDevice Pa_GetDefaultOutputDeviceID
-#endif
-
- /* public interface declared in m_imp.h */
-
- /* implementation */
-static PABLIO_Stream *pa_stream;
-static int pa_inchans, pa_outchans;
-static float *pa_soundin, *pa_soundout;
-
-#define MAX_PA_CHANS 32
-#define MAX_SAMPLES_PER_FRAME MAX_PA_CHANS * DEFDACBLKSIZE
-
-int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
- t_sample *soundout, int framesperbuf, int nbuffers,
- int indeviceno, int outdeviceno)
-{
- PaError err;
- static int initialized;
- int j, devno, pa_indev = 0, pa_outdev = 0;
-
- if (!initialized)
- {
- /* Initialize PortAudio */
- int err = Pa_Initialize();
- if ( err != paNoError )
- {
- fprintf( stderr,
- "Error number %d occured initializing portaudio\n",
- err);
- fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
- return (1);
- }
- initialized = 1;
- }
- /* post("in %d out %d rate %d device %d", inchans, outchans, rate, deviceno); */
- if (inchans != 0 && outchans != 0 && inchans != outchans)
- error("portaudio: number of input and output channels must match");
- if (inchans > MAX_PA_CHANS)
- {
- post("input channels reduced to maximum %d", MAX_PA_CHANS);
- inchans = MAX_PA_CHANS;
- }
- if (outchans > MAX_PA_CHANS)
- {
- post("output channels reduced to maximum %d", MAX_PA_CHANS);
- outchans = MAX_PA_CHANS;
- }
-
- if (inchans > 0)
- {
- for (j = 0, devno = 0; j < Pa_CountDevices(); j++)
- {
- const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
- if (info->maxInputChannels > 0)
- {
- if (devno == indeviceno)
- {
- pa_indev = j;
- break;
- }
- devno++;
- }
- }
- }
-
- if (outchans > 0)
- {
- for (j = 0, devno = 0; j < Pa_CountDevices(); j++)
- {
- const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
- if (info->maxOutputChannels > 0)
- {
- if (devno == outdeviceno)
- {
- pa_outdev = j;
- break;
- }
- devno++;
- }
- }
- }
-
- if (sys_verbose)
- {
- post("input device %d, channels %d", pa_indev, inchans);
- post("output device %d, channels %d", pa_outdev, outchans);
- post("framesperbuf %d, nbufs %d", framesperbuf, nbuffers);
- }
- if (inchans && outchans)
- err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_READ_WRITE, inchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
- else if (inchans)
- err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_READ, inchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
- else if (outchans)
- err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_WRITE, outchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
- else err = 0;
- if ( err != paNoError )
- {
- fprintf( stderr, "Error number %d occured opening portaudio stream\n",
- err);
- fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
- Pa_Terminate();
- sys_inchannels = sys_outchannels = 0;
- return (1);
- }
- else if (sys_verbose)
- post("... opened OK.");
- pa_inchans = inchans;
- pa_outchans = outchans;
- pa_soundin = soundin;
- pa_soundout = soundout;
- return (0);
-}
-
-void pa_close_audio( void)
-{
- if (pa_inchans || pa_outchans)
- CloseAudioStream( pa_stream );
- pa_inchans = pa_outchans = 0;
-}
-
-int pa_send_dacs(void)
-{
- float samples[MAX_SAMPLES_PER_FRAME], *fp1, *fp2;
- int i, j;
- double timebefore;
-
- timebefore = sys_getrealtime();
- if ((pa_inchans && GetAudioStreamReadable(pa_stream) < DEFDACBLKSIZE) ||
- (pa_outchans && GetAudioStreamWriteable(pa_stream) < DEFDACBLKSIZE))
- {
- if (pa_inchans && pa_outchans)
- {
- int synced = 0;
- while (GetAudioStreamWriteable(pa_stream) > 2*DEFDACBLKSIZE)
- {
- for (j = 0; j < pa_outchans; j++)
- for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
- fp2 += pa_outchans)
- {
- *fp2 = 0;
- }
- synced = 1;
- WriteAudioStream(pa_stream, samples, DEFDACBLKSIZE);
- }
- while (GetAudioStreamReadable(pa_stream) > 2*DEFDACBLKSIZE)
- {
- synced = 1;
- ReadAudioStream(pa_stream, samples, DEFDACBLKSIZE);
- }
- /* if (synced)
- post("sync"); */
- }
- return (SENDDACS_NO);
- }
- if (pa_inchans)
- {
- ReadAudioStream(pa_stream, samples, DEFDACBLKSIZE);
- for (j = 0, fp1 = pa_soundin; j < pa_inchans; j++, fp1 += DEFDACBLKSIZE)
- for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
- fp2 += pa_inchans)
- {
- fp1[i] = *fp2;
- }
- }
-#if 0
- {
- static int nread;
- if (nread == 0)
- {
- post("it's %f %f %f %f",
- pa_soundin[0], pa_soundin[1], pa_soundin[2], pa_soundin[3]);
- nread = 1000;
- }
- nread--;
- }
-#endif
- if (pa_outchans)
- {
- for (j = 0, fp1 = pa_soundout; j < pa_outchans; j++,
- fp1 += DEFDACBLKSIZE)
- for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
- fp2 += pa_outchans)
- {
- *fp2 = fp1[i];
- fp1[i] = 0;
- }
- WriteAudioStream(pa_stream, samples, DEFDACBLKSIZE);
- }
-
- if (sys_getrealtime() > timebefore + 0.002)
- {
- /* post("slept"); */
- return (SENDDACS_SLEPT);
- }
- else return (SENDDACS_YES);
-}
-
-
-void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */
-{
- int i,j;
- int numDevices;
- const PaDeviceInfo *pdi;
- PaError err;
- Pa_Initialize();
- numDevices = Pa_CountDevices();
- if( numDevices < 0 )
- {
- fprintf(stderr, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
- err = numDevices;
- goto error;
- }
- fprintf(stderr, "Audio Devices:\n");
- for( i=0; i<numDevices; i++ )
- {
- pdi = Pa_GetDeviceInfo( i );
- fprintf(stderr, "device %d:", i+1 );
- fprintf(stderr, " %s;", pdi->name );
- fprintf(stderr, "%d inputs, ", pdi->maxInputChannels );
- fprintf(stderr, "%d outputs", pdi->maxOutputChannels );
- if ( i == Pa_GetDefaultInputDevice() )
- fprintf(stderr, " (Default Input)");
- if ( i == Pa_GetDefaultOutputDevice() )
- fprintf(stderr, " (Default Output)");
- fprintf(stderr, "\n");
- }
-
- fprintf(stderr, "\n");
- return;
-
-error:
- fprintf( stderr, "An error occured while using the portaudio stream\n" );
- fprintf( stderr, "Error number: %d\n", err );
- fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
-
-}
-
- /* scanning for devices */
-void pa_getdevs(char *indevlist, int *nindevs,
- char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
-{
- int i, nin = 0, nout = 0, ndev;
- *canmulti = 1; /* one dev each for input and output */
-
- Pa_Initialize();
- ndev = Pa_CountDevices();
- for (i = 0; i < ndev; i++)
- {
- const PaDeviceInfo *pdi = Pa_GetDeviceInfo(i);
- if (pdi->maxInputChannels > 0 && nin < maxndev)
- {
- strcpy(indevlist + nin * devdescsize, pdi->name);
- nin++;
- }
- if (pdi->maxOutputChannels > 0 && nout < maxndev)
- {
- strcpy(outdevlist + nout * devdescsize, pdi->name);
- nout++;
- }
- }
- *nindevs = nin;
- *noutdevs = nout;
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_entry.c b/apps/plugins/pdbox/PDa/src/s_entry.c
deleted file mode 100644
index fd7b4c52fa..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_entry.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* In MSW, this is all there is to pd; the rest sits in a "pdlib" dll so
-that externs can link back to functions defined in pd. */
-
-#include <stdio.h>
-
-int sys_main(int argc, char **argv);
-
- /* WINBASEAPI PVOID WINAPI AddVectoredExceptionHandler(
- ULONG FirstHandler,
- PVECTORED_EXCEPTION_HANDLER VectoredHandler ); */
-
-#ifdef MSW
-#if 0
-#incldue "winbase.h"
-
-LONG NTAPI VectoredExceptionHandler(void *PEXCEPTION_POINTERS)
-{
- fprintf(stderr, "caught exception\n");
- return(EXCEPTION_CONTINUE_SEARCH);
-}
-
-
-int main(int argc, char **argv)
-{
- printf("Pd entry point\n");
- AddVectoredExceptionHandler(
- ULONG FirstHandler,
- PVECTORED_EXCEPTION_HANDLER VectoredHandler );
-
-
-#endif
-
-#if 1
-int main(int argc, char **argv)
-{
- __try
- {
- sys_main(argc, argv);
- }
- __finally
- {
- printf("caught an exception; stopping\n");
- }
-}
-#endif
-#else /* not MSW */
-int main(int argc, char **argv)
-{
- return (sys_main(argc, argv));
-}
-#endif
-
diff --git a/apps/plugins/pdbox/PDa/src/s_inter.c b/apps/plugins/pdbox/PDa/src/s_inter.c
deleted file mode 100644
index 9df9c82b40..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_inter.c
+++ /dev/null
@@ -1,1000 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* Pd side of the Pd/Pd-gui interface. Also, some system interface routines
-that didn't really belong anywhere. */
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include "m_imp.h"
-#ifdef UNIX
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <sys/mman.h>
-#endif
-#ifdef HAVE_BSTRING_H
-#include <bstring.h>
-#endif
-#ifdef MSW
-#include <io.h>
-#include <fcntl.h>
-#include <process.h>
-#include <winsock.h>
-typedef int pid_t;
-#define EADDRINUSE WSAEADDRINUSE
-#endif
-#include <stdarg.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-
-#ifdef MACOSX
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pthread.h>
-#else
-#include <stdlib.h>
-#endif
-
-#define DEBUG_MESSUP 1 /* messages up from pd to pd-gui */
-#define DEBUG_MESSDOWN 2 /* messages down from pd-gui to pd */
-
-/* T.Grill - make it a _little_ more adaptable... */
-#ifndef PDBINDIR
-#define PDBINDIR "bin/"
-#endif
-
-#ifndef WISHAPP
-#define WISHAPP "wish83.exe"
-#endif
-
-extern char pd_version[];
-
-typedef struct _fdpoll
-{
- int fdp_fd;
- t_fdpollfn fdp_fn;
- void *fdp_ptr;
-} t_fdpoll;
-
-#define INBUFSIZE 4096
-
-struct _socketreceiver
-{
- char *sr_inbuf;
- int sr_inhead;
- int sr_intail;
- void *sr_owner;
- int sr_udp;
- t_socketnotifier sr_notifier;
- t_socketreceivefn sr_socketreceivefn;
-};
-
-static int sys_nfdpoll;
-static t_fdpoll *sys_fdpoll;
-static int sys_maxfd;
-static int sys_guisock;
-
-static t_binbuf *inbinbuf;
-static t_socketreceiver *sys_socketreceiver;
-extern int sys_addhist(int phase);
-
-#ifdef MSW
-static LARGE_INTEGER nt_inittime;
-static double nt_freq = 0;
-
-static void sys_initntclock(void)
-{
- LARGE_INTEGER f1;
- LARGE_INTEGER now;
- QueryPerformanceCounter(&now);
- if (!QueryPerformanceFrequency(&f1))
- {
- fprintf(stderr, "pd: QueryPerformanceFrequency failed\n");
- f1.QuadPart = 1;
- }
- nt_freq = f1.QuadPart;
- nt_inittime = now;
-}
-
-#if 0
- /* this is a version you can call if you did the QueryPerformanceCounter
- call yourself. Necessary for time tagging incoming MIDI at interrupt
- level, for instance; but we're not doing that just now. */
-
-double nt_tixtotime(LARGE_INTEGER *dumbass)
-{
- if (nt_freq == 0) sys_initntclock();
- return (((double)(dumbass->QuadPart - nt_inittime.QuadPart)) / nt_freq);
-}
-#endif
-#endif /* MSW */
-
- /* get "real time" in seconds; take the
- first time we get called as a reference time of zero. */
-t_time sys_getrealtime(void)
-{
-#ifdef UNIX
- static struct timeval then;
- struct timeval now;
- gettimeofday(&now, 0);
- if (then.tv_sec == 0 && then.tv_usec == 0) then = now;
- return (now.tv_sec - then.tv_sec)*1000000 +
- (now.tv_usec - then.tv_usec);
-#endif
-#ifdef MSW
- LARGE_INTEGER now;
- QueryPerformanceCounter(&now);
- if (nt_freq == 0) sys_initntclock();
- return (((double)(now.QuadPart - nt_inittime.QuadPart)) / nt_freq);
-#endif
-}
-
-void sys_sockerror(char *s)
-{
-#ifdef MSW
- int err = WSAGetLastError();
- if (err == 10054) return;
- else if (err == 10044)
- {
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
- fprintf(stderr, "which is needed for Pd to talk to its GUI layer.\n");
- }
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
- fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
-}
-
-void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr)
-{
- int nfd = sys_nfdpoll;
- int size = nfd * sizeof(t_fdpoll);
- t_fdpoll *fp;
- sys_fdpoll = (t_fdpoll *)t_resizebytes(sys_fdpoll, size,
- size + sizeof(t_fdpoll));
- fp = sys_fdpoll + nfd;
- fp->fdp_fd = fd;
- fp->fdp_fn = fn;
- fp->fdp_ptr = ptr;
- sys_nfdpoll = nfd + 1;
- if (fd >= sys_maxfd) sys_maxfd = fd + 1;
-}
-
-void sys_rmpollfn(int fd)
-{
- int nfd = sys_nfdpoll;
- int i, size = nfd * sizeof(t_fdpoll);
- t_fdpoll *fp;
- for (i = nfd, fp = sys_fdpoll; i--; fp++)
- {
- if (fp->fdp_fd == fd)
- {
- while (i--)
- {
- fp[0] = fp[1];
- fp++;
- }
- sys_fdpoll = (t_fdpoll *)t_resizebytes(sys_fdpoll, size,
- size - sizeof(t_fdpoll));
- sys_nfdpoll = nfd - 1;
- return;
- }
- }
- post("warning: %d removed from poll list but not found", fd);
-}
-
-static int sys_domicrosleep(int microsec, int pollem)
-{
- struct timeval timout;
- int i, didsomething = 0;
- t_fdpoll *fp;
- timout.tv_sec = 0;
- timout.tv_usec = microsec;
- if (pollem)
- {
- fd_set readset, writeset, exceptset;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++)
- FD_SET(fp->fdp_fd, &readset);
- select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout);
- for (i = 0; i < sys_nfdpoll; i++)
- if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
- {
- (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd);
- didsomething = 1;
- }
- return (didsomething);
- }
- else
- {
- select(0, 0, 0, 0, &timout);
- return (0);
- }
-}
-
-void sys_microsleep(int microsec)
-{
- sys_domicrosleep(microsec, 1);
-}
-
-t_socketreceiver *socketreceiver_new(void *owner, t_socketnotifier notifier,
- t_socketreceivefn socketreceivefn, int udp)
-{
- t_socketreceiver *x = (t_socketreceiver *)getbytes(sizeof(*x));
- x->sr_inhead = x->sr_intail = 0;
- x->sr_owner = owner;
- x->sr_notifier = notifier;
- x->sr_socketreceivefn = socketreceivefn;
- x->sr_udp = udp;
- if (!(x->sr_inbuf = malloc(INBUFSIZE))) bug("t_socketreceiver");;
- return (x);
-}
-
-void socketreceiver_free(t_socketreceiver *x)
-{
- free(x->sr_inbuf);
- freebytes(x, sizeof(*x));
-}
-
- /* this is in a separately called subroutine so that the buffer isn't
- sitting on the stack while the messages are getting passed. */
-static int socketreceiver_doread(t_socketreceiver *x)
-{
- char messbuf[INBUFSIZE], *bp = messbuf;
- int indx;
- int inhead = x->sr_inhead;
- int intail = x->sr_intail;
- char *inbuf = x->sr_inbuf;
- if (intail == inhead) return (0);
- for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1))
- {
- /* if we hit a semi that isn't preceeded by a \, it's a message
- boundary. LATER we should deal with the possibility that the
- preceeding \ might itself be escaped! */
- char c = *bp++ = inbuf[indx];
- if (c == ';' && (!indx || inbuf[indx-1] != '\\'))
- {
- intail = (indx+1)&(INBUFSIZE-1);
- binbuf_text(inbinbuf, messbuf, bp - messbuf);
- if (sys_debuglevel & DEBUG_MESSDOWN)
- {
- write(2, messbuf, bp - messbuf);
- write(2, "\n", 1);
- }
- x->sr_inhead = inhead;
- x->sr_intail = intail;
- return (1);
- }
- }
- return (0);
-}
-
-static void socketreceiver_getudp(t_socketreceiver *x, int fd)
-{
- char buf[INBUFSIZE+1];
- int ret = recv(fd, buf, INBUFSIZE, 0);
- if (ret < 0)
- {
- sys_sockerror("recv");
- sys_rmpollfn(fd);
- sys_closesocket(fd);
- }
- else if (ret > 0)
- {
- buf[ret] = 0;
-#if 0
- post("%s", buf);
-#endif
- if (buf[ret-1] != '\n')
- {
-#if 0
- buf[ret] = 0;
- error("dropped bad buffer %s\n", buf);
-#endif
- }
- else
- {
- char *semi = strchr(buf, ';');
- if (semi)
- *semi = 0;
- binbuf_text(inbinbuf, buf, strlen(buf));
- outlet_setstacklim();
- if (x->sr_socketreceivefn)
- (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
- else bug("socketreceiver_getudp");
- }
- }
-}
-
-
-
-#include <termios.h>
-#include <string.h>
-
-static struct termios stored_settings;
-EXTERN int sys_stdin;
-
-void set_keypress(void)
-{
- struct termios new_settings;
-
- tcgetattr(0,&stored_settings);
-
- new_settings = stored_settings;
-
- /* Disable canonical mode, and set buffer size to 1 byte */
- new_settings.c_lflag &= (~ICANON);
- new_settings.c_cc[VTIME] = 0;
- new_settings.c_cc[VMIN] = 1;
-
-/* echo off */
- new_settings.c_lflag &= (~ECHO);
-
- tcsetattr(0,TCSANOW,&new_settings);
- return;
-}
-
-void reset_keypress(void)
-{
- if (sys_stdin)
- tcsetattr(0,TCSANOW,&stored_settings);
- return;
-}
-
-static t_symbol* _ss;
-
-
-void stdin_read(t_socketreceiver *x, int fd) {
- static char input[256];
-
- char* in;
- int got;
-
- got = read(fd,input,256);
- in = input;
- while (got-- && _ss->s_thing)
- pd_float(_ss->s_thing,(float)*in++);
-}
-
-void socketreceiver_read(t_socketreceiver *x, int fd)
-{
- if (x->sr_udp) /* UDP ("datagram") socket protocol */
- socketreceiver_getudp(x, fd);
- else /* TCP ("streaming") socket protocol */
- {
- char *semi;
- int readto =
- (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
- int ret;
-
- /* the input buffer might be full. If so, drop the whole thing */
- if (readto == x->sr_inhead)
- {
- fprintf(stderr, "pd: dropped message from gui\n");
- x->sr_inhead = x->sr_intail = 0;
- readto = INBUFSIZE;
- }
- else
- {
- ret = recv(fd, x->sr_inbuf + x->sr_inhead,
- readto - x->sr_inhead, 0);
- if (ret < 0)
- {
- sys_sockerror("recv");
- if (x == sys_socketreceiver) sys_bail(1);
- else
- {
- if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
- sys_rmpollfn(fd);
- sys_closesocket(fd);
- }
- }
- else if (ret == 0)
- {
- if (x == sys_socketreceiver)
- {
- fprintf(stderr, "pd: exiting\n");
- sys_bail(0);
- }
- else
- {
- post("EOF on socket %d\n", fd);
- if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
- sys_rmpollfn(fd);
- sys_closesocket(fd);
- }
- }
- else
- {
- x->sr_inhead += ret;
- if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
- while (socketreceiver_doread(x))
- {
- outlet_setstacklim();
- if (x->sr_socketreceivefn)
- (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
- else binbuf_eval(inbinbuf, 0, 0, 0);
- }
- }
- }
- }
-}
-
-void sys_closesocket(int fd)
-{
-#ifdef UNIX
- close(fd);
-#endif
-#ifdef MSW
- closesocket(fd);
-#endif
-}
-
-
-void sys_gui(char *s)
-{
- int length = strlen(s), written = 0, res, histwas = sys_addhist(4);
- if (sys_debuglevel & DEBUG_MESSUP)
- fprintf(stderr, "%s", s);
- if (sys_nogui)
- return;
- while (1)
- {
- res = send(sys_guisock, s + written, length, 0);
- if (res < 0)
- {
- perror("pd output pipe");
- sys_bail(1);
- }
- else
- {
- written += res;
- if (written >= length)
- break;
- }
- }
- sys_addhist(histwas);
-}
-
-/* LATER should do a bounds check -- but how do you get printf to do that?
- See also rtext_senditup() in this regard */
-
-void sys_vgui(char *fmt, ...)
-{
- int result, i;
- char buf[2048];
- va_list ap;
-
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- sys_gui(buf);
- va_end(ap);
-}
-
-
-#define FIRSTPORTNUM 5400
-
-/* -------------- signal handling for UNIX -------------- */
-
-#ifdef UNIX
-typedef void (*sighandler_t)(int);
-
-static void sys_signal(int signo, sighandler_t sigfun)
-{
- struct sigaction action;
- action.sa_flags = 0;
- action.sa_handler = sigfun;
- memset(&action.sa_mask, 0, sizeof(action.sa_mask));
-#if 0 /* GG says: don't use that */
- action.sa_restorer = 0;
-#endif
- if (sigaction(signo, &action, 0) < 0)
- perror("sigaction");
-}
-
-static void sys_exithandler(int n)
-{
- static int trouble = 0;
- if (!trouble)
- {
- trouble = 1;
- fprintf(stderr, "Pd: signal %d\n", n);
- sys_bail(1);
-
- }
- else _exit(1);
-}
-
-static void sys_alarmhandler(int n)
-{
- fprintf(stderr, "Pd: system call timed out\n");
-}
-
-static void sys_huphandler(int n)
-{
- struct timeval timout;
- timout.tv_sec = 0;
- timout.tv_usec = 30000;
- select(1, 0, 0, 0, &timout);
-}
-
-void sys_setalarm(int microsec)
-{
- struct itimerval gonzo;
-#if 0
- fprintf(stderr, "timer %d\n", microsec);
-#endif
- gonzo.it_interval.tv_sec = 0;
- gonzo.it_interval.tv_usec = 0;
- gonzo.it_value.tv_sec = 0;
- gonzo.it_value.tv_usec = microsec;
- if (microsec)
- sys_signal(SIGALRM, sys_alarmhandler);
- else sys_signal(SIGALRM, SIG_IGN);
- setitimer(ITIMER_REAL, &gonzo, 0);
-}
-
-#endif
-
-#ifdef __linux__
-
-#if defined(_POSIX_PRIORITY_SCHEDULING) || defined(_POSIX_MEMLOCK)
-#include <sched.h>
-#endif
-
-void sys_set_priority(int higher)
-{
-#ifdef _POSIX_PRIORITY_SCHEDULING
- struct sched_param par;
- int p1 ,p2, p3;
- p1 = sched_get_priority_min(SCHED_FIFO);
- p2 = sched_get_priority_max(SCHED_FIFO);
-#ifdef USEAPI_JACK
- p3 = (higher ? p1 + 7 : p1 + 5);
-#else
- p3 = (higher ? p2 - 1 : p2 - 3);
-#endif
- par.sched_priority = p3;
- if (sched_setscheduler(0,SCHED_FIFO,&par) != -1)
- fprintf(stderr, "priority %d scheduling enabled.\n", p3);
-#endif
-
-#ifdef _POSIX_MEMLOCK
- if (mlockall(MCL_FUTURE) != -1)
- fprintf(stderr, "memory locking enabled.\n");
-#endif
-
-}
-
-#endif /* __linux__ */
-
-static int sys_watchfd;
-
-#ifdef __linux__
-void glob_ping(t_pd *dummy)
-{
- if (write(sys_watchfd, "\n", 1) < 1)
- {
- fprintf(stderr, "pd: watchdog process died\n");
- sys_bail(1);
- }
-}
-#endif
-
-static int defaultfontshit[] = {
- 8, 5, 9, 10, 6, 10, 12, 7, 13, 14, 9, 17, 16, 10, 19, 24, 15, 28,
- 24, 15, 28};
-
-int sys_startgui(const char *guidir)
-{
- pid_t childpid;
- char cmdbuf[4*MAXPDSTRING];
- struct sockaddr_in server;
- int msgsock;
- char buf[15];
- int len = sizeof(server);
- int ntry = 0, portno = FIRSTPORTNUM;
- int xsock = -1;
-#ifdef MSW
- short version = MAKEWORD(2, 0);
- WSADATA nobby;
-#endif
-#ifdef UNIX
- int stdinpipe[2];
-#endif
- /* create an empty FD poll list */
- sys_fdpoll = (t_fdpoll *)t_getbytes(0);
- sys_nfdpoll = 0;
- inbinbuf = binbuf_new();
-
-#ifdef UNIX
- signal(SIGHUP, sys_huphandler);
- signal(SIGINT, sys_exithandler);
- signal(SIGQUIT, sys_exithandler);
- signal(SIGILL, sys_exithandler);
- signal(SIGIOT, sys_exithandler);
- signal(SIGFPE, SIG_IGN);
- /* signal(SIGILL, sys_exithandler);
- signal(SIGBUS, sys_exithandler);
- signal(SIGSEGV, sys_exithandler); */
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, SIG_IGN);
- signal(SIGTERM, SIG_IGN);
-#if 0 /* GG says: don't use that */
- signal(SIGSTKFLT, sys_exithandler);
-#endif
-#endif
-#ifdef MSW
- if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup");
-#endif
-
- if (sys_nogui)
- {
- /* fake the GUI's message giving cwd and font sizes; then
- skip starting the GUI up. */
- t_atom zz[19];
- int i;
-#ifdef MSW
- if (GetCurrentDirectory(MAXPDSTRING, cmdbuf) == 0)
- strcpy(cmdbuf, ".");
-#endif
-#ifdef UNIX
- if (!getcwd(cmdbuf, MAXPDSTRING))
- strcpy(cmdbuf, ".");
-
-#endif
- SETSYMBOL(zz, gensym(cmdbuf));
- for (i = 1; i < 22; i++)
- SETFLOAT(zz + i, defaultfontshit[i-1]);
- SETFLOAT(zz+22,0);
- glob_initfromgui(0, 0, 23, zz);
- }
- else
- {
-#ifdef MSW
- char scriptbuf[MAXPDSTRING+30], wishbuf[MAXPDSTRING+30], portbuf[80];
- int spawnret;
-
-#endif
-#ifdef MSW
- char intarg;
-#else
- int intarg;
-#endif
-
- /* create a socket */
- xsock = socket(AF_INET, SOCK_STREAM, 0);
- if (xsock < 0) sys_sockerror("socket");
-#if 0
- intarg = 0;
- if (setsockopt(xsock, SOL_SOCKET, SO_SNDBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
- intarg = 0;
- if (setsockopt(xsock, SOL_SOCKET, SO_RCVBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
-#endif
- intarg = 1;
- if (setsockopt(xsock, IPPROTO_TCP, TCP_NODELAY,
- &intarg, sizeof(intarg)) < 0)
-#ifndef MSW
- post("setsockopt (TCP_NODELAY) failed\n")
-#endif
- ;
-
-
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = INADDR_ANY;
-
- /* assign server port number */
- server.sin_port = htons((unsigned short)portno);
-
- /* name the socket */
- while (bind(xsock, (struct sockaddr *)&server, sizeof(server)) < 0)
- {
-#ifdef MSW
- int err = WSAGetLastError();
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
- if ((ntry++ > 20) || (err != EADDRINUSE))
- {
- perror("bind");
- fprintf(stderr,
- "Pd needs your machine to be configured with\n");
- fprintf(stderr,
- "'networking' turned on (see Pd's html doc for details.)\n");
- exit(1);
- }
- portno++;
- server.sin_port = htons((unsigned short)(portno));
- }
-
- if (sys_verbose) fprintf(stderr, "port %d\n", portno);
-
- sys_socketreceiver = socketreceiver_new(0, 0, 0, 0);
-
-#ifdef UNIX
- childpid = fork();
- if (childpid < 0)
- {
- if (errno) perror("sys_startgui");
- else fprintf(stderr, "sys_startgui failed\n");
- return (1);
- }
- else if (!childpid) /* we're the child */
- {
- seteuid(getuid()); /* lose setuid priveliges */
-#ifndef MACOSX
- /* the wish process in Unix will make a wish shell and
- read/write standard in and out unless we close the
- file descriptors. Somehow this doesn't make the MAC OSX
- version of Wish happy...*/
- if (pipe(stdinpipe) < 0)
- sys_sockerror("pipe");
- else
- {
- if (stdinpipe[0] != 0)
- {
- close (0);
- dup2(stdinpipe[0], 0);
- close(stdinpipe[0]);
- }
- }
-#endif
- if (!sys_guicmd)
- {
-#ifdef MACOSX
- char *homedir = getenv("HOME"), filename[250];
- struct stat statbuf;
- if (!homedir || strlen(homedir) > 150)
- goto nohomedir;
- sprintf(filename,
- "%s/Applications/Utilities/Wish shell.app/Contents/MacOS/Wish Shell",
- homedir);
- if (stat(filename, &statbuf) >= 0)
- goto foundit;
- sprintf(filename,
- "%s/Applications/Wish shell.app/Contents/MacOS/Wish Shell",
- homedir);
- if (stat(filename, &statbuf) >= 0)
- goto foundit;
- nohomedir:
- strcpy(filename,
- "/Applications/Utilities/Wish Shell.app/Contents/MacOS/Wish Shell");
- if (stat(filename, &statbuf) >= 0)
- goto foundit;
- strcpy(filename,
- "/Applications/Wish Shell.app/Contents/MacOS/Wish Shell");
- foundit:
- sprintf(cmdbuf, "\"%s\" %s/pd.tk %d\n", filename, guidir, portno);
-#else
- sprintf(cmdbuf,
-"TCL_LIBRARY=\"%s/tcl/library\" TK_LIBRARY=\"%s/tk/library\" \
- \"%s/pd-gui\" %d\n",
- sys_libdir->s_name, sys_libdir->s_name, guidir, portno);
-#endif
- sys_guicmd = cmdbuf;
- }
- if (sys_verbose) fprintf(stderr, "%s", sys_guicmd);
- execl("/bin/sh", "sh", "-c", sys_guicmd, 0);
- perror("pd: exec");
- _exit(1);
- }
-#endif /* UNIX */
-
-#ifdef MSW
- /* in MSW land "guipath" is unused; we just do everything from
- the libdir. */
- /* fprintf(stderr, "%s\n", sys_libdir->s_name); */
-
- strcpy(scriptbuf, "\"");
- strcat(scriptbuf, sys_libdir->s_name);
- strcat(scriptbuf, "/" PDBINDIR "pd.tk\"");
- sys_bashfilename(scriptbuf, scriptbuf);
-
- sprintf(portbuf, "%d", portno);
-
- strcpy(wishbuf, sys_libdir->s_name);
- strcat(wishbuf, "/" PDBINDIR WISHAPP);
- sys_bashfilename(wishbuf, wishbuf);
-
- spawnret = _spawnl(P_NOWAIT, wishbuf, WISHAPP, scriptbuf, portbuf, 0);
- if (spawnret < 0)
- {
- perror("spawnl");
- fprintf(stderr, "%s: couldn't load TCL\n", wishbuf);
- exit(1);
- }
-
-#endif /* MSW */
- }
-
-#ifdef __linux__
- /* now that we've spun off the child process we can promote
- our process's priority, if we happen to be root. */
- if (sys_hipriority)
- {
- if (!getuid() || !geteuid())
- {
- /* To prevent lockup, we fork off a watchdog process with
- higher real-time priority than ours. The GUI has to send
- a stream of ping messages to the watchdog THROUGH the Pd
- process which has to pick them up from the GUI and forward
- them. If any of these things aren't happening the watchdog
- starts sending "stop" and "cont" signals to the Pd process
- to make it timeshare with the rest of the system. (Version
- 0.33P2 : if there's no GUI, the watchdog pinging is done
- from the scheduler idle routine in this process instead.) */
-
- int pipe9[2], watchpid;
- if (pipe(pipe9) < 0)
- {
- seteuid(getuid()); /* lose setuid priveliges */
- sys_sockerror("pipe");
- return (1);
- }
- watchpid = fork();
- if (watchpid < 0)
- {
- seteuid(getuid()); /* lose setuid priveliges */
- if (errno)
- perror("sys_startgui");
- else fprintf(stderr, "sys_startgui failed\n");
- return (1);
- }
- else if (!watchpid) /* we're the child */
- {
- sys_set_priority(1);
- seteuid(getuid()); /* lose setuid priveliges */
- if (pipe9[1] != 0)
- {
- dup2(pipe9[0], 0);
- close(pipe9[0]);
- }
- close(pipe9[1]);
-
- sprintf(cmdbuf, "%s/pd-watchdog\n", guidir);
- if (sys_verbose) fprintf(stderr, "%s", cmdbuf);
- execl("/bin/sh", "sh", "-c", cmdbuf, 0);
- perror("pd: exec");
- _exit(1);
- }
- else /* we're the parent */
- {
- sys_set_priority(0);
- seteuid(getuid()); /* lose setuid priveliges */
- close(pipe9[0]);
- sys_watchfd = pipe9[1];
- /* We also have to start the ping loop in the GUI;
- this is done later when the socket is open. */
- }
- }
- else
- {
- post("realtime setting failed because not root\n");
- sys_hipriority = 0;
- }
- }
-
- seteuid(getuid()); /* lose setuid priveliges */
-#endif /* __linux__ */
-
-#ifdef MSW
- if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
- fprintf(stderr, "pd: couldn't set high priority class\n");
-#endif
-#ifdef MACOSX
- if (sys_hipriority)
- {
- struct sched_param param;
- int policy = SCHED_RR;
- int err;
- param.sched_priority = 80; // adjust 0 : 100
-
- err = pthread_setschedparam(pthread_self(), policy, &param);
- if (err)
- post("warning: high priority scheduling failed\n");
- }
-#endif /* MACOSX */
-
- if (!sys_nogui)
- {
- char buf[256];
- if (sys_verbose)
- fprintf(stderr, "Waiting for connection request... \n");
- if (listen(xsock, 5) < 0) sys_sockerror("listen");
-
- sys_guisock = accept(xsock, (struct sockaddr *) &server, &len);
-#ifdef OOPS
- close(xsock);
-#endif
- if (sys_guisock < 0) sys_sockerror("accept");
- sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read,
- sys_socketreceiver);
-
- if (sys_verbose)
- fprintf(stderr, "... connected\n");
-
- /* here is where we start the pinging. */
-#ifdef __linux__
- if (sys_hipriority)
- sys_gui("pdtk_watchdog\n");
-#endif
- sys_get_audio_apis(buf);
- sys_vgui("pdtk_pd_startup {%s} %s\n", pd_version, buf);
- }
- if (sys_stdin) {
- set_keypress();
- _ss = gensym("stdin");
- sys_addpollfn(1, (t_fdpollfn) stdin_read,NULL);
- }
- return (0);
-
-}
-
-
-static int sys_poll_togui(void)
-{
- /* LATER use this to flush output buffer to gui */
- return (0);
-}
-
-int sys_pollgui(void)
-{
- return (sys_domicrosleep(0, 1) || sys_poll_togui());
-}
-
-
-/* T.Grill - import clean quit function */
-extern void sys_exit(void);
-
-/* This is called when something bad has happened, like a segfault.
-Call glob_quit() below to exit cleanly.
-LATER try to save dirty documents even in the bad case. */
-void sys_bail(int n)
-{
- static int reentered = 0;
- reset_keypress();
- if (!reentered)
- {
- reentered = 1;
-#ifndef __linux /* sys_close_audio() hangs if you're in a signal? */
- fprintf(stderr, "closing audio...\n");
- sys_close_audio();
- fprintf(stderr, "closing MIDI...\n");
- sys_close_midi();
- fprintf(stderr, "... done.\n");
-#endif
- exit(1);
- }
- else _exit(n);
-}
-
-void glob_quit(void *dummy)
-{
- sys_vgui("exit\n");
- if (!sys_nogui)
- {
- close(sys_guisock);
- sys_rmpollfn(sys_guisock);
- }
- reset_keypress();
- sys_bail(0);
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_main.c b/apps/plugins/pdbox/PDa/src/s_main.c
deleted file mode 100644
index b77f804e9f..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_main.c
+++ /dev/null
@@ -1,839 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* IOhannes :
- * hacked the code to add advanced multidevice-support
- * 1311:forum::für::umläute:2001
- */
-
-char pd_version[] = "Pd version 0.37.4\n";
-char pd_compiletime[] = __TIME__;
-char pd_compiledate[] = __DATE__;
-
-#include "m_pd.h"
-#include "m_imp.h"
-#include "s_stuff.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <string.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-
-#ifdef UNIX
-#include <unistd.h>
-#endif
-#ifdef MSW
-#include <io.h>
-#include <windows.h>
-#include <winbase.h>
-#endif
-
-void pd_init(void);
-int sys_argparse(int argc, char **argv);
-void sys_findprogdir(char *progname);
-int sys_startgui(const char *guipath);
-int sys_rcfile(void);
-int m_scheduler(void);
-void sys_addhelppath(char *p);
-void alsa_adddev(char *name);
-
-int sys_debuglevel;
-int sys_verbose;
-int sys_noloadbang;
-int sys_nogui;
-int sys_stdin = 0;
-char *sys_guicmd;
-t_symbol *sys_libdir;
-static t_symbol *sys_guidir;
-static t_namelist *sys_externlist;
-static t_namelist *sys_openlist;
-static t_namelist *sys_messagelist;
-static int sys_version;
-int sys_oldtclversion; /* hack to warn g_rtext.c about old text sel */
-
-int sys_nmidiout = 1;
-#ifdef MSW
-int sys_nmidiin = 0;
-#else
-int sys_nmidiin = 1;
-#endif
-int sys_midiindevlist[MAXMIDIINDEV] = {1};
-int sys_midioutdevlist[MAXMIDIOUTDEV] = {1};
-
-static int sys_main_srate = DEFAULTSRATE;
-static int sys_main_advance = DEFAULTADVANCE;
-
-/* IOhannes { */
-
- /* here the "-1" counts signify that the corresponding vector hasn't been
- specified in command line arguments; sys_open_audio will detect this
- and fill things in. */
-int sys_nsoundin = -1;
-int sys_nsoundout = -1;
-int sys_soundindevlist[MAXAUDIOINDEV];
-int sys_soundoutdevlist[MAXAUDIOOUTDEV];
-
-int sys_nchin = -1;
-int sys_nchout = -1;
-int sys_chinlist[MAXAUDIOINDEV];
-int sys_choutlist[MAXAUDIOOUTDEV];
-/* } IOhannes */
-
-
-typedef struct _fontinfo
-{
- int fi_fontsize;
- int fi_maxwidth;
- int fi_maxheight;
- int fi_hostfontsize;
- int fi_width;
- int fi_height;
-} t_fontinfo;
-
- /* these give the nominal point size and maximum height of the characters
- in the six fonts. */
-
-static t_fontinfo sys_fontlist[] = {
- {8, 5, 9, 0, 0, 0}, {10, 7, 13, 0, 0, 0}, {12, 9, 16, 0, 0, 0},
- {16, 10, 20, 0, 0, 0}, {24, 15, 25, 0, 0, 0}, {36, 25, 45, 0, 0, 0}};
-#define NFONT (sizeof(sys_fontlist)/sizeof(*sys_fontlist))
-
-/* here are the actual font size structs on msp's systems:
-MSW:
-font 8 5 9 8 5 11
-font 10 7 13 10 6 13
-font 12 9 16 14 8 16
-font 16 10 20 16 10 18
-font 24 15 25 16 10 18
-font 36 25 42 36 22 41
-
-linux:
-font 8 5 9 8 5 9
-font 10 7 13 12 7 13
-font 12 9 16 14 9 15
-font 16 10 20 16 10 19
-font 24 15 25 24 15 24
-font 36 25 42 36 22 41
-*/
-
-static t_fontinfo *sys_findfont(int fontsize)
-{
- unsigned int i;
- t_fontinfo *fi;
- for (i = 0, fi = sys_fontlist; i < (NFONT-1); i++, fi++)
- if (fontsize < fi[1].fi_fontsize) return (fi);
- return (sys_fontlist + (NFONT-1));
-}
-
-int sys_nearestfontsize(int fontsize)
-{
- return (sys_findfont(fontsize)->fi_fontsize);
-}
-
-int sys_hostfontsize(int fontsize)
-{
- return (sys_findfont(fontsize)->fi_hostfontsize);
-}
-
-int sys_fontwidth(int fontsize)
-{
- return (sys_findfont(fontsize)->fi_width);
-}
-
-int sys_fontheight(int fontsize)
-{
- return (sys_findfont(fontsize)->fi_height);
-}
-
-int sys_defaultfont;
-#ifdef MSW
-#define DEFAULTFONT 12
-#else
-#define DEFAULTFONT 10
-#endif
-
-static void openit(const char *dirname, const char *filename)
-{
- char dirbuf[MAXPDSTRING], *nameptr;
- int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr,
- MAXPDSTRING, 0);
- if (fd)
- {
- close (fd);
- glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
- }
- else
- error("%s: can't open", filename);
-}
-
-#define NHOSTFONT 7
-
-/* this is called from the gui process. The first argument is the cwd, and
-succeeding args give the widths and heights of known fonts. We wait until
-these are known to open files and send messages specified on the command line.
-We ask the GUI to specify the "cwd" in case we don't have a local OS to get it
-from; for instance we could be some kind of RT embedded system. However, to
-really make this make sense we would have to implement
-open(), read(), etc, calls to be served somehow from the GUI too. */
-
-void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv)
-{
- char *cwd = atom_getsymbolarg(0, argc, argv)->s_name;
- t_namelist *nl;
- unsigned int i, j;
- if (argc != 2 + 3 * NHOSTFONT) bug("glob_initfromgui");
- for (i = 0; i < NFONT; i++)
- {
- int wantheight = sys_fontlist[i].fi_maxheight;
- for (j = 0; j < NHOSTFONT-1; j++)
- {
- if (atom_getintarg(3 * (j + 1) + 3, argc, argv) > wantheight)
- break;
- }
- /* j is now the "real" font index for the desired font index i. */
- sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * j + 1, argc, argv);
- sys_fontlist[i].fi_width = atom_getintarg(3 * j + 2, argc, argv);
- sys_fontlist[i].fi_height = atom_getintarg(3 * j + 3, argc, argv);
- }
-#if 0
- for (i = 0; i < 6; i++)
- fprintf(stderr, "font %d %d %d %d %d\n",
- sys_fontlist[i].fi_fontsize,
- sys_fontlist[i].fi_maxheight,
- sys_fontlist[i].fi_hostfontsize,
- sys_fontlist[i].fi_width,
- sys_fontlist[i].fi_height);
-#endif
- /* load dynamic libraries specified with "-lib" args */
- for (nl = sys_externlist; nl; nl = nl->nl_next)
- if (!sys_load_lib(cwd, nl->nl_string))
- post("%s: can't load library", nl->nl_string);
- namelist_free(sys_externlist);
- sys_externlist = 0;
- /* open patches specifies with "-open" args */
- for (nl = sys_openlist; nl; nl = nl->nl_next)
- openit(cwd, nl->nl_string);
- namelist_free(sys_openlist);
- sys_openlist = 0;
- /* send messages specified with "-send" args */
- for (nl = sys_messagelist; nl; nl = nl->nl_next)
- {
- t_binbuf *b = binbuf_new();
- binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
- binbuf_eval(b, 0, 0, 0);
- binbuf_free(b);
- }
- namelist_free(sys_messagelist);
- sys_messagelist = 0;
- sys_oldtclversion = atom_getfloatarg(1 + 3 * NHOSTFONT, argc, argv);
-}
-
-static void sys_afterargparse(void);
-
-/* this is called from main() in s_entry.c */
-int sys_main(int argc, char **argv)
-{
-#ifdef PD_DEBUG
- fprintf(stderr, "Pd: COMPILED FOR DEBUGGING\n");
-#endif
- pd_init();
- sys_findprogdir(argv[0]); /* set sys_progname, guipath */
-#ifdef UNIX
- sys_rcfile(); /* parse the startup file */
-#endif
- if (sys_argparse(argc, argv)) /* parse cmd line */
- return (1);
- sys_afterargparse(); /* post-argparse settings */
- if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n",
- pd_version, pd_compiletime, pd_compiledate);
- if (sys_version) /* if we were just asked our version, exit here. */
- return (0);
- if (sys_startgui(sys_guidir->s_name)) /* start the gui */
- return(1);
- /* open audio and MIDI */
- sys_open_midi(sys_nmidiin, sys_midiindevlist,
- sys_nmidiout, sys_midioutdevlist);
- sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist,
- sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist,
- sys_main_srate, sys_main_advance, 1);
- /* run scheduler until it quits */
-
- return (m_scheduler_pda());
- return (m_scheduler());
-}
-
-static char *(usagemessage[]) = {
-"usage: pd [-flags] [file]...\n",
-"\naudio configuration flags:\n",
-"-r <n> -- specify sample rate\n",
-"-audioindev ... -- audio in devices; e.g., \"1,3\" for first and third\n",
-"-audiooutdev ... -- audio out devices (same)\n",
-"-audiodev ... -- specify input and output together\n",
-"-inchannels ... -- audio input channels (by device, like \"2\" or \"16,8\")\n",
-"-outchannels ... -- number of audio out channels (same)\n",
-"-channels ... -- specify both input and output channels\n",
-"-audiobuf <n> -- specify size of audio buffer in msec\n",
-"-blocksize <n> -- specify audio I/O block size in sample frames\n",
-"-sleepgrain <n> -- specify number of milliseconds to sleep when idle\n",
-"-nodac -- suppress audio output\n",
-"-noadc -- suppress audio input\n",
-"-noaudio -- suppress audio input and output (-nosound is synonym) \n",
-"-listdev -- list audio and MIDI devices\n",
-
-#ifdef USEAPI_OSS
-"-oss -- use OSS audio API\n",
-"-32bit ----- allow 32 bit OSS audio (for RME Hammerfall)\n",
-#endif
-
-#ifdef USEAPI_ALSA
-"-alsa -- use ALSA audio API\n",
-"-alsaadd <name> -- add an ALSA device name to list\n",
-"-alsadev <n> ----- obsolete: use -audiodev\n",
-#endif
-
-#ifdef USEAPI_JACK
-"-jack -- use JACK audio API\n",
-#endif
-
-#ifdef USEAPI_PORTAUDIO
-#ifdef MSW
-"-asio -- use ASIO audio driver (via Portaudio)\n",
-"-pa -- synonym for -asio\n",
-#else
-"-pa -- use Portaudio API\n",
-#endif
-#endif
-
-#ifdef USEAPI_MMIO
-"-mmio -- use MMIO audio API (default for Windows)\n",
-#endif
-" (default audio API for this platform: ", API_DEFSTRING, ")\n\n",
-
-"\nMIDI configuration flags:\n",
-"-midiindev ... -- midi in device list; e.g., \"1,3\" for first and third\n",
-"-midioutdev ... -- midi out device list, same format\n",
-"-mididev ... -- specify -midioutdev and -midiindev together\n",
-"-nomidiin -- suppress MIDI input\n",
-"-nomidiout -- suppress MIDI output\n",
-"-nomidi -- suppress MIDI input and output\n",
-
-"\nother flags:\n",
-"-path <path> -- add to file search path\n",
-"-helppath <path> -- add to help file search path\n",
-"-open <file> -- open file(s) on startup\n",
-"-lib <file> -- load object library(s)\n",
-"-font <n> -- specify default font size in points\n",
-"-verbose -- extra printout on startup and when searching for files\n",
-"-version -- don't run Pd; just print out which version it is \n",
-"-d <n> -- specify debug level\n",
-"-noloadbang -- suppress all loadbangs\n",
-"-nogui -- suppress starting the GUI\n",
-"-stdin -- scan stdin for keypresses\n",
-"-guicmd \"cmd...\" -- substitute another GUI program (e.g., rsh)\n",
-"-send \"msg...\" -- send a message at startup (after patches are loaded)\n",
-#ifdef UNIX
-"-rt or -realtime -- use real-time priority\n",
-"-nrt -- don't use real-time priority\n",
-#endif
-};
-
-static void sys_parsedevlist(int *np, int *vecp, int max, char *str)
-{
- int n = 0;
- while (n < max)
- {
- if (!*str) break;
- else
- {
- char *endp;
- vecp[n] = strtol(str, &endp, 10);
- if (endp == str)
- break;
- n++;
- if (!endp)
- break;
- str = endp + 1;
- }
- }
- *np = n;
-}
-
-static int sys_getmultidevchannels(int n, int *devlist)
-{
- int sum = 0;
- if (n<0)return(-1);
- if (n==0)return 0;
- while(n--)sum+=*devlist++;
- return sum;
-}
-
-
- /* this routine tries to figure out where to find the auxilliary files
- Pd will need to run. This is either done by looking at the command line
- invokation for Pd, or if that fails, by consulting the variable
- INSTALL_PREFIX. In MSW, we don't try to use INSTALL_PREFIX. */
-void sys_findprogdir(char *progname)
-{
- char sbuf[MAXPDSTRING], sbuf2[MAXPDSTRING], *sp;
- char *lastslash;
-#ifdef UNIX
- struct stat statbuf;
-#endif
-
- /* find out by what string Pd was invoked; put answer in "sbuf". */
-#ifdef MSW
- GetModuleFileName(NULL, sbuf2, sizeof(sbuf2));
- sbuf2[MAXPDSTRING-1] = 0;
- sys_unbashfilename(sbuf2, sbuf);
-#endif /* MSW */
-#ifdef UNIX
- strncpy(sbuf, progname, MAXPDSTRING);
- sbuf[MAXPDSTRING-1] = 0;
-#endif
- lastslash = strrchr(sbuf, '/');
- if (lastslash)
- {
- /* bash last slash to zero so that sbuf is directory pd was in,
- e.g., ~/pd/bin */
- *lastslash = 0;
- /* go back to the parent from there, e.g., ~/pd */
- lastslash = strrchr(sbuf, '/');
- if (lastslash)
- {
- strncpy(sbuf2, sbuf, lastslash-sbuf);
- sbuf2[lastslash-sbuf] = 0;
- }
- else strcpy(sbuf2, "..");
- }
- else
- {
- /* no slashes found. Try INSTALL_PREFIX. */
-#ifdef INSTALL_PREFIX
- strcpy(sbuf2, INSTALL_PREFIX);
-#else
- strcpy(sbuf2, ".");
-#endif
- }
- /* now we believe sbuf2 holds the parent directory of the directory
- pd was found in. We now want to infer the "lib" directory and the
- "gui" directory. In "simple" UNIX installations, the layout is
- .../bin/pd
- .../bin/pd-gui
- .../doc
- and in "complicated" UNIX installations, it's:
- .../bin/pd
- .../lib/pd/bin/pd-gui
- .../lib/pd/doc
- To decide which, we stat .../lib/pd; if that exists, we assume it's
- the complicated layout. In MSW, it's the "simple" layout, but
- the gui program is straight wish80:
- .../bin/pd
- .../bin/wish80.exe
- .../doc
- */
-#ifdef UNIX
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/lib/pd");
- if (stat(sbuf, &statbuf) >= 0)
- {
- /* complicated layout: lib dir is the one we just stat-ed above */
- sys_libdir = gensym(sbuf);
- /* gui lives in .../lib/pd/bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/lib/pd/bin");
- sys_guidir = gensym(sbuf);
- }
- else
- {
- /* simple layout: lib dir is the parent */
- sys_libdir = gensym(sbuf2);
- /* gui lives in .../bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/bin");
- sys_guidir = gensym(sbuf);
- }
-#endif
-#ifdef MSW
- sys_libdir = gensym(sbuf2);
- sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
-#endif
-}
-
-#ifdef MSW
-static int sys_mmio = 1;
-#else
-static int sys_mmio = 0;
-#endif
-
-int sys_argparse(int argc, char **argv)
-{
- char sbuf[MAXPDSTRING];
- int i;
- argc--; argv++;
- while ((argc > 0) && **argv == '-')
- {
- if (!strcmp(*argv, "-r") && argc > 1 &&
- sscanf(argv[1], "%d", &sys_main_srate) >= 1)
- {
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-inchannels"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nchin,
- sys_chinlist, MAXAUDIOINDEV, argv[1]);
-
- if (!sys_nchin)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-outchannels"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nchout, sys_choutlist,
- MAXAUDIOOUTDEV, argv[1]);
-
- if (!sys_nchout)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-channels"))
- {
- sys_parsedevlist(&sys_nchin, sys_chinlist,MAXAUDIOINDEV,
- argv[1]);
- sys_parsedevlist(&sys_nchout, sys_choutlist,MAXAUDIOOUTDEV,
- argv[1]);
-
- if (!sys_nchout)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-soundbuf") || !strcmp(*argv, "-audiobuf"))
- {
- sys_main_advance = atoi(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-blocksize"))
- {
- sys_setblocksize(atoi(argv[1]));
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-sleepgrain"))
- {
- sys_sleepgrain = 1000 * atoi(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-nodac"))
- { /* IOhannes */
- sys_nsoundout=0;
- sys_nchout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-noadc"))
- { /* IOhannes */
- sys_nsoundin=0;
- sys_nchin = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nosound") || !strcmp(*argv, "-noaudio"))
- { /* IOhannes */
- sys_nsoundin=sys_nsoundout = 0;
- sys_nchin = sys_nchout = 0;
- argc--; argv++;
- }
-#ifdef USEAPI_OSS
- else if (!strcmp(*argv, "-oss"))
- {
- sys_set_audio_api(API_OSS);
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-32bit"))
- {
- sys_set_audio_api(API_OSS);
- oss_set32bit();
- argc--; argv++;
- }
-#endif
-#ifdef USEAPI_ALSA
- else if (!strcmp(*argv, "-alsa"))
- {
- sys_set_audio_api(API_ALSA);
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-alsaadd"))
- {
- if (argc > 1)
- alsa_adddev(argv[1]);
- else goto usage;
- argc -= 2; argv +=2;
- }
- /* obsolete flag for setting ALSA device number or name */
- else if (!strcmp(*argv, "-alsadev"))
- {
- int devno = 0;
- if (argv[1][0] >= '1' && argv[1][0] <= '9')
- devno = 1 + 2 * (atoi(argv[1]) - 1);
- else if (!strncmp(argv[1], "hw:", 3))
- devno = 1 + 2 * atoi(argv[1]+3);
- else if (!strncmp(argv[1], "plughw:", 7))
- devno = 2 + 2 * atoi(argv[1]+7);
- else goto usage;
- sys_nsoundin = sys_nsoundout = 1;
- sys_soundindevlist[0] = sys_soundoutdevlist[0] = devno;
- sys_set_audio_api(API_ALSA);
- argc -= 2; argv +=2;
- }
-#endif
-#ifdef USEAPI_JACK
- else if (!strcmp(*argv, "-jack"))
- {
- sys_set_audio_api(API_JACK);
- argc--; argv++;
- }
-#endif
-#ifdef USEAPI_PORTAUDIO
- else if (!strcmp(*argv, "-pa") || !strcmp(*argv, "-portaudio")
-#ifdef MSW
- || !strcmp(*argv, "-asio")
-#endif
- )
- {
- sys_set_audio_api(API_PORTAUDIO);
- sys_mmio = 0;
- argc--; argv++;
- }
-#endif
-#ifdef USEAPI_MMIO
- else if (!strcmp(*argv, "-mmio"))
- {
- sys_set_audio_api(API_MMIO);
- sys_mmio = 1;
- argc--; argv++;
- }
-#endif
- else if (!strcmp(*argv, "-nomidiin"))
- {
- sys_nmidiin = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nomidiout"))
- {
- sys_nmidiout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nomidi"))
- {
- sys_nmidiin = sys_nmidiout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-midiindev"))
- {
- sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
- argv[1]);
- if (!sys_nmidiin)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-midioutdev"))
- {
- sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
- argv[1]);
- if (!sys_nmidiout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-mididev"))
- {
- sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
- argv[1]);
- sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
- argv[1]);
- if (!sys_nmidiout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-path"))
- {
- sys_addpath(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-helppath"))
- {
- sys_addhelppath(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-open") && argc > 1)
- {
- sys_openlist = namelist_append(sys_openlist, argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-lib") && argc > 1)
- {
- sys_externlist = namelist_append(sys_externlist, argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-font") && argc > 1)
- {
- sys_defaultfont = sys_nearestfontsize(atoi(argv[1]));
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-verbose"))
- {
- sys_verbose = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-version"))
- {
- sys_version = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-d") && argc > 1 &&
- sscanf(argv[1], "%d", &sys_debuglevel) >= 1)
- {
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-noloadbang"))
- {
- sys_noloadbang = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nogui"))
- {
- sys_nogui = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-stdin"))
- {
- sys_stdin = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-guicmd") && argc > 1)
- {
- sys_guicmd = argv[1];
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-send") && argc > 1)
- {
- sys_messagelist = namelist_append(sys_messagelist, argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-listdev"))
- {
- sys_listdevs();
- argc--; argv++;
- }
-#ifdef UNIX
- else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime"))
- {
- sys_hipriority = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nrt"))
- {
- sys_hipriority = 0;
- argc--; argv++;
- }
-#endif
- else if (!strcmp(*argv, "-soundindev") ||
- !strcmp(*argv, "-audioindev"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
- MAXAUDIOINDEV, argv[1]);
- if (!sys_nsoundin)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-soundoutdev") ||
- !strcmp(*argv, "-audiooutdev"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
- MAXAUDIOOUTDEV, argv[1]);
- if (!sys_nsoundout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-sounddev") || !strcmp(*argv, "-audiodev"))
- {
- sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
- MAXAUDIOINDEV, argv[1]);
- sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
- MAXAUDIOOUTDEV, argv[1]);
- if (!sys_nsoundout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else
- {
- unsigned int i;
- usage:
- for (i = 0; i < sizeof(usagemessage)/sizeof(*usagemessage); i++)
- fprintf(stderr, "%s", usagemessage[i]);
- return (1);
- }
- }
- if (!sys_defaultfont)
- sys_defaultfont = DEFAULTFONT;
- for (; argc > 0; argc--, argv++)
- sys_openlist = namelist_append(sys_openlist, *argv);
-
-
- return (0);
-}
-
-int sys_getblksize(void)
-{
- return (DEFDACBLKSIZE);
-}
-
- /* stuff to do, once, after calling sys_argparse() -- which may itself
- be called twice because of the .pdrc hack. */
-static void sys_afterargparse(void)
-{
- char sbuf[MAXPDSTRING];
- int i;
- /* add "extra" library to path */
- strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/extra");
- sys_addpath(sbuf);
- strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/intern");
- sys_addpath(sbuf);
- /* add "doc/5.reference" library to helppath */
- strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/doc/5.reference");
- sys_addhelppath(sbuf);
- /* correct to make audio and MIDI device lists zero based. On
- MMIO, however, "1" really means the second device (the first one
- is "mapper" which is was not included when the command args were
- set up, so we leave it that way for compatibility. */
- if (!sys_mmio)
- {
- for (i = 0; i < sys_nsoundin; i++)
- sys_soundindevlist[i]--;
- for (i = 0; i < sys_nsoundout; i++)
- sys_soundoutdevlist[i]--;
- }
- for (i = 0; i < sys_nmidiin; i++)
- sys_midiindevlist[i]--;
- for (i = 0; i < sys_nmidiout; i++)
- sys_midioutdevlist[i]--;
-}
-
-static void sys_addreferencepath(void)
-{
- char sbuf[MAXPDSTRING];
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_midi.c b/apps/plugins/pdbox/PDa/src/s_midi.c
deleted file mode 100644
index 72a8792b25..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_midi.c
+++ /dev/null
@@ -1,642 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* Clock functions (which should move, but where?) and MIDI queueing */
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include "m_imp.h"
-#ifdef UNIX
-#include <unistd.h>
-#include <sys/time.h>
-#ifdef HAVE_BSTRING_H
-#include <bstring.h>
-#endif
-#endif
-#ifdef MSW
-#include <winsock.h>
-#include <sys/types.h>
-#include <sys/timeb.h>
-#include <wtypes.h>
-#endif
-#include <string.h>
-#include <stdio.h>
-#include <signal.h>
-
-typedef struct _midiqelem
-{
- double q_time;
- int q_portno;
- unsigned char q_onebyte;
- unsigned char q_byte1;
- unsigned char q_byte2;
- unsigned char q_byte3;
-} t_midiqelem;
-
-#define MIDIQSIZE 1024
-
-t_midiqelem midi_outqueue[MIDIQSIZE];
-int midi_outhead, midi_outtail;
-t_midiqelem midi_inqueue[MIDIQSIZE];
-int midi_inhead, midi_intail;
-static double sys_midiinittime;
-
- /* this is our current estimate for at what "system" real time the
- current logical time's output should occur. */
-static double sys_dactimeminusrealtime;
- /* same for input, should be schduler advance earlier. */
-static double sys_adctimeminusrealtime;
-
-static double sys_newdactimeminusrealtime = -1e20;
-static double sys_newadctimeminusrealtime = -1e20;
-static double sys_whenupdate;
-
-void sys_initmidiqueue( void)
-{
- sys_midiinittime = clock_getlogicaltime();
- sys_dactimeminusrealtime = sys_adctimeminusrealtime = 0;
-}
-
- /* this is called from the OS dependent code from time to time when we
- think we know the delay (outbuftime) in seconds, at which the last-output
- audio sample will go out the door. */
-void sys_setmiditimediff(double inbuftime, double outbuftime)
-{
- double dactimeminusrealtime =
- .001 * clock_gettimesince(sys_midiinittime)
- - outbuftime - sys_getrealtime();
- double adctimeminusrealtime =
- .001 * clock_gettimesince(sys_midiinittime)
- + inbuftime - sys_getrealtime();
- if (dactimeminusrealtime > sys_newdactimeminusrealtime)
- sys_newdactimeminusrealtime = dactimeminusrealtime;
- if (adctimeminusrealtime > sys_newadctimeminusrealtime)
- sys_newadctimeminusrealtime = adctimeminusrealtime;
- if (sys_getrealtime() > sys_whenupdate)
- {
- sys_dactimeminusrealtime = sys_newdactimeminusrealtime;
- sys_adctimeminusrealtime = sys_newadctimeminusrealtime;
- sys_newdactimeminusrealtime = -1e20;
- sys_newadctimeminusrealtime = -1e20;
- sys_whenupdate = sys_getrealtime() + 1;
- }
-}
-
- /* return the logical time of the DAC sample we believe is currently
- going out, based on how much "system time" has elapsed since the
- last time sys_setmiditimediff got called. */
-static double sys_getmidioutrealtime( void)
-{
- return (sys_getrealtime() + sys_dactimeminusrealtime);
-}
-
-static double sys_getmidiinrealtime( void)
-{
- return (sys_getrealtime() + sys_adctimeminusrealtime);
-}
-
-static void sys_putnext( void)
-{
- int portno = midi_outqueue[midi_outtail].q_portno;
- if (midi_outqueue[midi_outtail].q_onebyte)
- sys_putmidibyte(portno, midi_outqueue[midi_outtail].q_byte1);
- else sys_putmidimess(portno, midi_outqueue[midi_outtail].q_byte1,
- midi_outqueue[midi_outtail].q_byte2,
- midi_outqueue[midi_outtail].q_byte3);
- midi_outtail = (midi_outtail + 1 == MIDIQSIZE ? 0 : midi_outtail + 1);
-}
-
-/* #define TEST_DEJITTER */
-
-void sys_pollmidioutqueue( void)
-{
-#ifdef TEST_DEJITTER
- static int db = 0;
-#endif
- double midirealtime = sys_getmidioutrealtime();
-#ifdef TEST_DEJITTER
- if (midi_outhead == midi_outtail)
- db = 0;
-#endif
- while (midi_outhead != midi_outtail)
- {
-#ifdef TEST_DEJITTER
- if (!db)
- {
- post("out: del %f, midiRT %f logicaltime %f, RT %f dacminusRT %f",
- (midi_outqueue[midi_outtail].q_time - midirealtime),
- midirealtime, .001 * clock_gettimesince(sys_midiinittime),
- sys_getrealtime(), sys_dactimeminusrealtime);
- db = 1;
- }
-#endif
- if (midi_outqueue[midi_outtail].q_time <= midirealtime)
- sys_putnext();
- else break;
- }
-}
-
-static void sys_queuemidimess(int portno, int onebyte, int a, int b, int c)
-{
- t_midiqelem *midiqelem;
- int newhead = midi_outhead +1;
- if (newhead == MIDIQSIZE)
- newhead = 0;
- /* if FIFO is full flush an element to make room */
- if (newhead == midi_outtail)
- sys_putnext();
- midi_outqueue[midi_outhead].q_portno = portno;
- midi_outqueue[midi_outhead].q_onebyte = onebyte;
- midi_outqueue[midi_outhead].q_byte1 = a;
- midi_outqueue[midi_outhead].q_byte2 = b;
- midi_outqueue[midi_outhead].q_byte3 = c;
- midi_outqueue[midi_outhead].q_time =
- .001 * clock_gettimesince(sys_midiinittime);
- midi_outhead = newhead;
- sys_pollmidioutqueue();
-}
-
-#define MIDI_NOTEON 144
-#define MIDI_POLYAFTERTOUCH 160
-#define MIDI_CONTROLCHANGE 176
-#define MIDI_PROGRAMCHANGE 192
-#define MIDI_AFTERTOUCH 208
-#define MIDI_PITCHBEND 224
-
-void outmidi_noteon(int portno, int channel, int pitch, int velo)
-{
- if (pitch < 0) pitch = 0;
- else if (pitch > 127) pitch = 127;
- if (velo < 0) velo = 0;
- else if (velo > 127) velo = 127;
- sys_queuemidimess(portno, 0, MIDI_NOTEON + (channel & 0xf), pitch, velo);
-}
-
-void outmidi_controlchange(int portno, int channel, int ctl, int value)
-{
- if (ctl < 0) ctl = 0;
- else if (ctl > 127) ctl = 127;
- if (value < 0) value = 0;
- else if (value > 127) value = 127;
- sys_queuemidimess(portno, 0, MIDI_CONTROLCHANGE + (channel & 0xf),
- ctl, value);
-}
-
-void outmidi_programchange(int portno, int channel, int value)
-{
- if (value < 0) value = 0;
- else if (value > 127) value = 127;
- sys_queuemidimess(portno, 0,
- MIDI_PROGRAMCHANGE + (channel & 0xf), value, 0);
-}
-
-void outmidi_pitchbend(int portno, int channel, int value)
-{
- if (value < 0) value = 0;
- else if (value > 16383) value = 16383;
- sys_queuemidimess(portno, 0, MIDI_PITCHBEND + (channel & 0xf),
- (value & 127), ((value>>7) & 127));
-}
-
-void outmidi_aftertouch(int portno, int channel, int value)
-{
- if (value < 0) value = 0;
- else if (value > 127) value = 127;
- sys_queuemidimess(portno, 0, MIDI_AFTERTOUCH + (channel & 0xf), value, 0);
-}
-
-void outmidi_polyaftertouch(int portno, int channel, int pitch, int value)
-{
- if (pitch < 0) pitch = 0;
- else if (pitch > 127) pitch = 127;
- if (value < 0) value = 0;
- else if (value > 127) value = 127;
- sys_queuemidimess(portno, 0, MIDI_POLYAFTERTOUCH + (channel & 0xf),
- pitch, value);
-}
-
-void outmidi_mclk(int portno)
-{
- sys_queuemidimess(portno, 1, 0xf8, 0,0);
-}
-
-/* ------------------------- MIDI input queue handling ------------------ */
-typedef struct midiparser
-{
- int mp_status;
- int mp_gotbyte1;
- int mp_byte1;
-} t_midiparser;
-
-#define MIDINOTEOFF 0x80 /* 2 following 'data bytes' */
-#define MIDINOTEON 0x90 /* 2 */
-#define MIDIPOLYTOUCH 0xa0 /* 2 */
-#define MIDICONTROLCHANGE 0xb0 /* 2 */
-#define MIDIPROGRAMCHANGE 0xc0 /* 1 */
-#define MIDICHANNELTOUCH 0xd0 /* 1 */
-#define MIDIPITCHBEND 0xe0 /* 2 */
-#define MIDISTARTSYSEX 0xf0 /* (until F7) */
-#define MIDITIMECODE 0xf1 /* 1 */
-#define MIDISONGPOS 0xf2 /* 2 */
-#define MIDISONGSELECT 0xf3 /* 1 */
-#define MIDIRESERVED1 0xf4 /* ? */
-#define MIDIRESERVED2 0xf5 /* ? */
-#define MIDITUNEREQUEST 0xf6 /* 0 */
-#define MIDIENDSYSEX 0xf7 /* 0 */
-#define MIDICLOCK 0xf8 /* 0 */
-#define MIDITICK 0xf9 /* 0 */
-#define MIDISTART 0xfa /* 0 */
-#define MIDICONT 0xfb /* 0 */
-#define MIDISTOP 0xfc /* 0 */
-#define MIDIACTIVESENSE 0xfe /* 0 */
-#define MIDIRESET 0xff /* 0 */
-
- /* functions in x_midi.c */
-void inmidi_realtimein(int portno, int cmd);
-void inmidi_byte(int portno, int byte);
-void inmidi_sysex(int portno, int byte);
-void inmidi_noteon(int portno, int channel, int pitch, int velo);
-void inmidi_controlchange(int portno, int channel, int ctlnumber, int value);
-void inmidi_programchange(int portno, int channel, int value);
-void inmidi_pitchbend(int portno, int channel, int value);
-void inmidi_aftertouch(int portno, int channel, int value);
-void inmidi_polyaftertouch(int portno, int channel, int pitch, int value);
-
-static void sys_dispatchnextmidiin( void)
-{
- static t_midiparser parser[MAXMIDIINDEV], *parserp;
- int portno = midi_inqueue[midi_intail].q_portno,
- byte = midi_inqueue[midi_intail].q_byte1;
- if (!midi_inqueue[midi_intail].q_onebyte)
- bug("sys_dispatchnextmidiin");
- if (portno < 0 || portno >= MAXMIDIINDEV)
- bug("sys_dispatchnextmidiin 2");
- parserp = parser + portno;
- outlet_setstacklim();
-
- if (byte >= 0xf8)
- inmidi_realtimein(portno, byte);
- else
- {
- inmidi_byte(portno, byte);
- if (byte & 0x80)
- {
- if (byte == MIDITUNEREQUEST || byte == MIDIRESERVED1 ||
- byte == MIDIRESERVED2)
- parserp->mp_status = 0;
- else if (byte == MIDISTARTSYSEX)
- {
- inmidi_sysex(portno, byte);
- parserp->mp_status = byte;
- }
- else if (byte == MIDIENDSYSEX)
- {
- inmidi_sysex(portno, byte);
- parserp->mp_status = 0;
- }
- else
- {
- parserp->mp_status = byte;
- }
- parserp->mp_gotbyte1 = 0;
- }
- else
- {
- int cmd = (parserp->mp_status >= 0xf0 ? parserp->mp_status :
- (parserp->mp_status & 0xf0));
- int chan = (parserp->mp_status & 0xf);
- int byte1 = parserp->mp_byte1, gotbyte1 = parserp->mp_gotbyte1;
- switch (cmd)
- {
- case MIDINOTEOFF:
- if (gotbyte1)
- inmidi_noteon(portno, chan, byte1, 0),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDINOTEON:
- if (gotbyte1)
- inmidi_noteon(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDIPOLYTOUCH:
- if (gotbyte1)
- inmidi_polyaftertouch(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDICONTROLCHANGE:
- if (gotbyte1)
- inmidi_controlchange(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDIPROGRAMCHANGE:
- inmidi_programchange(portno, chan, byte);
- break;
- case MIDICHANNELTOUCH:
- inmidi_aftertouch(portno, chan, byte);
- break;
- case MIDIPITCHBEND:
- if (gotbyte1)
- inmidi_pitchbend(portno, chan, ((byte << 7) + byte1)),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDISTARTSYSEX:
- inmidi_sysex(portno, byte);
- break;
-
- /* other kinds of messages are just dropped here. We'll
- need another status byte before we start letting MIDI in
- again (no running status across "system" messages). */
- case MIDITIMECODE: /* 1 data byte*/
- break;
- case MIDISONGPOS: /* 2 */
- break;
- case MIDISONGSELECT: /* 1 */
- break;
- }
- }
- }
- midi_intail = (midi_intail + 1 == MIDIQSIZE ? 0 : midi_intail + 1);
-}
-
-void sys_pollmidiinqueue( void)
-{
-#ifdef TEST_DEJITTER
- static int db = 0;
-#endif
- double logicaltime = .001 * clock_gettimesince(sys_midiinittime);
-#ifdef TEST_DEJITTER
- if (midi_inhead == midi_intail)
- db = 0;
-#endif
- while (midi_inhead != midi_intail)
- {
-#ifdef TEST_DEJITTER
- if (!db)
- {
- post("in del %f, logicaltime %f, RT %f adcminusRT %f",
- (midi_inqueue[midi_intail].q_time - logicaltime),
- logicaltime, sys_getrealtime(), sys_adctimeminusrealtime);
- db = 1;
- }
-#endif
-#if 0
- if (midi_inqueue[midi_intail].q_time <= logicaltime - 0.007)
- post("late %f",
- 1000 * (logicaltime - midi_inqueue[midi_intail].q_time));
-#endif
- if (midi_inqueue[midi_intail].q_time <= logicaltime)
- {
-#if 0
- post("diff %f",
- 1000* (logicaltime - midi_inqueue[midi_intail].q_time));
-#endif
- sys_dispatchnextmidiin();
- }
- else break;
- }
-}
-
- /* this should be called from the system dependent MIDI code when a byte
- comes in, as a result of our calling sys_poll_midi. We stick it on a
- timetag queue and dispatch it at the appropriate logical time. */
-
-
-void sys_midibytein(int portno, int byte)
-{
- static int warned = 0;
- t_midiqelem *midiqelem;
- int newhead = midi_inhead +1;
- if (newhead == MIDIQSIZE)
- newhead = 0;
- /* if FIFO is full flush an element to make room */
- if (newhead == midi_intail)
- {
- if (!warned)
- {
- post("warning: MIDI timing FIFO overflowed");
- warned = 1;
- }
- sys_dispatchnextmidiin();
- }
- midi_inqueue[midi_inhead].q_portno = portno;
- midi_inqueue[midi_inhead].q_onebyte = 1;
- midi_inqueue[midi_inhead].q_byte1 = byte;
- midi_inqueue[midi_inhead].q_time = sys_getmidiinrealtime();
- midi_inhead = newhead;
- sys_pollmidiinqueue();
-}
-
-void sys_pollmidiqueue( void)
-{
-#if 0
- static double lasttime;
- double newtime = sys_getrealtime();
- if (newtime - lasttime > 0.007)
- post("delay %d", (int)(1000 * (newtime - lasttime)));
- lasttime = newtime;
-#endif
- sys_poll_midi(); /* OS dependent poll for MIDI input */
- sys_pollmidioutqueue();
- sys_pollmidiinqueue();
-}
-
-/******************** dialog window and device listing ********************/
-
-#ifdef USEAPI_OSS
-void midi_oss_init( void);
-#endif
-
- /* last requested parameters */
-static int midi_nmidiindev;
-static int midi_midiindev[MAXMIDIINDEV];
-static int midi_nmidioutdev;
-static int midi_midioutdev[MAXMIDIOUTDEV];
-
-static void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
- int *pnmidioutdev, int *pmidioutdev)
-{
- int i;
- *pnmidiindev = midi_nmidiindev;
- for (i = 0; i < MAXMIDIINDEV; i++)
- pmidiindev[i] = midi_midiindev[i];
- *pnmidioutdev = midi_nmidioutdev;
- for (i = 0; i < MAXMIDIOUTDEV; i++)
- pmidioutdev[i] = midi_midioutdev[i];
-}
-
-static void sys_save_midi_params(
- int nmidiindev, int *midiindev,
- int nmidioutdev, int *midioutdev)
-{
- int i;
- midi_nmidiindev = nmidiindev;
- for (i = 0; i < MAXMIDIINDEV; i++)
- midi_midiindev[i] = midiindev[i];
- midi_nmidioutdev = nmidioutdev;
- for (i = 0; i < MAXMIDIOUTDEV; i++)
- midi_midioutdev[i] = midioutdev[i];
-}
-
-void sys_open_midi(int nmidiindev, int *midiindev,
- int nmidioutdev, int *midioutdev)
-{
-#ifdef USEAPI_OSS
- midi_oss_init();
-#endif
- sys_do_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev);
- sys_save_midi_params(nmidiindev, midiindev,
- nmidioutdev, midioutdev);
-}
-
- /* open midi using whatever parameters were last used */
-void sys_reopen_midi( void)
-{
- int nmidiindev, midiindev[MAXMIDIINDEV];
- int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
- sys_get_midi_params(&nmidiindev, midiindev, &nmidioutdev, midioutdev);
- sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev);
-}
-
-#define MAXNDEV 20
-#define DEVDESCSIZE 80
-
-#ifdef MSW
-#define DEVONSET 0 /* microsoft device list starts at 0 (the "mapper"). */
-#else /* (see also MSW ifdef in sys_parsedevlist(), s_main.c) */
-#define DEVONSET 1 /* To agree with command line flags, normally start at 1 */
-#endif
-
-void sys_listmididevs(void )
-{
- char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
- int nindevs = 0, noutdevs = 0, i;
-
- midi_getdevs(indevlist, &nindevs, outdevlist, &noutdevs,
- MAXNDEV, DEVDESCSIZE);
-
- if (!nindevs)
- post("no midi input devices found");
- else
- {
- post("input devices:");
- for (i = 0; i < nindevs; i++)
- post("%d. %s", i+1, indevlist + i * DEVDESCSIZE);
- }
- if (!noutdevs)
- post("no midi output devices found");
- else
- {
- post("output devices:");
- for (i = 0; i < noutdevs; i++)
- post("%d. %s", i+DEVONSET, outdevlist + i * DEVDESCSIZE);
- }
-}
-
-extern t_class *glob_pdobject;
-
- /* start an midi settings dialog window */
-void glob_midi_properties(t_pd *dummy, t_floatarg flongform)
-{
- char buf[1024 + 2 * MAXNDEV*(DEVDESCSIZE+4)];
- /* these are the devices you're using: */
- int nindev, midiindev[MAXMIDIINDEV];
- int noutdev, midioutdev[MAXMIDIOUTDEV];
- int midiindev1, midiindev2, midiindev3, midiindev4,
- midioutdev1, midioutdev2, midioutdev3, midioutdev4;
-
- /* these are all the devices on your system: */
- char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
- int nindevs = 0, noutdevs = 0, i;
-
- char indevliststring[MAXNDEV*(DEVDESCSIZE+4)+80],
- outdevliststring[MAXNDEV*(DEVDESCSIZE+4)+80];
-
- midi_getdevs(indevlist, &nindevs, outdevlist, &noutdevs,
- MAXNDEV, DEVDESCSIZE);
-
- strcpy(indevliststring, "{ {none} ");
- for (i = 0; i < nindevs; i++)
- {
- strcat(indevliststring, "\"");
- strcat(indevliststring, indevlist + i * DEVDESCSIZE);
- strcat(indevliststring, "\" ");
- }
- strcat(indevliststring, "}");
-
- strcpy(outdevliststring, "{ {none} ");
- for (i = 0; i < noutdevs; i++)
- {
- strcat(outdevliststring, "\"");
- strcat(outdevliststring, outdevlist + i * DEVDESCSIZE);
- strcat(outdevliststring, "\" ");
- }
- strcat(outdevliststring, "}");
-
- sys_get_midi_params(&nindev, midiindev, &noutdev, midioutdev);
-
- if (nindev > 1 || noutdev > 1)
- flongform = 1;
-
- midiindev1 = (nindev > 0 && midiindev[0]>= 0 ? midiindev[0]+1 : 0);
- midiindev2 = (nindev > 1 && midiindev[1]>= 0 ? midiindev[1]+1 : 0);
- midiindev3 = (nindev > 2 && midiindev[2]>= 0 ? midiindev[2]+1 : 0);
- midiindev4 = (nindev > 3 && midiindev[3]>= 0 ? midiindev[3]+1 : 0);
- midioutdev1 = (noutdev > 0 && midioutdev[0]>=0 ? midioutdev[0]+1 : 0);
- midioutdev2 = (noutdev > 1 && midioutdev[1]>=0 ? midioutdev[1]+1 : 0);
- midioutdev3 = (noutdev > 2 && midioutdev[2]>=0 ? midioutdev[2]+1 : 0);
- midioutdev4 = (noutdev > 3 && midioutdev[3]>=0 ? midioutdev[3]+1 : 0);
-
- sprintf(buf,
-"pdtk_midi_dialog %%s \
-%s %d %d %d %d %s %d %d %d %d \
-%d\n",
- indevliststring,
- midiindev1, midiindev2, midiindev3, midiindev4,
- outdevliststring,
- midioutdev1, midioutdev2, midioutdev3, midioutdev4,
- (flongform != 0));
- gfxstub_deleteforkey(0);
- gfxstub_new(&glob_pdobject, glob_midi_properties, buf);
-}
-
- /* new values from dialog window */
-void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
-{
- int nmidiindev, midiindev[MAXMIDIINDEV];
- int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
- int i, nindev, noutdev;
- int newmidiindev[4], newmidioutdev[4];
-
- for (i = 0; i < 4; i++)
- {
- newmidiindev[i] = atom_getintarg(i, argc, argv);
- newmidioutdev[i] = atom_getintarg(i+4, argc, argv);
- }
-
- for (i = 0, nindev = 0; i < 4; i++)
- {
- if (newmidiindev[i] > 0)
- {
- newmidiindev[nindev] = newmidiindev[i]-1;
- nindev++;
- }
- }
- for (i = 0, noutdev = 0; i < 4; i++)
- {
- if (newmidioutdev[i] > 0)
- {
- newmidioutdev[noutdev] = newmidioutdev[i]-1;
- noutdev++;
- }
- }
-
- sys_close_midi();
- sys_open_midi(nindev, newmidiindev, noutdev, newmidioutdev);
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_midi_oss.c b/apps/plugins/pdbox/PDa/src/s_midi_oss.c
deleted file mode 100644
index fab1d84b6f..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_midi_oss.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/* Copyright (c) 1997-1999 Guenter Geiger, Miller Puckette, Larry Troxler,
-* Winfried Ritsch, Karl MacMillan, and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* MIDI I/O for Linux using OSS */
-
-#include <stdio.h>
-#ifdef UNIX
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "m_pd.h"
-#include "s_stuff.h"
-
-static int oss_nmidiin;
-static int oss_midiinfd[MAXMIDIINDEV];
-static int oss_nmidiout;
-static int oss_midioutfd[MAXMIDIOUTDEV];
-
-static void oss_midiout(int fd, int n)
-{
- char b = n;
- if ((write(fd, (char *) &b, 1)) != 1)
- perror("midi write");
-}
-
-#define O_MIDIFLAG O_NDELAY
-
-void sys_do_open_midi(int nmidiin, int *midiinvec,
- int nmidiout, int *midioutvec)
-{
- int i;
- for (i = 0; i < nmidiout; i++)
- oss_midioutfd[i] = -1;
- for (i = 0, oss_nmidiin = 0; i < nmidiin; i++)
- {
- int fd = -1, j, outdevindex = -1;
- char namebuf[80];
- int devno = midiinvec[i];
-
- for (j = 0; j < nmidiout; j++)
- if (midioutvec[j] == midiinvec[i])
- outdevindex = j;
-
- /* try to open the device for read/write. */
- if (devno == 0 && fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi READ/WRITE; returned %d\n", fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device %d: tried %s READ/WRITE; returned %d\n",
- devno, namebuf, fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READ/WRITE; returned %d\n",
- devno, namebuf, fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (devno == 1 && fd < 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi READONLY; returned %d\n", fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd >= 0)
- oss_midiinfd[oss_nmidiin++] = fd;
- else post("couldn't open MIDI input device %d", devno);
- }
- for (i = 0, oss_nmidiout = 0; i < nmidiout; i++)
- {
- int fd = oss_midioutfd[i];
- char namebuf[80];
- int devno = midioutvec[i];
- if (devno == 1 && fd < 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi WRITEONLY; returned %d\n", fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd >= 0)
- oss_midioutfd[oss_nmidiout++] = fd;
- else post("couldn't open MIDI output device %d", devno);
- }
-
- if (oss_nmidiin < nmidiin || oss_nmidiout < nmidiout || sys_verbose)
- post("opened %d MIDI input device(s) and %d MIDI output device(s).",
- oss_nmidiin, oss_nmidiout);
-
- sys_setalarm(0);
-}
-
-#define md_msglen(x) (((x)<0xC0)?2:((x)<0xE0)?1:((x)<0xF0)?2:\
- ((x)==0xF2)?2:((x)<0xF4)?1:0)
-
-void sys_putmidimess(int portno, int a, int b, int c)
-{
- if (portno >= 0 && portno < oss_nmidiout)
- {
- switch (md_msglen(a))
- {
- case 2:
- oss_midiout(oss_midioutfd[portno],a);
- oss_midiout(oss_midioutfd[portno],b);
- oss_midiout(oss_midioutfd[portno],c);
- return;
- case 1:
- oss_midiout(oss_midioutfd[portno],a);
- oss_midiout(oss_midioutfd[portno],b);
- return;
- case 0:
- oss_midiout(oss_midioutfd[portno],a);
- return;
- };
- }
-}
-
-void sys_putmidibyte(int portno, int byte)
-{
- if (portno >= 0 && portno < oss_nmidiout)
- oss_midiout(oss_midioutfd[portno], byte);
-}
-
-#if 0 /* this is the "select" version which doesn't work with OSS
- driver for emu10k1 (it doesn't implement select.) */
-void sys_poll_midi(void)
-{
- int i, throttle = 100;
- struct timeval timout;
- int did = 1, maxfd = 0;
- while (did)
- {
- fd_set readset, writeset, exceptset;
- did = 0;
- if (throttle-- < 0)
- break;
- timout.tv_sec = 0;
- timout.tv_usec = 0;
-
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- for (i = 0; i < oss_nmidiin; i++)
- {
- if (oss_midiinfd[i] > maxfd)
- maxfd = oss_midiinfd[i];
- FD_SET(oss_midiinfd[i], &readset);
- }
- select(maxfd+1, &readset, &writeset, &exceptset, &timout);
- for (i = 0; i < oss_nmidiin; i++)
- if (FD_ISSET(oss_midiinfd[i], &readset))
- {
- char c;
- int ret = read(oss_midiinfd[i], &c, 1);
- if (ret <= 0)
- fprintf(stderr, "Midi read error\n");
- else sys_midibytein(i, (c & 0xff));
- did = 1;
- }
- }
-}
-#else
-
- /* this version uses the asynchronous "read()" ... */
-void sys_poll_midi(void)
-{
- int i, throttle = 100;
- struct timeval timout;
- int did = 1, maxfd = 0;
- while (did)
- {
- fd_set readset, writeset, exceptset;
- did = 0;
- if (throttle-- < 0)
- break;
- for (i = 0; i < oss_nmidiin; i++)
- {
- char c;
- int ret = read(oss_midiinfd[i], &c, 1);
- if (ret < 0)
- {
- if (errno != EAGAIN)
- perror("MIDI");
- }
- else if (ret != 0)
- {
- sys_midibytein(i, (c & 0xff));
- did = 1;
- }
- }
- }
-}
-#endif
-
-void sys_close_midi()
-{
- int i;
- for (i = 0; i < oss_nmidiin; i++)
- close(oss_midiinfd[i]);
- for (i = 0; i < oss_nmidiout; i++)
- close(oss_midioutfd[i]);
- oss_nmidiin = oss_nmidiout = 0;
-}
-
-#define NSEARCH 10
-static int oss_nmidiindevs, oss_nmidioutdevs, oss_initted;
-
-void midi_oss_init(void)
-{
- int i;
- if (oss_initted)
- return;
- oss_initted = 1;
- for (i = 0; i < NSEARCH; i++)
- {
- int fd;
- char namebuf[80];
-
- oss_nmidiindevs = i;
- /* try to open the device for reading */
- if (i == 0)
- {
- fd = open("/dev/midi", O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- }
- sprintf(namebuf, "/dev/midi%2.2d", i);
- fd = open(namebuf, O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- sprintf(namebuf, "/dev/midi%d", i);
- fd = open(namebuf, O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- break;
- }
- for (i = 0; i < NSEARCH; i++)
- {
- int fd;
- char namebuf[80];
-
- oss_nmidioutdevs = i;
- /* try to open the device for writing */
- if (i == 0)
- {
- fd = open("/dev/midi", O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- }
- sprintf(namebuf, "/dev/midi%2.2d", i);
- fd = open(namebuf, O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- sprintf(namebuf, "/dev/midi%d", i);
- fd = open(namebuf, O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- break;
- }
-}
-
-void midi_getdevs(char *indevlist, int *nindevs,
- char *outdevlist, int *noutdevs, int maxndev, int devdescsize)
-{
- int i, ndev;
- if ((ndev = oss_nmidiindevs) > maxndev)
- ndev = maxndev;
- for (i = 0; i < ndev; i++)
- sprintf(indevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
- *nindevs = ndev;
-
- if ((ndev = oss_nmidioutdevs) > maxndev)
- ndev = maxndev;
- for (i = 0; i < ndev; i++)
- sprintf(outdevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
- *noutdevs = ndev;
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_midi_pm.c b/apps/plugins/pdbox/PDa/src/s_midi_pm.c
deleted file mode 100644
index a4f376e0ca..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_midi_pm.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler,
-* Winfried Ritsch, Karl MacMillan, and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
-
- this file calls portmidi to do MIDI I/O for MSW and Mac OSX.
-
-*/
-
-#include "m_pd.h"
-#include "s_stuff.h"
-#include <stdio.h>
-#ifdef UNIX
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "portaudio.h"
-#include "portmidi.h"
-#include "porttime.h"
-#include "pminternal.h"
-
-static PmStream *mac_midiindevlist[MAXMIDIINDEV];
-static PmStream *mac_midioutdevlist[MAXMIDIOUTDEV];
-static int mac_nmidiindev;
-static int mac_nmidioutdev;
-
-void sys_open_midi(int nmidiin, int *midiinvec,
- int nmidiout, int *midioutvec)
-{
- int i = 0;
- int n = 0;
- PmError err;
-
- Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */
- mac_nmidiindev = 0;
-
- /* protect the unwary from having MIDI inputs open; they're
- bad news if you close Pd's terminal window. see sys_nmidiin
- in s_main.c too. */
-#ifdef MSW
- if (nmidiin)
- {
- post(
- "midi input enabled; warning, don't close the DOS window directly!");
- }
- else post("not using MIDI input (use 'pd -midiindev 1' to override)");
-#endif
-
- for (i = 0; i < nmidiin; i++)
- {
- if (midiinvec[i] == DEFMIDIDEV)
- midiinvec[i] = Pm_GetDefaultInputDeviceID();
- err = Pm_OpenInput(&mac_midiindevlist[mac_nmidiindev], midiinvec[i],
- NULL, 100, NULL, NULL, NULL);
- if (err)
- post("could not open midi input device number %d: %s",
- midiinvec[i], Pm_GetErrorText(err));
- else
- {
- if (sys_verbose)
- post("Midi Input opened.\n");
- mac_nmidiindev++;
- }
- }
-
- mac_nmidioutdev = 0;
- for (i = 0; i < nmidiout; i++)
- {
- if (midioutvec[i] == DEFMIDIDEV)
- midioutvec[i] = Pm_GetDefaultOutputDeviceID();
- err = Pm_OpenOutput(&mac_midioutdevlist[mac_nmidioutdev], midioutvec[i],
- NULL, 0, NULL, NULL, 0);
- if (err)
- post("could not open midi output device number %d: %s",
- midioutvec[i], Pm_GetErrorText(err));
- else
- {
- if (sys_verbose)
- post("Midi Output opened.\n");
- mac_nmidioutdev++;
- }
- }
-}
-
-void sys_close_midi( void)
-{
- int i;
- for (i = 0; i < mac_nmidiindev; i++)
- Pm_Close(mac_midiindevlist[mac_nmidiindev]);
- mac_nmidiindev = 0;
- for (i = 0; i < mac_nmidioutdev; i++)
- Pm_Close(mac_midioutdevlist[mac_nmidioutdev]);
- mac_nmidioutdev = 0;
-}
-
-void sys_putmidimess(int portno, int a, int b, int c)
-{
- PmEvent buffer;
- fprintf(stderr, "put 1 msg %d %d\n", portno, mac_nmidioutdev);
- if (portno >= 0 && portno < mac_nmidioutdev)
- {
- buffer.message = Pm_Message(a, b, c);
- buffer.timestamp = 0;
- fprintf(stderr, "put msg\n");
- Pm_Write(mac_midioutdevlist[portno], &buffer, 1);
- }
-}
-
-void sys_putmidibyte(int portno, int byte)
-{
- post("sorry, no byte-by-byte MIDI output implemented in MAC OSX");
-}
-
-void sys_poll_midi(void)
-{
- int i, nmess;
- PmEvent buffer;
- for (i = 0; i < mac_nmidiindev; i++)
- {
- int nmess = Pm_Read(mac_midiindevlist[i], &buffer, 1);
- if (nmess > 0)
- {
- int status = Pm_MessageStatus(buffer.message);
- int data1 = Pm_MessageData1(buffer.message);
- int data2 = Pm_MessageData2(buffer.message);
- int msgtype = (status >> 4) - 8;
- switch (msgtype)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 6:
- sys_midibytein(i, status);
- sys_midibytein(i, data1);
- sys_midibytein(i, data2);
- break;
- case 4:
- case 5:
- sys_midibytein(i, status);
- sys_midibytein(i, data1);
- break;
- case 7:
- sys_midibytein(i, status);
- break;
- }
- }
- }
-}
-
-void sys_listmididevs(void) /* lifted from pa_devs.c in portaudio */
-{
- int i,j;
- for (i = 0; i < Pm_CountDevices(); i++)
- {
- const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
- printf("%d: %s, %s", i, info->interf, info->name);
- if (info->input) printf(" (input)");
- if (info->output) printf(" (output)");
- printf("\n");
- }
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_midi_sgi.c b/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
deleted file mode 100644
index 105a812b49..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-#include "s_stuff.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#ifdef HAVE_BSTRING_H
-#include <bstring.h>
-#endif
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <dmedia/audio.h>
-#include <sys/fpu.h>
-#include <dmedia/midi.h>
-int mdInit(void); /* prototype was messed up in midi.h */
-/* #include "sys/select.h" */
-
-
- /*
- set the special "flush zero" but (FS, bit 24) in the
- Control Status Register of the FPU of R4k and beyond
- so that the result of any underflowing operation will
- be clamped to zero, and no exception of any kind will
- be generated on the CPU.
-
- thanks to cpirazzi@cp.esd.sgi.com (Chris Pirazzi).
- */
-
-static void sgi_flush_all_underflows_to_zero(void)
-{
- union fpc_csr f;
- f.fc_word = get_fpc_csr();
- f.fc_struct.flush = 1;
- set_fpc_csr(f.fc_word);
-}
-
-#define NPORT 2
-
-static MDport sgi_inport[NPORT];
-static MDport sgi_outport[NPORT];
-
-void sgi_open_midi(int midiin, int midiout)
-{
- int i;
- int sgi_nports = mdInit();
- if (sgi_nports < 0) sgi_nports = 0;
- else if (sgi_nports > NPORT) sgi_nports = NPORT;
- if (sys_verbose)
- {
- if (!sgi_nports)
- {
- post("no serial ports are configured for MIDI;");
- post("if you want to use MIDI, try exiting Pd, typing");
- post("'startmidi -d /dev/ttyd2' to a shell, and restarting Pd.");
- }
- else if (sgi_nports == 1)
- post("Found one MIDI port on %s", mdGetName(0));
- else if (sgi_nports == 2)
- post("Found MIDI ports on %s and %s",
- mdGetName(0), mdGetName(1));
- }
- if (midiin)
- {
- for (i = 0; i < sgi_nports; i++)
- {
- if (!(sgi_inport[i] = mdOpenInPort(mdGetName(i))))
- error("MIDI input port %d: open failed", i+1);;
- }
- }
- if (midiout)
- {
- for (i = 0; i < sgi_nports; i++)
- {
- if (!(sgi_outport[i] = mdOpenOutPort(mdGetName(i))))
- error("MIDI output port %d: open failed", i+1);;
- }
- }
- return;
-}
-
-void sys_putmidimess(int portno, int a, int b, int c)
-{
- MDevent mdv;
- if (portno >= NPORT || portno < 0 || !sgi_outport[portno]) return;
- mdv.msg[0] = a;
- mdv.msg[1] = b;
- mdv.msg[2] = c;
- mdv.msg[3] = 0;
- mdv.sysexmsg = 0;
- mdv.stamp = 0;
- mdv.msglen = 0;
- if (mdSend(sgi_outport[portno], &mdv, 1) < 0)
- error("MIDI output error\n");
- post("msg out %d %d %d", a, b, c);
-}
-
-void sys_putmidibyte(int portno, int foo)
-{
- error("MIDI raw byte output not available on SGI");
-}
-
-void inmidi_noteon(int portno, int channel, int pitch, int velo);
-void inmidi_controlchange(int portno, int channel, int ctlnumber, int value);
-void inmidi_programchange(int portno, int channel, int value);
-void inmidi_pitchbend(int portno, int channel, int value);
-void inmidi_aftertouch(int portno, int channel, int value);
-void inmidi_polyaftertouch(int portno, int channel, int pitch, int value);
-
-void sys_poll_midi(void)
-{
- int i;
- MDport *mp;
- for (i = 0, mp = sgi_inport; i < NPORT; i++, mp++)
- {
- int ret, status, b1, b2, nfds;
- MDevent mdv;
- fd_set inports;
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- if (!*mp) continue;
- FD_ZERO(&inports);
- FD_SET(mdGetFd(*mp), &inports);
-
- if (select(mdGetFd(*mp)+1 , &inports, 0, 0, &timeout) < 0)
- perror("midi select");
- if (FD_ISSET(mdGetFd(*mp),&inports))
- {
- if (mdReceive(*mp, &mdv, 1) < 0)
- error("failure receiving message\n");
- else if (mdv.msg[0] == MD_SYSEX) mdFree(mdv.sysexmsg);
-
- else
- {
- int status = mdv.msg[0];
- int channel = (status & 0xf) + 1;
- int b1 = mdv.msg[1];
- int b2 = mdv.msg[2];
- switch(status & 0xf0)
- {
- case MD_NOTEOFF:
- inmidi_noteon(i, channel, b1, 0);
- break;
- case MD_NOTEON:
- inmidi_noteon(i, channel, b1, b2);
- break;
- case MD_POLYKEYPRESSURE:
- inmidi_polyaftertouch(i, channel, b1, b2);
- break;
- case MD_CONTROLCHANGE:
- inmidi_controlchange(i, channel, b1, b2);
- break;
- case MD_PITCHBENDCHANGE:
- inmidi_pitchbend(i, channel, ((b2 << 7) + b1));
- break;
- case MD_PROGRAMCHANGE:
- inmidi_programchange(i, channel, b1);
- break;
- case MD_CHANNELPRESSURE:
- inmidi_aftertouch(i, channel, b1);
- break;
- }
- }
- }
- }
-}
-
-void sys_open_midi(int nmidiin, int *midiinvec,
- int nmidiout, int *midioutvec)
-{
- sgi_open_midi(nmidiin!=0, nmidiout!=0);
-}
-
-
-void sys_close_midi( void)
-{
- /* ??? */
-}
-
-void sys_set_priority(int foo)
-{
- fprintf(stderr,
- "warning: priority boosting in IRIX not implemented yet\n");
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/s_watchdog.c b/apps/plugins/pdbox/PDa/src/s_watchdog.c
deleted file mode 100644
index e8653e9e39..0000000000
--- a/apps/plugins/pdbox/PDa/src/s_watchdog.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Copyright (c) 1997-2000 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* This file is compiled into the separate program, "pd-watchdog," which
-tries to prevent Pd from locking up the processor if it's at realtime
-priority. Linux only. Invoked from s_inter.c. */
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdio.h>
-
-int main(int argc, char **argv)
-{
- int happy = 1;
- while (1)
- {
- struct timeval timout;
- fd_set readset;
- if (happy)
- {
- timout.tv_sec = 5;
- timout.tv_usec = 0;
- }
- else
- {
- timout.tv_sec = 2;
- timout.tv_usec = 0;
- }
- FD_ZERO(&readset);
- FD_SET(0, &readset);
- select(1, &readset, 0, 0, &timout);
- if (FD_ISSET(0, &readset))
- {
- char buf[100];
- happy = 1;
- if (read(0, &buf, 100) <= 0)
- return (0);
- else continue;
- }
- happy = 0;
- kill(getppid(), SIGHUP);
- fprintf(stderr, "watchdog: signaling pd...\n");
- }
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/t_main.c b/apps/plugins/pdbox/PDa/src/t_main.c
deleted file mode 100644
index d68579e745..0000000000
--- a/apps/plugins/pdbox/PDa/src/t_main.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* This file should be compared with the corresponding thing in the TK
-* distribution whenever updating to newer versions of TCL/TK. */
-
-/*
- * Copyright (c) 1993 The Regents of the University of California.
- * Copyright (c) 1994 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-
-#ifndef MACOSX /* linux and IRIX only; in MACOSX we don't link this in */
-#include "tk.h"
-#include <stdlib.h>
-
-/*
- * The following variable is a special hack that is needed in order for
- * Sun shared libraries to be used for Tcl.
- */
-
-extern int matherr(void);
-int *tclDummyMathPtr = (int *) matherr;
-
-/*
- *----------------------------------------------------------------------
- *
- * main --
- *
- * This is the main program for the application.
- *
- * Results:
- * None: Tk_Main never returns here, so this procedure never
- * returns either.
- *
- * Side effects:
- * Whatever the application does.
- *
- *----------------------------------------------------------------------
- */
-
-void pdgui_startup(Tcl_Interp *interp);
-void pdgui_setname(char *name);
-void pdgui_setsock(int port);
-void pdgui_sethost(char *name);
-
-int
-main(int argc, char **argv)
-{
- pdgui_setname(argv[0]);
- if (argc >= 2)
- {
- pdgui_setsock(atoi(argv[1]));
- argc--; argv++;
- argv[0] = "Pd";
- }
- if (argc >= 2)
- {
- pdgui_sethost(argv[1]);
- argc--; argv++;
- argv[0] = "Pd";
- }
- Tk_Main(argc, argv, Tcl_AppInit);
- return 0; /* Needed only to prevent compiler warning. */
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * Tcl_AppInit --
- *
- * This procedure performs application-specific initialization.
- * Most applications, especially those that incorporate additional
- * packages, will have their own version of this procedure.
- * Results:
- * Returns a standard Tcl completion code, and leaves an error
- * message in interp->result if an error occurs.
- *
- * Side effects:
- * Depends on the startup script.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Tcl_AppInit(interp)
- Tcl_Interp *interp; /* Interpreter for application. */
-{
-
- if (Tcl_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
- if (Tk_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
- }
-
- /* setup specific to pd-gui: */
-
- pdgui_startup(interp);
-
- /*
- * Specify a user-specific startup file to invoke if the application
- * is run interactively. Typically the startup file is "~/.apprc"
- * where "app" is the name of the application. If this line is deleted
- * then no user-specific startup file will be run under any conditions.
- */
-
-#if 0
- tcl_RcFileName = "~/.pdrc";
-#endif
-
- return TCL_OK;
-}
-
-#endif /* MACOSX */
-
diff --git a/apps/plugins/pdbox/PDa/src/t_tkcmd.c b/apps/plugins/pdbox/PDa/src/t_tkcmd.c
deleted file mode 100644
index ff12a28494..0000000000
--- a/apps/plugins/pdbox/PDa/src/t_tkcmd.c
+++ /dev/null
@@ -1,398 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-#ifdef UNIX /* in unix this only works first; in NT it only works last. */
-#include "tk.h"
-#endif
-
-#include "t_tk.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#ifdef UNIX
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#ifdef HAVE_BSTRING_H
-#include <bstring.h>
-#endif
-#include <sys/time.h>
-#include <errno.h>
-#endif
-#ifdef MSW
-#include <winsock.h>
-#include <io.h>
-#endif
-#ifdef MSW
-#pragma warning( disable : 4305 ) /* uncast const double to float */
-#pragma warning( disable : 4244 ) /* uncast double to float */
-#pragma warning( disable : 4101 ) /* unused local variables */
-#endif
-
-#ifdef MSW
-#include "tk.h"
-#endif
-
-void tcl_mess(char *s);
-
-/***************** the socket setup code ********************/
-
-static int portno = 5400;
-
- /* some installations of linux don't know about "localhost" so give
- the loopback address; NT, on the other hand, can't understand the
- hostname "127.0.0.1". */
-char hostname[100] =
-#ifdef __linux__
- "127.0.0.1";
-#else
- "localhost";
-#endif
-
-void pdgui_setsock(int port)
-{
- portno = port;
-}
-
-void pdgui_sethost(char *name)
-{
- strncpy(hostname, name, 100);
- hostname[99] = 0;
-}
-
-static void pdgui_sockerror(char *s)
-{
-#ifdef MSW
- int err = WSAGetLastError();
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
-
- fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
- tcl_mess("exit\n");
- exit(1);
-}
-
-static int sockfd;
-
-/* The "pd_suck" command, which polls the socket.
- FIXME: if Pd sends something bigger than SOCKSIZE we're in trouble!
- This has to be set bigger than any array update message for instance.
-*/
-#define SOCKSIZE 20000
-
-static char pd_tkbuf[SOCKSIZE+1];
-int pd_spillbytes = 0;
-
-static void pd_readsocket(ClientData cd, int mask)
-{
- int ngot;
- fd_set readset, writeset, exceptset;
- struct timeval timout;
-
- timout.tv_sec = 0;
- timout.tv_usec = 0;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- FD_SET(sockfd, &readset);
- FD_SET(sockfd, &exceptset);
-
- if (select(sockfd+1, &readset, &writeset, &exceptset, &timout) < 0)
- perror("select");
- if (FD_ISSET(sockfd, &exceptset) || FD_ISSET(sockfd, &readset))
- {
- int ret;
- ret = recv(sockfd, pd_tkbuf + pd_spillbytes,
- SOCKSIZE - pd_spillbytes, 0);
- if (ret < 0) pdgui_sockerror("socket receive error");
- else if (ret == 0)
- {
- /* fprintf(stderr, "read %d\n", SOCKSIZE - pd_spillbytes); */
- fprintf(stderr, "pd_gui: pd process exited\n");
- tcl_mess("exit\n");
- }
- else
- {
- char *lastcr = 0, *bp = pd_tkbuf, *ep = bp + (pd_spillbytes + ret);
- int brace = 0;
- char lastc = 0;
- while (bp < ep)
- {
- char c = *bp;
- if (c == '}' && brace) brace--;
- else if (c == '{') brace++;
- else if (!brace && c == '\n' && lastc != '\\') lastcr = bp;
- lastc = c;
- bp++;
- }
- if (lastcr)
- {
- int xtra = pd_tkbuf + pd_spillbytes + ret - (lastcr+1);
- char bashwas = lastcr[1];
- lastcr[1] = 0;
- tcl_mess(pd_tkbuf);
- lastcr[1] = bashwas;
- if (xtra)
- {
- /* fprintf(stderr, "x %d\n", xtra); */
- memmove(pd_tkbuf, lastcr+1, xtra);
- }
- pd_spillbytes = xtra;
- }
- else
- {
- pd_spillbytes += ret;
- }
- }
- }
-}
-
-#ifndef UNIX
- /* if we aren't UNIX, we add a tcl command to poll the
- socket for data. */
-static int pd_pollsocketCmd(ClientData cd, Tcl_Interp *interp,
- int argc, char **argv)
-{
- pd_readsocket(cd, 0);
- return (TCL_OK);
-}
-#endif
-
-void pdgui_setupsocket(void)
-{
- struct sockaddr_in server;
- struct hostent *hp;
-#ifdef UNIX
- int retry = 10;
-#else
- int retry = 1;
-#endif
-#ifdef MSW
- short version = MAKEWORD(2, 0);
- WSADATA nobby;
-
- if (WSAStartup(version, &nobby)) pdgui_sockerror("setup");
-#endif
-
- /* create a socket */
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0) pdgui_sockerror("socket");
-
- /* connect socket using hostname provided in command line */
- server.sin_family = AF_INET;
-
- hp = gethostbyname(hostname);
-
- if (hp == 0)
- {
- fprintf(stderr,
- "localhost not found (inet protocol not installed?)\n");
- exit(1);
- }
- memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
-
- /* assign client port number */
- server.sin_port = htons((unsigned short)portno);
-
- /* try to connect */
- while (1)
- {
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
- goto gotit;
- retry--;
- if (retry <= 0)
- break;
- /* In UNIX there's a race condition; the child won't be
- able to connect before the parent (pd) has shed its
- setuid-ness. In case this is the problem, sleep and
- retry. */
- else
- {
-#ifdef UNIX
- fd_set readset, writeset, exceptset;
- struct timeval timout;
-
- timout.tv_sec = 0;
- timout.tv_usec = 100000;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- fprintf(stderr, "retrying connect...\n");
- if (select(1, &readset, &writeset, &exceptset, &timout) < 0)
- perror("select");
-#endif /* UNIX */
- }
- }
- pdgui_sockerror("connecting stream socket");
-gotit: ;
-#ifdef UNIX
- /* in unix we ask TK to call us back. In NT we have to poll. */
- Tk_CreateFileHandler(sockfd, TK_READABLE | TK_EXCEPTION,
- pd_readsocket, 0);
-#endif /* UNIX */
-}
-
-/**************************** commands ************************/
-static char *pdgui_path;
-
-/* The "pd" command, which cats its args together and throws the result
-* at the Pd interpreter.
-*/
-#define MAXWRITE 1024
-
-static int pdCmd(ClientData cd, Tcl_Interp *interp, int argc, char **argv)
-{
- if (argc == 2)
- {
- int n = strlen(argv[1]);
- if (send(sockfd, argv[1], n, 0) < n)
- {
- perror("stdout");
- tcl_mess("exit\n");
- }
- }
- else
- {
- int i;
- char buf[MAXWRITE];
- buf[0] = 0;
- for (i = 1; i < argc; i++)
- {
- if (strlen(argv[i]) + strlen(buf) + 2 > MAXWRITE)
- {
- interp->result = "pd: arg list too long";
- return (TCL_ERROR);
- }
- if (i > 1) strcat(buf, " ");
- strcat(buf, argv[i]);
- }
- if (send(sockfd, buf, strlen(buf), 0) < 0)
- {
- perror("stdout");
- tcl_mess("exit\n");
- }
- }
- return (TCL_OK);
-}
-
-/*********** "c" level access to tk functions. ******************/
-
-static Tcl_Interp *tk_myinterp;
-
-void tcl_mess(char *s)
-{
- int result;
- result = Tcl_Eval(tk_myinterp, s);
- if (result != TCL_OK)
- {
- if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result);
- }
-}
-
-/* LATER should do a bounds check -- but how do you get printf to do that? */
-void tcl_vmess(char *fmt, ...)
-{
- int result, i;
- char buf[MAXWRITE];
- va_list ap;
-
- va_start(ap, fmt);
-
- vsprintf(buf, fmt, ap);
- result = Tcl_Eval(tk_myinterp, buf);
- if (result != TCL_OK)
- {
- if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result);
- }
- va_end(ap);
-}
-
-#ifdef UNIX
-void pdgui_doevalfile(Tcl_Interp *interp, char *s)
-{
- char buf[GUISTRING];
- sprintf(buf, "set pd_guidir \"%s\"\n", pdgui_path);
- tcl_mess(buf);
- strcpy(buf, pdgui_path);
- strcat(buf, "/bin/");
- strcat(buf, s);
- if (Tcl_EvalFile(interp, buf) != TCL_OK)
- {
- char buf2[1000];
- sprintf(buf2, "puts [concat tcl: %s: can't open script]\n",
- buf);
- tcl_mess(buf2);
- }
-}
-
-void pdgui_evalfile(char *s)
-{
- pdgui_doevalfile(tk_myinterp, s);
-}
-#endif
-
-void pdgui_startup(Tcl_Interp *interp)
-{
-
- /* save pointer to the main interpreter */
- tk_myinterp = interp;
-
-
- /* add our own TK commands */
- Tcl_CreateCommand(interp, "pd", (Tcl_CmdProc*)pdCmd, (ClientData)NULL,
- (Tcl_CmdDeleteProc *)NULL);
-#ifndef UNIX
- Tcl_CreateCommand(interp, "pd_pollsocket",(Tcl_CmdProc*) pd_pollsocketCmd,
- (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
-#endif
- pdgui_setupsocket();
-
- /* read in the startup file */
-#if !defined(MSW) && !defined(MACOSX)
- pdgui_evalfile("pd.tk");
-#endif
-}
-
-#ifdef UNIX
-void pdgui_setname(char *s)
-{
- char *t;
- char *str;
- int n;
- if (t = strrchr(s, '/')) str = s, n = (t-s) + 1;
- else str = "./", n = 2;
- if (n > GUISTRING-100) n = GUISTRING-100;
- pdgui_path = malloc(n+9);
-
- strncpy(pdgui_path, str, n);
- while (strlen(pdgui_path) > 0 && pdgui_path[strlen(pdgui_path)-1] == '/')
- pdgui_path[strlen(pdgui_path)-1] = 0;
- if (t = strrchr(pdgui_path, '/'))
- *t = 0;
-}
-#endif
-
-int Pdtcl_Init(Tcl_Interp *interp)
-{
- const char *myvalue = Tcl_GetVar(interp, "argv", 0);
- int myportno;
- if (myvalue && (myportno = atoi(myvalue)) > 1)
- pdgui_setsock(myportno);
- tk_myinterp = interp;
- pdgui_startup(interp);
- interp->result = "loaded pdtcl_init";
-
- return (TCL_OK);
-}
-
-int Pdtcl_SafeInit(Tcl_Interp *interp) {
- fprintf(stderr, "Pdtcl_Safeinit 51\n");
- return (TCL_OK);
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/u_main.tk b/apps/plugins/pdbox/PDa/src/u_main.tk
deleted file mode 100644
index e8d5702f32..0000000000
--- a/apps/plugins/pdbox/PDa/src/u_main.tk
+++ /dev/null
@@ -1,3368 +0,0 @@
-set pd_nt 1
-# (The above is 0 for unix, 1 for microsoft, and 2 for Mac OSX. The first
-# line is automatically munged by the relevant makefiles.)
-
-# Copyright (c) 1997-1999 Miller Puckette.
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "LICENSE.txt," in this distribution.
-
-# changed by Thomas Musil 09.2001
-# between "pdtk_graph_dialog -- dialog window for graphs"
-# and "pdtk_array_dialog -- dialog window for arrays"
-# a new dialogbox was inserted, named:
-# "pdtk_iemgui_dialog -- dialog window for iem guis"
-#
-# all this changes are labeled with #######iemlib##########
-
-# Tearoff is set to true by default:
-set pd_tearoff 0
-set menubar 1
-
-set File "F"
-set Windows "W"
-set Edit "E"
-set Find "F"
-set Put "P"
-set Media "M"
-set Help "H"
-
-set color grey16
-set lightcolor grey24
-
-option add *font -*-helvetica-*--bold--9-*
-
-# los colores de la muerte
-
-option add *background $color
-option add *activeBackground $lightcolor
-
-option add *foreground white
-option add *activeForeground white
-
-option add *troughColor $lightcolor
-
-option add *highlightThickness 0
-option add *relief solid startupFile
-
-if {$pd_nt == 1} {
- global pd_guidir
- global pd_tearoff
- set pd_gui2 [string range $argv0 0 [expr [string last \\ $argv0 ] - 1]]
- regsub -all \\\\ $pd_gui2 / pd_gui3
- set pd_guidir $pd_gui3/..
- load $pd_guidir/bin/pdtcl
- set pd_tearoff 1
-}
-
-if {$pd_nt == 2} {
- global pd_guidir
- global pd_tearoff
- set pd_gui2 [string range $argv0 0 [expr [string last / $argv0 ] - 1]]
- set pd_guidir $pd_gui2/..
- load $pd_guidir/bin/pdtcl
- set pd_tearoff 0
-}
-
-# hack so you can easily test-run this script in linux... define pd_guidir
-# (which is normally defined at startup in pd under linux...)
-
-if {$pd_nt == 0} {
- if {! [info exists pd_guidir]} {
- global pd_guidir
- puts stderr {setting pd_guidir to '.'}
- set pd_guidir .
- }
-}
-
-# it's unfortunate but we seem to have to turn off global bindings
-# for Text objects to get control-s and control-t to do what we want for
-# "text" dialogs below. Also we have to get rid of tab's changing the focus.
-
-bind all <Key-Tab> ""
-bind all <<PrevWindow>> ""
-bind Text <Control-t> {}
-bind Text <Control-s> {}
-# puts stderr [bind all]
-
-################## set up main window #########################
-menu .mbar
-canvas .dummy -height 2p -width 6c
-
-frame .controls
-pack .controls .dummy -side top -fill x
-menu .mbar.file -tearoff $pd_tearoff
-.mbar add cascade -label "$File" -menu .mbar.file
-menu .mbar.find -tearoff $pd_tearoff
-.mbar add cascade -label "$Find" -menu .mbar.find
-menu .mbar.windows -postcommand [concat pdtk_fixwindowmenu] -tearoff $pd_tearoff
-menu .mbar.audio -tearoff $pd_tearoff
-if {$pd_nt != 2} {
- .mbar add cascade -label "$Windows" -menu .mbar.windows
- .mbar add cascade -label "$Media" -menu .mbar.audio
-} else {
-# Perhaps this is silly, but Mac HIG want "Window Help" as the last menus
- .mbar add cascade -label "$Media" -menu .mbar.audio
- .mbar add cascade -label "$Windows" -menu .mbar.windows
-}
-menu .mbar.help -tearoff $pd_tearoff
-.mbar add cascade -label "$Help" -menu .mbar.help
-
-set ctrls_audio_on 0
-set ctrls_meter_on 0
-set ctrls_inlevel 0
-set ctrls_outlevel 0
-
-frame .controls.switches
-checkbutton .controls.switches.audiobutton -text {compute audio} \
- -variable ctrls_audio_on \
- -anchor w \
- -command {pd [concat pd dsp $ctrls_audio_on \;]}
-
-checkbutton .controls.switches.meterbutton -text {peak meters} \
- -variable ctrls_meter_on \
- -anchor w \
- -command {pd [concat pd meters $ctrls_meter_on \;]}
-
-pack .controls.switches.meterbutton .controls.switches.audiobutton -side left
-
-frame .controls.inout
-frame .controls.inout.in
-label .controls.inout.in.label -text IN
-entry .controls.inout.in.level -textvariable ctrls_inlevel -width 3
-button .controls.inout.in.clip -text {CLIP} -state disabled
-pack .controls.inout.in.label .controls.inout.in.level \
- .controls.inout.in.clip -side top -pady 2
-
-frame .controls.inout.out
-label .controls.inout.out.label -text OUT
-entry .controls.inout.out.level -textvariable ctrls_outlevel -width 3
-button .controls.inout.out.clip -text {CLIP} -state disabled
-pack .controls.inout.out.label .controls.inout.out.level \
- .controls.inout.out.clip -side top -pady 2
-
-button .controls.dio -text "DIO\nerrors" \
- -command {pd [concat pd audiostatus \;]}
-
-pack .controls.switches -side bottom -pady 12
-pack .controls.inout.in .controls.inout.out -side left -padx 6
-pack .controls.inout -side left -padx 14
-pack .controls.dio -side right -padx 20
-
-bind . <Control-Key> {pdtk_pd_ctrlkey %W %K 0}
-bind . <Control-Shift-Key> {pdtk_pd_ctrlkey %W %K 1}
-if {$pd_nt == 2} {
- bind . <Mod1-Key> {pdtk_canvas_ctrlkey %W %K 0}
- bind . <Mod1-Shift-Key> {pdtk_canvas_ctrlkey %W %K 1}
-}
-
-
-wm title . "PDa"
-. configure -menu .mbar -width 200 -height 150
-
-############### set up global variables ################################
-
-set untitled_number 1
-set untitled_directory [pwd]
-set saveas_client doggy
-set pd_opendir $untitled_directory
-set pd_undoaction no
-set pd_redoaction no
-set pd_undocanvas no
-
-################ utility functions #########################
-
-proc pdtk_enquote {x} {
- set foo [string map {"," "" ";" "" \" ""} $x]
- set foo2 [string map {" " "\\ "} $foo]
- concat $foo2
-}
-
-proc pdtk_debug {x} {
- tk_messageBox -message $x -type ok
-}
-
-proc pdtk_watchdog {} {
- pd [concat pd ping \;]
- after 2000 {pdtk_watchdog}
-}
-
-proc pdtk_check {x message} {
- set answer [tk_messageBox \-message $x \-type yesno \-icon question]
- switch $answer {
- yes {pd $message} }
-# no {tk_messageBox \-message "cancelled" \-type ok}
-}
-
-set menu_windowlist {}
-
-proc pdtk_fixwindowmenu {} {
- global menu_windowlist
- .mbar.windows delete 0 end
- foreach i $menu_windowlist {
- .mbar.windows add command -label [lindex $i 0] \
- -command [concat menu_domenuwindow [lindex $i 1]]
- menu_fixwindowmenu [lindex $i 1]
- }
-}
-
-####### Odd little function to make better Mac accelerators #####
-
-proc accel_munge {acc} {
- global pd_nt
-
- if {$pd_nt == 2} {
- if [string is upper [string index $acc end]] {
- return [format "%s%s" "Shift+" \
- [string toupper [string map {Ctrl Meta} $acc] end]]
- } else {
- return [string toupper [string map {Ctrl Meta} $acc] end]
- }
- } else {
- return $acc
- }
-}
-
-
-
-############### the "New" menu command ########################
-proc menu_new {} {
- global untitled_number
- global untitled_directory
- pd [concat pd filename Untitled-$untitled_number $untitled_directory \;]
- pd {
- #N canvas;
- #X pop 1;
- }
- set untitled_number [expr $untitled_number + 1]
-}
-
-################## the "Open" menu command #########################
-
-proc menu_open {} {
- global pd_opendir
-
- set filename [tk_getOpenFile -defaultextension .pd \
- -filetypes { {{pd files} {.pd}} {{max files} {.pat}}} \
- -initialdir $pd_opendir]
-
- if {$filename != ""} {
- set directory [string range $filename 0 \
- [expr [string last / $filename ] - 1]]
- set pd_opendir $directory
- set basename [string range $filename \
- [expr [string last / $filename ] + 1] end]
-
-# pd_debug [concat file $filename base $basename dir $directory]
-
- pd [concat pd open [pdtk_enquote $basename] \
- [pdtk_enquote $directory]\;]
- }
-}
-
-################## the "Message" menu command #########################
-proc menu_send {} {
- toplevel .sendpanel
- entry .sendpanel.entry -textvariable send_textvariable
- pack .sendpanel.entry -side bottom -fill both -ipadx 100
- .sendpanel.entry select from 0
- .sendpanel.entry select adjust end
- bind .sendpanel.entry <KeyPress-Return> {
- pd [concat $send_textvariable \;]
- after 50 {destroy .sendpanel}
- }
- focus .sendpanel.entry
-}
-
-################## the "Quit" menu command #########################
-proc menu_really_quit {} {pd {pd quit;}}
-
-proc menu_quit {} {pd {pd quit;}}
-
-######### the "Pd" menu command, which puts the Pd window on top ########
-proc menu_pop_pd {} {raise .}
-
-######### the "audio" menu command ###############
-proc menu_audio {flag} {pd [concat pd dsp $flag \;]}
-
-######### the "documentation" menu command ###############
-
-set doc_number 1
-
-proc menu_opentext {filename} {
- global doc_number
- global pd_guidir
- global pd_myversion
- set name [format ".help%d" $doc_number]
- toplevel $name
- text $name.text -fg black -relief raised -bd 2 -font -*-courier-bold--normal--12-* \
- -yscrollcommand "$name.scroll set" -background white
- scrollbar $name.scroll -command "$name.text yview"
- pack $name.scroll -side right -fill y
- pack $name.text -side left -fill both -expand 1
-
- set f [open $filename]
- while {![eof $f]} {
- set bigstring [read $f 1000]
- regsub -all PD_BASEDIR $bigstring $pd_guidir bigstring2
- regsub -all PD_VERSION $bigstring2 $pd_myversion bigstring3
- $name.text insert end $bigstring3
- }
- close $f
- set doc_number [expr $doc_number + 1]
-}
-
-set help_directory $pd_guidir/doc
-
-proc menu_documentation {} {
- global help_directory
- global pd_nt
-
- set filename [tk_getOpenFile -defaultextension .pd \
- -filetypes { {{documentation} {.pd .txt .htm}} } \
- -initialdir $help_directory]
-
- if {$filename != ""} {
- if {[string first .txt $filename] >= 0} {
- menu_opentext $filename
- } elseif {[string first .htm $filename] >= 0} {
- if {$pd_nt == 0} {
- exec sh -c \
- [format "mozilla file:%s || netscape file:%s &\n" \
- $filename $filename]
- } elseif {$pd_nt == 2} {
- puts stderr [format "open %s" $filename]
- exec sh -c \
- [format "open %s" $filename]
- } else {
- exec rundll32 url.dll,FileProtocolHandler \
- [format "file:%s" $filename] &
- }
- } else {
- set help_directory [string range $filename 0 \
- [expr [string last / $filename ] - 1]]
- set basename [string range $filename \
- [expr [string last / $filename ] + 1] end]
- pd [concat pd open [pdtk_enquote $basename] \
- [pdtk_enquote $help_directory] \;]
- }
- }
-}
-
-proc menu_doc_open {subdir basename} {
- global pd_guidir
-
- set dirname $pd_guidir/$subdir
-
- if {[string first .txt $basename] >= 0} {
- menu_opentext $dirname/$basename
- } else {
- pd [concat pd open [pdtk_enquote $basename] \
- [pdtk_enquote $dirname] \;]
- }
-}
-
-############# routine to add audio and help menus ###############
-
-proc menu_addstd {mbar} {
- global pd_apilist
-# the "Audio" menu
- $mbar.audio add command -label {audio ON} -accelerator [accel_munge "Ctrl+/"] \
- -command {menu_audio 1}
- $mbar.audio add command -label {audio OFF} -accelerator [accel_munge "Ctrl+."] \
- -command {menu_audio 0}
- for {set x 0} {$x<[llength $pd_apilist]} {incr x} {
- $mbar.audio add radiobutton -label [lindex [lindex $pd_apilist $x] 0] \
- -command {menu_audio 0} -variable pd_whichapi \
- -value [lindex [lindex $pd_apilist $x] 1]\
- -command {pd [concat pd audio-setapi $pd_whichapi \;]}
- }
- $mbar.audio add command -label {Audio settings...} \
- -command {pd pd audio-properties \;}
-
- $mbar.audio add command -label {MIDI settings...} \
- -command {pd pd midi-properties \;}
- $mbar.audio add command -label {Test Audio and MIDI} \
- -command {menu_doc_open doc/7.stuff/tools testtone.pd}
- $mbar.audio add command -label {Load Meter} \
- -command {menu_doc_open doc/7.stuff/tools load-meter.pd}
-
-
- $mbar.audio add checkbutton -label "Show Menubar" \
- -indicatoron true -selectcolor grey85 \
- -variable menubar
-
-# the "Help" menu
- $mbar.help add command -label {About Pd} \
- -command {menu_doc_open doc/1.manual 1.introduction.txt}
- $mbar.help add command -label {Pure Documentation...} \
- -command {menu_documentation}
-}
-
-#################### the "File" menu for the Pd window ##############
-
-.mbar.file add command -label New -command {menu_new} \
- -accelerator [accel_munge "Ctrl+n"]
-.mbar.file add command -label Open -command {menu_open} \
- -accelerator [accel_munge "Ctrl+o"]
-.mbar.file add separator
-.mbar.file add command -label Message -command {menu_send} \
- -accelerator [accel_munge "Ctrl+m"]
-.mbar.file add command -label Path... \
- -command {pd pd start-path-dialog \;}
-.mbar.file add separator
-.mbar.file add command -label Quit -command {menu_quit} \
- -accelerator [accel_munge "Ctrl+q"]
-
-#################### the "Find" menu for the Pd window ##############
-.mbar.find add command -label {last error?} -command {menu_finderror}
-
-########### functions for menu functions on document windows ########
-
-proc menu_save {name} {
- pdtk_canvas_checkgeometry $name
- pd [concat $name menusave \;]
-}
-
-proc menu_saveas {name} {
- pdtk_canvas_checkgeometry $name
- pd [concat $name menusaveas \;]
-}
-
-proc menu_print {name} {
- set filename [tk_getSaveFile -initialfile pd.ps \
- -defaultextension .ps \
- -filetypes { {{postscript} {.ps}} }]
-
- if {$filename != ""} {
- $name.c postscript -file $filename
- }
-}
-
-proc menu_close {name} {
- pd [concat $name menuclose \;]
-}
-
-proc menu_undo {name} {
- global pd_undoaction
- global pd_redoaction
- global pd_undocanvas
- if {$name == $pd_undocanvas && $pd_undoaction != "no"} {
- pd [concat $name undo \;]
- }
-}
-
-proc menu_redo {name} {
- global pd_undoaction
- global pd_redoaction
- global pd_undocanvas
- if {$name == $pd_undocanvas && $pd_redoaction != "no"} {
- pd [concat $name redo \;]
- }
-}
-
-proc menu_cut {name} {
- pd [concat $name cut \;]
-}
-
-proc menu_copy {name} {
- pd [concat $name copy \;]
-}
-
-proc menu_paste {name} {
- pd [concat $name paste \;]
-}
-
-proc menu_duplicate {name} {
- pd [concat $name duplicate \;]
-}
-
-proc menu_selectall {name} {
- pd [concat $name selectall \;]
-}
-
-proc menu_texteditor {name} {
- pd [concat $name texteditor \;]
-}
-
-proc menu_font {name} {
- pd [concat $name menufont \;]
-}
-
-proc menu_tidyup {name} {
- pd [concat $name tidy \;]
-}
-
-proc menu_editmode {name} {
- pd [concat $name editmode 0 \;]
-}
-
-proc menu_object {name accel} {
- pd [concat $name obj $accel \;]
-}
-
-proc menu_message {name accel} {
- pd [concat $name msg $accel \;]
-}
-
-proc menu_floatatom {name accel} {
- pd [concat $name floatatom $accel \;]
-}
-
-proc menu_symbolatom {name accel} {
- pd [concat $name symbolatom $accel \;]
-}
-
-proc menu_comment {name accel} {
- pd [concat $name text $accel \;]
-}
-
-proc menu_graph {name} {
- pd [concat $name graph \;]
-}
-
-proc menu_array {name} {
- pd [concat $name menuarray \;]
-}
-
-############iemlib##################
-proc menu_bng {name accel} {
- pd [concat $name bng $accel \;]
-}
-
-proc menu_toggle {name accel} {
- pd [concat $name toggle $accel \;]
-}
-
-proc menu_numbox {name accel} {
- pd [concat $name numbox $accel \;]
-}
-
-proc menu_vslider {name accel} {
- pd [concat $name vslider $accel \;]
-}
-
-proc menu_hslider {name accel} {
- pd [concat $name hslider $accel \;]
-}
-
-proc menu_hradio {name accel} {
- pd [concat $name hradio $accel \;]
-}
-
-proc menu_vradio {name accel} {
- pd [concat $name vradio $accel \;]
-}
-
-proc menu_vumeter {name accel} {
- pd [concat $name vumeter $accel \;]
-}
-
-proc menu_mycnv {name accel} {
- pd [concat $name mycnv $accel \;]
-}
-
-############iemlib##################
-
-# correct edit menu, enabling or disabling undo/redo
-# LATER also cut/copy/paste
-proc menu_fixeditmenu {name} {
- global pd_undoaction
- global pd_redoaction
- global pd_undocanvas
-# puts stderr [concat menu_fixeditmenu $name $pd_undocanvas $pd_undoaction]
- if {$name == $pd_undocanvas && $pd_undoaction != "no"} {
- $name.m.edit entryconfigure "Undo*" -state normal \
- -label [concat "Undo " $pd_undoaction]
- } else {
- $name.m.edit entryconfigure "Undo*" -state disabled -label "Undo"
- }
- if {$name == $pd_undocanvas && $pd_redoaction != "no"} {
- $name.m.edit entryconfigure "Redo*" -state normal\
- -label [concat "Redo " $pd_redoaction]
- } else {
- $name.m.edit entryconfigure "Redo*" -state disabled
- }
-}
-
-# message from Pd to update the currently available undo/redo action
-proc pdtk_undomenu {name undoaction redoaction} {
- global pd_undoaction
- global pd_redoaction
- global pd_undocanvas
-# puts stderr [concat pdtk_undomenu $name $undoaction $redoaction]
- set pd_undocanvas $name
- set pd_undoaction $undoaction
- set pd_redoaction $redoaction
- if {$name != "nobody"} {
-# unpleasant way of avoiding a more unpleasant bug situation --atl 2002.11.25
- menu_fixeditmenu $name
- }
-}
-
-proc menu_windowparent {name} {
- pd [concat $name findparent \;]
-}
-
-proc menu_findagain {name} {
- pd [concat $name findagain \;]
-}
-
-proc menu_finderror {} {
- pd [concat pd finderror \;]
-}
-
-proc menu_domenuwindow {i} {
- raise $i
-}
-
-proc menu_fixwindowmenu {name} {
- global menu_windowlist
- global pd_tearoff
- global menubar
-
- if { $menubar == 1 } {
- $name.m.windows add command
- if $pd_tearoff {
- $name.m.windows delete 4 end
- } else {
- $name.m.windows delete 3 end
- }
- foreach i $menu_windowlist {
- $name.m.windows add command -label [lindex $i 0] \
- -command [concat menu_domenuwindow [lindex $i 1]]
- }
- }
-}
-
-################## the "find" menu item ###################
-
-set find_canvas nobody
-set find_string ""
-set find_count 1
-
-proc find_apply {name} {
- global find_string
- global find_canvas
- regsub -all \; $find_string " _semi_ " find_string2
- regsub -all \, $find_string2 " _comma_ " find_string3
-# puts stderr [concat $find_canvas find $find_string3 \
-# \;]
- pd [concat $find_canvas find $find_string3 \
- \;]
- after 50 destroy $name
-}
-
-proc find_cancel {name} {
- after 50 destroy $name
-}
-
-proc menu_findobject {canvas} {
- global find_string
- global find_canvas
- global find_count
-
- set name [format ".find%d" $find_count]
- set find_count [expr $find_count + 1]
-
- set find_canvas $canvas
-
- toplevel $name
-
- label $name.label -text {find...}
- pack $name.label -side top
-
- entry $name.entry -textvariable find_string
- pack $name.entry -side top
-
- frame $name.buttonframe
- pack $name.buttonframe -side bottom -fill x -pady 2m
- button $name.buttonframe.cancel -text {Cancel}\
- -command "find_cancel $name"
- button $name.buttonframe.ok -text {OK}\
- -command "find_apply $name"
- pack $name.buttonframe.cancel -side left -expand 1
- pack $name.buttonframe.ok -side left -expand 1
-
- $name.entry select from 0
- $name.entry select adjust end
- bind $name.entry <KeyPress-Return> [ concat find_apply $name]
- focus $name.entry
-}
-
-
-
-proc pdtk_canvas_menubar {name width height geometry editable} {
- global pd_opendir
- global pd_tearoff
- global pd_nt
-
- global File Edit Find Put Windows Media Help
-
-
- menu $name.m.file -tearoff $pd_tearoff
- $name.m add cascade -label "$File" -menu $name.m.file
-
- $name.m.file add command -label New -command {menu_new} \
- -accelerator [accel_munge "Ctrl+n"]
-
- $name.m.file add command -label Open -command {menu_open} \
- -accelerator [accel_munge "Ctrl+o"]
-
- $name.m.file add separator
- $name.m.file add command -label Message -command {menu_send} \
- -accelerator [accel_munge "Ctrl+m"]
-
- $name.m.file add command -label Path... \
- -command {pd pd start-path-dialog \;}
-
- $name.m.file add separator
- $name.m.file add command -label Close \
- -command [concat menu_close $name] \
- -accelerator [accel_munge "Ctrl+w"]
-
- $name.m.file add command -label Save -command [concat menu_save $name] \
- -accelerator [accel_munge "Ctrl+s"]
-
- $name.m.file add command -label "Save as..." \
- -command [concat menu_saveas $name] \
- -accelerator [accel_munge "Ctrl+S"]
-
- $name.m.file add command -label Print -command [concat menu_print $name] \
- -accelerator [accel_munge "Ctrl+p"]
-
- $name.m.file add separator
-
- $name.m.file add command -label Quit -command {menu_quit} \
- -accelerator [accel_munge "Ctrl+q"]
-
-# the edit menu
- menu $name.m.edit -postcommand [concat menu_fixeditmenu $name] -tearoff $pd_tearoff
- $name.m add cascade -label $Edit -menu $name.m.edit
-
- $name.m.edit add command -label Undo -command [concat menu_undo $name] \
- -accelerator [accel_munge "Ctrl+z"]
-
- $name.m.edit add command -label Redo -command [concat menu_redo $name] \
- -accelerator [accel_munge "Ctrl+Z"]
-
- $name.m.edit add separator
-
- $name.m.edit add command -label Cut -command [concat menu_cut $name] \
- -accelerator [accel_munge "Ctrl+x"]
-
- $name.m.edit add command -label Copy -command [concat menu_copy $name] \
- -accelerator [accel_munge "Ctrl+c"]
-
- $name.m.edit add command -label Paste \
- -command [concat menu_paste $name] \
- -accelerator [accel_munge "Ctrl+v"]
-
- $name.m.edit add command -label Duplicate \
- -command [concat menu_duplicate $name] \
- -accelerator [accel_munge "Ctrl+d"]
-
- $name.m.edit add command -label {Select all} \
- -command [concat menu_selectall $name] \
- -accelerator [accel_munge "Ctrl+a"]
-
- $name.m.edit add separator
-
- $name.m.edit add command -label {Text Editor} \
- -command [concat menu_texteditor $name] \
- -accelerator [accel_munge "Ctrl+t"]
-
- $name.m.edit add command -label Font \
- -command [concat menu_font $name]
-
- $name.m.edit add command -label {Tidy Up} \
- -command [concat menu_tidyup $name]
-
- $name.m.edit add separator
-
-############iemlib##################
-# instead of "red = #BC3C60" we take "grey85", so there is no difference,
-# if widget is selected or not.
-
- $name.m.edit add checkbutton -label "Edit mode" \
- -indicatoron true -selectcolor grey85 \
- -command [concat menu_editmode $name] \
- -accelerator [accel_munge "Ctrl+e"]
-
- if { $editable == 0 } {
- $name.m.edit entryconfigure "Edit mode" -indicatoron false }
-
-############iemlib##################
-
-# the put menu
- menu $name.m.put -tearoff $pd_tearoff
- $name.m add cascade -label $Put -menu $name.m.put
-
- $name.m.put add command -label Object \
- -command [concat menu_object $name 0] \
- -accelerator [accel_munge "Ctrl+1"]
-
- $name.m.put add command -label Message \
- -command [concat menu_message $name 0] \
- -accelerator [accel_munge "Ctrl+2"]
-
- $name.m.put add command -label Number \
- -command [concat menu_floatatom $name 0] \
- -accelerator [accel_munge "Ctrl+3"]
-
- $name.m.put add command -label Symbol \
- -command [concat menu_symbolatom $name 0] \
- -accelerator [accel_munge "Ctrl+4"]
-
- $name.m.put add command -label Comment \
- -command [concat menu_comment $name 0] \
- -accelerator [accel_munge "Ctrl+5"]
-
- $name.m.put add separator
-
-############iemlib##################
-
- $name.m.put add command -label Bang \
- -command [concat menu_bng $name 0] \
- -accelerator [accel_munge "Alt+b"]
-
- $name.m.put add command -label Toggle \
- -command [concat menu_toggle $name 0] \
- -accelerator [accel_munge "Alt+t"]
-
- $name.m.put add command -label Number2 \
- -command [concat menu_numbox $name 0] \
- -accelerator [accel_munge "Alt+n"]
-
- $name.m.put add command -label Vslider \
- -command [concat menu_vslider $name 0] \
- -accelerator [accel_munge "Alt+v"]
-
- $name.m.put add command -label Hslider \
- -command [concat menu_hslider $name 0] \
- -accelerator [accel_munge "Alt+h"]
-
- $name.m.put add command -label Vradio \
- -command [concat menu_vradio $name 0] \
- -accelerator [accel_munge "Alt+d"]
-
- $name.m.put add command -label Hradio \
- -command [concat menu_hradio $name 0] \
- -accelerator [accel_munge "Alt+i"]
-
- $name.m.put add command -label VU \
- -command [concat menu_vumeter $name 0] \
- -accelerator [accel_munge "Alt+u"]
-
- $name.m.put add command -label Canvas \
- -command [concat menu_mycnv $name 0] \
- -accelerator [accel_munge "Alt+c"]
-
-############iemlib##################
-
- $name.m.put add separator
-
- $name.m.put add command -label Graph \
- -command [concat menu_graph $name]
-
- $name.m.put add command -label Array \
- -command [concat menu_array $name]
-
-# the find menu
- menu $name.m.find -tearoff $pd_tearoff
- $name.m add cascade -label "$Find" -menu $name.m.find
-
- $name.m.find add command -label {Find...} \
- -accelerator [accel_munge "Ctrl+f"] \
- -command [concat menu_findobject $name]
- $name.m.find add command -label {Find Again} \
- -accelerator [accel_munge "Ctrl+g"] \
- -command [concat menu_findagain $name]
- $name.m.find add command -label {Find last error} \
- -command [concat menu_finderror]
-
-# the window menu
- menu $name.m.windows -postcommand [concat menu_fixwindowmenu $name] \
- -tearoff $pd_tearoff
-
- $name.m.windows add command -label {parent window}\
- -command [concat menu_windowparent $name]
- $name.m.windows add command -label {Pd window} -command menu_pop_pd
- $name.m.windows add separator
-
-# the audio menu
- menu $name.m.audio -tearoff $pd_tearoff
-
- if {$pd_nt != 2} {
- $name.m add cascade -label $Windows -menu $name.m.windows
- $name.m add cascade -label $Media -menu $name.m.audio
- } else {
- $name.m add cascade -label $Media -menu $name.m.audio
- $name.m add cascade -label $Windows -menu $name.m.windows
- }
-
-# the help menu
- menu $name.m.help -tearoff $pd_tearoff
- $name.m add cascade -label $Help -menu $name.m.help
-
- menu_addstd $name.m
-}
-
-
-############# pdtk_canvas_new -- create a new canvas ###############
-proc pdtk_canvas_new {name width height geometry editable} {
- global pd_opendir
- global pd_tearoff
- global pd_nt
- global menubar
-
- toplevel $name -menu $name.m
-# puts stderr [concat geometry: $geometry]
- wm geometry $name $geometry
- wm minsize $name 1 1
-
- canvas $name.c -width $width -height $height -background white \
- -yscrollcommand "$name.scrollvert set" \
- -xscrollcommand "$name.scrollhort set" \
- -scrollregion [concat 0 0 $width $height]
-
-
- scrollbar $name.scrollvert -command "$name.c yview" -width 7
- scrollbar $name.scrollhort -command "$name.c xview" \
- -orient horizontal -width 7
-
- pack $name.scrollhort -side bottom -fill x
- pack $name.scrollvert -side right -fill y
- pack $name.c -side left -expand 1 -fill both
-
-# the menubar
-
- menu $name.m
-
- if { $menubar == 1 } {
- pdtk_canvas_menubar $name $width $height $geometry $editable
- }
-
-# the popup menu
- menu $name.popup -tearoff false
- $name.popup add command -label {Properties} \
- -command [concat popup_action $name 0]
- $name.popup add command -label {Open} \
- -command [concat popup_action $name 1]
- $name.popup add command -label {Help} \
- -command [concat popup_action $name 2]
-
-# WM protocol
- wm protocol $name WM_DELETE_WINDOW [concat menu_close $name]
-
-# bindings.
-# this is idiotic -- how do you just sense what mod keys are down and
-# pass them on? I can't find it anywhere.
-# Here we encode shift as 1, control 2, alt 4, in agreement
-# with definitions in g_canvas.c. The third button gets "8" but we don't
-# bother with modifiers there.
-# We don't handle multiple clicks yet.
-
- bind $name.c <Button> {pdtk_canvas_click %W %x %y %b 0}
- bind $name.c <Shift-Button> {pdtk_canvas_click %W %x %y %b 1}
- bind $name.c <Control-Shift-Button> {pdtk_canvas_click %W %x %y %b 3}
- bind $name.c <Alt-Button> {pdtk_canvas_click %W %x %y %b 4}
- bind $name.c <Alt-Shift-Button> {pdtk_canvas_click %W %x %y %b 5}
- bind $name.c <Alt-Control-Button> {pdtk_canvas_click %W %x %y %b 6}
- bind $name.c <Alt-Control-Shift-Button> {pdtk_canvas_click %W %x %y %b 7}
- global pd_nt
- if {$pd_nt == 2} {
- bind $name.c <Button-2> {pdtk_canvas_click %W %x %y %b 8}
- bind $name.c <Control-Button> {pdtk_canvas_click %W %x %y %b 8}
- } else {
- bind $name.c <Button-3> {pdtk_canvas_click %W %x %y %b 8}
- bind $name.c <Control-Button> {pdtk_canvas_click %W %x %y %b 2}
- }
-# change mac to right-click, not middle click -atl 2002.09.02
-
- bind $name.c <ButtonRelease> {pdtk_canvas_mouseup %W %x %y %b}
- bind $name.c <Control-Key> {pdtk_canvas_ctrlkey %W %K 0}
- bind $name.c <Control-Shift-Key> {pdtk_canvas_ctrlkey %W %K 1}
- bind $name.c <Alt-Key> {pdtk_canvas_altkey %W %K %A}
-# bind $name.c <Mod1-Key> {puts stderr [concat mod1 %W %K %A]}
- if {$pd_nt == 2} {
- bind $name.c <Mod1-Key> {pdtk_canvas_ctrlkey %W %K 0}
- bind $name.c <Mod1-Shift-Key> {pdtk_canvas_ctrlkey %W %K 1}
- }
- bind $name.c <Key> {pdtk_canvas_key %W %K %A 0}
- bind $name.c <Shift-Key> {pdtk_canvas_key %W %K %A 1}
- bind $name.c <KeyRelease> {pdtk_canvas_keyup %W %K %A}
- bind $name.c <Motion> {pdtk_canvas_motion %W %x %y 0}
- bind $name.c <Alt-Motion> {pdtk_canvas_motion %W %x %y 4}
- bind $name.c <Map> {pdtk_canvas_map %W}
- bind $name.c <Unmap> {pdtk_canvas_unmap %W}
- focus $name.c
-# puts stderr "all done"
-# after 1 [concat raise $name]
-}
-
-#################### event binding procedures ################
-
-#get the name of the toplevel window for a canvas; this is also
-#the name of the canvas object in Pd.
-
-proc canvastosym {name} {
- string range $name 0 [expr [string length $name] - 3]
-}
-
-set pdtk_lastcanvasconfigured ""
-set pdtk_lastcanvasconfiguration ""
-
-proc pdtk_canvas_checkgeometry {topname} {
- set boo [winfo geometry $topname.c]
- set boo2 [wm geometry $topname]
- global pdtk_lastcanvasconfigured
- global pdtk_lastcanvasconfiguration
- if {$topname != $pdtk_lastcanvasconfigured || \
- $boo != $pdtk_lastcanvasconfiguration} {
- set pdtk_lastcanvasconfigured $topname
- set pdtk_lastcanvasconfiguration $boo
- pd $topname relocate $boo $boo2 \;
- }
-}
-
-proc pdtk_canvas_click {name x y b f} {
-# puts stderr [concat got $f]
- pd [canvastosym $name] mouse [$name canvasx $x] [$name canvasy $y] $b $f \;
-}
-
-proc pdtk_canvas_shiftclick {name x y b} {
- pd [canvastosym $name] mouse [$name canvasx $x] [$name canvasy $y] $b 1 \;
-}
-
-proc pdtk_canvas_ctrlclick {name x y b} {
- pd [canvastosym $name] mouse [$name canvasx $x] [$name canvasy $y] $b 2 \;
-}
-
-proc pdtk_canvas_altclick {name x y b} {
- pd [canvastosym $name] mouse [$name canvasx $x] [$name canvasy $y] $b 3 \;
-}
-
-proc pdtk_canvas_dblclick {name x y b} {
- pd [canvastosym $name] mouse [$name canvasx $x] [$name canvasy $y] $b 4 \;
-}
-
-set pdtk_canvas_mouseup_name 0
-set pdtk_canvas_mouseup_xminval 0
-set pdtk_canvas_mouseup_xmaxval 0
-set pdtk_canvas_mouseup_yminval 0
-set pdtk_canvas_mouseup_ymaxval 0
-
-proc pdtk_canvas_mouseup {name x y b} {
- pd [concat [canvastosym $name] mouseup [$name canvasx $x] \
- [$name canvasy $y] $b \;]
-
-# we use the mouseup event to update scrollbar ranges and recheck the
-# geometry of the window since I haven't taken the time to figure out
-# how to do it right.
-
- global pdtk_canvas_mouseup_name
- global pdtk_canvas_mouseup_xminval
- global pdtk_canvas_mouseup_xmaxval
- global pdtk_canvas_mouseup_yminval
- global pdtk_canvas_mouseup_ymaxval
-
- set size [$name bbox all]
- if {$size != ""} {
- set xminval 0
- set yminval 0
- set xmaxval 100
- set ymaxval 100
- set x1 [lindex $size 0]
- set x2 [lindex $size 2]
- set y1 [lindex $size 1]
- set y2 [lindex $size 3]
-
- if {$x1 < 0} {set xminval $x1}
- if {$y1 < 0} {set yminval $y1}
-
- if {$x2 > 100} {set xmaxval $x2}
- if {$y2 > 100} {set ymaxval $y2}
-
- if {$pdtk_canvas_mouseup_name != $name || \
- $pdtk_canvas_mouseup_xminval != $xminval || \
- $pdtk_canvas_mouseup_xmaxval != $xmaxval || \
- $pdtk_canvas_mouseup_yminval != $yminval || \
- $pdtk_canvas_mouseup_ymaxval != $ymaxval } {
-
- set newsize "$xminval $yminval $xmaxval $ymaxval"
- $name configure -scrollregion $newsize
- set pdtk_canvas_mouseup_name $name
- set pdtk_canvas_mouseup_xminval $xminval
- set pdtk_canvas_mouseup_xmaxval $xmaxval
- set pdtk_canvas_mouseup_yminval $yminval
- set pdtk_canvas_mouseup_ymaxval $ymaxval
- }
-
- }
- pdtk_canvas_checkgeometry [canvastosym $name]
-}
-
-proc pdtk_canvas_key {name key iso shift} {
-# puts stderr [concat down key= $key iso= $iso]
-# .controls.switches.meterbutton configure -text $key
-# HACK for MAC OSX -- backspace seems different; I don't understand why.
-# invesigate this LATER...
- global pd_nt
- if {$pd_nt == 2} {
- if {$key == "BackSpace"} {
- set key 8
- set keynum 8
- }
- if {$key == "Delete"} {
- set key 8
- set keynum 8
- }
- }
- if {$key == "KP_Delete"} {
- set key 127
- set keynum 127
- }
- if {$iso != ""} {
- scan $iso %c keynum
- pd [canvastosym $name] key 1 $keynum $shift\;
- } else {
- pd [canvastosym $name] key 1 $key $shift\;
- }
-}
-
-proc pdtk_canvas_keyup {name key iso} {
-# puts stderr [concat up key= $key iso= $iso]
- if {$iso != ""} {
- scan $iso %c keynum
- pd [canvastosym $name] key 0 $keynum 0 \;
- } else {
- pd [canvastosym $name] key 0 $key 0 \;
- }
-}
-
-proc pdtk_canvas_altkey {name key iso} {
-# puts stderr [concat alt-key $iso]
-############iemlib##################
- set topname [string trimright $name .c]
- if {$key == "b" || $key == "B"} {menu_bng $topname 1}
- if {$key == "t" || $key == "T"} {menu_toggle $topname 1}
- if {$key == "n" || $key == "N"} {menu_numbox $topname 1}
- if {$key == "v" || $key == "V"} {menu_vslider $topname 1}
- if {$key == "h" || $key == "H"} {menu_hslider $topname 1}
- if {$key == "i" || $key == "I"} {menu_hradio $topname 1}
- if {$key == "d" || $key == "D"} {menu_vradio $topname 1}
- if {$key == "u" || $key == "U"} {menu_vumeter $topname 1}
- if {$key == "c" || $key == "C"} {menu_mycnv $topname 1}
-############iemlib##################
-}
-
-proc pdtk_canvas_ctrlkey {name key shift} {
-# first get rid of ".c" suffix; we'll refer to the toplevel instead
- set topname [string trimright $name .c]
-# puts stderr [concat ctrl-key $key $topname]
-
- if {$key == "n" || $key == "N"} {menu_new}
- if {$key == "o" || $key == "O"} {menu_open}
- if {$key == "m" || $key == "M"} {menu_send}
- if {$key == "q" || $key == "Q"} {
- if {$shift == 1} {menu_really_quit} else {menu_quit}
- }
- if {$key == "s" || $key == "S"} {
- if {$shift == 1} {menu_saveas $topname} else {menu_save $topname}
- }
- if {$key == "z" || $key == "Z"} {
- if {$shift == 1} {menu_redo $topname} else {menu_undo $topname}
- }
- if {$key == "w" || $key == "W"} {menu_close $topname}
- if {$key == "p" || $key == "P"} {menu_print $topname}
- if {$key == "x" || $key == "X"} {menu_cut $topname}
- if {$key == "c" || $key == "C"} {menu_copy $topname}
- if {$key == "v" || $key == "V"} {menu_paste $topname}
- if {$key == "d" || $key == "D"} {menu_duplicate $topname}
- if {$key == "a" || $key == "A"} {menu_selectall $topname}
- if {$key == "t" || $key == "T"} {menu_texteditor $topname}
- if {$key == "f" || $key == "F"} {menu_findobject $topname}
- if {$key == "g" || $key == "G"} {menu_findagain $topname}
- if {$key == "1"} {menu_object $topname 1}
- if {$key == "2"} {menu_message $topname 1}
- if {$key == "3"} {menu_floatatom $topname 1}
- if {$key == "4"} {menu_symbolatom $topname 1}
- if {$key == "5"} {menu_comment $topname 1}
- if {$key == "slash"} {menu_audio 1}
- if {$key == "period"} {menu_audio 0}
- if {$key == "e" || $key == "E"} {menu_editmode $topname}
-}
-
-proc pdtk_canvas_motion {name x y mods} {
-# puts stderr [concat [canvastosym $name] $name $x $y]
- pd [canvastosym $name] motion [$name canvasx $x] [$name canvasy $y] $mods \;
-}
-
-# "map" event tells us when the canvas becomes visible (arg is "0") or
-# invisible (arg is ""). Invisibility means the Window Manager has minimized
-# us. We don't get a final "unmap" event when we destroy the window.
-proc pdtk_canvas_map {name} {
-# puts stderr [concat map $name]
- pd [canvastosym $name] map 1 \;
-}
-
-proc pdtk_canvas_unmap {name} {
-# puts stderr [concat unmap $name]
- pd [canvastosym $name] map 0 \;
-}
-
-set saveas_dir nowhere
-
-############ pdtk_canvas_saveas -- run a saveas dialog ##############
-
-proc pdtk_canvas_saveas {name initfile initdir} {
- set filename [tk_getSaveFile -initialfile $initfile \
- -initialdir $initdir -defaultextension .pd \
- -filetypes { {{pd files} {.pd}} {{max files} {.pat}} }]
-
- if {$filename != ""} {
- set directory [string range $filename 0 \
- [expr [string last / $filename ] - 1]]
- set basename [string range $filename \
- [expr [string last / $filename ] + 1] end]
- pd [concat $name savetofile [pdtk_enquote $basename] \
- [pdtk_enquote $directory] \;]
-# pd [concat $name savetofile $basename $directory \;]
- }
-}
-
-############ pdtk_canvas_dofont -- run a font and resize dialog #########
-
-set fontsize 0
-set stretchval 0
-set whichstretch 0
-
-proc dofont_apply {name} {
- global fontsize
- global stretchval
- global whichstretch
- set cmd [concat $name font $fontsize $stretchval $whichstretch \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc dofont_cancel {name} {
- set cmd [concat $name cancel \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc pdtk_canvas_dofont {name initsize} {
-
- global fontsize
- set fontsize $initsize
-
- global stretchval
- set stretchval 100
-
- global whichstretch
- set whichstretch 1
-
- toplevel $name
- wm title $name {FONT BOMB}
- wm protocol $name WM_DELETE_WINDOW [concat dofont_cancel $name]
-
- frame $name.buttonframe
- pack $name.buttonframe -side bottom -fill x -pady 2m
- button $name.buttonframe.cancel -text {Cancel}\
- -command "dofont_cancel $name"
- button $name.buttonframe.ok -text {Do it}\
- -command "dofont_apply $name"
- pack $name.buttonframe.cancel -side left -expand 1
- pack $name.buttonframe.ok -side left -expand 1
-
- frame $name.radiof
- pack $name.radiof -side left
-
- label $name.radiof.label -text {Font Size:}
- pack $name.radiof.label -side top
-
- radiobutton $name.radiof.radio8 -value 8 -variable fontsize -text "8"
- radiobutton $name.radiof.radio10 -value 10 -variable fontsize -text "10"
- radiobutton $name.radiof.radio12 -value 12 -variable fontsize -text "12"
- radiobutton $name.radiof.radio16 -value 16 -variable fontsize -text "16"
- radiobutton $name.radiof.radio24 -value 24 -variable fontsize -text "24"
- radiobutton $name.radiof.radio36 -value 36 -variable fontsize -text "36"
- pack $name.radiof.radio8 -side top -anchor w
- pack $name.radiof.radio10 -side top -anchor w
- pack $name.radiof.radio12 -side top -anchor w
- pack $name.radiof.radio16 -side top -anchor w
- pack $name.radiof.radio24 -side top -anchor w
- pack $name.radiof.radio36 -side top -anchor w
-
- frame $name.stretchf
- pack $name.stretchf -side left
-
- label $name.stretchf.label -text {Stretch:}
- pack $name.stretchf.label -side top
-
- entry $name.stretchf.entry -textvariable stretchval -width 5
- pack $name.stretchf.entry -side left
-
- radiobutton $name.stretchf.radio1 \
- -value 1 -variable whichstretch -text "X and Y"
- radiobutton $name.stretchf.radio2 \
- -value 2 -variable whichstretch -text "X only"
- radiobutton $name.stretchf.radio3 \
- -value 3 -variable whichstretch -text "Y only"
-
- pack $name.stretchf.radio1 -side top -anchor w
- pack $name.stretchf.radio2 -side top -anchor w
- pack $name.stretchf.radio3 -side top -anchor w
-
-}
-
-############ pdtk_gatom_dialog -- run a gatom dialog #########
-
-# see graph_apply, etc., for comments about handling variable names here...
-
-proc gatom_escape {sym} {
- if {[string length $sym] == 0} {
- set ret "-"
-# puts stderr [concat escape1 $sym $ret]
- } else {
- if {[string equal -length 1 $sym "-"]} {
- set ret [string replace $sym 0 0 "--"]
-# puts stderr [concat escape $sym $ret]
- } else {
- if {[string equal -length 1 $sym "$"]} {
- set ret [string replace $sym 0 0 "#"]
-# puts stderr [concat unescape $sym $ret]
- } else {
- set ret $sym
-# puts stderr [concat escape $sym "no change"]
- }
- }
- }
- concat $ret
-}
-
-proc gatom_unescape {sym} {
- if {[string equal -length 1 $sym "-"]} {
- set ret [string replace $sym 0 0 ""]
-# puts stderr [concat unescape $sym $ret]
- } else {
- if {[string equal -length 1 $sym "#"]} {
- set ret [string replace $sym 0 0 "$"]
-# puts stderr [concat unescape $sym $ret]
- } else {
- set ret $sym
-# puts stderr [concat unescape $sym "no change"]
- }
- }
- concat $ret
-}
-
-proc dogatom_apply {id} {
- set vid [string trimleft $id .]
-
- set var_gatomwidth [concat gatomwidth_$vid]
- global $var_gatomwidth
- set var_gatomlo [concat gatomlo_$vid]
- global $var_gatomlo
- set var_gatomhi [concat gatomhi_$vid]
- global $var_gatomhi
- set var_gatomwherelabel [concat gatomwherelabel_$vid]
- global $var_gatomwherelabel
- set var_gatomlabel [concat gatomlabel_$vid]
- global $var_gatomlabel
- set var_gatomsymfrom [concat gatomsymfrom_$vid]
- global $var_gatomsymfrom
- set var_gatomsymto [concat gatomsymto_$vid]
- global $var_gatomsymto
-
-# set cmd [concat $id param $gatomwidth $gatomlo $gatomhi \;]
-
- set cmd [concat $id param \
- [eval concat $$var_gatomwidth] \
- [eval concat $$var_gatomlo] \
- [eval concat $$var_gatomhi] \
- [eval gatom_escape $$var_gatomlabel] \
- [eval concat $$var_gatomwherelabel] \
- [eval gatom_escape $$var_gatomsymfrom] \
- [eval gatom_escape $$var_gatomsymto] \
- \;]
-
-# puts stderr $cmd
- pd $cmd
-}
-
-proc dogatom_cancel {name} {
- set cmd [concat $name cancel \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc dogatom_ok {name} {
- dogatom_apply $name
- dogatom_cancel $name
-}
-
-proc pdtk_gatom_dialog {id initwidth initlo inithi \
- wherelabel label symfrom symto} {
-
- set vid [string trimleft $id .]
-
- set var_gatomwidth [concat gatomwidth_$vid]
- global $var_gatomwidth
- set var_gatomlo [concat gatomlo_$vid]
- global $var_gatomlo
- set var_gatomhi [concat gatomhi_$vid]
- global $var_gatomhi
- set var_gatomwherelabel [concat gatomwherelabel_$vid]
- global $var_gatomwherelabel
- set var_gatomlabel [concat gatomlabel_$vid]
- global $var_gatomlabel
- set var_gatomsymfrom [concat gatomsymfrom_$vid]
- global $var_gatomsymfrom
- set var_gatomsymto [concat gatomsymto_$vid]
- global $var_gatomsymto
-
- set $var_gatomwidth $initwidth
- set $var_gatomlo $initlo
- set $var_gatomhi $inithi
- set $var_gatomwherelabel $wherelabel
- set $var_gatomlabel [gatom_unescape $label]
- set $var_gatomsymfrom [gatom_unescape $symfrom]
- set $var_gatomsymto [gatom_unescape $symto]
-
- toplevel $id
- wm title $id {Atom}
- wm protocol $id WM_DELETE_WINDOW [concat dogatom_cancel $id]
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "dogatom_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "dogatom_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "dogatom_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- frame $id.paramsymto
- pack $id.paramsymto -side bottom
- label $id.paramsymto.entryname -text {send symbol}
- entry $id.paramsymto.entry -textvariable $var_gatomsymto -width 20
- pack $id.paramsymto.entryname $id.paramsymto.entry -side left
-
- frame $id.paramsymfrom
- pack $id.paramsymfrom -side bottom
- label $id.paramsymfrom.entryname -text {receive symbol}
- entry $id.paramsymfrom.entry -textvariable $var_gatomsymfrom -width 20
- pack $id.paramsymfrom.entryname $id.paramsymfrom.entry -side left
-
- frame $id.radio
- pack $id.radio -side bottom
- label $id.radio.label -text {show label on:}
- frame $id.radio.l
- frame $id.radio.r
- pack $id.radio.label -side top
- pack $id.radio.l $id.radio.r -side left
- radiobutton $id.radio.l.radio0 -value 0 \
- -variable $var_gatomwherelabel \
- -text "left"
- radiobutton $id.radio.l.radio1 -value 1 \
- -variable $var_gatomwherelabel \
- -text "right"
- radiobutton $id.radio.r.radio2 -value 2 \
- -variable $var_gatomwherelabel \
- -text "top"
- radiobutton $id.radio.r.radio3 -value 3 \
- -variable $var_gatomwherelabel \
- -text "bottom"
- pack $id.radio.l.radio0 $id.radio.l.radio1 -side top -anchor w
- pack $id.radio.r.radio2 $id.radio.r.radio3 -side top -anchor w
-
-
- frame $id.paramlabel
- pack $id.paramlabel -side bottom
- label $id.paramlabel.entryname -text label
- entry $id.paramlabel.entry -textvariable $var_gatomlabel -width 20
- pack $id.paramlabel.entryname $id.paramlabel.entry -side left
-
- frame $id.paramhi
- pack $id.paramhi -side bottom
- label $id.paramhi.entryname -text "upper limit"
- entry $id.paramhi.entry -textvariable $var_gatomhi -width 8
- pack $id.paramhi.entryname $id.paramhi.entry -side left
-
- frame $id.paramlo
- pack $id.paramlo -side bottom
- label $id.paramlo.entryname -text "lower limit"
- entry $id.paramlo.entry -textvariable $var_gatomlo -width 8
- pack $id.paramlo.entryname $id.paramlo.entry -side left
-
- frame $id.params
- pack $id.params -side bottom
- label $id.params.entryname -text width
- entry $id.params.entry -textvariable $var_gatomwidth -width 4
- pack $id.params.entryname $id.params.entry -side left
-
-
-
- bind $id.paramhi.entry <KeyPress-Return> [concat dogatom_ok $id]
- bind $id.paramlo.entry <KeyPress-Return> [concat dogatom_ok $id]
- bind $id.params.entry <KeyPress-Return> [concat dogatom_ok $id]
- $id.params.entry select from 0
- $id.params.entry select adjust end
- focus $id.params.entry
-}
-
-############ pdtk_canvas_popup -- popup menu for canvas #########
-
-set popup_xpix 0
-set popup_ypix 0
-
-proc popup_action {name action} {
- global popup_xpix popup_ypix
- set cmd [concat $name done-popup $action $popup_xpix $popup_ypix \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc pdtk_canvas_popup {name xpix ypix canprop canopen} {
- global popup_xpix popup_ypix
- set popup_xpix $xpix
- set popup_ypix $ypix
- if {$canprop == 0} {$name.popup entryconfigure 0 -state disabled}
- if {$canprop == 1} {$name.popup entryconfigure 0 -state active}
- if {$canopen == 0} {$name.popup entryconfigure 1 -state disabled}
- if {$canopen == 1} {$name.popup entryconfigure 1 -state active}
- tk_popup $name.popup [expr $xpix + [winfo rootx $name.c]] \
- [expr $ypix + [winfo rooty $name.c]] 0
-}
-
-############ pdtk_graph_dialog -- dialog window for graphs #########
-
-# the graph and array dialogs can come up in many copies; but in TK the easiest
-# way to get data from an "entry", etc., is to set an associated variable
-# name. This is especially true for grouped "radio buttons". So we have
-# to synthesize variable names for each instance of the dialog. The dialog
-# gets a TK pathname $id, from which it strips the leading "." to make a
-# variable suffix $vid. Then you can get the actual value out by asking for
-# [eval concat $$variablename]. There should be an easier way but I don't see
-# it yet.
-
-proc graph_apply {id} {
-# strip "." from the TK id to make a variable name suffix
- set vid [string trimleft $id .]
-# for each variable, make a local variable to hold its name...
- set var_graph_x1 [concat graph_x1_$vid]
- global $var_graph_x1
- set var_graph_x2 [concat graph_x2_$vid]
- global $var_graph_x2
- set var_graph_xpix [concat graph_xpix_$vid]
- global $var_graph_xpix
- set var_graph_y1 [concat graph_y1_$vid]
- global $var_graph_y1
- set var_graph_y2 [concat graph_y2_$vid]
- global $var_graph_y2
- set var_graph_ypix [concat graph_ypix_$vid]
- global $var_graph_ypix
-
- pd [concat $id dialog \
- [eval concat $$var_graph_x1] \
- [eval concat $$var_graph_y1] \
- [eval concat $$var_graph_x2] \
- [eval concat $$var_graph_y2] \
- [eval concat $$var_graph_xpix] \
- [eval concat $$var_graph_ypix] \
- \;]
-}
-
-proc graph_cancel {id} {
- set cmd [concat $id cancel \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc graph_ok {id} {
- graph_apply $id
- graph_cancel $id
-}
-
-proc pdtk_graph_dialog {id x1 y1 x2 y2 xpix ypix} {
- set vid [string trimleft $id .]
- set var_graph_x1 [concat graph_x1_$vid]
- global $var_graph_x1
- set var_graph_x2 [concat graph_x2_$vid]
- global $var_graph_x2
- set var_graph_xpix [concat graph_xpix_$vid]
- global $var_graph_xpix
- set var_graph_y1 [concat graph_y1_$vid]
- global $var_graph_y1
- set var_graph_y2 [concat graph_y2_$vid]
- global $var_graph_y2
- set var_graph_ypix [concat graph_ypix_$vid]
- global $var_graph_ypix
-
- set $var_graph_x1 $x1
- set $var_graph_x2 $x2
- set $var_graph_xpix $xpix
- set $var_graph_y1 $y1
- set $var_graph_y2 $y2
- set $var_graph_ypix $ypix
-
- toplevel $id
- wm title $id {graph}
- wm protocol $id WM_DELETE_WINDOW [concat graph_cancel $id]
-
- label $id.label -text {GRAPH BOUNDS}
- pack $id.label -side top
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "graph_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "graph_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "graph_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- frame $id.xrangef
- pack $id.xrangef -side top
-
- label $id.xrangef.l1 -text "X from:"
- entry $id.xrangef.x1 -textvariable $var_graph_x1 -width 7
- label $id.xrangef.l2 -text "to:"
- entry $id.xrangef.x2 -textvariable $var_graph_x2 -width 7
- label $id.xrangef.l3 -text "screen width:"
- entry $id.xrangef.xpix -textvariable $var_graph_xpix -width 7
- pack $id.xrangef.l1 $id.xrangef.x1 \
- $id.xrangef.l2 $id.xrangef.x2 \
- $id.xrangef.l3 $id.xrangef.xpix -side left
-
- frame $id.yrangef
- pack $id.yrangef -side top
-
-# dig in the following that the upper bound is labeled y1 but the variable is
-# y2, etc. This is to deal with the inconsistent use of "upper and lower"
-# graph bounds... in the dialog the upper Y bound is the lower valued Y pixel.
- label $id.yrangef.l1 -text "Y from:"
- entry $id.yrangef.y1 -textvariable $var_graph_y2 -width 7
- label $id.yrangef.l2 -text "to:"
- entry $id.yrangef.y2 -textvariable $var_graph_y1 -width 7
- label $id.yrangef.l3 -text "screen height:"
- entry $id.yrangef.ypix -textvariable $var_graph_ypix -width 7
- pack $id.yrangef.l1 $id.yrangef.y1 \
- $id.yrangef.l2 $id.yrangef.y2 \
- $id.yrangef.l3 $id.yrangef.ypix -side left
-
- bind $id.xrangef.x1 <KeyPress-Return> [concat graph_ok $id]
- bind $id.xrangef.x2 <KeyPress-Return> [concat graph_ok $id]
- bind $id.xrangef.xpix <KeyPress-Return> [concat graph_ok $id]
- bind $id.yrangef.y1 <KeyPress-Return> [concat graph_ok $id]
- bind $id.yrangef.y2 <KeyPress-Return> [concat graph_ok $id]
- bind $id.yrangef.ypix <KeyPress-Return> [concat graph_ok $id]
- $id.xrangef.x2 select from 0
- $id.xrangef.x2 select adjust end
- focus $id.xrangef.x2
-}
-
-# begin of change "iemlib"
-############ pdtk_iemgui_dialog -- dialog window for iem guis #########
-
-set iemgui_define_min_flashhold 50
-set iemgui_define_min_flashbreak 10
-set iemgui_define_min_fontsize 4
-
-proc iemgui_clip_dim {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_wdt [concat iemgui_wdt_$vid]
- global $var_iemgui_wdt
- set var_iemgui_min_wdt [concat iemgui_min_wdt_$vid]
- global $var_iemgui_min_wdt
- set var_iemgui_hgt [concat iemgui_hgt_$vid]
- global $var_iemgui_hgt
- set var_iemgui_min_hgt [concat iemgui_min_hgt_$vid]
- global $var_iemgui_min_hgt
-
- if {[eval concat $$var_iemgui_wdt] < [eval concat $$var_iemgui_min_wdt]} {
- set $var_iemgui_wdt [eval concat $$var_iemgui_min_wdt]
- $id.dim.w_ent configure -textvariable $var_iemgui_wdt
- }
- if {[eval concat $$var_iemgui_hgt] < [eval concat $$var_iemgui_min_hgt]} {
- set $var_iemgui_hgt [eval concat $$var_iemgui_min_hgt]
- $id.dim.h_ent configure -textvariable $var_iemgui_hgt
- }
-}
-
-proc iemgui_clip_num {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_num [concat iemgui_num_$vid]
- global $var_iemgui_num
-
- if {[eval concat $$var_iemgui_num] > 2000} {
- set $var_iemgui_num 2000
- $id.para.num_ent configure -textvariable $var_iemgui_num
- }
- if {[eval concat $$var_iemgui_num] < 1} {
- set $var_iemgui_num 1
- $id.para.num_ent configure -textvariable $var_iemgui_num
- }
-}
-
-proc iemgui_sched_rng {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_min_rng [concat iemgui_min_rng_$vid]
- global $var_iemgui_min_rng
- set var_iemgui_max_rng [concat iemgui_max_rng_$vid]
- global $var_iemgui_max_rng
- set var_iemgui_rng_sch [concat iemgui_rng_sch_$vid]
- global $var_iemgui_rng_sch
-
- global iemgui_define_min_flashhold
- global iemgui_define_min_flashbreak
-
- if {[eval concat $$var_iemgui_rng_sch] == 2} {
- if {[eval concat $$var_iemgui_max_rng] < [eval concat $$var_iemgui_min_rng]} {
- set hhh [eval concat $$var_iemgui_min_rng]
- set $var_iemgui_min_rng [eval concat $$var_iemgui_max_rng]
- set $var_iemgui_max_rng $hhh
- $id.rng.max_ent configure -textvariable $var_iemgui_max_rng
- $id.rng.min_ent configure -textvariable $var_iemgui_min_rng }
- if {[eval concat $$var_iemgui_max_rng] < $iemgui_define_min_flashhold} {
- set $var_iemgui_max_rng $iemgui_define_min_flashhold
- $id.rng.max_ent configure -textvariable $var_iemgui_max_rng
- }
- if {[eval concat $$var_iemgui_min_rng] < $iemgui_define_min_flashbreak} {
- set $var_iemgui_min_rng $iemgui_define_min_flashbreak
- $id.rng.min_ent configure -textvariable $var_iemgui_min_rng
- }
- }
- if {[eval concat $$var_iemgui_rng_sch] == 1} {
- if {[eval concat $$var_iemgui_min_rng] == 0.0} {
- set $var_iemgui_min_rng 1.0
- $id.rng.min_ent configure -textvariable $var_iemgui_min_rng
- }
- }
-}
-
-proc iemgui_verify_rng {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_min_rng [concat iemgui_min_rng_$vid]
- global $var_iemgui_min_rng
- set var_iemgui_max_rng [concat iemgui_max_rng_$vid]
- global $var_iemgui_max_rng
- set var_iemgui_lin0_log1 [concat iemgui_lin0_log1_$vid]
- global $var_iemgui_lin0_log1
-
- if {[eval concat $$var_iemgui_lin0_log1] == 1} {
- if {[eval concat $$var_iemgui_max_rng] == 0.0 && [eval concat $$var_iemgui_min_rng] == 0.0} {
- set $var_iemgui_max_rng 1.0
- $id.rng.max_ent configure -textvariable $var_iemgui_max_rng
- }
- if {[eval concat $$var_iemgui_max_rng] > 0} {
- if {[eval concat $$var_iemgui_min_rng] <= 0} {
- set $var_iemgui_min_rng [expr [eval concat $$var_iemgui_max_rng] * 0.01]
- $id.rng.min_ent configure -textvariable $var_iemgui_min_rng
- }
- } else {
- if {[eval concat $$var_iemgui_min_rng] > 0} {
- set $var_iemgui_max_rng [expr [eval concat $$var_iemgui_min_rng] * 0.01]
- $id.rng.max_ent configure -textvariable $var_iemgui_max_rng
- }
- }
- }
-}
-
-proc iemgui_clip_fontsize {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_gn_fs [concat iemgui_gn_fs_$vid]
- global $var_iemgui_gn_fs
-
- global iemgui_define_min_fontsize
-
- if {[eval concat $$var_iemgui_gn_fs] < $iemgui_define_min_fontsize} {
- set $var_iemgui_gn_fs $iemgui_define_min_fontsize
- $id.gnfs.fs_ent configure -textvariable $var_iemgui_gn_fs
- }
-}
-
-proc iemgui_set_col_example {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_bcol [concat iemgui_bcol_$vid]
- global $var_iemgui_bcol
- set var_iemgui_fcol [concat iemgui_fcol_$vid]
- global $var_iemgui_fcol
- set var_iemgui_lcol [concat iemgui_lcol_$vid]
- global $var_iemgui_lcol
-
- $id.col_example_choose.lb_bk configure \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_lcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_lcol]]
-
- if { [eval concat $$var_iemgui_fcol] >= 0 } {
- $id.col_example_choose.fr_bk configure \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_fcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_fcol]]
- } else {
- $id.col_example_choose.fr_bk configure \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_bcol]]}
-}
-
-proc iemgui_preset_col {id presetcol} {
- set vid [string trimleft $id .]
-
- set var_iemgui_l2_f1_b0 [concat iemgui_l2_f1_b0_$vid]
- global $var_iemgui_l2_f1_b0
- set var_iemgui_bcol [concat iemgui_bcol_$vid]
- global $var_iemgui_bcol
- set var_iemgui_fcol [concat iemgui_fcol_$vid]
- global $var_iemgui_fcol
- set var_iemgui_lcol [concat iemgui_lcol_$vid]
- global $var_iemgui_lcol
-
- if { [eval concat $$var_iemgui_l2_f1_b0] == 0 } { set $var_iemgui_bcol $presetcol }
- if { [eval concat $$var_iemgui_l2_f1_b0] == 1 } { set $var_iemgui_fcol $presetcol }
- if { [eval concat $$var_iemgui_l2_f1_b0] == 2 } { set $var_iemgui_lcol $presetcol }
- iemgui_set_col_example $id
-}
-
-proc iemgui_choose_col_bkfrlb {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_l2_f1_b0 [concat iemgui_l2_f1_b0_$vid]
- global $var_iemgui_l2_f1_b0
- set var_iemgui_bcol [concat iemgui_bcol_$vid]
- global $var_iemgui_bcol
- set var_iemgui_fcol [concat iemgui_fcol_$vid]
- global $var_iemgui_fcol
- set var_iemgui_lcol [concat iemgui_lcol_$vid]
- global $var_iemgui_lcol
-
- if {[eval concat $$var_iemgui_l2_f1_b0] == 0} {
- set $var_iemgui_bcol [expr [eval concat $$var_iemgui_bcol] & 0xFCFCFC]
- set helpstring [tk_chooseColor -title "Background-Color" -initialcolor [format "#%6.6x" [eval concat $$var_iemgui_bcol]]]
- if { $helpstring != "" } {
- set $var_iemgui_bcol [string replace $helpstring 0 0 "0x"]
- set $var_iemgui_bcol [expr [eval concat $$var_iemgui_bcol] & 0xFCFCFC] }
- }
- if {[eval concat $$var_iemgui_l2_f1_b0] == 1} {
- set $var_iemgui_fcol [expr [eval concat $$var_iemgui_fcol] & 0xFCFCFC]
- set helpstring [tk_chooseColor -title "Front-Color" -initialcolor [format "#%6.6x" [eval concat $$var_iemgui_fcol]]]
- if { $helpstring != "" } {
- set $var_iemgui_fcol [string replace $helpstring 0 0 "0x"]
- set $var_iemgui_fcol [expr [eval concat $$var_iemgui_fcol] & 0xFCFCFC] }
- }
- if {[eval concat $$var_iemgui_l2_f1_b0] == 2} {
- set $var_iemgui_lcol [expr [eval concat $$var_iemgui_lcol] & 0xFCFCFC]
- set helpstring [tk_chooseColor -title "Label-Color" -initialcolor [format "#%6.6x" [eval concat $$var_iemgui_lcol]]]
- if { $helpstring != "" } {
- set $var_iemgui_lcol [string replace $helpstring 0 0 "0x"]
- set $var_iemgui_lcol [expr [eval concat $$var_iemgui_lcol] & 0xFCFCFC] }
- }
- iemgui_set_col_example $id
-}
-
-proc iemgui_lilo {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_lin0_log1 [concat iemgui_lin0_log1_$vid]
- global $var_iemgui_lin0_log1
- set var_iemgui_lilo0 [concat iemgui_lilo0_$vid]
- global $var_iemgui_lilo0
- set var_iemgui_lilo1 [concat iemgui_lilo1_$vid]
- global $var_iemgui_lilo1
-
- iemgui_sched_rng $id
-
- if {[eval concat $$var_iemgui_lin0_log1] == 0} {
- set $var_iemgui_lin0_log1 1
- $id.para.lilo configure -text [eval concat $$var_iemgui_lilo1]
- iemgui_verify_rng $id
- iemgui_sched_rng $id
- } else {
- set $var_iemgui_lin0_log1 0
- $id.para.lilo configure -text [eval concat $$var_iemgui_lilo0]
- }
-}
-
-proc iemgui_toggle_font {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_gn_f [concat iemgui_gn_f_$vid]
- global $var_iemgui_gn_f
-
- set $var_iemgui_gn_f [expr [eval concat $$var_iemgui_gn_f] + 1]
- if {[eval concat $$var_iemgui_gn_f] > 2} {set $var_iemgui_gn_f 0}
- if {[eval concat $$var_iemgui_gn_f] == 0} {$id.gnfs.fb configure -text "courier" -font {courier 10 bold}}
- if {[eval concat $$var_iemgui_gn_f] == 1} {$id.gnfs.fb configure -text "helvetica" -font {helvetica 10 bold}}
- if {[eval concat $$var_iemgui_gn_f] == 2} {$id.gnfs.fb configure -text "times" -font {times 10 bold}}
-}
-
-proc iemgui_lb {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_loadbang [concat iemgui_loadbang_$vid]
- global $var_iemgui_loadbang
-
- if {[eval concat $$var_iemgui_loadbang] == 0} {
- set $var_iemgui_loadbang 1
- $id.para.lb configure -text "init"
- } else {
- set $var_iemgui_loadbang 0
- $id.para.lb configure -text "no init"
- }
-}
-
-proc iemgui_stdy_jmp {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_steady [concat iemgui_steady_$vid]
- global $var_iemgui_steady
-
- if {[eval concat $$var_iemgui_steady]} {
- set $var_iemgui_steady 0
- $id.para.stdy_jmp configure -text "jump on click"
- } else {
- set $var_iemgui_steady 1
- $id.para.stdy_jmp configure -text "steady on click"
- }
-}
-
-proc iemgui_apply {id} {
- set vid [string trimleft $id .]
-
- set var_iemgui_wdt [concat iemgui_wdt_$vid]
- global $var_iemgui_wdt
- set var_iemgui_min_wdt [concat iemgui_min_wdt_$vid]
- global $var_iemgui_min_wdt
- set var_iemgui_hgt [concat iemgui_hgt_$vid]
- global $var_iemgui_hgt
- set var_iemgui_min_hgt [concat iemgui_min_hgt_$vid]
- global $var_iemgui_min_hgt
- set var_iemgui_min_rng [concat iemgui_min_rng_$vid]
- global $var_iemgui_min_rng
- set var_iemgui_max_rng [concat iemgui_max_rng_$vid]
- global $var_iemgui_max_rng
- set var_iemgui_lin0_log1 [concat iemgui_lin0_log1_$vid]
- global $var_iemgui_lin0_log1
- set var_iemgui_lilo0 [concat iemgui_lilo0_$vid]
- global $var_iemgui_lilo0
- set var_iemgui_lilo1 [concat iemgui_lilo1_$vid]
- global $var_iemgui_lilo1
- set var_iemgui_loadbang [concat iemgui_loadbang_$vid]
- global $var_iemgui_loadbang
- set var_iemgui_num [concat iemgui_num_$vid]
- global $var_iemgui_num
- set var_iemgui_steady [concat iemgui_steady_$vid]
- global $var_iemgui_steady
- set var_iemgui_snd [concat iemgui_snd_$vid]
- global $var_iemgui_snd
- set var_iemgui_rcv [concat iemgui_rcv_$vid]
- global $var_iemgui_rcv
- set var_iemgui_gui_nam [concat iemgui_gui_nam_$vid]
- global $var_iemgui_gui_nam
- set var_iemgui_gn_dx [concat iemgui_gn_dx_$vid]
- global $var_iemgui_gn_dx
- set var_iemgui_gn_dy [concat iemgui_gn_dy_$vid]
- global $var_iemgui_gn_dy
- set var_iemgui_gn_f [concat iemgui_gn_f_$vid]
- global $var_iemgui_gn_f
- set var_iemgui_gn_fs [concat iemgui_gn_fs_$vid]
- global $var_iemgui_gn_fs
- set var_iemgui_bcol [concat iemgui_bcol_$vid]
- global $var_iemgui_bcol
- set var_iemgui_fcol [concat iemgui_fcol_$vid]
- global $var_iemgui_fcol
- set var_iemgui_lcol [concat iemgui_lcol_$vid]
- global $var_iemgui_lcol
-
- iemgui_clip_dim $id
- iemgui_clip_num $id
- iemgui_sched_rng $id
- iemgui_verify_rng $id
- iemgui_sched_rng $id
- iemgui_clip_fontsize $id
-
- if {[eval concat $$var_iemgui_snd] == ""} {set hhhsnd "empty"} else {set hhhsnd [eval concat $$var_iemgui_snd]}
- if {[eval concat $$var_iemgui_rcv] == ""} {set hhhrcv "empty"} else {set hhhrcv [eval concat $$var_iemgui_rcv]}
- if {[eval concat $$var_iemgui_gui_nam] == ""} {set hhhgui_nam "empty"
- } else {
- set hhhgui_nam [eval concat $$var_iemgui_gui_nam]}
-
- if {[string index $hhhsnd 0] == "$"} {
- set hhhsnd [string replace $hhhsnd 0 0 #] }
- if {[string index $hhhrcv 0] == "$"} {
- set hhhrcv [string replace $hhhrcv 0 0 #] }
- if {[string index $hhhgui_nam 0] == "$"} {
- set hhhgui_nam [string replace $hhhgui_nam 0 0 #] }
-
- set hhhsnd [string map {" " _} $hhhsnd]
- set hhhrcv [string map {" " _} $hhhrcv]
- set hhhgui_nam [string map {" " _} $hhhgui_nam]
-
- pd [concat $id dialog \
- [eval concat $$var_iemgui_wdt] \
- [eval concat $$var_iemgui_hgt] \
- [eval concat $$var_iemgui_min_rng] \
- [eval concat $$var_iemgui_max_rng] \
- [eval concat $$var_iemgui_lin0_log1] \
- [eval concat $$var_iemgui_loadbang] \
- [eval concat $$var_iemgui_num] \
- $hhhsnd \
- $hhhrcv \
- $hhhgui_nam \
- [eval concat $$var_iemgui_gn_dx] \
- [eval concat $$var_iemgui_gn_dy] \
- [eval concat $$var_iemgui_gn_f] \
- [eval concat $$var_iemgui_gn_fs] \
- [eval concat $$var_iemgui_bcol] \
- [eval concat $$var_iemgui_fcol] \
- [eval concat $$var_iemgui_lcol] \
- [eval concat $$var_iemgui_steady] \
- \;]
-}
-
-proc iemgui_cancel {id} {pd [concat $id cancel \;]}
-
-proc iemgui_ok {id} {
- iemgui_apply $id
- iemgui_cancel $id
-}
-
-proc pdtk_iemgui_dialog {id mainheader \
- dim_header wdt min_wdt wdt_label hgt min_hgt hgt_label \
- rng_header min_rng min_rng_label max_rng max_rng_label rng_sched \
- lin0_log1 lilo0_label lilo1_label loadbang steady num_label num \
- snd rcv \
- gui_name \
- gn_dx gn_dy \
- gn_f gn_fs \
- bcol fcol lcol} {
-
- set vid [string trimleft $id .]
-
- set var_iemgui_wdt [concat iemgui_wdt_$vid]
- global $var_iemgui_wdt
- set var_iemgui_min_wdt [concat iemgui_min_wdt_$vid]
- global $var_iemgui_min_wdt
- set var_iemgui_hgt [concat iemgui_hgt_$vid]
- global $var_iemgui_hgt
- set var_iemgui_min_hgt [concat iemgui_min_hgt_$vid]
- global $var_iemgui_min_hgt
- set var_iemgui_min_rng [concat iemgui_min_rng_$vid]
- global $var_iemgui_min_rng
- set var_iemgui_max_rng [concat iemgui_max_rng_$vid]
- global $var_iemgui_max_rng
- set var_iemgui_rng_sch [concat iemgui_rng_sch_$vid]
- global $var_iemgui_rng_sch
- set var_iemgui_lin0_log1 [concat iemgui_lin0_log1_$vid]
- global $var_iemgui_lin0_log1
- set var_iemgui_lilo0 [concat iemgui_lilo0_$vid]
- global $var_iemgui_lilo0
- set var_iemgui_lilo1 [concat iemgui_lilo1_$vid]
- global $var_iemgui_lilo1
- set var_iemgui_loadbang [concat iemgui_loadbang_$vid]
- global $var_iemgui_loadbang
- set var_iemgui_num [concat iemgui_num_$vid]
- global $var_iemgui_num
- set var_iemgui_steady [concat iemgui_steady_$vid]
- global $var_iemgui_steady
- set var_iemgui_snd [concat iemgui_snd_$vid]
- global $var_iemgui_snd
- set var_iemgui_rcv [concat iemgui_rcv_$vid]
- global $var_iemgui_rcv
- set var_iemgui_gui_nam [concat iemgui_gui_nam_$vid]
- global $var_iemgui_gui_nam
- set var_iemgui_gn_dx [concat iemgui_gn_dx_$vid]
- global $var_iemgui_gn_dx
- set var_iemgui_gn_dy [concat iemgui_gn_dy_$vid]
- global $var_iemgui_gn_dy
- set var_iemgui_gn_f [concat iemgui_gn_f_$vid]
- global $var_iemgui_gn_f
- set var_iemgui_gn_fs [concat iemgui_gn_fs_$vid]
- global $var_iemgui_gn_fs
- set var_iemgui_l2_f1_b0 [concat iemgui_l2_f1_b0_$vid]
- global $var_iemgui_l2_f1_b0
- set var_iemgui_bcol [concat iemgui_bcol_$vid]
- global $var_iemgui_bcol
- set var_iemgui_fcol [concat iemgui_fcol_$vid]
- global $var_iemgui_fcol
- set var_iemgui_lcol [concat iemgui_lcol_$vid]
- global $var_iemgui_lcol
-
- set $var_iemgui_wdt $wdt
- set $var_iemgui_min_wdt $min_wdt
- set $var_iemgui_hgt $hgt
- set $var_iemgui_min_hgt $min_hgt
- set $var_iemgui_min_rng $min_rng
- set $var_iemgui_max_rng $max_rng
- set $var_iemgui_rng_sch $rng_sched
- set $var_iemgui_lin0_log1 $lin0_log1
- set $var_iemgui_lilo0 $lilo0_label
- set $var_iemgui_lilo1 $lilo1_label
- set $var_iemgui_loadbang $loadbang
- set $var_iemgui_num $num
- set $var_iemgui_steady $steady
- if {$snd == "empty"} {set $var_iemgui_snd [format ""]
- } else {set $var_iemgui_snd [format "%s" $snd]}
- if {$rcv == "empty"} {set $var_iemgui_rcv [format ""]
- } else {set $var_iemgui_rcv [format "%s" $rcv]}
- if {$gui_name == "empty"} {set $var_iemgui_gui_nam [format ""]
- } else {set $var_iemgui_gui_nam [format "%s" $gui_name]}
-
- if {[string index [eval concat $$var_iemgui_snd] 0] == "#"} {
- set $var_iemgui_snd [string replace [eval concat $$var_iemgui_snd] 0 0 $] }
- if {[string index [eval concat $$var_iemgui_rcv] 0] == "#"} {
- set $var_iemgui_rcv [string replace [eval concat $$var_iemgui_rcv] 0 0 $] }
- if {[string index [eval concat $$var_iemgui_gui_nam] 0] == "#"} {
- set $var_iemgui_gui_nam [string replace [eval concat $$var_iemgui_gui_nam] 0 0 $] }
- set $var_iemgui_gn_dx $gn_dx
- set $var_iemgui_gn_dy $gn_dy
- set $var_iemgui_gn_f $gn_f
- set $var_iemgui_gn_fs $gn_fs
-
- set $var_iemgui_bcol $bcol
- set $var_iemgui_fcol $fcol
- set $var_iemgui_lcol $lcol
-
- set $var_iemgui_l2_f1_b0 0
-
- toplevel $id
- wm title $id [format "%s-PROPERTIES" $mainheader]
- wm protocol $id WM_DELETE_WINDOW [concat iemgui_cancel $id]
-
- frame $id.dim
- pack $id.dim -side top
- label $id.dim.head -text $dim_header
- label $id.dim.w_lab -text $wdt_label -width 6
- entry $id.dim.w_ent -textvariable $var_iemgui_wdt -width 5
- label $id.dim.dummy1 -text " " -width 10
- label $id.dim.h_lab -text $hgt_label -width 6
- entry $id.dim.h_ent -textvariable $var_iemgui_hgt -width 5
- pack $id.dim.head -side top
- pack $id.dim.w_lab $id.dim.w_ent $id.dim.dummy1 -side left
- if { $hgt_label != "empty" } {
- pack $id.dim.h_lab $id.dim.h_ent -side left}
-
- frame $id.rng
- pack $id.rng -side top
- label $id.rng.head -text $rng_header
- label $id.rng.min_lab -text $min_rng_label -width 6
- entry $id.rng.min_ent -textvariable $var_iemgui_min_rng -width 9
- label $id.rng.dummy1 -text " " -width 1
- label $id.rng.max_lab -text $max_rng_label -width 8
- entry $id.rng.max_ent -textvariable $var_iemgui_max_rng -width 9
- if { $rng_header != "empty" } {
- pack $id.rng.head -side top
- if { $min_rng_label != "empty" } {
- pack $id.rng.min_lab $id.rng.min_ent -side left}
- if { $max_rng_label != "empty" } {
- pack $id.rng.dummy1 \
- $id.rng.max_lab $id.rng.max_ent -side left} }
-
- if { [eval concat $$var_iemgui_lin0_log1] >= 0 || [eval concat $$var_iemgui_loadbang] >= 0 || [eval concat $$var_iemgui_num] > 0 || [eval concat $$var_iemgui_steady] >= 0 } {
- label $id.space1 -text "---------------------------------"
- pack $id.space1 -side top }
-
- frame $id.para
- pack $id.para -side top
- label $id.para.dummy2 -text "" -width 1
- label $id.para.dummy3 -text "" -width 1
- if {[eval concat $$var_iemgui_lin0_log1] == 0} {
- button $id.para.lilo -text [eval concat $$var_iemgui_lilo0] -width 5 -command "iemgui_lilo $id" }
- if {[eval concat $$var_iemgui_lin0_log1] == 1} {
- button $id.para.lilo -text [eval concat $$var_iemgui_lilo1] -width 5 -command "iemgui_lilo $id" }
- if {[eval concat $$var_iemgui_loadbang] == 0} {
- button $id.para.lb -text "no init" -width 5 -command "iemgui_lb $id" }
- if {[eval concat $$var_iemgui_loadbang] == 1} {
- button $id.para.lb -text "init" -width 5 -command "iemgui_lb $id" }
- label $id.para.num_lab -text $num_label -width 9
- entry $id.para.num_ent -textvariable $var_iemgui_num -width 4
- if {[eval concat $$var_iemgui_steady] == 0} {
- button $id.para.stdy_jmp -text "jump on click" -width 11 -command "iemgui_stdy_jmp $id" }
- if {[eval concat $$var_iemgui_steady] == 1} {
- button $id.para.stdy_jmp -text "steady on click" -width 11 -command "iemgui_stdy_jmp $id" }
- if {[eval concat $$var_iemgui_lin0_log1] >= 0} {
- pack $id.para.lilo -side left -expand 1}
- if {[eval concat $$var_iemgui_loadbang] >= 0} {
- pack $id.para.dummy2 $id.para.lb -side left -expand 1}
- if {[eval concat $$var_iemgui_num] > 0} {
- pack $id.para.dummy3 $id.para.num_lab $id.para.num_ent -side left -expand 1}
- if {[eval concat $$var_iemgui_steady] >= 0} {
- pack $id.para.dummy3 $id.para.stdy_jmp -side left -expand 1}
- if { $snd != "nosndno" || $rcv != "norcvno" } {
- label $id.space2 -text "---------------------------------"
- pack $id.space2 -side top }
-
- frame $id.snd
- pack $id.snd -side top
- label $id.snd.dummy1 -text "" -width 2
- label $id.snd.lab -text "send-symbol:" -width 12
- entry $id.snd.ent -textvariable $var_iemgui_snd -width 20
- if { $snd != "nosndno" } {
- pack $id.snd.dummy1 $id.snd.lab $id.snd.ent -side left}
-
- frame $id.rcv
- pack $id.rcv -side top
- label $id.rcv.lab -text "receive-symbol:" -width 15
- entry $id.rcv.ent -textvariable $var_iemgui_rcv -width 20
- if { $rcv != "norcvno" } {
- pack $id.rcv.lab $id.rcv.ent -side left}
-
- frame $id.gnam
- pack $id.gnam -side top
- label $id.gnam.head -text "--------------label:---------------"
- label $id.gnam.dummy1 -text "" -width 1
- label $id.gnam.lab -text "name:" -width 6
- entry $id.gnam.ent -textvariable $var_iemgui_gui_nam -width 29
- label $id.gnam.dummy2 -text "" -width 1
- pack $id.gnam.head -side top
- pack $id.gnam.dummy1 $id.gnam.lab $id.gnam.ent $id.gnam.dummy2 -side left
-
- frame $id.gnxy
- pack $id.gnxy -side top
- label $id.gnxy.x_lab -text "x_off:" -width 6
- entry $id.gnxy.x_ent -textvariable $var_iemgui_gn_dx -width 5
- label $id.gnxy.dummy1 -text " " -width 10
- label $id.gnxy.y_lab -text "y_off:" -width 6
- entry $id.gnxy.y_ent -textvariable $var_iemgui_gn_dy -width 5
- pack $id.gnxy.x_lab $id.gnxy.x_ent $id.gnxy.dummy1 \
- $id.gnxy.y_lab $id.gnxy.y_ent -side left
-
- frame $id.gnfs
- pack $id.gnfs -side top
- label $id.gnfs.f_lab -text "font:" -width 6
- if {[eval concat $$var_iemgui_gn_f] == 0} {
- button $id.gnfs.fb -text "courier" -font {courier 10 bold} -width 7 -command "iemgui_toggle_font $id" }
- if {[eval concat $$var_iemgui_gn_f] == 1} {
- button $id.gnfs.fb -text "helvetica" -font {helvetica 10 bold} -width 7 -command "iemgui_toggle_font $id" }
- if {[eval concat $$var_iemgui_gn_f] == 2} {
- button $id.gnfs.fb -text "times" -font {times 10 bold} -width 7 -command "iemgui_toggle_font $id" }
- label $id.gnfs.dummy1 -text "" -width 1
- label $id.gnfs.fs_lab -text "fontsize:" -width 8
- entry $id.gnfs.fs_ent -textvariable $var_iemgui_gn_fs -width 5
- pack $id.gnfs.f_lab $id.gnfs.fb $id.gnfs.dummy1 \
- $id.gnfs.fs_lab $id.gnfs.fs_ent -side left
-
- label $id.col_head -text "--------------colors:--------------"
- pack $id.col_head -side top
-
- frame $id.col_select
- pack $id.col_select -side top
- radiobutton $id.col_select.radio0 -value 0 -variable $var_iemgui_l2_f1_b0 \
- -text "backgd" -width 5
- radiobutton $id.col_select.radio1 -value 1 -variable $var_iemgui_l2_f1_b0 \
- -text "front" -width 5
- radiobutton $id.col_select.radio2 -value 2 -variable $var_iemgui_l2_f1_b0 \
- -text "label" -width 5
- if { [eval concat $$var_iemgui_fcol] >= 0 } {
- pack $id.col_select.radio0 $id.col_select.radio1 $id.col_select.radio2 -side left
- } else {pack $id.col_select.radio0 $id.col_select.radio2 -side left}
-
- frame $id.col_example_choose
- pack $id.col_example_choose -side top
- button $id.col_example_choose.but -text "compose color" -width 10 \
- -command "iemgui_choose_col_bkfrlb $id"
- label $id.col_example_choose.dummy1 -text "" -width 1
- if { [eval concat $$var_iemgui_fcol] >= 0 } {
- button $id.col_example_choose.fr_bk -text "o=||=o" -width 5 \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_fcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_fcol]] -pady 2
- } else {
- button $id.col_example_choose.fr_bk -text "o=||=o" -width 5 \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] -pady 2}
- button $id.col_example_choose.lb_bk -text "testlabel" -width 7 \
- -background [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -activebackground [format "#%6.6x" [eval concat $$var_iemgui_bcol]] \
- -foreground [format "#%6.6x" [eval concat $$var_iemgui_lcol]] \
- -activeforeground [format "#%6.6x" [eval concat $$var_iemgui_lcol]] -pady 2
-
- pack $id.col_example_choose.but $id.col_example_choose.dummy1 \
- $id.col_example_choose.fr_bk $id.col_example_choose.lb_bk -side left
-
- label $id.space3 -text "------or click color preset:-------"
- pack $id.space3 -side top
-
- frame $id.bcol
- pack $id.bcol -side top
- foreach i { 0 1 2 3 4 5 6 7 8 9 } hexcol { 16579836 14737632 12369084 \
- 16572640 16572608 16579784 14220504 14220540 14476540 16308476 } {
- button $id.bcol.c$i -background [format "#%6.6x" $hexcol] \
- -activebackground [format "#%6.6x" $hexcol] \
- -font {courier 2 normal} -padx 7 -pady 6 \
- -command [format "iemgui_preset_col %s %d" $id $hexcol] }
- pack $id.bcol.c0 $id.bcol.c1 $id.bcol.c2 $id.bcol.c3 $id.bcol.c4 \
- $id.bcol.c5 $id.bcol.c6 $id.bcol.c7 $id.bcol.c8 $id.bcol.c9 -side left
-
- frame $id.fcol
- pack $id.fcol -side top
- foreach i { 0 1 2 3 4 5 6 7 8 9 } hexcol { 10526880 8158332 6316128 \
- 16525352 16559172 15263784 1370132 2684148 3952892 16003312 } {
- button $id.fcol.c$i -background [format "#%6.6x" $hexcol] \
- -activebackground [format "#%6.6x" $hexcol] \
- -font {courier 2 normal} -padx 7 -pady 6 \
- -command [format "iemgui_preset_col %s %d" $id $hexcol] }
- pack $id.fcol.c0 $id.fcol.c1 $id.fcol.c2 $id.fcol.c3 $id.fcol.c4 \
- $id.fcol.c5 $id.fcol.c6 $id.fcol.c7 $id.fcol.c8 $id.fcol.c9 -side left
-
- frame $id.lcol
- pack $id.lcol -side top
- foreach i { 0 1 2 3 4 5 6 7 8 9 } hexcol { 4210752 2105376 0 \
- 9177096 5779456 7874580 2641940 17488 5256 5767248 } {
- button $id.lcol.c$i -background [format "#%6.6x" $hexcol] \
- -activebackground [format "#%6.6x" $hexcol] \
- -font {courier 2 normal} -padx 7 -pady 6 \
- -command [format "iemgui_preset_col %s %d" $id $hexcol] }
- pack $id.lcol.c0 $id.lcol.c1 $id.lcol.c2 $id.lcol.c3 $id.lcol.c4 \
- $id.lcol.c5 $id.lcol.c6 $id.lcol.c7 $id.lcol.c8 $id.lcol.c9 -side left
-
-
- label $id.space4 -text "---------------------------------"
- pack $id.space4 -side top
-
- frame $id.cao
- pack $id.cao -side top
- button $id.cao.cancel -text {Cancel} -width 6 \
- -command "iemgui_cancel $id"
- label $id.cao.dummy1 -text "" -width 3
- button $id.cao.apply -text {Apply} -width 6 \
- -command "iemgui_apply $id"
- label $id.cao.dummy2 -text "" -width 3
- button $id.cao.ok -text {OK} -width 6 \
- -command "iemgui_ok $id"
- pack $id.cao.cancel $id.cao.dummy1 \
- $id.cao.apply $id.cao.dummy2 \
- $id.cao.ok -side left
-
- label $id.space5 -text ""
- pack $id.space5 -side top
-
- if {[info tclversion] < 8.4} {
- bind $id <Key-Tab> {tkTabToWindow [tk_focusNext %W]}
- bind $id <<PrevWindow>> {tkTabToWindow [tk_focusPrev %W]}
- } else {
- bind $id <Key-Tab> {tk::TabToWindow [tk_focusNext %W]}
- bind $id <<PrevWindow>> {tk::TabToWindow [tk_focusPrev %W]}
- }
-
- bind $id.dim.w_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.dim.h_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.rng.min_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.rng.max_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.para.num_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.snd.ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.rcv.ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.gnam.ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.gnxy.x_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.gnxy.y_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.gnfs.fs_ent <KeyPress-Return> [concat iemgui_ok $id]
- bind $id.cao.ok <KeyPress-Return> [concat iemgui_ok $id]
-
- $id.dim.w_ent select from 0
- $id.dim.w_ent select adjust end
- focus $id.dim.w_ent
-}
-# end of change "iemlib"
-
-############ pdtk_array_dialog -- dialog window for arrays #########
-proc array_apply {id} {
-# strip "." from the TK id to make a variable name suffix
- set vid [string trimleft $id .]
-# for each variable, make a local variable to hold its name...
- set var_array_name [concat array_name_$vid]
- global $var_array_name
- set var_array_n [concat array_n_$vid]
- global $var_array_n
- set var_array_saveit [concat array_saveit_$vid]
- global $var_array_saveit
- set var_array_otherflag [concat array_otherflag_$vid]
- global $var_array_otherflag
- set mofo [eval concat $$var_array_name]
- if {[string index $mofo 0] == "$"} {
- set mofo [string replace $mofo 0 0 #] }
-
- pd [concat $id arraydialog $mofo \
- [eval concat $$var_array_n] \
- [eval concat $$var_array_saveit] \
- [eval concat $$var_array_otherflag] \
- \;]
-}
-
-proc array_cancel {id} {
- set cmd [concat $id cancel \;]
- pd $cmd
-}
-
-proc array_ok {id} {
- array_apply $id
- array_cancel $id
-}
-
-proc pdtk_array_dialog {id name n saveit newone} {
- set vid [string trimleft $id .]
-
- set var_array_name [concat array_name_$vid]
- global $var_array_name
- set var_array_n [concat array_n_$vid]
- global $var_array_n
- set var_array_saveit [concat array_saveit_$vid]
- global $var_array_saveit
- set var_array_otherflag [concat array_otherflag_$vid]
- global $var_array_otherflag
-
- set $var_array_name $name
- set $var_array_n $n
- set $var_array_saveit $saveit
- set $var_array_otherflag 0
-
- toplevel $id
- wm title $id {array}
- wm protocol $id WM_DELETE_WINDOW [concat array_cancel $id]
-
- frame $id.name
- pack $id.name -side top
- label $id.name.label -text "name"
- entry $id.name.entry -textvariable $var_array_name
- pack $id.name.label $id.name.entry -side left
-
- frame $id.n
- pack $id.n -side top
- label $id.n.label -text "size"
- entry $id.n.entry -textvariable $var_array_n
- pack $id.n.label $id.n.entry -side left
-
- checkbutton $id.saveme -text {save contents} -variable $var_array_saveit \
- -anchor w
- pack $id.saveme -side top
-
- if {$newone != 0} {
- frame $id.radio
- pack $id.radio -side top
- radiobutton $id.radio.radio0 -value 0 \
- -variable $var_array_otherflag \
- -text "in new graph"
- radiobutton $id.radio.radio1 -value 1 \
- -variable $var_array_otherflag \
- -text "in last graph"
- pack $id.radio.radio0 -side top -anchor w
- pack $id.radio.radio1 -side top -anchor w
- } else {
- checkbutton $id.deleteme -text {delete me} \
- -variable $var_array_otherflag -anchor w
- pack $id.deleteme -side top
- }
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "array_cancel $id"
- if {$newone == 0} {button $id.buttonframe.apply -text {Apply}\
- -command "array_apply $id"}
- button $id.buttonframe.ok -text {OK}\
- -command "array_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- if {$newone == 0} {pack $id.buttonframe.apply -side left -expand 1}
- pack $id.buttonframe.ok -side left -expand 1
-
- bind $id.name.entry <KeyPress-Return> [concat array_ok $id]
- bind $id.n.entry <KeyPress-Return> [concat array_ok $id]
- $id.name.entry select from 0
- $id.name.entry select adjust end
- focus $id.name.entry
-}
-
-############ pdtk_canvas_dialog -- dialog window for canvass #########
-proc canvas_apply {id} {
-# strip "." from the TK id to make a variable name suffix
- set vid [string trimleft $id .]
-# for each variable, make a local variable to hold its name...
- set var_canvas_xscale [concat canvas_xscale_$vid]
- global $var_canvas_xscale
- set var_canvas_yscale [concat canvas_yscale_$vid]
- global $var_canvas_yscale
- set var_canvas_graphme [concat canvas_graphme_$vid]
- global $var_canvas_graphme
-# set var_canvas_stretch [concat canvas_stretch_$vid]
-# global $var_canvas_stretch
- pd [concat $id donecanvasdialog \
- [eval concat $$var_canvas_xscale] \
- [eval concat $$var_canvas_yscale] \
- [eval concat $$var_canvas_graphme] \
- \;]
-}
-
-proc canvas_cancel {id} {
- set cmd [concat $id cancel \;]
- pd $cmd
-}
-
-proc canvas_ok {id} {
- canvas_apply $id
- canvas_cancel $id
-}
-
-proc pdtk_canvas_dialog {id xscale yscale graphme stretch} {
- set vid [string trimleft $id .]
-
- set var_canvas_xscale [concat canvas_xscale_$vid]
- global $var_canvas_xscale
- set var_canvas_yscale [concat canvas_yscale_$vid]
- global $var_canvas_yscale
- set var_canvas_graphme [concat canvas_graphme_$vid]
- global $var_canvas_graphme
-# set var_canvas_stretch [concat canvas_stretch_$vid]
-# global $var_canvas_stretch
-
- set $var_canvas_xscale $xscale
- set $var_canvas_yscale $yscale
- set $var_canvas_graphme $graphme
-# set $var_canvas_stretch $stretch
-
- toplevel $id
- wm title $id {canvas}
- wm protocol $id WM_DELETE_WINDOW [concat canvas_cancel $id]
-
- frame $id.xscale
- pack $id.xscale -side top
- label $id.xscale.label -text "X units per pixel"
- entry $id.xscale.entry -textvariable $var_canvas_xscale -width 10
- pack $id.xscale.label $id.xscale.entry -side left
-
- frame $id.yscale
- pack $id.yscale -side top
- label $id.yscale.label -text "Y units per pixel"
- entry $id.yscale.entry -textvariable $var_canvas_yscale -width 10
- pack $id.yscale.label $id.yscale.entry -side left
-
- checkbutton $id.graphme -text {graph on parent} \
- -variable $var_canvas_graphme -anchor w
- pack $id.graphme -side top
-
-# checkbutton $id.stretch -text {stretch on resize} \
-# -variable $var_canvas_stretch -anchor w
-# pack $id.stretch -side top
-
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "canvas_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "canvas_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "canvas_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- bind $id.xscale.entry <KeyPress-Return> [concat canvas_ok $id]
- bind $id.yscale.entry <KeyPress-Return> [concat canvas_ok $id]
- $id.xscale.entry select from 0
- $id.xscale.entry select adjust end
- focus $id.xscale.entry
-}
-
-############ pdtk_data_dialog -- run a data dialog #########
-proc dodata_send {name} {
-# puts stderr [$name.text get 0.0 end]
-
- for {set i 1} {[$name.text compare [concat $i.0 + 3 chars] < end]} \
- {incr i 1} {
-# puts stderr [concat it's [$name.text get $i.0 [expr $i + 1].0]]
- set cmd [concat $name data [$name.text get $i.0 [expr $i + 1].0] \;]
-# puts stderr $cmd
- pd $cmd
- }
- set cmd [concat $name end \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc dodata_cancel {name} {
- set cmd [concat $name cancel \;]
-# puts stderr $cmd
- pd $cmd
-}
-
-proc dodata_ok {name} {
- dodata_send $name
- dodata_cancel $name
-}
-
-proc pdtk_data_dialog {name stuff} {
-
- toplevel $name
- wm title $name {Atom}
- wm protocol $name WM_DELETE_WINDOW [concat dodata_cancel $name]
-
- frame $name.buttonframe
- pack $name.buttonframe -side bottom -fill x -pady 2m
- button $name.buttonframe.send -text {Send (Ctrl s)}\
- -command [concat dodata_send $name]
- button $name.buttonframe.ok -text {OK (Ctrl t)}\
- -command [concat dodata_ok $name]
- pack $name.buttonframe.send -side left -expand 1
- pack $name.buttonframe.ok -side left -expand 1
-
- text $name.text -relief raised -bd 2 -height 40 -width 60 \
- -yscrollcommand "$name.scroll set" -font -*-courier-bold--normal--12-*
- scrollbar $name.scroll -command "$name.text yview"
- pack $name.scroll -side right -fill y
- pack $name.text -side left -fill both -expand 1
- $name.text insert end $stuff
- focus $name.text
- bind $name.text <Control-t> [concat dodata_ok $name]
- bind $name.text <Control-s> [concat dodata_send $name]
-}
-
-############ check or uncheck the "edit" menu item ##############
-#####################iemlib#######################
-proc pdtk_canvas_editval {name value} {
- if { $value } {
- $name.m.edit entryconfigure "Edit mode" -indicatoron true
- } else {
- $name.m.edit entryconfigure "Edit mode" -indicatoron false
- }
-}
-#####################iemlib#######################
-
-############ pdtk_text_new -- create a new text object #2###########
-proc pdtk_text_new {canvasname myname x y text font color} {
-# if {$font < 13} {set fontname [format -*-courier-bold----%d-* $font]}
-# if {$font >= 13} {set fontname [format -*-courier-----%d-* $font]}
- $canvasname create text $x $y \
- -font [format -*-courier-bold--normal--%d-* $font] \
- -tags $myname -text $text -fill $color -anchor nw
-# pd [concat $myname size [$canvasname bbox $myname] \;]
-}
-
-################ pdtk_text_set -- change the text ##################
-proc pdtk_text_set {canvasname myname text} {
- $canvasname itemconfig $myname -text $text
-# pd [concat $myname size [$canvasname bbox $myname] \;]
-}
-
-############### event binding procedures for Pd window ################
-
-proc pdtk_pd_ctrlkey {name key shift} {
-# puts stderr [concat key $key shift $shift]
-# .dummy itemconfig goo -text [concat ---> control-key event $key];
- if {$key == "n" || $key == "N"} {menu_new}
- if {$key == "o" || $key == "O"} {menu_open}
- if {$key == "m" || $key == "M"} {menu_send}
- if {$key == "q" || $key == "Q"} {
- if {$shift == 1} {menu_really_quit} else {menu_quit}
- }
- if {$key == "slash"} {menu_audio 1}
- if {$key == "period"} {menu_audio 0}
-}
-
-######### startup function. ##############
-# Tell pd the current directory; this is used in case the command line
-# asked pd to open something. Also, get character width and height for
-# font sizes 8, 10, 12, 14, 16, and 24.
-
-proc pdtk_pd_startup {version apilist} {
- global pd_myversion pd_apilist
- set pd_myversion $version
- set pd_apilist $apilist
-
- set width1 [font measure -*-courier-bold--normal--8-* x]
- set height1 [lindex [font metrics -*-courier-bold--normal--8-*] 5]
-
- set width2 [font measure -*-courier-bold--normal--10-* x]
- set height2 [lindex [font metrics -*-courier-bold--normal--10-*] 5]
-
- set width3 [font measure -*-courier-bold--normal--12-* x]
- set height3 [lindex [font metrics -*-courier-bold--normal--12-*] 5]
-
- set width4 [font measure -*-courier-bold--normal--14-* x]
- set height4 [lindex [font metrics -*-courier-bold--normal--14-*] 5]
-
- set width5 [font measure -*-courier-bold--normal--16-* x]
- set height5 [lindex [font metrics -*-courier-bold--normal--16-*] 5]
-
- set width6 [font measure -*-courier-bold--normal--24-* x]
- set height6 [lindex [font metrics -*-courier-bold--normal--24-*] 5]
-
- set width7 [font measure -*-courier-bold--normal--36-* x]
- set height7 [lindex [font metrics -*-courier-bold--normal--36-*] 5]
-
- set tclpatch [info patchlevel]
- if {$tclpatch == "8.3.0" || \
- $tclpatch == "8.3.1" || \
- $tclpatch == "8.3.2" || \
- $tclpatch == "8.3.3" } {
- set oldtclversion 1
- } else {
- set oldtclversion 0
- }
- pd [concat pd init [pdtk_enquote [pwd]] \
- 8 $width1 $height1 \
- 10 $width2 $height2 \
- 12 $width3 $height3 \
- 14 $width4 $height4 \
- 16 $width5 $height5 \
- 24 $width6 $height6 \
- 36 $width7 $height7 \
- $oldtclversion \;];
-
- # add the audio and help menus to the Pd window. We delayed this
- # so that we'd know the value of "apilist".
- menu_addstd .mbar
-
-}
-
-##################### DSP ON/OFF, METERS, DIO ERROR ###################
-proc pdtk_pd_dsp {value} {
- global ctrls_audio_on
- if {$value == "ON"} {set ctrls_audio_on 1} else {set ctrls_audio_on 0}
-# puts stderr [concat its $ctrls_audio_on]
-}
-
-proc pdtk_pd_meters {indb outdb inclip outclip} {
-# puts stderr [concat meters $indb $outdb $inclip $outclip]
- global ctrls_inlevel ctrls_outlevel
- set ctrls_inlevel $indb
- if {$inclip == 1} {
- .controls.inout.in.clip configure -background red
- } else {
- .controls.inout.in.clip configure -background grey
- }
- set ctrls_outlevel $outdb
- if {$outclip == 1} {
- .controls.inout.out.clip configure -background red
- } else {
- .controls.inout.out.clip configure -background grey
- }
-
-}
-
-proc pdtk_pd_dio {red} {
-# puts stderr [concat dio $red]
- if {$red == 1} {
- .controls.dio configure -background red -activebackground red
- } else {
- .controls.dio configure -background grey -activebackground lightgrey
- }
-
-}
-
-############# text editing from the "edit" menu ###################
-set edit_number 1
-
-proc texteditor_send {name} {
- set topname [string trimright $name .text]
- for {set i 0} \
- {[$name compare [concat 0.0 + [expr $i + 1] chars] < end]} \
- {incr i 1} {
- set cha [$name get [concat 0.0 + $i chars]]
- scan $cha %c keynum
- pd [concat pd key 1 $keynum 0 \;]
- }
-}
-
-proc texteditor_ok {name} {
- set topname [string trimright $name .text]
- texteditor_send $name
- destroy $topname
-}
-
-
-proc pdtk_pd_texteditor {stuff} {
- global edit_number
- set name [format ".text%d" $edit_number]
- set edit_number [expr $edit_number + 1]
-
- toplevel $name
- wm title $name {TEXT}
-
- frame $name.buttons
- pack $name.buttons -side bottom -fill x -pady 2m
- button $name.buttons.send -text {Send (Ctrl s)}\
- -command "texteditor_send $name.text"
- button $name.buttons.ok -text {OK (Ctrl t)}\
- -command "texteditor_ok $name.text"
- pack $name.buttons.send -side left -expand 1
- pack $name.buttons.ok -side left -expand 1
-
- text $name.text -relief raised -bd 2 -height 12 -width 60 \
- -yscrollcommand "$name.scroll set" -font -*-courier-bold--normal--12-*
- scrollbar $name.scroll -command "$name.text yview"
- pack $name.scroll -side right -fill y
- pack $name.text -side left -fill both -expand 1
- $name.text insert end $stuff
- focus $name.text
- bind $name.text <Control-t> {texteditor_ok %W}
- bind $name.text <Control-s> {texteditor_send %W}
-}
-
-############# open and save dialogs for objects in Pd ##########
-
-proc pdtk_openpanel {target} {
- global pd_opendir
- set filename [tk_getOpenFile \
- -initialdir $pd_opendir]
- if {$filename != ""} {
- set directory [string range $filename 0 \
- [expr [string last / $filename ] - 1]]
- set pd_opendir $directory
-
- pd [concat $target symbol [pdtk_enquote $filename] \;]
- }
-}
-
-proc pdtk_savepanel {target} {
- set filename [tk_getSaveFile]
- if {$filename != ""} {
- pd [concat $target symbol [pdtk_enquote $filename] \;]
- }
-}
-
-########################### comport hack ########################
-
-set com1 0
-set com2 0
-set com3 0
-set com4 0
-
-proc com1_open {} {
- global com1
- set com1 [open com1 w]
- .dummy itemconfig goo -text $com1
- fconfigure $com1 -buffering none
- fconfigure $com1 -mode 19200,e,8,2
-}
-
-proc com1_send {str} {
- global com1
- puts -nonewline $com1 $str
-}
-
-
-############# start a polling process to watch the socket ##############
-# this is needed for nt, and presumably for Mac as well.
-# in UNIX this is handled by a tcl callback (set up in t_tkcmd.c)
-
-if {$pd_nt == 1} {
- proc polleofloop {} {
- pd_pollsocket
- after 20 polleofloop
- }
-
- polleofloop
-}
-
-####################### audio dialog ##################3
-
-proc audio_apply {id} {
- global audio_indev1 audio_indev2 audio_indev3 audio_indev4
- global audio_inchan1 audio_inchan2 audio_inchan3 audio_inchan4
- global audio_outdev1 audio_outdev2 audio_outdev3 audio_outdev4
- global audio_outchan1 audio_outchan2 audio_outchan3 audio_outchan4
- global audio_sr audio_advance
-
- pd [concat pd audio-dialog \
- $audio_indev1 \
- $audio_indev2 \
- $audio_indev3 \
- $audio_indev4 \
- $audio_inchan1 \
- $audio_inchan2 \
- $audio_inchan3 \
- $audio_inchan4 \
- $audio_outdev1 \
- $audio_outdev2 \
- $audio_outdev3 \
- $audio_outdev4 \
- $audio_outchan1 \
- $audio_outchan2 \
- $audio_outchan3 \
- $audio_outchan4 \
- $audio_sr \
- $audio_advance \
- \;]
-}
-
-proc audio_cancel {id} {
- pd [concat $id cancel \;]
-}
-
-proc audio_ok {id} {
- audio_apply $id
- audio_cancel $id
-}
-
-# callback from popup menu
-proc audio_popup_action {buttonname varname devlist index} {
- global audio_indevlist audio_outdevlist $varname
- $buttonname configure -text [lindex $devlist $index]
-# puts stderr [concat popup_action $buttonname $varname $index]
- set $varname $index
-}
-
-# create a popup menu
-proc audio_popup {name buttonname varname devlist} {
- if [winfo exists $name.popup] {destroy $name.popup}
- menu $name.popup -tearoff false
-# puts stderr [concat $devlist ]
- for {set x 0} {$x<[llength $devlist]} {incr x} {
- $name.popup add command -label [lindex $devlist $x] \
- -command [list audio_popup_action \
- $buttonname $varname $devlist $x]
- }
- tk_popup $name.popup [winfo pointerx $name] [winfo pointery $name] 0
-}
-
-# start a dialog window to select audio devices and settings. "multi"
-# is 0 if only one device is allowed; 1 if one apiece may be specified for
-# input and output; and 2 if we can select multiple devices. "longform"
-# (which only makes sense if "multi" is 2) asks us to make controls for
-# opening several devices; if not, we get an extra button to turn longform
-# on and restart the dialog.
-
-proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
- inchan1 inchan2 inchan3 inchan4 \
- outdevlist outdev1 outdev2 outdev3 outdev4 \
- outchan1 outchan2 outchan3 outchan4 sr advance multi longform} {
- global audio_indev1 audio_indev2 audio_indev3 audio_indev4
- global audio_inchan1 audio_inchan2 audio_inchan3 audio_inchan4
- global audio_outdev1 audio_outdev2 audio_outdev3 audio_outdev4
- global audio_outchan1 audio_outchan2 audio_outchan3 audio_outchan4
- global audio_sr audio_advance
- global audio_indevlist audio_outdevlist
-
- set audio_indev1 $indev1
- set audio_indev2 $indev2
- set audio_indev3 $indev3
- set audio_indev4 $indev4
- set audio_inchan1 $inchan1
- set audio_inchan2 $inchan2
- set audio_inchan3 $inchan3
- set audio_inchan4 $inchan4
- set audio_outdev1 $outdev1
- set audio_outdev2 $outdev2
- set audio_outdev3 $outdev3
- set audio_outdev4 $outdev4
- set audio_outchan1 $outchan1
- set audio_outchan2 $outchan2
- set audio_outchan3 $outchan3
- set audio_outchan4 $outchan4
- set audio_sr $sr
- set audio_advance $advance
- set audio_indevlist $indevlist
- set audio_outdevlist $outdevlist
-
- toplevel $id
- wm title $id {audio}
- wm protocol $id WM_DELETE_WINDOW [concat audio_cancel $id]
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "audio_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "audio_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "audio_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- # sample rate and advance
- frame $id.srf
- pack $id.srf -side top
-
- label $id.srf.l1 -text "sample rate:"
- entry $id.srf.x1 -textvariable audio_sr -width 7
- label $id.srf.l2 -text "delay (msec):"
- entry $id.srf.x2 -textvariable audio_advance -width 4
- pack $id.srf.l1 $id.srf.x1 $id.srf.l2 $id.srf.x2 -side left
-
- # input device 1
- frame $id.in1f
- pack $id.in1f -side top
-
- label $id.in1f.l1 -text "input device 1:"
- button $id.in1f.x1 -text [lindex $indevlist $audio_indev1] \
- -command [list audio_popup $id $id.in1f.x1 audio_indev1 $indevlist]
- label $id.in1f.l2 -text "channels:"
- entry $id.in1f.x2 -textvariable audio_inchan1 -width 3
- pack $id.in1f.l1 $id.in1f.x1 $id.in1f.l2 $id.in1f.x2 -side left
-
- # input device 2
- if {$longform && $multi > 1 && [llength $indevlist] > 1} {
- frame $id.in2f
- pack $id.in2f -side top
-
- label $id.in2f.l1 -text "input device 2:"
- button $id.in2f.x1 -text [lindex $indevlist $audio_indev2] \
- -command [list audio_popup $id $id.in2f.x1 audio_indev2 $indevlist]
- label $id.in2f.l2 -text "channels:"
- entry $id.in2f.x2 -textvariable audio_inchan2 -width 3
- pack $id.in2f.l1 $id.in2f.x1 $id.in2f.l2 $id.in2f.x2 -side left
- }
-
- # input device 3
- if {$longform && $multi > 1 && [llength $indevlist] > 2} {
- frame $id.in3f
- pack $id.in3f -side top
-
- label $id.in3f.l1 -text "input device 3:"
- button $id.in3f.x1 -text [lindex $indevlist $audio_indev3] \
- -command [list audio_popup $id $id.in3f.x1 audio_indev3 $indevlist]
- label $id.in3f.l2 -text "channels:"
- entry $id.in3f.x2 -textvariable audio_inchan3 -width 3
- pack $id.in3f.l1 $id.in3f.x1 $id.in3f.l2 $id.in3f.x2 -side left
- }
-
- # input device 4
- if {$longform && $multi > 1 && [llength $indevlist] > 3} {
- frame $id.in4f
- pack $id.in4f -side top
-
- label $id.in4f.l1 -text "input device 4:"
- button $id.in4f.x1 -text [lindex $indevlist $audio_indev4] \
- -command [list audio_popup $id $id.in4f.x1 audio_indev4 $indevlist]
- label $id.in4f.l2 -text "channels:"
- entry $id.in4f.x2 -textvariable audio_inchan4 -width 3
- pack $id.in4f.l1 $id.in4f.x1 $id.in4f.l2 $id.in4f.x2 -side left
- }
-
- # output device 1
- frame $id.out1f
- pack $id.out1f -side top
-
- if {$multi == 0} {
- label $id.out1f.l1 \
- -text "(output device same as input device) .............. "
- } else {
- label $id.out1f.l1 -text "output device 1:"
- button $id.out1f.x1 -text [lindex $outdevlist $audio_outdev1] \
- -command \
- [list audio_popup $id $id.out1f.x1 audio_outdev1 $outdevlist]
- }
- label $id.out1f.l2 -text "channels:"
- entry $id.out1f.x2 -textvariable audio_outchan1 -width 3
- if {$multi == 0} {
- pack $id.out1f.l1 $id.out1f.l2 $id.out1f.x2 -side left
- } else {
- pack $id.out1f.l1 $id.out1f.x1 $id.out1f.l2 $id.out1f.x2 -side left
- }
-
- # output device 2
- if {$longform && $multi > 1 && [llength $indevlist] > 1} {
- frame $id.out2f
- pack $id.out2f -side top
- label $id.out2f.l1 -text "output device 2:"
- button $id.out2f.x1 -text [lindex $outdevlist $audio_outdev2] \
- -command \
- [list audio_popup $id $id.out2f.x1 audio_outdev2 $outdevlist]
- label $id.out2f.l2 -text "channels:"
- entry $id.out2f.x2 -textvariable audio_outchan2 -width 3
- pack $id.out2f.l1 $id.out2f.x1 $id.out2f.l2 $id.out2f.x2 -side left
- }
-
- # output device 3
- if {$longform && $multi > 1 && [llength $indevlist] > 2} {
- frame $id.out3f
- pack $id.out3f -side top
- label $id.out3f.l1 -text "output device 3:"
- button $id.out3f.x1 -text [lindex $outdevlist $audio_outdev3] \
- -command \
- [list audio_popup $id $id.out3f.x1 audio_outdev3 $outdevlist]
- label $id.out3f.l2 -text "channels:"
- entry $id.out3f.x2 -textvariable audio_outchan3 -width 3
- pack $id.out3f.l1 $id.out3f.x1 $id.out3f.l2 $id.out3f.x2 -side left
- }
-
- # output device 4
- if {$longform && $multi > 1 && [llength $indevlist] > 3} {
- frame $id.out4f
- pack $id.out4f -side top
- label $id.out4f.l1 -text "output device 4:"
- button $id.out4f.x1 -text [lindex $outdevlist $audio_outdev4] \
- -command \
- [list audio_popup $id $id.out4f.x1 audio_outdev4 $outdevlist]
- label $id.out4f.l2 -text "channels:"
- entry $id.out4f.x2 -textvariable audio_outchan4 -width 3
- pack $id.out4f.l1 $id.out4f.x1 $id.out4f.l2 $id.out4f.x2 -side left
- }
-
- # if not the "long form" but if "multi" is 2, make a button to
- # restart with longform set.
-
- if {$longform == 0 && $multi > 1} {
- frame $id.longbutton
- pack $id.longbutton -side top
- button $id.longbutton.b -text {use multiple devices} \
- -command {pd pd audio-properties 1 \;}
- pack $id.longbutton.b
- }
- bind $id.srf.x1 <KeyPress-Return> [concat audio_ok $id]
- bind $id.srf.x2 <KeyPress-Return> [concat audio_ok $id]
- bind $id.in1f.x2 <KeyPress-Return> [concat audio_ok $id]
- $id.srf.x1 select from 0
- $id.srf.x1 select adjust end
- focus $id.srf.x1
-}
-
-####################### midi dialog ##################3
-
-proc midi_apply {id} {
- global midi_indev1 midi_indev2 midi_indev3 midi_indev4
- global midi_outdev1 midi_outdev2 midi_outdev3 midi_outdev4
-
- pd [concat pd midi-dialog \
- $midi_indev1 \
- $midi_indev2 \
- $midi_indev3 \
- $midi_indev4 \
- $midi_outdev1 \
- $midi_outdev2 \
- $midi_outdev3 \
- $midi_outdev4 \
- \;]
-}
-
-proc midi_cancel {id} {
- pd [concat $id cancel \;]
-}
-
-proc midi_ok {id} {
- midi_apply $id
- midi_cancel $id
-}
-
-# callback from popup menu
-proc midi_popup_action {buttonname varname devlist index} {
- global midi_indevlist midi_outdevlist $varname
- $buttonname configure -text [lindex $devlist $index]
-# puts stderr [concat popup_action $buttonname $varname $index]
- set $varname $index
-}
-
-# create a popup menu
-proc midi_popup {name buttonname varname devlist} {
- if [winfo exists $name.popup] {destroy $name.popup}
- menu $name.popup -tearoff false
-# puts stderr [concat $devlist ]
- for {set x 0} {$x<[llength $devlist]} {incr x} {
- $name.popup add command -label [lindex $devlist $x] \
- -command [list midi_popup_action \
- $buttonname $varname $devlist $x]
- }
- tk_popup $name.popup [winfo pointerx $name] [winfo pointery $name] 0
-}
-
-# start a dialog window to select midi devices. "longform" asks us to make
-# controls for opening several devices; if not, we get an extra button to
-# turn longform on and restart the dialog.
-
-proc pdtk_midi_dialog {id indevlist indev1 indev2 indev3 indev4 \
- outdevlist outdev1 outdev2 outdev3 outdev4 longform} {
- global midi_indev1 midi_indev2 midi_indev3 midi_indev4
- global midi_outdev1 midi_outdev2 midi_outdev3 midi_outdev4
- global midi_indevlist midi_outdevlist
-
- set midi_indev1 $indev1
- set midi_indev2 $indev2
- set midi_indev3 $indev3
- set midi_indev4 $indev4
- set midi_outdev1 $outdev1
- set midi_outdev2 $outdev2
- set midi_outdev3 $outdev3
- set midi_outdev4 $outdev4
- set midi_indevlist $indevlist
- set midi_outdevlist $outdevlist
-
- toplevel $id
- wm title $id {midi}
- wm protocol $id WM_DELETE_WINDOW [concat midi_cancel $id]
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "midi_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "midi_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "midi_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- # input device 1
- frame $id.in1f
- pack $id.in1f -side top
-
- label $id.in1f.l1 -text "input device 1:"
- button $id.in1f.x1 -text [lindex $indevlist $midi_indev1] \
- -command [list midi_popup $id $id.in1f.x1 midi_indev1 $indevlist]
- pack $id.in1f.l1 $id.in1f.x1 -side left
-
- # input device 2
- if {$longform && [llength $indevlist] > 2} {
- frame $id.in2f
- pack $id.in2f -side top
-
- label $id.in2f.l1 -text "input device 2:"
- button $id.in2f.x1 -text [lindex $indevlist $midi_indev2] \
- -command [list midi_popup $id $id.in2f.x1 midi_indev2 $indevlist]
- pack $id.in2f.l1 $id.in2f.x1 -side left
- }
-
- # input device 3
- if {$longform && [llength $indevlist] > 3} {
- frame $id.in3f
- pack $id.in3f -side top
-
- label $id.in3f.l1 -text "input device 3:"
- button $id.in3f.x1 -text [lindex $indevlist $midi_indev3] \
- -command [list midi_popup $id $id.in3f.x1 midi_indev3 $indevlist]
- pack $id.in3f.l1 $id.in3f.x1 -side left
- }
-
- # input device 4
- if {$longform && [llength $indevlist] > 4} {
- frame $id.in4f
- pack $id.in4f -side top
-
- label $id.in4f.l1 -text "input device 4:"
- button $id.in4f.x1 -text [lindex $indevlist $midi_indev4] \
- -command [list midi_popup $id $id.in4f.x1 midi_indev4 $indevlist]
- pack $id.in4f.l1 $id.in4f.x1 -side left
- }
-
- # output device 1
-
- frame $id.out1f
- pack $id.out1f -side top
- label $id.out1f.l1 -text "output device 1:"
- button $id.out1f.x1 -text [lindex $outdevlist $midi_outdev1] \
- -command [list midi_popup $id $id.out1f.x1 midi_outdev1 $outdevlist]
- pack $id.out1f.l1 $id.out1f.x1 -side left
-
- # output device 2
- if {$longform && [llength $indevlist] > 2} {
- frame $id.out2f
- pack $id.out2f -side top
- label $id.out2f.l1 -text "output device 2:"
- button $id.out2f.x1 -text [lindex $outdevlist $midi_outdev2] \
- -command \
- [list midi_popup $id $id.out2f.x1 midi_outdev2 $outdevlist]
- pack $id.out2f.l1 $id.out2f.x1 -side left
- }
-
- # output device 3
- if {$longform && [llength $indevlist] > 3} {
- frame $id.out3f
- pack $id.out3f -side top
- label $id.out3f.l1 -text "output device 3:"
- button $id.out3f.x1 -text [lindex $outdevlist $midi_outdev3] \
- -command \
- [list midi_popup $id $id.out3f.x1 midi_outdev3 $outdevlist]
- pack $id.out3f.l1 $id.out3f.x1 -side left
- }
-
- # output device 4
- if {$longform && [llength $indevlist] > 4} {
- frame $id.out4f
- pack $id.out4f -side top
- label $id.out4f.l1 -text "output device 4:"
- button $id.out4f.x1 -text [lindex $outdevlist $midi_outdev4] \
- -command \
- [list midi_popup $id $id.out4f.x1 midi_outdev4 $outdevlist]
- pack $id.out4f.l1 $id.out4f.x1 -side left
- }
-
- # if not the "long form" make a button to
- # restart with longform set.
-
- if {$longform == 0} {
- frame $id.longbutton
- pack $id.longbutton -side top
- button $id.longbutton.b -text {use multiple devices} \
- -command {pd pd midi-properties 1 \;}
- pack $id.longbutton.b
- }
-}
-
-############ pdtk_path_dialog -- dialog window for search path #########
-
-proc path_apply {id} {
- global pd_path0 pd_path1 pd_path2 pd_path3 pd_path4
- global pd_path5 pd_path6 pd_path7 pd_path8 pd_path9
-
- pd [concat pd path-dialog \
- $pd_path0 $pd_path1 $pd_path2 $pd_path3 $pd_path4 \
- $pd_path5 $pd_path6 $pd_path7 $pd_path8 $pd_path9 \
- \;]
-}
-
-proc path_cancel {id} {
- pd [concat $id cancel \;]
-}
-
-proc path_ok {id} {
- path_apply $id
- path_cancel $id
-}
-set pd_path0 sdfgh
-
-proc pdtk_path_dialog {id} {
- global pd_path0 pd_path1 pd_path2 pd_path3 pd_path4
- global pd_path5 pd_path6 pd_path7 pd_path8 pd_path9
-
- toplevel $id
- wm title $id {PD search path for patches and other files}
- wm protocol $id WM_DELETE_WINDOW [concat path_cancel $id]
-
- frame $id.buttonframe
- pack $id.buttonframe -side bottom -fill x -pady 2m
- button $id.buttonframe.cancel -text {Cancel}\
- -command "path_cancel $id"
- button $id.buttonframe.apply -text {Apply}\
- -command "path_apply $id"
- button $id.buttonframe.ok -text {OK}\
- -command "path_ok $id"
- pack $id.buttonframe.cancel -side left -expand 1
- pack $id.buttonframe.apply -side left -expand 1
- pack $id.buttonframe.ok -side left -expand 1
-
- for {set x 0} {$x < 10} {incr x} {
- # input device 1
- entry $id.f$x -textvariable pd_path$x -width 80
- bind $id.f$x <KeyPress-Return> [concat path_ok $id]
- pack $id.f$x -side top
- }
-
- focus $id.f0
-}
-
-proc pd_set {var value} {
- global $var
- set $var $value
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/u_pdreceive.c b/apps/plugins/pdbox/PDa/src/u_pdreceive.c
deleted file mode 100644
index 51e60f7d5f..0000000000
--- a/apps/plugins/pdbox/PDa/src/u_pdreceive.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/* Copyright (c) 2000 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in the Pd distribution. */
-
-/* the "pdreceive" command. This is a standalone program that receives messages
-from Pd via the netsend/netreceive ("FUDI") protocol, and copies them to
-standard output. */
-
-#include <sys/types.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#ifdef UNIX
-#include <sys/time.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#define SOCKET_ERROR -1
-#else
-#include <winsock.h>
-#endif
-
-typedef struct _fdpoll
-{
- int fdp_fd;
- char *fdp_inbuf;
- int fdp_inhead;
- int fdp_intail;
- int fdp_udp;
-} t_fdpoll;
-
-static int nfdpoll;
-static t_fdpoll *fdpoll;
-static int maxfd;
-static int sockfd;
-static int protocol;
-
-static void sockerror(char *s);
-static void x_closesocket(int fd);
-static void dopoll(void);
-#define BUFSIZE 4096
-
-int main(int argc, char **argv)
-{
- int portno;
- struct sockaddr_in server;
- int nretry = 10;
-#ifdef MSW
- short version = MAKEWORD(2, 0);
- WSADATA nobby;
-#endif
- if (argc < 2 || sscanf(argv[1], "%d", &portno) < 1 || portno <= 0)
- goto usage;
- if (argc >= 3)
- {
- if (!strcmp(argv[2], "tcp"))
- protocol = SOCK_STREAM;
- else if (!strcmp(argv[2], "udp"))
- protocol = SOCK_DGRAM;
- else goto usage;
- }
- else protocol = SOCK_STREAM;
-#ifdef MSW
- if (WSAStartup(version, &nobby)) sockerror("WSAstartup");
-#endif
- sockfd = socket(AF_INET, protocol, 0);
- if (sockfd < 0)
- {
- sockerror("socket()");
- exit(1);
- }
- maxfd = sockfd + 1;
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = INADDR_ANY;
-
-#ifdef IRIX
- /* this seems to work only in IRIX but is unnecessary in
- Linux. Not sure what MSW needs in place of this. */
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
- post("setsockopt failed\n");
-#endif
-
- /* assign client port number */
- server.sin_port = htons((unsigned short)portno);
-
- /* name the socket */
- if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
- {
- sockerror("bind");
- x_closesocket(sockfd);
- return (0);
- }
- if (protocol == SOCK_STREAM)
- {
- if (listen(sockfd, 5) < 0)
- {
- sockerror("listen");
- x_closesocket(sockfd);
- exit(1);
- }
- }
- /* now loop forever selecting on sockets */
- while (1)
- dopoll();
-
-usage:
- fprintf(stderr, "usage: pdreceive <portnumber> [udp|tcp]\n");
- fprintf(stderr, "(default is tcp)\n");
- exit(1);
-}
-
-static void addport(int fd)
-{
- int nfd = nfdpoll;
- t_fdpoll *fp;
- fdpoll = (t_fdpoll *)realloc(fdpoll,
- (nfdpoll+1) * sizeof(t_fdpoll));
- fp = fdpoll + nfdpoll;
- fp->fdp_fd = fd;
- nfdpoll++;
- if (fd >= maxfd) maxfd = fd + 1;
- fp->fdp_inhead = fp->fdp_intail = 0;
- if (!(fp->fdp_inbuf = malloc(BUFSIZE)))
- {
- fprintf(stderr, "out of memory");
- exit(1);
- }
- printf("number_connected %d;\n", nfdpoll);
-}
-
-static void rmport(t_fdpoll *x)
-{
- int nfd = nfdpoll;
- int i, size = nfdpoll * sizeof(t_fdpoll);
- t_fdpoll *fp;
- for (i = nfdpoll, fp = fdpoll; i--; fp++)
- {
- if (fp == x)
- {
- x_closesocket(fp->fdp_fd);
- free(fp->fdp_inbuf);
- while (i--)
- {
- fp[0] = fp[1];
- fp++;
- }
- fdpoll = (t_fdpoll *)realloc(fdpoll,
- (nfdpoll-1) * sizeof(t_fdpoll));
- nfdpoll--;
- printf("number_connected %d;\n", nfdpoll);
- return;
- }
- }
- fprintf(stderr, "warning: item removed from poll list but not found");
-}
-
-static void doconnect(void)
-{
- int fd = accept(sockfd, 0, 0);
- if (fd < 0)
- perror("accept");
- else addport(fd);
-}
-
-static void udpread(void)
-{
- char buf[BUFSIZE];
- int ret = recv(sockfd, buf, BUFSIZE, 0);
- if (ret < 0)
- {
- sockerror("recv (udp)");
- x_closesocket(sockfd);
- exit(1);
- }
- else if (ret > 0)
- {
-#ifdef UNIX
- if (write(1, buf, ret) < ret)
- {
- perror("write");
- exit(1);
- }
-#else
- int j;
- for (j = 0; j < ret; j++)
- putchar(buf[j]);
-#endif
- }
-}
-
-static int tcpmakeoutput(t_fdpoll *x)
-{
- char messbuf[BUFSIZE+1], *bp = messbuf;
- int indx;
- int inhead = x->fdp_inhead;
- int intail = x->fdp_intail;
- char *inbuf = x->fdp_inbuf;
- if (intail == inhead)
- return (0);
- for (indx = intail; indx != inhead; indx = (indx+1)&(BUFSIZE-1))
- {
- /* search for a semicolon. */
- char c = *bp++ = inbuf[indx];
- if (c == ';')
- {
- intail = (indx+1)&(BUFSIZE-1);
- if (inbuf[intail] == '\n')
- intail = (intail+1)&(BUFSIZE-1);
- *bp++ = '\n';
-#ifdef UNIX
- write(1, messbuf, bp - messbuf);
-#else
- {
- int j;
- for (j = 0; j < bp - messbuf; j++)
- putchar(messbuf[j]);
- }
-#endif
- x->fdp_inhead = inhead;
- x->fdp_intail = intail;
- return (1);
- }
- }
- return (0);
-}
-
-static void tcpread(t_fdpoll *x)
-{
- int readto =
- (x->fdp_inhead >= x->fdp_intail ? BUFSIZE : x->fdp_intail-1);
- int ret;
-
- /* the input buffer might be full. If so, drop the whole thing */
- if (readto == x->fdp_inhead)
- {
- fprintf(stderr, "pd: dropped message from gui\n");
- x->fdp_inhead = x->fdp_intail = 0;
- readto = BUFSIZE;
- }
- else
- {
- ret = recv(x->fdp_fd, x->fdp_inbuf + x->fdp_inhead,
- readto - x->fdp_inhead, 0);
- if (ret < 0)
- {
- sockerror("recv (tcp)");
- rmport(x);
- }
- else if (ret == 0)
- rmport(x);
- else
- {
- x->fdp_inhead += ret;
- if (x->fdp_inhead >= BUFSIZE)
- x->fdp_inhead = 0;
- while (tcpmakeoutput(x))
- ;
- }
- }
-}
-
-static void dopoll(void)
-{
- int i;
- t_fdpoll *fp;
- fd_set readset, writeset, exceptset;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
-
- FD_SET(sockfd, &readset);
- if (protocol == SOCK_STREAM)
- {
- for (fp = fdpoll, i = nfdpoll; i--; fp++)
- FD_SET(fp->fdp_fd, &readset);
- }
- if (select(maxfd+1, &readset, &writeset, &exceptset, 0) < 0)
- {
- perror("select");
- exit(1);
- }
- if (protocol == SOCK_STREAM)
- {
- for (i = 0; i < nfdpoll; i++)
- if (FD_ISSET(fdpoll[i].fdp_fd, &readset))
- tcpread(&fdpoll[i]);
- if (FD_ISSET(sockfd, &readset))
- doconnect();
- }
- else
- {
- if (FD_ISSET(sockfd, &readset))
- udpread();
- }
-}
-
-
-static void sockerror(char *s)
-{
-#ifdef MSW
- int err = WSAGetLastError();
- if (err == 10054) return;
- else if (err == 10044)
- {
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
- }
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
- fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
-}
-
-static void x_closesocket(int fd)
-{
-#ifdef UNIX
- close(fd);
-#endif
-#ifdef MSW
- closesocket(fd);
-#endif
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/u_pdsend.c b/apps/plugins/pdbox/PDa/src/u_pdsend.c
deleted file mode 100644
index 4fe714d70f..0000000000
--- a/apps/plugins/pdbox/PDa/src/u_pdsend.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/* Copyright (c) 2000 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in the Pd distribution. */
-
-/* the "pdsend" command. This is a standalone program that forwards messages
-from its standard input to Pd via the netsend/netreceive ("FUDI") protocol. */
-
-#include <sys/types.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#ifdef UNIX
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#define SOCKET_ERROR -1
-#else
-#include <winsock.h>
-#endif
-
-void sockerror(char *s);
-void x_closesocket(int fd);
-#define BUFSIZE 4096
-
-int main(int argc, char **argv)
-{
- int sockfd, portno, protocol;
- struct sockaddr_in server;
- struct hostent *hp;
- char *hostname;
- int nretry = 10;
-#ifdef MSW
- short version = MAKEWORD(2, 0);
- WSADATA nobby;
-#endif
- if (argc < 2 || sscanf(argv[1], "%d", &portno) < 1 || portno <= 0)
- goto usage;
- if (argc >= 3)
- hostname = argv[2];
- else hostname = "127.0.0.1";
- if (argc >= 4)
- {
- if (!strcmp(argv[3], "tcp"))
- protocol = SOCK_STREAM;
- else if (!strcmp(argv[3], "udp"))
- protocol = SOCK_DGRAM;
- else goto usage;
- }
- else protocol = SOCK_STREAM;
-#ifdef MSW
- if (WSAStartup(version, &nobby)) sockerror("WSAstartup");
-#endif
-
- sockfd = socket(AF_INET, protocol, 0);
- if (sockfd < 0)
- {
- sockerror("socket()");
- exit(1);
- }
- /* connect socket using hostname provided in command line */
- server.sin_family = AF_INET;
- hp = gethostbyname(hostname);
- if (hp == 0)
- {
- fprintf(stderr, "%s: unknown host\n", hostname);
- x_closesocket(sockfd);
- exit(1);
- }
- memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
-
- /* assign client port number */
- server.sin_port = htons((unsigned short)portno);
-
-#if 0 /* try this again for 4.0; this crashed my RH 6.2 machine!) */
-
- /* try to connect. */
- for (nretry = 0; nretry < (protocol == SOCK_STREAM ? 10 : 1); nretry++)
-
- {
- if (nretry > 0)
- {
- sleep (nretry < 5 ? 1 : 5);
- fprintf(stderr, "retrying...");
- }
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
- goto connected;
- sockerror("connect");
- }
- x_closesocket(sockfd);
- exit(1);
-connected: ;
-#else
- /* try to connect. */
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
- {
- sockerror("connect");
- x_closesocket(sockfd);
- exit(1);
- }
-#endif
- /* now loop reading stdin and sending it to socket */
- while (1)
- {
- char buf[BUFSIZE], *bp, nsent, nsend;
- if (!fgets(buf, BUFSIZE, stdin))
- break;
- nsend = strlen(buf);
- for (bp = buf, nsent = 0; nsent < nsend;)
- {
- int res = send(sockfd, buf, nsend-nsent, 0);
- if (res < 0)
- {
- sockerror("send");
- goto done;
- }
- nsent += res;
- bp += res;
- }
- }
-done:
- if (ferror(stdin))
- perror("stdin");
- exit (0);
-usage:
- fprintf(stderr, "usage: pdsend <portnumber> [host] [udp|tcp]\n");
- fprintf(stderr, "(default is localhost and tcp)\n");
- exit(1);
-}
-
-void sockerror(char *s)
-{
-#ifdef MSW
- int err = WSAGetLastError();
- if (err == 10054) return;
- else if (err == 10044)
- {
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
- }
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
- fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
-}
-
-void x_closesocket(int fd)
-{
-#ifdef UNIX
- close(fd);
-#endif
-#ifdef MSW
- closesocket(fd);
-#endif
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/x_gui.c b/apps/plugins/pdbox/PDa/src/x_gui.c
deleted file mode 100644
index c54fef948d..0000000000
--- a/apps/plugins/pdbox/PDa/src/x_gui.c
+++ /dev/null
@@ -1,378 +0,0 @@
-/* Copyright (c) 1997-2000 Miller Puckette.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* dialogs. LATER, deal with the situation where the object goes
-away before the panel does... */
-
-#include "m_pd.h"
-#include <stdio.h>
-#include <string.h>
-#ifdef UNIX
-#include <unistd.h>
-#endif
-
-/* --------------------- graphics responder ---------------- */
-
-/* make one of these if you want to put up a dialog window but want to be
-protected from getting deleted and then having the dialog call you back. In
-this design the calling object doesn't have to keep the address of the dialog
-window around; instead we keep a list of all open dialogs. Any object that
-might have dialogs, when it is deleted, simply checks down the dialog window
-list and breaks off any dialogs that might later have sent messages to it.
-Only when the dialog window itself closes do we delete the gfxstub object. */
-
-static t_class *gfxstub_class;
-
-typedef struct _gfxstub
-{
- t_pd x_pd;
- t_pd *x_owner;
- void *x_key;
- t_symbol *x_sym;
- struct _gfxstub *x_next;
-} t_gfxstub;
-
-static t_gfxstub *gfxstub_list;
-
- /* create a new one. the "key" is an address by which the owner
- will identify it later; if the owner only wants one dialog, this
- could just be a pointer to the owner itself. The string "cmd"
- is a TK command to create the dialog, with "%s" embedded in
- it so we can provide a name by which the GUI can send us back
- messages; e.g., "pdtk_canvas_dofont %s 10". */
-
-void gfxstub_new(t_pd *owner, void *key, const char *cmd)
-{
- char buf[MAXPDSTRING];
- char namebuf[80];
- t_gfxstub *x;
- t_symbol *s;
- /* if any exists with matching key, no need to make a
- new one; just tell tk to send it front. */
- for (x = gfxstub_list; x; x = x->x_next)
- {
- if (x->x_key == key)
- {
- sys_vgui("raise .gfxstub%x\n", x);
- sys_vgui("focus .gfxstub%x\n", x);
- return;
- }
- }
- if (strlen(cmd) + 84 > MAXPDSTRING)
- return;
- x = (t_gfxstub *)pd_new(gfxstub_class);
- sprintf(namebuf, ".gfxstub%x", (t_int)x);
-
- s = gensym(namebuf);
- pd_bind(&x->x_pd, s);
- x->x_owner = owner;
- x->x_sym = s;
- x->x_key = key;
- x->x_next = gfxstub_list;
- gfxstub_list = x;
- sprintf(buf, cmd, s->s_name);
- sys_gui(buf);
-}
-
-static void gfxstub_offlist(t_gfxstub *x)
-{
- t_gfxstub *y1, *y2;
- if (gfxstub_list == x)
- gfxstub_list = x->x_next;
- else for (y1 = gfxstub_list; y2 = y1->x_next; y1 = y2)
- if (y2 == x)
- {
- y1->x_next = y2->x_next;
- break;
- }
-}
-
- /* if the owner disappears, we still may have to stay around until our
- dialog window signs off. Anyway we can now tell the GUI to destroy the
- window. */
-void gfxstub_deleteforkey(void *key)
-{
- t_gfxstub *y;
- int didit = 1;
- while (didit)
- {
- didit = 0;
- for (y = gfxstub_list; y; y = y->x_next)
- {
- if (y->x_key == key)
- {
- sys_vgui("destroy .gfxstub%x\n", y);
- y->x_owner = 0;
- gfxstub_offlist(y);
- didit = 1;
- break;
- }
- }
- }
-}
-
-/* --------- pd messages for gfxstub (these come from the GUI) ---------- */
-
- /* "cancel" to request that we close the dialog window. */
-static void gfxstub_cancel(t_gfxstub *x)
-{
- gfxstub_deleteforkey(x->x_key);
-}
-
- /* "signoff" comes from the GUI to say the dialog window closed. */
-static void gfxstub_signoff(t_gfxstub *x)
-{
- gfxstub_offlist(x);
- pd_free(&x->x_pd);
-}
-
-static t_binbuf *gfxstub_binbuf;
-
- /* a series of "data" messages rebuilds a scalar */
-static void gfxstub_data(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
-{
- if (!gfxstub_binbuf)
- gfxstub_binbuf = binbuf_new();
- binbuf_add(gfxstub_binbuf, argc, argv);
- binbuf_addsemi(gfxstub_binbuf);
-}
- /* the "end" message terminates rebuilding the scalar */
-static void gfxstub_end(t_gfxstub *x)
-{
- canvas_dataproperties((t_canvas *)x->x_owner,
- (t_scalar *)x->x_key, gfxstub_binbuf);
- binbuf_free(gfxstub_binbuf);
- gfxstub_binbuf = 0;
-}
-
- /* anything else is a message from the dialog window to the owner;
- just forward it. */
-static void gfxstub_anything(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
-{
- if (x->x_owner)
- pd_typedmess(x->x_owner, s, argc, argv);
-}
-
-static void gfxstub_free(t_gfxstub *x)
-{
- pd_unbind(&x->x_pd, x->x_sym);
-}
-
-static void gfxstub_setup(void)
-{
- gfxstub_class = class_new(gensym("gfxstub"), (t_newmethod)gfxstub_new,
- (t_method)gfxstub_free,
- sizeof(t_gfxstub), CLASS_PD, 0);
- class_addanything(gfxstub_class, gfxstub_anything);
- class_addmethod(gfxstub_class, (t_method)gfxstub_signoff,
- gensym("signoff"), 0);
- class_addmethod(gfxstub_class, (t_method)gfxstub_data,
- gensym("data"), A_GIMME, 0);
- class_addmethod(gfxstub_class, (t_method)gfxstub_end,
- gensym("end"), 0);
- class_addmethod(gfxstub_class, (t_method)gfxstub_cancel,
- gensym("cancel"), 0);
-}
-
-/* -------------------------- openpanel ------------------------------ */
-
-static t_class *openpanel_class;
-
-typedef struct _openpanel
-{
- t_object x_obj;
- t_symbol *x_s;
-} t_openpanel;
-
-static void *openpanel_new(void)
-{
- char buf[50];
- t_openpanel *x = (t_openpanel *)pd_new(openpanel_class);
- sprintf(buf, "d%x", (t_int)x);
- x->x_s = gensym(buf);
- pd_bind(&x->x_obj.ob_pd, x->x_s);
- outlet_new(&x->x_obj, &s_symbol);
- return (x);
-}
-
-static void openpanel_bang(t_openpanel *x)
-{
- sys_vgui("pdtk_openpanel %s\n", x->x_s->s_name);
-}
-
-static void openpanel_symbol(t_openpanel *x, t_symbol *s)
-{
- outlet_symbol(x->x_obj.ob_outlet, s);
-}
-
-static void openpanel_free(t_openpanel *x)
-{
- pd_unbind(&x->x_obj.ob_pd, x->x_s);
-}
-
-static void openpanel_setup(void)
-{
- openpanel_class = class_new(gensym("openpanel"),
- (t_newmethod)openpanel_new, (t_method)openpanel_free,
- sizeof(t_openpanel), 0, A_DEFFLOAT, 0);
- class_addbang(openpanel_class, openpanel_bang);
- class_addsymbol(openpanel_class, openpanel_symbol);
-}
-
-/* -------------------------- savepanel ------------------------------ */
-
-static t_class *savepanel_class;
-
-typedef struct _savepanel
-{
- t_object x_obj;
- t_symbol *x_s;
-} t_savepanel;
-
-static void *savepanel_new(void)
-{
- char buf[50];
- t_savepanel *x = (t_savepanel *)pd_new(savepanel_class);
- sprintf(buf, "d%x", (t_int)x);
- x->x_s = gensym(buf);
- pd_bind(&x->x_obj.ob_pd, x->x_s);
- outlet_new(&x->x_obj, &s_symbol);
- return (x);
-}
-
-static void savepanel_bang(t_savepanel *x)
-{
- sys_vgui("pdtk_savepanel %s\n", x->x_s->s_name);
-}
-
-static void savepanel_symbol(t_savepanel *x, t_symbol *s)
-{
- outlet_symbol(x->x_obj.ob_outlet, s);
-}
-
-static void savepanel_free(t_savepanel *x)
-{
- pd_unbind(&x->x_obj.ob_pd, x->x_s);
-}
-
-static void savepanel_setup(void)
-{
- savepanel_class = class_new(gensym("savepanel"),
- (t_newmethod)savepanel_new, (t_method)savepanel_free,
- sizeof(t_savepanel), 0, A_DEFFLOAT, 0);
- class_addbang(savepanel_class, savepanel_bang);
- class_addsymbol(savepanel_class, savepanel_symbol);
-}
-
-/* ---------------------- key and its relatives ------------------ */
-
-static t_symbol *key_sym, *keyup_sym, *keyname_sym;
-static t_class *key_class, *keyup_class, *keyname_class;
-
-typedef struct _key
-{
- t_object x_obj;
-} t_key;
-
-static void *key_new( void)
-{
- t_key *x = (t_key *)pd_new(key_class);
- outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, key_sym);
- return (x);
-}
-
-static void key_float(t_key *x, t_floatarg f)
-{
- outlet_float(x->x_obj.ob_outlet, f);
-}
-
-static void key_free(t_key *x)
-{
- pd_unbind(&x->x_obj.ob_pd, key_sym);
-}
-
-typedef struct _keyup
-{
- t_object x_obj;
-} t_keyup;
-
-static void *keyup_new( void)
-{
- t_keyup *x = (t_keyup *)pd_new(keyup_class);
- outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, keyup_sym);
- return (x);
-}
-
-static void keyup_float(t_keyup *x, t_floatarg f)
-{
- outlet_float(x->x_obj.ob_outlet, f);
-}
-
-static void keyup_free(t_keyup *x)
-{
- pd_unbind(&x->x_obj.ob_pd, keyup_sym);
-}
-
-typedef struct _keyname
-{
- t_object x_obj;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_keyname;
-
-static void *keyname_new( void)
-{
- t_keyname *x = (t_keyname *)pd_new(keyname_class);
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_symbol);
- pd_bind(&x->x_obj.ob_pd, keyname_sym);
- return (x);
-}
-
-static void keyname_list(t_keyname *x, t_symbol *s, int ac, t_atom *av)
-{
- outlet_symbol(x->x_outlet2, atom_getsymbolarg(1, ac, av));
- outlet_float(x->x_outlet1, atom_getfloatarg(0, ac, av));
-}
-
-static void keyname_free(t_keyname *x)
-{
- pd_unbind(&x->x_obj.ob_pd, keyname_sym);
-}
-
-static void key_setup(void)
-{
- key_class = class_new(gensym("key"),
- (t_newmethod)key_new, (t_method)key_free,
- sizeof(t_key), CLASS_NOINLET, 0);
- class_addfloat(key_class, key_float);
- key_sym = gensym("#key");
-
- keyup_class = class_new(gensym("keyup"),
- (t_newmethod)keyup_new, (t_method)keyup_free,
- sizeof(t_keyup), CLASS_NOINLET, 0);
- class_addfloat(keyup_class, keyup_float);
- keyup_sym = gensym("#keyup");
- class_sethelpsymbol(keyup_class, gensym("key"));
-
- keyname_class = class_new(gensym("keyname"),
- (t_newmethod)keyname_new, (t_method)keyname_free,
- sizeof(t_keyname), CLASS_NOINLET, 0);
- class_addlist(keyname_class, keyname_list);
- keyname_sym = gensym("#keyname");
- class_sethelpsymbol(keyname_class, gensym("key"));
-}
-
-/* -------------------------- setup routine ------------------------------ */
-
-void x_gui_setup(void)
-{
- gfxstub_setup();
- openpanel_setup();
- savepanel_setup();
- key_setup();
-}
-
diff --git a/apps/plugins/pdbox/PDa/src/x_midi.c b/apps/plugins/pdbox/PDa/src/x_midi.c
deleted file mode 100644
index e9f3601057..0000000000
--- a/apps/plugins/pdbox/PDa/src/x_midi.c
+++ /dev/null
@@ -1,1314 +0,0 @@
-/* Copyright (c) 1997-2001 Miller Puckette and others.
-* For information on usage and redistribution, and for a DISCLAIMER OF ALL
-* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* MIDI. */
-
-#include "m_pd.h"
-void outmidi_noteon(int portno, int channel, int pitch, int velo);
-void outmidi_controlchange(int portno, int channel, int ctlno, int value);
-void outmidi_programchange(int portno, int channel, int value);
-void outmidi_pitchbend(int portno, int channel, int value);
-void outmidi_aftertouch(int portno, int channel, int value);
-void outmidi_polyaftertouch(int portno, int channel, int pitch, int value);
-void outmidi_mclk(int portno);
-
-/* ----------------------- midiin and sysexin ------------------------- */
-
-static t_symbol *midiin_sym, *sysexin_sym;
-
-static t_class *midiin_class, *sysexin_class;
-
-typedef struct _midiin
-{
- t_object x_obj;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_midiin;
-
-static void *midiin_new( void)
-{
- t_midiin *x = (t_midiin *)pd_new(midiin_class);
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, midiin_sym);
-#ifndef __linux__
- pd_error(x, "midiin: works under Linux only");
-#endif
- return (x);
-}
-
-static void midiin_list(t_midiin *x, t_symbol *s, int ac, t_atom *av)
-{
- outlet_float(x->x_outlet2, atom_getfloatarg(1, ac, av) + 1);
- outlet_float(x->x_outlet1, atom_getfloatarg(0, ac, av));
-}
-
-static void midiin_free(t_midiin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, midiin_sym);
-}
-
-static void *sysexin_new( void)
-{
- t_midiin *x = (t_midiin *)pd_new(sysexin_class);
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, sysexin_sym);
-#ifndef __linux__
- pd_error(x, "sysexin: works under Linux only");
-#endif
- return (x);
-}
-
-static void sysexin_free(t_midiin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, sysexin_sym);
-}
-
-static void midiin_setup(void)
-{
- midiin_class = class_new(gensym("midiin"), (t_newmethod)midiin_new,
- (t_method)midiin_free, sizeof(t_midiin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(midiin_class, midiin_list);
- class_sethelpsymbol(midiin_class, gensym("midi"));
- midiin_sym = gensym("#midiin");
-
- sysexin_class = class_new(gensym("sysexin"), (t_newmethod)sysexin_new,
- (t_method)sysexin_free, sizeof(t_midiin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(sysexin_class, midiin_list);
- class_sethelpsymbol(sysexin_class, gensym("midi"));
- sysexin_sym = gensym("#sysexin");
-}
-
-void inmidi_byte(int portno, int byte)
-{
- t_atom at[2];
- if (midiin_sym->s_thing)
- {
- SETFLOAT(at, byte);
- SETFLOAT(at+1, portno + 1);
- pd_list(midiin_sym->s_thing, 0, 2, at);
- }
-}
-
-void inmidi_sysex(int portno, int byte)
-{
- t_atom at[2];
- if (sysexin_sym->s_thing)
- {
- SETFLOAT(at, byte);
- SETFLOAT(at+1, portno + 1);
- pd_list(sysexin_sym->s_thing, 0, 2, at);
- }
-}
-
-/* ----------------------- notein ------------------------- */
-
-static t_symbol *notein_sym;
-
-static t_class *notein_class;
-
-typedef struct _notein
-{
- t_object x_obj;
- t_float x_channel;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
- t_outlet *x_outlet3;
-} t_notein;
-
-static void *notein_new(t_floatarg f)
-{
- t_notein *x = (t_notein *)pd_new(notein_class);
- x->x_channel = f;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- if (f == 0) x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, notein_sym);
- return (x);
-}
-
-static void notein_list(t_notein *x, t_symbol *s, int argc, t_atom *argv)
-{
- float pitch = atom_getfloatarg(0, argc, argv);
- float velo = atom_getfloatarg(1, argc, argv);
- float channel = atom_getfloatarg(2, argc, argv);
- if (x->x_channel != 0)
- {
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet2, velo);
- outlet_float(x->x_outlet1, pitch);
- }
- else
- {
- outlet_float(x->x_outlet3, channel);
- outlet_float(x->x_outlet2, velo);
- outlet_float(x->x_outlet1, pitch);
- }
-}
-
-static void notein_free(t_notein *x)
-{
- pd_unbind(&x->x_obj.ob_pd, notein_sym);
-}
-
-static void notein_setup(void)
-{
- notein_class = class_new(gensym("notein"), (t_newmethod)notein_new,
- (t_method)notein_free, sizeof(t_notein), CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(notein_class, notein_list);
- class_sethelpsymbol(notein_class, gensym("midi"));
- notein_sym = gensym("#notein");
-}
-
-void inmidi_noteon(int portno, int channel, int pitch, int velo)
-{
- if (notein_sym->s_thing)
- {
- t_atom at[3];
- SETFLOAT(at, pitch);
- SETFLOAT(at+1, velo);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(notein_sym->s_thing, &s_list, 3, at);
- }
-}
-
-/* ----------------------- ctlin ------------------------- */
-
-static t_symbol *ctlin_sym;
-
-static t_class *ctlin_class;
-
-typedef struct _ctlin
-{
- t_object x_obj;
- t_float x_channel;
- t_float x_ctlno;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
- t_outlet *x_outlet3;
-} t_ctlin;
-
-static void *ctlin_new(t_symbol *s, int argc, t_atom *argv)
-{
- int ctlno, channel;
- t_ctlin *x = (t_ctlin *)pd_new(ctlin_class);
- if (!argc) ctlno = -1;
- else ctlno = atom_getfloatarg(0, argc, argv);
- channel = atom_getfloatarg(1, argc, argv);
- x->x_channel = channel;
- x->x_ctlno = ctlno;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- if (!channel)
- {
- if (x->x_ctlno < 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
- }
- pd_bind(&x->x_obj.ob_pd, ctlin_sym);
- return (x);
-}
-
-static void ctlin_list(t_ctlin *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_float ctlnumber = atom_getfloatarg(0, argc, argv);
- t_float value = atom_getfloatarg(1, argc, argv);
- t_float channel = atom_getfloatarg(2, argc, argv);
- if (x->x_ctlno >= 0 && x->x_ctlno != ctlnumber) return;
- if (x->x_channel > 0 && x->x_channel != channel) return;
- if (x->x_channel == 0) outlet_float(x->x_outlet3, channel);
- if (x->x_ctlno < 0) outlet_float(x->x_outlet2, ctlnumber);
- outlet_float(x->x_outlet1, value);
-}
-
-static void ctlin_free(t_ctlin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, ctlin_sym);
-}
-
-static void ctlin_setup(void)
-{
- ctlin_class = class_new(gensym("ctlin"), (t_newmethod)ctlin_new,
- (t_method)ctlin_free, sizeof(t_ctlin),
- CLASS_NOINLET, A_GIMME, 0);
- class_addlist(ctlin_class, ctlin_list);
- class_sethelpsymbol(ctlin_class, gensym("midi"));
- ctlin_sym = gensym("#ctlin");
-}
-
-void inmidi_controlchange(int portno, int channel, int ctlnumber, int value)
-{
- if (ctlin_sym->s_thing)
- {
- t_atom at[3];
- SETFLOAT(at, ctlnumber);
- SETFLOAT(at+1, value);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(ctlin_sym->s_thing, &s_list, 3, at);
- }
-}
-
-/* ----------------------- pgmin ------------------------- */
-
-static t_symbol *pgmin_sym;
-
-static t_class *pgmin_class;
-
-typedef struct _pgmin
-{
- t_object x_obj;
- t_float x_channel;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_pgmin;
-
-static void *pgmin_new(t_floatarg f)
-{
- t_pgmin *x = (t_pgmin *)pd_new(pgmin_class);
- x->x_channel = f;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- if (f == 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, pgmin_sym);
- return (x);
-}
-
-static void pgmin_list(t_pgmin *x, t_symbol *s, int argc, t_atom *argv)
-{
- float value = atom_getfloatarg(0, argc, argv);
- float channel = atom_getfloatarg(1, argc, argv);
- if (x->x_channel != 0)
- {
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
- }
- else
- {
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
- }
-}
-
-static void pgmin_free(t_pgmin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, pgmin_sym);
-}
-
-static void pgmin_setup(void)
-{
- pgmin_class = class_new(gensym("pgmin"), (t_newmethod)pgmin_new,
- (t_method)pgmin_free, sizeof(t_pgmin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(pgmin_class, pgmin_list);
- class_sethelpsymbol(pgmin_class, gensym("midi"));
- pgmin_sym = gensym("#pgmin");
-}
-
-void inmidi_programchange(int portno, int channel, int value)
-{
- if (pgmin_sym->s_thing)
- {
- t_atom at[2];
- SETFLOAT(at, value + 1);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(pgmin_sym->s_thing, &s_list, 2, at);
- }
-}
-
-/* ----------------------- bendin ------------------------- */
-
-static t_symbol *bendin_sym;
-
-static t_class *bendin_class;
-
-typedef struct _bendin
-{
- t_object x_obj;
- t_float x_channel;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_bendin;
-
-static void *bendin_new(t_floatarg f)
-{
- t_bendin *x = (t_bendin *)pd_new(bendin_class);
- x->x_channel = f;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- if (f == 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, bendin_sym);
- return (x);
-}
-
-static void bendin_list(t_bendin *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_float value = atom_getfloatarg(0, argc, argv);
- t_float channel = atom_getfloatarg(1, argc, argv);
- if (x->x_channel != 0)
- {
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
- }
- else
- {
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
- }
-}
-
-static void bendin_free(t_bendin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, bendin_sym);
-}
-
-static void bendin_setup(void)
-{
- bendin_class = class_new(gensym("bendin"), (t_newmethod)bendin_new,
- (t_method)bendin_free, sizeof(t_bendin), CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(bendin_class, bendin_list);
- class_sethelpsymbol(bendin_class, gensym("midi"));
- bendin_sym = gensym("#bendin");
-}
-
-void inmidi_pitchbend(int portno, int channel, int value)
-{
- if (bendin_sym->s_thing)
- {
- t_atom at[2];
- SETFLOAT(at, value);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(bendin_sym->s_thing, &s_list, 2, at);
- }
-}
-
-/* ----------------------- touchin ------------------------- */
-
-static t_symbol *touchin_sym;
-
-static t_class *touchin_class;
-
-typedef struct _touchin
-{
- t_object x_obj;
- t_float x_channel;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_touchin;
-
-static void *touchin_new(t_floatarg f)
-{
- t_touchin *x = (t_touchin *)pd_new(touchin_class);
- x->x_channel = f;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- if (f == 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, touchin_sym);
- return (x);
-}
-
-static void touchin_list(t_touchin *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_float value = atom_getfloatarg(0, argc, argv);
- t_float channel = atom_getfloatarg(1, argc, argv);
- if (x->x_channel)
- {
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
- }
- else
- {
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
- }
-}
-
-static void touchin_free(t_touchin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, touchin_sym);
-}
-
-static void touchin_setup(void)
-{
- touchin_class = class_new(gensym("touchin"), (t_newmethod)touchin_new,
- (t_method)touchin_free, sizeof(t_touchin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(touchin_class, touchin_list);
- class_sethelpsymbol(touchin_class, gensym("midi"));
- touchin_sym = gensym("#touchin");
-}
-
-void inmidi_aftertouch(int portno, int channel, int value)
-{
- if (touchin_sym->s_thing)
- {
- t_atom at[2];
- SETFLOAT(at, value);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(touchin_sym->s_thing, &s_list, 2, at);
- }
-}
-
-/* ----------------------- polytouchin ------------------------- */
-
-static t_symbol *polytouchin_sym;
-
-static t_class *polytouchin_class;
-
-typedef struct _polytouchin
-{
- t_object x_obj;
- t_float x_channel;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
- t_outlet *x_outlet3;
-} t_polytouchin;
-
-static void *polytouchin_new(t_floatarg f)
-{
- t_polytouchin *x = (t_polytouchin *)pd_new(polytouchin_class);
- x->x_channel = f;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- if (f == 0) x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, polytouchin_sym);
- return (x);
-}
-
-static void polytouchin_list(t_polytouchin *x, t_symbol *s, int argc,
- t_atom *argv)
-{
- t_float pitch = atom_getfloatarg(0, argc, argv);
- t_float value = atom_getfloatarg(1, argc, argv);
- t_float channel = atom_getfloatarg(2, argc, argv);
- if (x->x_channel != 0)
- {
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet2, pitch);
- outlet_float(x->x_outlet1, value);
- }
- else
- {
- outlet_float(x->x_outlet3, channel);
- outlet_float(x->x_outlet2, pitch);
- outlet_float(x->x_outlet1, value);
- }
-}
-
-static void polytouchin_free(t_polytouchin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, polytouchin_sym);
-}
-
-static void polytouchin_setup(void)
-{
- polytouchin_class = class_new(gensym("polytouchin"),
- (t_newmethod)polytouchin_new, (t_method)polytouchin_free,
- sizeof(t_polytouchin), CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(polytouchin_class, polytouchin_list);
- class_sethelpsymbol(polytouchin_class, gensym("midi"));
- polytouchin_sym = gensym("#polytouchin");
-}
-
-void inmidi_polyaftertouch(int portno, int channel, int pitch, int value)
-{
- if (polytouchin_sym->s_thing)
- {
- t_atom at[3];
- SETFLOAT(at, pitch);
- SETFLOAT(at+1, value);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(polytouchin_sym->s_thing, &s_list, 3, at);
- }
-}
-
-/*----------------------- midiclkin--(midi F8 message )---------------------*/
-static t_symbol *midiclkin_sym;
-
-static t_class *midiclkin_class;
-
-
-typedef struct _midiclkin
-{
- t_object x_obj;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_midiclkin;
-
-static void *midiclkin_new(t_floatarg f)
-{
- t_midiclkin *x = (t_midiclkin *)pd_new(midiclkin_class);
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, midiclkin_sym);
- return (x);
-}
-
-static void midiclkin_list(t_midiclkin *x, t_symbol *s, int argc, t_atom *argv)
-{
- float value = atom_getfloatarg(0, argc, argv);
- float count = atom_getfloatarg(1, argc, argv);
- outlet_float(x->x_outlet2, count);
- outlet_float(x->x_outlet1, value);
-}
-
-static void midiclkin_free(t_midiclkin *x)
-{
- pd_unbind(&x->x_obj.ob_pd, midiclkin_sym);
-}
-
-static void midiclkin_setup(void)
-{
- midiclkin_class = class_new(gensym("midiclkin"),
- (t_newmethod)midiclkin_new, (t_method)midiclkin_free,
- sizeof(t_midiclkin), CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(midiclkin_class, midiclkin_list);
- class_sethelpsymbol(midiclkin_class, gensym("midi"));
- midiclkin_sym = gensym("#midiclkin");
-}
-
-void inmidi_clk(double timing)
-{
-
- static float prev = 0;
- static float count = 0;
- float cur,diff;
-
- if (midiclkin_sym->s_thing)
- {
- t_atom at[2];
- diff =timing - prev;
- count++;
-
- if (count == 3)
- { /* 24 count per quoter note */
- SETFLOAT(at, 1 );
- count = 0;
- }
- else SETFLOAT(at, 0);
-
- SETFLOAT(at+1, diff);
- pd_list(midiclkin_sym->s_thing, &s_list, 2, at);
- prev = timing;
- }
-}
-
-/*----------midirealtimein (midi FA,FB,FC,FF message )-----------------*/
-
-static t_symbol *midirealtimein_sym;
-
-static t_class *midirealtimein_class;
-
-typedef struct _midirealtimein
-{
- t_object x_obj;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
-} t_midirealtimein;
-
-static void *midirealtimein_new( void)
-{
- t_midirealtimein *x = (t_midirealtimein *)pd_new(midirealtimein_class);
- x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- pd_bind(&x->x_obj.ob_pd, midirealtimein_sym);
-#ifndef MSW
- pd_error(x, "midirealtimein: works under MSW only");
-#endif
- return (x);
-}
-
-static void midirealtimein_list(t_midirealtimein *x, t_symbol *s,
- int argc, t_atom *argv)
-{
- float portno = atom_getfloatarg(0, argc, argv);
- float byte = atom_getfloatarg(1, argc, argv);
-
- outlet_float(x->x_outlet2, portno);
- outlet_float(x->x_outlet1, byte);
-}
-
-static void midirealtimein_free(t_midirealtimein *x)
-{
- pd_unbind(&x->x_obj.ob_pd, midirealtimein_sym);
-}
-
-static void midirealtimein_setup(void)
-{
- midirealtimein_class = class_new(gensym("midirealtimein"),
- (t_newmethod)midirealtimein_new, (t_method)midirealtimein_free,
- sizeof(t_midirealtimein), CLASS_NOINLET, A_DEFFLOAT, 0);
- class_addlist(midirealtimein_class, midirealtimein_list);
- class_sethelpsymbol(midirealtimein_class, gensym("midi"));
- midirealtimein_sym = gensym("#midirealtimein");
-}
-
-void inmidi_realtimein(int portno, int SysMsg)
-{
- if (midirealtimein_sym->s_thing)
- {
- t_atom at[2];
- SETFLOAT(at, portno);
- SETFLOAT(at+1, SysMsg);
- pd_list(midirealtimein_sym->s_thing, &s_list, 1, at);
- }
-}
-
-/* -------------------------- midiout -------------------------- */
-
-static t_class *midiout_class;
-
-void sys_putmidibyte(int portno, int byte);
-
-typedef struct _midiout
-{
- t_object x_obj;
- t_float x_portno;
-} t_midiout;
-
-static void *midiout_new(t_floatarg portno)
-{
- t_midiout *x = (t_midiout *)pd_new(midiout_class);
- if (portno <= 0) portno = 1;
- x->x_portno = portno;
- floatinlet_new(&x->x_obj, &x->x_portno);
-#ifdef __irix__
- post("midiout: unimplemented in IRIX");
-#endif
- return (x);
-}
-
-static void midiout_float(t_midiout *x, t_floatarg f)
-{
- sys_putmidibyte(x->x_portno - 1, f);
-}
-
-static void midiout_setup(void)
-{
- midiout_class = class_new(gensym("midiout"), (t_newmethod)midiout_new, 0,
- sizeof(t_midiout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addfloat(midiout_class, midiout_float);
- class_sethelpsymbol(midiout_class, gensym("midi"));
-}
-
-/* -------------------------- noteout -------------------------- */
-
-static t_class *noteout_class;
-
-typedef struct _noteout
-{
- t_object x_obj;
- t_float x_velo;
- t_float x_channel;
-} t_noteout;
-
-static void *noteout_new(t_floatarg channel)
-{
- t_noteout *x = (t_noteout *)pd_new(noteout_class);
- x->x_velo = 0;
- if (channel < 1) channel = 1;
- x->x_channel = channel;
- floatinlet_new(&x->x_obj, &x->x_velo);
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void noteout_float(t_noteout *x, t_float f)
-{
- int binchan = x->x_channel - 1;
- if (binchan < 0)
- binchan = 0;
- outmidi_noteon((binchan >> 4),
- (binchan & 15), (int)f, (int)x->x_velo);
-}
-
-static void noteout_setup(void)
-{
- noteout_class = class_new(gensym("noteout"), (t_newmethod)noteout_new, 0,
- sizeof(t_noteout), 0, A_DEFFLOAT, 0);
- class_addfloat(noteout_class, noteout_float);
- class_sethelpsymbol(noteout_class, gensym("midi"));
-}
-
-
-/* -------------------------- ctlout -------------------------- */
-
-static t_class *ctlout_class;
-
-typedef struct _ctlout
-{
- t_object x_obj;
- t_float x_ctl;
- t_float x_channel;
-} t_ctlout;
-
-static void *ctlout_new(t_floatarg ctl, t_floatarg channel)
-{
- t_ctlout *x = (t_ctlout *)pd_new(ctlout_class);
- x->x_ctl = ctl;
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- floatinlet_new(&x->x_obj, &x->x_ctl);
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void ctlout_float(t_ctlout *x, t_float f)
-{
- int binchan = x->x_channel - 1;
- if (binchan < 0)
- binchan = 0;
- outmidi_controlchange((binchan >> 4),
- (binchan & 15), (int)(x->x_ctl), (int)f);
-}
-
-static void ctlout_setup(void)
-{
- ctlout_class = class_new(gensym("ctlout"), (t_newmethod)ctlout_new, 0,
- sizeof(t_ctlout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addfloat(ctlout_class, ctlout_float);
- class_sethelpsymbol(ctlout_class, gensym("midi"));
-}
-
-
-/* -------------------------- pgmout -------------------------- */
-
-static t_class *pgmout_class;
-
-typedef struct _pgmout
-{
- t_object x_obj;
- t_float x_channel;
-} t_pgmout;
-
-static void *pgmout_new(t_floatarg channel)
-{
- t_pgmout *x = (t_pgmout *)pd_new(pgmout_class);
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void pgmout_float(t_pgmout *x, t_floatarg f)
-{
- int binchan = x->x_channel - 1;
- int n = f - 1;
- if (binchan < 0)
- binchan = 0;
- if (n < 0) n = 0;
- else if (n > 127) n = 127;
- outmidi_programchange((binchan >> 4),
- (binchan & 15), n);
-}
-
-static void pgmout_setup(void)
-{
- pgmout_class = class_new(gensym("pgmout"), (t_newmethod)pgmout_new, 0,
- sizeof(t_pgmout), 0, A_DEFFLOAT, 0);
- class_addfloat(pgmout_class, pgmout_float);
- class_sethelpsymbol(pgmout_class, gensym("midi"));
-}
-
-
-/* -------------------------- bendout -------------------------- */
-
-static t_class *bendout_class;
-
-typedef struct _bendout
-{
- t_object x_obj;
- t_float x_channel;
-} t_bendout;
-
-static void *bendout_new(t_floatarg channel)
-{
- t_bendout *x = (t_bendout *)pd_new(bendout_class);
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void bendout_float(t_bendout *x, t_float f)
-{
- int binchan = x->x_channel - 1;
- int n = (int)f + 8192;
- if (binchan < 0)
- binchan = 0;
- outmidi_pitchbend((binchan >> 4), (binchan & 15), n);
-}
-
-static void bendout_setup(void)
-{
- bendout_class = class_new(gensym("bendout"), (t_newmethod)bendout_new, 0,
- sizeof(t_bendout), 0, A_DEFFLOAT, 0);
- class_addfloat(bendout_class, bendout_float);
- class_sethelpsymbol(bendout_class, gensym("midi"));
-}
-
-/* -------------------------- touch -------------------------- */
-
-static t_class *touchout_class;
-
-typedef struct _touchout
-{
- t_object x_obj;
- t_float x_channel;
-} t_touchout;
-
-static void *touchout_new(t_floatarg channel)
-{
- t_touchout *x = (t_touchout *)pd_new(touchout_class);
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void touchout_float(t_touchout *x, t_float f)
-{
- int binchan = x->x_channel - 1;
- if (binchan < 0)
- binchan = 0;
- outmidi_aftertouch((binchan >> 4), (binchan & 15), (int)f);
-}
-
-static void touchout_setup(void)
-{
- touchout_class = class_new(gensym("touchout"), (t_newmethod)touchout_new, 0,
- sizeof(t_touchout), 0, A_DEFFLOAT, 0);
- class_addfloat(touchout_class, touchout_float);
- class_sethelpsymbol(touchout_class, gensym("midi"));
-}
-
-/* -------------------------- polytouch -------------------------- */
-
-static t_class *polytouchout_class;
-
-typedef struct _polytouchout
-{
- t_object x_obj;
- t_float x_channel;
- t_float x_pitch;
-} t_polytouchout;
-
-static void *polytouchout_new(t_floatarg channel)
-{
- t_polytouchout *x = (t_polytouchout *)pd_new(polytouchout_class);
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- x->x_pitch = 0;
- floatinlet_new(&x->x_obj, &x->x_pitch);
- floatinlet_new(&x->x_obj, &x->x_channel);
- return (x);
-}
-
-static void polytouchout_float(t_polytouchout *x, t_float n)
-{
- int binchan = x->x_channel - 1;
- if (binchan < 0)
- binchan = 0;
- outmidi_polyaftertouch((binchan >> 4), (binchan & 15), x->x_pitch, n);
-}
-
-static void polytouchout_setup(void)
-{
- polytouchout_class = class_new(gensym("polytouchout"),
- (t_newmethod)polytouchout_new, 0,
- sizeof(t_polytouchout), 0, A_DEFFLOAT, 0);
- class_addfloat(polytouchout_class, polytouchout_float);
- class_sethelpsymbol(polytouchout_class, gensym("midi"));
-}
-
-/* -------------------------- makenote -------------------------- */
-
-static t_class *makenote_class;
-
-typedef struct _hang
-{
- t_clock *h_clock;
- struct _hang *h_next;
- t_float h_pitch;
- struct _makenote *h_owner;
-} t_hang;
-
-typedef struct _makenote
-{
- t_object x_obj;
- t_float x_velo;
- t_float x_dur;
- t_outlet *x_pitchout;
- t_outlet *x_velout;
- t_hang *x_hang;
-} t_makenote;
-
-static void *makenote_new(t_floatarg velo, t_floatarg dur)
-{
- t_makenote *x = (t_makenote *)pd_new(makenote_class);
- x->x_velo = velo;
- x->x_dur = dur;
- floatinlet_new(&x->x_obj, &x->x_velo);
- floatinlet_new(&x->x_obj, &x->x_dur);
- x->x_pitchout = outlet_new(&x->x_obj, &s_float);
- x->x_velout = outlet_new(&x->x_obj, &s_float);
- x->x_hang = 0;
- return (x);
-}
-
-static void makenote_tick(t_hang *hang)
-{
- t_makenote *x = hang->h_owner;
- t_hang *h2, *h3;
- outlet_float(x->x_velout, 0);
- outlet_float(x->x_pitchout, hang->h_pitch);
- if (x->x_hang == hang) x->x_hang = hang->h_next;
- else for (h2 = x->x_hang; h3 = h2->h_next; h2 = h3)
- {
- if (h3 == hang)
- {
- h2->h_next = h3->h_next;
- break;
- }
- }
- clock_free(hang->h_clock);
- freebytes(hang, sizeof(*hang));
-}
-
-static void makenote_float(t_makenote *x, t_float f)
-{
- t_hang *hang;
- if (!x->x_velo) return;
- outlet_float(x->x_velout, x->x_velo);
- outlet_float(x->x_pitchout, f);
- hang = (t_hang *)getbytes(sizeof *hang);
- hang->h_next = x->x_hang;
- x->x_hang = hang;
- hang->h_pitch = f;
- hang->h_owner = x;
- hang->h_clock = clock_new(hang, (t_method)makenote_tick);
- clock_delay(hang->h_clock, (x->x_dur >= 0 ? x->x_dur : 0));
-}
-
-static void makenote_stop(t_makenote *x)
-{
- t_hang *hang;
- while (hang = x->x_hang)
- {
- outlet_float(x->x_velout, 0);
- outlet_float(x->x_pitchout, hang->h_pitch);
- x->x_hang = hang->h_next;
- clock_free(hang->h_clock);
- freebytes(hang, sizeof(*hang));
- }
-}
-
-static void makenote_clear(t_makenote *x)
-{
- t_hang *hang;
- while (hang = x->x_hang)
- {
- x->x_hang = hang->h_next;
- clock_free(hang->h_clock);
- freebytes(hang, sizeof(*hang));
- }
-}
-
-static void makenote_setup(void)
-{
- makenote_class = class_new(gensym("makenote"),
- (t_newmethod)makenote_new, (t_method)makenote_clear,
- sizeof(t_makenote), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addfloat(makenote_class, makenote_float);
- class_addmethod(makenote_class, (t_method)makenote_stop, gensym("stop"),
- 0);