[PD] Toxy (was Re: [Instance])

patrice colet megalegoland at yahoo.fr
Tue May 8 06:24:30 CEST 2007


Good question, the [widget] and [tot] externals are maybe hacks, but
also very powerfull if the user knows tcl and tk, but with a limited set
of examples, certainly because a few people did try to explore this.
 I'm trying to build a 'good old' pianoroll,

http://megalego.free.fr/pd/pianoroll/proll.JPG

with starting from the grid widget available in ix widget extensions,
 but it's a quite complicated task for someone that just begin to
understand what is an interpreted language, if anyone is interested into
looking at the code it's attached.


Le lundi 07 mai 2007 à 14:08 -0500, Kyle Klipowicz a écrit :
> One question I have with the toxy sliders is this: in the
> multiscale-test.pd file, there are some really neat sliders, but how
> do you create these, and what are the creation arguments?
> 
> I know that we can just go in to the patch as a text file and get this
> information, but it would be nice if there were some more instructions
> on the usage of these really powerful gui tools. What references are
> recommended for experimenting with this?
> 
> ~Kyle
> 
> On 5/7/07, carmen <_ at whats-your.name> wrote:
> > On Mon May 07, 2007 at 01:26:09PM -0500, Kyle Klipowicz wrote:
> > > You are right, I just started looking through the Toxy library
> > > examples, and so far it looks really nice! I'm excited about this! How
> > > do these sliders and such compare with the iemgui objects in terms of
> > > gridlock?
> >
> > you mean like when the widgets stop updating graphically (numbox moves the value but doesnt reflect the changes in the GUI) or something else?
> >
> > it works better than iemgui for effiiency since you can just send over values, instead of drawing instructions which are often 4x as long.
> >
> > as long as you stay within the socket bandwidth limit, i found win32 was the best performer. i mean a scrolling full color 25fps spectrogram was using 2% total CPU, if the task manager is to be believed, on a lowly single-core 2ghz amd64. the same patch on linux has pd and X eaech using like 20% CPU, if top can be believed :/
> >
> > i'd agree Toxy is pretty nice - its the best youre going to get with the old pd-gui - you get constructors, destructors, all of Tk, and you dont have to know/care how nastily the rest of the GUI is implemented :)
> >
> > _______________________________________________
> > PD-list at iem.at mailing list
> > UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
> >
> 
> 
-------------- next part --------------

namespace eval ::xt { 


    proc proll_clic {w k t div scx scy} {
	    
        zoom $w $k $t $scx $scy
	    bind $w <Motion> "::xt::draw $w $t %x %y $div motion 0 item"
		bind $w <1> "::xt::draw $w $t %x %y $div draw 0 item"		
	}
	proc draw {w t x y div type i item} {
    if {$i == 0} {
        set x [$w canvasx $x]
        set y [$w canvasy $y]
		}
		for {set z 0} {$z <= [expr $div - 1]} {incr z}  {
	    set j [expr $z + 1]
		if {$z < 1} {
		set rectx1 0
		set rectx2 [lindex [$w coords gridver1] 0] 
		set q $z
		}
		if {$z > 0} {
		set x1 [lindex [$w coords gridver$z] 0]
		set x2 [lindex [$w coords gridver$j] 0]
	        if {$x1 <= $x && $x <=$x2} {
		    set rectx1 $x1
			set rectx2 $x2
			set q $z
		    }
		}
		}
	    for {set i 0} {$i <= 127} {incr i} {
	    set j [expr $i + 1]
		if {$i < 1} {
		set recty1 0
		set recty2 [lindex [$w coords gridhor1] 1]
        set o 0
		}
		if {$i > 0} {
		set y1 [lindex [$w coords gridhor$i] 1]
		set y2 [lindex [$w coords gridhor$j] 1]
	        if {$y1 <= $y && $y <=$y2} {

		    set recty1 $y1
			set recty2 $y2
			set o [expr abs(-1*($i-127))]			
			}
		}
		}
	switch -- $type {    
	    draw {
		if {[$w find withtag note$rectx1$rectx2] == ""} {
		pd "$t.rp _cb  add $q  $o  127  500;"
		proll_draw $w $t draw $rectx1 $rectx2 $recty1 $recty2 $div}}
	    redraw {
		$w delete $item
        proll_draw $w $t draw $rectx1 $rectx2 $recty1 $recty2 $div		
		}
		delete {
		pd "$t.rp _cb  delete $q  $o;"
		$w delete $item
		}
		motion {proll_draw $w $t $type $rectx1 0 $recty1 0 $div}
    }
	}

    proc proll_draw {w t type x1 x2 y1 y2 d} {
    
	    set x1 [expr $x1+1];set x2 [expr $x2-1];set y1 [expr $y1+1];set y2 [expr $y2-1]	
        switch -- $type {
	    draw {
	    $w create rectangle $x1 $y1 $x2 $y2 -fill red -tags note$x1$y1 -activefill yellow -disabledfill black
#        dump $w $t $d
#		pd "$t.rp _cb end;"
        }
	    motion {
	    set item note$x1$y1
        $w bind $item <3> "::xt::draw $w $t %x %y $d delete 1 $item"
	    $w bind $item <Enter> "$w configure -cursor hand2"
	    $w bind $item <Leave> "$w configure -cursor arrow"
        $w bind $item <B1-Motion> "::xt::move_note $w $t $item %x %y $d"

  		
	        }
	    }	
    }

