# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2011 Peter Becker >>> Rhythmus pur Melodie in Rhythmus umformen || Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< History: 17.05.11 - Erste Ausgabe """ from xml.dom.minidom import NodeList, Node, Element version = '1.0.0' def transform(note): global hals if note.tagName == 'clefSign': note.setAttribute('clef','P3') # Schlagzeugschlüssel setzen elif note.tagName == 'keySign': note.setAttribute('fifths','0') # Tonart weg elif note.tagName == 'chord': head = note.getElementsByTagName('head') #messageBox('HEAD',str(head)) head[0].setAttribute('pitch','B5') # Ton auf h' setzen alter = head[0].getElementsByTagName('alter') if alter: alter[0].setAttribute('step','0') # und Vorzeichen löschen slur = note.getElementsByTagName('slur') #messageBox('SLUR',str(slur)) if slur: # Bindebogen anpassen x1 = '0.78125' x2 = '1.78125' x3 = '-0.53125' x4 = '0.46875' if hals == 0: y1 = '1' y2 = '2.5' y3 = '2.5' y4 = '1' else: y1 = '-1' y2 = '-2.5' y3 = '-2.5' y4 = '-1' slur[0].setAttribute('x1',x1) slur[0].setAttribute('y1',y1) slur[0].setAttribute('x2',x2) slur[0].setAttribute('y2',y2) slur[0].setAttribute('x3',x3) slur[0].setAttribute('y3',y3) slur[0].setAttribute('x4',x4) slur[0].setAttribute('y4',y4) bracket = note.getElementsByTagName('bracket') if bracket: if hals == 0: x1 = '0.5625' y1 = '-5.5' x2 = '1.5625' y2 = '-5.5' oi = 'up' else: x1 = '-0.4375' y1 = '5.375' x2 = '0.5625' y2 = '5.375' oi = 'down' bracket[0].setAttribute('x1',x1) bracket[0].setAttribute('y1',y1) bracket[0].setAttribute('x2',x2) bracket[0].setAttribute('y2',y2) bracket[0].setAttribute('orientation',oi) stem = note.getElementsByTagName('stem') if stem: if hals == 0: stem[0].setAttribute('dir','up') else: stem[0].setAttribute('dir','down') 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 changeDoc(score): global hals system = score.getElementsByTagName('system') for sy in range(system.length): staves = system[sy].getElementsByTagName('staves') for sv in range(staves.length): staff = staves[sv].getElementsByTagName('staff') for st in range(staff.length): voices = staff[st].getElementsByTagName('voices') for vs in range(voices.length): voice = voices[vs].getElementsByTagName('voice') for vo in range(voice.length): if hals == 0: voice[vo].setAttribute('stemDir','up') else: voice[vo].setAttribute('stemDir','down') noteObjs = voice[vo].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObjs.childNodes) for no in range(objList.length): obj = objList[no] transform(obj) notation = score.getElementsByTagName('notation') # 1-Linien System setzen for nt in range(notation.length): notation[nt].setAttribute('noteLines','1') def pqDialog(): global hals options = ScriptOptions() opt = options.get() Bopt = ['Hals nach oben','Hals nach unten'] radioB = Radio(Bopt, value=int(opt.get('hals', 0)),text='Halsrichtung') box = VBox([radioB],padding=4) dlg = Dialog('Rhythmus-pur Version: '+ version, box) if dlg.run(): hals = radioB.value() opt.update(dict(hals=hals)) options.set(opt) return True else: return False # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): global doc doc = score.parentNode changeDoc(score) if pqDialog(): if activeScore(): activeScore().registerUndo('Rhythmus-pur') tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)