# -*- 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 <<< Force Articulation

This scripts places articulation signs at marked notes with a selected duration.

At the moment the marking must remain within one staff or voice.

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

Artikulation erzwingen

Artikulationszeichen auf Noten einer ausgewählten Länge innerhalb der Markierung setzen.

Die Markierung kann sich derzeit nur innerhalb einer Zeile oder Stimme befinden.

Bei Problemen bitte eine Mail an peter_becker@freenet.de

Articulatie forceren

Dit script plaatst articulatietekens bij gemarkeerde noten met een geselecteerde notenwaarde.

De markering moet momenteel beperkt blijven tot één notenbalk of stem.

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

History: 06.07.10 - PB Version 1.0.0 Erste Ausgabe 10.07.20 - WW Version 1.1.0 Internationalisierung (en-de-nl) + 'Brevis' + 'Hilfe' 11.07.20 - PB Version 1.1.1 Absturz beseitigt wenn ein Pause markiert wurde """ version = '1.1.1' english = { 'Error' :'Error', 'noScore' :'No active score', '64th' :'64th', '32th' :'32th', '16th' :'16th', '8th' :'8th', '4th' :'4th', 'half' :'Half', 'whole' :'Whole', 'brevis' :'Brevis', 'all' :'All', 'without' :'without', 'staccato' :'Staccato', 'tenuto' :'Tenuto', 'staccatoTenuto':'Staccato-Tenuto', 'staccatissimo' :'Staccatissimo', 'normalAccent' :'Normal Accent', 'strongAccent' :'Strong Accent', 'weakBeat' :'Weak Beat', 'strongBeat' :'Strong Beat', 'artSign' :'Articulation Sign ', 'duration' :'Duration ', 'title' :'Force Articulation', 'version' :' Version: ', 'help' :'F o r c e   A r t i c u l a t i o n\n\ \nThis scripts places articulation signs at marked notes \ with a selected duration.\n\ \nAt the moment the marking must remain within one staff or voice.' } german = { 'Error' :'Fehler', 'noScore' :'keine aktive Partitur', '64th' :'64-tel', '32th' :'32-tel', '16th' :'16-tel', '8th' :'8-tel', '4th' :'4-tel', 'half' :'Halbe', 'whole' :'Ganze', 'brevis' :'Brevis', 'all' :'Alle', 'without' :'ohne', 'staccato' :'Staccato', 'tenuto' :'Tenuto', 'staccatoTenuto':'Staccato-Tenuto', 'staccatissimo' :'Staccatissimo', 'normalAccent' :'normaler Akzent', 'strongAccent' :'starker Akzent', 'weakBeat' :'weicher Schlag', 'strongBeat' :'schwerer Schlag', 'artSign' :'Articulationszeichen ', 'duration' :'Notenlänge ', 'title' :'Artikulation erzwingen', 'version' :' Version: ', 'help' :'A r t i k u l a t i o n   e r z w i n g e n\n\ \nArtikulationszeichen auf Noten einer ausgewählten Länge \ innerhalb der Markierung setzen.\n\ \nDie Markierung kann sich derzeit nur innerhalb einer Zeile \ oder Stimme befinden.' } dutch = { 'Error' :'Fout', 'noScore' :'Geen actieve partituur', '64th' :'64ste', '32th' :'32ste', '16th' :'16de', '8th' :'8ste', '4th' :'Kwart', 'half' :'Halve', 'whole' :'Hele', 'brevis' :'Brevis', 'all' :'Alle', 'without' :'Zonder', 'staccato' :'Staccato', 'tenuto' :'Tenuto', 'staccatoTenuto':'Staccato-Tenuto', 'staccatissimo' :'Staccatissimo', 'normalAccent' :'Normaal accent', 'strongAccent' :'Sterk accent', 'weakBeat' :'Zwak maatdeel', 'strongBeat' :'Sterk maatdeel', 'artSign' :'Articulatieteken ', 'duration' :'Notenwaarde ', 'title' :'Articulatie forceren', 'version' :' Versie: ', 'help' :'A r t i c u l a t i e   f o r c e r e n\n\ \nDit script plaatst articulatietekens bij gemarkeerde noten \ met een geselecteerde notenwaarde.\n\ \nDe markering moet momenteel beperkt blijven tot één notenbalk \ of stem.' } try: setStringTable( ("en", english), ("de", german), ("nl", dutch)) except: def tr(s): return german[s] #---------------------------------------------- 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(tr('Error'), tr('noScore')) 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','2/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] ix = ix + 1 #messageBox('OBJ',str(obj.tagName)) if obj.tagName == 'chord': hd = obj.getElementsByTagName('head') pi = hd[0].getAttribute('pitch') 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 = [tr('64th'),tr('32th'),tr('16th'), tr('8th'), tr('4th'), tr('half'), tr('whole'),tr('brevis'),tr('all')] aopt = [tr('without'),tr('staccato'),tr('tenuto'),tr('staccatoTenuto'),tr('staccatissimo'), tr('normalAccent'),tr('strongAccent'),tr('weakBeat'),tr('strongBeat')] radioA = Radio(aopt, value=int(opt.get('akzent', 0))) radioL = Radio(lopt, value=int(opt.get('laenge', 0))) hBoxA = HBox([Label(tr('artSign')), radioA]) hBoxL = HBox([Label(tr('duration')), radioL]) box = HBox([hBoxL,hBoxA]) dlg = Dialog(tr('title') + tr('version') + version, box, tr('help')) 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)