Stack overflow usually comes from recursiveness in patches until Pd's stack
overflows, or at least that's my experience of that error.

The pdtk_post logic has changed a lot in 0.43 with drastic improvements.  You
can now post 1000 lines/sec and still patch in Pd.

In related work, I've been playing around with making array redrawing respect
the Tk event loop more.  Basically, each draw command you send gets queued
until the event loop executes it.  But for something like an array, there is
no reason to draw multiple times in a single loop, so when a new draw command
gets posted, it cancels the previous one if it hasn't run already.  That is
the key to what made pdtk_post so much faster as well.  Another part of that
is using "after idle" so that Tk doesn't drop everything to try to run that
command, but instead queues it to happen in a big chunk.

You can see the first stab at this work for arrays in the attached patches.
The first patch is only there because it needs to be applied for the 2nd patch
to apply cleanly.  They apply to pure-data.git master.

.hc


On 10/24/2012 08:47 PM, Ivica Bukvic wrote:
> It is only the draw command, not the communication...
> 
> BTW do either of you know why one would be getting pdtk_post { stack
> overflow } messages? Doors that mean the cpu is unable to handle all gui
> requests?
> On Oct 24, 2012 8:32 PM, "Hans-Christoph Steiner" <[email protected]> wrote:
> 
>>
>> Thanks for that info.  Sounds like a good idea in general.  I personally
>> can't
>> think of any reason why the DSP would need to be on during the quitting.
>>  But
>> for the 'redraw' part, that depends.  If it is literally only redrawing
>> that
>> is suspended, that would be fine.  But if its all Pd<-->GUI communications,
>> that will probably cause problems.
>>
>> .hc
>>
>> On 10/24/2012 06:02 PM, Ivica Ico Bukvic wrote:
>>> Hans and Iohannes,
>>>
>>> The following is FYI.
>>>
>>> Several months ago I integrated the close all patches before quitting
>> patch
>>> in pd-l2ork and since then I've been experiencing extremely sporadic
>> crashes
>>> on close that would hang pd-l2ork. Now, I am not sure this is because of
>>> architectural differences between regular pd and pd-l2ork but I doubt it
>>> since most of the said components are very similar if not identical.
>>>
>>> The bottom line is this only occurs on very low-powered machines (e.g.
>>> netbook) and relatively large patches and even then it does so very
>>> sporadically. Consequently, I implemented an improvement to the closing
>>> mechanism that consists of 2 additional steps and apparently alleviates
>> said
>>> problems entirely:
>>>
>>> 1) disable further redraws (this prevents calling functions that may be
>>> referencing null pointers)--I have a special global var for this which is
>>> also being used to optimize redrawing (many actions in pd-l2ork are
>> several
>>> times faster than regular pd as a result of this implementation--just
>> look
>>> for do_not_redraw call in the source if curious)
>>>
>>> 2) suspend dsp before going through the patches (all sub-patches try to
>>> suspend it and resume it but for some reason, due to asynchronous nature
>> of
>>> communication between tcl and c funny things occasionally happen on
>>> low-powered machines, so this way we ensure it is entirely off throughout
>>> the whole destruction process)
>>>
>>> Hope this helps!
>>>
>>> Ivica Ico Bukvic, D.M.A.
>>> Composition, Music Technology
>>> Director, DISIS Interactive Sound & Intermedia Studio
>>> Director, L2Ork Linux Laptop Orchestra
>>> Head, ICAT IMPACT Studio
>>> Virginia Tech
>>> Dept. of Music - 0240
>>> Blacksburg, VA 24061
>>> (540) 231-6139
>>> (540) 231-5034 (fax)
>>> [email protected]
>>> http://www.music.vt.edu/faculty/bukvic/
>>>
>>>
>>>
>>
> 
>From f994eb249daf8dac552ea97e9f40ed0cf32456fa Mon Sep 17 00:00:00 2001
From: Hans-Christoph Steiner <[email protected]>
Date: Mon, 8 Oct 2012 10:56:24 -0400
Subject: [PATCH 1/2] remove pdtk_array.tcl, its unused and is old duplicates
 of dialog_array.tcl

