+class Break (Music):
+ def __init__ (self, tp="break"):
+ Music.__init__ (self)
+ self.type = tp
+ def print_ly (self, printer):
+ if self.type:
+ printer.dump ("\\%s" % self.type)
+
+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
+ self.context_modifications = []
+ # 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 add_context_modification (self, modification):
+ self.context_modifications.append (modification)
+
+ def print_ly_contents (self, printer):
+ for c in self.children:
+ if c:
+ c.print_ly (printer)
+ def needs_with (self):
+ 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")
+ return needs_with
+ def print_ly_context_mods (self, printer):
+ 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)
+
+ def print_ly_overrides (self, printer):
+ needs_with = self.needs_with () | (len (self.context_modifications) > 0);
+ if needs_with:
+ printer.dump ("\\with {")
+ self.print_ly_context_mods (printer)
+ for m in self.context_modifications:
+ printer.dump (m)
+ 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 needs_with (self):
+ return False
+ def print_ly_context_mods (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:
+ # Chord names need to come before the staff itself!
+ for [v, lyrics, figuredbass, chordnames] in voices:
+ if chordnames:
+ printer ('\context ChordNames = "%s" \\%s' % (chordnames, chordnames))
+
+ # now comes the real staff definition:
+ 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, figuredbass, chordnames] 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()
+ if figuredbass:
+ printer ('\context FiguredBass = "%s" \\%s' % (figuredbass, figuredbass))
+ 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.lisp_expression ())
+ 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)
+
+class Score:
+ def __init__ (self):
+ self.contents = None
+ self.create_midi = False
+
+ def set_contents (self, contents):
+ self.contents = contents
+
+ def set_part_information (self, part_id, staves_info):
+ if self.contents:
+ self.contents.set_part_information (part_id, staves_info)
+
+ def print_ly (self, printer):
+ printer.dump ("\\score {");
+ printer.newline ()
+ if self.contents:
+ self.contents.print_ly (printer);
+ printer.dump ("\\layout {}");
+ printer.newline ()
+ if not self.create_midi:
+ printer.dump ("% To create MIDI output, uncomment the following line:");
+ printer.newline ();
+ printer.dump ("% ");
+ printer.dump ("\\midi {}");
+ printer.newline ()
+ printer.dump ("}");
+ printer.newline ()
+
+