Hi João,

It appeared to be a simple program in Tcl, which you should have, as it comes with Pd. The usage is: tclsh changeCoords.tcl patchName xcoord ycoord line1 ?line2? ...
lineN arguments may be a number or a range, like 12-15.

The patch is currently dumped to the console. Only minimal checking is done.

If you remove the #'s for the puts "..." lines, you can see some interim results (which will ruin the patch format).

Greetings,

Fred Jan
#!/usr/bin/env tclsh
#

if {$argc < 4} {
    error "Usage: tclsh changeCoords.tcl patchName xcoord ycoord line1 ?line2? ..."
}

set patchName [lindex $argv 0]
set xcoord    [lindex $argv 1]
set ycoord    [lindex $argv 2]
set lineArgCount $argc
set lineList {}

#puts "patchName $patchName; xcoord $xcoord; ycoord $ycoord lineArgCount; $lineArgCount"
# line arguments may be numeric or a numeric range "nn-mm" (inclusive)

for {set start 3} {$lineArgCount > $start} {incr start} {
        set arg [lindex $argv $start]
#        puts "$start: $arg"
        if [regexp {(\d+)-(\d+)} $arg lineRange startLine endLine] {
                if {$startLine < $endLine} {
#                        puts "startLine $startLine; endLine $endLine;;  $lineRange"
                        for {set line $startLine} {$line <= $endLine} {incr line} {
                                lappend lineList $line
                        }
                }
        } else {
#                puts "line $arg"
                lappend lineList $arg
        }
}

puts "lines to patch: $lineList"

set lineCount 1
set f [open $patchName]
while {[gets $f patchLine] >= 0} {
    if [regexp {\#[ANX] } $patchLine] {
        if {[lsearch $lineList $lineCount] >= 0} {
            if [regexp {\#X obj (\d+) (\d+) (.+)} $patchLine allOfLine orgX orgY restOfLine] {
#                puts -nonewline "$lineCount: "
                puts "#X obj $xcoord $ycoord $restOfLine"
            } else {
#                puts -nonewline "$lineCount: "
                puts $patchLine
            }
        } else {
#            puts -nonewline "$lineCount: "
            puts $patchLine
        }
        incr lineCount
    } else {
        puts $patchLine
    }
}
close $f
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to