# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2009 Peter Becker Splitting Notes (in the middle of the measure)

Attention: At the moment only fit for the 4/4 meter or individual notes.

This script divides the measure in two, that is, when a note reaches across the middle of the measure, it will be divided into two smaller tied notes. It is also possible to select directly an individual note for this purpose.

In case of failures please a mail to peter_becker@freenet.de

Noten mitteln

Achtung : Derzeit nur für den 4/4 Takt oder einzelne Noten verwenden.

Dieses Skript mittelt den Takt, das heißt, wenn eine Note das Mitten eines Taktes überschreitet, wird die Note gespaltet in zwei kleinere angebundenen Noten. Die Note kann zu diesem Zweck auch direkt ausgewählt werden.

Im Fehlerfall bitte eine Mail an peter_becker@freenet.de

Noten opspltsen (midden in de maat)

N.B.: Momenteel is het script slechts bruikbaar voor de 4/4 maat of afzonderlijke noten.

Dit script deelt de maat doormidden, d.w.z. wanneer een noot over het midden van een maat heen reikt, wordt deze opgesplitst in twee kleinere overgebonden noten. Met dit doel kan de noot ook direct worden geselecteerd.

Foutmeldingen graag naar peter_becker@freenet.de

History: 29.06.09 - V 1.0.0 PB Erste Ausgabe 15.08.09 - V 1.0.1 PB mehr Sicherheit bei Ermittlung der Zeilen 04.12.17 - V 1.0 2 WW Internationalisierung en-de-nl 05.12.17 - V 1.0.3 PB überflüssigen Vorspann entfernt und Version hinzugefügt, Dialog behält jetzt die Auswahl 08.12.17 - V 1.0.4 WW auch einzelne (punktierte) halbe Noten werden gespaltet 08.12.17 - V 1.0.5 PB Akkordverdopplung behoben 14.10.19 - V 1.0.6 WW Übersetzungen korrigiert und Infotext nach 'Hilfe' kopiert 25.08.20 - V 1.0.7 WW Im engl. und niederl. Dialogtext Untertitel 'Solution' besser positioniert 07.10.20 - V 1.0.8 WW Optionen 3. und 9. zugefügt; Reihenfolge geändert; Dialogtext ausgebreitet mit Fußnoten """ #------------------------------------------------ version = '1.0.8' english = { 'error' :'Error', 'noScore' :'no active score', 'noteCurs' :'Note after cursor', '1VoiceStaff' :'One voice in the staff', 'allVoicesStaff' :'All voices in a staff', 'system' :'System', 'score' :'Score', 'divideNote' :'Dividing a note', 'preNote' :'Note in front', 'origNote' :' Note to be divided ', 'solution' :'Solution', 'note1' :'at the beginning of the measure; possibly more notes with total duration of 1/8 note ', 'note2' :'at the beginning of the measure; possibly more notes with total duration of 1/4 note ', 'note3' :'or another note value, provided that the total duration of all notes from the barline ', 'note4' :'up to the note to be divided corresponds with a dotted 1/4 note ', 'crossMidlde' :'Crossing the middle of the measure', 'divideNotes' :'Dividing Notes (in the middle of the measure) Version : ', 'help' :'This script divides the measure in two, that is, \ when a note reaches across the middle of the measure, it will be divided \ into two smaller tied notes. It is also possible to select \ directly an individual note for this purpose.\n\ \nAttention: At the moment only fit for the 4/4 meter \ or individual notes.' } german = { 'error' :'Fehler', 'noScore' :'keine aktive Partitur', 'noteCurs' :'Note nach Cursor', '1VoiceStaff' :'eine Stimme in der Zeile', 'allVoicesStaff' :'alle Stimmen in einer Zeile', 'system' :'System', 'score' :'Partitur', 'divideNote' :'Note mitteln', 'preNote' :'Vorlaufnote', 'origNote' :'Mittenüberschreitung', 'solution' :'Auflösung', 'note1' :'am Anfang des Taktes; möglicherweise mehr Noten mit Gesamtlänge einer 1/8 Note ', 'note2' :'am Anfang des Taktes; möglicherweise mehr Noten mit Gesamtlänge einer 1/4 Note ', 'note3' :'oder sonstiger Notenwert, wenn nur die Gesamtlänge aller Noten vom Taktstrich ab ', 'note4' :'bis zur aufzuteilen Note einer punktierten 1/4 Note entspricht ', 'crossMidlde' :'Mittenüberschreitung', 'divideNotes' :'Noten mitteln Version : ', 'help' :'Dieses Skript mittelt den Takt, das heißt, \ wenn eine Note das Mitten eines Taktes überschreitet, \ wird die Note gespaltet in zwei kleinere angebundenen Noten. \ Die Note kann zu diesem Zweck auch direkt ausgewählt werden.\n\ \nAchtung : Derzeit nur für den 4/4 Takt oder einzelne Noten verwenden.' } dutch = { 'error' :'Fout', 'noScore' :'geen actieve partituur', 'noteCurs' :'Noot na cursor', '1VoiceStaff' :'Één stem in de notenbalk', 'allVoicesStaff' :'Alle stemmen in een notenbalk', 'system' :'Systeem', 'score' :'Partituur', 'divideNote' :'Noot opsplitsen', 'preNote' :'Noot vooraf ', 'origNote' :' Op te splitsen noot ', 'note1' :'aan het begin van de maat; eventueel meer noten met een totale lengte van 1/8 noot ', 'note2' :'aan het begin van de maat; eventueel meer noten met een totale lengte van 1/4 noot ', 'note3' :'of een andere notenwaarde, mits de totale lengte van alle noten vanaf de maatstreep ', 'note4' :'tot de op te splitsen noot overeenkomt met een gepuncteerde 1/4 noot ', 'solution' :'Oplossing', 'crossMidlde' :'Overschrijding van het midden van de maat', 'divideNotes' :'Noten opsplitsen (midden in de maat) Versie : ', 'help' :'Dit script deelt de maat doormidden, \ d.w.z. wanneer een noot over het midden van een maat heen reikt, \ wordt deze opgesplitst in twee kleinere overgebonden noten. \ Met dit doel kan de noot ook direct worden geselecteerd. \n\ \nN.B.: Momenteel is het script slechts bruikbaar voor \ de 4/4 maat of afzonderlijke noten.' } try: setStringTable( ("en", english), ("de", german), ("nl", dutch)) except: def tr(s): return german[s] #------------------------------------------------- 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(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 addNewElementNode(el,tagName): # add new Node with tagName "tagName" to el global doc newChild = doc.createElement(tagName) el.appendChild(newChild) return newChild def NoteAufteilen(punkt,duration,obj): if punkt == '2' or punkt == '3' or punkt == '6' or punkt == '7' or punkt == '8': duration[0].setAttribute('base','1/4') elif punkt == '0' or punkt == '1' or punkt == '5': duration[0].setAttribute('base','1/8') elif punkt == '4': duration[0].setAttribute('base','1/2') heads = obj.getElementsByTagName('head') for n in range(heads.length): if punkt == '1' or punkt == '2' or punkt == '4' or punkt == '6': duration[0].removeAttribute('dots') if punkt == '7' or punkt == '8': duration[0].setAttribute('dots','1') tie = addNewElementNode(heads[n],'tie') tie.setAttribute('begin','true') el = obj.cloneNode(1) obj.parentNode.insertBefore(el,obj) tie.setAttribute('end','true') tie.removeAttribute('begin') dos = obj.getElementsByTagName('drawObjects') #falls draw Objects an der 2. Note dranhängen if dos: #diese jetzt löschen dos[0].parentNode.removeChild(dos[0]) if punkt == '1': duration[0].setAttribute('base','1/4') elif punkt == '2': duration[0].setAttribute('base','1/8') elif punkt == '4': duration[0].setAttribute('base','1/4') elif punkt == '5': duration[0].setAttribute('base','1/4') duration[0].setAttribute('dots','1') elif punkt == '6': duration[0].setAttribute('base','1/2') elif punkt == '7': duration[0].setAttribute('base','1/8') duration[0].setAttribute('dots','0') elif punkt == '8': duration[0].setAttribute('base','1/4') duration[0].setAttribute('dots','1') break # Abbruch, sonst gibt es Akkordverdopplung bei Akkorden def getBaseData(score): global sel, system, staff,voice, noteObject, objList, selvon selvon = sel[0] 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) def mitteln(score): global sel, system, staff,voice, noteObject, objList, selvon, vo, takt global cas1, cas2, cas3, cas4, cas5, cas6, cas7, cas8, cas9 for obj in range(objList.length): du = 0 no = vo.noteObj(obj) if objList[obj].tagName == 'timeSign': time = no.meter() takt = 0 elif no.isChord(): duration = objList[obj].getElementsByTagName('duration') if duration[0].hasAttribute('dots'): dot = duration[0].getAttribute('dots') else: dot = '0' lng = duration[0].getAttribute('base') du = no.duration() takt = takt + du #messageBox('TAKT',str(du) + '\n' + str(takt) + '\n' + str(dot) + '\n' + str(cas6)) lng = duration[0].getAttribute('base') if str(takt) == '3/4' and str(lng) == '1/2' and dot == '1' and cas1 == 1: NoteAufteilen('4',duration,objList[obj]) elif str(takt) == '5/8' and str(lng) == '1/2' and dot == '0' and cas2 == 1: NoteAufteilen('7',duration,objList[obj]) elif str(takt) == '7/8' and str(lng) == '1/2' and dot == '1' and cas3 == 1: NoteAufteilen('8',duration,objList[obj]) elif str(takt) == '5/8' and str(lng) == '1/4' and dot <> '0' and cas4 == 1: NoteAufteilen('2',duration,objList[obj]) elif str(takt) == '3/4' and str(lng) == '1/2' and dot == '0' and cas5 == 1: NoteAufteilen('3',duration,objList[obj]) elif str(takt) == '1' and str(lng) == '1/2' and dot == '1' and cas6 == 1: NoteAufteilen('6',duration,objList[obj]) elif str(takt) == '5/8' and str(lng) == '1/4' and dot == '0' and cas7 == 1: NoteAufteilen('0',duration,objList[obj]) elif str(takt) == '3/4' and str(lng) == '1/4' and dot <> '0' and cas8 == 1: NoteAufteilen('1',duration,objList[obj]) elif str(takt) == '7/8' and str(lng) == '1/2' and dot == '0' and cas9 == 1: NoteAufteilen('5',duration,objList[obj]) if no.implBarline(): takt = 0 elif no.isRest(): du = no.duration() takt = takt + du if no.implBarline(): takt = 0 elif no.isBarline(): takt = 0 # Hier kommt die Klasse die vom Ende her aufgerufen wird ------------------------------------------------- class ScoreChange(ScoreChange): def changeScore(self, score): global doc, sel, system, staff,voice, noteObject, objList, selvon, vo, takt global auswahl, cas1, cas2, cas3, cas4, cas5, cas6, cas7, cas8, cas9 doc = score.parentNode sel = getCursor() if sel == None: return else: if auswahl == 0: # nur Note getBaseData(score) obj = objList[selvon[3]] if obj.tagName == 'chord': dot = '0' duration = obj.getElementsByTagName('duration') lng = duration[0].getAttribute('base') if duration[0].hasAttribute('dots'): dot = duration[0].getAttribute('dots') if lng == '1/4' and dot == '0': NoteAufteilen('0',duration,obj) elif lng =='1/4' and dot == '1': NoteAufteilen('1',duration,obj) elif lng == '1/2' and dot == '0': NoteAufteilen('3',duration,obj) elif lng =='1/2' and dot == '1': NoteAufteilen('6',duration,obj) elif auswahl == 1: # eine Stimme in einer Zeile takt = 0 getBaseData(score) vo=activeScore().system(selvon[0]).staff(selvon[1]).voice(selvon[2]) mitteln(score) elif auswahl == 2: # alle Stimmen in einer Zeile getBaseData(score) obj = objList[selvon[3]] voiceList = getElementObjects(obj.parentNode.parentNode.parentNode.childNodes) for voIx in range(voiceList.length): takt = 0 noteObject = voiceList[voIx].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) vo=activeScore().system(selvon[0]).staff(selvon[1]).voice(voIx) voice=voiceList[voIx] for obj in range(objList.length): no = vo.noteObj(obj) mitteln(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(selvon[0]).staff(stIx).voice(voIx) voice=voiceList[voIx] noteObject = voiceList[voIx].getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) takt = 0 for obj in range(objList.length): no = vo.noteObj(obj) mitteln(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) takt = 0 for obj in range(objList.length): no = vo.noteObj(obj) mitteln(score) return # Jetzt kommt der Code für den Dialog---------------------------------------------------------------------- def scriptDialog(): global auswahl, cas1, cas2, cas3, cas4, cas5, cas6, cas7, cas8, cas9, version options = ScriptOptions() opt = options.get() radAuswahl = Radio([tr('noteCurs'),tr('1VoiceStaff'),tr('allVoicesStaff'),tr('system'),tr('score')],text=tr('divideNote'),value=int(opt.get('auswahl', 0))) lblVor = Label(tr('preNote'),width=9) lblUeb = Label(tr('origNote'),width=9) lblLeer= Label(' ',width=2) lblAbs = Label(' ',width=5) lblAuf = Label(tr('solution'),width=6) lblVor1 = Label(' 1/8*',width=7) lblVor2 = Label(' 1/4**',width=7) lblVor3 = Label('(¼ +) 1/8***',width=7) lblVor4 = Label(' ----',width=7) 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(' -> ',width=6) lblAuf1 = Label(' 1/8 ._.1/8',width=12) lblAuf2 = Label(' 1/8 ._.1/4',width=12) lblAuf3 = Label(' 1/4 . ._.1/8',width=12) lblAuf4 = Label(' 1/4 ._.1/8',width=12) lblAuf5 = Label(' 1/8 ._.1/4 .',width=12) lblAuf6 = Label(' 1/4 ._.1/4',width=12) lblAuf7 = Label(' 1/4 ._.1/2',width=12) lblAuf8 = Label(' 1/2 ._.1/4',width=12) lblAuf9 = Label(' 1/4 . ._.1/4 .',width=12) lblStrich = Label('-------------------------------------------------',width=50) lblStern1 = Label('*',width=2) lblStern2 = Label('**',width=2) lblStern3 = Label('***',width=2) lblNote1 = Label(tr('note1'),width=50) lblNote2 = Label(tr('note2'),width=50) lblNote3 = Label(tr('note3'),width=50) lblNote4 = Label(tr('note4'),width=50) chkCas1 = CheckBox(' ',value=int(opt.get('cas1', 0))) chkCas2 = CheckBox(' ',value=int(opt.get('cas2', 0))) chkCas3 = CheckBox(' ',value=int(opt.get('cas3', 0))) chkCas4 = CheckBox(' ',value=int(opt.get('cas4', 1))) chkCas5 = CheckBox(' ',value=int(opt.get('cas5', 0))) chkCas6 = CheckBox(' ',value=int(opt.get('cas6', 0))) chkCas7 = CheckBox(' ',value=int(opt.get('cas7', 1))) chkCas8 = CheckBox(' ',value=int(opt.get('cas8', 1))) chkCas9 = CheckBox(' ',value=int(opt.get('cas9', 0))) subboxL = HBox([lblLeer]) subboxU = HBox([lblLeer,lblVor,lblUeb,lblAbs,lblAuf,lblAbs]) subbox1 = HBox([lblLeer,lblVor4,lblUeb4,lblAbs1,lblAuf8,chkCas1]) subbox2 = HBox([lblLeer,lblVor1,lblUeb3,lblAbs1,lblAuf3,chkCas2]) subbox3 = HBox([lblLeer,lblVor1,lblUeb4,lblAbs1,lblAuf9,chkCas3]) subbox4 = HBox([lblLeer,lblVor2,lblUeb2,lblAbs1,lblAuf4,chkCas4]) subbox5 = HBox([lblLeer,lblVor2,lblUeb3,lblAbs1,lblAuf6,chkCas5]) subbox6 = HBox([lblLeer,lblVor2,lblUeb4,lblAbs1,lblAuf7,chkCas6]) subbox7 = HBox([lblLeer,lblVor3,lblUeb1,lblAbs1,lblAuf1,chkCas7]) subbox8 = HBox([lblLeer,lblVor3,lblUeb2,lblAbs1,lblAuf2,chkCas8]) subbox9 = HBox([lblLeer,lblVor3,lblUeb3,lblAbs1,lblAuf5,chkCas9]) subboxN1 = HBox([lblStrich]) subboxN2 = HBox([lblStern1,lblNote1]) subboxN3 = HBox([lblStern2,lblNote2]) subboxN4 = HBox([lblStern3,lblNote3]) subboxN5 = HBox([lblLeer,lblNote4]) #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,subbox8,subbox9,subboxN1,subboxN2,subboxN3,subboxN4,subboxN5],text=tr('crossMidlde')) box = VBox([HBox([radAuswahl,selBox])]) dlg = Dialog(tr('divideNotes') + str(version), box, help=tr('help')) # 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() cas8 = chkCas8.value() cas9 = chkCas9.value() opt.update(dict(auswahl=auswahl, cas1=cas1, cas2=cas2, cas3=cas3, cas4=cas4, cas5=cas5, cas6=cas6, cas7=cas7, cas8=cas8, cas9=cas9)) options.set(opt) 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("Noten mitteln") 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)