2
2
# This line continues for Tcl, but is a single line for 'sh' \
3
3
exec /usr/bin/wish " $0 " -- ${1+" $@ " }
4
4
5
- # TODO accept biquad lists on the inlet
6
5
# TODO handle changes in samplerate using [block~]
7
- # TODO make Tk tags local to each instance...
8
6
9
7
# ------------- .mmb edits ----------------
10
8
#
@@ -605,6 +603,7 @@ proc filterview::changebandwidth {my x y} {
605
603
}
606
604
set filterwidth [expr $filterx2 - $filterx1 ]
607
605
set filtercenter [expr $filterx1 + ($filterwidth /2)]
606
+
608
607
$tkcanvas coords bandleft$tag $filterx1 $framey1 $filterx1 $framey2
609
608
$tkcanvas coords bandcenter$tag $filtercenter $framey1 $filtercenter $framey2
610
609
$tkcanvas coords bandright$tag $filterx2 $framey1 $filterx2 $framey2
@@ -731,14 +730,13 @@ proc filterview::set_for_editmode {mytoplevel} {
731
730
732
731
# ------------------------------------------------------------------------------#
733
732
734
- # sets up an instance of the class
735
- proc filterview::new {my canvas name t x1 y1 x2 y2} {
733
+ # sets up an new instance of the class
734
+ proc filterview::new {my canvas rname t x1 y1 x2 y2} {
736
735
namespace eval $my {
737
- # ------------------------------
738
- # per-instance variables
739
- variable tag " tag"
740
- variable tkcanvas " .tkcanvas"
741
- variable receive_name " receive_name"
736
+ # init all here to make sure they are not blank
737
+ variable tag " tag" ; # unique ID for canvas elements
738
+ variable tkcanvas " .tkcanvas" ; # Tk canvas this is drawn on
739
+ variable receive_name " receive_name" ; # Pd name to send callbacks to
742
740
743
741
variable currentfiltertype " peaking"
744
742
@@ -752,23 +750,31 @@ proc filterview::new {my canvas name t x1 y1 x2 y2} {
752
750
variable b1 0
753
751
variable b2 0
754
752
}
755
- variable ${my} ::tkcanvas $canvas
756
- variable ${my} ::receive_name $name
753
+
754
+ variable ${my} ::receive_name $rname
757
755
variable ${my} ::tag $t
758
756
757
+ update $my $canvas $x1 $y1 $x2 $y2
758
+ }
759
+
760
+ # updates an existing instance when its about to be drawn again
761
+ proc filterview::update {my canvas x1 y1 x2 y2} {
762
+ variable ${my} ::tkcanvas $canvas
763
+
759
764
# convert these all to floats so the math works properly
760
765
variable ${my} ::framex1 [expr $x1 * 1.0]
761
766
variable ${my} ::framey1 [expr $y1 * 1.0]
762
767
variable ${my} ::framex2 [expr $x2 * 1.0]
763
768
variable ${my} ::framey2 [expr $y2 * 1.0]
764
-
769
+
765
770
variable ${my} ::midpoint [expr (( $framey2 - $framey1 ) / 2 ) + $framey1 ]
766
771
variable ${my} :: hzperpixel [expr 20000 .0 / ($framex2 - $framex1 )]
767
772
variable ${my} :: magnatudeperpixel [expr 0 .5 / ($framey2 - $framey1 )]
768
773
769
774
# TODO make these set by something else, saved state?
770
775
variable ${my} :: filterx1 [expr $framex1 + 120 .0 ]
771
776
variable ${my} :: filterx2 [expr $framex1 + 180 .0 ]
777
+ # TODO what about gain?
772
778
773
779
variable ${my} :: filtergain $midpoint
774
780
variable ${my} :: filterwidth [expr $filterx2 - $filterx1 ]
@@ -809,11 +815,17 @@ proc filterview::setfiltertype {my filtertype} {
809
815
update_coefficients $my
810
816
}
811
817
812
- proc filterview::drawme {my} {
818
+ proc filterview::drawme {my canvas name t x1 y1 x2 y2 filtertype} {
819
+ # if the $my namespace already exists, that means we already
820
+ # have an instance active and setup.
821
+ if {[namespace exists $my ]} {
822
+ update $my $canvas $x1 $y1 $x2 $y2
823
+ } else {
824
+ new $my $canvas $name $t $x1 $y1 $x2 $y2
825
+ }
813
826
variable ${my} :: tkcanvas
814
827
variable ${my} :: receive_name
815
828
variable ${my} :: tag
816
- variable ${my} :: currentfiltertype
817
829
variable ${my} :: framex1
818
830
variable ${my} :: framey1
819
831
variable ${my} :: framex2
@@ -878,7 +890,7 @@ proc filterview::drawme {my} {
878
890
$framex2 $outlety $outletx $outlety $outletx $framey2 \
879
891
-tags [list $tag nlet$tag ]
880
892
881
- setfiltertype $my $currentfiltertype
893
+ setfiltertype $my $filtertype
882
894
883
895
# run to set things up
884
896
stop_editing $my
@@ -936,10 +948,8 @@ proc filterview::setup {} {
936
948
wm geometry . 400 x400 +500 +40
937
949
canvas $tkcanvas
938
950
pack $tkcanvas -side left -expand 1 -fill both
939
- filterview::new $my $tkcanvas FAKE_RECEIVE_NAME $tag 30 .0 30 .0 330 .0 230 .0
951
+ filterview::drawme $my $tkcanvas FAKE_RECEIVE_NAME $tag 30 .0 30 .0 330 .0 230 .0 "peaking"
940
952
filterview::set_for_editmode .
941
- filterview::setfiltertype $my "peaking"
942
- filterview::drawme $my
943
953
}
944
954
}
945
955
0 commit comments