+class StaffGroup:
+ def __init__ (self, command = "StaffGroup"):
+ self.stafftype = command
+ self.id = None
+ self.instrument_name = None
+ self.short_instrument_name = None
+ self.symbol = None
+ self.spanbar = None
+ self.children = []
+ self.is_group = True
+ # part_information is a list with entries of the form
+ # [staffid, voicelist]
+ # where voicelist is a list with entries of the form
+ # [voiceid1, [lyricsid11, lyricsid12,...] ]
+ self.part_information = None
+
+ def append_staff (self, staff):
+ self.children.append (staff)
+
+ def set_part_information (self, part_name, staves_info):
+ if part_name == self.id:
+ self.part_information = staves_info
+ else:
+ for c in self.children:
+ c.set_part_information (part_name, staves_info)
+
+ def print_ly_contents (self, printer):
+ for c in self.children:
+ if c:
+ c.print_ly (printer)
+ def print_ly_overrides (self, printer):
+ needs_with = False
+ needs_with |= self.spanbar == "no"
+ needs_with |= self.instrument_name != None
+ needs_with |= self.short_instrument_name != None
+ needs_with |= (self.symbol != None) and (self.symbol != "bracket")
+ if needs_with:
+ printer.dump ("\\with {")
+ if self.instrument_name or self.short_instrument_name:
+ printer.dump ("\\consists \"Instrument_name_engraver\"")
+ if self.spanbar == "no":
+ printer.dump ("\\override SpanBar #'transparent = ##t")
+ brack = {"brace": "SystemStartBrace",
+ "none": "f",
+ "line": "SystemStartSquare"}.get (self.symbol, None)
+ if brack:
+ printer.dump ("systemStartDelimiter = #'%s" % brack)
+ printer.dump ("}")
+
+ def print_ly (self, printer):
+ if self.stafftype:
+ printer.dump ("\\new %s" % self.stafftype)
+ self.print_ly_overrides (printer)
+ printer.dump ("<<")
+ printer.newline ()
+ if self.stafftype and self.instrument_name:
+ printer.dump ("\\set %s.instrumentName = %s" % (self.stafftype,
+ escape_instrument_string (self.instrument_name)))
+ printer.newline ()
+ if self.stafftype and self.short_instrument_name:
+ printer.dump ("\\set %s.shortInstrumentName = %s" % (self.stafftype,
+ escape_instrument_string (self.short_instrument_name)))
+ printer.newline ()
+ self.print_ly_contents (printer)
+ printer.newline ()
+ printer.dump (">>")
+ printer.newline ()
+
+
+class Staff (StaffGroup):
+ def __init__ (self, command = "Staff"):
+ StaffGroup.__init__ (self, command)
+ self.is_group = False
+ self.part = None
+ self.voice_command = "Voice"
+ self.substafftype = None
+
+ def print_ly_overrides (self, printer):
+ pass
+
+ def print_ly_contents (self, printer):
+ if not self.id or not self.part_information:
+ return
+ sub_staff_type = self.substafftype
+ if not sub_staff_type:
+ sub_staff_type = self.stafftype
+
+ for [staff_id, voices] in self.part_information:
+ if staff_id:
+ printer ('\\context %s = "%s" << ' % (sub_staff_type, staff_id))
+ else:
+ printer ('\\context %s << ' % sub_staff_type)
+ printer.newline ()
+ n = 0
+ nr_voices = len (voices)
+ for [v, lyrics] in voices:
+ n += 1
+ voice_count_text = ''
+ if nr_voices > 1:
+ voice_count_text = {1: ' \\voiceOne', 2: ' \\voiceTwo',
+ 3: ' \\voiceThree'}.get (n, ' \\voiceFour')
+ printer ('\\context %s = "%s" {%s \\%s }' % (self.voice_command, v, voice_count_text, v))
+ printer.newline ()
+
+ for l in lyrics:
+ printer ('\\new Lyrics \\lyricsto "%s" \\%s' % (v,l))
+ printer.newline()
+ printer ('>>')
+
+ def print_ly (self, printer):
+ if self.part_information and len (self.part_information) > 1:
+ self.stafftype = "PianoStaff"
+ self.substafftype = "Staff"
+ StaffGroup.print_ly (self, printer)
+
+class TabStaff (Staff):
+ def __init__ (self, command = "TabStaff"):
+ Staff.__init__ (self, command)
+ self.string_tunings = []
+ self.tablature_format = None
+ self.voice_command = "TabVoice"
+ def print_ly_overrides (self, printer):
+ if self.string_tunings or self.tablature_format:
+ printer.dump ("\\with {")
+ if self.string_tunings:
+ printer.dump ("stringTunings = #'(")
+ for i in self.string_tunings:
+ printer.dump ("%s" % i.semitones ())
+ printer.dump (")")
+ if self.tablature_format:
+ printer.dump ("tablatureFormat = #%s" % self.tablature_format)
+ printer.dump ("}")
+
+
+class DrumStaff (Staff):
+ def __init__ (self, command = "DrumStaff"):
+ Staff.__init__ (self, command)
+ self.drum_style_table = None
+ self.voice_command = "DrumVoice"
+ def print_ly_overrides (self, printer):
+ if self.drum_style_table:
+ printer.dump ("\with {")
+ printer.dump ("drumStyleTable = #%s" % self.drum_style_table)
+ printer.dump ("}")
+
+class RhythmicStaff (Staff):
+ def __init__ (self, command = "RhythmicStaff"):
+ Staff.__init__ (self, command)
+
+