diff options
author | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-26 14:53:22 +0000 |
---|---|---|
committer | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-26 14:53:22 +0000 |
commit | becd4c66f77da3ff9078ec06aebb9ade3247e30b (patch) | |
tree | e5524f11b4cdc2457c27765cf0a97184ad7c16c5 /composer | |
parent | 1e1d2285d538c7fc71e687ce0eb77ea880e113e0 (diff) |
restored normality (editor/pd protocol and load/save in-patch data)
svn path=/trunk/externals/ffext/; revision=12459
Diffstat (limited to 'composer')
-rw-r--r-- | composer/Editor.cpp | 24 | ||||
-rw-r--r-- | composer/Editor.hpp | 2 | ||||
-rw-r--r-- | composer/Pattern.cpp | 6 | ||||
-rw-r--r-- | composer/PdClasses.cpp | 173 | ||||
-rw-r--r-- | composer/PdClasses.hpp | 13 | ||||
-rw-r--r-- | composer/Track.cpp | 26 | ||||
-rw-r--r-- | composer/Track.hpp | 14 | ||||
-rw-r--r-- | composer/editor.tk | 142 |
8 files changed, 273 insertions, 127 deletions
diff --git a/composer/Editor.cpp b/composer/Editor.cpp index c56d853..1b62b55 100644 --- a/composer/Editor.cpp +++ b/composer/Editor.cpp @@ -58,7 +58,29 @@ void Editor::init(t_track_proxy *x) x->track->getName().c_str(), 16, "NULL", - 1); +#ifdef DEBUG + 1 +#else + 0 +#endif + ); +} + +void Editor::dispatch(t_track_proxy *x, int argc, t_atom* argv) +{ + string s = ""; + for(int i = 0; i < argc; i++) + { + s += " {"; + char buf[MAXPDSTRING]; + atom_string(&argv[i], buf, MAXPDSTRING); + s += buf; + s += "}"; + } + sys_vgui("pd::composer::dispatch %s%s\n", + x->editor_recv->s_name, + s.c_str() + ); } void Editor::openWindow(t_track_proxy *x) diff --git a/composer/Editor.hpp b/composer/Editor.hpp index 9364320..94c30a9 100644 --- a/composer/Editor.hpp +++ b/composer/Editor.hpp @@ -1,10 +1,12 @@ #include "PdClasses.hpp" +#include <m_pd.h> class Editor { public: static void uploadCode(); static void init(t_track_proxy *x); + static void dispatch(t_track_proxy *x, int argc, t_atom* argv); static void openWindow(t_track_proxy *x); static void closeWindow(t_track_proxy *x); }; diff --git a/composer/Pattern.cpp b/composer/Pattern.cpp index 69c60f4..8335b28 100644 --- a/composer/Pattern.cpp +++ b/composer/Pattern.cpp @@ -6,6 +6,8 @@ using std::cout; using std::cerr; using std::endl; +#define WRAP(v,w) (((v)<0)?(((w)-1)-((-(v)-1)%(w))):((v)%(w))) + Pattern::Pattern(int numRows, int numCols, string patternName) : name(patternName) { @@ -72,10 +74,14 @@ void Pattern::resize(int numRows, int numCols) void Pattern::setCell(int row, int col, Cell cell) { + row = WRAP(row, rows.size()); + col = WRAP(col, columns); rows[row][col] = cell; } Cell Pattern::getCell(int row, int col) { + row = WRAP(row, rows.size()); + col = WRAP(col, columns); return rows[row][col]; } diff --git a/composer/PdClasses.cpp b/composer/PdClasses.cpp index cdf13ce..0ca07c1 100644 --- a/composer/PdClasses.cpp +++ b/composer/PdClasses.cpp @@ -14,6 +14,7 @@ using std::cerr; using std::endl; #define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT) +#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL) t_atom result_argv[MAX_RESULT_SIZE]; int result_argc; @@ -31,11 +32,9 @@ 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); #include "classsetup.cpp" - /* class_addmethod(track_proxy_class, (t_method)track_proxy_data, \ - gensym("data"), A_GIMME, A_NULL);*/ + 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_setsavefn(track_proxy_class, track_proxy_save); @@ -73,9 +72,9 @@ 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?) */ - t_pd* x2; + /*t_pd* x2; while((x2 = pd_findbyclass(gensym(TRACK_SELECTOR), track_proxy_class))) - pd_unbind(x2, gensym(TRACK_SELECTOR)); + pd_unbind(x2, gensym(TRACK_SELECTOR));*/ pd_unbind(&x->x_obj.ob_pd, x->editor_recv); } @@ -91,13 +90,13 @@ void track_proxy_save(t_gobj *z, t_binbuf *b) gensym("track"), gensym(s->getName().c_str()), gensym(t->getName().c_str())); - for(unsigned int p = 0; p < t->getPatternCount(); p++) + for(map<string,Pattern *>::iterator i = t->patternsBegin(); i != t->patternsEnd(); i++) { + Pattern *pattern = i->second; binbuf_addv(b, "ss", gensym(TRACK_SELECTOR), gensym("data")); - Pattern *pattern = t->getPattern(p); t_int r = pattern->getRows(); t_int c = pattern->getColumns(); - binbuf_addv(b, "siii", gensym(pattern->getName().c_str()), p, r, c); + binbuf_addv(b, "sii", gensym(pattern->getName().c_str()), r, c); t_atom tmp; for(unsigned int j = 0; j < r; j++) { @@ -124,6 +123,45 @@ void track_proxy_save(t_gobj *z, t_binbuf *b) binbuf_addv(b, "sss;", gensym(TRACK_SELECTOR), gensym("data"), gensym("end")); } +void track_proxy_data(t_track_proxy *x, t_symbol *s, int argc, t_atom *argv) +{ + if(argc == 1 && IS_A_SYMBOL(argv,0) && argv[0].a_w.w_symbol == gensym("end")) + { + pd_unbind(&x->x_obj.ob_pd, gensym(TRACK_SELECTOR)); + return; + } + if(argc < 3 || !IS_A_SYMBOL(argv,0) || !IS_A_FLOAT(argv,1) || !IS_A_FLOAT(argv,2)) + { + pd_error(x, "unrecognized format for in-patch data"); + return; + } + t_symbol *pat = argv[0].a_w.w_symbol; + t_int rows = (t_int) argv[1].a_w.w_float; + t_int cols = (t_int) argv[2].a_w.w_float; + if(argc != (3 + rows * cols)) + { + pd_error(x, "unrecognized format for in-patch data (malformed data?)"); + return; + } + Track *t = x->track; + t->addPattern(rows, cols, pat->s_name); + Pattern *p = t->getPattern(pat->s_name); + if(!p) + { + pd_error(x, "fatal error: cannot create patern"); + return; + } + int a = 3; + for(int r = 0; r < rows; r++) + { + for(int c = 0; c < cols; c++) + { + p->setCell(r, c, argv[a]); + a++; + } + } +} + void track_proxy_properties(t_gobj *z, t_glist *owner) { t_track_proxy *x = (t_track_proxy *) z; @@ -140,6 +178,7 @@ void track_proxy_send_result(t_track_proxy *x, int outlet, int editor) } if(editor) { + Editor::dispatch(x, result_argc, &result_argv[0]); } } @@ -156,42 +195,38 @@ int track_proxy_editor(t_track_proxy *x, t_floatarg arg) if(a > 0) Editor::openWindow(x); else Editor::closeWindow(x); } + result_argc = 0; } int track_proxy_getpatterns(t_track_proxy *x) { SETSYMBOL(&result_argv[0], gensym("patternnames")); result_argc = 1; - for(unsigned int i = 0; i < x->track->getPatternCount(); i++) + Track *t = x->track; + for(map<string,Pattern *>::iterator i = t->patternsBegin(); i != t->patternsEnd(); i++) { - if(result_argc >= MAX_RESULT_SIZE) - { - pd_error(x, "getpatternnames: result too long"); - return -2; - } - Pattern *pattern = x->track->getPattern(i); - if(!pattern) + if(result_argc >= MAX_RESULT_SIZE) { - pd_error(x, "getpatternnames: no such pattern: %d", i); - return -1; + pd_error(x, "getpatternnames: result too long"); + return -2; } - SETSYMBOL(&result_argv[result_argc], gensym(pattern->getName().c_str())); + Pattern *pattern = i->second; + SETSYMBOL(&result_argv[result_argc], gensym(pattern->getName().c_str())); result_argc++; } return 0; } -int track_proxy_getpatternsize(t_track_proxy *x, t_floatarg pat) +int track_proxy_getpatternsize(t_track_proxy *x, t_symbol *pat) { - t_int p = (t_int) pat; - Pattern *pattern = x->track->getPattern(p); + Pattern *pattern = x->track->getPattern(pat->s_name); if(!pattern) { - pd_error(x, "getpatternsize: no such pattern: %d", p); + pd_error(x, "getpatternsize: no such pattern: %s", pat->s_name); return -1; } SETSYMBOL(&result_argv[0], gensym("patternsize")); - SETFLOAT(&result_argv[1], (t_float) p); + SETSYMBOL(&result_argv[1], pat); SETFLOAT(&result_argv[2], pattern->getRows()); SETFLOAT(&result_argv[3], pattern->getColumns()); result_argc = 4; @@ -200,17 +235,18 @@ 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) { - if(argc < 2 || !IS_A_FLOAT(argv,0) || !IS_A_FLOAT(argv,1)) + result_argc = 0; + if(argc < 2 || !IS_A_SYMBOL(argv,0) || !IS_A_FLOAT(argv,1)) { - pd_error(x, "setrow: usage: setrow <pattern#> <row#> <atom0> <atom1> ..."); + pd_error(x, "setrow: usage: setrow <pattern> <row#> <atom0> <atom1> ..."); return -1; } - t_int p = (t_int) argv[0].a_w.w_float; + t_symbol *pat = argv[0].a_w.w_symbol; + Pattern *pattern = x->track->getPattern(pat->s_name); t_int r = (t_int) argv[1].a_w.w_float; - Pattern *pattern = x->track->getPattern(p); if(!pattern) { - pd_error(x, "setrow: no such pattern: %d", p); + pd_error(x, "setrow: no such pattern: %s", pat->s_name); return -2; } if((argc - 2) != pattern->getColumns()) @@ -222,67 +258,107 @@ int track_proxy_setrow(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv) { pattern->setCell(r, i - 2, argv[i]); } - result_argc = 0; return 0; } -int track_proxy_getrow(t_track_proxy *x, t_floatarg pat, t_floatarg rownum) +int track_proxy_getrow(t_track_proxy *x, t_symbol *pat, t_floatarg rownum) { - t_int p = (t_int) pat; t_int r = (t_int) rownum; - Pattern *pattern = x->track->getPattern(p); + Pattern *pattern = x->track->getPattern(pat->s_name); if(!pattern) { - pd_error(x, "getrow: no such pattern: %d", p); + pd_error(x, "getrow: no such pattern: %s", pat->s_name); return -2; } SETSYMBOL(&result_argv[0], gensym("patternrow")); - SETFLOAT(&result_argv[1], (t_float) p); + SETSYMBOL(&result_argv[1], pat); SETFLOAT(&result_argv[2], (t_float) r); result_argc = 3; for(unsigned int i = 0; i < pattern->getColumns(); i++) { - if(result_argc >= MAX_RESULT_SIZE) + if(result_argc >= MAX_RESULT_SIZE) { - pd_error(x, "getrow: result too long"); - return -2; - } + pd_error(x, "getrow: result too long"); + return -2; + } result_argv[result_argc] = pattern->getCell(r, i); result_argc++; } return 0; } +int track_proxy_setcell(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv) +{ + result_argc = 0; + if(argc != 4 || !IS_A_SYMBOL(argv,0) || !IS_A_FLOAT(argv,1) || !IS_A_FLOAT(argv,2)) + { + pd_error(x, "setrow: usage: setcell <pattern> <row#> <col#> <atom>"); + return -1; + } + t_symbol *pat = argv[0].a_w.w_symbol; + Pattern *pattern = x->track->getPattern(pat->s_name); + t_int r = (t_int) argv[1].a_w.w_float; + t_int c = (t_int) argv[2].a_w.w_float; + if(!pattern) + { + pd_error(x, "setcell: no such pattern: %s", pat->s_name); + return -2; + } + pattern->setCell(r, c, argv[3]); + return 0; +} + +int track_proxy_getcell(t_track_proxy *x, t_symbol *pat, t_floatarg rownum, t_floatarg colnum) +{ + t_int r = (t_int) rownum; + t_int c = (t_int) colnum; + Pattern *pattern = x->track->getPattern(pat->s_name); + if(!pattern) + { + pd_error(x, "getcell: no such pattern: %s", pat->s_name); + return -2; + } + SETSYMBOL(&result_argv[0], gensym("patterncell")); + SETSYMBOL(&result_argv[1], pat); + SETFLOAT(&result_argv[2], (t_float) r); + SETFLOAT(&result_argv[3], (t_float) c); + result_argv[4] = pattern->getCell(r, c); + result_argc = 5; + return 0; +} + + int track_proxy_addpattern(t_track_proxy *x, t_symbol *name, t_floatarg rows, t_floatarg cols) { + result_argc = 0; t_int r = (t_int) rows; t_int c = (t_int) cols; x->track->addPattern(r, c, string(name->s_name)); return 0; } -int track_proxy_removepattern(t_track_proxy *x, t_floatarg pat) +int track_proxy_removepattern(t_track_proxy *x, t_symbol *pat) { - t_int p = (t_int) pat; - Pattern *pattern = x->track->getPattern(p); + result_argc = 0; + Pattern *pattern = x->track->getPattern(pat->s_name); if(!pattern) { - pd_error(x, "removepattern: no such pattern: %d", p); + pd_error(x, "removepattern: no such pattern: %s", pat->s_name); return -2; } pd_error(x, "removepattern: not implemented yet"); return -9; } -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_symbol *pat, t_floatarg rows, t_floatarg cols) { - t_int p = (t_int) pat; + result_argc = 0; t_int r = (t_int) rows; t_int c = (t_int) cols; - Pattern *pattern = x->track->getPattern(p); + Pattern *pattern = x->track->getPattern(pat->s_name); if(!pattern) { - pd_error(x, "resizepattern: no such pattern: %d", p); + pd_error(x, "resizepattern: no such pattern: %s", pat->s_name); return -2; } pattern->resize(r, c); @@ -291,6 +367,7 @@ int track_proxy_resizepattern(t_track_proxy *x, t_floatarg pat, t_floatarg rows, int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst) { + result_argc = 0; pd_error(x, "copypattern: not implemented yet"); return -9; } diff --git a/composer/PdClasses.hpp b/composer/PdClasses.hpp index e0c4bfe..da3c7bd 100644 --- a/composer/PdClasses.hpp +++ b/composer/PdClasses.hpp @@ -25,18 +25,21 @@ void track_proxy_setup(void); 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_data(t_track_proxy *x, t_symbol *s, int argc, t_atom *argv); 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); /*#begin methods*/ +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_getpatternsize(t_track_proxy *x, t_symbol *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_getrow(t_track_proxy *x, t_symbol *pat, t_floatarg rownum); +int track_proxy_setcell(t_track_proxy *x, t_symbol *sel, int argc, t_atom *argv); +int track_proxy_getcell(t_track_proxy *x, t_symbol *pat, t_floatarg rownum, t_floatarg colnum); 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_removepattern(t_track_proxy *x, t_symbol *pat); +int track_proxy_resizepattern(t_track_proxy *x, t_symbol *pat, t_floatarg rows, t_floatarg cols); int track_proxy_copypattern(t_track_proxy *x, t_symbol *src, t_symbol *dst); /*#end methods*/ diff --git a/composer/Track.cpp b/composer/Track.cpp index 47ad81b..2154ecf 100644 --- a/composer/Track.cpp +++ b/composer/Track.cpp @@ -27,10 +27,14 @@ void Track::print() { cerr << "---- Track: " << name << " ----" << endl; - for(unsigned int i = 0; i < patterns.size(); i++) + /*for(unsigned int i = 0; i < patterns.size(); i++) { cerr << " Pattern[" << patterns[i]->getName() << "]: " << patterns[i]->getName() << endl; - } + }*/ + for(map<string,Pattern *>::iterator i = patterns.begin(); i != patterns.end(); i++) + { + cerr << " Pattern[" << i->first << "]: " << i->second->getName() << endl; + } cerr << "---- End track (" << name << ") ----" << endl; } @@ -38,10 +42,22 @@ void Track::print() void Track::addPattern(int rows, int cols, string name) { Pattern *pattern = new Pattern(rows, cols, name); - patterns.push_back(pattern); + //patterns.push_back(pattern); + patterns[name] = pattern; } -Pattern *Track::getPattern(int n) +/*Pattern *Track::getPattern(int n) { - return patterns[n]; + if(n < 0 || n >= patterns.size()) + return 0; + else + return patterns[n]; +}*/ + +Pattern *Track::getPattern(const string &p) +{ + if(patterns.find(p) != patterns.end()) + return patterns[p]; + else + return 0; } diff --git a/composer/Track.hpp b/composer/Track.hpp index 3bd2135..0d6c2cb 100644 --- a/composer/Track.hpp +++ b/composer/Track.hpp @@ -1,13 +1,15 @@ #ifndef COMPOSER_TRACK_H_INCLUDED #define COMPOSER_TRACK_H_INCLUDED +#include <map> #include <string> -#include <vector> +//#include <vector> #include <m_pd.h> using std::string; -using std::vector; +//using std::vector; +using std::map; class Song; class Pattern; @@ -18,15 +20,19 @@ public: static Track *byName(string songName, string trackName); private: string name; - vector<Pattern *> patterns; + //vector<Pattern *> patterns; + map<string,Pattern *> patterns; Song *song; protected: Track(Song *_song, string trackName); public: void print(); void addPattern(int rows, int cols, string name); - Pattern *getPattern(int n); + //Pattern *getPattern(int n); + Pattern *getPattern(const string &p); inline unsigned int getPatternCount() {return patterns.size();} + inline map<string,Pattern *>::iterator patternsBegin() {return patterns.begin();} + inline map<string,Pattern *>::iterator patternsEnd() {return patterns.end();} inline Song *getSong() {return song;} inline const string &getName() {return name;} }; diff --git a/composer/editor.tk b/composer/editor.tk index 1b90732..9b2fcd6 100644 --- a/composer/editor.tk +++ b/composer/editor.tk @@ -38,8 +38,8 @@ namespace eval pd::composer { array set trackname {} variable currentpattern array set currentpattern {} - variable length - array set length {} + variable size + array set size {} variable columns array set columns {} variable patterns @@ -70,55 +70,54 @@ namespace eval pd::composer { catch {pd {*}$what} } - proc createPattern {id name len} { + proc editCommand {method args} { + linsert $args 0 [uplevel {set id}] ${method}E + } + + proc createPattern {id name rows cols} { debugPrint [info level 0] - variable length variable patterns if {$name in $patterns($id)} { return -code error "Pattern '$name' already exists" } - set len [expr {int($len)}] - if {$len <= 0} { - return -code error "Length must be positive integer" + set rows [expr {int($rows)}] + set cols [expr {int($cols)}] + if {$rows <= 0 || $cols <= 0} { + return -code error "Pattern dimensions must pe positive integer" } - sendGui [concat $id EDIT addpattern $name $len] + sendGui [editCommand addpattern $name $rows $cols] } proc removePattern {id name} { debugPrint [info level 0] - variable length; - variable patterns; - - sendGui [concat $id EDIT removepattern $name] + sendGui [editCommand removepattern $name] } proc copyPattern {id src dst} { debugPrint [info level 0] - variable length; - - sendGui [concat $id EDIT copypattern $src $dst] + sendGui [editCommand copypattern $src $dst] } - proc resizePattern {id name newSize} { + proc resizePattern {id name rows cols} { debugPrint [info level 0] variable currentpattern; - variable length; + variable size; - if {$newSize == [dict get $length($id) $name]} return + if {[list $rows $cols] == [dict get $size($id) $name]} return - set len [expr {int($newSize)}] - if {$len <= 0} { - return -code error "Length must pe positive integer" + set rows [expr {int($rows)}] + set cols [expr {int($cols)}] + if {$rows <= 0 || $cols <= 0} { + return -code error "Pattern dimensions must pe positive integer" } - sendGui [concat $id EDIT resizepattern $name $len] + sendGui [editCommand resizepattern $name $rows $cols] } proc renamePattern {id name newName} { debugPrint [info level 0] - variable length; variable patterns; if {$name == $newName} return @@ -130,7 +129,7 @@ namespace eval pd::composer { return -code error "No such pattern: '$name'" } - sendGui [concat $id EDIT renamepattern $name $newName] + sendGui [editCommand renamepattern $name $newName] } proc generateNewPatternName {id} { @@ -144,10 +143,10 @@ namespace eval pd::composer { } proc displayPattern {id name} { - debugPrint "request-pattern-length" + debugPrint "request-pattern-size" variable showpattern set showpattern($id) 1 - sendGui [concat $id EDIT getpatternlength $name] + sendGui [editCommand getpatternsize $name] } proc updateTitle {id} { @@ -171,7 +170,7 @@ namespace eval pd::composer { debugPrint [info level 0] variable currentpattern variable patterns - variable length + variable size variable columns variable w variable songname @@ -186,8 +185,8 @@ namespace eval pd::composer { return } - set rows [dict get $length($id) $name] - set cols $columns($id) + #set cols $columns($id) + lassign [dict get $size($id) $name] rows cols grid $w($id).t -row 10 -column 0 -sticky news debugPrint "resizing tktable widget to ${rows}x${cols}" $w($id).t configure -state normal -variable [getDataVar $id] -rows $rows -cols [expr {1+$cols}] @@ -219,7 +218,7 @@ namespace eval pd::composer { proc edit {id r c bwrite value} { # NOT USED #if {$bwrite} { - # sendGui [concat $id EDIT setcell $currentpattern($id) $r $c $value] + # sendGui [editCommand setcell $currentpattern($id) $r $c $value] #} else { #} } @@ -321,7 +320,7 @@ namespace eval pd::composer { debugPrint "wm" wm minsize $w($id) 300 150 - wm protocol $w($id) WM_DELETE_WINDOW "[namespace current]::sendGui {$id EDIT editor-close}" + wm protocol $w($id) WM_DELETE_WINDOW [list [namespace current]::sendGui [editCommand editor 0]] debugPrint "menu" menu $w($id).m -tearoff 0 @@ -349,8 +348,8 @@ namespace eval pd::composer { set startup($id) 1 set showpattern($id) 0 debugPrint "request-patterns" - sendGui [concat $id EDIT getpatterns] - sendGui [concat $id EDIT gettracks] + sendGui [editCommand getpatterns] + #sendGui [editCommand gettracks] return $w($id) } @@ -387,7 +386,7 @@ namespace eval pd::composer { set newVal [dict get [dict merge [list $newVal $newVal] [lreverse $symbolmap]] $newVal] debugPrint "AFTER: newVal = '$newVal'" - sendGui [concat $id EDIT setcell $currentpattern($id) $row $col $newVal] + sendGui [editCommand setcell $currentpattern($id) $row $col $newVal] return 1 } @@ -397,15 +396,17 @@ namespace eval pd::composer { variable currentpattern variable w set bname 1 - set blength 1 + set brows 1 + set bcols 0 set old_name {} catch {set old_name $currentpattern($id)} set vname {} - set vlength {} + set vrows {} + set vcols {} set action_cancel {destroy %w} set action_ok $action_cancel - set opts {vname vlength bname blength action_ok action_cancel} + set opts {vname vrows vcols bname brows bcols action_ok action_cancel} foreach opt $opts { catch {set $opt [dict get $options $opt]} } @@ -424,43 +425,52 @@ namespace eval pd::composer { } grid [ttk::label $w_.lname -text "Name: "] -row 0 -column 0 - grid [ttk::label $w_.llength -text "Rows: "] -row 1 -column 0 + grid [ttk::label $w_.lrows -text "Rows: "] -row 1 -column 0 + grid [ttk::label $w_.lcols -text "Cols: "] -row 2 -column 0 grid [ttk::entry $w_.ename] -row 0 -column 1 - grid [ttk::entry $w_.elength] -row 1 -column 1 - grid [ttk::frame $w_.b] -row 2 -columnspan 2 + grid [ttk::entry $w_.erows] -row 1 -column 1 + grid [ttk::entry $w_.ecols] -row 2 -column 1 + grid [ttk::frame $w_.b] -row 999 -columnspan 2 grid [ttk::button $w_.b.ok -text Ok -command $action_ok] -row 0 -column 0 -in $w_.b grid [ttk::button $w_.b.cancel -text Cancel -command $action_cancel] -row 0 -column 1 -in $w_.b $w_.ename insert 0 $vname - $w_.elength insert 0 $vlength + $w_.erows insert 0 $vrows + $w_.ecols insert 0 $vcols if {!$bname} {$w_.ename configure -state disabled} - if {!$blength} {$w_.elength configure -state disabled} + if {!$brows} {$w_.erows configure -state disabled} + if {!$bcols} {$w_.ecols configure -state disabled} } proc patternPropertiesDialog {id {options {}}} { debugPrint [info level 0] variable currentpattern; - variable length; + variable size; dict set options action_ok { - %ns::resizePattern %id %old_name [%w.elength get] + %ns::resizePattern %id %old_name [%w.erows get] [%w.ecols get] %ns::renamePattern %id %old_name [%w.ename get] destroy %w } dict set options vname $currentpattern($id) - dict set options vlength [dict get $length($id) $currentpattern($id)] + lassign [dict get $size($id) $currentpattern($id)] pat_rows pat_cols + dict set options vrows $pat_rows + dict set options vcols $pat_cols patternPropertiesDialog_common $id $options } proc copyPatternDialog {id {options {}}} { debugPrint [info level 0] variable w; - variable length; + variable size; - dict set options blength 0 + dict set options brows 0 + dict set options bcols 0 dict set options vname [generateNewPatternName $id] - dict set options vlength [dict get $length($id) $currentpattern($id)] + lassign [dict get $size($id) $currentpattern($id)] pat_rows pat_cols + dict set options vrows $pat_rows + dict set options vcols $pat_rows dict set options action_ok { %ns::copyPattern %id %old_name [%w.ename get] destroy %w @@ -484,11 +494,12 @@ namespace eval pd::composer { proc newPatternDialog {id {options {}}} { debugPrint [info level 0] dict set options action_ok { - %ns::createPattern %id [%w.ename get] [%w.elength get] + %ns::createPattern %id [%w.ename get] [%w.erows get] [%w.ecols get] destroy %w } dict set options vname [generateNewPatternName $id] - dict set options vlength 16 + dict set options vrows 16 + dict set options vcols 8 patternPropertiesDialog_common $id $options } @@ -500,7 +511,7 @@ namespace eval pd::composer { variable w variable songname variable trackname - variable length + variable size variable currentpattern variable columns set w($id) .w_${song_name}_${track_name} @@ -511,7 +522,7 @@ namespace eval pd::composer { } else { set currentpattern($id) $set_current_pattern } - set length($id) {} + set size($id) {} set columns($id) $cols } @@ -536,14 +547,14 @@ namespace eval pd::composer { debugPrint [info level 0] variable w variable patterns - variable length + variable size variable currentpattern variable startup variable showpattern variable columns variable quirks_fix_int_floats switch -exact [lindex $args 0] { - patterns { + patternnames { # for track mode set patterns($id) [lrange $args 1 end] debugPrint "patterns <- $patterns($id)" @@ -564,18 +575,20 @@ namespace eval pd::composer { #$w($id).t configure -state normal -cols $cols set columns($id) $cols } - patternlength { + patternsize { set pat_name [lindex $args 1] - set pat_length [lindex $args 2] - debugPrint "got patternlength: '$pat_name' (len=$pat_length)" - if {![dict exists $length($id) $pat_name] || [dict get $length($id) $pat_name] != $pat_length || $showpattern($id)} { - dict set length($id) $pat_name $pat_length - for {set i 0} {$i < $pat_length} {incr i} { - sendGui [concat $id EDIT getrow $pat_name $i] + set pat_rows [lindex $args 2] + set pat_cols [lindex $args 3] + set new_size [list $pat_rows $pat_cols] + debugPrint "got patternsize: '$pat_name' (size = $pat_rows x $pat_cols)" + if {![dict exists $size($id) $pat_name] || [dict get $size($id) $pat_name] != $new_size || $showpattern($id)} { + dict set size($id) $pat_name $new_size + for {set i 0} {$i < $pat_rows} {incr i} { + sendGui [editCommand getrow $pat_name $i] } } } - row { + patternrow { set pat_name [lindex $args 1] if {$quirks_fix_int_floats} { set row_num [expr {int([lindex $args 2])}] @@ -588,14 +601,15 @@ namespace eval pd::composer { for {set i 0} {$i < [llength $row]} {incr i} { setCellValueUI $id $pat_name $row_num $i [lindex $row $i] } - if {$row_num + 1 == [dict get $length($id) $pat_name]} { + lassign [dict get $size($id) $pat_name] pat_rows pat_cols + if {$row_num + 1 == $pat_rows} { if {$showpattern($id)} { set showpattern($id) 0 displayPattern_async $id $pat_name } } } - cell { + patterncell { set pat_name [lindex $args 1] if {$quirks_fix_int_floats} { set row_num [expr {int([lindex $args 2])}] |