    proc move_note {w t item x y d} {
        foreach {x0 y0 x1 y1} [$w coords $item] break
		set xc [expr $x1 - $x0]; set yc [expr $y1 - $y0];
		if {$x > ($x1-($xc/4))} {
		$w coord $item $x0 $y0 $x $y1
		} else {
        $w coord $item [expr $x - ($xc/2)] [expr $y - ($yc/2)] [expr $x + ($xc/2)] [expr $y + ($yc/2)]
#	    $w bind $item <ButtonRelease-1> "::xt::draw $w $t %x %y $d redraw 0 $item"
        }		
	}
    proc proll_new {t tg w h bg fg ln div size scx scy n} {
	if {[winfo exists $t.proll] != 1} {	    
        panedwindow $t.panh -orient vertical
		panedwindow $t.panv -orient horizontal
        scrollbar $t.hscroll -orient horiz -command [list $t.proll xview] 
        scrollbar $t.vscroll -command [list xt::yview $t ] 		
        canvas $t.proll -width $w -height $h -bg $bg -xscrollcommand [list $t.hscroll set] 
	    canvas $t.keys -width 15 -height $h -yscrollcommand [list $t.vscroll set]
		canvas $t.control -width $w -height 5 -bg white  
		$t.panv add $t.keys -minsize 20 -sticky e 
        $t.panv add $t.proll -minsize 50
        $t.panh add $t.panv -minsize 70
        $t.panh add $t.control -minsize 10		
        grid $t.panh	-in $t -row 1 -column 1
        grid $t.vscroll -in $t -row 1 -column 2 -sticky ns
        grid $t.hscroll -in $t -row 2  -column 1 -sticky we
	    proll $t.proll $t.keys $t $div $w $h $ln	
        proll_clic $t.proll $t.keys $tg $div $scx $scy		

    }
	}

    proc yview {w args} {
        eval [linsert $args 0 $w.proll yview]
        eval [linsert $args 0 $w.keys yview]
	}
	proc zoom {w keys t x y} {	
	$keys scale all 0 0 1 $y
	$w scale all 0 0 $x $y
	$w configure -scrollregion [$w bbox all]
	$keys configure -scrollregion [$keys bbox all]
    }

    proc proll {w keys t lines ww hw color} {
	for {set x 1} {$x <= $lines} {incr x} {
	    set col $color
	    set ow [expr $ww.0 * $x.0 / $lines.0]
        set mod [expr $x % 4] 
		if {$mod == 0} {set col red}
        $w create line $ow 0 $ow $hw -fill $col -tag gridver$x 		
	}
	set notes 128
	for {set x 1} {$x <= $notes} {incr x} {
	    set oh [expr $hw.0 * $x.0 / $notes.0]
	    $w create line 0 $oh $ww $oh -fill $color -tags gridhor$x
	}
	keyboard $w $keys
    }

	proc keyboard {w keys} {
	for {set x 1} {$x <= 128} {incr x} {
    set y [expr $x - 1]
	if {$x == 1} { 
	set recty 0 } 
	if {$x > 1} {
	set recty [lindex [$w coord gridhor$y] 1]
	}
	set mod [expr $x % 12]
    if {$mod==1 | $mod==4 | $mod==6 | $mod==9 | $mod==11} {
    set color black
	} else {
	set color white
	}
	$keys create rectangle 0 $recty 20 [lindex [$w coord gridhor$x] 1] \
	-fill $color -tag key$x 
	}
	}
	
    proc dump {w t div} {
        foreach item [$w find all] {
            if {[$w type $item] == "rectangle" } {
	            foreach {a b c d} [$w coords $item] break
                draw $w $t $a $b $div out 0 .
	        }
        }		
	}

}	
#> proll frame
#. -bd 3
#. #w 128 #h 128 #x 0.5 #y 0.5
#. #fg red #bg blue #ln yellow
#. #size 12 #div 16 #scalex 3 #scaley 5 



