From d00d35241ac97369edb5d5f466b9966a5871417a Mon Sep 17 00:00:00 2001
From: Claude Heiland-Allen <claude@mathr.co.uk>
Date: Mon, 24 Sep 2018 22:41:50 +0100
Subject: [PATCH 33/39] bundled: pd-0.47-1

---
 bundled/g_canvas.h |  57 ++++++++++++++++++++-----
 bundled/m_imp.h    |   2 +-
 bundled/m_pd.h     | 102 ++++++++++++++++++++++++++++++++-------------
 3 files changed, 119 insertions(+), 42 deletions(-)

diff --git a/bundled/g_canvas.h b/bundled/g_canvas.h
index c4acb402..6b9e8ee1 100644
--- a/bundled/g_canvas.h
+++ b/bundled/g_canvas.h
@@ -34,7 +34,7 @@ glist has its own window, even if miniaturized.
 */
 
 /* NOTE: this file describes Pd implementation details which may change
-in future releases.  The public (stable) API is in m_pd.h. */  
+in future releases.  The public (stable) API is in m_pd.h. */
 
 #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
 extern "C" {
@@ -71,7 +71,7 @@ EXTERN_STRUCT _tscalar;
 #define t_tscalar struct _tscalar
 
 EXTERN_STRUCT _canvasenvironment;
-#define t_canvasenvironment struct _canvasenvironment 
+#define t_canvasenvironment struct _canvasenvironment
 
 EXTERN_STRUCT _fielddesc;
 #define t_fielddesc struct _fielddesc
@@ -124,11 +124,11 @@ typedef struct _editor
 /* editor structure for "garrays".  We don't bother to delete and regenerate
 this structure when the "garray" becomes invisible or visible, although we
 could do so if the structure gets big (like the "editor" above.) */
-    
+
 typedef struct _arrayvis
 {
     t_updateheader av_upd;          /* update header structure */
-    t_garray *av_garray;            /* owning structure */    
+    t_garray *av_garray;            /* owning structure */
 } t_arrayvis;
 
 /* the t_tick structure describes where to draw x and y "ticks" for a glist */
@@ -146,7 +146,7 @@ area of a window.
 */
 
 struct _glist
-{  
+{
     t_object gl_obj;            /* header in case we're a glist */
     t_gobj *gl_list;            /* the actual data */
     struct _gstub *gl_stub;     /* safe pointer handler */
@@ -164,7 +164,7 @@ struct _glist
     int gl_screeny2;
     int gl_xmargin;                /* origin for GOP rectangle */
     int gl_ymargin;
-    t_tick gl_xtick;            /* ticks marking X values */    
+    t_tick gl_xtick;            /* ticks marking X values */
     int gl_nxlabels;            /* number of X coordinate labels */
     t_symbol **gl_xlabel;           /* ... an array to hold them */
     t_float gl_xlabely;               /* ... and their Y coordinates */
@@ -175,19 +175,21 @@ struct _glist
     t_editor *gl_editor;        /* editor structure when visible */
     t_symbol *gl_name;          /* symbol bound here */
     int gl_font;                /* nominal font size in points, e.g., 10 */
+    int gl_zoom;                /* zoom factor (integer zoom-in only) */
     struct _glist *gl_next;         /* link in list of toplevels */
     t_canvasenvironment *gl_env;    /* root canvases and abstractions only */
     unsigned int gl_havewindow:1;   /* true if we own a window */
     unsigned int gl_mapped:1;       /* true if, moreover, it's "mapped" */
     unsigned int gl_dirty:1;        /* (root canvas only:) patch has changed */
     unsigned int gl_loading:1;      /* am now loading from file */
-    unsigned int gl_willvis:1;      /* make me visible after loading */ 
+    unsigned int gl_willvis:1;      /* make me visible after loading */
     unsigned int gl_edit:1;         /* edit mode */
     unsigned int gl_isdeleting:1;   /* we're inside glist_delete -- hack! */
     unsigned int gl_goprect:1;      /* draw rectangle for graph-on-parent */
     unsigned int gl_isgraph:1;      /* show as graph on parent */
     unsigned int gl_hidetext:1;     /* hide object-name + args when doing graph on parent */
     unsigned int gl_private:1;      /* private flag used in x_scalar.c */
+    unsigned int gl_isclone:1;      /* esists as part of a clone object */
 };
 
 #define gl_gobj gl_obj.te_g
@@ -294,7 +296,7 @@ typedef void (*t_parentgetrectfn)(t_gobj *x, struct _glist *glist,
     t_word *data, t_template *tmpl, t_float basex, t_float basey,
     int *x1, int *y1, int *x2, int *y2);
         /* displace it */
-typedef void (*t_parentdisplacefn)(t_gobj *x, struct _glist *glist, 
+typedef void (*t_parentdisplacefn)(t_gobj *x, struct _glist *glist,
     t_word *data, t_template *tmpl, t_float basex, t_float basey,
     int dx, int dy);
         /* change color to show selection */
@@ -336,7 +338,7 @@ struct _parentwidgetbehavior
 #define CURSOR_EDITMODE_RESIZE 7
 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_whichfind;  /* last canvas we did a find in */
 extern t_class *vinlet_class, *voutlet_class;
 extern int glist_valid;         /* incremented when pointers might be stale */
 
@@ -379,6 +381,9 @@ EXTERN int glist_isvisible(t_glist *x);
 EXTERN int glist_istoplevel(t_glist *x);
 EXTERN t_glist *glist_findgraph(t_glist *x);
 EXTERN int glist_getfont(t_glist *x);
+EXTERN int glist_fontwidth(t_glist *x);
+EXTERN int glist_fontheight(t_glist *x);
+EXTERN int glist_getzoom(t_glist *x);
 EXTERN void glist_sort(t_glist *canvas);
 EXTERN void glist_read(t_glist *x, t_symbol *filename, t_symbol *format);
 EXTERN void glist_mergefile(t_glist *x, t_symbol *filename, t_symbol *format);
@@ -407,7 +412,7 @@ EXTERN void canvas_create_editor(t_glist *x);
 EXTERN void canvas_destroy_editor(t_glist *x);
 void canvas_deletelinesforio(t_canvas *x, t_text *text,
     t_inlet *inp, t_outlet *outp);
-extern int glist_amreloadingabstractions; /* stop GUI changes while reloading */ 
+extern int glist_amreloadingabstractions; /* stop GUI changes while reloading */
 
 /* -------------------- functions on texts ------------------------- */
 EXTERN void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize);
@@ -455,6 +460,8 @@ EXTERN void canvas_deletelinesfor(t_canvas *x, t_text *text);
 EXTERN void canvas_stowconnections(t_canvas *x);
 EXTERN void canvas_restoreconnections(t_canvas *x);
 EXTERN void canvas_redraw(t_canvas *x);
+EXTERN void canvas_closebang(t_canvas *x);
+EXTERN void canvas_initbang(t_canvas *x);
 
 EXTERN t_inlet *canvas_addinlet(t_canvas *x, t_pd *who, t_symbol *sym);
 EXTERN void canvas_rminlet(t_canvas *x, t_inlet *ip);
@@ -492,6 +499,16 @@ EXTERN int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
     int *x1p, int *y1p, int *x2p, int *y2p);
 EXTERN int canvas_setdeleting(t_canvas *x, int flag);
 
+#define LB_LOAD 0       /* "loadbang" actions - 0 for original meaning */
+#define LB_INIT 1       /* loaded but not yet connected to parent patch */
+#define LB_CLOSE 2      /* about to close */
+
+    /* Pointer to canvas that was saved necessitating a reload of abstractions
+    of that name.  We use as a flag to stop canvases from being marked "dirty"
+    if we have to touch them to reload; also suppress window list update.
+    "clone~" uses this to identify which copy NOT to reload */
+t_glist *glist_reloadingabstraction;
+
 typedef void (*t_undofn)(t_canvas *canvas, void *buf,
     int action);        /* a function that does UNDO/REDO */
 #define UNDO_FREE 0                     /* free current undo/redo buffer */
@@ -512,6 +529,21 @@ EXTERN void canvas_selectinrect(t_canvas *x, int lox, int loy, int hix, int hiy)
 
 EXTERN t_glist *pd_checkglist(t_pd *x);
 
+/* a function that gets called for each path by canvas_path_iterate
+ * if the function returns 0, the iteration is terminated;
+ * <path> pointer to the path
+ * <data> is the pointer given to canvas_path_iterate()
+ * <ce> is a pointer to the canvas-environment that provided <path> in its
+ * search-path (or NULL)
+ */
+typedef int (*t_canvas_path_iterator)(const char *path, void *user_data);
+/*
+ * iterate over all search-paths for <x> calling <fun> with the user-supplied
+ * <data>
+ * iteration stops once all paths are exhausted or calling <fun> returned 0.
+ */
+EXTERN int canvas_path_iterate(t_canvas *x, t_canvas_path_iterator fun,
+    void *user_data);
 
 /* ---- functions on canvasses as objects  --------------------- */
 
@@ -569,7 +601,7 @@ EXTERN void array_getcoordinate(t_glist *glist,
 EXTERN int array_getfields(t_symbol *elemtemplatesym,
     t_canvas **elemtemplatecanvasp,
     t_template **elemtemplatep, int *elemsizep,
-    t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc, 
+    t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc,
     int *xonsetp, int *yonsetp, int *wonsetp);
 
 /* --------------------- templates ------------------------- */
@@ -617,6 +649,9 @@ EXTERN void guiconnect_notarget(t_guiconnect *x, double timedelay);
 EXTERN t_symbol *iemgui_raute2dollar(t_symbol *s);
 EXTERN t_symbol *iemgui_dollar2raute(t_symbol *s);
 
+/*-------------  g_clone.c ------------- */
+extern t_class *clone_class;
+
 #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
 }
 #endif
diff --git a/bundled/m_imp.h b/bundled/m_imp.h
index 177cf9f9..f186a28a 100644
--- a/bundled/m_imp.h
+++ b/bundled/m_imp.h
@@ -6,7 +6,7 @@
 Pd, but not shared with Pd objects. */
 
 /* NOTE: this file describes Pd implementation details which may change
-in future releases.  The public (stable) API is in m_pd.h. */  
+in future releases.  The public (stable) API is in m_pd.h. */
 
 /* LATER consider whether to use 'char' for method arg types to save space */
 #ifndef __m_imp_h_
diff --git a/bundled/m_pd.h b/bundled/m_pd.h
index c0837ae8..a0dafc5e 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 46
-#define PD_BUGFIX_VERSION 7
+#define PD_MINOR_VERSION 47
+#define PD_BUGFIX_VERSION 1
 #define PD_TEST_VERSION ""
 extern int pd_compatibilitylevel;   /* e.g., 43 for pd 0.43 compatibility */
 
@@ -39,12 +39,15 @@ extern int pd_compatibilitylevel;   /* e.g., 43 for pd 0.43 compatibility */
 #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
+    /* On most c compilers, you can just say "struct foo;" to declare a
+    structure whose elements are defined elsewhere.  On MSVC, when compiling
+    C (but not C++) code, you have to say "extern struct foo;".  So we make
+    a stupid macro: */
+#if defined(_MSC_VER) && !defined(_LANGUAGE_C_PLUS_PLUS) \
+    && !defined(__cplusplus)
 #define EXTERN_STRUCT extern struct
+#else
+#define EXTERN_STRUCT struct
 #endif
 
 /* Define some attributes, specific to the compiler */
@@ -137,7 +140,7 @@ typedef struct _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;
@@ -165,7 +168,7 @@ typedef enum
     A_COMMA,
     A_DEFFLOAT,
     A_DEFSYM,
-    A_DOLLAR, 
+    A_DOLLAR,
     A_DOLLSYM,
     A_GIMME,
     A_CANT
@@ -442,6 +445,8 @@ EXTERN void canvas_makefilename(t_glist *c, char *file,
 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_zoomfontwidth(int fontsize, int zoom, int worstcase);
+EXTERN int sys_zoomfontheight(int fontsize, int zoom, int worstcase);
 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);
@@ -470,7 +475,7 @@ EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
 
 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, 
+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, ...);
@@ -552,7 +557,7 @@ EXTERN int sys_close(int fd);
 EXTERN FILE *sys_fopen(const char *filename, const char *mode);
 EXTERN int sys_fclose(FILE *stream);
 
