[PD-cvs] pd/src desire.tk,1.1.2.600.2.146,1.1.2.600.2.147

chunlee chunlee at users.sourceforge.net
Sun Dec 31 19:49:23 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16226

Modified Files:
      Tag: desiredata
	desire.tk 
Log Message:
first attempts on subpatcherize that perserves the connection


Index: desire.tk
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.tk,v
retrieving revision 1.1.2.600.2.146
retrieving revision 1.1.2.600.2.147
diff -C2 -d -r1.1.2.600.2.146 -r1.1.2.600.2.147
*** desire.tk	31 Dec 2006 00:35:26 -0000	1.1.2.600.2.146
--- desire.tk	31 Dec 2006 18:49:19 -0000	1.1.2.600.2.147
***************
*** 297,300 ****
--- 297,307 ----
  set subpatcherize(edit) 0 
  set subpatcherize(paste) 0
+ set subpatcherize(incoming) {}
+ set subpatcherize(incoming_inlet) {}
+ set subpatcherize(incoming_outlet) {}
+ set subpatcherize(outgoing) {}
+ set subpatcherize(outgoing_inlet) {}
+ set subpatcherize(outgoing_outlet) {}
+ 
  #-----------------------------------------------------------------------------------#
  # adapted from matju's MetaRuby (UndoQueue.rb)
***************
*** 2397,2401 ****
  		} else {
  			if {$subpatcherize(paste)} {set subpatherize(paste) 0}
! 			if {$subpatcherize(edit)} {set subpatherize(edit) 0}
  		}
  		
--- 2404,2408 ----
  		} else {
  			if {$subpatcherize(paste)} {set subpatherize(paste) 0}
! 			if {$subpatcherize(edit)} {set subpatherize(edit) 0; $self draw_wires}
  		}
  		
***************
*** 3287,3291 ****
--- 3294,3312 ----
  
  def Canvas new_object_subpatcherize {subpatch} {$subpatch subpatcherize_paste}
