From cd4531bd85bef6360e41d86479b8c15b54abc1a1 Mon Sep 17 00:00:00 2001
From: Claude Heiland-Allen <claude@mathr.co.uk>
Date: Mon, 24 Sep 2018 22:38:42 +0100
Subject: [PATCH 32/39] bundled: pd-0.46-7

---
 bundled/g_canvas.h |  1 -
 bundled/m_imp.h    | 28 ++++++++++++++++++++++++
 bundled/m_pd.h     | 54 ++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/bundled/g_canvas.h b/bundled/g_canvas.h
index 38714446..c4acb402 100644
--- a/bundled/g_canvas.h
+++ b/bundled/g_canvas.h
@@ -337,7 +337,6 @@ struct _parentwidgetbehavior
 EXTERN void canvas_setcursor(t_glist *x, unsigned int cursornum);
 
 extern t_canvas *canvas_whichfind;  /* last canvas we did a find in */ 
-extern t_canvas *canvas_list;       /* list of all root canvases */
 extern t_class *vinlet_class, *voutlet_class;
 extern int glist_valid;         /* incremented when pointers might be stale */
 
diff --git a/bundled/m_imp.h b/bundled/m_imp.h
index 58468fd8..177cf9f9 100644
--- a/bundled/m_imp.h
+++ b/bundled/m_imp.h
@@ -54,6 +54,31 @@ struct _class
     char c_drawcommand;             /* a drawing command for a template */
 };
 
+struct _pdinstance
+{
+    double pd_systime;          /* global time in Pd ticks */
+    t_clock *pd_clock_setlist;  /* list of set clocks */
+    t_int *pd_dspchain;         /* DSP chain */
+    int pd_dspchainsize;        /* number of elements in DSP chain */
+    t_canvas *pd_canvaslist;    /* list of all root canvases */
+    int pd_dspstate;            /* whether DSP is on or off */
+    t_signal *pd_signals;       /* list of signals used by DSP chain */
+    t_symbol *pd_midiin_sym;    /* symbols bound to incoming MIDI... */
+    t_symbol *pd_sysexin_sym;
+    t_symbol *pd_notein_sym;
+    t_symbol *pd_ctlin_sym;
+    t_symbol *pd_pgmin_sym;
+    t_symbol *pd_bendin_sym;
+    t_symbol *pd_touchin_sym;
+    t_symbol *pd_polytouchin_sym;
+    t_symbol *pd_midiclkin_sym;
+    t_symbol *pd_midirealtimein_sym;
+};
+
+extern t_pdinstance *pd_this;
+
+/* m_class.c */
+EXTERN void pd_emptylist(t_pd *x);
 
 /* m_obj.c */
 EXTERN int obj_noutlets(t_object *x);
@@ -78,5 +103,8 @@ EXTERN int obj_sigoutletindex(t_object *x, int m);
 EXTERN t_pd *glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir);
 EXTERN void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv);
 EXTERN void glob_quit(void *dummy);
+EXTERN void open_via_helppath(const char *name, const char *dir);
+
+
 #define __m_imp_h_
 #endif /* __m_imp_h_ */
diff --git a/bundled/m_pd.h b/bundled/m_pd.h
index 52805a89..c0837ae8 100644
--- a/bundled/m_pd.h
+++ b/bundled/m_pd.h
@@ -9,8 +9,8 @@ extern "C" {
 #endif
 
 #define PD_MAJOR_VERSION 0
-#define PD_MINOR_VERSION 45
-#define PD_BUGFIX_VERSION 5
+#define PD_MINOR_VERSION 46
+#define PD_BUGFIX_VERSION 7
 #define PD_TEST_VERSION ""
 extern int pd_compatibilitylevel;   /* e.g., 43 for pd 0.43 compatibility */
 
@@ -247,7 +247,17 @@ typedef struct _text t_object;
 
 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 */
@@ -273,12 +283,27 @@ 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)))
-#define mess1(x, s, a) ((*getfn((x), (s)))((x), (a)))
-#define mess2(x, s, a,b) ((*getfn((x), (s)))((x), (a),(b)))
-#define mess3(x, s, a,b,c) ((*getfn((x), (s)))((x), (a),(b),(c)))
-#define mess4(x, s, a,b,c,d) ((*getfn((x), (s)))((x), (a),(b),(c),(d)))
-#define mess5(x, s, a,b,c,d,e) ((*getfn((x), (s)))((x), (a),(b),(c),(d),(e)))
+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);
 
@@ -597,8 +622,8 @@ typedef struct _resample
 {
   int method;       /* up/downsampling method ID */
 
-  t_int downsample; /* downsampling factor */
-  t_int upsample;   /* upsampling factor */
+  int downsample; /* downsampling factor */
+  int upsample;   /* upsampling factor */
 
   t_sample *s_vec;   /* here we hold the resampled data */
   int      s_n;
@@ -726,6 +751,17 @@ static inline int PD_BIGORSMALL(t_sample f) {
     /* 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
-- 
2.19.1

