# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2010 Peter Becker >>> ForceArticulation : Artikulation erzwingen Artikulationszeichen auf Noten einer ausgewählten Länge innerhalb der Markierung setzen. |Die Markierung kann sich derzeit nur innerhalb einer Zeile befinden.|| Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< History: 06.07.10 - Erste Ausgabe """ import xml.dom, tempfile import tkFont import Tkinter from caplib.capDOM import * from xml.dom.minidom import NodeList, Node, Element doc = [] # parentNode von score 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 changeDoc(score): global doc, laenge, akzent #messageBox('vorz',str(vorz)) doc = score.parentNode if laenge == '1': laenge = '1/1' notenlaenge = ['1/64','1/32','1/16','1/8','1/4','1/2','1/1','0'] artikulation = ['keine','staccato','tenuto','staccato tenuto', 'staccatissimo','normalAccent','strongAccent','weakBeat','strongBeat'] sel = getCursor() if sel == None: # return else: selvon = sel[0] selbis = sel[1] ix = 0 while selvon[3]+ix < selbis[3]: system = score.getElementsByTagName('system')[selvon[0]] staff = system.getElementsByTagName('staff')[selvon[1]] voice = staff.getElementsByTagName('voice')[selvon[2]] noteObject = voice.getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) sy = activeScore().system(selvon[0]) st = sy.staff(selvon[1]) vo = st.voice(0) no = vo.noteObj(selvon[3]+ix) if objList.length <= selvon[3]: ix = ix + 1 return obj = objList[selvon[3]+ix] hd = obj.getElementsByTagName('head') pi = hd[0].getAttribute('pitch') ix = ix + 1 #messageBox('OBJ',str(obj.tagName)) if obj.tagName == 'chord': articulation = obj.getElementsByTagName('articulation') duration = obj.getElementsByTagName('duration') base = duration[0].getAttribute('base') #messageBox('OBJ',str(laenge) + '\n' + str(akzent)) nlAttr = notenlaenge[laenge] arAttr = artikulation[akzent] if nlAttr == base or nlAttr == '0' : #messageBox('OBJ',str(base) + '\n' + str(nlAttr) + '\n' + str(arAttr)) if articulation and arAttr == 'keine': articulation[0].removeAttribute('type') elif articulation and arAttr <> 'keine': articulation[0].setAttribute('type',arAttr) else: ar = addNewElementNode(obj,'articulation') ar.setAttribute('type',arAttr) else: return return def pqDialog(): global laenge, akzent options = ScriptOptions() opt = options.get() #messageBox('OPT',str(opt)) lopt = ['64-tel','32-tel','16-tel', '8-tel', '4-tel', 'Halbe', 'Ganze','Alle'] aopt = ['ohne','Staccato','Tenuto','Staccato-Tenuto','Staccatissimo','normaler Akzent','starker Akzent','weicher Schlag','schwerer Schlag'] radioA = Radio(aopt, value=int(opt.get('akzent', 0))) radioL = Radio(lopt, value=int(opt.get('laenge', 0))) hBoxA = HBox([Label('Akzent '), radioA]) hBoxL = HBox([Label('Notenlänge '), radioL]) box = HBox([hBoxL,hBoxA]) dlg = Dialog('Artikulation erzwingen', box) if dlg.run(): laenge = radioL.value() akzent = radioA.value() opt.update(dict(laenge=laenge, akzent=akzent)) options.set(opt) return True else: return False # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): changeDoc(score) if activeScore(): global tempInput, tempOutput if pqDialog(): activeScore().registerUndo("ForceArticulation") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)