# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2010 Peter Becker >>> Alte Vorzeichen Vorzeichen an markierten Noten unsichtbar machen und klein über die Note schreiben || Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< Old accidentals

With this script accidentals at marked notes can be hided and placed above the notes in reduced size. In case of problems please mail to peter_becker@freenet.de

Alte Vorzeichen

Vorzeichen an markierten Noten unsichtbar machen und klein über die Note schreiben Bei Problemen bitte eine Mail an peter_becker@freenet.de

Oude voortekens

Voortekes bij gemarkeerde noten onzichtbaar maken en klein boven de noten schrijven Bij problemen s.v.p. een mail naar peter_becker@freenet.de

Tags : 2086-62 History: 22.04.10 - Version 1.0.0 Erste Ausgabe 01.11.15 - Version 1.0.1 Kleine Änderungen, (mit (WW) markiert) 21.08.17 - Version 1.0.2 Internationalisiert (en-de-nl) (WW) 01.12.19 - Version 1.0.3 alle alten Vorzeichen auf die selbe Größe bringen """ english = { 'error' :'Error', 'noScore' :'No active Score', 'replaceAll' :'Replace accidental(s) - also accidentals belonging to key', 'replaceExceptKey' :'Replace accidental(s) - except accidentals belonging to key', 'setSharp' :'Set sharp - tone is raised in this case', 'setFlat' :'Set flat - tone is lowered in this case', 'setHeight' :'Change Height - height of all accidentals will be set to defined size', 'priority' :' This option has priority above all other options', 'cancelAccidental' :'Cancel accidental - extant accidental will be replaced by high positioned natural', 'size' :'Size ', 'action' :'Action for marked notes', 'titel' :'Old Accidentals Version=' } german = { 'error' :'Fehler', 'noScore' :'keine aktive Partitur', 'replaceAll' :'Vorzeichen ersetzen - auch tonartbedingte Vorzeichen', 'replaceExceptKey' :'Vorzeichen ersetzen - ohne tonartbedingte Vorzeichen', 'setSharp' :'Kreuz setzen - Ton wird gegebenenfalls erhöht', 'setFlat' :'b setzen - Ton wird gegebenenfalls vermindert', 'setHeight' :'Größe aller Vorzeichen auf den definierten Wert ändern', 'priority' :' Diese Option hat Vorrang vor allen Anderen', 'cancelAccidental' :'Vorzeichen auflösen - vorhandenes Vorzeichen wird gegebenenfalls entfernt', 'size' :'Zeichengröße ', 'action' :'Aktion für markierte Noten', 'titel' :'Alte Vorzeichen Version=' } dutch = { 'error' :'Fout', 'noScore' :'geen actieve partituur', 'replaceAll' :'Voorteken(s) vervangen - ook voortekens bij de toonsoort behorend', 'replaceExceptKey' :'Voorteken(s) vervangen - behalve voortekens bij de toonsoort behorend', 'setSharp' :'Kruis zetten - de toon wordt in dit geval verhoogd', 'setFlat' :'Mol zetten - de toon wordt in dit geval verlaagd', 'setHeight' :'Tekengrootte veranderen - de grootte van alle voortekens verandert in ingestelde tekengrootte', 'priority' :' Deze optie heeft voorrang boven alle andere', 'cancelAccidental' :'Voorteken opheffen - bestaand voorteken wordt vervangen door hoog geplaatst herstellingsteken', 'size' :'Tekengrootte ', 'action' :'Actie voor voor gemarkeerde noten', 'titel' :'Oude voortekens Versie=' } 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 version = '1.0.3' 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 hasAlter(pi,obj): # Hat die Note ein Vorzeichen ? takt1 = [] list0 = [ ] list1 = ['F'] list2 = ['F','C'] list3 = ['F','C','G'] list4 = ['F','C','G','D'] list5 = ['F','C','G','D','A'] list6 = ['F','C','G','D','A','E'] list7 = ['F','C','G','D','A','E','B'] listM1 = ['B'] listM2 = ['B','E'] listM3 = ['B','E','A'] listM4 = ['B','E','A','D'] listM5 = ['B','E','A','D','G'] listM6 = ['B','E','A','D','G','C'] listM7 = ['B','E','A','D','G','C','F'] key = obj.curKey() if key == 0: liste = list0 elif key == 1: liste = list1 elif key == 2: liste = list2 elif key == 3: liste = list3 elif key == 4: liste = list4 elif key == 5: liste = list5 elif key == 6: liste = list6 elif key == 7: liste = list7 elif key == -1: liste = listM1 elif key == -2: liste = listM2 elif key == -3: liste = listM3 elif key == -4: liste = listM4 elif key == -5: liste = listM5 elif key == -6: liste = listM6 elif key == -7: liste = listM7 if pi[0] in liste: # Ton hat in der Tonart normalerweise ein Vorzeichen #messageBox('HasAlter','norm VZ') vz = 0 else: vz = 1 #messageBox('HasAlter','kein VZ') return vz def changeVorzeichen(score,chord): global doc, size messageBox('yych',str(chord)) drawObjects = addElementNode(chord,'drawObjects') drawObjectL = getElementObjects(drawObjects.childNodes) ix = 0 messageBox('XX',str(drawObjectL)) while ix < len(drawObjectL): basic = findElementNode(drawObjectL[ix],'basic') if basic <> 'NONE' and basic.hasAttribute('tag'): tag = basic.getAttribute('tag') if tag == '2086-62': font = findElementNode(drawObjectL[ix],'font') #messageBox('XX',str(font)) def setVorzeichen(score,chord,step,vorz,pi,no): global doc, size vz = hasAlter(pi,no) #messageBox('SV',str(vz) + '\n' + str(step)) if vz == 0 and step <> '0' and vorz == 1: return #messageBox('VZ',str(vz)) 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-62': 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','capella3') font.setAttribute('height',str(size)) font.setAttribute('charSet','2') font.setAttribute('pitchAndFamily','2') #text.setAttribute('y','-4') ## ausser Wirkung, s. unten (WW) text.setAttribute('x','0.4') ## war 0.5 (WW) #messageBox('STEP',str(step)) if step == '1': #messageBox('STEP1',str(step)) content.appendChild(score.parentNode.createTextNode('S')) text.setAttribute('y','-3.5') ## zugefügt (WW) elif step == '-1': #messageBox('STEP2',str(step)) content.appendChild(score.parentNode.createTextNode('Q')) text.setAttribute('y','-2.9') ## zugefügt (WW) elif step == '0': #messageBox('STEP3',str(step)) content.appendChild(score.parentNode.createTextNode('R')) text.setAttribute('y','-3.5') ## zugefügt (WW) basic = addNewElementNode(drawObj,'basic') basic.setAttribute('tag','2086-62') return def changeDoc(score): global doc, vorz, high, size #messageBox('vorz',str(vorz)) doc = score.parentNode if high == 0: 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': alter = obj.getElementsByTagName('alter') if alter : step = alter[0].getAttribute('step') if step: #messageBox('Step1',str(step)) alter[0].setAttribute('display','suppress') if vorz == 2: alter[0].setAttribute('step','1') step = '1' elif vorz == 3: alter[0].setAttribute('step','-1') step = '-1' elif vorz == 4: alter[0].removeAttribute('step') step = '0' setVorzeichen(score, obj, step, vorz, pi, no) else: #messageBox('Step1a',str(step)) display = alter[0].getAttribute('display') #messageBox('Step1a',str(display)) if display == 'force': force = 'force' else: force = 'none' #if display <> 'auto': # alter[0].setAttribute('display','suppress') #messageBox('Step2',str(step) + '\n' + str(alter[0])) if (vorz == 0 or vorz == 1) and force and not step: step = '0' elif vorz == 2: alter[0].setAttribute('step','1') step = '1' elif vorz == 3: alter[0].setAttribute('step','-1') step = '-1' elif vorz == 4: if alter[0].hasAttribute('step'): alter[0].removeAttribute('step') step = '0' setVorzeichen(score, obj, step, vorz, pi, no) else: head = obj.getElementsByTagName('head') alter = addNewElementNode(head[0],'alter') alter.setAttribute('display','suppress') if vorz <> 0 and vorz <> 1: if vorz == 2: step = '1' alter.setAttribute('step','1') elif vorz == 3: step = '-1' alter.setAttribute('step','-1') elif vorz == 4: if alter.hasAttribute('step'): alter.removeAttribute('step') step = '0' #messageBox('Step3',str(step) + '\n' + str(obj)) setVorzeichen(score, obj, step, vorz, pi, no) else: #messageBox('STEP4a','kein Vorzeichen gefunden') #messageBox('STEP4b',str(pi) + '\n' + str(no)) vz = hasAlter(pi,no) # hat der Ton normalerweise ein Vorzeichen ? #messageBox('STEP4c',str(vz)) if vz == 0: step = '0' setVorzeichen(score, obj, step, vorz, pi, no) else: return return else: basic = score.getElementsByTagName('basic') for ba in range(basic.length): if basic[ba].hasAttribute('tag'): tag = basic[ba].getAttribute('tag') if tag == '2086-62': txt = basic[ba].parentNode.getElementsByTagName('text') font = txt[0].getElementsByTagName('font') font[0].setAttribute('height',str(size)) def pqDialog(): global vorz, size, high options = ScriptOptions() opt = options.get() #messageBox('OPT',str(opt)) Sopt = ['8','9','10', '11', '12', '13', '14'] # zugfügt: '14' (WW) #comboS = ComboBox(Sopt, width=12, value=1) comboS = ComboBox(Sopt, width=12, value=int(opt.get('size', '1'))) Aopt = [tr('replaceAll'),tr('replaceExceptKey'),tr('setSharp'),tr('setFlat'),tr('cancelAccidental')] #radioA = Radio(Aopt, value=('vorz', 0)) radioA = Radio(Aopt, value=int(opt.get('vorz', 0))) checkA = CheckBox(tr('setHeight'),value=int(opt.get('high', '0'))) hBox1 = HBox([Label(tr('size')), comboS]) vBox1 = VBox([hBox1,Label(' '), checkA, Label(tr('priority')) ]) box = VBox([radioA, Label(' '), vBox1],text=tr('action')) dlg = Dialog(tr('titel')+version, box) if dlg.run(): vorz = radioA.value() size = comboS.value() high = checkA .value() opt.update(dict(size=size, vorz=vorz)) options.set(opt) size = size+8 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("AlteVorzeichen") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)