# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2010 Peter Becker >>> ChorAlong Lautstärke für eine einzelne Stimmen hervorheben|| Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< History: 03.08.2010 - Erste Ausgabe 4-stimmig, 4 Notenzeilen System 14.08.2010 - Anzahl Stimmen und Zeilen beliebig 24.08.2010 - Balance und Original sichern und wiederherstellen 27.08.2010 - Sicherung dateiabhängig machen 30.08.2010 - Wording im Menu angepasst """ import xml.dom, tempfile import tkFont import Tkinter from caplib.capDOM import * from xml.dom.minidom import * from re import * from string import * import shelve def changeDoc(score): global select,laut,leise,blaut,bleise,fun,anzahlStimmen,volume,balance,options,opt #messageBox('vorz',str(select) + '\n' + str(laut) + '\n' + str(leise)) bandbreite = 'NOK' while bandbreite == 'NOK' : if pqDialog(score): if fun == 0: if int(laut) < 0 or int(laut) > 127 or int(leise) < 0 or int(leise) > 127: messageBox('falsche Voreinstellung - Lautstärke','erlaubte Bandbreite 0 bis 127') bandbreite = 'NOK' elif int(blaut) < -64 or int(blaut) > 63 or int(bleise) < -64 or int(bleise) > 63: messageBox('falsche Voreinstellung - Balance','erlaubte Bandbreite -64 bis 63') bandbreite = 'NOK' else: bandbreite = 'OK' if select == anzahlStimmen: # alles laut layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): for snd in sLs.getElementsByTagName('sound'): snd.setAttribute('volume',str(laut)) snd.setAttribute('panorama','0') else: cnt = 0 layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): for snd in sLs.getElementsByTagName('sound'): if cnt == select: snd.setAttribute('volume',str(laut)) snd.setAttribute('panorama',str(blaut)) cnt = cnt + 1 else: snd.setAttribute('volume',str(leise)) snd.setAttribute('panorama',str(bleise)) cnt = cnt + 1 elif fun == 1: volume = [] balance = [] layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): for snd in sLs.getElementsByTagName('sound'): vol = latin1_e(snd.getAttribute('volume')) if snd.hasAttribute('panorama'): pan = latin1_e(snd.getAttribute('panorama')) else: pan = '0' volume.append(vol) balance.append(pan) saveStandart(score,volume,balance) else: bandbreite = 'OK' volorg = [] balorg = [] layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): for snd in sLs.getElementsByTagName('sound'): vol = latin1_e(snd.getAttribute('volume')) if snd.hasAttribute('panorama'): pan = latin1_e(snd.getAttribute('panorama')) else: pan = '0' volorg.append(vol) balorg.append(pan) cnt = 0 status = restoreStandart(score) if status == 'NOK': messageBox('RESTORE STATUS1','Es existiert keine gültige Sicherung für diese Datei.') return if len(volorg) <> len(volume): messageBox('RESTORE STATUS2','Die vorhandene Dateisicherung entspricht nicht dem Mustersystem der aktuellen Datei.') return layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): for snd in sLs.getElementsByTagName('sound'): vol = volume bal = balance snd.setAttribute('volume',str(vol[cnt])) snd.setAttribute('panorama',str(bal[cnt])) cnt = cnt + 1 else: bandbreite = 'OK' # entspricht Abbruch def restoreStandart(score): global volume, balance path = upper(activeScore().pathName()) if path.endswith('CAPX') == 1: path=path.rstrip('CAPX') else: path=path.rstrip('CAP') StandartSave = shelve.open(path + 'CAL') if StandartSave.has_key('V'): volume = StandartSave['V'] balance = StandartSave['B'] status = 'OK' else: status = 'NOK' StandartSave.close() return status def saveStandart(score,volume,balance): path = upper(activeScore().pathName()) if path.endswith('CAPX') == 1: path=path.rstrip('CAPX') else: path=path.rstrip('CAP') StandartSave = shelve.open(path + 'CAL') daten = {'V':volume,'B':balance} #messageBox('DAT',str(daten)) StandartSave.update(daten) StandartSave.close() def pqDialog(score): global select,laut,leise,fun,anzahlStimmen,blaut,bleise,volume,options,opt lt = '100' ls = '50' bls = '-64' blt = '63' fn = '0' options = ScriptOptions() opt = options.get() stimmen = [] funktion = ['Stimme hervorheben','aktuellen Zustand sichern','gesicherten Zustand wiederherstellen'] layout = score.getElementsByTagName('layout')[0] staves = layout.getElementsByTagName('staves')[0] for sLs in staves.getElementsByTagName('staffLayout'): desc = sLs.getAttribute('description') cnt = 0 for snd in sLs.getElementsByTagName('sound'): element = latin1_e(desc + '-' + str(cnt) + ' hervorheben') stimmen.append(element) cnt = cnt + 1 stimmen.append('Alle Stimmen gleichwertig (Laut). Balance wird auf Mitte gestellt') anzahlStimmen = len(stimmen)-1 radioF = Radio(funktion, value=int(opt.get('fn', 0))) lablTitel = Label(' Lautstärke Balance ') lablLeer = Label(' ') lablText1 = Label('ACHTUNG : Die Stimmen werden wie im Mustersystem angegeben, angezeigt. ') lablText2 = Label(' Die Stimmbezeichnung kommt aus dem Feld "Beschreibung". ') lablText3 = Label(' Mehrere Stimmen in einer Zeile werden durchnummeriert, ') lablText4 = Label(' aber nur, wenn sie auch im Mustersystem sichtbar sind. ') lablText5 = Label(' Balance und Anzeige mit getrennter Reglung mehrerer ') lablText6 = Label(' Stimmen pro Zeile nur ab Capella V7 unterstützt. ') lablLaut = Label('LAUT ',width=6) editLaut = Edit (opt.get('lt',str(lt)),width=4) lablLeise = Label('LEISE ',width=6) editLeise = Edit (opt.get('ls',str(ls)),width=4) editBLaut = Edit (opt.get('blt',str(blt)),width=4) editBLeise = Edit (opt.get('bls',str(bls)),width=4) radioS = Radio(stimmen, value=int(opt.get('sel', 0))) vBoxF = VBox([radioF],text='Funktion') hBox1 = HBox([lablLeise,editLeise,lablLeer,editBLeise]) hBox2 = HBox([lablLaut,editLaut,lablLeer,editBLaut]) vBoxV = VBox([lablTitel,lablLeer,hBox1,hBox2],text='Voreinstellungen') vBoxS = VBox([radioS,lablLeer],text='Stimmen aus Mustersystem') box = VBox([vBoxF,vBoxV,vBoxS,lablText1,lablText2,lablText3,lablText4,lablText5,lablText6,lablLeer]) dlg = Dialog('gewünscht Hervorhebung auswählen', box) if dlg.run(): select = radioS.value() fun = radioF.value() laut = editLaut.value() leise = editLeise.value() bleise = editBLeise.value() blaut = editBLaut.value() opt.update(dict(sel=select, lt=laut, ls=leise, blt=blaut, bls=bleise)) options.set(opt) return True else: return False def latin1_e(u): return u.encode('Latin-1') # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): changeDoc(score) if activeScore(): global tempInput, tempOutput activeScore().registerUndo("ChorAlong") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)