---
 po/Makefile.am     |    2 +-
 tcl/Makefile.am    |    2 +-
 tcl/pdtk_array.tcl |  346 ----------------------------------------------------
 tcl/pkgIndex.tcl   |    1 -
 4 files changed, 2 insertions(+), 349 deletions(-)
 delete mode 100644 tcl/pdtk_array.tcl

diff --git a/po/Makefile.am b/po/Makefile.am
index da38360..0dd847f 100644
--- a/po/Makefile.am
+++ b/po/Makefile.am
@@ -9,7 +9,7 @@ if MACOSX
   PATH := /sw/lib/gettext-tools-0.17/bin:${PATH}
 endif
 
-TCLFILES = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pdtk_array.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl scrollbox.tcl pd_guiprefs.tcl
+TCLFILES = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl scrollbox.tcl pd_guiprefs.tcl
 
 FILES = $(addprefix ../tcl/, $(TCLFILES)) iemgui_dynamic_strings.tcl pd_dynamic_strings.tcl
 
diff --git a/tcl/Makefile.am b/tcl/Makefile.am
index b553f77..3f7809e 100644
--- a/tcl/Makefile.am
+++ b/tcl/Makefile.am
@@ -10,7 +10,7 @@ bin_SCRIPTS = pd-gui.tcl
 
 libpdtcldir = $(pkglibdir)/tcl
 dist_libpdtcl_SCRIPTS = pd-gui.tcl
-dist_libpdtcl_DATA = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pdtk_array.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl pdtk_textwindow.tcl scrollbox.tcl pd_guiprefs.tcl pd.ico
+dist_libpdtcl_DATA = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl pdtk_textwindow.tcl scrollbox.tcl pd_guiprefs.tcl pd.ico
 
 etags: TAGS
 	etags --append --language=none --regex="/proc[ \t]+\([^ \t]+\)/\1/" *.tcl
