[PD-dev] [PATCH 06/10] fixed race-condition in the audio/midi API initialization

Hans-Christoph Steiner hans at at.or.at
Thu Jul 15 15:46:09 CEST 2010


That's the idea of the wait4pd stuff, to make sure that pd is started  
before continuing on.  I don't think this is necessary.  Do you have a  
way to trigger pd taking too long to start up?

.hc

On Jul 15, 2010, at 2:57 AM, IOhannes m zmoelnig wrote:

> if Pd takes too long to startup, Pd-gui will initialize the audio/ 
> midi API-menus
> with NULL-lists;
> if Pd finally shows up, the menu cannot be modified anymore, and  
> thus the user
> cannot select the API they want.
>
> the fix moves the audio/midi APIs into a sub-menu of "Media", and  
> provides a
> function ::pd_menus::build_media_api_menus that will clear the old  
> API-menus and
> refill them with the new API-lists.
> this allows Pd-core, to update the API-lists after the GUI has been  
> initialized.
> ---
> tcl/pd-gui.tcl   |    1 +
> tcl/pd_menus.tcl |   50 ++++++++++++++++++++++++++++++++ 
> +-----------------
> 2 files changed, 34 insertions(+), 17 deletions(-)
>
> diff --git a/tcl/pd-gui.tcl b/tcl/pd-gui.tcl
> index c99decc..b4f20b3 100755
> --- a/tcl/pd-gui.tcl
> +++ b/tcl/pd-gui.tcl
> @@ -460,6 +460,7 @@ proc pdtk_pd_startup {major minor bugfix test
>     if {$::tcl_version >= 8.5} {find_default_font}
>     set_base_font $sys_font $sys_fontweight
>     fit_font_into_metrics
> +    ::pd_menus::build_media_api_menus $::pdwindow_menubar.media
>     set ::wait4pd "started"
> }
>
> diff --git a/tcl/pd_menus.tcl b/tcl/pd_menus.tcl
> index fc617df..7157c5e 100644
> --- a/tcl/pd_menus.tcl
> +++ b/tcl/pd_menus.tcl
> @@ -224,6 +224,32 @@ proc ::pd_menus::build_find_menu {mymenu} {
>         -command {pdsend {pd finderror}}
> }
>
> +
> +## update the audio/midi API lists
> +# this is done by first clearing the menus, and then rebuilding  
> them from scratch
> +proc ::pd_menus::build_media_api_menus {mymenu} {
> +    if { [winfo exists $mymenu.audio] } {
> +        $mymenu.audio delete 0 [ $mymenu.audio index last]
> +        set audio_apilist_length [llength $::audio_apilist]
> +        for {set x 0} {$x<$audio_apilist_length} {incr x} {
> +            $mymenu.audio add radiobutton -label [lindex [lindex  
> $::audio_apilist $x] 0] \
> +                -command {menu_audio 0} -variable ::pd_whichapi \
> +                -value [lindex [lindex $::audio_apilist $x] 1]\
> +                -command {pdsend "pd audio-setapi $::pd_whichapi"}
> +        }
> +    }
> +    if { [winfo exists $mymenu.midi] } {
> +        $mymenu.midi  delet  0 [ $mymenu.midi  index last]
> +        set midi_apilist_length [llength $::midi_apilist]
> +        for {set x 0} {$x<$midi_apilist_length} {incr x} {
> +            $mymenu.midi add radiobutton -label [lindex [lindex  
> $::midi_apilist $x] 0] \
> +                -command {menu_midi 0} -variable ::pd_whichmidiapi \
> +                -value [lindex [lindex $::midi_apilist $x] 1]\
> +                -command {pdsend "pd midi-setapi $::pd_whichmidiapi"}
> +        }
> +    }
> +}
> +
> proc ::pd_menus::build_media_menu {mymenu} {
>     variable accelerator
>     $mymenu add radiobutton -label [_ "DSP On"] -accelerator  
> "$accelerator+/" \
> @@ -237,23 +263,13 @@ proc ::pd_menus::build_media_menu {mymenu} {
>     $mymenu add command -label [_ "Load Meter"] \
>         -command {menu_doc_open doc/7.stuff/tools load-meter.pd}
>
> -    set audio_apilist_length [llength $::audio_apilist]
> -    if {$audio_apilist_length > 0} {$mymenu add separator}
> -    for {set x 0} {$x<$audio_apilist_length} {incr x} {
> -        $mymenu add radiobutton -label [lindex [lindex  
> $::audio_apilist $x] 0] \
> -            -command {menu_audio 0} -variable ::pd_whichapi \
> -            -value [lindex [lindex $::audio_apilist $x] 1]\
> -            -command {pdsend "pd audio-setapi $::pd_whichapi"}
> -    }
> -
> -    set midi_apilist_length [llength $::midi_apilist]
> -    if {$midi_apilist_length > 0} {$mymenu add separator}
> -    for {set x 0} {$x<$midi_apilist_length} {incr x} {
> -        $mymenu add radiobutton -label [lindex [lindex  
> $::midi_apilist $x] 0] \
> -            -command {menu_midi 0} -variable ::pd_whichmidiapi \
> -            -value [lindex [lindex $::midi_apilist $x] 1]\
> -            -command {pdsend "pd midi-setapi $::pd_whichmidiapi"}
> -    }
> +    menu $mymenu.audio
> +    menu $mymenu.midi
> +    $mymenu add cascade -label [_ "Audio"] -menu $mymenu.audio
> +    $mymenu add cascade -label [_ "Midi"] -menu $mymenu.midi
> +
> +    build_media_api_menus $mymenu
> +
>     if {$::windowingsystem ne "aqua"} {
>         $mymenu add  separator
>         create_preferences_menu $mymenu.preferences
> -- 
> 1.7.1
>



----------------------------------------------------------------------------

Terrorism is not an enemy.  It cannot be defeated.  It's a tactic.   
It's about as sensible to say we declare war on night attacks and  
expect we're going to win that war.  We're not going to win the war on  
terrorism.        - retired U.S. Army general, William Odom





More information about the Pd-dev mailing list