From 645f148010e91b18ba51a3b455edf3c164c5a443 Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Wed, 2 Apr 2014 00:59:26 -0400 Subject: [PATCH] *updated hcs externals to the latest version --- externals/hcs/Makefile | 183 ++++++++++++++++++++------ externals/hcs/canvas_name.c | 103 +++++++++------ externals/hcs/ce_path.c | 8 +- externals/hcs/classpath-help.pd | 86 +++--------- externals/hcs/classpath.c | 18 +-- externals/hcs/colorpanel.c | 17 ++- externals/hcs/cursor-help.pd | 6 +- externals/hcs/cursor.c | 138 ++----------------- externals/hcs/folder_list.c | 7 +- externals/hcs/group.c | 14 +- externals/hcs/helppath.c | 8 +- externals/hcs/keyboard_layout-help.pd | 37 ------ externals/hcs/keyboard_layout.c | 116 ---------------- externals/hcs/passwd.c | 16 +-- externals/hcs/screensize.c | 2 +- externals/hcs/split_path.c | 12 +- externals/hcs/sql_query-help.pd | 6 +- externals/hcs/sql_query.c | 2 +- externals/hcs/stat-help.pd | 6 +- externals/hcs/stat.c | 16 +-- externals/hcs/sys_gui-help.pd | 6 +- externals/hcs/sys_gui.c | 68 ++++++---- externals/hcs/uname.c | 2 +- externals/hcs/version.c | 2 +- externals/hcs/window_name.c | 107 +++++++++------ 25 files changed, 405 insertions(+), 581 deletions(-) delete mode 100644 externals/hcs/keyboard_layout-help.pd delete mode 100644 externals/hcs/keyboard_layout.c diff --git a/externals/hcs/Makefile b/externals/hcs/Makefile index 497d95594..61315d439 100644 --- a/externals/hcs/Makefile +++ b/externals/hcs/Makefile @@ -1,11 +1,12 @@ -## Pd library template version 1.0.3 +## Pd library template version 1.0.11 # For instructions on how to use this template, see: # http://puredata.info/docs/developer/MakefileTemplate LIBRARY_NAME = hcs # add your .c source files, one object per file, to the SOURCES -# variable, help files will be included automatically -SOURCES = canvas_name.c ce_path.c classpath.c colorpanel.c cursor.c folder_list.c group.c helppath.c keyboard_layout.c passwd.c screensize.c setenv.c split_path.c sql_query.c stat.c sys_gui.c uname.c unsetenv.c version.c window_name.c +# variable, help files will be included automatically, and for GUI +# objects, the matching .tcl file too +SOURCES = canvas_name.c ce_path.c classpath.c colorpanel.c cursor.c folder_list.c group.c helppath.c passwd.c screensize.c setenv.c split_path.c sql_query.c stat.c sys_gui.c uname.c unsetenv.c version.c window_name.c # For objects that only build on certain platforms, add those to the SOURCES # line for the right platforms. @@ -35,9 +36,11 @@ EXTRA_DIST = README-ifeel.txt ifeel.h # #------------------------------------------------------------------------------# -CFLAGS = -DPD -I"$(PD_INCLUDE)/pd" -Wall -W -g -LDFLAGS = -LIBS = +ALL_CFLAGS = -I"$(PD_INCLUDE)" +ALL_LDFLAGS = +SHARED_LDFLAGS = +ALL_LIBS = + #------------------------------------------------------------------------------# # @@ -45,12 +48,17 @@ LIBS = # #------------------------------------------------------------------------------# +# these can be set from outside without (usually) breaking the build +CFLAGS = -Wall -W -g +LDFLAGS = +LIBS = + # get library version from meta file LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd) -CFLAGS += -DVERSION='"$(LIBRARY_VERSION)"' +ALL_CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"' -PD_INCLUDE = $(PD_PATH)/include +PD_INCLUDE = $(PD_PATH)/include/pd # where to install the library, overridden below depending on platform prefix = /usr/local libdir = $(prefix)/lib @@ -66,7 +74,7 @@ ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) -ORIGDIR=pd-$(LIBRARY_NAME)_$(LIBRARY_VERSION) +ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION) UNAME := $(shell uname -s) ifeq ($(UNAME),Darwin) @@ -74,6 +82,7 @@ ifeq ($(UNAME),Darwin) ifeq ($(CPU),arm) # iPhone/iPod Touch SOURCES += $(SOURCES_iphoneos) EXTENSION = pd_darwin + SHARED_EXTENSION = dylib OS = iphoneos PD_PATH = /Applications/Pd-extended.app/Contents/Resources IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin @@ -83,14 +92,16 @@ ifeq ($(UNAME),Darwin) ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer - CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) - LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) - LIBS += -lc + ALL_CFLAGS := $(IPHONE_CFLAGS) $(ALL_CFLAGS) + ALL_LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) + SHARED_LDFLAGS += -arch armv6 -dynamiclib -undefined dynamic_lookup $(ISYSROOT) + ALL_LIBS += -lc $(LIBS_iphoneos) STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) else # Mac OS X SOURCES += $(SOURCES_macosx) EXTENSION = pd_darwin + SHARED_EXTENSION = dylib OS = macosx PD_PATH = /Applications/Pd-extended.app/Contents/Resources OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast @@ -101,27 +112,87 @@ ifeq ($(UNAME),Darwin) FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4 SOURCES += $(SOURCES_iphoneos) endif - CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include - LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib + ALL_CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include # if the 'pd' binary exists, check the linking against it to aid with stripping - LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd) - LIBS += -lc + BUNDLE_LOADER = $(shell test ! -e $(PD_PATH)/bin/pd || echo -bundle_loader $(PD_PATH)/bin/pd) + ALL_LDFLAGS += $(FAT_FLAGS) -bundle $(BUNDLE_LOADER) -undefined dynamic_lookup -L/sw/lib + SHARED_LDFLAGS += $(FAT_FLAGS) -dynamiclib -undefined dynamic_lookup \ + -install_name @loader_path/$(SHARED_LIB) -compatibility_version 1 -current_version 1.0 + ALL_LIBS += -lc $(LIBS_macosx) STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) # install into ~/Library/Pd on Mac OS X since /usr/local isn't used much pkglibdir=$(HOME)/Library/Pd endif endif +# Tho Android uses Linux, we use this fake uname to provide an easy way to +# setup all this things needed to cross-compile for Android using the NDK +ifeq ($(UNAME),ANDROID) + CPU := arm + SOURCES += $(SOURCES_android) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = android + PD_PATH = /usr + NDK_BASE := /usr/local/android-ndk + NDK_PLATFORM_VERSION := 5 + NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_VERSION)/arch-arm + NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]') + NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-x86 + CC := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT) + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += + LDFLAGS += -rdynamic -shared + SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared + LIBS += -lc $(LIBS_android) + STRIP := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-strip \ + --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif ifeq ($(UNAME),Linux) CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = linux + PD_PATH = /usr + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared + ALL_LIBS += -lc $(LIBS_linux) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq ($(UNAME),GNU) + # GNU/Hurd, should work like GNU/Linux for basically all externals + CPU := $(shell uname -m) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + SHARED_EXTENSION = so OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer - CFLAGS += -fPIC - LDFLAGS += -Wl,--export-dynamic -shared -fPIC - LIBS += -lc + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc $(LIBS_linux) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq ($(UNAME),GNU/kFreeBSD) + # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals + CPU := $(shell uname -m) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = linux + PD_PATH = /usr + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc $(LIBS_linux) STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif @@ -129,12 +200,14 @@ ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_cygwin) EXTENSION = dll + SHARED_EXTENSION = dll OS = cygwin - PD_PATH = $(cygpath $(PROGRAMFILES))/pd + PD_PATH = $(shell cygpath $$PROGRAMFILES)/pd OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer - CFLAGS += - LDFLAGS += -Wl,--export-dynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" - LIBS += -lc -lpd + ALL_CFLAGS += + ALL_LDFLAGS += -rdynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc -lpd $(LIBS_cygwin) STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif @@ -142,12 +215,16 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_windows) EXTENSION = dll + SHARED_EXTENSION = dll OS = windows - PD_PATH = $(shell cd "$(PROGRAMFILES)"/pd && pwd) + PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd) + # MinGW doesn't seem to include cc so force gcc + CC=gcc OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer - CFLAGS += -mms-bitfields - LDFLAGS += -s -shared -Wl,--enable-auto-import - LIBS += -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 + ALL_CFLAGS += -mms-bitfields + ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" + SHARED_LDFLAGS += -shared + ALL_LIBS += -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 $(LIBS_windows) STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif @@ -155,42 +232,57 @@ endif # in case somebody manually set the HELPPATCHES above HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd) -CFLAGS += $(OPT_CFLAGS) +ALL_CFLAGS := $(ALL_CFLAGS) $(CFLAGS) $(OPT_CFLAGS) +ALL_LDFLAGS := $(LDFLAGS) $(ALL_LDFLAGS) +ALL_LIBS := $(LIBS) $(ALL_LIBS) +SHARED_SOURCE ?= $(shell test ! -e lib$(LIBRARY_NAME).c || \ + echo lib$(LIBRARY_NAME).c ) +SHARED_HEADER ?= $(shell test ! -e $(LIBRARY_NAME).h || echo $(LIBRARY_NAME).h) +SHARED_LIB = $(SHARED_SOURCE:.c=.$(SHARED_EXTENSION)) -.PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags $(LIBRARY_NAME) +.PHONY = install libdir_install single_install install-doc install-examples install-manual clean distclean dist etags $(LIBRARY_NAME) -all: $(SOURCES:.c=.$(EXTENSION)) +all: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) %.o: %.c - $(CC) $(CFLAGS) -o "$*.o" -c "$*.c" + $(CC) $(ALL_CFLAGS) -o "$*.o" -c "$*.c" -%.$(EXTENSION): %.o - $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS) +%.$(EXTENSION): %.o $(SHARED_LIB) + $(CC) $(ALL_LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(ALL_LIBS) $(SHARED_LIB) chmod a-x "$*.$(EXTENSION)" # this links everything into a single binary file $(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o - $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS) + $(CC) $(ALL_LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(ALL_LIBS) chmod a-x $(LIBRARY_NAME).$(EXTENSION) +$(SHARED_LIB): $(SHARED_SOURCE:.c=.o) + $(CC) $(SHARED_LDFLAGS) -o $(SHARED_LIB) $(SHARED_SOURCE:.c=.o) $(LIBS) + install: libdir_install # The meta and help files are explicitly installed to make sure they are # actually there. Those files are not optional, then need to be there. -libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual +libdir_install: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) install-doc install-examples install-manual $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(SOURCES))" || (\ $(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) + test -z "$(strip $(SHARED_LIB))" || \ + $(INSTALL_DATA) $(SHARED_LIB) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(wildcard $(SOURCES:.c=.tcl)))" || \ + $(INSTALL_DATA) $(wildcard $(SOURCES:.c=.tcl)) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) # install library linked as single binary -single_install: $(LIBRARY_NAME) install-doc install-exec +single_install: $(LIBRARY_NAME) install-doc install-examples install-manual $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) @@ -219,10 +311,11 @@ install-manual: clean: - -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) + -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) $(SHARED_SOURCE:.c=.o) -rm -f -- $(SOURCES:.c=.$(EXTENSION)) -rm -f -- $(LIBRARY_NAME).o -rm -f -- $(LIBRARY_NAME).$(EXTENSION) + -rm -f -- $(SHARED_LIB) distclean: clean -rm -f -- $(DISTBINDIR).tar.gz @@ -238,7 +331,7 @@ $(DISTBINDIR): libdir: all $(DISTBINDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) - $(INSTALL_DATA) $(SOURCES) $(DISTBINDIR) + $(INSTALL_DATA) $(SOURCES) $(SHARED_SOURCE) $(SHARED_HEADER) $(DISTBINDIR) $(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR) test -z "$(strip $(EXTRA_DIST))" || \ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTBINDIR) @@ -257,6 +350,12 @@ dist: $(DISTDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTDIR) test -z "$(strip $(ALLSOURCES))" || \ $(INSTALL_DATA) $(ALLSOURCES) $(DISTDIR) + test -z "$(strip $(wildcard $(ALLSOURCES:.c=.tcl)))" || \ + $(INSTALL_DATA) $(wildcard $(ALLSOURCES:.c=.tcl)) $(DISTDIR) + test -z "$(strip $(SHARED_HEADER))" || \ + $(INSTALL_DATA) $(SHARED_HEADER) $(DISTDIR) + test -z "$(strip $(SHARED_SOURCE))" || \ + $(INSTALL_DATA) $(SHARED_SOURCE) $(DISTDIR) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) $(DISTDIR) test -z "$(strip $(HELPPATCHES))" || \ @@ -289,17 +388,25 @@ etags: etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h showsetup: + @echo "CC: $(CC)" @echo "CFLAGS: $(CFLAGS)" @echo "LDFLAGS: $(LDFLAGS)" @echo "LIBS: $(LIBS)" + @echo "ALL_CFLAGS: $(ALL_CFLAGS)" + @echo "ALL_LDFLAGS: $(ALL_LDFLAGS)" + @echo "ALL_LIBS: $(ALL_LIBS)" @echo "PD_INCLUDE: $(PD_INCLUDE)" @echo "PD_PATH: $(PD_PATH)" @echo "objectsdir: $(objectsdir)" @echo "LIBRARY_NAME: $(LIBRARY_NAME)" @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)" @echo "SOURCES: $(SOURCES)" + @echo "SHARED_HEADER: $(SHARED_HEADER)" + @echo "SHARED_SOURCE: $(SHARED_SOURCE)" + @echo "SHARED_LIB: $(SHARED_LIB)" @echo "PDOBJECTS: $(PDOBJECTS)" @echo "ALLSOURCES: $(ALLSOURCES)" + @echo "ALLSOURCES TCL: $(wildcard $(ALLSOURCES:.c=.tcl))" @echo "UNAME: $(UNAME)" @echo "CPU: $(CPU)" @echo "pkglibdir: $(pkglibdir)" diff --git a/externals/hcs/canvas_name.c b/externals/hcs/canvas_name.c index 4f2f88c0c..d8fa11ae0 100644 --- a/externals/hcs/canvas_name.c +++ b/externals/hcs/canvas_name.c @@ -6,62 +6,86 @@ #define DEBUG(x) static t_class *canvas_name_class; -static t_canvas *canvas; typedef struct _canvas_name { - t_object x_obj; - t_atom x_atom; - t_symbol *x_canvas_name; - t_symbol *x_remote_name; + t_object x_obj; + t_canvas *x_canvas; + t_symbol *receive_name; + t_int depth; } t_canvas_name; -static void canvas_name_bang(t_canvas_name *x) +static t_symbol* make_canvas_symbol(t_canvas* canvas) { - if (x->x_atom.a_type == A_SYMBOL) - { - canvas=(t_canvas *)pd_findbyclass(x->x_remote_name, canvas_class); char buf[MAXPDSTRING]; - snprintf(buf, MAXPDSTRING, ".x%lx.c", (long unsigned int)canvas); - x->x_canvas_name = gensym(buf); - } - outlet_symbol(x->x_obj.ob_outlet,x->x_canvas_name); + return gensym(buf); } -static void *canvas_name_new(t_symbol *s, int argc, t_atom *argv) +static t_symbol* get_canvas_by_depth(t_canvas_name *x) { - t_atom a; - if (argc == 0) + t_canvas *canvas = x->x_canvas; + int depth = x->depth; + if(depth<0)depth=0; + while(depth && canvas) { - argc = 1; - SETFLOAT(&a, 0); - argv = &a; + canvas = canvas->gl_owner; + depth--; } - t_canvas_name *x = (t_canvas_name *)pd_new(canvas_name_class); - x->x_atom = *argv; - if (argv->a_type == A_FLOAT) - { // thx to IOhannes's iemguts: - t_glist *glist=(t_glist *)canvas_getcurrent(); - canvas=(t_canvas *)glist_getcanvas(glist); - int depth=(int)atom_getint(&x->x_atom); + return make_canvas_symbol(canvas); +} - if(depth<0)depth=0; - while(depth && canvas) { - canvas=canvas->gl_owner; - depth--; - } - char buf[MAXPDSTRING]; +static t_symbol* get_canvas_by_name(t_canvas_name *x) +{ + return make_canvas_symbol((t_canvas *)pd_findbyclass(x->receive_name, canvas_class)); +} - snprintf(buf, MAXPDSTRING, ".x%lx.c", (long unsigned int)canvas); - x->x_canvas_name = gensym(buf); - } +static t_symbol* get_canvas_name(t_canvas_name *x) +{ + if(x->receive_name == &s_) + return get_canvas_by_depth(x); else - { - x->x_remote_name = (t_symbol *)atom_getsymbol(&x->x_atom); - } + return get_canvas_by_name(x); +} + +static void canvas_name_bang(t_canvas_name *x) +{ + /* actually get the canvas name each time to make sure we get + * accurate info in case of changes. If we cache the result, a + * canvas could have been deleted or renamed. */ + outlet_symbol(x->x_obj.ob_outlet, get_canvas_name(x)); +} + +static void canvas_name_anything(t_canvas_name *x, t_symbol *s, int argc, t_atom *argv) +{ + t_symbol *first_symbol = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(s == &s_float) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else if (first_symbol == &s_) + x->receive_name = s; + else + x->receive_name = first_symbol; + canvas_name_bang(x); +} + +static void *canvas_name_new(t_symbol *s, int argc, t_atom *argv) +{ + t_canvas_name *x = (t_canvas_name *)pd_new(canvas_name_class); + + t_glist* glist = (t_glist *)canvas_getcurrent(); + x->x_canvas = (t_canvas *)glist_getcanvas(glist); + + t_symbol *tmp = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(tmp == &s_) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else + x->receive_name = tmp; - outlet_new(&x->x_obj, &s_symbol); + outlet_new(&x->x_obj, &s_symbol); return(x); } @@ -73,4 +97,5 @@ void canvas_name_setup(void) sizeof(t_canvas_name), 0, A_GIMME, 0); class_addbang(canvas_name_class, (t_method)canvas_name_bang); + class_addanything(canvas_name_class, (t_method)canvas_name_anything); } diff --git a/externals/hcs/ce_path.c b/externals/hcs/ce_path.c index 54b0c6b6b..97a214e82 100644 --- a/externals/hcs/ce_path.c +++ b/externals/hcs/ce_path.c @@ -104,8 +104,8 @@ void ce_path_setup(void) class_addmethod(ce_path_class, (t_method) ce_path_rewind, gensym("rewind"), 0); - post("[ce_path] %s", version); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - post("\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, - PD_MINOR_VERSION, PD_BUGFIX_VERSION); + logpost(NULL, 4, "[ce_path] %s", version); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); + logpost(NULL, 4, "\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, + PD_MINOR_VERSION, PD_BUGFIX_VERSION); } diff --git a/externals/hcs/classpath-help.pd b/externals/hcs/classpath-help.pd index d603628f0..c2ed5a77c 100644 --- a/externals/hcs/classpath-help.pd +++ b/externals/hcs/classpath-help.pd @@ -1,65 +1,16 @@ -#N canvas 427 35 555 619 10; -#X declare; -#X obj 0 595 cnv 15 552 21 empty \$0-pddp.cnv.footer empty 20 12 0 -14 -228856 -66577 0; -#X obj 0 0 cnv 15 552 40 empty \$0-pddp.cnv.header classpath 3 12 0 -18 -204280 -1 0; -#X obj 0 294 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 8 12 0 13 --228856 -1 0; -#X obj 0 399 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 8 12 0 -13 -228856 -1 0; -#X obj 0 485 cnv 3 550 3 empty \$0-pddp.cnv.argument arguments 8 12 -0 13 -228856 -1 0; -#X obj 0 535 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 8 12 -0 13 -228856 -1 0; -#N canvas 214 518 428 109 Related_objects 0; -#X obj 1 1 cnv 15 425 20 empty \$0-pddp.cnv.subheading empty 3 12 0 -14 -204280 -1 0; -#X text 7 1 [path] Related Objects; -#X obj 22 42 declare; -#X restore 102 597 pd Related_objects; -#X obj 78 303 cnv 17 3 80 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 --162280 0; -#X obj 78 408 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 --162280 0; -#X obj 78 441 cnv 17 3 35 empty \$0-pddp.cnv.let.1 1 5 9 0 16 -228856 --162280 0; -#X msg 91 84 bang; -#X symbolatom 102 188 0 0 0 0 - - -; -#X obj 91 214 print; -#X text 138 83 get next item in list of loaded libs; -#X text 150 137 start at the top of the list again; -#X msg 103 138 rewind; -#X text 97 539 [path] appends directories to the canvas-local path. -; -#X text 98 302 bang; -#X text 98 407 symbol; -#X text 98 440 bang; -#X obj 208 188 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +#N canvas 0 26 425 241 10; +#X obj 40 130 classpath; +#X msg 40 92 bang; +#X obj 65 180 print; +#X symbolatom 40 208 0 0 0 0 - - -; +#X obj 101 155 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#X text 229 187 bang after the end of the list is reached; -#X text 11 23 load paths from a patch; -#X text 168 407 - a "bang" to the inlet of [path] sends a symbol to -the left outlet which the name of a loaded path.; -#X text 167 440 - once [path] has output the last path in the list -\, sending another "bang" to its inlet will cause a "bang" to be sent -out its right outlet.; -#X text 80 501 n) symbol atom; -#X text 167 501 - the arguments to [path] specify the paths to load -for patch.; -#X obj 4 597 pddp/pddplink all_about_help_patches.pd -text Usage Guide -; -#X msg 98 111 append lib/extrahiddenstuff; -#X text 274 109 add another path to the list; -#X text 98 362 rewind; -#X text 98 336 append; -#X text 168 362 - resets to output at the top of the list of paths. -; -#X text 168 336 - add a path to the end of the list of paths.; -#X obj 91 162 classpath ../lib abs; -#X obj 483 9 classpath; -#X text 168 302 - sending a "bang" to [classpath] makes it output the -loaded paths one at a time (i.e. \, one per bang).; +#X text 19 22 This object returns each path in the global classpath +one at a time with each bang. [reset( refreshs the classpath data and +starts again at the top of the list \, like [textfile] or [qlist]'s +[reset(.; +#X text 124 154 <-- banged when the end of the list is reached; +#X msg 82 92 rewind; #N canvas 435 26 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; @@ -70,10 +21,9 @@ Wilkes for Pd version 0.42.; #X text 12 85 OUTLET_0 symbol; #X text 12 105 OUTLET_1 bang; #X text 12 5 KEYWORDS control pd-op; -#X restore 504 599 pd META; -#X connect 10 0 34 0; -#X connect 15 0 34 0; -#X connect 28 0 34 0; -#X connect 34 0 11 0; -#X connect 34 0 12 0; -#X connect 34 1 20 0; +#X restore 376 221 pd META; +#X connect 0 0 2 0; +#X connect 0 0 3 0; +#X connect 0 1 4 0; +#X connect 1 0 0 0; +#X connect 7 0 0 0; diff --git a/externals/hcs/classpath.c b/externals/hcs/classpath.c index fe5ab981a..4b81b63d7 100644 --- a/externals/hcs/classpath.c +++ b/externals/hcs/classpath.c @@ -40,8 +40,6 @@ static char *version = "$Revision: 1.3 $"; -t_int classpath_instance_count; - #define DEBUG(x) //#define DEBUG(x) x @@ -103,16 +101,6 @@ static void *classpath_new() DEBUG(post("classpath_new");); t_classpath *x = (t_classpath *)pd_new(classpath_class); - if(!classpath_instance_count) - { - post("[classpath] %s",version); - post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - post("\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, - PD_MINOR_VERSION, PD_BUGFIX_VERSION); - } - classpath_instance_count++; - x->x_data_outlet = outlet_new(&x->x_obj, &s_symbol); x->x_status_outlet = outlet_new(&x->x_obj, 0); @@ -144,5 +132,11 @@ void classpath_setup(void) gensym("rewind"), 0); class_addmethod(classpath_class,(t_method) classpath_add,gensym("add"), A_DEFSYMBOL, 0); + + logpost(NULL, 4, "[classpath] %s",version); + logpost(NULL, 4, "\twritten by Hans-Christoph Steiner <hans@eds.org>"); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); + logpost(NULL, 4, "\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, + PD_MINOR_VERSION, PD_BUGFIX_VERSION); } diff --git a/externals/hcs/colorpanel.c b/externals/hcs/colorpanel.c index a7ef291c7..b7874085b 100644 --- a/externals/hcs/colorpanel.c +++ b/externals/hcs/colorpanel.c @@ -2,8 +2,7 @@ #include <stdlib.h> #include <string.h> #include <m_pd.h> - -#define DEBUG(x) +#include <m_imp.h> static t_class *colorpanel_class; @@ -16,13 +15,12 @@ typedef struct _colorpanel static void colorpanel_bang(t_colorpanel *x) { - sys_vgui("pd [concat %s callback [tk_chooseColor -initialcolor %s] \\;]\n", + sys_vgui("after idle [list after 100 ::hcs::colorpanel::open %s %s]\n", x->x_s->s_name, x->current_color); } static void colorpanel_symbol(t_colorpanel *x, t_symbol *s) { - DEBUG(post("setting initial color: %s", s->s_name);); strncpy(x->current_color, s->s_name, MAXPDSTRING); colorpanel_bang(x); } @@ -36,7 +34,8 @@ static void colorpanel_list(t_colorpanel *x, t_symbol *s, int argc, t_atom *argv char color_string[MAXPDSTRING]; strncpy(color_string,"#",MAXPDSTRING); - if(argc > 2) post("[colorpanel] warning more than three elements in list"); + if(argc > 3) + logpost(x, 2, "[colorpanel] warning more than three elements in list"); for(i=0; i<3; i++) { tmp_symbol = atom_getsymbolarg(i, argc, argv); @@ -48,11 +47,11 @@ static void colorpanel_list(t_colorpanel *x, t_symbol *s, int argc, t_atom *argv } else { - pd_error(x,"[colorpanel] symbol atom in color list"); + pd_error(x,"[colorpanel] symbols are not allowed in the color list"); + return; } } memcpy(x->current_color, color_string, 7); - DEBUG(post("setting initial color: %s", x->current_color);); colorpanel_bang(x); } @@ -99,4 +98,8 @@ void colorpanel_setup(void) class_addlist(colorpanel_class, (t_method)colorpanel_list); class_addmethod(colorpanel_class, (t_method)colorpanel_callback, gensym("callback"), A_DEFSYMBOL, 0); + + sys_vgui("eval [read [open {%s/%s.tcl}]]\n", + colorpanel_class->c_externdir->s_name, + colorpanel_class->c_name->s_name); } diff --git a/externals/hcs/cursor-help.pd b/externals/hcs/cursor-help.pd index 1df5f8800..92b4d1098 100644 --- a/externals/hcs/cursor-help.pd +++ b/externals/hcs/cursor-help.pd @@ -1,4 +1,4 @@ -#N canvas 0 31 659 523 10; +#N canvas 1 88 659 523 10; #X obj 388 293 pddp/pddplink http://tcl.tk/man/tcl8.5/TkCmd/cursors.htm ; #X text 273 276 Here's a complete list of the available cursors:; @@ -65,7 +65,7 @@ #X restore 509 309 pd image of all cursors; #X msg 328 124 clock; #X msg 288 124 arrow; -#N canvas 415 238 494 344 META 0; +#N canvas 413 246 494 344 META 0; #X text 12 155 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL v3; @@ -75,7 +75,7 @@ Wilkes for Pd version 0.42.; runmode_addpoint editmode_nothing editmode_connect editmode_disconnect ; #X text 12 115 OUTLET_0; -#X text 12 5 KEYWORDS control canvas-op needs_work (outlet?); +#X text 12 5 KEYWORDS control canvas-op user_input; #X restore 600 498 pd META; #X connect 2 0 8 1; #X connect 3 0 8 1; diff --git a/externals/hcs/cursor.c b/externals/hcs/cursor.c index 9f69d5f27..c9e6b1c49 100644 --- a/externals/hcs/cursor.c +++ b/externals/hcs/cursor.c @@ -5,6 +5,7 @@ pd.tk, or cursor reset method could be done in help patch */ #include <stdlib.h> #include <string.h> #include <m_pd.h> +#include <m_imp.h> #include "g_canvas.h" #define POLLTIME 10 @@ -30,117 +31,15 @@ typedef struct _cursor // t_outlet *status_outlet; // not used (yet?) } t_cursor; -static void create_namespace(void) -{ - sys_gui("if { [namespace exists ::hcs_cursor_class]} {\n"); - sys_gui(" puts stderr {WARNING: ::hcs_cursor_class namespace exists!}\n"); - sys_gui("} else {\n"); - sys_gui(" namespace eval ::hcs_cursor_class {\n"); - sys_gui(" variable continue_pollmotion 0\n"); - sys_gui(" variable last_x 0\n"); - sys_gui(" variable last_y 0\n"); - sys_gui(" }\n"); - sys_gui("}\n"); -} - -static void create_proc_test(void) -{ - sys_gui ("if {[info commands ::hcs_cursor_class::proc_test] eq {::hcs_cursor_class::proc_test}} {"); - sys_gui(" puts stderr {WARNING: ::hcs_cursor_class::proc_test exists!}\n"); - sys_gui("} else {\n"); - sys_gui(" proc ::hcs_cursor_class::proc_test {proc_name} {\n"); - sys_gui(" if {[info commands ::hcs_cursor_class::$proc_name] eq $proc_name} {\n"); - sys_gui(" puts stderr {WARNING: ::hcs_cursor_class::$proc_name exists!}\n"); - sys_gui(" return 1\n"); - sys_gui(" } else {\n"); - sys_gui(" return 0\n"); - sys_gui(" }\n"); - sys_gui(" }\n"); - sys_gui("}\n"); -} - -/* in Pd 0.43, the internal proc changed from 'pd' to 'pdsend' */ -static void create_legacy_pd (void) -{ - post("creating legacy 'pdsend' using legacy 'pd' proc"); - sys_gui("if {[info commands pdsend] ne {pdsend}} {\n"); - sys_gui(" proc pdsend {message} {pd $message}\n"); - sys_gui("}\n"); -} - -/* idea from #tcl for a Tcl unbind */ -static void create_unbind (void) -{ - sys_gui("if { ! [::hcs_cursor_class::proc_test unbind]} {"); - sys_gui(" proc ::hcs_cursor_class::unbind {tag event script} {\n"); - sys_gui(" set bind {}\n"); - sys_gui(" foreach x [split [bind $tag $event] \"\n\"] {\n"); - sys_gui(" if {$x != $script} {\n"); - sys_gui(" lappend bind $x\n"); - sys_gui(" }\n"); - sys_gui(" }\n"); - sys_gui(" bind $tag $event {}\n"); - sys_gui(" foreach x $bind {bind $tag $event $x}\n"); - sys_gui(" }\n"); - sys_gui("}\n"); -} - -static void create_button_proc(void) -{ - sys_gui ("if { ! [::hcs_cursor_class::proc_test button]} {"); - sys_gui (" proc ::hcs_cursor_class::button {button state} {\n"); - sys_vgui(" pd [concat %s button $button $state \\;]\n", - cursor_receive_symbol->s_name); - sys_gui (" }\n"); - sys_gui ("}\n"); -} - -static void create_mousewheel_proc(void) -{ - sys_gui ("if { ! [::hcs_cursor_class::proc_test mousewheel]} {"); - sys_gui (" proc ::hcs_cursor_class::mousewheel {delta} {\n"); - sys_vgui(" pd [concat %s mousewheel $delta \\;]\n", - cursor_receive_symbol->s_name); - sys_gui (" }\n"); - sys_gui ("}\n"); -} - -static void create_motion_proc(void) -{ - sys_gui("if { ![::hcs_cursor_class::proc_test motion]} {\n"); - sys_gui (" proc ::hcs_cursor_class::motion {x y} {\n"); - sys_gui (" if { $x != $::hcs_cursor_class::last_x \\\n"); - sys_gui (" || $y != $::hcs_cursor_class::last_y} {\n"); - sys_vgui(" pd [concat %s motion $x $y \\;]\n", - cursor_receive_symbol->s_name); - sys_gui (" set ::hcs_cursor_class::last_x $x\n"); - sys_gui (" set ::hcs_cursor_class::last_y $y\n"); - sys_gui (" }\n"); - sys_gui (" }\n"); - sys_gui ("}\n"); -} - -static void create_pollmotion_proc(void) -{ - sys_gui ("if { ![::hcs_cursor_class::proc_test pollmotion]} {\n"); - sys_gui (" proc ::hcs_cursor_class::pollmotion {} {\n"); - sys_vgui(" ::hcs_cursor_class::motion [winfo pointerx .] [winfo pointery .]\n"); - sys_gui (" if {$::hcs_cursor_class::continue_pollmotion != 0} { \n"); - sys_gui (" after 10 ::hcs_cursor_class::pollmotion\n"); - sys_gui (" }\n"); - sys_gui (" }\n"); - sys_gui ("}\n"); -} - static void cursor_setmethod(t_cursor *x, t_symbol *s, int argc, t_atom *argv) { - sys_vgui("set cursor_%s \"%s\"\n", s->s_name, atom_getsymbol(argv)->s_name); + sys_vgui("set ::cursor_%s \"%s\"\n", s->s_name, atom_getsymbol(argv)->s_name); canvas_setcursor(x->parent_canvas, 0); /* hack to refresh the cursor */ } static void cursor_bang(t_cursor *x) { - sys_vgui("pd [concat %s motion [winfo pointerxy .] \\;]\n", + sys_vgui("pdsend \"%s motion [winfo pointerxy .]\"", x->receive_symbol->s_name); } @@ -153,12 +52,8 @@ static void cursor_float(t_cursor *x, t_float f) x->am_polling = 0; cursor_instances_polling--; /* if no more objects are listening, stop sending the events */ - if (cursor_instances_polling == 0) { - sys_gui("set ::hcs_cursor_class::continue_pollmotion 0 \n"); - sys_gui("::hcs_cursor_class::unbind all <ButtonPress> {::hcs_cursor_class::button %b 1}\n"); - sys_gui("::hcs_cursor_class::unbind all <ButtonRelease> {::hcs_cursor_class::button %b 0}\n"); - sys_gui("::hcs_cursor_class::unbind all <MouseWheel> {::hcs_cursor_class::mousewheel %D}\n"); - } + if (cursor_instances_polling == 0) + sys_gui("::hcs::cursor::stoppolling \n"); pd_unbind(&x->x_obj.ob_pd, cursor_receive_symbol); } } else { @@ -167,13 +62,8 @@ static void cursor_float(t_cursor *x, t_float f) pd_bind(&x->x_obj.ob_pd, cursor_receive_symbol); cursor_instances_polling++; /* if this is the first instance to start, set up Tcl binding and polling */ - if (cursor_instances_polling == 1) { - sys_gui("set ::hcs_cursor_class::continue_pollmotion 1 \n"); - sys_gui("::hcs_cursor_class::pollmotion \n"); - sys_gui("bind all <ButtonPress> {+::hcs_cursor_class::button %b 1}\n"); - sys_gui("bind all <ButtonRelease> {+::hcs_cursor_class::button %b 0}\n"); - sys_gui("bind all <MouseWheel> {+::hcs_cursor_class::mousewheel %D}\n"); - } + if (cursor_instances_polling == 1) + sys_gui("::hcs::cursor::startpolling\n"); } } } @@ -271,14 +161,8 @@ void cursor_setup(void) class_addmethod(cursor_class, (t_method)cursor_setmethod, gensym("editmode_disconnect"), A_GIMME, 0); - create_namespace(); - create_proc_test(); -/* TODO figure this out once 0.43 is released */ -/* if(PD_MAJOR_VERSION == 0 && PD_MINOR_VERSION < 43) - create_legacy_pd();*/ - create_unbind(); - create_motion_proc(); - create_pollmotion_proc(); - create_mousewheel_proc(); - create_button_proc(); + sys_vgui("eval [read [open {%s/%s.tcl}]]\n", + cursor_class->c_externdir->s_name, + cursor_class->c_name->s_name); + sys_vgui("::hcs::cursor::setup %s\n", cursor_receive_symbol->s_name); } diff --git a/externals/hcs/folder_list.c b/externals/hcs/folder_list.c index fe4769249..b0f2f9787 100644 --- a/externals/hcs/folder_list.c +++ b/externals/hcs/folder_list.c @@ -1,7 +1,7 @@ /* --------------------------------------------------------------------------*/ /* */ /* object for getting file listings using wildcard patterns */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006 Hans-Christoph Steiner */ /* */ @@ -188,10 +188,11 @@ static void folder_list_set(t_folder_list* x, t_symbol *s) char envVarBuffer[FILENAME_MAX]; if( (s->s_name[0] == '~') && (s->s_name[1] == '/')) { + // TODO this is probably never freed! patternBuffer = getbytes(FILENAME_MAX); strcpy(patternBuffer,"%USERPROFILE%"); strncat(patternBuffer, s->s_name + 1, FILENAME_MAX - 1); - post("set: %s", patternBuffer); + verbose(-1, "set: %s", patternBuffer); } else { @@ -237,7 +238,7 @@ static void *folder_list_new(t_symbol *s) strncpy(buffer,currentdir->s_name,MAXPDSTRING); strncat(buffer,"/*",MAXPDSTRING); x->x_pattern = gensym(buffer); - post("setting pattern to default: %s",x->x_pattern->s_name); + logpost(x, 3, "setting pattern to default: %s",x->x_pattern->s_name); } return (x); diff --git a/externals/hcs/group.c b/externals/hcs/group.c index 298ce164d..a19d736e6 100644 --- a/externals/hcs/group.c +++ b/externals/hcs/group.c @@ -1,7 +1,7 @@ /* --------------------------------------------------------------------------*/ /* */ /* converts a GID number to a user name symbol */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006 Hans-Christoph Steiner */ /* */ @@ -42,8 +42,6 @@ static char *version = "$Revision: 1.3 $"; -t_int group_instance_count; - #define DEBUG(x) //#define DEBUG(x) x @@ -213,13 +211,6 @@ static void *group_new(t_symbol *s, int argc, t_atom *argv) t_group *x = (t_group *)pd_new(group_class); - if(!group_instance_count) - { - post("[group] %s",version); - post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - } - group_instance_count++; floatinlet_new(&x->x_obj, &x->x_gid); x->x_data_outlet = outlet_new(&x->x_obj, 0); @@ -260,6 +251,9 @@ void group_setup(void) gensym("set"), A_GIMME, 0); + logpost(NULL, 4, "[group] %s",version); + logpost(NULL, 4, "\twritten by Hans-Christoph Steiner <hans@eds.org>"); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); } #endif /* NOT _WIN32 */ diff --git a/externals/hcs/helppath.c b/externals/hcs/helppath.c index 1fb05c2a6..fd0382bae 100644 --- a/externals/hcs/helppath.c +++ b/externals/hcs/helppath.c @@ -128,9 +128,9 @@ void helppath_setup(void) class_addmethod(helppath_class,(t_method) helppath_add,gensym("add"), A_DEFSYMBOL, 0); - post("[helppath] %s", version); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - post("\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, - PD_MINOR_VERSION, PD_BUGFIX_VERSION); + logpost(NULL, 4, "[helppath] %s", version); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); + logpost(NULL, 4, "\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, + PD_MINOR_VERSION, PD_BUGFIX_VERSION); } diff --git a/externals/hcs/keyboard_layout-help.pd b/externals/hcs/keyboard_layout-help.pd deleted file mode 100644 index 9b0a01c33..000000000 --- a/externals/hcs/keyboard_layout-help.pd +++ /dev/null @@ -1,37 +0,0 @@ -#N canvas 0 26 553 346 10; -#X msg 116 32 bang; -#X msg 144 63 menu; -#X obj 242 244 flatspace/popup 124 25 #ffffff _ option; -#X msg 141 209 options; -#X obj 203 163 route clear; -#X symbolatom 116 277 0 0 0 0 - - -; -#X text 183 64 see all options in the popup menu; -#X obj 308 111 symbol; -#X text 250 283 select a new input method with the popup menu; -#X obj 202 185 bang; -#X msg 197 208 name language; -#N canvas 231 99 494 344 META 0; -#X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan -Wilkes for Pd version 0.42.; -#X text 12 25 LICENSE GPL v3; -#X text 12 125 AUTHOR Hans-Christoph Steiner; -#X text 12 5 KEYWORDS control GUI needs_work (object won't create) -; -#X text 12 45 DESCRIPTION needs a description; -#X text 12 65 INLET_0 bang menu symbol; -#X text 12 85 OUTLET_0; -#X text 12 105 OUTLET_1; -#X restore 502 322 pd META; -#X obj 116 144 keyboard_layout; -#X connect 0 0 12 0; -#X connect 1 0 12 0; -#X connect 2 1 7 0; -#X connect 3 0 2 0; -#X connect 4 0 9 0; -#X connect 4 1 2 0; -#X connect 7 0 12 0; -#X connect 9 0 3 0; -#X connect 9 0 10 0; -#X connect 10 0 2 0; -#X connect 12 0 5 0; -#X connect 12 1 4 0; diff --git a/externals/hcs/keyboard_layout.c b/externals/hcs/keyboard_layout.c deleted file mode 100644 index b51168cff..000000000 --- a/externals/hcs/keyboard_layout.c +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright 2006 Fredrik Olofsson - * Copyright 2007 Free Software Foundation - * ported to Pd by Hans-Christoph Steiner <hans@at.or.at> from f0.keyboard_layout.c - */ - -#include "m_pd.h" -#ifdef __APPLE__ -#include <Carbon/Carbon.h> -#endif - -static t_class *keyboard_layout_class; - -typedef struct _keyboard_layout { - t_object x_obj; - t_outlet* x_data_outlet; - t_outlet* x_status_outlet; -} t_keyboard_layout; - -#ifdef __APPLE__ - -//---------------------------------------------------------------------------------------------- -void keyboard_layout_bang(t_keyboard_layout *x) { - //OSStatus err; - KeyboardLayoutRef currentLayoutRef; - const void *keyboardName; - char cKeyboardName[100]; - - KLGetCurrentKeyboardLayout(¤tLayoutRef); - KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); - CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); - - outlet_symbol(x->x_data_outlet, gensym(cKeyboardName)); -} - -void keyboard_layout_menu(t_keyboard_layout *x) { - //OSStatus err; - KeyboardLayoutRef currentLayoutRef; - const void *keyboardName; - char cKeyboardName[100]; - CFIndex countOfLayouts; - CFIndex i; - t_atom name; - -// TODO this should probably output [menu clear( so other messages work too - outlet_anything(x->x_status_outlet, gensym("clear"), 0, NULL); - - KLGetKeyboardLayoutCount(&countOfLayouts); - for(i= 0; i<countOfLayouts; i++) { - KLGetKeyboardLayoutAtIndex(i, ¤tLayoutRef); - KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); - CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); - - SETSYMBOL(&name, gensym(cKeyboardName)); -// TODO this should probably output [menu append( so other messages work too - outlet_anything(x->x_status_outlet, gensym("append"), 1, &name); - } -} - -void keyboard_layout_anything(t_keyboard_layout *x, t_symbol *s, short argc, t_atom *argv) { - //OSStatus err; - KeyboardLayoutRef currentLayoutRef; - const void *keyboardName; - char cKeyboardName[100]; - - keyboardName= CFStringCreateWithCString(NULL, s->s_name, kCFStringEncodingASCII); - KLGetKeyboardLayoutWithName(keyboardName, ¤tLayoutRef); - KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); - CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); - KLSetCurrentKeyboardLayout(currentLayoutRef); - //outlet_anything(x->t_out, s, 0, NULL); - keyboard_layout_bang(x); -} - -void *keyboard_layout_new(void) { - t_keyboard_layout *x = (t_keyboard_layout *)pd_new(keyboard_layout_class); - - x->x_data_outlet = outlet_new(&x->x_obj, &s_float); - x->x_status_outlet = outlet_new(&x->x_obj, &s_symbol); - - return (x); -} - -//---------------------------------------------------------------------------------------------- -void keyboard_layout_setup(void) { - keyboard_layout_class = class_new(gensym("keyboard_layout"), - (t_newmethod)keyboard_layout_new, - NULL, - sizeof(t_keyboard_layout), - 0, A_GIMME, 0); - - class_addbang(keyboard_layout_class, (t_method)keyboard_layout_bang); - class_addanything(keyboard_layout_class, (t_method)keyboard_layout_anything); - - class_addmethod(keyboard_layout_class, (t_method)keyboard_layout_menu, - gensym("menu"), 0); - - post("f0.keyboard_layout v1.1-ub; distributed under GNU GPL license"); -} - - -#else /* GNU/Linux and Windows */ - - -void keyboard_layout_new(void) -{ - post("f0.keyboard_layout v1.1-ub; distributed under GNU GPL license"); - post("ERROR: this objectclass is currently only for Mac OS X"); -} - -void keyboard_layout_setup(void) -{ - keyboard_layout_class = class_new(gensym("text"), (t_method)keyboard_layout_new, - NULL, sizeof(t_keyboard_layout), 0, 0); -} - -#endif /* __APPLE__ */ diff --git a/externals/hcs/passwd.c b/externals/hcs/passwd.c index 8045bb3f6..0be2ca859 100644 --- a/externals/hcs/passwd.c +++ b/externals/hcs/passwd.c @@ -1,7 +1,7 @@ /* --------------------------------------------------------------------------*/ /* */ /* converts a UID number to a user name symbol */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006 Hans-Christoph Steiner */ /* */ @@ -41,8 +41,6 @@ static char *version = "$Revision: 1.3 $"; -t_int passwd_instance_count; - #define DEBUG(x) //#define DEBUG(x) x @@ -162,14 +160,6 @@ static void *passwd_new(t_symbol *s, int argc, t_atom *argv) t_passwd *x = (t_passwd *)pd_new(passwd_class); - if(!passwd_instance_count) - { - post("[passwd] %s",version); - post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - } - passwd_instance_count++; - floatinlet_new(&x->x_obj, &x->x_uid); x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); @@ -209,6 +199,10 @@ void passwd_setup(void) gensym("set"), A_GIMME, 0); + + logpost(NULL, 4, "[passwd] %s",version); + logpost(NULL, 4, "\twritten by Hans-Christoph Steiner <hans@eds.org>"); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); } #endif /* NOT _WIN32 */ diff --git a/externals/hcs/screensize.c b/externals/hcs/screensize.c index 5a795d970..e742ea693 100644 --- a/externals/hcs/screensize.c +++ b/externals/hcs/screensize.c @@ -14,7 +14,7 @@ typedef struct _screensize static void screensize_bang(t_screensize *x) { - sys_vgui("pd [concat %s screensize [winfo screenwidth .] [winfo screenheight .] \\;]\n", + sys_vgui("pdsend \"%s screensize [winfo screenwidth .] [winfo screenheight .]\"\n", x->receive_symbol->s_name); } diff --git a/externals/hcs/split_path.c b/externals/hcs/split_path.c index dfd8c67f0..5a8626988 100644 --- a/externals/hcs/split_path.c +++ b/externals/hcs/split_path.c @@ -1,6 +1,6 @@ /* (C) Guenter Geiger <geiger@epy.co.at> */ -/* I started with stripdir.c and turned it into split_path.c <hans@at.or.at> */ +/* I started with stripdir.c and turned it into split_path.c <hans@eds.org> */ #include <m_pd.h> #include <string.h> @@ -13,8 +13,6 @@ static char *version = "$Revision: 1.1 $"; -t_int split_path_instance_count; - /* ------------------------ split_path ----------------------------- */ static t_class *split_path_class; @@ -60,12 +58,6 @@ static void *split_path_new() t_split_path *x = (t_split_path *)pd_new(split_path_class); x->x_path_outlet = (t_outlet *)outlet_new(&x->x_obj, &s_symbol); x->x_filename_outlet = (t_outlet *)outlet_new(&x->x_obj, &s_symbol); - if(!split_path_instance_count) - { - post("[split_path] %s",version); - post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); - } - split_path_instance_count++; return (x); } @@ -74,6 +66,8 @@ void split_path_setup(void) split_path_class = class_new(gensym("split_path"), (t_newmethod)split_path_new, 0, sizeof(t_split_path), 0,0); class_addsymbol(split_path_class,split_path_symbol); + logpost(NULL, 4, "[split_path] %s",version); + logpost(NULL, 4, "\twritten by Hans-Christoph Steiner <hans@eds.org>"); } diff --git a/externals/hcs/sql_query-help.pd b/externals/hcs/sql_query-help.pd index e21f2b9f7..e65e2e0a6 100644 --- a/externals/hcs/sql_query-help.pd +++ b/externals/hcs/sql_query-help.pd @@ -1,4 +1,4 @@ -#N canvas 0 26 562 464 10; +#N canvas 1 96 562 464 10; #X obj 342 184 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144 -1 -1 0 1; #X floatatom 400 216 5 0 0 0 - - -; @@ -34,7 +34,7 @@ #X msg 323 18 4; #X obj 98 95 pddp/print; #X obj 323 71 pddp/print; -#N canvas 453 163 494 344 META 0; +#N canvas 447 187 494 344 META 0; #X text 12 165 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL v3; @@ -44,7 +44,7 @@ Wilkes for Pd version 0.42.; #X text 12 105 OUTLET_0; #X text 12 125 OUTLET_1; #X text 12 65 INLET_0; -#X text 12 5 KEYWORDS control needs_work (xlets&description); +#X text 12 5 KEYWORDS control; #X restore 513 443 pd META; #X connect 0 0 11 1; #X connect 1 0 11 1; diff --git a/externals/hcs/sql_query.c b/externals/hcs/sql_query.c index 8d230f042..bb0420e4b 100644 --- a/externals/hcs/sql_query.c +++ b/externals/hcs/sql_query.c @@ -1,6 +1,6 @@ /* * object for generating SQL queries with SQL ? placeholders - * Written by Hans-Christoph Steiner <hans@at.or.at> + * Written by Hans-Christoph Steiner <hans@eds.org> * * Copyright (c) 2007 Free Software Foundation * diff --git a/externals/hcs/stat-help.pd b/externals/hcs/stat-help.pd index cfc4db5a9..d91baf78a 100644 --- a/externals/hcs/stat-help.pd +++ b/externals/hcs/stat-help.pd @@ -1,4 +1,4 @@ -#N canvas 0 26 577 526 10; +#N canvas 1 88 577 526 10; #X msg 108 68 bang; #X text 150 68 run on current folder; #X symbolatom 6 470 0 0 0 3 filename - -; @@ -69,7 +69,7 @@ on its right outlet:; #X text 47 242 unknown; #X restore 398 218 pd possible errors; #X text 8 3 [stat] gets information about files; -#N canvas 280 175 494 344 META 0; +#N canvas 278 183 494 344 META 0; #X text 12 165 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL v3; @@ -79,7 +79,7 @@ Wilkes for Pd version 0.42.; #X text 12 85 INLET_1; #X text 12 105 OUTLET_0 anything; #X text 12 125 OUTLET_1 anything; -#X text 12 5 KEYWORDS control needs_work (xlets); +#X text 12 5 KEYWORDS control; #X restore 528 505 pd META; #X obj 270 405 gid2group_name; #X connect 0 0 21 0; diff --git a/externals/hcs/stat.c b/externals/hcs/stat.c index 06a4295df..cd63daba5 100644 --- a/externals/hcs/stat.c +++ b/externals/hcs/stat.c @@ -1,7 +1,7 @@ /* --------------------------------------------------------------------------*/ /* */ /* object for getting file type (dir, link, exe, etc) using a filename */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006 Hans-Christoph Steiner */ /* */ @@ -40,8 +40,6 @@ static char *version = "$Revision: 1.5 $"; -t_int stat_instance_count; - #define DEBUG(x) //#define DEBUG(x) x @@ -264,15 +262,6 @@ static void *stat_new(t_symbol *s) t_stat *x = (t_stat *)pd_new(stat_class); - if(!stat_instance_count) - { - post("[stat] %s",version); - post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - } - stat_instance_count++; - - symbolinlet_new(&x->x_obj, &x->x_filename); x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); @@ -308,5 +297,8 @@ void stat_setup(void) /* add inlet message methods */ class_addmethod(stat_class,(t_method) stat_set,gensym("set"), A_DEFSYM, 0); + logpost(NULL, 4, "[stat] %s",version); + logpost(NULL, 4, "\twritten by Hans-Christoph Steiner <hans@eds.org>"); + logpost(NULL, 4, "\tcompiled on "__DATE__" at "__TIME__ " "); } diff --git a/externals/hcs/sys_gui-help.pd b/externals/hcs/sys_gui-help.pd index ede38f068..c8699e38f 100644 --- a/externals/hcs/sys_gui-help.pd +++ b/externals/hcs/sys_gui-help.pd @@ -1,4 +1,4 @@ -#N canvas 196 22 620 614 10; +#N canvas 194 88 620 614 10; #X obj 78 213 sys_gui; #X text 136 59 open the help browser; #X msg 51 93 set text_color #f0f; @@ -110,7 +110,7 @@ are Tcl/Tk commands from the pd to the Pg GUI process.; #X connect 5 0 4 0; #X connect 5 1 4 1; #X restore 170 489 pd pak ------------------; -#N canvas 280 175 494 344 META 0; +#N canvas 278 183 494 344 META 0; #X text 12 65 PLATFORM windows macosx gnulinux; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; @@ -120,7 +120,7 @@ Wilkes for Pd version 0.42.; ; #X text 12 85 INLET_0 anything; #X text 12 105 OUTLET_0; -#X text 12 5 KEYWORDS control pd_op needs_work (outlet?); +#X text 12 5 KEYWORDS control pd_op; #X restore 512 562 pd META; #X obj 78 236 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; diff --git a/externals/hcs/sys_gui.c b/externals/hcs/sys_gui.c index 570e1ea92..753c19027 100644 --- a/externals/hcs/sys_gui.c +++ b/externals/hcs/sys_gui.c @@ -3,64 +3,72 @@ #include <m_pd.h> #include "g_canvas.h" -#define DEBUG(x) - static t_class *sys_gui_class; typedef struct _sys_gui { t_object x_obj; + t_symbol* x_receive_symbol; + t_outlet* x_outlet; char *send_buffer; } t_sys_gui; -static void sys_gui_bang(t_sys_gui *x) +static void execute_buffer(t_sys_gui *x, int argc, t_atom *argv) { - sys_gui(x->send_buffer); -} - -static void sys_gui_anything(t_sys_gui *x, t_symbol *s, int argc, t_atom *argv) -{ - DEBUG(post("sys_gui_anything");); int i = 0; char buf[MAXPDSTRING]; - snprintf(x->send_buffer, MAXPDSTRING, "%s ", s->s_name); for(i=0;i<argc;++i) { atom_string(argv + i, buf, MAXPDSTRING); strncat(x->send_buffer, buf, MAXPDSTRING - strlen(x->send_buffer)); strncat(x->send_buffer, " ", MAXPDSTRING - strlen(x->send_buffer)); } - strncat(x->send_buffer, " ;\n", 3); + strncat(x->send_buffer, " ;\n", MAXPDSTRING - strlen(x->send_buffer)); + snprintf(buf, MAXPDSTRING - strlen(x->send_buffer), + "pdsend \"%s finished\";\n", x->x_receive_symbol->s_name ); + strncat(x->send_buffer, buf, MAXPDSTRING - strlen(x->send_buffer)); sys_gui(x->send_buffer); } -static void sys_gui_list(t_sys_gui *x, t_symbol *s, int argc, t_atom *argv) +static void sys_gui_bang(t_sys_gui *x) { - DEBUG(post("sys_gui_list");); - int i = 0; - char buf[MAXPDSTRING]; - - for(i=0;i<argc;++i) - { - atom_string(argv + i, buf, MAXPDSTRING); - strncat(x->send_buffer, buf, MAXPDSTRING - strlen(x->send_buffer)); - strncat(x->send_buffer, " ", MAXPDSTRING - strlen(x->send_buffer)); - } - strncat(x->send_buffer, " ;\n", 3); sys_gui(x->send_buffer); } +static void sys_gui_finished(t_sys_gui *x) +{ + outlet_bang(x->x_outlet); +} + +static void sys_gui_anything(t_sys_gui *x, t_symbol *s, int argc, t_atom *argv) +{ + snprintf(x->send_buffer, MAXPDSTRING, "%s ", s->s_name); + execute_buffer(x, argc, argv); +} + +static void sys_gui_list(t_sys_gui *x, t_symbol *s, int argc, t_atom *argv) +{ + x->send_buffer = '\0'; + execute_buffer(x, argc, argv); +} + static void sys_gui_free(t_sys_gui *x) { + pd_unbind(&x->x_obj.ob_pd, x->x_receive_symbol); freebytes(x->send_buffer,MAXPDSTRING); } static void *sys_gui_new(t_symbol *s) { t_sys_gui *x = (t_sys_gui *)pd_new(sys_gui_class); + x->x_outlet = outlet_new(&x->x_obj, &s_anything); + + char buf[MAXPDSTRING]; + sprintf(buf, "#%lx", (t_int)x); + x->x_receive_symbol = gensym(buf); + pd_bind(&x->x_obj.ob_pd, x->x_receive_symbol); - outlet_new(&x->x_obj, &s_anything); x->send_buffer = (char *)getbytes(MAXPDSTRING); return(x); @@ -68,11 +76,17 @@ static void *sys_gui_new(t_symbol *s) void sys_gui_setup(void) { - sys_gui_class = class_new(gensym("sys_gui"), - (t_newmethod)sys_gui_new, (t_method)sys_gui_free, - sizeof(t_sys_gui), 0, 0); + sys_gui_class = class_new( + gensym("sys_gui"), + (t_newmethod)sys_gui_new, + (t_method)sys_gui_free, + sizeof(t_sys_gui), + 0, + 0); class_addanything(sys_gui_class, (t_method)sys_gui_anything); class_addbang(sys_gui_class, (t_method)sys_gui_bang); class_addlist(sys_gui_class, (t_method)sys_gui_list); + class_addmethod(sys_gui_class, (t_method)sys_gui_finished, + gensym("finished"), 0); } diff --git a/externals/hcs/uname.c b/externals/hcs/uname.c index 8fd2bfa90..4c75000e5 100644 --- a/externals/hcs/uname.c +++ b/externals/hcs/uname.c @@ -1,7 +1,7 @@ /* --------------------------------------------------------------------------*/ /* */ /* object for getting uname info */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006,2010 Hans-Christoph Steiner */ /* */ diff --git a/externals/hcs/version.c b/externals/hcs/version.c index f78fd2dbc..fd1fe1cc3 100644 --- a/externals/hcs/version.c +++ b/externals/hcs/version.c @@ -3,7 +3,7 @@ /* object for getting the version of Pd-extended */ /* (it gets the version at compile time, so it will show the version of Pd */ /* that is was compiled against) */ -/* Written by Hans-Christoph Steiner <hans@at.or.at> */ +/* Written by Hans-Christoph Steiner <hans@eds.org> */ /* */ /* Copyright (c) 2006, 2010 Hans-Christoph Steiner */ /* */ diff --git a/externals/hcs/window_name.c b/externals/hcs/window_name.c index 6292f2675..0528e9fa2 100644 --- a/externals/hcs/window_name.c +++ b/externals/hcs/window_name.c @@ -6,71 +6,96 @@ #define DEBUG(x) static t_class *window_name_class; -static t_canvas *canvas; typedef struct _window_name { - t_object x_obj; - t_atom x_atom; - t_symbol *x_window_name; - t_symbol *x_remote_name; + t_object x_obj; + t_canvas *x_canvas; + t_symbol *receive_name; + t_int depth; } t_window_name; -static void window_name_bang(t_window_name *x) +static t_symbol* make_canvas_symbol(t_canvas* canvas) { - if (x->x_atom.a_type == A_SYMBOL) - { - canvas=(t_canvas *)pd_findbyclass(x->x_remote_name, canvas_class); char buf[MAXPDSTRING]; - snprintf(buf, MAXPDSTRING, ".x%lx", (long unsigned int)canvas); - x->x_window_name = gensym(buf); - } - outlet_symbol(x->x_obj.ob_outlet,x->x_window_name); + return gensym(buf); } -static void *window_name_new(t_symbol *s, int argc, t_atom *argv) +static t_symbol* get_canvas_by_depth(t_window_name *x) { - t_atom a; - if (argc == 0) + t_canvas *canvas = x->x_canvas; + int depth = x->depth; + if(depth<0)depth=0; + while(depth && canvas) { - argc = 1; - SETFLOAT(&a, 0); - argv = &a; + canvas = canvas->gl_owner; + depth--; } - t_window_name *x = (t_window_name *)pd_new(window_name_class); - x->x_atom = *argv; - if (argv->a_type == A_FLOAT) - { // thx to IOhannes's iemguts: - t_glist *glist=(t_glist *)canvas_getcurrent(); - canvas=(t_canvas *)glist_getcanvas(glist); - int depth=(int)atom_getint(&x->x_atom); + return make_canvas_symbol(canvas); +} - if(depth<0)depth=0; - while(depth && canvas->gl_owner) { - canvas=canvas->gl_owner; - depth--; - } - char buf[MAXPDSTRING]; +static t_symbol* get_canvas_by_name(t_window_name *x) +{ + return make_canvas_symbol((t_canvas *)pd_findbyclass(x->receive_name, canvas_class)); +} - snprintf(buf, MAXPDSTRING, ".x%lx", (long unsigned int)canvas); - x->x_window_name = gensym(buf); - } +static t_symbol* get_window_name(t_window_name *x) +{ + if(x->receive_name == &s_) + return get_canvas_by_depth(x); else - { - x->x_remote_name = (t_symbol *)atom_getsymbol(&x->x_atom); - } + return get_canvas_by_name(x); +} + +static void window_name_bang(t_window_name *x) +{ + /* actually get the canvas name each time to make sure we get + * accurate info in case of changes. If we cache the result, a + * canvas could have been deleted or renamed. */ + outlet_symbol(x->x_obj.ob_outlet, get_window_name(x)); +} + +static void window_name_anything(t_window_name *x, t_symbol *s, int argc, t_atom *argv) +{ + t_symbol *first_symbol = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(s == &s_float) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else if (first_symbol == &s_) + x->receive_name = s; + else + x->receive_name = first_symbol; + window_name_bang(x); +} + +static void *window_name_new(t_symbol *s, int argc, t_atom *argv) +{ + t_window_name *x = (t_window_name *)pd_new(window_name_class); + + t_glist* glist = (t_glist *)canvas_getcurrent(); + x->x_canvas = (t_canvas *)glist_getcanvas(glist); + + t_symbol *tmp = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(tmp == &s_) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else + x->receive_name = tmp; - outlet_new(&x->x_obj, &s_symbol); + outlet_new(&x->x_obj, &s_symbol); return(x); } void window_name_setup(void) { - window_name_class = class_new(gensym("window_name"), - (t_newmethod)window_name_new, NULL, + window_name_class = class_new(gensym("window_name"), + (t_newmethod)window_name_new, NULL, sizeof(t_window_name), 0, A_GIMME, 0); class_addbang(window_name_class, (t_method)window_name_bang); + class_addanything(window_name_class, (t_method)window_name_anything); } -- GitLab