# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2010 Peter Becker >>> Taktnummern für Capella V7 Das ist ein Capella Version 7 Skript. || Es fügt an der Cursorposition eine Taktnummer ein <<< # 10.05.2010 Erste Version # 11.05.2010 Absturz verhindert wenn Cursor am Ende einer Zeile steht """ #---------------------------------------------------------------------------- co = cursorObj() # NoteObj nach Cursor ixSy = curSelection()[0][0] # Cursor Position als Index für die System ixSt = curSelection()[0][1] # Cursor Position als Index für die Staff ixVo = curSelection()[0][2] # Cursor Position als Index für die Voice ixNo = curSelection()[0][3] # Cursor Position als Index für das NoteObject #----------------------------------------------------------------------------- colors = [Color.black, Color.red, Color.blue, Color.green] colorNames = ['schwarz', 'rot', 'blau', 'grün' ] rundung = ['16' , '32', '48', '64' ] txtabst = ['16' , '32', '48'] position = ['-10' , '-9', '-8', '-7', '-6', '-5' , '-4', '-3', '-2'] #----------------------------------------------------------------------------- ver, sub, sr = capVersion() #messageBox('capella', 'Version %d.%02d-%02d' % (ver, sub, sr)) if ver <> 7: messageBox('Skript','Dieses Skript funktioniert erst ab Capella Version 7') elif not co: messageBox('Cursor','Der Cursor steht nicht vor einem gültigen Notenobjekt') else: #--- Dialog -------------------------------------------------------------------------------------------- def pqDialog(): global size,sansSerif, colorF, rahmen, radius, abstand, vpos options = ScriptOptions() opt = options.get() #----- Dialogaufbau --------------------------------- # Schriftgröße comboSize = ComboBox([str(i) for i in range(6,15)],value=int(opt.get('size', '11'))-6) hBox5 = HBox([Label('&Größe'), comboSize, Label('Punkt', width=10)], padding=8) # ohne Serifen checkS = CheckBox('ohne Serifen', value=int(opt.get('sansSerif', '0'))) # Farbe comboColorF = ComboBox(colorNames, width=8, value=int(opt.get('clrF', '0'))) hBoxF = HBox([Label('Farbe'), comboColorF], padding=16) # Gruppe Schrift zusammensetzen: vBoxF = VBox([hBox5, checkS, hBoxF], text='Schrift', padding=8) #---------------------------------------------------- # Rahmen form = Radio(['keiner','rechteckig','oval','abgerundetes Rechteck'],value=int(opt.get('rahmen', '1'))) # Rundung und Textabstand... comboRdg = ComboBox(rundung, width=6, value=int(opt.get('rdg', '0'))) comboTxt = ComboBox(txtabst, width=6, value=int(opt.get('txt', '0'))) hBox2a = HBox([Label('Rundungsradius '), comboRdg, Label(' /32 Zwischenräume ')]) hBox2b = HBox([Label('Abstand zum Text '), comboTxt, Label(' /32 Zwischenräume ')]) vBox2 = VBox([Label(' '), Label(' '), hBox2a, Label(' ')], padding=16) # Position comboPos = ComboBox(position, width=6, value=int(opt.get('pos', '-4'))+10) hBox6 = HBox([Label('Abstand zur Mittellinie'), comboPos], padding=8) # Gruppe Rahmen zusammensetzen: hBox3a = HBox([form, vBox2]) vBox3 = VBox([hBox3a,hBox2b], padding=4, text ='Rahmen') #--- alles zusammensetzen: vBox = VBox([vBoxF, vBox3, hBox6,' '], padding=16) #---------------------------------------------------- dlg = Dialog('Taktnummerierung', vBox) if dlg.run(): size = comboSize.value() + 6 sansSerif = checkS.value() colorF = comboColorF.value() rahmen = form.value() radius = comboRdg.value() abstand = comboTxt.value() vpos = comboPos.value() - 10 opt.update(dict(size=size, sansSerif=sansSerif, clrF=colorF, rahmen=rahmen, rdg=radius, txt=abstand, pos=vpos)) options.set(opt) return True else: return False if pqDialog(): rad = 0 if sansSerif == 1: ts = 'Arial' else: ts = 'Times New Roman' if rahmen == 0: xframe = 'none' elif rahmen == 1: xframe = 'rectangle' elif rahmen == 2: xframe = 'ellipse' else: xframe = 'rectangle' rad = (float(radius) +1 ) * 16 / 32 sys = activeScore().system(ixSy) staff = sys.staff(ixSt) voice = staff.voice(ixVo) obj = voice.noteObj(ixNo) #if obj: # messageBox('OBJ','OBJ') #messageBox('OBJ',str(obj.subType()) + '\n' + str(ixNo)) objS = obj #messageBox('sys',str(sys) + '\n' + str(staff) + '\n' + str(voice) + '\n' + str(note)) ix = ixNo xpos = 0 while ix > 0: objC = voice.noteObj(ix) objP = voice.noteObj(ix-1) #messageBox('ST',str(objC) + '\n' + str(objP) + '\n' + str(objS)) if objC.isChord() or objC.isRest() or objC.isBarline(): #messageBox('ST1',str(objC) + '\n' + str(objP) + '\n' + str(objS) + '\ndown=' + str(down)) if objC.isBarline(): xpos = 0 obj = objC #messageBox('BL',str(obj) + '\n' + str(xpos) + '\n' + str(ix)) break elif objC.implBarline() and objP.implBarline(): #messageBox('IBL1',str(obj) + '\n' + str(ix)) xpos = (objC.posX(1) - objP.implBarline().posX())*-1 obj = objC break elif objC.implBarline() == 0 and objP.implBarline(): #messageBox('IBL2',str(obj) + '\n' + str(ix)) xpos = (objC.posX(1) - objP.implBarline().posX())*-1 obj = objC break else: ix = ix - 1 objS = objC #messageBox('ST2',str(ix)) else: xpos = -2 obj = objS #messageBox('ELSE',str(obj) + '\n' + str(xpos) + '\n' + str(ix)) break txt = dict( type = 'text', x = xpos, y = vpos, frame = xframe, radius = rad, frameDistance = (float(abstand) +1 ) * 16 / 32, font = dict(height=size, weight=0, pitchAndFamily=0, face=ts, color = colors[colorF]), content = '$(|)', basic = dict(scope='system') ) #messageBox('end',str(obj) + '\n' + str(xpos) + '\n' + str(ix) + '\n' + str(txt)) obj.addDrawObj(txt)