# -*- 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 <<< History: 29.07.07 - Erste Ausgabe 29.11.07 - time-, key- ,clefSign, barline und drawObjs färben 29.11.07 - Objekte wählbar 22.02.10 - Jetzt auch auf der Basis des Beschreibungsfeldes im Partiturlayout auswählbar """ import xml.dom, tempfile from caplib.capDOM import ScoreChange from xml.dom.minidom import NodeList, Node, Element 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: name = "--" for system in score.getElementsByTagName('system'): # Feldbeschreibung der ausgewählten Zeile feststellen rowIx = 0 for staff in system.getElementsByTagName('staff'): #messageBox('staff',str(rowIx) + '\n' + str(curRow)) if rowIx == curRow: voiIx = 0 for voice in staff.getElementsByTagName('voice'): #messageBox('voice',str(voiIx) + '\n' + str(curVoi)) if voiIx == curVoi and staff.hasAttribute('layout'): name = staff.getAttribute('layout') #messageBox('layout',str(name)) break voiIx = voiIx + 1 rowIx = rowIx + 1 if name <> "--": break if name <> "--": break #messageBox('name',str(name)) for system in score.getElementsByTagName('system'): for staff in system.getElementsByTagName('staff'): if staff.hasAttribute('layout'): name2 = staff.getAttribute('layout') if name == name2: for voice in staff.getElementsByTagName('voice'): 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) 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(['rot','orange','orange-gelb','gelb','gelb-grün','grün','blau-grün','grün-blau','blau','violett','rot-violett','schwarz','dunkelgrau','hellgrau','weiss'],text='Farbe auswählen',value=0) radRange = Radio(['Stimme nur in dieser Zeile einfärben','Stimme in allen Zeilen einfärben'],text='Bereich auswählen',value=0) radArt = Radio(['Schlüssel, Tonart, Takt und feste Taktstriche nicht einfärben','Schlüssel, Tonart, Takt und feste Taktstriche einfärben'],text='zusätzliche Objekte auswählen',value=0) radMeth = Radio(['nach Position in der Partitur auswählen','nach Feld "Beschreibung" im Mustersystem auswählen'],text='Auswahl Methode',value=0) lablSc = Label('Zähler für ersten Faulenzer ',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='Stimmen färben') box = VBox([mainboxSc,placeholder1],padding=1) dlg = Dialog('Stimmen färben', 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)