diff --git a/tcl/pdtk_array.tcl b/tcl/pdtk_array.tcl
deleted file mode 100644
index 107a722..0000000
--- a/tcl/pdtk_array.tcl
+++ /dev/null
@@ -1,346 +0,0 @@
-package provide pdtk_array 0.1
-
-#### jsarlo #####
-proc pdtk_array_listview_setpage {arrayName page} {
-    global pd_array_listview_page
-    set pd_array_listview_page($arrayName) $page
-}
-
-proc pdtk_array_listview_changepage {arrayName np} {
-    global pd_array_listview_page
-    pdtk_array_listview_setpage \
-        $arrayName [expr $pd_array_listview_page($arrayName) + $np]
-    pdtk_array_listview_fillpage $arrayName
-}
-
-proc pdtk_array_listview_fillpage {arrayName} {
-    global pd_array_listview_page
-    global pd_array_listview_id
-    set windowName [format ".%sArrayWindow" $arrayName]
-    set topItem [expr [lindex [$windowName.lb yview] 0] * \
-                     [$windowName.lb size]]
-    
-    if {[winfo exists $windowName]} {
-        set cmd "$pd_array_listview_id($arrayName) \
-               arrayviewlistfillpage \
-               $pd_array_listview_page($arrayName) \
-               $topItem"
-        
-        pdsend $cmd
-    }
-}
-
-proc pdtk_array_listview_new {id arrayName page} {
-    global pd_array_listview_page
-    global pd_array_listview_id
-    global fontname fontweight
-    set pd_array_listview_page($arrayName) $page
-    set pd_array_listview_id($arrayName) $id
-    set windowName [format ".%sArrayWindow" $arrayName]
-    if [winfo exists $windowName] then [destroy $windowName]
-    toplevel $windowName
-    wm protocol $windowName WM_DELETE_WINDOW \
-        "pdtk_array_listview_close $id $arrayName"
-    wm title $windowName [concat $arrayName "(list view)"]
-    # FIXME
-    set font 12
-    set $windowName.lb [listbox $windowName.lb -height 20 -width 25\
-                            -selectmode extended \
-                            -relief solid -background white -borderwidth 1 \
-                            -font [format {{%s} %d %s} $fontname $font $fontweight]\
-                            -yscrollcommand "$windowName.lb.sb set"]
-    set $windowName.lb.sb [scrollbar $windowName.lb.sb \
-                               -command "$windowName.lb yview" -orient vertical]
-    place configure $windowName.lb.sb -relheight 1 -relx 0.9 -relwidth 0.1
-    pack $windowName.lb -expand 1 -fill both
-    bind $windowName.lb <Double-ButtonPress-1> \
-        "pdtk_array_listview_edit $arrayName $page $font"
-    # handle copy/paste
-    if {[tk windowingsystem] eq "x11"} {
-        selection handle $windowName.lb \
-            "pdtk_array_listview_lbselection $arrayName"
-    } else {
-        if {[tk windowingsystem] eq "win32"} {
-            bind $windowName.lb <ButtonPress-3> \
-                "pdtk_array_listview_popup $arrayName"
-        } 
-    }
-    set $windowName.prevBtn [button $windowName.prevBtn -text "<-" \
-                                 -command "pdtk_array_listview_changepage $arrayName -1"]
-    set $windowName.nextBtn [button $windowName.nextBtn -text "->" \
-                                 -command "pdtk_array_listview_changepage $arrayName 1"]
-    pack $windowName.prevBtn -side left -ipadx 20 -pady 10 -anchor s
-    pack $windowName.nextBtn -side right -ipadx 20 -pady 10 -anchor s
-    focus $windowName
-}
-
-proc pdtk_array_listview_lbselection {arrayName off size} {
-    set windowName [format ".%sArrayWindow" $arrayName]
-    set itemNums [$windowName.lb curselection]
-    set cbString ""
-    for {set i 0} {$i < [expr [llength $itemNums] - 1]} {incr i} {
-        set listItem [$windowName.lb get [lindex $itemNums $i]]
-        append cbString [string range $listItem \
-                             [expr [string first ") " $listItem] + 2] \
-                             end]
-        append cbString "\n"
-    }
-    set listItem [$windowName.lb get [lindex $itemNums $i]]
-    append cbString [string range $listItem \
-                         [expr [string first ") " $listItem] + 2] \
-                         end]
-    set last $cbString
-}
-
-# Win32 uses a popup menu for copy/paste
-proc pdtk_array_listview_popup {arrayName} {
-    set windowName [format ".%sArrayWindow" $arrayName]
-    if [winfo exists $windowName.popup] then [destroy $windowName.popup]
-    menu $windowName.popup -tearoff false
-    $windowName.popup add command -label {Copy} \
-        -command "pdtk_array_listview_copy $arrayName; \
-                  destroy $windowName.popup"
-    $windowName.popup add command -label {Paste} \
-        -command "pdtk_array_listview_paste $arrayName; \
-                  destroy $windowName.popup"
-    tk_popup $windowName.popup [winfo pointerx $windowName] \
-        [winfo pointery $windowName] 0
-}
-
-proc pdtk_array_listview_copy {arrayName} {
-    set windowName [format ".%sArrayWindow" $arrayName]
-    set itemNums [$windowName.lb curselection]
-    set cbString ""
-    for {set i 0} {$i < [expr [llength $itemNums] - 1]} {incr i} {
-        set listItem [$windowName.lb get [lindex $itemNums $i]]
-        append cbString [string range $listItem \
-                             [expr [string first ") " $listItem] + 2] \
-                             end]
-        append cbString "\n"
-    }
-    set listItem [$windowName.lb get [lindex $itemNums $i]]
-    append cbString [string range $listItem \
-                         [expr [string first ") " $listItem] + 2] \
-                         end]
-    clipboard clear
-    clipboard append $cbString
-}
-
-proc pdtk_array_listview_paste {arrayName} {
-    global pd_array_listview_page
-    global pd_array_listview_pagesize
-    set cbString [selection get -selection CLIPBOARD]
-    set lbName [format ".%sArrayWindow.lb" $arrayName]
-    set itemNum [lindex [$lbName curselection] 0]
-    set splitChars ", \n"
-    set itemString [split $cbString $splitChars]
-    set flag 1
-    for {set i 0; set counter 0} {$i < [llength $itemString]} {incr i} {
-        if {[lindex $itemString $i] != {}} {
-            pdsend "$arrayName [expr $itemNum + \
-                                       [expr $counter + \
-                                            [expr $pd_array_listview_pagesize \
-                                                 * $pd_array_listview_page($arrayName)]]] \
-                    [lindex $itemString $i]"
-            incr counter
-            set flag 0
-        }
-    }
-}
-
-proc pdtk_array_listview_edit {arrayName page font} {
-    global pd_array_listview_entry
-    global fontname fontweight
-    set lbName [format ".%sArrayWindow.lb" $arrayName]
-    if {[winfo exists $lbName.entry]} {
-        pdtk_array_listview_update_entry \
-            $arrayName $pd_array_listview_entry($arrayName)
-        unset pd_array_listview_entry($arrayName)
-    }
-    set itemNum [$lbName index active]
-    set pd_array_listview_entry($arrayName) $itemNum
-    set bbox [$lbName bbox $itemNum]
-    set y [expr [lindex $bbox 1] - 4]
-    set $lbName.entry [entry $lbName.entry \
-                           -font [format {{%s} %d %s} $fontname $font $fontweight]]
-    $lbName.entry insert 0 []
-    place configure $lbName.entry -relx 0 -y $y -relwidth 1
-    lower $lbName.entry
-    focus $lbName.entry
-    bind $lbName.entry <Return> \
-        "pdtk_array_listview_update_entry $arrayName $itemNum;"
-}
-
-proc pdtk_array_listview_update_entry {arrayName itemNum} {
-    global pd_array_listview_page
-    global pd_array_listview_pagesize
-    set lbName [format ".%sArrayWindow.lb" $arrayName]
-    set splitChars ", \n"
-    set itemString [split [$lbName.entry get] $splitChars]
-    set flag 1
-    for {set i 0; set counter 0} {$i < [llength $itemString]} {incr i} {
-        if {[lindex $itemString $i] != {}} {
-            pdsend [concat $arrayName [expr $itemNum + \
-                                       [expr $counter + \
-                                            [expr $pd_array_listview_pagesize \
-                                                 * $pd_array_listview_page($arrayName)]]] \
-                    [lindex $itemString $i] \;]
-            incr counter
-            set flag 0
-        }
-    }
-    pdtk_array_listview_fillpage $arrayName
-    destroy $lbName.entry
-}
-
-proc pdtk_array_listview_closeWindow {arrayName} {
-    set windowName [format ".%sArrayWindow" $arrayName]
-    destroy $windowName
-}
-
-proc pdtk_array_listview_close {id arrayName} {
-    pdtk_array_listview_closeWindow $arrayName
-    pdsend "$id arrayviewclose"
-}
-##### end jsarlo #####
-
-############ pdtk_array_dialog -- dialog window for arrays #########
-# see comments above (pdtk_gatom_dialog) about variable name handling 
-
-proc array_apply {id} {
-    # strip "." from the TK id to make a variable name suffix 
-    set vid [string trimleft $id .]
-    # for each variable, make a local variable to hold its name...
-    set var_array_name [concat array_name_$vid]
-    global $var_array_name
-    set var_array_n [concat array_n_$vid]
-    global $var_array_n
-    set var_array_saveit [concat array_saveit_$vid]
-    global $var_array_saveit
-    set var_array_drawasrects [concat array_drawasrects_$vid]
-    global $var_array_drawasrects
-    set var_array_otherflag [concat array_otherflag_$vid]
-    global $var_array_otherflag
-    set mofo [eval concat $$var_array_name]
-    if {[string index $mofo 0] == "$"} {
-        set mofo [string replace $mofo 0 0 #] }
-
-    set saveit [eval concat $$var_array_saveit]
-    set drawasrects [eval concat $$var_array_drawasrects]
-
-    pdsend "$id arraydialog $mofo [eval concat $$var_array_n] \
-            [expr $saveit + 2 * $drawasrects] [eval concat $$var_array_otherflag]"
-}
-
-# jsarlo
-proc array_viewlist {id} {
-    pdsend "$id arrayviewlistnew"
-}
-# end jsarlo
-
-proc array_cancel {id} {
-    pdsend "$id cancel"
-}
-
-proc array_ok {id} {
-    array_apply $id
-    array_cancel $id
-}
-
-proc pdtk_array_dialog {id name n flags newone} {
-    set vid [string trimleft $id .]
-
-    set var_array_name [concat array_name_$vid]
-    global $var_array_name
-    set var_array_n [concat array_n_$vid]
-    global $var_array_n
-    set var_array_saveit [concat array_saveit_$vid]
-    global $var_array_saveit
-    set var_array_drawasrects [concat array_drawasrects_$vid]
-    global $var_array_drawasrects
-    set var_array_otherflag [concat array_otherflag_$vid]
-    global $var_array_otherflag
-
-    set $var_array_name $name
-    set $var_array_n $n
-    set $var_array_saveit [expr ( $flags & 1 ) != 0]
-    set $var_array_drawasrects [expr ( $flags & 2 ) != 0]
-    set $var_array_otherflag 0
-
-    toplevel $id
-    wm title $id {array}
-    wm resizable $id 0 0
-    wm protocol $id WM_DELETE_WINDOW [concat array_cancel $id]
-
-    ::pd_bindings::panel_bindings $id "array"
-
-    frame $id.name
-    pack $id.name -side top
-    label $id.name.label -text "name"
-    entry $id.name.entry -textvariable $var_array_name
-    pack $id.name.label $id.name.entry -side left
-
-    frame $id.n
-    pack $id.n -side top
-    label $id.n.label -text "size"
-    entry $id.n.entry -textvariable $var_array_n
-    pack $id.n.label $id.n.entry -side left
-
-    checkbutton $id.saveme -text {save contents} -variable $var_array_saveit \
-        -anchor w
-    pack $id.saveme -side top
-
-    frame $id.drawasrects
-    pack $id.drawasrects -side top
-    radiobutton $id.drawasrects.drawasrects0 -value 0 \
-        -variable $var_array_drawasrects \
-        -text "draw as points"
-    radiobutton $id.drawasrects.drawasrects1 -value 1 \
-        -variable $var_array_drawasrects \
-        -text "polygon"
-    radiobutton $id.drawasrects.drawasrects2 -value 2 \
-        -variable $var_array_drawasrects \
-        -text "bezier curve"
-    pack $id.drawasrects.drawasrects0 -side top -anchor w
-    pack $id.drawasrects.drawasrects1 -side top -anchor w
-    pack $id.drawasrects.drawasrects2 -side top -anchor w
-
-    if {$newone != 0} {
-        frame $id.radio
-        pack $id.radio -side top
-        radiobutton $id.radio.radio0 -value 0 \
-            -variable $var_array_otherflag \
-            -text "in new graph"
-        radiobutton $id.radio.radio1 -value 1 \
-            -variable $var_array_otherflag \
-            -text "in last graph"
-        pack $id.radio.radio0 -side top -anchor w
-        pack $id.radio.radio1 -side top -anchor w
-    } else {    
-        checkbutton $id.deleteme -text {delete me} \
-            -variable $var_array_otherflag -anchor w
-        pack $id.deleteme -side top
-    }
-    # jsarlo
-    if {$newone == 0} {
-        button $id.listview -text {View list}\
-            -command "array_viewlist $id $name 0"
-        pack $id.listview -side left
-    }
-    # end jsarlo
-    frame $id.buttonframe
-    pack $id.buttonframe -side bottom -fill x -pady 2m
-    button $id.buttonframe.cancel -text {Cancel}\
-        -command "array_cancel $id"
-    if {$newone == 0} {button $id.buttonframe.apply -text {Apply}\
-                           -command "array_apply $id"}
-    button $id.buttonframe.ok -text {OK}\
-        -command "array_ok $id"
-    pack $id.buttonframe.cancel -side left -expand 1
-    if {$newone == 0} {pack $id.buttonframe.apply -side left -expand 1}
-    pack $id.buttonframe.ok -side left -expand 1
-    
-    $id.name.entry select from 0
-    $id.name.entry select adjust end
-    focus $id.name.entry
-}
diff --git a/tcl/pkgIndex.tcl b/tcl/pkgIndex.tcl
index e3f7d2f..5532237 100644
--- a/tcl/pkgIndex.tcl
+++ b/tcl/pkgIndex.tcl
@@ -35,4 +35,3 @@ package ifneeded pdtk_textwindow 0.1 [list source [file join $dir pdtk_textwindo
 package ifneeded scrollbox 0.1 [list source [file join $dir scrollbox.tcl]]
 package ifneeded scrollboxwindow 0.1 [list source [file join $dir scrollboxwindow.tcl]]
 package ifneeded wheredoesthisgo 0.1 [list source [file join $dir wheredoesthisgo.tcl]]
-package ifneeded pdtk_array 0.1 [list source [file join $dir pdtk_array.tcl]]
-- 
1.7.9.5

>From 681e9b2b35832559165c7371899d938ca2bec155 Mon Sep 17 00:00:00 2001
From: Hans-Christoph Steiner <[email protected]>
Date: Mon, 8 Oct 2012 12:21:45 -0400
Subject: [PATCH 2/2] first working version of "after idle" technique

---
 po/Makefile.am        |    2 +-
 src/g_template.c      |   22 +++++++++++-----
 tcl/Makefile.am       |    2 +-
 tcl/pd-gui.tcl        |    1 +
 tcl/pdtk_template.tcl |   67 +++++++++++++++++++++++++++++++++++++++++++++++++
 tcl/pkgIndex.tcl      |    1 +
 6 files changed, 87 insertions(+), 8 deletions(-)
 create mode 100644 tcl/pdtk_template.tcl

diff --git a/po/Makefile.am b/po/Makefile.am
index 0dd847f..1558015 100644
--- a/po/Makefile.am
+++ b/po/Makefile.am
@@ -9,7 +9,7 @@ if MACOSX
   PATH := /sw/lib/gettext-tools-0.17/bin:${PATH}
 endif
 
-TCLFILES = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl scrollbox.tcl pd_guiprefs.tcl
+TCLFILES = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_template.tcl pdtk_text.tcl scrollbox.tcl pd_guiprefs.tcl
 
 FILES = $(addprefix ../tcl/, $(TCLFILES)) iemgui_dynamic_strings.tcl pd_dynamic_strings.tcl
 
diff --git a/src/g_template.c b/src/g_template.c
index a2b583d..1b5f465 100644
--- a/src/g_template.c
+++ b/src/g_template.c
@@ -1416,6 +1416,9 @@ static void *plot_new(t_symbol *classsym, t_int argc, t_atom *argv)
     else fielddesc_setfloat_const(&x->x_xinc, 1);
     if (argc) fielddesc_setfloatarg(&x->x_style, argc--, argv++);
     else fielddesc_setfloat_const(&x->x_style, defstyle);
+
+    sys_vgui("pdtk_template_create_plot_line %lx\n", x);
+
     return (x);
 }
 
@@ -1828,7 +1831,8 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                     /* no "w" field.  If the linewidth is positive, draw a
                     segmented line with the requested width; otherwise don't
                     draw the trace at all. */
-                sys_vgui(".x%lx.c create line \\\n", glist_getcanvas(glist));
+                sys_vgui("::%lx::plot_line .x%lx.c {\\\n", x, glist_getcanvas(glist));
+                //sys_vgui(".x%lx.c create line \\\n", glist_getcanvas(glist));
 
                 for (xsum = xloc, i = 0; i < nelem; i++)
                 {
@@ -1860,11 +1864,17 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                     glist_ytopixels(glist, basey + yloc + 
                         fielddesc_cvttocoord(yfielddesc, yval)));
 
-                sys_vgui("-width %f\\\n", linewidth);
-                sys_vgui("-fill %s\\\n", outline);
-                if (style == PLOTSTYLE_BEZ) sys_vgui("-smooth 1\\\n");
-
-                sys_vgui("-tags [list plot%lx array]\n", data);
+                //sys_vgui("-width %f\\\n", linewidth);
+                //sys_vgui("-fill %s\\\n", outline);
+                //if (style == PLOTSTYLE_BEZ) sys_vgui("-smooth 1\\\n");
+
+                //sys_vgui("-tags [list plot%lx array]\n", data);
+                // NEW!
+                sys_vgui("} %f %s %i plot%lx \n",
+                         linewidth,
+                         outline,
+                         style == PLOTSTYLE_BEZ,
+                         data);
             }
         }
             /* We're done with the outline; now draw all the points.
diff --git a/tcl/Makefile.am b/tcl/Makefile.am
index 3f7809e..04f1ffd 100644
--- a/tcl/Makefile.am
+++ b/tcl/Makefile.am
@@ -10,7 +10,7 @@ bin_SCRIPTS = pd-gui.tcl
 
 libpdtcldir = $(pkglibdir)/tcl
 dist_libpdtcl_SCRIPTS = pd-gui.tcl
-dist_libpdtcl_DATA = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_text.tcl pdtk_textwindow.tcl scrollbox.tcl pd_guiprefs.tcl pd.ico
+dist_libpdtcl_DATA = apple_events.tcl dialog_canvas.tcl dialog_gatom.tcl dialog_path.tcl pd_bindings.tcl pd_menus.tcl pdwindow.tcl scrollboxwindow.tcl AppMain.tcl dialog_data.tcl dialog_iemgui.tcl dialog_startup.tcl pd_connect.tcl pkgIndex.tcl wheredoesthisgo.tcl dialog_array.tcl dialog_find.tcl dialog_message.tcl helpbrowser.tcl pdtk_canvas.tcl pkg_mkIndex.tcl dialog_audio.tcl dialog_font.tcl dialog_midi.tcl opt_parser.tcl pd_menucommands.tcl pdtk_template.tcl pdtk_text.tcl pdtk_textwindow.tcl scrollbox.tcl pd_guiprefs.tcl pd.ico
 
 etags: TAGS
 	etags --append --language=none --regex="/proc[ \t]+\([^ \t]+\)/\1/" *.tcl
diff --git a/tcl/pd-gui.tcl b/tcl/pd-gui.tcl
index fe1f87f..c6dc242 100755
--- a/tcl/pd-gui.tcl
+++ b/tcl/pd-gui.tcl
@@ -43,6 +43,7 @@ package require helpbrowser
 package require pd_menucommands
 package require opt_parser
 package require pdtk_canvas
+package require pdtk_template
 package require pdtk_text
 package require pdtk_textwindow
 # TODO eliminate this kludge:
diff --git a/tcl/pdtk_template.tcl b/tcl/pdtk_template.tcl
new file mode 100644
index 0000000..b9f5987
--- /dev/null
+++ b/tcl/pdtk_template.tcl
@@ -0,0 +1,67 @@
+package provide pdtk_template 0.1
+
+proc pdtk_template_create_plot_points {objectid dataid} {
+    namespace eval ::$dataid {
+        variable x1 0
+        variable y1 0
+        variable x2 0
+        variable y2 0
+        proc plot_points {x1 y1 x2 y2} {
+            set ::${dataid}::x1 $x1
+            set ::${dataid}::y1 $y1
+            set ::${dataid}::x2 $x2
+            set ::${dataid}::y2 $y2
+            $objectid create rectangle $x1 $y1 $x2 $y2 \
+                -fill black -width 0 -tags [list $dataid array]
+        }
+    }
+}
+
+proc pdtk_template_create_plot_line {objid} {
+    puts stderr "pdtk_template_create_plot_points $objid"
+    if { [namespace exists ::$objid] } {
+        return
+    }
+    namespace eval ::$objid {
+        variable ns
+        variable mycanvas
+        variable dataid
+        variable linewidth
+        variable color
+        variable smooth
+        variable coordlist
+        proc plot_line {mycanvas coordlist linewidth color smooth dataid} {
+            # if the previous draw_line hasn't fired yet, cancel it,
+            # we only need the most recent one to fire in a given event
+            # loop redraw cycle
+            variable ns
+            after cancel ::${ns}::do_plot_line
+            set ::${ns}::mycanvas $mycanvas
+            set ::${ns}::coordlist $coordlist
+            set ::${ns}::linewidth $linewidth
+            set ::${ns}::color $color
+            set ::${ns}::smooth $smooth
+            set ::${ns}::dataid $dataid
+            after idle ::${ns}::do_plot_line
+        }
+        proc do_plot_line {} {
+            variable mycanvas
+            variable coordlist
+            variable linewidth
+            variable color
+            variable smooth
+            variable dataid
+            # puts stderr "mycanvas: $mycanvas"
+            # puts stderr "coordlist: $coordlist"
+            # puts stderr "linewidth: $linewidth"
+            # puts stderr "color: $color"
+            # puts stderr "smooth: $smooth"
+            # puts stderr "dataid: $dataid"
+            $mycanvas create line $coordlist \
+                -width $linewidth -fill $color -smooth $smooth \
+                -tags [list $dataid array]
+        }
+    }
+    set ::${objid}::ns $objid
+    puts stderr "pdtk_template_create_plot_points $objid DONE"
+}
diff --git a/tcl/pkgIndex.tcl b/tcl/pkgIndex.tcl
index 5532237..7dbeaf4 100644
--- a/tcl/pkgIndex.tcl
+++ b/tcl/pkgIndex.tcl
@@ -30,6 +30,7 @@ package ifneeded pdwindow 0.1 [list source [file join $dir pdwindow.tcl]]
 package ifneeded pd_menucommands 0.1 [list source [file join $dir pd_menucommands.tcl]]
 package ifneeded pd_menus 0.1 [list source [file join $dir pd_menus.tcl]]
 package ifneeded pdtk_canvas 0.1 [list source [file join $dir pdtk_canvas.tcl]]
+package ifneeded pdtk_template 0.1 [list source [file join $dir pdtk_template.tcl]]
 package ifneeded pdtk_text 0.1 [list source [file join $dir pdtk_text.tcl]]
 package ifneeded pdtk_textwindow 0.1 [list source [file join $dir pdtk_textwindow.tcl]]
 package ifneeded scrollbox 0.1 [list source [file join $dir scrollbox.tcl]]
-- 
1.7.9.5

_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to