BEGIN { filename = "" } function getTagIndent() { return gensub(/^([ \t]+).*/,"\\1","g",$0) } function getTagName() { return gensub(/^ *<([a-zA-Z]+).*/,"\\1","g",$0) } function getTag() { tag = getTagName() t = $0 # may not be on the same line - read as many as needed while ((index(t,"") == 0) && (match(t,"/> *$") == 0)) { if (getline > 0) t = t "\n" $0; else break; } return t } function getTagValue() { tag = getTagName() t = $0 t = gensub("^ *<" tag "[^>]*>","","g",t) t = gensub("","","g",t) return t } function getTagAttribute(attr) { tag = getTagName() t = $0 t = gensub("^ *<" tag ".* " attr "=\"([^\"]+)\"\\/?>(.*)","\\1","g",t) return t } function getMetaTag() { tag = gensub(/^ *<([a-zA-Z]+).*/,"\\1","g",$0) t = $0 # may not be on the same line - read as many as needed while ((index(t,"") == 0) && (match(t,"/> *$") == 0)) { if (getline > 0) t = t "\n" $0; else break; } #t = gensub("^ *<" tag " name=\"([^\"]+)\"\\/?>(.*)","\\2","g",t) #t = gensub(".*","","g",t) return t } function FileName() { # strip the path from file name return gensub(/^([^\\]*\\)*/,"","g",FILENAME) } # scan the file # ---------------------------------------------------------------------- (FNR == 1) { part = 0 delete aMixer # hymn aMixer["soprano/alto"] = "40,95,1,1" # violin,,show,mute aMixer["tenor/bass"] = "42,31,1,1" # cello aMixer["soprano"] = "56,111,0,0" # trumpet aMixer["alto"] = "56,79,0,0" # trumpet (alto sax = 65) aMixer["tenor"] = "57,47,0,0" # trombone aMixer["bass"] = "58,15,0,0" # tuba aMixer["piano"] = "0,63,1,0" # piano aMixer["descant"] = "68,79,1,0" # oboe aMixer["voice"] = "68,63,1,0" # oboe (flute = 73) # SATB aMixer["soprano"] = "56,111,1,0" # trumpet aMixer["alto"] = "56,79,1,0" # trumpet (alto sax = 65) aMixer["tenor"] = "57,47,1,0" # trombone aMixer["bass"] = "58,15,1,0" # tuba aMixer["piano"] = "0,63,1,0" # piano } /^ +(.*)<\/programVersion>/ { programVersion = gensub(/(.*)(.*)(<\/programVersion>.*)/,"\\2","g") if (substr(programVersion,1,2) != "2.") { print "FATAL: only scores created with MuseScore version 2.x are supported: " FILENAME > "/dev/stderr" exit } } /^ */ { Part = 1 } /^ */ { StaffId = gensub(/^[^"]+"([0-9]+)".*$/,"\\1","g",$0) } /^ */ && (Part == 1) { if (Instrument == 0) { $0 = getTag() trackDesc = tolower(getTagValue()) delete aMixerVal if (trackDesc in aMixer) { split(aMixer[trackDesc],aMixerVal,",") show = aMixerVal[3]+0 if (show == 0) { print getTagIndent() "0" } } } else { $0 = getTag() trackName = tolower(getTagValue()) } } /^ */ && (Part == 1) { Instrument = 1 } /^ */ && (Instrument == 1) { instrumentId = getTag() } /^ */ && (Instrument == 1) { Channel = 1 } # selected instrument in mixer /^ */ && (Channel == 1) { if (trackDesc in aMixer) { # update instrument selected in mixer $0 = getTag() programValue = getTagAttribute("value") programValue = aMixerVal[1] $0 = gensub(/( 64) ) { print getTagIndent() "" } next } } /^ *<\/Channel>/ && (Instrument == 1) { if (trackDesc in aMixer) { # mute mute = aMixerVal[4]+0 if (mute != 0) { print getTagIndent() "1" } } Channel = 0 } /^ *<\/Instrument>/ && (Part == 1) { Instrument = 0 Channel = 0 } /^ *<\/Part>/ { Part = 0 programValue = "" controllerValue = "" show = "" mute = "" instrumentId = "" trackName = "" trackDesc = "" StaffId = "" } { print } END {}