changeset 467:03a2cd5f151b prerelease

Libpd headers moved to include/, rm useless basic_libpd example, fixed Makefile to actually build default_libpd_render
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 20 Jun 2016 16:57:35 +0100
parents 1d585c5fa663
children 85cf9c0da052
files Makefile core/default_libpd_render.cpp examples/basic_libpd/m_pd.h examples/basic_libpd/main.cpp examples/basic_libpd/render.cpp examples/basic_libpd/s_stuff.h examples/basic_libpd/z_libpd.h include/libpd/m_pd.h include/libpd/s_stuff.h include/libpd/z_libpd.h
diffstat 10 files changed, 1704 insertions(+), 1795 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Jun 20 16:09:00 2016 +0100
+++ b/Makefile	Mon Jun 20 16:57:35 2016 +0100
@@ -207,7 +207,7 @@
 # function, and conditionally call one of two recursive make targets depending on whether
 # we want to link in the default main file or not. The kludge is the mess of a shell script
 # line below. Surely there's a better way to do this?
-$(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
+$(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_PD_OBJS)
 	$(eval DEFAULT_MAIN_CONDITIONAL :=\
 	    $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : '))
 	@#If there is a _main.pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/default_libpd_render.cpp	Mon Jun 20 16:57:35 2016 +0100
@@ -0,0 +1,403 @@
+/*
+ * render.cpp
+ *
+ *  Created on: Oct 24, 2014
+ *      Author: parallels
+ */
+
+#include <Bela.h>
+#include <DigitalChannelManager.h>
+#include <cmath>
+#include <I2c_Codec.h>
+#include <PRU.h>
+#include <stdio.h>
+#include <libpd/z_libpd.h>
+#include <libpd/s_stuff.h>
+#include <UdpServer.h>
+#include <Midi.h>
+//extern t_sample* sys_soundin;
+//extern t_sample* sys_soundout;
+// if you are 100% sure of what value was used to compile libpd/puredata, then
+// you could #define this instead of getting it at runtime. It has proved to give some 0.3%
+// performance boost when it is 8 (thanks to vectorize optimizations I guess).
+int gBufLength;
+
+float* gInBuf;
+float* gOutBuf;
+
+void pdnoteon(int ch, int pitch, int vel) {
+  printf("noteon: %d %d %d\n", ch, pitch, vel);
+}
+
+void Bela_printHook(const char *recv){
+	rt_printf("%s", recv);
+}
+
+void libpdReadFilesLoop(){
+    while(!gShouldStop){
+    	// check for modified sockets/file descriptors
+    	// (libpd would normally do this every block WITHIN the audio thread)
+    	// not sure if this is thread-safe at the moment
+    	libpd_sys_microsleep(0);
+        usleep(1000);
+    }
+}
+
+#define PARSE_MIDI
+static AuxiliaryTask libpdReadFilesTask;
+static Midi midi;
+static DigitalChannelManager dcm;
+//UdpServer udpServer;
+
+void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){
+	libpd_float((char*)receiverName, (float)state);
+//	rt_printf("%s: %d\n", (char*)receiverName, state);
+}
+
+#define LIBPD_DIGITAL_OFFSET 11 // digitals are preceded by 2 audio and 8 analogs (even if using a different number of analogs)
+
+void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){
+	if(strcmp(source, "bela_setDigital") == 0){
+		// symbol is the direction, argv[0] is the channel, argv[1] (optional)
+		// is signal("sig" or "~") or message("message", default) rate
+		bool isMessageRate = true; // defaults to message rate
+		bool direction = 0; // initialize it just to avoid the compiler's warning
+		bool disable = false;
+		if(strcmp(symbol, "in") == 0){
+			direction = INPUT;
+		} else if(strcmp(symbol, "out") == 0){
+			direction = OUTPUT;
+		} else if(strcmp(symbol, "disable") == 0){
+			disable = true;
+		} else {
+			return;
+		}
+		if(argc == 0){
+			return;
+		} else if (libpd_is_float(&argv[0]) == false){
+			return;
+		}
+		int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET;
+		if(disable == true){
+			dcm.unmanage(channel);
+			return;
+		}
+		if(argc >= 2){
+			t_atom* a = &argv[1];
+			if(libpd_is_symbol(a)){
+				char *s = libpd_get_symbol(a);
+				if(strcmp(s, "~") == 0  || strncmp(s, "sig", 3) == 0){
+					isMessageRate = false;
+				}
+			}
+		}
+		dcm.manage(channel, direction, isMessageRate);
+	}
+}
+
+void Bela_floatHook(const char *source, float value){
+	// let's make this as optimized as possible for built-in digital Out parsing
+	// the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between 11 and 26
+	static int prefixLength = 15; // strlen("bela_digitalOut")
+	if(strncmp(source, "bela_digitalOut", prefixLength)==0){
+		if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2)
+			if(source[prefixLength + 1] != 0){
+				// quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi
+				int receiver = ((source[prefixLength] - 48) * 10);
+				receiver += (source[prefixLength+1] - 48);
+				unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
+				if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
+					dcm.setValue(channel, value);
+				}
+			}
+		}
+	}
+}
+
+char receiverNames[16][21]={
+	{"bela_digitalIn11"},{"bela_digitalIn12"},{"bela_digitalIn13"},{"bela_digitalIn14"},{"bela_digitalIn15"},
+	{"bela_digitalIn16"},{"bela_digitalIn17"},{"bela_digitalIn18"},{"bela_digitalIn19"},{"bela_digitalIn20"},
+	{"bela_digitalIn21"},{"bela_digitalIn22"},{"bela_digitalIn23"},{"bela_digitalIn24"},{"bela_digitalIn25"},
+	{"bela_digitalIn26"}
+};
+
+static unsigned int analogChannelsInUse;
+static unsigned int gLibpdBlockSize;
+static unsigned int gChannelsInUse = 26;
+
+bool setup(BelaContext *context, void *userData)
+{
+	dcm.setCallback(sendDigitalMessage);
+	analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels - context->digitalChannels);
+	if(context->digitalChannels > 0){
+		for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){
+			dcm.setCallbackArgument(ch, receiverNames[ch]);
+		}
+	}
+	midi.readFrom(0);
+	midi.writeTo(0);
+#ifdef PARSE_MIDI
+	midi.enableParser(true);
+#else
+	midi.enableParser(false);
+#endif /* PARSE_MIDI */
+//	gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse);
+//	udpServer.bindToPort(1234);
+
+	gLibpdBlockSize = libpd_blocksize();
+	// check that we are not running with a blocksize smaller than gLibPdBlockSize
+	// it would still work, but the load would be executed unevenly between calls to render
+	if(context->audioFrames < gLibpdBlockSize){
+		fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize);
+		return false;
+	}
+	// set hooks before calling libpd_init
+	libpd_set_printhook(Bela_printHook);
+	libpd_set_floathook(Bela_floatHook);
+	libpd_set_messagehook(Bela_messageHook);
+	libpd_set_noteonhook(pdnoteon);
+	//TODO: add hooks for other midi events and generate MIDI output appropriately
+	libpd_init();
+	//TODO: ideally, we would analyse the ASCII of the patch file and find out which in/outs to use
+	libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate);
+	gInBuf = libpd_get_sys_soundin();
+	gOutBuf = libpd_get_sys_soundout();
+
+	libpd_start_message(1); // one entry in list
+	libpd_add_float(1.0f);
+	libpd_finish_message("pd", "dsp");
+
+	gBufLength = max(gLibpdBlockSize, context->audioFrames);
+
+
+	// bind your receivers here
+	libpd_bind("bela_digitalOut11");
+	libpd_bind("bela_digitalOut12");
+	libpd_bind("bela_digitalOut13");
+	libpd_bind("bela_digitalOut14");
+	libpd_bind("bela_digitalOut15");
+	libpd_bind("bela_digitalOut16");
+	libpd_bind("bela_digitalOut17");
+	libpd_bind("bela_digitalOut18");
+	libpd_bind("bela_digitalOut19");
+	libpd_bind("bela_digitalOut20");
+	libpd_bind("bela_digitalOut21");
+	libpd_bind("bela_digitalOut22");
+	libpd_bind("bela_digitalOut23");
+	libpd_bind("bela_digitalOut24");
+	libpd_bind("bela_digitalOut25");
+	libpd_bind("bela_digitalOut26");
+	libpd_bind("bela_setDigital");
+
+	char file[] = "_main.pd";
+	char folder[] = "./";
+	// open patch       [; pd open file folder(
+	libpd_openfile(file, folder);
+	libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles");
+	Bela_scheduleAuxiliaryTask(libpdReadFilesTask);
+
+
+	return true;
+}
+
+// render() is called regularly at the highest priority by the audio engine.
+// Input and output are given from the audio hardware and the other
+// ADCs and DACs (if available). If only audio is available, numMatrixFrames
+// will be 0.
+
+void render(BelaContext *context, void *userData)
+{
+	int num;
+	// the safest thread-safe option to handle MIDI input is to process the MIDI buffer
+	// from the audio thread.
+#ifdef PARSE_MIDI
+	while((num = midi.getParser()->numAvailableMessages()) > 0){
+		static MidiChannelMessage message;
+		message = midi.getParser()->getNextChannelMessage();
+		//message.prettyPrint(); // use this to print beautified message (channel, data bytes)
+		switch(message.getType()){
+			case kmmNoteOn:
+			{
+				int noteNumber = message.getDataByte(0);
+				int velocity = message.getDataByte(1);
+				int channel = message.getChannel();
+				libpd_noteon(channel, noteNumber, velocity);
+				break;
+			}
+			case kmmNoteOff:
+			{
+				/* PureData does not seem to handle noteoff messages as per the MIDI specs,
+				 * so that the noteoff velocity is ignored. Here we convert them to noteon
+				 * with a velocity of 0.
+				 */
+				int noteNumber = message.getDataByte(0);
+//				int velocity = message.getDataByte(1); // would be ignored by Pd
+				int channel = message.getChannel();
+				libpd_noteon(channel, noteNumber, 0);
+				break;
+			}
+			case kmmControlChange:
+			{
+				int channel = message.getChannel();
+				int controller = message.getDataByte(0);
+				int value = message.getDataByte(1);
+				libpd_controlchange(channel, controller, value);
+				break;
+			}
+			case kmmProgramChange:
+			{
+				int channel = message.getChannel();
+				int program = message.getDataByte(0);
+				libpd_programchange(channel, program);
+				break;
+			}
+			case kmmPolyphonicKeyPressure:
+			{
+				int channel = message.getChannel();
+				int pitch = message.getDataByte(0);
+				int value = message.getDataByte(1);
+				libpd_polyaftertouch(channel, pitch, value);
+				break;
+			}
+			case kmmChannelPressure:
+			{
+				int channel = message.getChannel();
+				int value = message.getDataByte(0);
+				libpd_aftertouch(channel, value);
+				break;
+			}
+			case kmmPitchBend:
+			{
+				int channel = message.getChannel();
+				int value =  (message.getDataByte(1) << 7)| message.getDataByte(0);
+				libpd_pitchbend(channel, value);
+				break;
+			}
+			case kmmNone:
+			case kmmAny:
+				break;
+		}
+	}
+#else
+	int input;
+	while((input = midi.getInput()) >= 0){
+		libpd_midibyte(0, input);
+	}
+#endif /* PARSE_MIDI */
+
+	static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize;
+
+	// these are reset at every audio callback. Persistence across audio callbacks
+	// is handled by the core code.
+//	setDataOut = 0;
+//	clearDataOut = 0;
+
+	for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick){
+		unsigned int audioFrameBase = gLibpdBlockSize * tick;
+		unsigned int j;
+		unsigned int k;
+		float* p0;
+		float* p1;
+		for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
+			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
+				*p1 = audioRead(context, audioFrameBase + j, k);
+			}
+		}
+		// then analogs
+		// this loop resamples by ZOH, as needed, using m
+		if(context->analogChannels == 8 ){ //hold the value for two frames
+			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
+				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					unsigned int analogFrame = (audioFrameBase + j) / 2;
+					*p1 = analogRead(context, analogFrame, k);
+				}
+			}
+		} else if(context->analogChannels == 4){ //write every frame
+			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
+				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					unsigned int analogFrame = audioFrameBase + j;
+					*p1 = analogRead(context, analogFrame, k);
+				}
+			}
+		} else if(context->analogChannels == 2){ //drop every other frame
+			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
+				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					unsigned int analogFrame = (audioFrameBase + j) * 2;
+					*p1 = analogRead(context, analogFrame, k);
+				}
+			}
+		}
+
+		//then digital
+		// note: in multiple places below we assume that the number of digitals is same as number of audio
+		// digital in at message-rate
+		dcm.processInput(&context->digital[audioFrameBase], gLibpdBlockSize);
+
+		// digital in at signal-rate
+		for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
+			unsigned int digitalFrame = audioFrameBase + j;
+			for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8);
+					k < 16; ++k, p1 += gLibpdBlockSize) {
+				if(dcm.isSignalRate(k) && dcm.isInput(k)){ // only process input channels that are handled at signal rate
+					*p1 = digitalRead(context, digitalFrame, k);
+				}
+			}
+		}
+
+		libpd_process_sys(); // process the block
+
+		//digital out
+		// digital out at signal-rate
+		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
+			unsigned int digitalFrame = (audioFrameBase + j);
+			for (k = 0, p1 = p0  + gLibpdBlockSize * (context->audioChannels + 8);
+					k < context->digitalChannels; k++, p1 += gLibpdBlockSize) {
+				if(dcm.isSignalRate(k) && dcm.isOutput(k)){ // only process output channels that are handled at signal rate
+					digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5);
+				}
+			}
+		}
+
+		// digital out at message-rate
+		dcm.processOutput(&context->digital[audioFrameBase], gLibpdBlockSize);
+
+		//audio
+		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
+			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
+				audioWrite(context, audioFrameBase + j, k, *p1);
+			}
+		}
+
+		//analog
+		if(context->analogChannels == 8){
+			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames
+				unsigned int analogFrame = (audioFrameBase + j) / 2;
+				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					analogWriteOnce(context, analogFrame, k, *p1);
+				}
+			}
+		} else if(context->analogChannels == 4){ //write every frame
+			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
+				unsigned int analogFrame = (audioFrameBase + j);
+				for (k = 0, p1 = p0  + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					analogWriteOnce(context, analogFrame, k, *p1);
+				}
+			}
+		} else if(context->analogChannels == 2){ //write every frame twice
+			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
+				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+					int analogFrame = audioFrameBase * 2 + j * 2;
+					analogWriteOnce(context, analogFrame, k, *p1);
+					analogWriteOnce(context, analogFrame + 1, k, *p1);
+				}
+			}
+		}
+	}
+}
+
+// cleanup() is called once at the end, after the audio has stopped.
+// Release any resources that were allocated in setup().
+
+void cleanup(BelaContext *context, void *userData)
+{
+}
--- a/examples/basic_libpd/m_pd.h	Mon Jun 20 16:09:00 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,770 +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.  */
-
-#ifndef __m_pd_h_
-
-#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
-extern "C" {
-#endif
-
-#define PD_MAJOR_VERSION 0
-#define PD_MINOR_VERSION 46
-#define PD_BUGFIX_VERSION 6
-#define PD_TEST_VERSION ""
-extern int pd_compatibilitylevel;   /* e.g., 43 for pd 0.43 compatibility */
-
-/* old name for "MSW" flag -- we have to take it for the sake of many old
-"nmakefiles" for externs, which will define NT and not MSW */
-#if defined(NT) && !defined(MSW)
-#define MSW
-#endif
-
-/* These pragmas are only used for MSVC, not MinGW or Cygwin <hans@at.or.at> */
-#ifdef _MSC_VER
-/* #pragma warning( disable : 4091 ) */
-#pragma warning( disable : 4305 )  /* uncast const double to float */
-#pragma warning( disable : 4244 )  /* uncast float/int conversion etc. */
-#pragma warning( disable : 4101 )  /* unused automatic variables */
-#endif /* _MSC_VER */
-
-    /* the external storage class is "extern" in UNIX; in MSW it's ugly. */
-#ifdef _WIN32
-#ifdef PD_INTERNAL
-#define EXTERN __declspec(dllexport) extern
-#else
-#define EXTERN __declspec(dllimport) extern
-#endif /* PD_INTERNAL */
-#else
-#define EXTERN extern
-#endif /* _WIN32 */
-
-    /* and depending on the compiler, hidden data structures are
-    declared differently: */
-#if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ )
-#define EXTERN_STRUCT struct
-#else
-#define EXTERN_STRUCT extern struct
-#endif
-
-/* Define some attributes, specific to the compiler */
-#if defined(__GNUC__)
-#define ATTRIBUTE_FORMAT_PRINTF(a, b) __attribute__ ((format (printf, a, b)))
-#else
-#define ATTRIBUTE_FORMAT_PRINTF(a, b)
-#endif
-
-#if !defined(_SIZE_T) && !defined(_SIZE_T_)
-#include <stddef.h>     /* just for size_t -- how lame! */
-#endif
-
-/* Microsoft Visual Studio is not C99, it does not provide stdint.h */
-#ifdef _MSC_VER
-typedef signed __int8     int8_t;
-typedef signed __int16    int16_t;
-typedef signed __int32    int32_t;
-typedef signed __int64    int64_t;
-typedef unsigned __int8   uint8_t;
-typedef unsigned __int16  uint16_t;
-typedef unsigned __int32  uint32_t;
-typedef unsigned __int64  uint64_t;
-#else
-# include <stdint.h>
-#endif
-
-/* for FILE, needed by sys_fopen() and sys_fclose() only */
-#include <stdio.h>
-
-#define MAXPDSTRING 1000        /* use this for anything you want */
-#define MAXPDARG 5              /* max number of args we can typecheck today */
-
-/* signed and unsigned integer types the size of a pointer:  */
-#if !defined(PD_LONGINTTYPE)
-#define PD_LONGINTTYPE long
-#endif
-
-#if !defined(PD_FLOATSIZE)
-  /* normally, our floats (t_float, t_sample,...) are 32bit */
-# define PD_FLOATSIZE 32
-#endif
-
-#if PD_FLOATSIZE == 32
-# define PD_FLOATTYPE float
-/* an unsigned int of the same size as FLOATTYPE: */
-# define PD_FLOATUINTTYPE unsigned int
-
-#elif PD_FLOATSIZE == 64
-# define PD_FLOATTYPE double
-# define PD_FLOATUINTTYPE unsigned long
-#else
-# error invalid FLOATSIZE: must be 32 or 64
-#endif
-
-typedef PD_LONGINTTYPE t_int;       /* pointer-size integer */
-typedef PD_FLOATTYPE t_float;       /* a float type at most the same size */
-typedef PD_FLOATTYPE t_floatarg;    /* float type for function calls */
-
-typedef struct _symbol
-{
-    char *s_name;
-    struct _class **s_thing;
-    struct _symbol *s_next;
-} t_symbol;
-
-EXTERN_STRUCT _array;
-#define t_array struct _array       /* g_canvas.h */
-
-/* pointers to glist and array elements go through a "stub" which sticks
-around after the glist or array is freed.  The stub itself is deleted when
-both the glist/array is gone and the refcount is zero, ensuring that no
-gpointers are pointing here. */
-
-#define GP_NONE 0       /* the stub points nowhere (has been cut off) */
-#define GP_GLIST 1      /* the stub points to a glist element */
-#define GP_ARRAY 2      /* ... or array */
-
-typedef struct _gstub
-{
-    union
-    {
-        struct _glist *gs_glist;    /* glist we're in */
-        struct _array *gs_array;    /* array we're in */
-    } gs_un;
-    int gs_which;                   /* GP_GLIST/GP_ARRAY */
-    int gs_refcount;                /* number of gpointers pointing here */
-} t_gstub;
-
-typedef struct _gpointer           /* pointer to a gobj in a glist */
-{
-    union
-    {   
-        struct _scalar *gp_scalar;  /* scalar we're in (if glist) */
-        union word *gp_w;           /* raw data (if array) */
-    } gp_un;
-    int gp_valid;                   /* number which must match gpointee */
-    t_gstub *gp_stub;               /* stub which points to glist/array */
-} t_gpointer;
-
-typedef union word
-{
-    t_float w_float;
-    t_symbol *w_symbol;
-    t_gpointer *w_gpointer;
-    t_array *w_array;
-    struct _binbuf *w_binbuf;
-    int w_index;
-} t_word;
-
-typedef enum
-{
-    A_NULL,
-    A_FLOAT,
-    A_SYMBOL,
-    A_POINTER,
-    A_SEMI,
-    A_COMMA,
-    A_DEFFLOAT,
-    A_DEFSYM,
-    A_DOLLAR, 
-    A_DOLLSYM,
-    A_GIMME,
-    A_CANT
-}  t_atomtype;
-
-#define A_DEFSYMBOL A_DEFSYM    /* better name for this */
-
-typedef struct _atom
-{
-    t_atomtype a_type;
-    union word a_w;
-} t_atom;
-
-EXTERN_STRUCT _class;
-#define t_class struct _class
-
-EXTERN_STRUCT _outlet;
-#define t_outlet struct _outlet
-
-EXTERN_STRUCT _inlet;
-#define t_inlet struct _inlet
-
-EXTERN_STRUCT _binbuf;
-#define t_binbuf struct _binbuf
-
-EXTERN_STRUCT _clock;
-#define t_clock struct _clock
-
-EXTERN_STRUCT _outconnect;
-#define t_outconnect struct _outconnect
-
-EXTERN_STRUCT _glist;
-#define t_glist struct _glist
-#define t_canvas struct _glist  /* LATER lose this */
-
-typedef t_class *t_pd;      /* pure datum: nothing but a class pointer */
-
-typedef struct _gobj        /* a graphical object */
-{
-    t_pd g_pd;              /* pure datum header (class) */
-    struct _gobj *g_next;   /* next in list */
-} t_gobj;
-
-typedef struct _scalar      /* a graphical object holding data */
-{
-    t_gobj sc_gobj;         /* header for graphical object */
-    t_symbol *sc_template;  /* template name (LATER replace with pointer) */
-    t_word sc_vec[1];       /* indeterminate-length array of words */
-} t_scalar;
-
-typedef struct _text        /* patchable object - graphical, with text */
-{
-    t_gobj te_g;                /* header for graphical object */
-    t_binbuf *te_binbuf;        /* holder for the text */
-    t_outlet *te_outlet;        /* linked list of outlets */
-    t_inlet *te_inlet;          /* linked list of inlets */
-    short te_xpix;              /* x&y location (within the toplevel) */
-    short te_ypix;
-    short te_width;             /* requested width in chars, 0 if auto */
-    unsigned int te_type:2;     /* from defs below */
-} t_text;
-
-#define T_TEXT 0        /* just a textual comment */
-#define T_OBJECT 1      /* a MAX style patchable object */
-#define T_MESSAGE 2     /* a MAX stype message */
-#define T_ATOM 3        /* a cell to display a number or symbol */
-
-#define te_pd te_g.g_pd
-
-   /* t_object is synonym for t_text (LATER unify them) */
-
-typedef struct _text t_object;
-
-#define ob_outlet te_outlet
-#define ob_inlet te_inlet
-#define ob_binbuf te_binbuf
-#define ob_pd te_g.g_pd
-#define ob_g te_g
-
-typedef void (*t_method)(void);
-typedef void *(*t_newmethod)( void);
-
-/* in ARM 64 a varargs prototype generates a different function call sequence
-from a fixed one, so in that special case we make a more restrictive
-definition for t_gotfn.  This will break some code in the "chaos" package
-in Pd extended.  (that code will run incorrectly anyhow so why not catch it
-at compile time anyhow.) */
-#if defined(__APPLE__) && defined(__aarch64__)
-typedef void (*t_gotfn)(void *x);
-#else
-typedef void (*t_gotfn)(void *x, ...);
-#endif
-
-/* ---------------- pre-defined objects and symbols --------------*/
-EXTERN t_pd pd_objectmaker;     /* factory for creating "object" boxes */
-EXTERN t_pd pd_canvasmaker;     /* factory for creating canvases */
-EXTERN t_symbol s_pointer;
-EXTERN t_symbol s_float;
-EXTERN t_symbol s_symbol;
-EXTERN t_symbol s_bang;
-EXTERN t_symbol s_list;
-EXTERN t_symbol s_anything;
-EXTERN t_symbol s_signal;
-EXTERN t_symbol s__N;
-EXTERN t_symbol s__X;
-EXTERN t_symbol s_x;
-EXTERN t_symbol s_y;
-EXTERN t_symbol s_;
-
-/* --------- prototypes from the central message system ----------- */
-EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv);
-EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv);
-EXTERN t_symbol *gensym(const char *s);
-EXTERN t_gotfn getfn(t_pd *x, t_symbol *s);
-EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s);
-EXTERN void nullfn(void);
-EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...);
-
-/* the following macrose are for sending non-type-checkable mesages, i.e.,
-using function lookup but circumventing type checking on arguments.  Only
-use for internal messaging protected by A_CANT so that the message can't
-be generated at patch level. */
-#define mess0(x, s) ((*getfn((x), (s)))((x)))
-typedef void (*t_gotfn1)(void *x, void *arg1);
-#define mess1(x, s, a) ((*(t_gotfn1)getfn((x), (s)))((x), (a)))
-typedef void (*t_gotfn2)(void *x, void *arg1, void *arg2);
-#define mess2(x, s, a,b) ((*(t_gotfn2)getfn((x), (s)))((x), (a),(b)))
-typedef void (*t_gotfn3)(void *x, void *arg1, void *arg2, void *arg3);
-#define mess3(x, s, a,b,c) ((*(t_gotfn3)getfn((x), (s)))((x), (a),(b),(c)))
-typedef void (*t_gotfn4)(void *x,
-    void *arg1, void *arg2, void *arg3, void *arg4);
-#define mess4(x, s, a,b,c,d) \
-    ((*(t_gotfn4)getfn((x), (s)))((x), (a),(b),(c),(d)))
-typedef void (*t_gotfn5)(void *x,
-    void *arg1, void *arg2, void *arg3, void *arg4, void *arg5);
-#define mess5(x, s, a,b,c,d,e) \
-    ((*(t_gotfn5)getfn((x), (s)))((x), (a),(b),(c),(d),(e)))
-
-EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
-EXTERN t_pd *pd_newest(void);
-
-/* --------------- memory management -------------------- */
-EXTERN void *getbytes(size_t nbytes);
-EXTERN void *getzbytes(size_t nbytes);
-EXTERN void *copybytes(void *src, size_t nbytes);
-EXTERN void freebytes(void *x, size_t nbytes);
-EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize);
-
-/* -------------------- atoms ----------------------------- */
-
-#define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0)
-#define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0)
-#define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \
-    (atom)->a_w.w_gpointer = (gp))
-#define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f))
-#define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \
-    (atom)->a_w.w_symbol = (s))
-#define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \
-    (atom)->a_w.w_index = (n))
-#define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \
-    (atom)->a_w.w_symbol= (s))
-
-EXTERN t_float atom_getfloat(t_atom *a);
-EXTERN t_int atom_getint(t_atom *a);
-EXTERN t_symbol *atom_getsymbol(t_atom *a);
-EXTERN t_symbol *atom_gensym(t_atom *a);
-EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv);
-EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv);
-EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv);
-
-EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize);
-
-/* ------------------  binbufs --------------- */
-
-EXTERN t_binbuf *binbuf_new(void);
-EXTERN void binbuf_free(t_binbuf *x);
-EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y);
-
-EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size);
-EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
-EXTERN void binbuf_clear(t_binbuf *x);
-EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv);
-EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...);
-EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y);
-EXTERN void binbuf_addsemi(t_binbuf *x);
-EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv);
-EXTERN void binbuf_print(t_binbuf *x);
-EXTERN int binbuf_getnatom(t_binbuf *x);
-EXTERN t_atom *binbuf_getvec(t_binbuf *x);
-EXTERN int binbuf_resize(t_binbuf *x, int newsize);
-EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv);
-EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname,
-    int crflag);
-EXTERN int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas,
-    int crflag);
-EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
-    int crflag);
-EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir,
-    int crflag);
-EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
-EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
-    int tonew);
-
-/* ------------------  clocks --------------- */
-
-EXTERN t_clock *clock_new(void *owner, t_method fn);
-EXTERN void clock_set(t_clock *x, double systime);
-EXTERN void clock_delay(t_clock *x, double delaytime);
-EXTERN void clock_unset(t_clock *x);
-EXTERN void clock_setunit(t_clock *x, double timeunit, int sampflag);
-EXTERN double clock_getlogicaltime(void);
-EXTERN double clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */
-EXTERN double clock_gettimesince(double prevsystime);
-EXTERN double clock_gettimesincewithunits(double prevsystime,
-    double units, int sampflag);
-EXTERN double clock_getsystimeafter(double delaytime);
-EXTERN void clock_free(t_clock *x);
-
-/* ----------------- pure data ---------------- */
-EXTERN t_pd *pd_new(t_class *cls);
-EXTERN void pd_free(t_pd *x);
-EXTERN void pd_bind(t_pd *x, t_symbol *s);
-EXTERN void pd_unbind(t_pd *x, t_symbol *s);
-EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c);
-EXTERN void pd_pushsym(t_pd *x);
-EXTERN void pd_popsym(t_pd *x);
-EXTERN t_symbol *pd_getfilename(void);
-EXTERN t_symbol *pd_getdirname(void);
-EXTERN void pd_bang(t_pd *x);
-EXTERN void pd_pointer(t_pd *x, t_gpointer *gp);
-EXTERN void pd_float(t_pd *x, t_float f);
-EXTERN void pd_symbol(t_pd *x, t_symbol *s);
-EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv);
-EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv);
-#define pd_class(x) (*(x))
-
-/* ----------------- pointers ---------------- */
-EXTERN void gpointer_init(t_gpointer *gp);
-EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto);
-EXTERN void gpointer_unset(t_gpointer *gp);
-EXTERN int gpointer_check(const t_gpointer *gp, int headok);
-
-/* ----------------- patchable "objects" -------------- */
-EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1,
-    t_symbol *s2);
-EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp);
-EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp);
-EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp);
-EXTERN t_inlet *signalinlet_new(t_object *owner, t_float f);
-EXTERN void inlet_free(t_inlet *x);
-
-EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s);
-EXTERN void outlet_bang(t_outlet *x);
-EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp);
-EXTERN void outlet_float(t_outlet *x, t_float f);
-EXTERN void outlet_symbol(t_outlet *x, t_symbol *s);
-EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
-EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
-EXTERN t_symbol *outlet_getsymbol(t_outlet *x);
-EXTERN void outlet_free(t_outlet *x);
-EXTERN t_object *pd_checkobject(t_pd *x);
-
-
-/* -------------------- canvases -------------- */
-
-EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir);
-
-EXTERN void canvas_setargs(int argc, t_atom *argv);
-EXTERN void canvas_getargs(int *argcp, t_atom **argvp);
-EXTERN t_symbol *canvas_getcurrentdir(void);
-EXTERN t_glist *canvas_getcurrent(void);
-EXTERN void canvas_makefilename(t_glist *c, char *file,
-    char *result,int resultsize);
-EXTERN t_symbol *canvas_getdir(t_glist *x);
-EXTERN char sys_font[]; /* default typeface set in s_main.c */
-EXTERN char sys_fontweight[]; /* default font weight set in s_main.c */
-EXTERN int sys_fontwidth(int fontsize);
-EXTERN int sys_fontheight(int fontsize);
-EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b);
-EXTERN int canvas_open(t_canvas *x, const char *name, const char *ext,
-    char *dirresult, char **nameresult, unsigned int size, int bin);
-
-/* ---------------- widget behaviors ---------------------- */
-
-EXTERN_STRUCT _widgetbehavior;
-#define t_widgetbehavior struct _widgetbehavior
-
-EXTERN_STRUCT _parentwidgetbehavior;
-#define t_parentwidgetbehavior struct _parentwidgetbehavior
-EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
-
-/* -------------------- classes -------------- */
-
-#define CLASS_DEFAULT 0         /* flags for new classes below */
-#define CLASS_PD 1
-#define CLASS_GOBJ 2
-#define CLASS_PATCHABLE 3
-#define CLASS_NOINLET 8
-
-#define CLASS_TYPEMASK 3
-
-
-EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod,
-    t_method freemethod, size_t size, int flags, t_atomtype arg1, ...);
-EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s, 
-    t_atomtype type1, ...);
-EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
-    t_atomtype arg1, ...);
-EXTERN void class_addbang(t_class *c, t_method fn);
-EXTERN void class_addpointer(t_class *c, t_method fn);
-EXTERN void class_doaddfloat(t_class *c, t_method fn);
-EXTERN void class_addsymbol(t_class *c, t_method fn);
-EXTERN void class_addlist(t_class *c, t_method fn);
-EXTERN void class_addanything(t_class *c, t_method fn);
-EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s);
-EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w);
-EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w);
-EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c);
-EXTERN char *class_getname(t_class *c);
-EXTERN char *class_gethelpname(t_class *c);
-EXTERN char *class_gethelpdir(t_class *c);
-EXTERN void class_setdrawcommand(t_class *c);
-EXTERN int class_isdrawcommand(t_class *c);
-EXTERN void class_domainsignalin(t_class *c, int onset);
-EXTERN void class_set_extern_dir(t_symbol *s);
-#define CLASS_MAINSIGNALIN(c, type, field) \
-    class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0)
-
-         /* prototype for functions to save Pd's to a binbuf */
-typedef void (*t_savefn)(t_gobj *x, t_binbuf *b);
-EXTERN void class_setsavefn(t_class *c, t_savefn f);
-EXTERN t_savefn class_getsavefn(t_class *c);
-EXTERN void obj_saveformat(t_object *x, t_binbuf *bb); /* add format to bb */
-
-        /* prototype for functions to open properties dialogs */
-typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist);
-EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f);
-EXTERN t_propertiesfn class_getpropertiesfn(t_class *c);
-
-#ifndef PD_CLASS_DEF
-#define class_addbang(x, y) class_addbang((x), (t_method)(y))
-#define class_addpointer(x, y) class_addpointer((x), (t_method)(y))
-#define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y))
-#define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y))
-#define class_addlist(x, y) class_addlist((x), (t_method)(y))
-#define class_addanything(x, y) class_addanything((x), (t_method)(y))
-#endif
-
-/* ------------   printing --------------------------------- */
-EXTERN void post(const char *fmt, ...);
-EXTERN void startpost(const char *fmt, ...);
-EXTERN void poststring(const char *s);
-EXTERN void postfloat(t_floatarg f);
-EXTERN void postatom(int argc, t_atom *argv);
-EXTERN void endpost(void);
-EXTERN void error(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
-EXTERN void verbose(int level, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
-EXTERN void bug(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
-EXTERN void pd_error(void *object, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
-EXTERN void logpost(const void *object, const int level, const char *fmt, ...)
-    ATTRIBUTE_FORMAT_PRINTF(3, 4);
-EXTERN void sys_logerror(const char *object, const char *s);
-EXTERN void sys_unixerror(const char *object);
-EXTERN void sys_ouch(void);
-
-
-/* ------------  system interface routines ------------------- */
-EXTERN int sys_isreadablefile(const char *name);
-EXTERN int sys_isabsolutepath(const char *dir);
-EXTERN void sys_bashfilename(const char *from, char *to);
-EXTERN void sys_unbashfilename(const char *from, char *to);
-EXTERN int open_via_path(const char *dir, const char *name, const char *ext,
-    char *dirresult, char **nameresult, unsigned int size, int bin);
-EXTERN int sched_geteventno(void);
-EXTERN double sys_getrealtime(void);
-EXTERN int (*sys_idlehook)(void);   /* hook to add idle time computation */
-
-/* Win32's open()/fopen() do not handle UTF-8 filenames so we need
- * these internal versions that handle UTF-8 filenames the same across
- * all platforms.  They are recommended for use in external
- * objectclasses as well so they work with Unicode filenames on Windows */
-EXTERN int sys_open(const char *path, int oflag, ...);
-EXTERN int sys_close(int fd);
-EXTERN FILE *sys_fopen(const char *filename, const char *mode);
-EXTERN int sys_fclose(FILE *stream);
-
-/* ------------  threading ------------------- */ 
-EXTERN void sys_lock(void);
-EXTERN void sys_unlock(void);
-EXTERN int sys_trylock(void);
-
-
-/* --------------- signals ----------------------------------- */
-
-typedef PD_FLOATTYPE t_sample;
-typedef union _sampleint_union {
-  t_sample f;
-  PD_FLOATUINTTYPE i;
-} t_sampleint_union;
-#define MAXLOGSIG 32
-#define MAXSIGSIZE (1 << MAXLOGSIG)
-
-typedef struct _signal
-{
-    int s_n;            /* number of points in the array */
-    t_sample *s_vec;    /* the array */
-    t_float s_sr;         /* sample rate */
-    int s_refcount;     /* number of times used */
-    int s_isborrowed;   /* whether we're going to borrow our array */
-    struct _signal *s_borrowedfrom;     /* signal to borrow it from */
-    struct _signal *s_nextfree;         /* next in freelist */
-    struct _signal *s_nextused;         /* next in used list */
-    int s_vecsize;      /* allocated size of array in points */
-} t_signal;
-
-typedef t_int *(*t_perfroutine)(t_int *args);
-
-EXTERN t_int *plus_perform(t_int *args);
-EXTERN t_int *zero_perform(t_int *args);
-EXTERN t_int *copy_perform(t_int *args);
-
-EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n);
-EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n);
-EXTERN void dsp_add_scalarcopy(t_float *in, t_sample *out, int n);
-EXTERN void dsp_add_zero(t_sample *out, int n);
-
-EXTERN int sys_getblksize(void);
-EXTERN t_float sys_getsr(void);
-EXTERN int sys_get_inchannels(void);
-EXTERN int sys_get_outchannels(void);
-
-EXTERN void dsp_add(t_perfroutine f, int n, ...);
-EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec);
-EXTERN void pd_fft(t_float *buf, int npoints, int inverse);
-EXTERN int ilog2(int n);
-
-EXTERN void mayer_fht(t_sample *fz, int n);
-EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag);
-EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag);
-EXTERN void mayer_realfft(int n, t_sample *real);
-EXTERN void mayer_realifft(int n, t_sample *real);
-
-EXTERN float *cos_table;
-#define LOGCOSTABSIZE 9
-#define COSTABSIZE (1<<LOGCOSTABSIZE)
-
-EXTERN int canvas_suspend_dsp(void);
-EXTERN void canvas_resume_dsp(int oldstate);
-EXTERN void canvas_update_dsp(void);
-EXTERN int canvas_dspstate;
-
-/*   up/downsampling */
-typedef struct _resample
-{
-  int method;       /* up/downsampling method ID */
-
-  int downsample; /* downsampling factor */
-  int upsample;   /* upsampling factor */
-
-  t_sample *s_vec;   /* here we hold the resampled data */
-  int      s_n;
-
-  t_sample *coeffs;  /* coefficients for filtering... */
-  int      coefsize;
-
-  t_sample *buffer;  /* buffer for filtering */
-  int      bufsize;
-} t_resample;
-
-EXTERN void resample_init(t_resample *x);
-EXTERN void resample_free(t_resample *x);
-
-EXTERN void resample_dsp(t_resample *x, t_sample *in, int insize, t_sample *out, int outsize, int method);
-EXTERN void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method);
-EXTERN void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method);
-
-/* ----------------------- utility functions for signals -------------- */
-EXTERN t_float mtof(t_float);
-EXTERN t_float ftom(t_float);
-EXTERN t_float rmstodb(t_float);
-EXTERN t_float powtodb(t_float);
-EXTERN t_float dbtorms(t_float);
-EXTERN t_float dbtopow(t_float);
-
-EXTERN t_float q8_sqrt(t_float);
-EXTERN t_float q8_rsqrt(t_float);
-#ifndef N32     
-EXTERN t_float qsqrt(t_float);  /* old names kept for extern compatibility */
-EXTERN t_float qrsqrt(t_float);
-#endif
-/* --------------------- data --------------------------------- */
-
-    /* graphical arrays */
-EXTERN_STRUCT _garray;
-#define t_garray struct _garray
-
-EXTERN t_class *garray_class;
-EXTERN int garray_getfloatarray(t_garray *x, int *size, t_float **vec);
-EXTERN int garray_getfloatwords(t_garray *x, int *size, t_word **vec);
-EXTERN void garray_redraw(t_garray *x);
-EXTERN int garray_npoints(t_garray *x);
-EXTERN char *garray_vec(t_garray *x);
-EXTERN void garray_resize(t_garray *x, t_floatarg f);  /* avoid; use this: */
-EXTERN void garray_resize_long(t_garray *x, long n);   /* better version */
-EXTERN void garray_usedindsp(t_garray *x);
-EXTERN void garray_setsaveit(t_garray *x, int saveit);
-EXTERN t_glist *garray_getglist(t_garray *x);
-EXTERN t_array *garray_getarray(t_garray *x);
-EXTERN t_class *scalar_class;
-
-EXTERN t_float *value_get(t_symbol *s);
-EXTERN void value_release(t_symbol *s);
-EXTERN int value_getfloat(t_symbol *s, t_float *f);
-EXTERN int value_setfloat(t_symbol *s, t_float f);
-
-/* ------- GUI interface - functions to send strings to TK --------- */
-typedef void (*t_guicallbackfn)(t_gobj *client, t_glist *glist);
-
-EXTERN void sys_vgui(char *fmt, ...);
-EXTERN void sys_gui(char *s);
-EXTERN void sys_pretendguibytes(int n);
-EXTERN void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f);
-EXTERN void sys_unqueuegui(void *client);
-    /* dialog window creation and destruction */
-EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd);
-EXTERN void gfxstub_deleteforkey(void *key);
-
-extern t_class *glob_pdobject;  /* object to send "pd" messages */
-
-/*-------------  Max 0.26 compatibility --------------------*/
-
-/* the following reflects the new way classes are laid out, with the class
-   pointing to the messlist and not vice versa. Externs shouldn't feel it. */
-typedef t_class *t_externclass;
-
-EXTERN void c_extern(t_externclass *cls, t_newmethod newroutine,
-    t_method freeroutine, t_symbol *name, size_t size, int tiny, \
-    t_atomtype arg1, ...);
-EXTERN void c_addmess(t_method fn, t_symbol *sel, t_atomtype arg1, ...);
-
-#define t_getbytes getbytes
-#define t_freebytes freebytes
-#define t_resizebytes resizebytes
-#define typedmess pd_typedmess
-#define vmess pd_vmess
-
-/* A definition to help gui objects straddle 0.34-0.35 changes.  If this is
-defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
-
-#define PD_USE_TE_XPIX
-
-#ifndef _MSC_VER /* Microoft compiler can't handle "inline" function/macros */
-#if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
-/* a test for NANs and denormals.  Should only be necessary on i386. */
-# if PD_FLOATSIZE == 32
-static inline int PD_BADFLOAT(t_sample f) {
-  t_sampleint_union u;
-  u.f=f;
-  return ((u.i & 0x7f800000)==0) || ((u.i&0x7f800000)==0x7f800000);
-}
-/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
-static inline int PD_BIGORSMALL(t_sample f) {
-  t_sampleint_union u;
-  u.f=f;
-  return ((u.i & 0x60000000)==0) || ((u.i & 0x60000000)==0x60000000);
-}
-# else
-#  warning 64bit mode: BIGORSMALL not implemented yet
-#  define PD_BADFLOAT(f) 0
-#  define PD_BIGORSMALL(f) 0
-# endif
-#else
-# define PD_BADFLOAT(f) 0
-# define PD_BIGORSMALL(f) 0
-#endif
-#else   /* _MSC_VER */
-#define PD_BADFLOAT(f) ((((*(unsigned int*)&(f))&0x7f800000)==0) || \
-    (((*(unsigned int*)&(f))&0x7f800000)==0x7f800000))
-/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
-#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
-    (((*(unsigned int*)&(f))&0x60000000)==0x60000000))
-#endif /* _MSC_VER */
-    /* get version number at run time */
-EXTERN void sys_getversion(int *major, int *minor, int *bugfix);
-
-EXTERN_STRUCT _pdinstance;
-#define t_pdinstance struct _pdinstance       /* m_imp.h */
-
-/* m_pd.c */
-
-EXTERN t_pdinstance *pdinstance_new( void);
-EXTERN void pd_setinstance(t_pdinstance *x);
-EXTERN void pdinstance_free(t_pdinstance *x);
-EXTERN t_canvas *pd_getcanvaslist(void);
-EXTERN int pd_getdspstate(void);
-
-#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
-}
-#endif
-
-#define __m_pd_h_
-#endif /* __m_pd_h_ */
--- a/examples/basic_libpd/main.cpp	Mon Jun 20 16:09:00 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * default_main.cpp
- *
- *  Created on: Oct 24, 2014
- *      Author: parallels
- */
-#include <unistd.h>
-#include <iostream>
-#include <cstdlib>
-#include <libgen.h>
-#include <signal.h>
-#include <getopt.h>
-#include "../include/Bela.h"
-
-using namespace std;
-
-// Handle Ctrl-C by requesting that the audio rendering stop
-void interrupt_handler(int var)
-{
-	gShouldStop = true;
-}
-
-// Print usage information
-void usage(const char * processName)
-{
-	cerr << "Usage: " << processName << " [options]" << endl;
-
-	Bela_usage();
-
-	cerr << "   --help [-h]:                Print this menu\n";
-}
-
-int main(int argc, char *argv[])
-{
-	BelaInitSettings settings;	// Standard audio settings
-
-	struct option customOptions[] =
-	{
-		{"help", 0, NULL, 'h'},
-		{NULL, 0, NULL, 0}
-	};
-
-	// Set default settings
-	Bela_defaultSettings(&settings);
-
-	// Parse command-line arguments
-	while (1) {
-		int c;
-		if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
-				break;
-		switch (c) {
-		case 'h':
-				usage(basename(argv[0]));
-				exit(0);
-		case '?':
-		default:
-				usage(basename(argv[0]));
-				exit(1);
-		}
-	}
-
-	// Initialise the PRU audio device
-	if(Bela_initAudio(&settings, 0) != 0) {
-		cout << "Error: unable to initialise audio" << endl;
-		return -1;
-	}
-
-	// Start the audio device running
-	if(Bela_startAudio()) {
-		cout << "Error: unable to start real-time audio" << endl;
-		return -1;
-	}
-
-	// Set up interrupt handler to catch Control-C and SIGTERM
-	signal(SIGINT, interrupt_handler);
-	signal(SIGTERM, interrupt_handler);
-
-	// Run until told to stop
-	while(!gShouldStop) {
-		usleep(100000);
-	}
-
-	// Stop the audio device
-	Bela_stopAudio();
-
-	// Clean up any resources allocated for audio
-	Bela_cleanupAudio();
-
-	// All done!
-	return 0;
-}
--- a/examples/basic_libpd/render.cpp	Mon Jun 20 16:09:00 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,403 +0,0 @@
-/*
- * render.cpp
- *
- *  Created on: Oct 24, 2014
- *      Author: parallels
- */
-
-#include <Bela.h>
-#include <DigitalChannelManager.h>
-#include <cmath>
-#include <I2c_Codec.h>
-#include <PRU.h>
-#include <stdio.h>
-#include "z_libpd.h"
-#include "s_stuff.h"
-#include <UdpServer.h>
-#include <Midi.h>
-//extern t_sample* sys_soundin;
-//extern t_sample* sys_soundout;
-// if you are 100% sure of what value was used to compile libpd/puredata, then
-// you could #define this instead of getting it at runtime. It has proved to give some 0.3%
-// performance boost when it is 8 (thanks to vectorize optimizations I guess).
-int gBufLength;
-
-float* gInBuf;
-float* gOutBuf;
-
-void pdnoteon(int ch, int pitch, int vel) {
-  printf("noteon: %d %d %d\n", ch, pitch, vel);
-}
-
-void Bela_printHook(const char *recv){
-	rt_printf("%s", recv);
-}
-
-void libpdReadFilesLoop(){
-    while(!gShouldStop){
-    	// check for modified sockets/file descriptors
-    	// (libpd would normally do this every block WITHIN the audio thread)
-    	// not sure if this is thread-safe at the moment
-    	libpd_sys_microsleep(0);
-        usleep(1000);
-    }
-}
-
-#define PARSE_MIDI
-static AuxiliaryTask libpdReadFilesTask;
-static Midi midi;
-static DigitalChannelManager dcm;
-//UdpServer udpServer;
-
-void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){
-	libpd_float((char*)receiverName, (float)state);
-//	rt_printf("%s: %d\n", (char*)receiverName, state);
-}
-
-#define LIBPD_DIGITAL_OFFSET 11 // digitals are preceded by 2 audio and 8 analogs (even if using a different number of analogs)
-
-void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){
-	if(strcmp(source, "bela_setDigital") == 0){
-		// symbol is the direction, argv[0] is the channel, argv[1] (optional)
-		// is signal("sig" or "~") or message("message", default) rate
-		bool isMessageRate = true; // defaults to message rate
-		bool direction = 0; // initialize it just to avoid the compiler's warning
-		bool disable = false;
-		if(strcmp(symbol, "in") == 0){
-			direction = INPUT;
-		} else if(strcmp(symbol, "out") == 0){
-			direction = OUTPUT;
-		} else if(strcmp(symbol, "disable") == 0){
-			disable = true;
-		} else {
-			return;
-		}
-		if(argc == 0){
-			return;
-		} else if (libpd_is_float(&argv[0]) == false){
-			return;
-		}
-		int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET;
-		if(disable == true){
-			dcm.unmanage(channel);
-			return;
-		}
-		if(argc >= 2){
-			t_atom* a = &argv[1];
-			if(libpd_is_symbol(a)){
-				char *s = libpd_get_symbol(a);
-				if(strcmp(s, "~") == 0  || strncmp(s, "sig", 3) == 0){
-					isMessageRate = false;
-				}
-			}
-		}
-		dcm.manage(channel, direction, isMessageRate);
-	}
-}
-
-void Bela_floatHook(const char *source, float value){
-	// let's make this as optimized as possible for built-in digital Out parsing
-	// the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between 11 and 26
-	static int prefixLength = 15; // strlen("bela_digitalOut")
-	if(strncmp(source, "bela_digitalOut", prefixLength)==0){
-		if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2)
-			if(source[prefixLength + 1] != 0){
-				// quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi
-				int receiver = ((source[prefixLength] - 48) * 10);
-				receiver += (source[prefixLength+1] - 48);
-				unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
-				if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
-					dcm.setValue(channel, value);
-				}
-			}
-		}
-	}
-}
-
-char receiverNames[16][21]={
-	{"bela_digitalIn11"},{"bela_digitalIn12"},{"bela_digitalIn13"},{"bela_digitalIn14"},{"bela_digitalIn15"},
-	{"bela_digitalIn16"},{"bela_digitalIn17"},{"bela_digitalIn18"},{"bela_digitalIn19"},{"bela_digitalIn20"},
-	{"bela_digitalIn21"},{"bela_digitalIn22"},{"bela_digitalIn23"},{"bela_digitalIn24"},{"bela_digitalIn25"},
-	{"bela_digitalIn26"}
-};
-
-static unsigned int analogChannelsInUse;
-static unsigned int gLibpdBlockSize;
-static unsigned int gChannelsInUse = 26;
-
-bool setup(BelaContext *context, void *userData)
-{
-	dcm.setCallback(sendDigitalMessage);
-	analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels - context->digitalChannels);
-	if(context->digitalChannels > 0){
-		for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){
-			dcm.setCallbackArgument(ch, receiverNames[ch]);
-		}
-	}
-	midi.readFrom(0);
-	midi.writeTo(0);
-#ifdef PARSE_MIDI
-	midi.enableParser(true);
-#else
-	midi.enableParser(false);
-#endif /* PARSE_MIDI */
-//	gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse);
-//	udpServer.bindToPort(1234);
-
-	gLibpdBlockSize = libpd_blocksize();
-	// check that we are not running with a blocksize smaller than gLibPdBlockSize
-	// it would still work, but the load would be executed unevenly between calls to render
-	if(context->audioFrames < gLibpdBlockSize){
-		fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize);
-		return false;
-	}
-	// set hooks before calling libpd_init
-	libpd_set_printhook(Bela_printHook);
-	libpd_set_floathook(Bela_floatHook);
-	libpd_set_messagehook(Bela_messageHook);
-	libpd_set_noteonhook(pdnoteon);
-	//TODO: add hooks for other midi events and generate MIDI output appropriately
-	libpd_init();
-	//TODO: ideally, we would analyse the ASCII of the patch file and find out which in/outs to use
-	libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate);
-	gInBuf = libpd_get_sys_soundin();
-	gOutBuf = libpd_get_sys_soundout();
-
-	libpd_start_message(1); // one entry in list
-	libpd_add_float(1.0f);
-	libpd_finish_message("pd", "dsp");
-
-	gBufLength = max(gLibpdBlockSize, context->audioFrames);
-
-
-	// bind your receivers here
-	libpd_bind("bela_digitalOut11");
-	libpd_bind("bela_digitalOut12");
-	libpd_bind("bela_digitalOut13");
-	libpd_bind("bela_digitalOut14");
-	libpd_bind("bela_digitalOut15");
-	libpd_bind("bela_digitalOut16");
-	libpd_bind("bela_digitalOut17");
-	libpd_bind("bela_digitalOut18");
-	libpd_bind("bela_digitalOut19");
-	libpd_bind("bela_digitalOut20");
-	libpd_bind("bela_digitalOut21");
-	libpd_bind("bela_digitalOut22");
-	libpd_bind("bela_digitalOut23");
-	libpd_bind("bela_digitalOut24");
-	libpd_bind("bela_digitalOut25");
-	libpd_bind("bela_digitalOut26");
-	libpd_bind("bela_setDigital");
-
-	char file[] = "_main.pd";
-	char folder[] = "./";
-	// open patch       [; pd open file folder(
-	libpd_openfile(file, folder);
-	libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles");
-	Bela_scheduleAuxiliaryTask(libpdReadFilesTask);
-
-
-	return true;
-}
-
-// render() is called regularly at the highest priority by the audio engine.
-// Input and output are given from the audio hardware and the other
-// ADCs and DACs (if available). If only audio is available, numMatrixFrames
-// will be 0.
-
-void render(BelaContext *context, void *userData)
-{
-	int num;
-	// the safest thread-safe option to handle MIDI input is to process the MIDI buffer
-	// from the audio thread.
-#ifdef PARSE_MIDI
-	while((num = midi.getParser()->numAvailableMessages()) > 0){
-		static MidiChannelMessage message;
-		message = midi.getParser()->getNextChannelMessage();
-		//message.prettyPrint(); // use this to print beautified message (channel, data bytes)
-		switch(message.getType()){
-			case kmmNoteOn:
-			{
-				int noteNumber = message.getDataByte(0);
-				int velocity = message.getDataByte(1);
-				int channel = message.getChannel();
-				libpd_noteon(channel, noteNumber, velocity);
-				break;
-			}
-			case kmmNoteOff:
-			{
-				/* PureData does not seem to handle noteoff messages as per the MIDI specs,
-				 * so that the noteoff velocity is ignored. Here we convert them to noteon
-				 * with a velocity of 0.
-				 */
-				int noteNumber = message.getDataByte(0);
-//				int velocity = message.getDataByte(1); // would be ignored by Pd
-				int channel = message.getChannel();
-				libpd_noteon(channel, noteNumber, 0);
-				break;
-			}
-			case kmmControlChange:
-			{
-				int channel = message.getChannel();
-				int controller = message.getDataByte(0);
-				int value = message.getDataByte(1);
-				libpd_controlchange(channel, controller, value);
-				break;
-			}
-			case kmmProgramChange:
-			{
-				int channel = message.getChannel();
-				int program = message.getDataByte(0);
-				libpd_programchange(channel, program);
-				break;
-			}
-			case kmmPolyphonicKeyPressure:
-			{
-				int channel = message.getChannel();
-				int pitch = message.getDataByte(0);
-				int value = message.getDataByte(1);
-				libpd_polyaftertouch(channel, pitch, value);
-				break;
-			}
-			case kmmChannelPressure:
-			{
-				int channel = message.getChannel();
-				int value = message.getDataByte(0);
-				libpd_aftertouch(channel, value);
-				break;
-			}
-			case kmmPitchBend:
-			{
-				int channel = message.getChannel();
-				int value =  (message.getDataByte(1) << 7)| message.getDataByte(0);
-				libpd_pitchbend(channel, value);
-				break;
-			}
-			case kmmNone:
-			case kmmAny:
-				break;
-		}
-	}
-#else
-	int input;
-	while((input = midi.getInput()) >= 0){
-		libpd_midibyte(0, input);
-	}
-#endif /* PARSE_MIDI */
-
-	static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize;
-
-	// these are reset at every audio callback. Persistence across audio callbacks
-	// is handled by the core code.
-//	setDataOut = 0;
-//	clearDataOut = 0;
-
-	for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick){
-		unsigned int audioFrameBase = gLibpdBlockSize * tick;
-		unsigned int j;
-		unsigned int k;
-		float* p0;
-		float* p1;
-		for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
-				*p1 = audioRead(context, audioFrameBase + j, k);
-			}
-		}
-		// then analogs
-		// this loop resamples by ZOH, as needed, using m
-		if(context->analogChannels == 8 ){ //hold the value for two frames
-			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					unsigned int analogFrame = (audioFrameBase + j) / 2;
-					*p1 = analogRead(context, analogFrame, k);
-				}
-			}
-		} else if(context->analogChannels == 4){ //write every frame
-			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					unsigned int analogFrame = audioFrameBase + j;
-					*p1 = analogRead(context, analogFrame, k);
-				}
-			}
-		} else if(context->analogChannels == 2){ //drop every other frame
-			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					unsigned int analogFrame = (audioFrameBase + j) * 2;
-					*p1 = analogRead(context, analogFrame, k);
-				}
-			}
-		}
-
-		//then digital
-		// note: in multiple places below we assume that the number of digitals is same as number of audio
-		// digital in at message-rate
-		dcm.processInput(&context->digital[audioFrameBase], gLibpdBlockSize);
-
-		// digital in at signal-rate
-		for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-			unsigned int digitalFrame = audioFrameBase + j;
-			for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8);
-					k < 16; ++k, p1 += gLibpdBlockSize) {
-				if(dcm.isSignalRate(k) && dcm.isInput(k)){ // only process input channels that are handled at signal rate
-					*p1 = digitalRead(context, digitalFrame, k);
-				}
-			}
-		}
-
-		libpd_process_sys(); // process the block
-
-		//digital out
-		// digital out at signal-rate
-		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
-			unsigned int digitalFrame = (audioFrameBase + j);
-			for (k = 0, p1 = p0  + gLibpdBlockSize * (context->audioChannels + 8);
-					k < context->digitalChannels; k++, p1 += gLibpdBlockSize) {
-				if(dcm.isSignalRate(k) && dcm.isOutput(k)){ // only process output channels that are handled at signal rate
-					digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5);
-				}
-			}
-		}
-
-		// digital out at message-rate
-		dcm.processOutput(&context->digital[audioFrameBase], gLibpdBlockSize);
-
-		//audio
-		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
-			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
-				audioWrite(context, audioFrameBase + j, k, *p1);
-			}
-		}
-
-		//analog
-		if(context->analogChannels == 8){
-			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames
-				unsigned int analogFrame = (audioFrameBase + j) / 2;
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					analogWriteOnce(context, analogFrame, k, *p1);
-				}
-			}
-		} else if(context->analogChannels == 4){ //write every frame
-			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
-				unsigned int analogFrame = (audioFrameBase + j);
-				for (k = 0, p1 = p0  + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					analogWriteOnce(context, analogFrame, k, *p1);
-				}
-			}
-		} else if(context->analogChannels == 2){ //write every frame twice
-			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
-					int analogFrame = audioFrameBase * 2 + j * 2;
-					analogWriteOnce(context, analogFrame, k, *p1);
-					analogWriteOnce(context, analogFrame + 1, k, *p1);
-				}
-			}
-		}
-	}
-}
-
-// cleanup() is called once at the end, after the audio has stopped.
-// Release any resources that were allocated in setup().
-
-void cleanup(BelaContext *context, void *userData)
-{
-}
--- a/examples/basic_libpd/s_stuff.h	Mon Jun 20 16:09:00 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,411 +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.  */
-
-/* Audio and MIDI I/O, and other scheduling and system stuff. */
-
-/* NOTE: this file describes Pd implementation details which may change
-in future releases.  The public (stable) API is in m_pd.h. */  
-
-/* in s_path.c */
-
-typedef struct _namelist    /* element in a linked list of stored strings */
-{
-    struct _namelist *nl_next;  /* next in list */
-    char *nl_string;            /* the string */
-} t_namelist;
-
-t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup);
-t_namelist *namelist_append_files(t_namelist *listwas, const char *s);
-void namelist_free(t_namelist *listwas);
-char *namelist_get(t_namelist *namelist, int n);
-void sys_setextrapath(const char *p);
-extern int sys_usestdpath;
-extern t_namelist *sys_externlist;
-extern t_namelist *sys_searchpath;
-extern t_namelist *sys_helppath;
-int sys_open_absolute(const char *name, const char* ext,
-    char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp);
-int sys_trytoopenone(const char *dir, const char *name, const char* ext,
-    char *dirresult, char **nameresult, unsigned int size, int bin);
-t_symbol *sys_decodedialog(t_symbol *s);
-
-/* s_file.c */
-
-void sys_loadpreferences( void);
-void sys_savepreferences( void);
-extern int sys_defeatrt;
-extern t_symbol *sys_flags;
-
-/* s_main.c */
-extern int sys_debuglevel;
-extern int sys_verbose;
-extern int sys_noloadbang;
-extern int sys_nogui;
-extern char *sys_guicmd;
-
-EXTERN int sys_nearestfontsize(int fontsize);
-EXTERN int sys_hostfontsize(int fontsize);
-
-extern int sys_defaultfont;
-EXTERN t_symbol *sys_libdir;    /* library directory for auxilliary files */
-extern t_symbol *sys_guidir;    /* directory holding pd_gui, u_pdsend, etc */
-
-/* s_loader.c */
-
-typedef int (*loader_t)(t_canvas *canvas, char *classname); /* callback type */
-EXTERN int sys_load_lib(t_canvas *canvas, char *filename);
-EXTERN void sys_register_loader(loader_t loader);
-
-/* s_audio.c */
-
-#define SENDDACS_NO 0           /* return values for sys_send_dacs() */
-#define SENDDACS_YES 1 
-#define SENDDACS_SLEPT 2
-
-#define DEFDACBLKSIZE 8
-extern int sys_schedblocksize;  /* audio block size for scheduler */
-extern int sys_hipriority;      /* real-time flag, true if priority boosted */
-EXTERN t_sample *sys_soundout;
-EXTERN t_sample *sys_soundin;
-extern int sys_inchannels;
-extern int sys_outchannels;
-extern int sys_advance_samples; /* scheduler advance in samples */
-extern int sys_blocksize;       /* audio I/O block size in sample frames */
-extern t_float sys_dacsr;
-extern int sys_schedadvance;
-extern int sys_sleepgrain;
-EXTERN void sys_set_audio_settings(int naudioindev, int *audioindev,
-    int nchindev, int *chindev,
-    int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
-    int srate, int advance, int callback, int blocksize);
-/* the same as above, but reopens the audio subsystem if needed */
-EXTERN void sys_set_audio_settings_reopen(int naudioindev, int *audioindev,
-    int nchindev, int *chindev,
-    int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
-    int srate, int advance, int callback, int blocksize);
-EXTERN void sys_reopen_audio( void);
-EXTERN void sys_close_audio(void);
-    /* return true if the interface prefers always being open (ala jack) : */
-EXTERN int audio_shouldkeepopen( void);
-EXTERN int audio_isopen( void);     /* true if audio interface is open */
-EXTERN int sys_audiodevnametonumber(int output, const char *name);
-EXTERN void sys_audiodevnumbertoname(int output, int devno, char *name,
-    int namesize);
-
-int sys_send_dacs(void);
-void sys_reportidle(void);
-void sys_set_priority(int higher);
-void sys_audiobuf(int nbufs);
-void sys_getmeters(t_sample *inmax, t_sample *outmax);
-void sys_listdevs(void);
-void sys_setblocksize(int n);
-
-EXTERN void sys_get_audio_devs(char *indevlist, int *nindevs,
-                          char *outdevlist, int *noutdevs, int *canmulti, int *cancallback, 
-                          int maxndev, int devdescsize);
-EXTERN void sys_get_audio_apis(char *buf);
-
-/* s_midi.c */
-#define MAXMIDIINDEV 16         /* max. number of input ports */
-#define MAXMIDIOUTDEV 16        /* max. number of output ports */
-extern int sys_midiapi;
-extern int sys_nmidiin;
-extern int sys_nmidiout;
-extern int sys_midiindevlist[];
-extern int sys_midioutdevlist[];
-
-EXTERN void sys_open_midi(int nmidiin, int *midiinvec,
-    int nmidiout, int *midioutvec, int enable);
-
-EXTERN void sys_get_midi_apis(char *buf);
-EXTERN void sys_get_midi_devs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, 
-   int maxndev, int devdescsize);
-EXTERN void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
-    int *pnmidioutdev, int *pmidioutdev);
-EXTERN int sys_mididevnametonumber(int output, const char *name);
-EXTERN void sys_mididevnumbertoname(int output, int devno, char *name,
-    int namesize);
-
-EXTERN void sys_reopen_midi( void);
-EXTERN void sys_close_midi( void);
-EXTERN void sys_putmidimess(int portno, int a, int b, int c);
-EXTERN void sys_putmidibyte(int portno, int a);
-EXTERN void sys_poll_midi(void);
-EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
-EXTERN void sys_midibytein(int portno, int byte);
-
-    /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
-void midi_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
-void sys_do_open_midi(int nmidiindev, int *midiindev,
-    int nmidioutdev, int *midioutdev);
-
-#ifdef USEAPI_ALSA
-EXTERN void sys_alsa_putmidimess(int portno, int a, int b, int c);
-EXTERN void sys_alsa_putmidibyte(int portno, int a);
-EXTERN void sys_alsa_poll_midi(void);
-EXTERN void sys_alsa_setmiditimediff(double inbuftime, double outbuftime);
-EXTERN void sys_alsa_midibytein(int portno, int byte);
-EXTERN void sys_alsa_close_midi( void);
-
-
-    /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
-void midi_alsa_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
-void sys_alsa_do_open_midi(int nmidiindev, int *midiindev,
-    int nmidioutdev, int *midioutdev);
-#endif
-
-/* m_sched.c */
-EXTERN void sys_log_error(int type);
-#define ERR_NOTHING 0
-#define ERR_ADCSLEPT 1
-#define ERR_DACSLEPT 2
-#define ERR_RESYNC 3
-#define ERR_DATALATE 4
-
-#define SCHED_AUDIO_NONE 0
-#define SCHED_AUDIO_POLL 1 
-#define SCHED_AUDIO_CALLBACK 2
-void sched_set_using_audio(int flag);
-
-/* s_inter.c */
-
-EXTERN void sys_microsleep(int microsec);
-EXTERN void sys_init_fdpoll(void);
-
-EXTERN void sys_bail(int exitcode);
-EXTERN int sys_pollgui(void);
-
-EXTERN_STRUCT _socketreceiver;
-#define t_socketreceiver struct _socketreceiver
-
-typedef void (*t_socketnotifier)(void *x, int n);
-typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
-
-EXTERN t_socketreceiver *socketreceiver_new(void *owner,
-    t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
-EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
-EXTERN void sys_sockerror(char *s);
-EXTERN void sys_closesocket(int fd);
-
-typedef void (*t_fdpollfn)(void *ptr, int fd);
-EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
-EXTERN void sys_rmpollfn(int fd);
-#if defined(USEAPI_OSS) || defined(USEAPI_ALSA)
-void sys_setalarm(int microsec);
-#endif
-
-#define API_NONE 0
-#define API_ALSA 1
-#define API_OSS 2
-#define API_MMIO 3
-#define API_PORTAUDIO 4
-#define API_JACK 5
-#define API_SGI 6           /* gone */
-#define API_AUDIOUNIT 7
-#define API_ESD 8           /* no idea what this was, probably gone now */
-#define API_DUMMY 9
-
-    /* figure out which API should be the default.  The one we judge most
-    likely to offer a working device takes precedence so that if you
-    start up Pd for the first time there's a reasonable chance you'll have
-    sound.  (You'd think portaudio would be best but it seems to default
-    to jack on linux, and and on Windows we only use it for ASIO). 
-    If nobody shows up, define DUMMY and make it the default.*/
-#if defined(USEAPI_MMIO)
-# define API_DEFAULT API_MMIO
-# define API_DEFSTRING "MMIO"
-#elif defined(USEAPI_ALSA)
-# define API_DEFAULT API_ALSA
-# define API_DEFSTRING "ALSA"
-#elif defined(USEAPI_OSS)
-# define API_DEFAULT API_OSS
-# define API_DEFSTRING "OSS"
-#elif defined(USEAPI_AUDIOUNIT)
-# define API_DEFAULT API_AUDIOUNIT
-# define API_DEFSTRING "AudioUnit"
-#elif defined(USEAPI_ESD)
-# define API_DEFAULT API_ESD
-# define API_DEFSTRING "ESD (?)"
-#elif defined(USEAPI_PORTAUDIO)
-# define API_DEFAULT API_PORTAUDIO
-# define API_DEFSTRING "portaudio"
-#elif defined(USEAPI_JACK)
-# define API_DEFAULT API_JACK
-# define API_DEFSTRING "Jack audio connection kit"
-#else 
-# ifndef USEAPI_DUMMY   /* we need at least one so bring in the dummy */
-# define USEAPI_DUMMY
-# endif /* USEAPI_DUMMY */
-# define API_DEFAULT API_DUMMY
-# define API_DEFSTRING "dummy audio"
-#endif 
-
-#define DEFAULTAUDIODEV 0
-
-#define MAXAUDIOINDEV 4
-#define MAXAUDIOOUTDEV 4
-
-#define DEFMIDIDEV 0
-
-#define DEFAULTSRATE 44100
-#ifdef _WIN32
-#define DEFAULTADVANCE 80
-#else
-#ifdef __APPLE__
-#define DEFAULTADVANCE 5    /* this is in addition to their own delay */
-#else
-#define DEFAULTADVANCE 25
-#endif
-#endif
-
-typedef void (*t_audiocallback)(void);
-
-int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
-    t_sample *soundout, int framesperbuf, int nbuffers,
-    int indeviceno, int outdeviceno, t_audiocallback callback);
-void pa_close_audio(void);
-int pa_send_dacs(void);
-void sys_reportidle(void);
-void pa_listdevs(void);
-void pa_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int oss_open_audio(int naudioindev, int *audioindev, int nchindev,
-    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
-    int *choutdev, int rate, int blocksize);
-void oss_close_audio(void);
-int oss_send_dacs(void);
-void oss_reportidle(void);
-void oss_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
-    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
-    int *choutdev, int rate, int blocksize);
-void alsa_close_audio(void);
-int alsa_send_dacs(void);
-void alsa_reportidle(void);
-void alsa_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int jack_open_audio(int wantinchans, int wantoutchans, int srate,
-    t_audiocallback callback);
-void jack_close_audio(void);
-int jack_send_dacs(void);
-void jack_reportidle(void);
-void jack_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-void jack_listdevs(void);
-
-int mmio_open_audio(int naudioindev, int *audioindev,
-    int nchindev, int *chindev, int naudiooutdev, int *audiooutdev,
-    int nchoutdev, int *choutdev, int rate, int blocksize);
-void mmio_close_audio( void);
-void mmio_reportidle(void);
-int mmio_send_dacs(void);
-void mmio_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int audiounit_open_audio(int naudioindev, int *audioindev, int nchindev,
-    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
-    int *choutdev, int rate);
-void audiounit_close_audio(void);
-int audiounit_send_dacs(void);
-void audiounit_listdevs(void);
-void audiounit_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int esd_open_audio(int naudioindev, int *audioindev, int nchindev,
-    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
-    int *choutdev, int rate);
-void esd_close_audio(void);
-int esd_send_dacs(void);
-void esd_listdevs(void);
-void esd_getdevs(char *indevlist, int *nindevs,
-    char *outdevlist, int *noutdevs, int *canmulti, 
-        int maxndev, int devdescsize);
-
-int dummy_open_audio(int nin, int nout, int sr);
-int dummy_close_audio( void);
-int dummy_send_dacs( void);
-void dummy_getdevs(char *indevlist, int *nindevs, char *outdevlist,
-    int *noutdevs, int *canmulti, int maxndev, int devdescsize);
-void dummy_listdevs( void);
-
-void sys_listmididevs(void);
-EXTERN void sys_set_midi_api(int whichapi);
-EXTERN void sys_set_audio_api(int whichapi);
-EXTERN int sys_audioapi;
-EXTERN void sys_set_audio_state(int onoff);
-
-/* API dependent audio flags and settings */
-void oss_set32bit( void);
-void linux_alsa_devname(char *devname);
-
-EXTERN void sys_get_audio_params(
-    int *pnaudioindev, int *paudioindev, int *chindev,
-    int *pnaudiooutdev, int *paudiooutdev, int *choutdev,
-    int *prate, int *padvance, int *callback, int *blocksize);
-void sys_save_audio_params(
-    int naudioindev, int *audioindev, int *chindev,
-    int naudiooutdev, int *audiooutdev, int *choutdev,
-    int rate, int advance, int callback, int blocksize);
-
-/* s_file.c */
-
-typedef void (*t_printhook)(const char *s);
-extern t_printhook sys_printhook;  /* set this to override printing */
-extern int sys_printtostderr;
-
-/* jsarlo { */
-
-EXTERN double sys_time;
-EXTERN double sys_time_per_dsp_tick;
-EXTERN int sys_externalschedlib;
-
-EXTERN t_sample* get_sys_soundout(void ) ;
-EXTERN t_sample* get_sys_soundin(void ) ;
-EXTERN int* get_sys_main_advance(void ) ;
-EXTERN double* get_sys_time_per_dsp_tick(void ) ;
-EXTERN int* get_sys_schedblocksize(void ) ;
-EXTERN double* get_sys_time(void ) ;
-EXTERN t_float* get_sys_dacsr(void ) ;
-EXTERN int* get_sys_sleepgrain(void ) ;
-EXTERN int* get_sys_schedadvance(void ) ;
-
-EXTERN void sys_clearhist(void );
-EXTERN void sys_initmidiqueue(void );
-EXTERN int sys_addhist(int phase);
-EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
-EXTERN void sched_tick( void);
-EXTERN void sys_pollmidiqueue(void );
-EXTERN int sys_pollgui(void );
-EXTERN void sys_setchsr(int chin, int chout, int sr);
-
-EXTERN void inmidi_realtimein(int portno, int cmd);
-EXTERN void inmidi_byte(int portno, int byte);
-EXTERN void inmidi_sysex(int portno, int byte);
-EXTERN void inmidi_noteon(int portno, int channel, int pitch, int velo);
-EXTERN void inmidi_controlchange(int portno,
-                                 int channel,
-                                 int ctlnumber,
-                                 int value);
-EXTERN void inmidi_programchange(int portno, int channel, int value);
-EXTERN void inmidi_pitchbend(int portno, int channel, int value);
-EXTERN void inmidi_aftertouch(int portno, int channel, int value);
-EXTERN void inmidi_polyaftertouch(int portno,
-                                  int channel,
-                                  int pitch,
-                                  int value);
-/* } jsarlo */
-extern t_widgetbehavior text_widgetbehavior;
--- a/examples/basic_libpd/z_libpd.h	Mon Jun 20 16:09:00 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2010 Peter Brinkmann (peter.brinkmann@gmail.com)
- *
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
- *
- * See https://github.com/libpd/libpd/wiki for documentation
- *
- */
-
-#ifndef __Z_LIBPD_H__
-#define __Z_LIBPD_H__
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "m_pd.h"
-
-EXTERN int libpd_init(void);
-EXTERN void libpd_clear_search_path(void);
-EXTERN void libpd_add_to_search_path(const char *sym);
-
-EXTERN void *libpd_openfile(const char *basename, const char *dirname);
-EXTERN void libpd_closefile(void *p);
-EXTERN int libpd_getdollarzero(void *p);
-
-EXTERN int libpd_blocksize(void);
-EXTERN int libpd_init_audio(int inChans, int outChans, int sampleRate);
-EXTERN int libpd_process_raw(const float *inBuffer, float *outBuffer);
-EXTERN t_sample* libpd_get_sys_soundin();
-EXTERN t_sample* libpd_get_sys_soundout();
-EXTERN int libpd_process_sys();
-EXTERN int libpd_process_short(const int ticks,
-    const short *inBuffer, short *outBuffer);
-EXTERN int libpd_process_float(int ticks,
-    const float *inBuffer, float *outBuffer);
-EXTERN int libpd_process_double(int ticks,
-    const double *inBuffer, double *outBuffer);
-
-EXTERN int libpd_arraysize(const char *name);
-// The parameters of the next two functions are inspired by memcpy.
-EXTERN int libpd_read_array(float *dest, const char *src, int offset, int n);
-EXTERN int libpd_write_array(const char *dest, int offset, float *src, int n);
-
-EXTERN int libpd_bang(const char *recv);
-EXTERN int libpd_float(const char *recv, float x);
-EXTERN int libpd_symbol(const char *recv, const char *sym);
-
-EXTERN void libpd_set_float(t_atom *v, float x);
-EXTERN void libpd_set_symbol(t_atom *v, const char *sym);
-EXTERN int libpd_list(const char *recv, int argc, t_atom *argv);
-EXTERN int libpd_message(const char *recv, const char *msg, int argc, t_atom *argv);
-
-EXTERN int libpd_start_message(int max_length);
-EXTERN void libpd_add_float(float x);
-EXTERN void libpd_add_symbol(const char *sym);
-EXTERN int libpd_finish_list(const char *recv);
-EXTERN int libpd_finish_message(const char *recv, const char *msg);
-
-EXTERN int libpd_exists(const char *sym);
-EXTERN void *libpd_bind(const char *sym);
-EXTERN void libpd_unbind(void *p);
-
-EXTERN int libpd_is_float(t_atom *a);
-EXTERN int libpd_is_symbol(t_atom *a);
-EXTERN float libpd_get_float(t_atom *a);
-EXTERN char *libpd_get_symbol(t_atom *a);
-EXTERN t_atom *libpd_next_atom(t_atom *a);
-
-typedef void (*t_libpd_printhook)(const char *recv);
-typedef void (*t_libpd_banghook)(const char *recv);
-typedef void (*t_libpd_floathook)(const char *recv, float x);
-typedef void (*t_libpd_symbolhook)(const char *recv, const char *sym);
-typedef void (*t_libpd_listhook)(const char *recv, int argc, t_atom *argv);
-typedef void (*t_libpd_messagehook)(const char *recv, const char *msg,
-    int argc, t_atom *argv);
-
-EXTERN void libpd_set_printhook(const t_libpd_printhook hook);
-EXTERN void libpd_set_banghook(const t_libpd_banghook hook);
-EXTERN void libpd_set_floathook(const t_libpd_floathook hook);
-EXTERN void libpd_set_symbolhook(const t_libpd_symbolhook hook);
-EXTERN void libpd_set_listhook(const t_libpd_listhook hook);
-EXTERN void libpd_set_messagehook(const t_libpd_messagehook hook);
-
-EXTERN int libpd_noteon(int channel, int pitch, int velocity);
-EXTERN int libpd_controlchange(int channel, int controller, int value);
-EXTERN int libpd_programchange(int channel, int value);
-EXTERN int libpd_pitchbend(int channel, int value);
-EXTERN int libpd_aftertouch(int channel, int value);
-EXTERN int libpd_polyaftertouch(int channel, int pitch, int value);
-EXTERN int libpd_midibyte(int port, int byte);
-EXTERN int libpd_sysex(int port, int byte);
-EXTERN int libpd_sysrealtime(int port, int byte);
-
-typedef void (*t_libpd_noteonhook)(int channel, int pitch, int velocity);
-typedef void (*t_libpd_controlchangehook)(int channel,
-    int controller, int value);
-typedef void (*t_libpd_programchangehook)(int channel, int value);
-typedef void (*t_libpd_pitchbendhook)(int channel, int value);
-typedef void (*t_libpd_aftertouchhook)(int channel, int value);
-typedef void (*t_libpd_polyaftertouchhook)(int channel, int pitch, int value);
-typedef void (*t_libpd_midibytehook)(int port, int byte);
-
-EXTERN void libpd_set_noteonhook(const t_libpd_noteonhook hook);
-EXTERN void libpd_set_controlchangehook(const t_libpd_controlchangehook hook);
-EXTERN void libpd_set_programchangehook(const t_libpd_programchangehook hook);
-EXTERN void libpd_set_pitchbendhook(const t_libpd_pitchbendhook hook);
-EXTERN void libpd_set_aftertouchhook(const t_libpd_aftertouchhook hook);
-EXTERN void libpd_set_polyaftertouchhook(const t_libpd_polyaftertouchhook hook);
-EXTERN void libpd_set_midibytehook(const t_libpd_midibytehook hook);
-EXTERN void libpd_sys_microsleep(int sleep);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpd/m_pd.h	Mon Jun 20 16:57:35 2016 +0100
@@ -0,0 +1,770 @@
+/* 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.  */
+
+#ifndef __m_pd_h_
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+extern "C" {
+#endif
+
+#define PD_MAJOR_VERSION 0
+#define PD_MINOR_VERSION 46
+#define PD_BUGFIX_VERSION 6
+#define PD_TEST_VERSION ""
+extern int pd_compatibilitylevel;   /* e.g., 43 for pd 0.43 compatibility */
+
+/* old name for "MSW" flag -- we have to take it for the sake of many old
+"nmakefiles" for externs, which will define NT and not MSW */
+#if defined(NT) && !defined(MSW)
+#define MSW
+#endif
+
+/* These pragmas are only used for MSVC, not MinGW or Cygwin <hans@at.or.at> */
+#ifdef _MSC_VER
+/* #pragma warning( disable : 4091 ) */
+#pragma warning( disable : 4305 )  /* uncast const double to float */
+#pragma warning( disable : 4244 )  /* uncast float/int conversion etc. */
+#pragma warning( disable : 4101 )  /* unused automatic variables */
+#endif /* _MSC_VER */
+
+    /* the external storage class is "extern" in UNIX; in MSW it's ugly. */
+#ifdef _WIN32
+#ifdef PD_INTERNAL
+#define EXTERN __declspec(dllexport) extern
+#else
+#define EXTERN __declspec(dllimport) extern
+#endif /* PD_INTERNAL */
+#else
+#define EXTERN extern
+#endif /* _WIN32 */
+
+    /* and depending on the compiler, hidden data structures are
+    declared differently: */
+#if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ )
+#define EXTERN_STRUCT struct
+#else
+#define EXTERN_STRUCT extern struct
+#endif
+
+/* Define some attributes, specific to the compiler */
+#if defined(__GNUC__)
+#define ATTRIBUTE_FORMAT_PRINTF(a, b) __attribute__ ((format (printf, a, b)))
+#else
+#define ATTRIBUTE_FORMAT_PRINTF(a, b)
+#endif
+
+#if !defined(_SIZE_T) && !defined(_SIZE_T_)
+#include <stddef.h>     /* just for size_t -- how lame! */
+#endif
+
+/* Microsoft Visual Studio is not C99, it does not provide stdint.h */
+#ifdef _MSC_VER
+typedef signed __int8     int8_t;
+typedef signed __int16    int16_t;
+typedef signed __int32    int32_t;
+typedef signed __int64    int64_t;
+typedef unsigned __int8   uint8_t;
+typedef unsigned __int16  uint16_t;
+typedef unsigned __int32  uint32_t;
+typedef unsigned __int64  uint64_t;
+#else
+# include <stdint.h>
+#endif
+
+/* for FILE, needed by sys_fopen() and sys_fclose() only */
+#include <stdio.h>
+
+#define MAXPDSTRING 1000        /* use this for anything you want */
+#define MAXPDARG 5              /* max number of args we can typecheck today */
+
+/* signed and unsigned integer types the size of a pointer:  */
+#if !defined(PD_LONGINTTYPE)
+#define PD_LONGINTTYPE long
+#endif
+
+#if !defined(PD_FLOATSIZE)
+  /* normally, our floats (t_float, t_sample,...) are 32bit */
+# define PD_FLOATSIZE 32
+#endif
+
+#if PD_FLOATSIZE == 32
+# define PD_FLOATTYPE float
+/* an unsigned int of the same size as FLOATTYPE: */
+# define PD_FLOATUINTTYPE unsigned int
+
+#elif PD_FLOATSIZE == 64
+# define PD_FLOATTYPE double
+# define PD_FLOATUINTTYPE unsigned long
+#else
+# error invalid FLOATSIZE: must be 32 or 64
+#endif
+
+typedef PD_LONGINTTYPE t_int;       /* pointer-size integer */
+typedef PD_FLOATTYPE t_float;       /* a float type at most the same size */
+typedef PD_FLOATTYPE t_floatarg;    /* float type for function calls */
+
+typedef struct _symbol
+{
+    char *s_name;
+    struct _class **s_thing;
+    struct _symbol *s_next;
+} t_symbol;
+
+EXTERN_STRUCT _array;
+#define t_array struct _array       /* g_canvas.h */
+
+/* pointers to glist and array elements go through a "stub" which sticks
+around after the glist or array is freed.  The stub itself is deleted when
+both the glist/array is gone and the refcount is zero, ensuring that no
+gpointers are pointing here. */
+
+#define GP_NONE 0       /* the stub points nowhere (has been cut off) */
+#define GP_GLIST 1      /* the stub points to a glist element */
+#define GP_ARRAY 2      /* ... or array */
+
+typedef struct _gstub
+{
+    union
+    {
+        struct _glist *gs_glist;    /* glist we're in */
+        struct _array *gs_array;    /* array we're in */
+    } gs_un;
+    int gs_which;                   /* GP_GLIST/GP_ARRAY */
+    int gs_refcount;                /* number of gpointers pointing here */
+} t_gstub;
+
+typedef struct _gpointer           /* pointer to a gobj in a glist */
+{
+    union
+    {   
+        struct _scalar *gp_scalar;  /* scalar we're in (if glist) */
+        union word *gp_w;           /* raw data (if array) */
+    } gp_un;
+    int gp_valid;                   /* number which must match gpointee */
+    t_gstub *gp_stub;               /* stub which points to glist/array */
+} t_gpointer;
+
+typedef union word
+{
+    t_float w_float;
+    t_symbol *w_symbol;
+    t_gpointer *w_gpointer;
+    t_array *w_array;
+    struct _binbuf *w_binbuf;
+    int w_index;
+} t_word;
+
+typedef enum
+{
+    A_NULL,
+    A_FLOAT,
+    A_SYMBOL,
+    A_POINTER,
+    A_SEMI,
+    A_COMMA,
+    A_DEFFLOAT,
+    A_DEFSYM,
+    A_DOLLAR, 
+    A_DOLLSYM,
+    A_GIMME,
+    A_CANT
+}  t_atomtype;
+
+#define A_DEFSYMBOL A_DEFSYM    /* better name for this */
+
+typedef struct _atom
+{
+    t_atomtype a_type;
+    union word a_w;
+} t_atom;
+
+EXTERN_STRUCT _class;
+#define t_class struct _class
+
+EXTERN_STRUCT _outlet;
+#define t_outlet struct _outlet
+
+EXTERN_STRUCT _inlet;
+#define t_inlet struct _inlet
+
+EXTERN_STRUCT _binbuf;
+#define t_binbuf struct _binbuf
+
+EXTERN_STRUCT _clock;
+#define t_clock struct _clock
+
+EXTERN_STRUCT _outconnect;
+#define t_outconnect struct _outconnect
+
+EXTERN_STRUCT _glist;
+#define t_glist struct _glist
+#define t_canvas struct _glist  /* LATER lose this */
+
+typedef t_class *t_pd;      /* pure datum: nothing but a class pointer */
+
+typedef struct _gobj        /* a graphical object */
+{
+    t_pd g_pd;              /* pure datum header (class) */
+    struct _gobj *g_next;   /* next in list */
+} t_gobj;
+
+typedef struct _scalar      /* a graphical object holding data */
+{
+    t_gobj sc_gobj;         /* header for graphical object */
+    t_symbol *sc_template;  /* template name (LATER replace with pointer) */
+    t_word sc_vec[1];       /* indeterminate-length array of words */
+} t_scalar;
+
+typedef struct _text        /* patchable object - graphical, with text */
+{
+    t_gobj te_g;                /* header for graphical object */
+    t_binbuf *te_binbuf;        /* holder for the text */
+    t_outlet *te_outlet;        /* linked list of outlets */
+    t_inlet *te_inlet;          /* linked list of inlets */
+    short te_xpix;              /* x&y location (within the toplevel) */
+    short te_ypix;
+    short te_width;             /* requested width in chars, 0 if auto */
+    unsigned int te_type:2;     /* from defs below */
+} t_text;
+
+#define T_TEXT 0        /* just a textual comment */
+#define T_OBJECT 1      /* a MAX style patchable object */
+#define T_MESSAGE 2     /* a MAX stype message */
+#define T_ATOM 3        /* a cell to display a number or symbol */
+
+#define te_pd te_g.g_pd
+
+   /* t_object is synonym for t_text (LATER unify them) */
+
+typedef struct _text t_object;
+
+#define ob_outlet te_outlet
+#define ob_inlet te_inlet
+#define ob_binbuf te_binbuf
+#define ob_pd te_g.g_pd
+#define ob_g te_g
+
+typedef void (*t_method)(void);
+typedef void *(*t_newmethod)( void);
+
+/* in ARM 64 a varargs prototype generates a different function call sequence
+from a fixed one, so in that special case we make a more restrictive
+definition for t_gotfn.  This will break some code in the "chaos" package
+in Pd extended.  (that code will run incorrectly anyhow so why not catch it
+at compile time anyhow.) */
+#if defined(__APPLE__) && defined(__aarch64__)
+typedef void (*t_gotfn)(void *x);
+#else
+typedef void (*t_gotfn)(void *x, ...);
+#endif
+
+/* ---------------- pre-defined objects and symbols --------------*/
+EXTERN t_pd pd_objectmaker;     /* factory for creating "object" boxes */
+EXTERN t_pd pd_canvasmaker;     /* factory for creating canvases */
+EXTERN t_symbol s_pointer;
+EXTERN t_symbol s_float;
+EXTERN t_symbol s_symbol;
+EXTERN t_symbol s_bang;
+EXTERN t_symbol s_list;
+EXTERN t_symbol s_anything;
+EXTERN t_symbol s_signal;
+EXTERN t_symbol s__N;
+EXTERN t_symbol s__X;
+EXTERN t_symbol s_x;
+EXTERN t_symbol s_y;
+EXTERN t_symbol s_;
+
+/* --------- prototypes from the central message system ----------- */
+EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv);
+EXTERN t_symbol *gensym(const char *s);
+EXTERN t_gotfn getfn(t_pd *x, t_symbol *s);
+EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s);
+EXTERN void nullfn(void);
+EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...);
+
+/* the following macrose are for sending non-type-checkable mesages, i.e.,
+using function lookup but circumventing type checking on arguments.  Only
+use for internal messaging protected by A_CANT so that the message can't
+be generated at patch level. */
+#define mess0(x, s) ((*getfn((x), (s)))((x)))
+typedef void (*t_gotfn1)(void *x, void *arg1);
+#define mess1(x, s, a) ((*(t_gotfn1)getfn((x), (s)))((x), (a)))
+typedef void (*t_gotfn2)(void *x, void *arg1, void *arg2);
+#define mess2(x, s, a,b) ((*(t_gotfn2)getfn((x), (s)))((x), (a),(b)))
+typedef void (*t_gotfn3)(void *x, void *arg1, void *arg2, void *arg3);
+#define mess3(x, s, a,b,c) ((*(t_gotfn3)getfn((x), (s)))((x), (a),(b),(c)))
+typedef void (*t_gotfn4)(void *x,
+    void *arg1, void *arg2, void *arg3, void *arg4);
+#define mess4(x, s, a,b,c,d) \
+    ((*(t_gotfn4)getfn((x), (s)))((x), (a),(b),(c),(d)))
+typedef void (*t_gotfn5)(void *x,
+    void *arg1, void *arg2, void *arg3, void *arg4, void *arg5);
+#define mess5(x, s, a,b,c,d,e) \
+    ((*(t_gotfn5)getfn((x), (s)))((x), (a),(b),(c),(d),(e)))
+
+EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_pd *pd_newest(void);
+
+/* --------------- memory management -------------------- */
+EXTERN void *getbytes(size_t nbytes);
+EXTERN void *getzbytes(size_t nbytes);
+EXTERN void *copybytes(void *src, size_t nbytes);
+EXTERN void freebytes(void *x, size_t nbytes);
+EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize);
+
+/* -------------------- atoms ----------------------------- */
+
+#define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0)
+#define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0)
+#define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \
+    (atom)->a_w.w_gpointer = (gp))
+#define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f))
+#define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \
+    (atom)->a_w.w_symbol = (s))
+#define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \
+    (atom)->a_w.w_index = (n))
+#define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \
+    (atom)->a_w.w_symbol= (s))
+
+EXTERN t_float atom_getfloat(t_atom *a);
+EXTERN t_int atom_getint(t_atom *a);
+EXTERN t_symbol *atom_getsymbol(t_atom *a);
+EXTERN t_symbol *atom_gensym(t_atom *a);
+EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv);
+EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv);
+EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv);
+
+EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize);
+
+/* ------------------  binbufs --------------- */
+
+EXTERN t_binbuf *binbuf_new(void);
+EXTERN void binbuf_free(t_binbuf *x);
+EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y);
+
+EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size);
+EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
+EXTERN void binbuf_clear(t_binbuf *x);
+EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...);
+EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y);
+EXTERN void binbuf_addsemi(t_binbuf *x);
+EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_print(t_binbuf *x);
+EXTERN int binbuf_getnatom(t_binbuf *x);
+EXTERN t_atom *binbuf_getvec(t_binbuf *x);
+EXTERN int binbuf_resize(t_binbuf *x, int newsize);
+EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv);
+EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname,
+    int crflag);
+EXTERN int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas,
+    int crflag);
+EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
+    int crflag);
+EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir,
+    int crflag);
+EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
+EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
+    int tonew);
+
+/* ------------------  clocks --------------- */
+
+EXTERN t_clock *clock_new(void *owner, t_method fn);
+EXTERN void clock_set(t_clock *x, double systime);
+EXTERN void clock_delay(t_clock *x, double delaytime);
+EXTERN void clock_unset(t_clock *x);
+EXTERN void clock_setunit(t_clock *x, double timeunit, int sampflag);
+EXTERN double clock_getlogicaltime(void);
+EXTERN double clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */
+EXTERN double clock_gettimesince(double prevsystime);
+EXTERN double clock_gettimesincewithunits(double prevsystime,
+    double units, int sampflag);
+EXTERN double clock_getsystimeafter(double delaytime);
+EXTERN void clock_free(t_clock *x);
+
+/* ----------------- pure data ---------------- */
+EXTERN t_pd *pd_new(t_class *cls);
+EXTERN void pd_free(t_pd *x);
+EXTERN void pd_bind(t_pd *x, t_symbol *s);
+EXTERN void pd_unbind(t_pd *x, t_symbol *s);
+EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c);
+EXTERN void pd_pushsym(t_pd *x);
+EXTERN void pd_popsym(t_pd *x);
+EXTERN t_symbol *pd_getfilename(void);
+EXTERN t_symbol *pd_getdirname(void);
+EXTERN void pd_bang(t_pd *x);
+EXTERN void pd_pointer(t_pd *x, t_gpointer *gp);
+EXTERN void pd_float(t_pd *x, t_float f);
+EXTERN void pd_symbol(t_pd *x, t_symbol *s);
+EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+#define pd_class(x) (*(x))
+
+/* ----------------- pointers ---------------- */
+EXTERN void gpointer_init(t_gpointer *gp);
+EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto);
+EXTERN void gpointer_unset(t_gpointer *gp);
+EXTERN int gpointer_check(const t_gpointer *gp, int headok);
+
+/* ----------------- patchable "objects" -------------- */
+EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1,
+    t_symbol *s2);
+EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp);
+EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp);
+EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp);
+EXTERN t_inlet *signalinlet_new(t_object *owner, t_float f);
+EXTERN void inlet_free(t_inlet *x);
+
+EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s);
+EXTERN void outlet_bang(t_outlet *x);
+EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp);
+EXTERN void outlet_float(t_outlet *x, t_float f);
+EXTERN void outlet_symbol(t_outlet *x, t_symbol *s);
+EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_symbol *outlet_getsymbol(t_outlet *x);
+EXTERN void outlet_free(t_outlet *x);
+EXTERN t_object *pd_checkobject(t_pd *x);
+
+
+/* -------------------- canvases -------------- */
+
+EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir);
+
+EXTERN void canvas_setargs(int argc, t_atom *argv);
+EXTERN void canvas_getargs(int *argcp, t_atom **argvp);
+EXTERN t_symbol *canvas_getcurrentdir(void);
+EXTERN t_glist *canvas_getcurrent(void);
+EXTERN void canvas_makefilename(t_glist *c, char *file,
+    char *result,int resultsize);
+EXTERN t_symbol *canvas_getdir(t_glist *x);
+EXTERN char sys_font[]; /* default typeface set in s_main.c */
+EXTERN char sys_fontweight[]; /* default font weight set in s_main.c */
+EXTERN int sys_fontwidth(int fontsize);
+EXTERN int sys_fontheight(int fontsize);
+EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b);
+EXTERN int canvas_open(t_canvas *x, const char *name, const char *ext,
+    char *dirresult, char **nameresult, unsigned int size, int bin);
+
+/* ---------------- widget behaviors ---------------------- */
+
+EXTERN_STRUCT _widgetbehavior;
+#define t_widgetbehavior struct _widgetbehavior
+
+EXTERN_STRUCT _parentwidgetbehavior;
+#define t_parentwidgetbehavior struct _parentwidgetbehavior
+EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
+
+/* -------------------- classes -------------- */
+
+#define CLASS_DEFAULT 0         /* flags for new classes below */
+#define CLASS_PD 1
+#define CLASS_GOBJ 2
+#define CLASS_PATCHABLE 3
+#define CLASS_NOINLET 8
+
+#define CLASS_TYPEMASK 3
+
+
+EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod,
+    t_method freemethod, size_t size, int flags, t_atomtype arg1, ...);
+EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s, 
+    t_atomtype type1, ...);
+EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
+    t_atomtype arg1, ...);
+EXTERN void class_addbang(t_class *c, t_method fn);
+EXTERN void class_addpointer(t_class *c, t_method fn);
+EXTERN void class_doaddfloat(t_class *c, t_method fn);
+EXTERN void class_addsymbol(t_class *c, t_method fn);
+EXTERN void class_addlist(t_class *c, t_method fn);
+EXTERN void class_addanything(t_class *c, t_method fn);
+EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s);
+EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w);
+EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w);
+EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c);
+EXTERN char *class_getname(t_class *c);
+EXTERN char *class_gethelpname(t_class *c);
+EXTERN char *class_gethelpdir(t_class *c);
+EXTERN void class_setdrawcommand(t_class *c);
+EXTERN int class_isdrawcommand(t_class *c);
+EXTERN void class_domainsignalin(t_class *c, int onset);
+EXTERN void class_set_extern_dir(t_symbol *s);
+#define CLASS_MAINSIGNALIN(c, type, field) \
+    class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0)
+
+         /* prototype for functions to save Pd's to a binbuf */
+typedef void (*t_savefn)(t_gobj *x, t_binbuf *b);
+EXTERN void class_setsavefn(t_class *c, t_savefn f);
+EXTERN t_savefn class_getsavefn(t_class *c);
+EXTERN void obj_saveformat(t_object *x, t_binbuf *bb); /* add format to bb */
+
+        /* prototype for functions to open properties dialogs */
+typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist);
+EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f);
+EXTERN t_propertiesfn class_getpropertiesfn(t_class *c);
+
+#ifndef PD_CLASS_DEF
+#define class_addbang(x, y) class_addbang((x), (t_method)(y))
+#define class_addpointer(x, y) class_addpointer((x), (t_method)(y))
+#define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y))
+#define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y))
+#define class_addlist(x, y) class_addlist((x), (t_method)(y))
+#define class_addanything(x, y) class_addanything((x), (t_method)(y))
+#endif
+
+/* ------------   printing --------------------------------- */
+EXTERN void post(const char *fmt, ...);
+EXTERN void startpost(const char *fmt, ...);
+EXTERN void poststring(const char *s);
+EXTERN void postfloat(t_floatarg f);
+EXTERN void postatom(int argc, t_atom *argv);
+EXTERN void endpost(void);
+EXTERN void error(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
+EXTERN void verbose(int level, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
+EXTERN void bug(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
+EXTERN void pd_error(void *object, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
+EXTERN void logpost(const void *object, const int level, const char *fmt, ...)
+    ATTRIBUTE_FORMAT_PRINTF(3, 4);
+EXTERN void sys_logerror(const char *object, const char *s);
+EXTERN void sys_unixerror(const char *object);
+EXTERN void sys_ouch(void);
+
+
+/* ------------  system interface routines ------------------- */
+EXTERN int sys_isreadablefile(const char *name);
+EXTERN int sys_isabsolutepath(const char *dir);
+EXTERN void sys_bashfilename(const char *from, char *to);
+EXTERN void sys_unbashfilename(const char *from, char *to);
+EXTERN int open_via_path(const char *dir, const char *name, const char *ext,
+    char *dirresult, char **nameresult, unsigned int size, int bin);
+EXTERN int sched_geteventno(void);
+EXTERN double sys_getrealtime(void);
+EXTERN int (*sys_idlehook)(void);   /* hook to add idle time computation */
+
+/* Win32's open()/fopen() do not handle UTF-8 filenames so we need
+ * these internal versions that handle UTF-8 filenames the same across
+ * all platforms.  They are recommended for use in external
+ * objectclasses as well so they work with Unicode filenames on Windows */
+EXTERN int sys_open(const char *path, int oflag, ...);
+EXTERN int sys_close(int fd);
+EXTERN FILE *sys_fopen(const char *filename, const char *mode);
+EXTERN int sys_fclose(FILE *stream);
+
+/* ------------  threading ------------------- */ 
+EXTERN void sys_lock(void);
+EXTERN void sys_unlock(void);
+EXTERN int sys_trylock(void);
+
+
+/* --------------- signals ----------------------------------- */
+
+typedef PD_FLOATTYPE t_sample;
+typedef union _sampleint_union {
+  t_sample f;
+  PD_FLOATUINTTYPE i;
+} t_sampleint_union;
+#define MAXLOGSIG 32
+#define MAXSIGSIZE (1 << MAXLOGSIG)
+
+typedef struct _signal
+{
+    int s_n;            /* number of points in the array */
+    t_sample *s_vec;    /* the array */
+    t_float s_sr;         /* sample rate */
+    int s_refcount;     /* number of times used */
+    int s_isborrowed;   /* whether we're going to borrow our array */
+    struct _signal *s_borrowedfrom;     /* signal to borrow it from */
+    struct _signal *s_nextfree;         /* next in freelist */
+    struct _signal *s_nextused;         /* next in used list */
+    int s_vecsize;      /* allocated size of array in points */
+} t_signal;
+
+typedef t_int *(*t_perfroutine)(t_int *args);
+
+EXTERN t_int *plus_perform(t_int *args);
+EXTERN t_int *zero_perform(t_int *args);
+EXTERN t_int *copy_perform(t_int *args);
+
+EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n);
+EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n);
+EXTERN void dsp_add_scalarcopy(t_float *in, t_sample *out, int n);
+EXTERN void dsp_add_zero(t_sample *out, int n);
+
+EXTERN int sys_getblksize(void);
+EXTERN t_float sys_getsr(void);
+EXTERN int sys_get_inchannels(void);
+EXTERN int sys_get_outchannels(void);
+
+EXTERN void dsp_add(t_perfroutine f, int n, ...);
+EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec);
+EXTERN void pd_fft(t_float *buf, int npoints, int inverse);
+EXTERN int ilog2(int n);
+
+EXTERN void mayer_fht(t_sample *fz, int n);
+EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_realfft(int n, t_sample *real);
+EXTERN void mayer_realifft(int n, t_sample *real);
+
+EXTERN float *cos_table;
+#define LOGCOSTABSIZE 9
+#define COSTABSIZE (1<<LOGCOSTABSIZE)
+
+EXTERN int canvas_suspend_dsp(void);
+EXTERN void canvas_resume_dsp(int oldstate);
+EXTERN void canvas_update_dsp(void);
+EXTERN int canvas_dspstate;
+
+/*   up/downsampling */
+typedef struct _resample
+{
+  int method;       /* up/downsampling method ID */
+
+  int downsample; /* downsampling factor */
+  int upsample;   /* upsampling factor */
+
+  t_sample *s_vec;   /* here we hold the resampled data */
+  int      s_n;
+
+  t_sample *coeffs;  /* coefficients for filtering... */
+  int      coefsize;
+
+  t_sample *buffer;  /* buffer for filtering */
+  int      bufsize;
+} t_resample;
+
+EXTERN void resample_init(t_resample *x);
+EXTERN void resample_free(t_resample *x);
+
+EXTERN void resample_dsp(t_resample *x, t_sample *in, int insize, t_sample *out, int outsize, int method);
+EXTERN void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method);
+EXTERN void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method);
+
+/* ----------------------- utility functions for signals -------------- */
+EXTERN t_float mtof(t_float);
+EXTERN t_float ftom(t_float);
+EXTERN t_float rmstodb(t_float);
+EXTERN t_float powtodb(t_float);
+EXTERN t_float dbtorms(t_float);
+EXTERN t_float dbtopow(t_float);
+
+EXTERN t_float q8_sqrt(t_float);
+EXTERN t_float q8_rsqrt(t_float);
+#ifndef N32     
+EXTERN t_float qsqrt(t_float);  /* old names kept for extern compatibility */
+EXTERN t_float qrsqrt(t_float);
+#endif
+/* --------------------- data --------------------------------- */
+
+    /* graphical arrays */
+EXTERN_STRUCT _garray;
+#define t_garray struct _garray
+
+EXTERN t_class *garray_class;
+EXTERN int garray_getfloatarray(t_garray *x, int *size, t_float **vec);
+EXTERN int garray_getfloatwords(t_garray *x, int *size, t_word **vec);
+EXTERN void garray_redraw(t_garray *x);
+EXTERN int garray_npoints(t_garray *x);
+EXTERN char *garray_vec(t_garray *x);
+EXTERN void garray_resize(t_garray *x, t_floatarg f);  /* avoid; use this: */
+EXTERN void garray_resize_long(t_garray *x, long n);   /* better version */
+EXTERN void garray_usedindsp(t_garray *x);
+EXTERN void garray_setsaveit(t_garray *x, int saveit);
+EXTERN t_glist *garray_getglist(t_garray *x);
+EXTERN t_array *garray_getarray(t_garray *x);
+EXTERN t_class *scalar_class;
+
+EXTERN t_float *value_get(t_symbol *s);
+EXTERN void value_release(t_symbol *s);
+EXTERN int value_getfloat(t_symbol *s, t_float *f);
+EXTERN int value_setfloat(t_symbol *s, t_float f);
+
+/* ------- GUI interface - functions to send strings to TK --------- */
+typedef void (*t_guicallbackfn)(t_gobj *client, t_glist *glist);
+
+EXTERN void sys_vgui(char *fmt, ...);
+EXTERN void sys_gui(char *s);
+EXTERN void sys_pretendguibytes(int n);
+EXTERN void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f);
+EXTERN void sys_unqueuegui(void *client);
+    /* dialog window creation and destruction */
+EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd);
+EXTERN void gfxstub_deleteforkey(void *key);
+
+extern t_class *glob_pdobject;  /* object to send "pd" messages */
+
+/*-------------  Max 0.26 compatibility --------------------*/
+
+/* the following reflects the new way classes are laid out, with the class
+   pointing to the messlist and not vice versa. Externs shouldn't feel it. */
+typedef t_class *t_externclass;
+
+EXTERN void c_extern(t_externclass *cls, t_newmethod newroutine,
+    t_method freeroutine, t_symbol *name, size_t size, int tiny, \
+    t_atomtype arg1, ...);
+EXTERN void c_addmess(t_method fn, t_symbol *sel, t_atomtype arg1, ...);
+
+#define t_getbytes getbytes
+#define t_freebytes freebytes
+#define t_resizebytes resizebytes
+#define typedmess pd_typedmess
+#define vmess pd_vmess
+
+/* A definition to help gui objects straddle 0.34-0.35 changes.  If this is
+defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
+
+#define PD_USE_TE_XPIX
+
+#ifndef _MSC_VER /* Microoft compiler can't handle "inline" function/macros */
+#if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
+/* a test for NANs and denormals.  Should only be necessary on i386. */
+# if PD_FLOATSIZE == 32
+static inline int PD_BADFLOAT(t_sample f) {
+  t_sampleint_union u;
+  u.f=f;
+  return ((u.i & 0x7f800000)==0) || ((u.i&0x7f800000)==0x7f800000);
+}
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+static inline int PD_BIGORSMALL(t_sample f) {
+  t_sampleint_union u;
+  u.f=f;
+  return ((u.i & 0x60000000)==0) || ((u.i & 0x60000000)==0x60000000);
+}
+# else
+#  warning 64bit mode: BIGORSMALL not implemented yet
+#  define PD_BADFLOAT(f) 0
+#  define PD_BIGORSMALL(f) 0
+# endif
+#else
+# define PD_BADFLOAT(f) 0
+# define PD_BIGORSMALL(f) 0
+#endif
+#else   /* _MSC_VER */
+#define PD_BADFLOAT(f) ((((*(unsigned int*)&(f))&0x7f800000)==0) || \
+    (((*(unsigned int*)&(f))&0x7f800000)==0x7f800000))
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
+    (((*(unsigned int*)&(f))&0x60000000)==0x60000000))
+#endif /* _MSC_VER */
+    /* get version number at run time */
+EXTERN void sys_getversion(int *major, int *minor, int *bugfix);
+
+EXTERN_STRUCT _pdinstance;
+#define t_pdinstance struct _pdinstance       /* m_imp.h */
+
+/* m_pd.c */
+
+EXTERN t_pdinstance *pdinstance_new( void);
+EXTERN void pd_setinstance(t_pdinstance *x);
+EXTERN void pdinstance_free(t_pdinstance *x);
+EXTERN t_canvas *pd_getcanvaslist(void);
+EXTERN int pd_getdspstate(void);
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+}
+#endif
+
+#define __m_pd_h_
+#endif /* __m_pd_h_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpd/s_stuff.h	Mon Jun 20 16:57:35 2016 +0100
@@ -0,0 +1,411 @@
+/* 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.  */
+
+/* Audio and MIDI I/O, and other scheduling and system stuff. */
+
+/* NOTE: this file describes Pd implementation details which may change
+in future releases.  The public (stable) API is in m_pd.h. */  
+
+/* in s_path.c */
+
+typedef struct _namelist    /* element in a linked list of stored strings */
+{
+    struct _namelist *nl_next;  /* next in list */
+    char *nl_string;            /* the string */
+} t_namelist;
+
+t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup);
+t_namelist *namelist_append_files(t_namelist *listwas, const char *s);
+void namelist_free(t_namelist *listwas);
+char *namelist_get(t_namelist *namelist, int n);
+void sys_setextrapath(const char *p);
+extern int sys_usestdpath;
+extern t_namelist *sys_externlist;
+extern t_namelist *sys_searchpath;
+extern t_namelist *sys_helppath;
+int sys_open_absolute(const char *name, const char* ext,
+    char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp);
+int sys_trytoopenone(const char *dir, const char *name, const char* ext,
+    char *dirresult, char **nameresult, unsigned int size, int bin);
+t_symbol *sys_decodedialog(t_symbol *s);
+
+/* s_file.c */
+
+void sys_loadpreferences( void);
+void sys_savepreferences( void);
+extern int sys_defeatrt;
+extern t_symbol *sys_flags;
+
+/* s_main.c */
+extern int sys_debuglevel;
+extern int sys_verbose;
+extern int sys_noloadbang;
+extern int sys_nogui;
+extern char *sys_guicmd;
+
+EXTERN int sys_nearestfontsize(int fontsize);
+EXTERN int sys_hostfontsize(int fontsize);
+
+extern int sys_defaultfont;
+EXTERN t_symbol *sys_libdir;    /* library directory for auxilliary files */
+extern t_symbol *sys_guidir;    /* directory holding pd_gui, u_pdsend, etc */
+
+/* s_loader.c */
+
+typedef int (*loader_t)(t_canvas *canvas, char *classname); /* callback type */
+EXTERN int sys_load_lib(t_canvas *canvas, char *filename);
+EXTERN void sys_register_loader(loader_t loader);
+
+/* s_audio.c */
+
+#define SENDDACS_NO 0           /* return values for sys_send_dacs() */
+#define SENDDACS_YES 1 
+#define SENDDACS_SLEPT 2
+
+#define DEFDACBLKSIZE 8
+extern int sys_schedblocksize;  /* audio block size for scheduler */
+extern int sys_hipriority;      /* real-time flag, true if priority boosted */
+EXTERN t_sample *sys_soundout;
+EXTERN t_sample *sys_soundin;
+extern int sys_inchannels;
+extern int sys_outchannels;
+extern int sys_advance_samples; /* scheduler advance in samples */
+extern int sys_blocksize;       /* audio I/O block size in sample frames */
+extern t_float sys_dacsr;
+extern int sys_schedadvance;
+extern int sys_sleepgrain;
+EXTERN void sys_set_audio_settings(int naudioindev, int *audioindev,
+    int nchindev, int *chindev,
+    int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
+    int srate, int advance, int callback, int blocksize);
+/* the same as above, but reopens the audio subsystem if needed */
+EXTERN void sys_set_audio_settings_reopen(int naudioindev, int *audioindev,
+    int nchindev, int *chindev,
+    int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
+    int srate, int advance, int callback, int blocksize);
+EXTERN void sys_reopen_audio( void);
+EXTERN void sys_close_audio(void);
+    /* return true if the interface prefers always being open (ala jack) : */
+EXTERN int audio_shouldkeepopen( void);
+EXTERN int audio_isopen( void);     /* true if audio interface is open */
+EXTERN int sys_audiodevnametonumber(int output, const char *name);
+EXTERN void sys_audiodevnumbertoname(int output, int devno, char *name,
+    int namesize);
+
+int sys_send_dacs(void);
+void sys_reportidle(void);
+void sys_set_priority(int higher);
+void sys_audiobuf(int nbufs);
+void sys_getmeters(t_sample *inmax, t_sample *outmax);
+void sys_listdevs(void);
+void sys_setblocksize(int n);
+
+EXTERN void sys_get_audio_devs(char *indevlist, int *nindevs,
+                          char *outdevlist, int *noutdevs, int *canmulti, int *cancallback, 
+                          int maxndev, int devdescsize);
+EXTERN void sys_get_audio_apis(char *buf);
+
+/* s_midi.c */
+#define MAXMIDIINDEV 16         /* max. number of input ports */
+#define MAXMIDIOUTDEV 16        /* max. number of output ports */
+extern int sys_midiapi;
+extern int sys_nmidiin;
+extern int sys_nmidiout;
+extern int sys_midiindevlist[];
+extern int sys_midioutdevlist[];
+
+EXTERN void sys_open_midi(int nmidiin, int *midiinvec,
+    int nmidiout, int *midioutvec, int enable);
+
+EXTERN void sys_get_midi_apis(char *buf);
+EXTERN void sys_get_midi_devs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, 
+   int maxndev, int devdescsize);
+EXTERN void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
+    int *pnmidioutdev, int *pmidioutdev);
+EXTERN int sys_mididevnametonumber(int output, const char *name);
+EXTERN void sys_mididevnumbertoname(int output, int devno, char *name,
+    int namesize);
+
+EXTERN void sys_reopen_midi( void);
+EXTERN void sys_close_midi( void);
+EXTERN void sys_putmidimess(int portno, int a, int b, int c);
+EXTERN void sys_putmidibyte(int portno, int a);
+EXTERN void sys_poll_midi(void);
+EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sys_midibytein(int portno, int byte);
+
+    /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
+void midi_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
+void sys_do_open_midi(int nmidiindev, int *midiindev,
+    int nmidioutdev, int *midioutdev);
+
+#ifdef USEAPI_ALSA
+EXTERN void sys_alsa_putmidimess(int portno, int a, int b, int c);
+EXTERN void sys_alsa_putmidibyte(int portno, int a);
+EXTERN void sys_alsa_poll_midi(void);
+EXTERN void sys_alsa_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sys_alsa_midibytein(int portno, int byte);
+EXTERN void sys_alsa_close_midi( void);
+
+
+    /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
+void midi_alsa_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
+void sys_alsa_do_open_midi(int nmidiindev, int *midiindev,
+    int nmidioutdev, int *midioutdev);
+#endif
+
+/* m_sched.c */
+EXTERN void sys_log_error(int type);
+#define ERR_NOTHING 0
+#define ERR_ADCSLEPT 1
+#define ERR_DACSLEPT 2
+#define ERR_RESYNC 3
+#define ERR_DATALATE 4
+
+#define SCHED_AUDIO_NONE 0
+#define SCHED_AUDIO_POLL 1 
+#define SCHED_AUDIO_CALLBACK 2
+void sched_set_using_audio(int flag);
+
+/* s_inter.c */
+
+EXTERN void sys_microsleep(int microsec);
+EXTERN void sys_init_fdpoll(void);
+
+EXTERN void sys_bail(int exitcode);
+EXTERN int sys_pollgui(void);
+
+EXTERN_STRUCT _socketreceiver;
+#define t_socketreceiver struct _socketreceiver
+
+typedef void (*t_socketnotifier)(void *x, int n);
+typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
+
+EXTERN t_socketreceiver *socketreceiver_new(void *owner,
+    t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
+EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
+EXTERN void sys_sockerror(char *s);
+EXTERN void sys_closesocket(int fd);
+
+typedef void (*t_fdpollfn)(void *ptr, int fd);
+EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
+EXTERN void sys_rmpollfn(int fd);
+#if defined(USEAPI_OSS) || defined(USEAPI_ALSA)
+void sys_setalarm(int microsec);
+#endif
+
+#define API_NONE 0
+#define API_ALSA 1
+#define API_OSS 2
+#define API_MMIO 3
+#define API_PORTAUDIO 4
+#define API_JACK 5
+#define API_SGI 6           /* gone */
+#define API_AUDIOUNIT 7
+#define API_ESD 8           /* no idea what this was, probably gone now */
+#define API_DUMMY 9
+
+    /* figure out which API should be the default.  The one we judge most
+    likely to offer a working device takes precedence so that if you
+    start up Pd for the first time there's a reasonable chance you'll have
+    sound.  (You'd think portaudio would be best but it seems to default
+    to jack on linux, and and on Windows we only use it for ASIO). 
+    If nobody shows up, define DUMMY and make it the default.*/
+#if defined(USEAPI_MMIO)
+# define API_DEFAULT API_MMIO
+# define API_DEFSTRING "MMIO"
+#elif defined(USEAPI_ALSA)
+# define API_DEFAULT API_ALSA
+# define API_DEFSTRING "ALSA"
+#elif defined(USEAPI_OSS)
+# define API_DEFAULT API_OSS
+# define API_DEFSTRING "OSS"
+#elif defined(USEAPI_AUDIOUNIT)
+# define API_DEFAULT API_AUDIOUNIT
+# define API_DEFSTRING "AudioUnit"
+#elif defined(USEAPI_ESD)
+# define API_DEFAULT API_ESD
+# define API_DEFSTRING "ESD (?)"
+#elif defined(USEAPI_PORTAUDIO)
+# define API_DEFAULT API_PORTAUDIO
+# define API_DEFSTRING "portaudio"
+#elif defined(USEAPI_JACK)
+# define API_DEFAULT API_JACK
+# define API_DEFSTRING "Jack audio connection kit"
+#else 
+# ifndef USEAPI_DUMMY   /* we need at least one so bring in the dummy */
+# define USEAPI_DUMMY
+# endif /* USEAPI_DUMMY */
+# define API_DEFAULT API_DUMMY
+# define API_DEFSTRING "dummy audio"
+#endif 
+
+#define DEFAULTAUDIODEV 0
+
+#define MAXAUDIOINDEV 4
+#define MAXAUDIOOUTDEV 4
+
+#define DEFMIDIDEV 0
+
+#define DEFAULTSRATE 44100
+#ifdef _WIN32
+#define DEFAULTADVANCE 80
+#else
+#ifdef __APPLE__
+#define DEFAULTADVANCE 5    /* this is in addition to their own delay */
+#else
+#define DEFAULTADVANCE 25
+#endif
+#endif
+
+typedef void (*t_audiocallback)(void);
+
+int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
+    t_sample *soundout, int framesperbuf, int nbuffers,
+    int indeviceno, int outdeviceno, t_audiocallback callback);
+void pa_close_audio(void);
+int pa_send_dacs(void);
+void sys_reportidle(void);
+void pa_listdevs(void);
+void pa_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int oss_open_audio(int naudioindev, int *audioindev, int nchindev,
+    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+    int *choutdev, int rate, int blocksize);
+void oss_close_audio(void);
+int oss_send_dacs(void);
+void oss_reportidle(void);
+void oss_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
+    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+    int *choutdev, int rate, int blocksize);
+void alsa_close_audio(void);
+int alsa_send_dacs(void);
+void alsa_reportidle(void);
+void alsa_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int jack_open_audio(int wantinchans, int wantoutchans, int srate,
+    t_audiocallback callback);
+void jack_close_audio(void);
+int jack_send_dacs(void);
+void jack_reportidle(void);
+void jack_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+void jack_listdevs(void);
+
+int mmio_open_audio(int naudioindev, int *audioindev,
+    int nchindev, int *chindev, int naudiooutdev, int *audiooutdev,
+    int nchoutdev, int *choutdev, int rate, int blocksize);
+void mmio_close_audio( void);
+void mmio_reportidle(void);
+int mmio_send_dacs(void);
+void mmio_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int audiounit_open_audio(int naudioindev, int *audioindev, int nchindev,
+    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+    int *choutdev, int rate);
+void audiounit_close_audio(void);
+int audiounit_send_dacs(void);
+void audiounit_listdevs(void);
+void audiounit_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int esd_open_audio(int naudioindev, int *audioindev, int nchindev,
+    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+    int *choutdev, int rate);
+void esd_close_audio(void);
+int esd_send_dacs(void);
+void esd_listdevs(void);
+void esd_getdevs(char *indevlist, int *nindevs,
+    char *outdevlist, int *noutdevs, int *canmulti, 
+        int maxndev, int devdescsize);
+
+int dummy_open_audio(int nin, int nout, int sr);
+int dummy_close_audio( void);
+int dummy_send_dacs( void);
+void dummy_getdevs(char *indevlist, int *nindevs, char *outdevlist,
+    int *noutdevs, int *canmulti, int maxndev, int devdescsize);
+void dummy_listdevs( void);
+
+void sys_listmididevs(void);
+EXTERN void sys_set_midi_api(int whichapi);
+EXTERN void sys_set_audio_api(int whichapi);
+EXTERN int sys_audioapi;
+EXTERN void sys_set_audio_state(int onoff);
+
+/* API dependent audio flags and settings */
+void oss_set32bit( void);
+void linux_alsa_devname(char *devname);
+
+EXTERN void sys_get_audio_params(
+    int *pnaudioindev, int *paudioindev, int *chindev,
+    int *pnaudiooutdev, int *paudiooutdev, int *choutdev,
+    int *prate, int *padvance, int *callback, int *blocksize);
+void sys_save_audio_params(
+    int naudioindev, int *audioindev, int *chindev,
+    int naudiooutdev, int *audiooutdev, int *choutdev,
+    int rate, int advance, int callback, int blocksize);
+
+/* s_file.c */
+
+typedef void (*t_printhook)(const char *s);
+extern t_printhook sys_printhook;  /* set this to override printing */
+extern int sys_printtostderr;
+
+/* jsarlo { */
+
+EXTERN double sys_time;
+EXTERN double sys_time_per_dsp_tick;
+EXTERN int sys_externalschedlib;
+
+EXTERN t_sample* get_sys_soundout(void ) ;
+EXTERN t_sample* get_sys_soundin(void ) ;
+EXTERN int* get_sys_main_advance(void ) ;
+EXTERN double* get_sys_time_per_dsp_tick(void ) ;
+EXTERN int* get_sys_schedblocksize(void ) ;
+EXTERN double* get_sys_time(void ) ;
+EXTERN t_float* get_sys_dacsr(void ) ;
+EXTERN int* get_sys_sleepgrain(void ) ;
+EXTERN int* get_sys_schedadvance(void ) ;
+
+EXTERN void sys_clearhist(void );
+EXTERN void sys_initmidiqueue(void );
+EXTERN int sys_addhist(int phase);
+EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sched_tick( void);
+EXTERN void sys_pollmidiqueue(void );
+EXTERN int sys_pollgui(void );
+EXTERN void sys_setchsr(int chin, int chout, int sr);
+
+EXTERN void inmidi_realtimein(int portno, int cmd);
+EXTERN void inmidi_byte(int portno, int byte);
+EXTERN void inmidi_sysex(int portno, int byte);
+EXTERN void inmidi_noteon(int portno, int channel, int pitch, int velo);
+EXTERN void inmidi_controlchange(int portno,
+                                 int channel,
+                                 int ctlnumber,
+                                 int value);
+EXTERN void inmidi_programchange(int portno, int channel, int value);
+EXTERN void inmidi_pitchbend(int portno, int channel, int value);
+EXTERN void inmidi_aftertouch(int portno, int channel, int value);
+EXTERN void inmidi_polyaftertouch(int portno,
+                                  int channel,
+                                  int pitch,
+                                  int value);
+/* } jsarlo */
+extern t_widgetbehavior text_widgetbehavior;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpd/z_libpd.h	Mon Jun 20 16:57:35 2016 +0100
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2010 Peter Brinkmann (peter.brinkmann@gmail.com)
+ *
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+ *
+ * See https://github.com/libpd/libpd/wiki for documentation
+ *
+ */
+
+#ifndef __Z_LIBPD_H__
+#define __Z_LIBPD_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "m_pd.h"
+
+EXTERN int libpd_init(void);
+EXTERN void libpd_clear_search_path(void);
+EXTERN void libpd_add_to_search_path(const char *sym);
+
+EXTERN void *libpd_openfile(const char *basename, const char *dirname);
+EXTERN void libpd_closefile(void *p);
+EXTERN int libpd_getdollarzero(void *p);
+
+EXTERN int libpd_blocksize(void);
+EXTERN int libpd_init_audio(int inChans, int outChans, int sampleRate);
+EXTERN int libpd_process_raw(const float *inBuffer, float *outBuffer);
+EXTERN t_sample* libpd_get_sys_soundin();
+EXTERN t_sample* libpd_get_sys_soundout();
+EXTERN int libpd_process_sys();
+EXTERN int libpd_process_short(const int ticks,
+    const short *inBuffer, short *outBuffer);
+EXTERN int libpd_process_float(int ticks,
+    const float *inBuffer, float *outBuffer);
+EXTERN int libpd_process_double(int ticks,
+    const double *inBuffer, double *outBuffer);
+
+EXTERN int libpd_arraysize(const char *name);
+// The parameters of the next two functions are inspired by memcpy.
+EXTERN int libpd_read_array(float *dest, const char *src, int offset, int n);
+EXTERN int libpd_write_array(const char *dest, int offset, float *src, int n);
+
+EXTERN int libpd_bang(const char *recv);
+EXTERN int libpd_float(const char *recv, float x);
+EXTERN int libpd_symbol(const char *recv, const char *sym);
+
+EXTERN void libpd_set_float(t_atom *v, float x);
+EXTERN void libpd_set_symbol(t_atom *v, const char *sym);
+EXTERN int libpd_list(const char *recv, int argc, t_atom *argv);
+EXTERN int libpd_message(const char *recv, const char *msg, int argc, t_atom *argv);
+
+EXTERN int libpd_start_message(int max_length);
+EXTERN void libpd_add_float(float x);
+EXTERN void libpd_add_symbol(const char *sym);
+EXTERN int libpd_finish_list(const char *recv);
+EXTERN int libpd_finish_message(const char *recv, const char *msg);
+
+EXTERN int libpd_exists(const char *sym);
+EXTERN void *libpd_bind(const char *sym);
+EXTERN void libpd_unbind(void *p);
+
+EXTERN int libpd_is_float(t_atom *a);
+EXTERN int libpd_is_symbol(t_atom *a);
+EXTERN float libpd_get_float(t_atom *a);
+EXTERN char *libpd_get_symbol(t_atom *a);
+EXTERN t_atom *libpd_next_atom(t_atom *a);
+
+typedef void (*t_libpd_printhook)(const char *recv);
+typedef void (*t_libpd_banghook)(const char *recv);
+typedef void (*t_libpd_floathook)(const char *recv, float x);
+typedef void (*t_libpd_symbolhook)(const char *recv, const char *sym);
+typedef void (*t_libpd_listhook)(const char *recv, int argc, t_atom *argv);
+typedef void (*t_libpd_messagehook)(const char *recv, const char *msg,
+    int argc, t_atom *argv);
+
+EXTERN void libpd_set_printhook(const t_libpd_printhook hook);
+EXTERN void libpd_set_banghook(const t_libpd_banghook hook);
+EXTERN void libpd_set_floathook(const t_libpd_floathook hook);
+EXTERN void libpd_set_symbolhook(const t_libpd_symbolhook hook);
+EXTERN void libpd_set_listhook(const t_libpd_listhook hook);
+EXTERN void libpd_set_messagehook(const t_libpd_messagehook hook);
+
+EXTERN int libpd_noteon(int channel, int pitch, int velocity);
+EXTERN int libpd_controlchange(int channel, int controller, int value);
+EXTERN int libpd_programchange(int channel, int value);
+EXTERN int libpd_pitchbend(int channel, int value);
+EXTERN int libpd_aftertouch(int channel, int value);
+EXTERN int libpd_polyaftertouch(int channel, int pitch, int value);
+EXTERN int libpd_midibyte(int port, int byte);
+EXTERN int libpd_sysex(int port, int byte);
+EXTERN int libpd_sysrealtime(int port, int byte);
+
+typedef void (*t_libpd_noteonhook)(int channel, int pitch, int velocity);
+typedef void (*t_libpd_controlchangehook)(int channel,
+    int controller, int value);
+typedef void (*t_libpd_programchangehook)(int channel, int value);
+typedef void (*t_libpd_pitchbendhook)(int channel, int value);
+typedef void (*t_libpd_aftertouchhook)(int channel, int value);
+typedef void (*t_libpd_polyaftertouchhook)(int channel, int pitch, int value);
+typedef void (*t_libpd_midibytehook)(int port, int byte);
+
+EXTERN void libpd_set_noteonhook(const t_libpd_noteonhook hook);
+EXTERN void libpd_set_controlchangehook(const t_libpd_controlchangehook hook);
+EXTERN void libpd_set_programchangehook(const t_libpd_programchangehook hook);
+EXTERN void libpd_set_pitchbendhook(const t_libpd_pitchbendhook hook);
+EXTERN void libpd_set_aftertouchhook(const t_libpd_aftertouchhook hook);
+EXTERN void libpd_set_polyaftertouchhook(const t_libpd_polyaftertouchhook hook);
+EXTERN void libpd_set_midibytehook(const t_libpd_midibytehook hook);
+EXTERN void libpd_sys_microsleep(int sleep);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif