aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-11-30 21:19:28 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-11-30 21:19:28 +0000
commit30634c6bd679dcd250a9568e3958ce9dbf2e2aeb (patch)
tree7fd9dfdd55fb2041634936731c967533932ec5a6
created project folder for quickbindings, a plugin for mapping single keys to snippets of a patchsvn2git-root
svn path=/trunk/scripts/guiplugins/quickbindings/; revision=14541
-rw-r--r--quickbindings-plugin.tcl39
1 files changed, 39 insertions, 0 deletions
diff --git a/quickbindings-plugin.tcl b/quickbindings-plugin.tcl
new file mode 100644
index 0000000..8f6081a
--- /dev/null
+++ b/quickbindings-plugin.tcl
@@ -0,0 +1,39 @@
+# this is a rough attempt to bind keys to little snippets of patches.
+# Currently, there are only three keys bound: o r s
+
+package require pd_connect ;# for pdsend
+
+namespace eval ::patch_by_key:: {
+ variable patches
+ array set patches {}
+}
+
+proc ::patch_by_key::init {} {
+ variable patches
+ # map keys to patch snippets
+ set patches(o) "#X obj 1 2 osc~;"
+ set patches(r) "#X obj 1 2 r test;"
+ set patches(s) "#X obj 1 2 s test;"
+}
+
+proc ::patch_by_key::key {tkcanvas key x y} {
+ pdtk_post "::patch_by_key::key $tkcanvas $key $x $y"
+ variable patches
+ set mytoplevel [winfo toplevel $tkcanvas]
+
+ # make sure we have a mapping for the key before continuing
+ if {[lsearch -exact [array names patches] $key] == -1} {return}
+ # only do this for PatchWindows, not dialogs, pdwindow, etc.
+ if {[winfo class $mytoplevel] ne "PatchWindow"} {return}
+ # only do this if the canvas is in editmode
+ if {$::editmode($mytoplevel) != 1} {return}
+
+ # regexp magic to replace #X with the current canvas name, and the
+ # (x,y) with the current mouse location
+ set x [$tkcanvas canvasx $x]
+ set y [$tkcanvas canvasy $y]
+ pdsend [regsub -- {#X (\S+) [0-9]+ [0-9]+} $patches($key) "$mytoplevel \\1 $x $y"]
+}
+
+::patch_by_key::init
+bind all <Key> "+::patch_by_key::key %W %K %x %y"