#!/bin/sh # the next line restarts using tclsh -*- tcl -*- \ exec tclsh "$0" "$@" proc s {} {source test-abc.tcl} ;# source this file just issuing 's' in tclsh global auto_path ;# so that sourcing this file can work if {[file exists ./tclabc[info sharedlibextension]]} { # accept to run in the source directory set abclib . load ./tclabc[info sharedlibextension] set abcversion [package require tclabc] } else { set prefix /usr/local set exec_prefix ${prefix} set abclib ${exec_prefix}/lib/tclabc/ set auto_path "$abclib $auto_path" set abcversion 1.1.0 package require -exact tclabc $abcversion } ########################################################### # proc to convert a single accidental from Tartini-Couper ABC to Sagittal proc abc2sag {{acc 0}} { set accidentals [list \ 5 -40 \ 4107 -68 \ 3 -92 \ 11 -120 \ 2 144 \ 9 168 \ 1 196 \ 4105 220 \ 4 248 \ ] for {set i 0} {$i < [llength $accidentals]} {incr i 2} { if {[lindex $accidentals $i] == $acc} { set sag [expr ([lindex $accidentals [expr 1+$i]]) ] if {$sag < 0} { set sag [expr 8*(-$sag-1) + 3] ;# flatten } else { set sag [expr 8*($sag-1) + 1] ;# sharpen } return $sag } } return 0 } ################################################## # test ABC input abc load { X:1 K:C __c _3/c _c _/c =c ^/c ^c ^3/c ^^c | } puts "" puts "Original Tartini-Couper ABC:\n" puts [abc dump] while {[abc get] != "EOT"} { ;# currently only reads the first voice set sym [abc get]; set type [lindex $sym 0] if {$type == "note" || $type == "grace"} { for {set i 3} {$i < [expr [llength $sym] ]} {incr i 2} { set sym [lreplace $sym $i $i [abc2sag [lindex $sym $i]]] } abc set $sym } abc go next } puts "Resulting Sagittal ABC:\n" puts [abc dump]