aboutsummaryrefslogtreecommitdiff
path: root/composer
diff options
context:
space:
mode:
authormescalinum <mescalinum@users.sourceforge.net>2009-09-25 22:49:47 +0000
committermescalinum <mescalinum@users.sourceforge.net>2009-09-25 22:49:47 +0000
commit6b894cab3b6e3c1ba966025a32dd0d2cd057ae7c (patch)
treed885b3231ea486230cf989994345f1531e0d73e7 /composer
parentf8ac52e520aa5e20a256a3fd9a649b461f3afeef (diff)
add editor: old code, new black magic (comm protocol still to implement)
svn path=/trunk/externals/ffext/; revision=12452
Diffstat (limited to 'composer')
-rw-r--r--composer/Editor.cpp74
-rw-r--r--composer/Editor.hpp10
-rw-r--r--composer/Makefile14
-rw-r--r--composer/PdClasses.cpp53
-rw-r--r--composer/PdClasses.hpp26
5 files changed, 148 insertions, 29 deletions
diff --git a/composer/Editor.cpp b/composer/Editor.cpp
new file mode 100644
index 0000000..c56d853
--- /dev/null
+++ b/composer/Editor.cpp
@@ -0,0 +1,74 @@
+#include "Editor.hpp"
+#include "Track.hpp"
+#include "Song.hpp"
+
+#include <iostream>
+#include <string>
+
+#include <m_pd.h>
+
+#include "editor_tk.cpp"
+static const int editor_tk_len = sizeof(editor_tk) / sizeof(editor_tk[0]);
+
+using std::cerr;
+using std::endl;
+using std::string;
+
+static char hexnibble(unsigned int i)
+{
+ i &= 0xf;
+ return (i < 0xa) ? ('0' + i) : ('a' + i - 0xa);
+}
+
+static const char* urlencode(char c)
+{
+ static char buf[4];
+ buf[0] = '%';
+ buf[1] = hexnibble((c & 0xf0) >> 4);
+ buf[2] = hexnibble(c & 0xf);
+ buf[3] = '\0';
+ return &buf[0];
+}
+
+void Editor::uploadCode()
+{
+ sys_gui("proc Xeval {c {d {}}} {switch $c {begin {set ::Xeval_map {}; for {set i 0} {$i < 256} {incr i} {lappend ::Xeval_map \%[format \%02x $i] [format \%c $i]}; set ::Xeval_data {}} data {append ::Xeval_data [string map $::Xeval_map $d]\\n} end {uplevel #0 $::Xeval_data; unset ::Xeval_map; unset ::Xeval_data}}}\n");
+ sys_gui("Xeval begin\n");
+ for(int i = 0; i < editor_tk_len; i++)
+ {
+ string s = "Xeval data {";
+ string l = editor_tk[i];
+ for(int j = 0; j < l.length(); j++)
+ {
+ if(isalnum(l[j])) s.append(1, l[j]);
+ else s += string(urlencode(l[j]));
+ }
+ s += "}\n";
+ sys_gui(const_cast<char*>(s.c_str()));
+ }
+ sys_gui("Xeval end\n");
+}
+
+void Editor::init(t_track_proxy *x)
+{
+ uploadCode();
+ sys_vgui("pd::composer::init %s %s %s %d %s %d\n",
+ x->editor_recv->s_name,
+ x->track->getSong()->getName().c_str(),
+ x->track->getName().c_str(),
+ 16,
+ "NULL",
+ 1);
+}
+
+void Editor::openWindow(t_track_proxy *x)
+{
+ x->editor_open = 1;
+ sys_vgui("pd::composer::openWindow %s\n", x->editor_recv->s_name);
+}
+
+void Editor::closeWindow(t_track_proxy *x)
+{
+ x->editor_open = 0;
+ sys_vgui("pd::composer::closeWindow %s\n", x->editor_recv->s_name);
+}
diff --git a/composer/Editor.hpp b/composer/Editor.hpp
new file mode 100644
index 0000000..9364320
--- /dev/null
+++ b/composer/Editor.hpp
@@ -0,0 +1,10 @@
+#include "PdClasses.hpp"
+
+class Editor
+{
+public:
+ static void uploadCode();
+ static void init(t_track_proxy *x);
+ static void openWindow(t_track_proxy *x);
+ static void closeWindow(t_track_proxy *x);
+};
diff --git a/composer/Makefile b/composer/Makefile
index dff36ef..5825813 100644
--- a/composer/Makefile
+++ b/composer/Makefile
@@ -28,7 +28,7 @@ endif
LIBNAME = composer
INCLUDES = -I../../pd/src -I/usr/include #-I/usr/include/tcl$(TCL_VERSION)
-CFLAGS += -funroll-loops -fno-operator-names -fno-omit-frame-pointer -falign-functions=16 -Wall -fPIC
+CFLAGS += -funroll-loops -fno-operator-names -fno-omit-frame-pointer -falign-functions=16 -Wno-deprecated -fPIC
CFLAGS += -DPDSUF=\"$(PDSUF)\"
LDSHARED = $(CXX) $(PDBUNDLEFLAGS)
@@ -38,17 +38,23 @@ all: $(LIBNAME)$(PDSUF)
'[size: '`ls -gGh $(LIBNAME)$(PDSUF) | cut -d " " -f 3`']'
clean::
- rm -f $(LIBNAME)$(PDSUF) *.o *~
+ rm -f $(LIBNAME)$(PDSUF) editor_tk.cpp *.o *~
.SUFFIXES: .cpp .o
-SRCS = Song.cpp Pattern.cpp Track.cpp PdClasses.cpp
+SRCS = Song.cpp Pattern.cpp Track.cpp Editor.o PdClasses.cpp
OBJS = ${SRCS:.cpp=.o}
+editor_tk.cpp: editor.tk
+ ( echo 'static const char* editor_tk[] = {'; \
+ sed -e 's/\(["\\]\)/\\\1/g' -e 's/^/"/' -e 's/$$/",/' \
+ editor.tk; echo '"" };' ) > editor_tk.cpp
+
Song.o: Song.cpp Song.hpp
Pattern.o: Pattern.cpp Pattern.hpp
Track.o: Track.cpp Track.hpp
-PdClass.o: PdClasses.cpp PdClasses.h
+Editor.o: Editor.cpp Editor.hpp editor_tk.cpp
+PdClass.o: PdClasses.cpp PdClasses.hpp
.cpp.o: Makefile
$(CXX) $(CFLAGS) $(INCLUDES) -xc++ -c $<
diff --git a/composer/PdClasses.cpp b/composer/PdClasses.cpp
index d8ca17a..3d38c98 100644
--- a/composer/PdClasses.cpp
+++ b/composer/PdClasses.cpp
@@ -2,6 +2,7 @@
#include "Song.hpp"
#include "Track.hpp"
#include "Pattern.hpp"
+#include "Editor.hpp"
#include <iostream>
@@ -27,6 +28,8 @@ void track_proxy_setup(void)
CLASS_DEFAULT,
A_SYMBOL, A_SYMBOL, A_NULL
);
+ class_addmethod(track_proxy_class, (t_method)track_proxy_editor, \
+ gensym("editor"), A_FLOAT, A_NULL);
class_addmethod(track_proxy_class, (t_method)track_proxy_getpatterns, \
gensym("getpatterns"), A_NULL);
class_addmethod(track_proxy_class, (t_method)track_proxy_getpatternsize, \
@@ -46,13 +49,13 @@ void track_proxy_setup(void)
/* class_addmethod(track_proxy_class, (t_method)track_proxy_data, \
gensym("data"), A_GIMME, A_NULL);*/
#if PD_MINOR_VERSION >= 37
- //class_setpropertiesfn(track_proxy_class, track_proxy_properties);
+ class_setpropertiesfn(track_proxy_class, track_proxy_properties);
class_setsavefn(track_proxy_class, track_proxy_save);
#endif
class_sethelpsymbol(track_proxy_class, gensym("track.pd"));
}
-static t_track_proxy *track_proxy_new(t_symbol *song_name, t_symbol *track_name)
+t_track_proxy *track_proxy_new(t_symbol *song_name, t_symbol *track_name)
{
t_track_proxy *x = (t_track_proxy*)pd_new(track_proxy_class);
x->outlet = outlet_new(&x->x_obj, &s_list);
@@ -73,10 +76,12 @@ static t_track_proxy *track_proxy_new(t_symbol *song_name, t_symbol *track_name)
// bind to TRACK_SELECTOR for loading in-patch data
pd_bind(&x->x_obj.ob_pd, gensym(TRACK_SELECTOR));
+ Editor::init(x);
+
return x;
}
-static void track_proxy_free(t_track_proxy *x)
+void track_proxy_free(t_track_proxy *x)
{
pd_unbind(&x->x_obj.ob_pd, gensym(TRACK_SELECTOR));
/* LATER find a way to get TRACK_SELECTOR unbound earlier (at end of load?) */
@@ -87,7 +92,7 @@ static void track_proxy_free(t_track_proxy *x)
pd_unbind(&x->x_obj.ob_pd, x->editor_recv);
}
-static void track_proxy_save(t_gobj *z, t_binbuf *b)
+void track_proxy_save(t_gobj *z, t_binbuf *b)
{
t_track_proxy *x = (t_track_proxy*)z;
Track *t = x->track;
@@ -131,7 +136,14 @@ static void track_proxy_save(t_gobj *z, t_binbuf *b)
binbuf_addv(b, "sss;", gensym(TRACK_SELECTOR), gensym("data"), gensym("end"));
}
-static void track_proxy_send_result(t_track_proxy *x, int outlet, int editor)
+void track_proxy_properties(t_gobj *z, t_glist *owner)
+{
+ t_track_proxy *x = (t_track_proxy *) z;
+ if(!x->editor_open) Editor::openWindow(x);
+ else Editor::closeWindow(x);
+}
+
+void track_proxy_send_result(t_track_proxy *x, int outlet, int editor)
{
if(result_argc <= 0) return;
if(outlet)
@@ -143,7 +155,22 @@ static void track_proxy_send_result(t_track_proxy *x, int outlet, int editor)
}
}
-static int track_proxy_getpatterns(t_track_proxy *x)
+int track_proxy_editor(t_track_proxy *x, t_floatarg arg)
+{
+ t_int a = (t_int) arg;
+ if(a < 0)
+ {
+ if(!x->editor_open) Editor::openWindow(x);
+ else Editor::closeWindow(x);
+ }
+ else
+ {
+ if(a > 0) Editor::openWindow(x);
+ else Editor::closeWindow(x);
+ }
+}
+
+int track_proxy_getpatterns(t_track_proxy *x)
{
SETSYMBOL(&result_argv[0], gensym("patternnames"));
result_argc = 1;
@@ -166,7 +193,7 @@ static int track_proxy_getpatterns(t_track_proxy *x)
return 0;
}
-static int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat)
+int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat)
{
t_int p = (t_int) pat;
Pattern *pattern = x->track->getPattern(p);
@@ -183,7 +210,7 @@ static int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat)
return 0;
}
-static int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv)
+int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv)
{
if(argc < 2 || !IS_A_FLOAT(argv,0) || !IS_A_FLOAT(argv,1))
{
@@ -211,7 +238,7 @@ static int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom
return 0;
}
-static int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownum)
+int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownum)
{
t_int p = (t_int) pat;
t_int r = (t_int) rownum;
@@ -238,7 +265,7 @@ static int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownu
return 0;
}
-static int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg rows, t_floatarg cols)
+int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg rows, t_floatarg cols)
{
t_int r = (t_int) rows;
t_int c = (t_int) cols;
@@ -246,7 +273,7 @@ static int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg r
return 0;
}
-static int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat)
+int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat)
{
t_int p = (t_int) pat;
Pattern *pattern = x->track->getPattern(p);
@@ -259,7 +286,7 @@ static int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat)
return -9;
}
-static int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatarg rows, t_floatarg cols)
+int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatarg rows, t_floatarg cols)
{
t_int p = (t_int) pat;
t_int r = (t_int) rows;
@@ -274,7 +301,7 @@ static int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatar
return 0;
}
-static int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst)
+int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst)
{
pd_error(x, "copypattern: not implemented yet");
return -9;
diff --git a/composer/PdClasses.hpp b/composer/PdClasses.hpp
index acf261e..fe504cd 100644
--- a/composer/PdClasses.hpp
+++ b/composer/PdClasses.hpp
@@ -22,18 +22,20 @@ typedef struct _track_proxy
} t_track_proxy;
void track_proxy_setup(void);
-static t_track_proxy *track_proxy_new(t_symbol *song_name, t_symbol *track_name);
-static void track_proxy_free(t_track_proxy *x);
-static void track_proxy_save(t_gobj *z, t_binbuf *b);
-static void track_proxy_send_result(t_track_proxy *x, int outlet, int editor);
-static int track_proxy_getpatterns(t_track_proxy *x);
-static int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat);
-static int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv);
-static int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownum);
-static int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg rows, t_floatarg cols);
-static int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat);
-static int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatarg rows, t_floatarg cols);
-static int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst);
+t_track_proxy *track_proxy_new(t_symbol *song_name, t_symbol *track_name);
+void track_proxy_free(t_track_proxy *x);
+void track_proxy_save(t_gobj *z, t_binbuf *b);
+void track_proxy_properties(t_gobj *z, t_glist *owner);
+void track_proxy_send_result(t_track_proxy *x, int outlet, int editor);
+int track_proxy_editor(t_track_proxy *x, t_floatarg arg);
+int track_proxy_getpatterns(t_track_proxy *x);
+int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat);
+int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv);
+int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownum);
+int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg rows, t_floatarg cols);
+int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat);
+int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatarg rows, t_floatarg cols);
+int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst);
extern "C" void composer_setup(void);