pure-data/src/s_inter_gui.c

/* Copyright (c) 2022 IOhannes m zmölnig.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

/* Pd side of the Pd/Pd-gui interface. */

#include "m_pd.h"
#include "s_stuff.h"
#include <stdarg.h>
#include <string.h>

/* NULL-terminated */
#define GUI_VMESS__END
/* use space to structure the format-string */
#define GUI_VMESS__IGNORE

/* floating point number (automatically promoted to double) */
#define GUI_VMESS__FLOAT
/* fixed point number (automatically promoted to int) */
#define GUI_VMESS__INT

/* 0-terminated strings are untrusted and need escaping */
#define GUI_VMESS__STRING
/* the same goes for char arrays ("pascalstring") */
#define GUI_VMESS__PASCALSTRING
/* rawstrings don't need encoding */
#define GUI_VMESS__RAWSTRING

/* takes an int-representation of a 24bit RGB color */
#define GUI_VMESS__COLOR

/* generic pointer; this is not actually used, and probably should stay that way */
#define GUI_VMESS__POINTER
/* a Pd-object */
#define GUI_VMESS__OBJECT

/* takes a Pd-message of the form "t_symbol*, int argc, t_atom*argv" */
#define GUI_VMESS__MESSAGE

/* arrays are capitalized */
#define GUI_VMESS__ATOMS
#define GUI_VMESS__ATOMARRAY
#define GUI_VMESS__FLOATARRAY
#define GUI_VMESS__FLOATWORDS
#define GUI_VMESS__FLOATWORDARRAY
#define GUI_VMESS__STRINGARRAY
#define GUI_VMESS__RAWSTRINGARRAY

/* canvases */
#define GUI_VMESS__CANVAS
#define GUI_VMESS__CANVASARRAY

/* toplevel windows are legacy: this should go away (use 'c' instead) */
#define GUI_VMESS__WINDOW

/* more ideas for types (the IDs need discussion)
 * - float32 array ('1'), float64 array ('2'): think libpd
 * - symbols ('y'), symbolarray ('Y'): this is just a shorthand for 's',
 *   so probably overkill
 * - t_word array ('W')

 * - a continuation char ('+'), to keep formating and values close together:
 *   e.g.  pdgui_vmess(..., "i+", 12, "i+", 13);
 */


/* sys_vgui() and sys_gui() are deprecated for externals
   and shouldn't be used directly within Pd.
   however, the we do use them for implementing the high-level
   communication (such as pdgui_vmess),
   so we do not want the compiler to shout out loud.
 */
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined _MSC_VER
#pragma warning( disable : 4996 )
#endif

static PERTHREAD char* s_escbuffer =;
static PERTHREAD size_t s_esclength =;
#ifndef GUI_ALLOCCHUNK
#define GUI_ALLOCCHUNK
#endif
static char*get_escapebuffer(const char*s, int size)
{}
static const char* str_escape(const char*s, int size)
{}

t_val;

//#define DEBUGME
/* constructs a string that can be passed on to sys_gui() */
#ifdef DEBUGME
static void print_val(t_val v) {
    char str[80];
    dprintf(2, "value[%c] ", v.type);
    switch (v.type) {
    case GUI_VMESS__ATOMS:
        atom_string(v.value.p, str, sizeof(str));
        dprintf(2, "(atom)%s", str);
        break;
    case GUI_VMESS__FLOAT:
        dprintf(2, "(float)%f", v.value.d);
        break;
    case GUI_VMESS__INT:
        dprintf(2, "(int)%d", v.value.i);
        break;
    case GUI_VMESS__COLOR:
        dprintf(2, "(color)#%06x", v.value.i & 0xFFFFFF);
        break;
    case GUI_VMESS__STRING:
        dprintf(2, "(string)\"%s\"", v.value.p);
        break;
    case GUI_VMESS__PASCALSTRING:
        dprintf(2, "(pascalstring)\"%.*s\"", v.size, v.value.p);
        break;
    case GUI_VMESS__RAWSTRING:
        dprintf(2, "(rawstring)\"%s\"", v.value.p);
        break;
    case GUI_VMESS__WINDOW:
    case GUI_VMESS__CANVAS:
        dprintf(2, "(glist)%p", v.value.p);
            /* estimate the size required for the array */
        break;
    case GUI_VMESS__ATOMARRAY:
    case GUI_VMESS__FLOATARRAY:
    case GUI_VMESS__FLOATWORDS:
    case GUI_VMESS__FLOATWORDARRAY:
    case GUI_VMESS__STRINGARRAY:
    case GUI_VMESS__RAWSTRINGARRAY:
    case GUI_VMESS__POINTER:
    case GUI_VMESS__OBJECT:
    case GUI_VMESS__CANVASARRAY:
        dprintf(2, "%dx @%p", v.size, v.value.p);
            /* estimate the size required for the array */
        break;
    case GUI_VMESS__MESSAGE:
        dprintf(2, "(message)%s %d@%p", v.string, v.size, v.value.p);
        break;
    default:
        break;
    }
    dprintf(2, "\n");
}
#else
static void print_val(t_val v) {}
#ifdef dprintf
#undef dprintf
#endif
int dprintf(int fd, const char* format, ...) {}
#endif

static void sendatoms(int argc, t_atom*argv, int raw) {}

static int addmess(const t_val *v)
{}

static int va2value(const char fmt, va_list *args, t_val*v) {}


void pdgui_vamess(const char* message, const char* format, va_list args_)
{}
void pdgui_endmess(void)
{}


/* constructs a string that can be passed on to sys_gui() */
/* TODO: shouldn't this have a pointer to t_pdinstance? */
void pdgui_vmess(const char* message, const char* format, ...)
{}