# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2009 Peter Becker >>> Pausen unsichtbar Achtung : Die ausgewählten Pausen werden unsichtbar markiert|| Im Fehlerfall bitte eine Mail an peter_becker@freenet.de <<< History: 15.08.09 - Erste Ausgabe 17.08.09 - kleine Korrekturen """ import xml.dom, tempfile from caplib.capDOM import * from xml.dom.minidom import * doc = [] # parentNode von score 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 addNewElementNode(el,tagName): # add new Node with tagName "tagName" to el global doc newChild = doc.createElement(tagName) el.appendChild(newChild) return newChild def getBaseData(score): global sel, system, staff, voice, chord, system1, staff1, voice1, chord1, noteObject, objList global sy1,st1,vo1,ob1,sy2,st2,vo2,ob2 (sy1,st1,vo1,ob1),(sy2,st2,vo2,ob2) = sel system = score.getElementsByTagName('system')[sy1] staff = system.getElementsByTagName('staff')[st1] voice = staff.getElementsByTagName('voice')[vo1] nobjs = voice.getElementsByTagName('noteObjects')[0] objList = getElementObjects(nobjs.childNodes) def verbergen(score): global sel, system, staff,voice, noteObject, objList, vo, takt, auswahl global cas1, cas2, cas3, cas4, cas5, cas6, cas7 global sy1,st1,vo1,ob1,sy2,st2,vo2,ob2,ix for ob in objList: if auswahl == 0: if ix < ob2: #messageBox('LST',str(objList[ix])) obj = objList[ix] #messageBox('SE',str(obj)) ix = ix+1 if obj.tagName == 'rest': display = obj.getElementsByTagName('display') #messageBox('SE',str(display)) if str(display) == '[]': display = addNewElementNode(obj,'display') display.setAttribute('invisible','true') else: display[0].setAttribute('invisible','true') else: break else : if ob.tagName == 'rest': display = ob.getElementsByTagName('display') #messageBox('SE',str(display)) if str(display) == '[]': display = addNewElementNode(ob,'display') display.setAttribute('invisible','true') else: display[0].setAttribute('invisible','true') # Hier kommt die Klasse die vom Ende her aufgerufen wird ------------------------------------------------- class ScoreChange(ScoreChange): def changeScore(self, score): global doc, sel, system, staff, voice, chord, system1, staff1, voice1, chord1, noteObject global sy1,st1,vo1,ob1,sy2,st2,vo2,ob2,ix global objList,vo, takt global auswahl, cas1, cas2, cas3, cas4, cas5, cas6, cas7 doc = score.parentNode sel = getCursor() #messageBox('Markierung',str(sel)) if sel == None: return else: if auswahl == 0: # nur Note getBaseData(score) if sel <> 0: ix = ob1 verbergen(score) elif auswahl == 1: # eine Stimme in einer Zeile getBaseData(score) ix = 0 verbergen(score) elif auswahl == 2: # alle Stimmen in einer Zeile getBaseData(score) obj = objList[vo1] voiceList = getElementObjects(obj.parentNode.parentNode.parentNode.childNodes) #messageBox('VL',str(voiceList)) for voIx in range(voiceList.length): takt = 0 noteObject = voiceList[voIx].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) vo=activeScore().system(sy1).staff(st1).voice(voIx) voice=voiceList[voIx] for obj in range(objList.length): no = vo.noteObj(obj) ix = 0 verbergen(score) elif auswahl == 3: # System getBaseData(score) staves = staff.parentNode staffList = getElementObjects(staves.childNodes) for stIx in range(staffList.length): voicesList = getElementObjects(staffList[stIx].childNodes) for vsIx in range(voicesList.length): voiceList = getElementObjects(voicesList[vsIx].childNodes) for voIx in range(voiceList.length): vo=activeScore().system(sy1).staff(stIx).voice(voIx) voice=voiceList[voIx] noteObject = voiceList[voIx].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) for obj in range(objList.length): no = vo.noteObj(obj) ix = 0 verbergen(score) elif auswahl == 4: # Partitur getBaseData(score) systems = system.parentNode systemList = getElementObjects(systems.childNodes) for syIx in range(systemList.length): staves = getElementObjects(systemList[syIx].childNodes) for svIx in range(staves.length): staffList = getElementObjects(staves[svIx].childNodes) for stIx in range(staffList.length): voicesList = getElementObjects(staffList[stIx].childNodes) for vsIx in range(voicesList.length): voiceList = getElementObjects(voicesList[vsIx].childNodes) for voIx in range(voiceList.length): vo=activeScore().system(syIx).staff(stIx).voice(voIx) voice=voiceList[voIx] noteObject = voiceList[voIx].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) for obj in range(objList.length): no = vo.noteObj(obj) ix = 0 verbergen(score) return # Jetzt kommt der Code für den Dialog---------------------------------------------------------------------- def scriptDialog(): global auswahl, cas1, cas2, cas3, cas4, cas5, cas6, cas7 radAuswahl = Radio(['markierte Noten in der Zeile','eine Stimme in der Zeile','alle Stimmen in einer Zeile','System','Partitur'],text='Bereichswahl',value=0) lblVor = Label('Vorlaufnote ',width=6) lblUeb = Label('Mittenüberschreitung',width=6) lblLeer= Label(' ') lblAbs = Label(' ',with=6) lblAuf = Label(' Auflösung',width=6) lblVor1 = Label(' 1/8 ',width=6) lblVor2 = Label(' 1/4 ',width=6) lblVor3 = Label(' ',width=6) lblUeb1 = Label(' 1/4 ',width=6) lblUeb2 = Label(' 1/4 . ',width=6) lblUeb3 = Label(' 1/2 ',width=6) lblUeb4 = Label(' 1/2 . ',width=6) lblAbs1 = Label(' -> ',with=6) lblAuf1 = Label(' 1/8 ._.1/8 ',width=6) lblAuf2 = Label(' 1/8 ._.1/4 ',width=6) lblAuf3 = Label(' 1/4 . ._.1/8 ',width=6) lblAuf4 = Label(' 1/4 ._.1/8 ',width=6) lblAuf5 = Label(' 1/4 ._.1/4 . ',width=6) lblAuf6 = Label(' 1/4 ._.1/4 ',width=6) lblAuf7 = Label(' 1/4 ._.1/2 ',width=6) lblAuf8 = Label(' 1/2 ._.1/4 ',width=6) chkCas1 = CheckBox(' ',value=1) chkCas2 = CheckBox(' ',value=1) chkCas3 = CheckBox(' ',value=0) chkCas4 = CheckBox(' ',value=1) chkCas5 = CheckBox(' ',value=0) chkCas6 = CheckBox(' ',value=0) chkCas7 = CheckBox(' ',value=0) subboxL = HBox([lblLeer]) subboxU = HBox([lblVor,lblUeb,lblAbs,lblAuf,lblAbs]) subbox1 = HBox([lblVor1,lblUeb1,lblAbs1,lblAuf1,chkCas1]) subbox2 = HBox([lblVor1,lblUeb2,lblAbs1,lblAuf2,chkCas2]) subbox3 = HBox([lblVor1,lblUeb3,lblAbs1,lblAuf3,chkCas3]) subbox4 = HBox([lblVor2,lblUeb2,lblAbs1,lblAuf4,chkCas4]) subbox5 = HBox([lblVor2,lblUeb3,lblAbs1,lblAuf6,chkCas5]) subbox6 = HBox([lblVor2,lblUeb4,lblAbs1,lblAuf7,chkCas6]) subbox7 = HBox([lblVor3,lblUeb4,lblAbs1,lblAuf8,chkCas7]) #chkCopy = CheckBox('übernehmen ',value=int(opt.get('copy',str(cy)))) # Daten aus anderer Partitur übernehmen #subboxCopy = VBox([chkCopy],text='Datenübernahme') selBox = VBox([subboxU,subboxL,subbox1,subbox2,subbox3,subbox4,subbox5,subbox6,subbox7],text='Pausen unsichtbar') #box = HBox([radAuswahl,selBox]) box = HBox([radAuswahl]) dlg = Dialog('Pausen unsichtbar', box) # und nun wird der Dialog aufgerufen ---------------------------------------------------------------------- if dlg.run(): auswahl = radAuswahl.value() cas1 = chkCas1.value() cas2 = chkCas2.value() cas3 = chkCas3.value() cas4 = chkCas4.value() cas5 = chkCas5.value() cas6 = chkCas6.value() cas7 = chkCas7.value() return True else: return False # das sollte immer am Ende stehen, denn sonst lassen sich die Aktionen des Skriptes nicht rückgängig machen if activeScore(): if scriptDialog(): activeScore().registerUndo("Pausen unsichtbar") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) # messageBox(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)