::xt::proll_new .- .| .#w .#h .#bg .#fg .#ln .#div .#size .#scalex .#scaley .#note
-------------- next part --------------
#N canvas 438 1 590 718 10;
#X obj 146 255 widget proll p1 #scalex 1.04 #scaley 9 #h 215 #w 268
;
#X obj 323 103 makenote 3.2 500;
#X obj 322 135 noteout;
#X obj 11 386 print;
#X obj 52 281 t a a;
#X obj 11 330 spigot;
#X obj 50 310 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 150 207 r \$0-proll-in;
#X obj 52 402 s \$0-proll-out;
#N canvas 0 0 462 312 proll-config 0;
#X floatatom 202 48 3 1 1000 0 - - -;
#X obj 202 93 / 100;
#X msg 172 134 #scalex \$1;
#X msg 177 165 #scaley \$1;
#X floatatom 243 46 3 1 1000 0 - - -;
#X floatatom 180 192 5 0 0 0 - - -;
#X obj 243 91 / 10;
#X msg 242 226 #h \$1;
#X msg 180 210 #w \$1;
#X floatatom 243 205 5 0 0 0 - - -;
#X obj 161 267 s \$0-proll-in;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 10 0;
#X connect 3 0 10 0;
#X connect 4 0 6 0;
#X connect 5 0 8 0;
#X connect 6 0 3 0;
#X connect 7 0 10 0;
#X connect 8 0 10 0;
#X connect 9 0 7 0;
#X restore 203 78 pd proll-config;
#N canvas 290 2 377 718 proll-dump 1;
#X obj 110 19 r \$0-proll-out;
#X obj 113 235 list trim;
#X obj 125 494 outlet;
#X obj 39 455 print TXT;
#N canvas 491 164 490 340 init 0;
#X obj 185 183 until;
#X msg 185 209 add -1;
#X msg 236 211 clear;
#X obj 183 123 t b b;
#X obj 208 92 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 150 93 loadbang;
#X obj 183 249 s \$0-txt;
#X obj 183 159 i 16;
#X connect 0 0 1 0;
#X connect 1 0 6 0;
#X connect 2 0 6 0;
#X connect 3 0 7 0;
#X connect 3 1 2 0;
#X connect 4 0 3 0;
#X connect 5 0 3 0;
#X connect 7 0 0 0;
#X restore 19 20 pd init;
#X obj 94 337 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 43 273 print mess;
#X obj 142 276 s \$0-msg;
#X obj 112 42 route add;
#X obj 89 365 msgfile;
#X obj 43 304 r \$0-msg;
#X floatatom 286 108 5 0 0 0 - - -;
#X obj 262 149 metro;
#X obj 275 183 i 0;
#X obj 275 204 + 1;
#X obj 273 227 mod 16;
#X obj 229 101 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X floatatom 273 251 5 0 0 0 - - -;
#X obj 243 47 expr (60000/$f1);
#X obj 287 127 / 4;
#X obj 27 365;
#X msg 23 331 print;
#X obj 227 361 s \$0-msg;
#X obj 146 419 unpack f f f;
#X obj 118 470 spigot;
#X obj 93 392 t a a;
#X obj 65 421 spigot;
#X obj 21 46 route delete;
#X obj 25 100 t a a;
#X msg 50 149 goto \$1;
#X msg 26 195 delete \, insert \$2;
#X obj 26 219 s \$0-msg;
#X obj 289 327 loadbang;
#X obj 229 77 inlet;
#X obj 239 14 inlet;
#X obj 229 311 until;
#X obj 127 390 s \$0-msg-bang;
#X obj 268 287 r \$0-msg-bang;
#X msg 238 336 rewind;
#X obj 224 277 t b b a;
#X obj 145 446 ==;
#X obj 113 150 list prepend add;
#X connect 0 0 8 0;
#X connect 0 0 27 0;
#X connect 1 0 7 0;
#X connect 1 0 6 0;
#X connect 5 0 9 0;
#X connect 8 0 41 0;
#X connect 9 0 25 0;
#X connect 9 0 26 0;
#X connect 9 1 36 0;
#X connect 10 0 9 0;
#X connect 11 0 19 0;
#X connect 12 0 13 0;
#X connect 13 0 14 0;
#X connect 14 0 13 1;
#X connect 14 0 15 0;
#X connect 15 0 17 0;
#X connect 16 0 12 0;
#X connect 18 0 11 0;
#X connect 19 0 12 1;
#X connect 21 0 9 0;
#X connect 23 0 40 0;
#X connect 24 0 2 0;
#X connect 25 0 24 0;
#X connect 25 1 23 0;
#X connect 26 0 3 0;
#X connect 27 0 28 0;
#X connect 28 0 30 0;
#X connect 28 1 29 0;
#X connect 29 0 31 0;
#X connect 30 0 31 0;
#X connect 33 0 16 0;
#X connect 34 0 18 0;
#X connect 35 0 22 0;
#X connect 37 0 35 1;
#X connect 38 0 22 0;
#X connect 39 0 35 0;
#X connect 39 1 38 0;
#X connect 39 2 40 1;
#X connect 40 0 24 1;
#X connect 41 0 1 0;
#X restore 321 47 pd proll-dump;
#X obj 323 72 unpack f f f;
#X obj 322 191 qlist;
#X obj 320 24 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 382 21 nbx 5 14 -1e+037 1e+037 0 1 empty empty empty 0 -8 0
10 -262144 -1 -1 120 256;
#X connect 0 0 4 0;
#X connect 1 0 2 0;
#X connect 1 1 2 1;
#X connect 4 0 5 0;
#X connect 4 1 8 0;
#X connect 5 0 3 0;
#X connect 6 0 5 1;
#X connect 7 0 0 0;
#X connect 10 0 11 0;
#X connect 11 0 1 0;
#X connect 11 1 1 2;
#X connect 11 2 1 1;
#X connect 13 0 10 0;
#X connect 14 0 10 1;


More information about the Pd-list mailing list