# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2007 Peter Becker >>> Stimme färben. Die zu färbende Stimme mit dem Cursor markieren, und dann das Script aufrufen|| Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< coloring voices

Mark the voice to be coloured with the cursor and open the script.

In case of problems please mail to peter_becker@freenet.de

Stimme färben

Die zu färbende Stimme mit dem Cursor markieren, und dann das Script aufrufen

Bei Problemen bitte eine Mail an peter_becker@freenet.de

Stem inkleuren

Markeer de in te kleuren stem met de cursor en open vervolgens het script.

Bij problemen s.v.p. een mail naar peter_becker@freenet.de

History: 29.07.07 - V 1.0.0 PB Erste Ausgabe 29.11.07 - V 1.0.1 PB time-, key- ,clefSign, barline und drawObjs färben 29.11.07 - V 1.1.0 PB Objekte wählbar 22.02.10 - V 1.2.0 PB Jetzt auch auf der Basis des Beschreibungsfeldes im Partiturlayout auswählbar 06.03.13 - V 1.3.0 PB Trennschärfe erhöht. Stimme muss in einem System ausgewählt werden, in dem alle Stimmen vorhanden sind. 25.01.19 - V 1.3.1 WW Internationalisierung (en-de-nl) """ english = { 'red' :'red', 'ora' :'orange', 'oraYel' :'orange yellow', 'yel' :'yellow', 'yelGrn' :'yellow green', 'grn' :'green', 'bluGrn' :'blue green', 'grnBlu' :'green blue', 'blu' :'blue', 'vio' :'violet', 'redVio' :'red violet', 'bla' :'black', 'darGry' :'dark gray', 'litGry' :'light gray', 'whi' :'white', 'selCol' :'Select colour', 'selStaff' :'color only voice in this system', 'selAllStaves' :'Color voice in all systems', 'selRange' :'Select range', 'noColClef' :'Do not colour clef, key, meter and fixed barlines', 'colClef' :'Colour clef, key, meter and fixed barlines', 'selAdd' :'Select additional Objects', 'position' :'Select after position in the score', 'description' :'Select after the field "Description" in the staff lay out', 'selMethod' :'Selection method', 'counter1stMeas':'Counter for the first measure repetition ', 'colorVoices' :'Colouring voices', 'title' :'Colouring voices - Version : ' } german = { 'red' :'rot', 'ora' :'orange', 'oraYel' :'orange-gelb', 'yel' :'gelb', 'yelGrn' :'gelb-grün', 'grn' :'grün', 'bluGrn' :'blau-grün', 'grnBlu' :'grün-blau', 'blu' :'blau', 'vio' :'violett', 'redVio' :'rot-violett', 'bla' :'schwarz', 'darGry' :'dunkelgrau', 'litGry' :'hellgrau', 'whi' :'weiss', 'selCol' :'Farbe auswählen', 'selStaff' :'Stimme nur in dieser Zeile einfärben', 'selAllStaves' :'Stimme in allen Zeilen einfärben', 'selRange' :'Bereich auswählen', 'noColClef' :'Schlüssel, Tonart, Takt und feste Taktstriche nicht einfärben', 'colClef' :'Schlüssel, Tonart, Takt und feste Taktstriche einfärben', 'selAdd' :'zusätzliche Objekte auswählen', 'position' :'nach Position in der Partitur auswählen', 'description' :'nach Feld "Beschreibung" im Mustersystem auswählen', 'selMethod' :'Auswahl Methode', 'counter1stMeas':'Zähler für ersten Faulenzer ', 'colVoices' :'Stimmen färben', 'title' :'Stimmen färben - Version : ' } dutch = { 'red' :'rood', 'ora' :'oranje', 'oraYel' :'oranje-geel', 'yel' :'geel', 'yelGrn' :'geel-groen', 'grn' :'groen', 'bluGrn' :'blauw-groen', 'grnBlu' :'groen-blauw', 'blu' :'blauw', 'vio' :'violet', 'redVio' :'rood-violet', 'bla' :'zwart', 'darGry' :'donkergrijs', 'litGry' :'lichtgrijs', 'whi' :'wit', 'selCol' :'Kleur selecteren', 'selStaff' :'Stem alleen in dit systeem inkleuren', 'selAllStaves' :'Stem in alle systemen inkleuren', 'selRange' :'Bereik selecteren', 'noColClef' :'Sleutel, toonsoort, maatsoort en vaste maatstrepen niet inkleuren', 'colClef' :'Sleutel, toonsoort, maatsoort en vaste maatstrepen inkleuren', 'selAdd' :'extra objecten selecteren', 'position' :'naar positie in de partituur selecteren', 'description' :'naar veld "Beschrijving" in het sjabloon selecteren', 'selMethod' :'Selectiemethode', 'counter1stMeas':'Teller boven de eerste maatherhaling ', 'colVoices' :'Stemmen inkleuren', 'title' :'Stemmen inkleuren - Versie : ' } try: setStringTable( ("en", english), ("de", german), ("nl", dutch)) except: def tr(s): return german[s] #----------------------------------------------------------------- import xml.dom, tempfile from caplib.capDOM import ScoreChange from xml.dom.minidom import NodeList, Node, Element version = '1.3.1' doc = [] # parentNode von score FarbenListe=[('#F00'),# rot ('#F80'),# orange ('#FC0'),# orangegelb ('#FF0'),# gelb ('#8F0'),# gelbgrün ('#0E0'),# grün ('#078'),# blaugrün ('#039'),# grünblau ('#00F'),# blau ('#60A'),# violett ('#E05'),# rotviolett ('#000'),# schwarz ('#888'),# dunkelgrau ('#CCC'),# hellgrau ('#FFF')]# weiss FarbenListeX=[('FF0000'),# rot ('FF8000'),# orange ('FFC000'),# orangegelb ('FFFF00'),# gelb ('80FF00'),# gelbgrün ('00E000'),# grün ('007080'),# blaugrün ('003090'),# grünblau ('0000FF'),# blau ('6000A0'),# violett ('E00050'),# rotviolett ('000000'),# schwarz ('808080'),# dunkelgrau ('C0C0C0'),# hellgrau ('FFFFFF')]# weiss def latin1_e(u): return u.encode('Latin-1') def getCursor(): sel = curSelection() result = None if sel == 0: messageBox('Fehler', 'keine aktive Partitur') return result return sel def getElementObjects(objList): # returns a List newList = NodeList() for n in range(objList.length): if objList[n].nodeType == objList[n].ELEMENT_NODE: newList.append(objList[n]) return newList def findElementNode(el,tagName): global doc childs = el.childNodes for n in range(childs.length): if childs[n].nodeType ==childs[n].ELEMENT_NODE and childs[n].tagName == tagName: return childs[n] return 'NONE' def addElementNode(el,tagName): # Neue Node zu "el" hinzufügen wenn Node "tagName" nicht existiert # ansonsten existierende Node zurückmelden global doc childs = el.childNodes for n in range(childs.length): if childs[n].nodeType ==childs[n].ELEMENT_NODE and childs[n].tagName == tagName: return childs[n] newChild = doc.createElement(tagName) el.appendChild(newChild) return newChild def addNewElementNode(el,tagName): # add new Node with tagName "tagName" to el global doc newChild = doc.createElement(tagName) el.appendChild(newChild) return newChild def getElementObjects(objList): # returns a List newList = NodeList() for n in range(objList.length): if objList[n].nodeType == objList[n].ELEMENT_NODE: newList.append(objList[n]) return newList def addCount(score,chord,count): global doc drawObjects = addElementNode(chord,'drawObjects') drawObjectL = getElementObjects(drawObjects.childNodes) ix = 0 while ix < len(drawObjectL): basic = findElementNode(drawObjectL[ix],'basic') if basic <> 'NONE' and basic.hasAttribute('tag'): tag = basic.getAttribute('tag') if tag == '2086-60': drawObjectL[ix].parentNode.removeChild(drawObjectL[ix]) ix = ix+1 drawObj = addNewElementNode(drawObjects,'drawObj') text = addNewElementNode(drawObj,'text') font = addNewElementNode(text,'font') content = addNewElementNode(text,'content') font.setAttribute('face','Times New Roman') font.setAttribute('height','8') font.setAttribute('pitchAndFamily','0') font.setAttribute('weight','0') text.setAttribute('y','-2.5') text.setAttribute('x','0.1') if int(count) >= 10: text.setAttribute('x','-0.3125') basic = addNewElementNode(drawObj,'basic') basic.setAttribute('tag','2086-60') #messageBox('ADD',str(score) + '\n' + str(chord) + '\n' + str(count)) content.appendChild(score.parentNode.createTextNode(str(count))) return def changeDoc(score): global doc, selFarbe, selRange, selArt, selMeth doc = score.parentNode sel = getCursor() if sel == None: # return else: curSys = sel[0][0] curRow = sel[0][1] curVoi = sel[0][2] voiIx = 0 rowIx = 0 if selMeth == 0: for system in score.getElementsByTagName('system'): rowIx = 0 for staff in system.getElementsByTagName('staff'): if rowIx == curRow: voiIx = 0 for voice in staff.getElementsByTagName('voice'): if voiIx == curVoi: noteObjects = voice.getElementsByTagName('noteObjects') for child in noteObjects[0].childNodes: if child.nodeType == child.ELEMENT_NODE: if child.tagName == 'rest' or child.tagName =='chord': changeElement(child) if child.tagName == 'barline' or child.tagName == 'timeSign' or child.tagName =='keySign' or child.tagName =='clefSign': changeElement(child) voiIx = voiIx + 1 rowIx = rowIx + 1 else: sysIx = 0 name = '--' found = 0 curSys = int(curSys) for systems in score.getElementsByTagName('systems'): for system in systems.getElementsByTagName('system'): if sysIx == curSys: for staves in system.getElementsByTagName('staves'): rowIx = 0 for staff in staves.getElementsByTagName('staff'): if rowIx == curRow: if staff.hasAttribute('layout'): name = staff.getAttribute('layout') #messageBox('name1',str(name)) found = 1 break else: rowIx = rowIx + 1 if found == 1: break else: sysIx = sysIx + 1 if found == 1: break if found == 1: break #messageBox('name2',str(name)) for system in score.getElementsByTagName('system'): staffIx = 0 for staves in system.getElementsByTagName('staves'): for staff in system.getElementsByTagName('staff'): if staff.hasAttribute('layout'): name2 = staff.getAttribute('layout') if name == name2: voiIx = 0 for voices in staff.getElementsByTagName('voices'): for voice in voices.getElementsByTagName('voice'): if voiIx == curVoi: voiIx = voiIx + 1 noteObjects = voice.getElementsByTagName('noteObjects') for child in noteObjects[0].childNodes: if child.nodeType == child.ELEMENT_NODE: if child.tagName == 'rest' or child.tagName =='chord': changeElement(child) if child.tagName == 'barline' or child.tagName == 'timeSign' or child.tagName =='keySign' or child.tagName =='clefSign': changeElement(child) else: voiIx = voiIx + 1 return def pqDialog(): global selFarbe, selRange, selArt, selMeth placeholder1 = Label(' ',width=1) placeholder2 = Label(' ',width=1) placeholder3 = Label(' ',width=1) placeholder4 = Label(' ',width=1) radFarbe = Radio([tr('red'),tr('ora'),tr('oraYel'),tr('yel'),tr('yelGrn'),tr('grn'),tr('bluGrn'),tr('grnBlu'),tr('blu'),tr('vio'),tr('redVio'),tr('bla'),tr('darGry'),tr('litGry'),tr('whi')],text=tr('selCol'),value=0) radRange = Radio([tr('selStaff'),tr('selAllStaves')],text=tr('selRange'),value=0) radArt = Radio([tr('noColClef'),tr('colClef')],text=tr('selAdd'),value=0) radMeth = Radio([tr('position'),tr('description')],text=tr('selMethod'),value=0) lablSc = Label(tr('counter1stMeas'),width=6) subboxFa = HBox([radFarbe,placeholder4],padding=0) subboxRa = HBox([radRange,placeholder4],padding=0) subboxAr = VBox([radArt,radMeth,placeholder4],padding=0) #box1 = HBox([subboxFa,subboxRa,placeholder4],padding=4) box1 = HBox([subboxFa,subboxAr,placeholder4],padding=4) mainboxSc = VBox([box1],text=tr('colVoices')) box = VBox([mainboxSc,placeholder1],padding=1) dlg = Dialog(tr('title') + version, box) if dlg.run(): selFarbe = int(radFarbe.value()) selRange = int(radRange.value()) selArt = int(radArt.value()) selMeth = int(radMeth.value()) return True else: return False #class BlockScoreChange (ScoreChange): def changeElement(el): global selFarbe, FarbenListeX, selArt if el.tagName in ['chord','rest']: for dOs in el.getElementsByTagName('drawObj'): for child in dOs.childNodes: if child.nodeType == child.ELEMENT_NODE: if child.tagName == "slur" or child.tagName == "wedge" or child.tagName == "wavyLine" or child.tagName == "bracket" or child.tagName == "volta" or child.tagName == "trill": child.setAttribute('color',FarbenListeX[selFarbe]) if child.tagName == "text": for tchild in child.childNodes: if tchild.nodeType == tchild.ELEMENT_NODE: if tchild.tagName == "font": tchild.setAttribute('color',FarbenListeX[selFarbe]) olddisplays = el.getElementsByTagName('display') if olddisplays: display = olddisplays[0] else: display = doc.createElement('display') el.appendChild(display) display.setAttribute('color',FarbenListeX[selFarbe]) elif el.tagName in ['clefSign','timeSign','keySign','barline'] and selArt == 1: el.setAttribute('color',FarbenListeX[selFarbe]) # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): changeDoc(score) if activeScore(): if pqDialog(): global tempInput, tempOutput activeScore().registerUndo("Stimme faerben") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)