diff options
author | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-13 16:02:50 +0000 |
---|---|---|
committer | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-13 16:02:50 +0000 |
commit | 386b250dd27a237a4498161fbec4e8e1f3eb0438 (patch) | |
tree | 5a517ec73a7d1154b46d989103b0ab9c635ab541 /dynreceive.tcl | |
parent | c32da54436725487fb784119c8aec28080af843e (diff) |
add a usage example of pd_bind/pd_unbind
svn path=/trunk/externals/tclpd/; revision=12332
Diffstat (limited to 'dynreceive.tcl')
-rw-r--r-- | dynreceive.tcl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/dynreceive.tcl b/dynreceive.tcl new file mode 100644 index 0000000..e9c61b5 --- /dev/null +++ b/dynreceive.tcl @@ -0,0 +1,52 @@ +source pdlib.tcl + +pd::class dynreceive { + constructor { + set @sym {} + if {[pd::args] > 0} { + set @sym [pd::arg 0 symbol] + pd_bind [tclpd_get_instance_pd $self] [gensym $@sym] + } + pd::add_outlet $self + } + + destructor { + # don't forget to call pd_unbind, or sending things to a symbol + # bound to dead object will crash pd! + if {$@sym != {}} { + pd_unbind [tclpd_get_instance_pd $self] [gensym $@sym] + } + } + + 0_set { + # send [set empty( to clear the receive symbol + set s [pd::arg 0 symbol] + if {$@sym != {}} { + pd_unbind [tclpd_get_instance_pd $self] [gensym $@sym] + } + if {$s == {empty}} { + set @sym {} + } else { + set @sym $s + pd_bind [tclpd_get_instance_pd $self] [gensym $@sym] + } + } + + 0_bang { + pd::outlet $self 0 bang + } + + 0_float { + pd::outlet $self 0 float [pd::arg 0 float] + } + + 0_symbol { + pd::outlet $self 0 symbol [gensym [pd::arg 0 symbol]] + } + + 0_anything { + set sel [pd::arg 0 symbol] + set argz [lrange $args 1 end] + pd::outlet $self 0 $sel $argz + } +} |