-/* ------------  threading ------------------- */ 
+/* ------------  threading ------------------- */
 EXTERN void sys_lock(void);
 EXTERN void sys_unlock(void);
 EXTERN int sys_trylock(void);
@@ -652,7 +657,7 @@ EXTERN t_float dbtopow(t_float);
 
 EXTERN t_float q8_sqrt(t_float);
 EXTERN t_float q8_rsqrt(t_float);
-#ifndef N32     
+#ifndef N32
 EXTERN t_float qsqrt(t_float);  /* old names kept for extern compatibility */
 EXTERN t_float qrsqrt(t_float);
 #endif
@@ -720,33 +725,70 @@ defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
 #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);
+#if PD_FLOATSIZE == 32
+
+typedef  union
+{
+    t_float f;
+    unsigned int ui;
+}t_bigorsmall32;
+
+static inline int PD_BADFLOAT(t_float f)  /* malformed float */
+{
+    t_bigorsmall32 pun;
+    pun.f = f;
+    pun.ui &= 0x7f800000;
+    return((pun.ui == 0) | (pun.ui == 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);
+
+static inline int PD_BIGORSMALL(t_float f)  /* exponent outside (-64,64) */
+{
+    t_bigorsmall32 pun;
+    pun.f = f;
+    return((pun.ui & 0x20000000) == ((pun.ui >> 1) & 0x20000000));
 }
-# 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
+
+#elif PD_FLOATSIZE == 64
+
+typedef  union
+{
+    t_float f;
+    unsigned int ui[2];
+}t_bigorsmall64;
+
+static inline int PD_BADFLOAT(t_float f)  /* malformed double */
+{
+    t_bigorsmall64 pun;
+    pun.f = f;
+    pun.ui[1] &= 0x7ff00000;
+    return((pun.ui[1] == 0) | (pun.ui[1] == 0x7ff00000));
+}
+
+static inline int PD_BIGORSMALL(t_float f)  /* exponent outside (-512,512) */
+{
+    t_bigorsmall64 pun;
+    pun.f = f;
+    return((pun.ui[1] & 0x20000000) == ((pun.ui[1] >> 1) & 0x20000000));
+}
+
+#endif /* PD_FLOATSIZE */
+#else /* not INTEL or ARM */
+#define PD_BADFLOAT(f) 0
+#define PD_BIGORSMALL(f) 0
 #endif
+
 #else   /* _MSC_VER */
+#if PD_FLOATSIZE == 32
 #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))
+#else   /* 64 bits... don't know what to do here */
+#define PD_BADFLOAT(f) (!(((f) >= 0) || ((f) <= 0)))
+#define PD_BIGORSMALL(f) ((f) > 1e150 || (f) <  -1e150 \
+    || (f) > -1e-150 && (f) < 1e-150 )
+#endif
 #endif /* _MSC_VER */
     /* get version number at run time */
 EXTERN void sys_getversion(int *major, int *minor, int *bugfix);
-- 
2.19.1

