From 30634c6bd679dcd250a9568e3958ce9dbf2e2aeb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 30 Nov 2010 21:19:28 +0000 Subject: created project folder for quickbindings, a plugin for mapping single keys to snippets of a patch svn path=/trunk/scripts/guiplugins/quickbindings/; revision=14541 --- quickbindings-plugin.tcl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 quickbindings-plugin.tcl 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 "+::patch_by_key::key %W %K %x %y" -- cgit v1.2.1