# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2005/2011 Peter Becker >>> DiaHarm_C : französische Tabulaturschrift für Diatonische Harmonika Umsetzen von Noten in französische Tabulatur für Diatonische Harmonika. -> Schritt 3 von 3|| Begleitstimme und Tabulatur Schlüssel einfügen|| ||Achtung : Font Ziach.ttf muss installiert sein|| Bei Problemen bitte eine e-mail an peter_becker@freenet.de <<< 18.10.2005 Erste Version 26.07.2011 Version 2.0.0 28.07.2011 Version 2.0.1 keine Änderung zu 2.0.0 08.05.2012 Version 2.0.2 Fehler beim generieren der Begleitstimme durch schärfere Kontrolle ab Capella 7.1-08 """ import xml.dom, tempfile from caplib.capDOM import ScoreChange checkCapVersion(5,1,5) version = '2.0.2' activeScore().registerUndo("DiaHarm_C") for sysix in range(activeScore().nSystems()): # normales Zeilenende feststellen nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -1 # Index zur Griffschrift Zeile TabVoice = activeScore().system(sysix).staff(tabix).voice(0) # Griffschrift Stimme just = activeScore().system(sysix).get('justified') if just == 1: anz = TabVoice.nNoteObjs()-1 zeilenEndeJust = TabVoice.noteObj(anz).posX() break else : zeilenEndeJust = 999 # Absturz verhindert falls nur Kurzzeilen for sysix in range(activeScore().nSystems()): # Zeile falls erforderlich justieren nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -1 # Index zur Griffschrift Zeile TabVoice = activeScore().system(sysix).staff(tabix).voice(0) # Griffschrift Stimme just = activeScore().system(sysix).get('justified') if just == 0: anz = TabVoice.nNoteObjs()-1 zeilenEnde = TabVoice.noteObj(anz).posX() if zeilenEnde > zeilenEndeJust: activeScore().system(sysix).set('justified',1) options = ScriptOptions() opt = options.get() placeholder1 = Label(' ',width=1) placeholder2 = Label(' ',width=1) placeholder3 = Label(' ',width=1) placeholder4 = Label(' ',width=1) radFormatTyp = Radio(['nur Bass','3er Takt = Aaa / 4er = Takt Aaaa / 6er Takt = Aaaaaa','3er Takt = Aaa / 4er = Takt AaAa / 6er Takt = AaaAaa'],text='Formatierungsoption auswählen',value=int(opt.get('FormatTyp','0'))) subboxFormat = HBox([radFormatTyp,placeholder2],padding=4) mainboxFormat = VBox([subboxFormat],text='Begleitschema') box = VBox([mainboxFormat,placeholder1],padding=1) dlg = Dialog('DiaHarm_C Version: ' + version, box) if dlg.run(): formatTyp = radFormatTyp.value() opt = dict( FormatTyp = str(formatTyp) ) options.set(opt) else: exit(0) druck = 'no' x1n = 0 x2n = 0 y1n = 0 y2n = 0 posN = 0 for sysix in range(activeScore().nSystems()): # Begleitakkorde aus Melodiezeile löschen nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -3 # Index zur Melodie Zeile TabVoice = activeScore().system(sysix).staff(tabix).voice(0) # Melodie Stimme for i in range(TabVoice.nNoteObjs()): note = TabVoice.noteObj(i) for k in range(note.nDrawObjs()): # und löschen d = note.drawObj(k) if d <> 0: if d.has_key('tag'): note.deleteDrawObj(k) d['y'] = -5 if d['content'] == 'A': d['content'] = 'Am' if d['content'] <> 'P' and d['content'] <> 'T': note.addDrawObj(d) for sysix in range(activeScore().nSystems()): nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -3 # Index zur Melodie Zeile bglix = nStaves -1 # Index zur Begleitzeile TabVoice = activeScore().system(sysix).staff(tabix).voice(0) # Melodie Stimme BglVoice = activeScore().system(sysix).staff(bglix).voice(0) # Begleitstimme position = 0 meter = 1 # default Taktlänge = 4/4 exBar = 0 # expl.Barline for i in range(TabVoice.nNoteObjs()): note = TabVoice.noteObj(i) if note.subType() == NoteObj.METER: # Taktangabe als Textobjekt vorbereiten meter = note.meter() d = dict(type = 'text', content = '!T' + str(meter)) for ii in range(TabVoice.nNoteObjs()-i): # nächste Note oder Pause finden nextNote = TabVoice.noteObj(i+ii) if nextNote.isChord() or nextNote.isRest(): break nextNote.addDrawObj(d) # Takt an nächste Note oder Pause als Text hängen for k in range(note.nDrawObjs()): # falls eine Taktangabe an der Note hängt d = note.drawObj(k) taktTag = 0 if d['type'] == 'text': xx = d['content'][0:2] if xx == '!T': taktTag = 1 # freigeben zum kopieren in die Begleitzeile if d.has_key('tag') or taktTag == 1: # falls Begleitakkord oder Taktangabe Bposition = 0 Bnote = [] ix = 0 notePos = note.posX(False) for i in range(BglVoice.nNoteObjs()): Bnote = BglVoice.noteObj(i) BnotePos = Bnote.posX(False) if Bnote.isChord() or Bnote.isRest(): while BnotePos < notePos: # korrekte Begleitnote finden ix = ix + 1 Bnote = BglVoice.noteObj(i+ix) BnotePos = Bnote.posX(False) d['y'] = 2 if (d['content'] <> 'T' and d['content'] <> 'P') or (d.has_key('tag') and d['tag'] <> '2086-55'): # falls kein Pseudo Akkord oder InstrumentId if d['content'] == 'Am': d['content'] = 'A' Bnote.addDrawObj(d) # und dranhängen if taktTag == 1: # falls Takangabe dann Original löschen note.deleteDrawObj(k) break meter = 1 # Default Takt = 4/4 ba = ' ' yy = ' ' ct = 1 #messageBox('Trap','Begleitung ergänzen') for sysix in range(activeScore().nSystems()): # Begleitung in Begleitzeile ergänzen nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -1 # Index zur Griffschrift Zeile BglVoice = activeScore().system(sysix).staff(tabix).voice(0) # Griffschrift Stimme for i in range(BglVoice.nNoteObjs()): am = 'no' note = BglVoice.noteObj(i) if note.isChord() or note.isRest(): for ii in range(note.nDrawObjs()): d = note.drawObj(ii) if d <> 0: if d['type'] == 'text': xx = d['content'][0:2] if xx == '!T': meter = d['content'][2:] # Takt extrahieren note.deleteDrawObj(ii) # und Taktmerker löschen if d <> 0: #messageBox('TAG',str(d['content'])) if d.has_key('tag') and d['tag'] <> '2086-55': # Akkordwechsel gefunden am = 'gefunden' yy = d['content'] Begleitung = dict( A = dict(wert='a'), B = dict(wert='b'), C = dict(wert='c'), D = dict(wert='d'), E = dict(wert='e'), F = dict(wert='f'), G = dict(wert='g'), H = dict(wert='h'), P = dict(wert='-'), T = dict(wert='-') ) ba = Begleitung[str(yy)]['wert'] # Begleitakkord merken ct = 1 # Bass if am == 'no': duration = str(note.duration()) d = dict(type = 'text',y = 2,content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) if formatTyp == 1: # Format Typ 1 = Aaa , Aaaa, Aaaaaa etc if duration == str('1/8'): # 8tel Begleitung #messageBox('am=n0 ,str(meter) + ' Cnt=' + str(ct) + '\nyy=' + str(yy) + ' ba=' + str(ba)) ct = ct + 1 if meter == str('1') and ct <= 8: # 4/4 tel Takt d = dict(type = 'text',y = 2,content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif meter == str('2/4') or meter == str('1/2'): # 2/4 tel Takt if ct == 1: # 2/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 4: # 2/4 tel Takt zweite Hälfte ct = 0 elif meter == str('3/4'): # 3/4 tel Takt if ct == 1: # 3/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 6: # 3/4 tel Takt zweite Hälfte ct = 0 note.addDrawObj(d) elif duration == str('1/4'): # 4tel Begleitung ct = ct + 1 if meter == str('1') and ct <= 4: # 4/4 tel Takt d = dict(type = 'text',y = 2,content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif meter == str('2/4') or meter == str('1/2'): # 2/4 tel Takt if ct == 1: # 2/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 2: # 3/4 tel Takt zweite Hälfte ct = 0 elif meter == str('3/4'): # 3/4 oder 6/8 tel Takt if ct == 1: # 3/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 3: # 3/4 tel Takt zweite Hälfte ct = 0 note.addDrawObj(d) elif formatTyp == 2: # Format Typ 2 = Aaa , AaAa, AaaAaa etc if duration == str('1/8'): # 8tel Begleitung #messageBox('Begleitstimme' ,str(meter) + ' Cnt=' + str(ct) + '\nyy=' + str(yy) + ' ba=' + str(ba)) ct = ct + 1 if meter == str('1') and ct <= 4: # 4/4 tel Takt erste Hälfte x = 1 # Dummy Operation elif meter == str('1') and ct == 5: # 4/4 tel Takt zweite Hälft d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) note.addDrawObj(d) d = dict(type = 'text',y = 2,content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) ct = 1 elif meter == str('2/4') or meter == str('1/2'): # 2/4 tel Takt if ct == 1: # 2/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) note.addDrawObj(d) elif ct == 2: # 2/4 tel Takt zweite Hälfte ct = 0 elif meter == str('3/4') and ct <= 3: # 6/8 tel Takt erste Hälfte note.addDrawObj(d) elif meter == str('3/4') and ct == 4: # 6/8 tel Takt zweite Hälfte d = dict(type = 'text', y = 2, content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) note.addDrawObj(d) d = dict(content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) ct = 1 if ct <> 1: note.addDrawObj(d) elif duration == str('1/4'): # 4tel Begleitung #messageBox('Begleitstimme' ,str(meter) + ' Cnt=' + str(ct) + '\nyy=' + str(yy) + ' ba=' + str(ba)) ct = ct + 1 if meter == str('1') and ct <= 2: # 4/4 tel Takt erste Hälfte x = 1 # Dummy operation elif meter == str('1') and ct == 3: # 4/4 tel Takt zweite Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) note.addDrawObj(d) d = dict(type = 'text',y = 2,content = str(ba), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) ct = 1 elif meter == str('2/4') or meter == str('1/2'): # 2/4 tel Takt if ct == 1: # 2/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 2: # 2/4 tel Takt zweite Hälfte ct = 0 elif meter == str('3/4'): # 3/4 tel Takt if ct == 1: # 3/4 tel Takt erste Hälfte d = dict(type = 'text',y = 2,content = str(yy), font = dict(height = 8, pitchAndFamily = 34, face = 'Arial', weight = 700)) elif ct == 3: # 3/4 tel Takt zweite Hälfte ct = 0 if ct <> 1: note.addDrawObj(d) for sysix in range(activeScore().nSystems()): # Tabulatur Zeichen einfügen und # Verbindungslinie unterdrücken nStaves = activeScore().system(sysix).nStaves() tabix = nStaves -2 # Index zur Griffschrift Zeile TabVoice = activeScore().system(sysix).staff(tabix).voice(0) # Griffschrift Stimme aa = activeScore().system(sysix).getAttributes() for i in range(TabVoice.nNoteObjs()): note = TabVoice.noteObj(i) if note.isChord() or note.isRest(): pos = note.posX(1) l1 = dict(type = 'line',x1 = pos*-1,x2 = pos*-1,y1=2,y2=9,lineWidth = 0.6, color=Color.white) note.addDrawObj(l1) # Linie weg t1 = dict(type = 'text',y = 0.2,x = (pos*-1)-0.5,content = 'D', # TAB Sign P/T font = dict(height = 18, pitchAndFamily = 2, charSet = 2, face = 'Ziach', weight = 10)) note.addDrawObj(t1) break