| 1 |
# |
| 2 |
# $Id: chordbox.tcl,v 1.4 2002/08/28 15:39:51 t16 Exp $ |
| 3 |
# |
| 4 |
# Graphical helper tool for gchords.sty, written by David R. Lovell, |
| 5 |
# with additions by Kasper Peeters. |
| 6 |
# |
| 7 |
upvar #0 ChordBoxInfo cb |
| 8 |
upvar #0 BlotArray blot |
| 9 |
upvar #0 DampArray damp |
| 10 |
wm title . "Chord Box" |
| 11 |
|
| 12 |
frame .top |
| 13 |
frame .middle |
| 14 |
frame .bottom |
| 15 |
|
| 16 |
set strings 6 |
| 17 |
set frets [lindex $argv 0] |
| 18 |
if {$frets == ""} { |
| 19 |
puts "Usage: wish chordbox.tcl \[number of frets\]" |
| 20 |
exit |
| 21 |
} |
| 22 |
set dx 0.5 |
| 23 |
set dy 1.0 |
| 24 |
set left $dx |
| 25 |
set right [expr $left + ($strings - 1) * $dx] |
| 26 |
set width [expr $right + $left] |
| 27 |
set bottom [expr 0.3 * $dy] |
| 28 |
set top [expr $bottom + ($frets - 1) * $dy] |
| 29 |
set height [expr $top + $bottom] |
| 30 |
set xgrid [expr $dx] |
| 31 |
set ygrid [expr $dy] |
| 32 |
canvas .c -width ${width}c -height ${height}c |
| 33 |
.c config -cursor dot |
| 34 |
|
| 35 |
set cb(rad) [winfo fpixels .c [expr 0.3 * $dx]c] |
| 36 |
set cb(gridx) [winfo fpixels .c ${dx}c] |
| 37 |
set cb(gridy) [winfo fpixels .c ${dy}c] |
| 38 |
set cb(left) [winfo fpixels .c ${left}c] |
| 39 |
set cb(right) [winfo fpixels .c ${right}c] |
| 40 |
set cb(top) [winfo fpixels .c [expr ($frets - 1) * $dy]c] |
| 41 |
set cb(bottom) [winfo fpixels .c ${dy}c] |
| 42 |
set cb(nut) [winfo fpixels .c ${bottom}c] |
| 43 |
set cb(damp) [winfo fpixels .c [expr $bottom / 2]c] |
| 44 |
|
| 45 |
#label .name -text "Name: " |
| 46 |
#entry .nameentry -width 15 -relief sunken -bd 2 -textvariable name |
| 47 |
label .spell -text "Name: " |
| 48 |
entry .spellentry -width 15 -relief sunken -bd 2 -textvariable spelling |
| 49 |
scale .zerofret -from -1 -to 24 -length ${height}c -width 0.3c -orient vertical -variable zerofret |
| 50 |
#set zerofret -1 |
| 51 |
button .print -text Print -command print |
| 52 |
button .quit -text Quit -command exit |
| 53 |
|
| 54 |
pack .print .quit -in .top -side left -fill x -expand 1 |
| 55 |
pack .zerofret .c -in .middle -side left -fill y -expand 1 |
| 56 |
pack .spellentry .spell -in .bottom -side bottom -padx 1m -pady 1m |
| 57 |
#pack .nameentry .name -in .bottom -side bottom -padx 1m -pady 1m |
| 58 |
pack .top .middle .bottom -side top -fill x -expand 1 |
| 59 |
|
| 60 |
for {set i 0} {$i < $strings} {incr i} { |
| 61 |
set x [expr $left + $i * $dx] |
| 62 |
.c create line ${x}c ${bottom}c ${x}c ${top}c |
| 63 |
} |
| 64 |
for {set i 0} {$i < [expr $frets - 1]} {incr i} { |
| 65 |
set y [expr $bottom + $i * $dy] |
| 66 |
.c create line ${left}c ${y}c ${right}c ${y}c |
| 67 |
} |
| 68 |
|
| 69 |
bind .c <1> "mkBlot .c %x %y" |
| 70 |
|
| 71 |
|
| 72 |
proc mkBlot { c x y } { |
| 73 |
upvar #0 ChordBoxInfo cb |
| 74 |
upvar #0 BlotArray blot |
| 75 |
upvar #0 DampArray damp |
| 76 |
|
| 77 |
set cx [$c canvasx $x $cb(gridx)] |
| 78 |
set cy [$c canvasy $y $cb(gridy)] |
| 79 |
if {($cx < $cb(left))} { |
| 80 |
set cx $cb(left) |
| 81 |
} |
| 82 |
if {($cx > $cb(right))} { |
| 83 |
set cx $cb(right) |
| 84 |
} |
| 85 |
if {($cy < $cb(nut))} { |
| 86 |
set s [expr round($cx / $cb(gridx))] |
| 87 |
if [info exists damp($s)] { |
| 88 |
$c delete $damp($s) |
| 89 |
unset damp($s) |
| 90 |
} else { |
| 91 |
set damp($s) [$c create line \ |
| 92 |
[expr $cx - $cb(rad)] [expr $cb(damp) - $cb(rad)]\ |
| 93 |
[expr $cx + $cb(rad)] [expr $cb(damp) + $cb(rad)]\ |
| 94 |
$cx $cb(damp) \ |
| 95 |
[expr $cx - $cb(rad)] [expr $cb(damp) + $cb(rad)]\ |
| 96 |
[expr $cx + $cb(rad)] [expr $cb(damp) - $cb(rad)]\ |
| 97 |
] |
| 98 |
} |
| 99 |
return |
| 100 |
} |
| 101 |
|
| 102 |
if {($cy < $cb(bottom))} { |
| 103 |
set cy $cb(bottom) |
| 104 |
} |
| 105 |
if {($cy > $cb(top))} { |
| 106 |
set cy $cb(top) |
| 107 |
} |
| 108 |
set f [expr round($cy / $cb(gridy))] |
| 109 |
set s [expr round($cx / $cb(gridx))] |
| 110 |
|
| 111 |
# puts "$x, $y = ($cx,$cy), $s, $f" |
| 112 |
|
| 113 |
if [info exists blot($s,$f)] { |
| 114 |
$c delete $blot($s,$f) |
| 115 |
unset blot($s,$f) |
| 116 |
} else { |
| 117 |
set blot($s,$f) [$c create oval\ |
| 118 |
[expr $cx - $cb(rad)] [expr $cy - $cb(rad)] \ |
| 119 |
[expr $cx + $cb(rad)] [expr $cy + $cb(rad)] -fill black] |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
proc print {} { |
| 124 |
upvar #0 ChordBoxInfo cb |
| 125 |
upvar #0 frets frets |
| 126 |
upvar #0 strings strings |
| 127 |
upvar #0 zerofret zerofret |
| 128 |
# upvar #0 name name |
| 129 |
upvar #0 spelling spelling |
| 130 |
upvar #0 BlotArray blot |
| 131 |
upvar #0 DampArray damp |
| 132 |
|
| 133 |
puts "\\def\\numfrets\{$frets\}" |
| 134 |
puts -nonewline "\\chord\{" |
| 135 |
if {$zerofret == 0} { |
| 136 |
puts -nonewline "t" |
| 137 |
} |
| 138 |
if {$zerofret > 0} { |
| 139 |
puts -nonewline $zerofret |
| 140 |
} |
| 141 |
puts -nonewline "\}\{" |
| 142 |
|
| 143 |
for {set s 1} {$s <= $strings} {incr s} { |
| 144 |
set nmarks 0 |
| 145 |
for {set f 0} {$f < $frets} {incr f} { |
| 146 |
if [info exists blot($s,$f)] { |
| 147 |
puts -nonewline "p\{$f\}" |
| 148 |
incr nmarks |
| 149 |
} |
| 150 |
} |
| 151 |
if {$nmarks == 0} { |
| 152 |
if [info exists damp($s)] { |
| 153 |
puts -nonewline "x" |
| 154 |
} else { |
| 155 |
puts -nonewline "n" |
| 156 |
} |
| 157 |
} |
| 158 |
if {$s < $strings} { |
| 159 |
puts -nonewline "," |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
puts -nonewline "\}\{" |
| 164 |
|
| 165 |
# if { $name != "" } { |
| 166 |
# puts -nonewline "$name" |
| 167 |
# } |
| 168 |
# |
| 169 |
# puts -nonewline "\}\{" |
| 170 |
|
| 171 |
if { $spelling != "" } { |
| 172 |
regsub -all , $spelling \},\{ texspelling |
| 173 |
regsub -all b $texspelling \\ensuremath\{\\flat\} texspelling |
| 174 |
regsub -all \# $texspelling \\ensuremath\{\\sharp\} texspelling |
| 175 |
puts -nonewline "\{$texspelling\}" |
| 176 |
} |
| 177 |
puts "\}" |
| 178 |
} |