+ def Canvas new_object_subpatcherize_inletconnect {inlet obj} {
+ 	puts "           inlet::: $inlet"
+ 	if {[regexp {^[0-9]{1,8}i} $inlet idx]} {set idx [string trimright $idx i]}
+ 	if {[regexp {i[0-9]{1,8}} $inlet port]} {set port [string trimleft $port i]}
+ 	$self connect [list [lsearch $@children $obj] 0 $idx $port]
+ }
+ def Canvas new_object_subpatcherize_outletconnect {outlet obj} {
+ 	if {[regexp {^[0-9]{1,8}o} $outlet idx]} {set idx [string trimright $idx o]}
+ 	if {[regexp {o[0-9]{1,8}} $outlet port]} {set port [string trimleft $port o]}
+ 	$self connect [list $idx $port [lsearch $@children $obj] 0]
+ }
  def Canvas subpatcherize {} {
+ 	set ::subpatcherize(incoming) {}; set ::subpatcherize(outgoing) {}
+ 	set ::subpatcherize(incoming_inlet) {}; set ::subpatcherize(incoming_outlet) {}
+ 	set ::subpatcherize(outgoing_inlet) {}; set ::subpatcherize(outgoing_outlet) {}
  	if {![llength $@selection]} {return}
  	set x 0; set y 0
***************
*** 3297,3308 ****
  	set x [expr $x / [llength $@selection]]
  	set y [expr $y / [llength $@selection]]
  	$self cut
  	netsend [list .$self "push"]
  	netsend [list #N canvas 0 0 450 300 sub 0] [list $self new_object_subpatcherize]
  	netsend [list #X restore $x $y pd sub]
  	netsend [list .$self "pop"]
  }
! def Canvas subpatcherize_paste {} {
  	global subpatcherize
  	set subpatcherize(paste) 1
  	set in 0
--- 3318,3407 ----
  	set x [expr $x / [llength $@selection]]
  	set y [expr $y / [llength $@selection]]
+ 	$self subpatcherize_outside
  	$self cut
+ 	$self subpatcherize_make_sub $x $y
+ }
+ 
+ def Canvas subpatcherize_make_sub {x y} {
  	netsend [list .$self "push"]
  	netsend [list #N canvas 0 0 450 300 sub 0] [list $self new_object_subpatcherize]
  	netsend [list #X restore $x $y pd sub]
  	netsend [list .$self "pop"]
+ 
  }
! 
! def Canvas subpatcherize_outside {} {
! 	foreach x $@selection {
! 		foreach wire [$x wires2] {$self subpatcherize_outside_wire $x $wire}
! 	}
! }
! def Canvas subpatcherize_outside_wire {x wire} {
! 	set wire_list [$wire report]
! 	switch [lsearch $wire_list $x] {
! 		0 {
! 			set obj [lindex $wire_list 2]
! 			if {[lsearch $@selection $obj] < 0} {
! 				set outlet [lindex $wire_list 1]
! 				set x_idx [lsearch $@selection $x]
! 				set obj_out ${x_idx}o${outlet}
! 				if {[lsearch $::subpatcherize(outgoing_outlet) $obj_out] < 0} {
! 					lappend ::subpatcherize(outgoing_outlet) $obj_out
! 				}
! 				set inlet [lindex $wire_list 3]
! 				set outlet [lsearch $::subpatcherize(outgoing_outlet) $obj_out]
! 				lappend ::subpatcherize(outgoing) [list last $outlet $obj $inlet]
! 				set obj_in ${obj}i${inlet}
! 				if {[lsearch $::subpatcherize(outgoing_inlet) $obj_in] < 0} {
! 					lappend ::subpatcherize(outgoing_inlet) $obj_in
! 				}
! 			}
! 		}
! 		2 {
! 			set obj [lindex $wire_list 0]
! 			if {[lsearch $@selection $obj] < 0} {
! 				set inlet [lindex $wire_list 3]
! 				set x_idx [lsearch $@selection $x]
! 				set obj_in ${x_idx}i${inlet}
! 				if {[lsearch $::subpatcherize(incoming_inlet) $obj_in] < 0} {
! 					lappend ::subpatcherize(incoming_inlet) $obj_in
! 				}
! 				set outlet [lindex $wire_list 1]
! 				set inlet [lsearch $::subpatcherize(incoming_inlet) $obj_in]
! 				lappend ::subpatcherize(incoming) [list $obj $outlet last $inlet]
! 				set obj_out ${obj}o${outlet}
! 				if {[lsearch $::subpatcherize(incoming_outlet) $obj_out] < 0} {
! 					lappend ::subpatcherize(incoming_outlet) $obj_out
! 				}
! 			}
! 		}
! 	}
! 	puts "-------------------------------------"
! 	puts " in:::: $::subpatcherize(incoming)"
! 	puts " incoming_outlet:: $::subpatcherize(incoming_outlet)  "
! 	puts " incoming_inlet::: $::subpatcherize(incoming_inlet)"
! 	puts "-------------------------------------"
! 	puts " out:::: $::subpatcherize(outgoing)"
! 	puts " outgoing_outlet:: $::subpatcherize(outgoing_outlet)  "
! 	puts " outgoing_inlet::: $::subpatcherize(outgoing_inlet)"
! 	puts "-------------------------------------"
! 
! }
! def Canvas subpatcherize_makeports {} {
  	global subpatcherize
+ 	set i 0
+ 	foreach inlet $::subpatcherize(incoming_inlet) {
+ 		netsend [list #X obj [expr $i*100] 0 inlet] \
+ 		    [list $self new_object_subpatcherize_inletconnect $inlet]
+ 		incr i
+ 	}
+ 	set i 0
+ 	foreach outlet $::subpatcherize(outgoing_outlet) {
+ 		netsend [list #X obj [expr $i*100] 200 outlet] \
+ 		    [list $self new_object_subpatcherize_outletconnect $outlet]
+ 		incr i
+ 	}
+ }
+ 
+ def Canvas subpatcherize_paste {} {
  	set subpatcherize(paste) 1
  	set in 0
***************
*** 3310,3318 ****
  	netsend [list .$self "push"]
  	foreach mess [pd_mess_split [$::clipboard value]] {netsend $mess}
  	netsend [list #X pop 1]
! 	set subpatcherize(edit) 1
  	$self edit
  }
  
  def Canvas end_action {} {
  	switch -- $@action {
--- 3409,3436 ----
  	netsend [list .$self "push"]
  	foreach mess [pd_mess_split [$::clipboard value]] {netsend $mess}
+ 	$self subpatcherize_makeports
  	netsend [list #X pop 1]
! 	$self subpatcherize_reconnect_outside
! 	set ::subpatcherize(edit) 1
  	$self edit
  }
  
+ def Canvas subpatcherize_reconnect_outside {} {
+ 	foreach wire $::subpatcherize(incoming) {
+ 		set canvas [$self canvas]
+ 		set from [lsearch [$canvas children] [lindex $wire 0]]
+ 		set to [lsearch [[$self canvas] children] $self]
+ 		set wire2 [list $from [lindex $wire 1] $to [lindex $wire 3]]
+ 		$canvas connect $wire2
+ 	}
+ 	foreach wire $::subpatcherize(outgoing) {
+ 		set canvas [$self canvas]
+ 		set to [lsearch [$canvas children] [lindex $wire 2]]
+ 		set from [lsearch [[$self canvas] children] $self]
+ 		set wire2 [list $from [lindex $wire 1] $to [lindex $wire 3]]
+ 		$canvas connect $wire2
+ 	}
+ }
+ 
  def Canvas end_action {} {
  	switch -- $@action {





More information about the Pd-cvs mailing list