Пример #1
0
 def assignLyrics(self, name, node, verse = 0):
     l = LyricMode(self.doc)
     if verse:
         name = name + nums(verse)
         Text(l, '\\set stanza = "%d."\n' % verse)
     Comment(l, ' ' + _("Lyrics follow here."))
     Newline(l)
     self.assignGeneric(name, node, l)
Пример #2
0
 def buildStaff(self, name, clef, octave, pdoc, numVoices):
     """
     Build a staff with the given number of voices and name.
     """
     staff = self.newStaff(pdoc, name)
     c = Seqr(staff)
     if clef:
         Clef(c, clef)
     if numVoices == 1:
         self.assignMusic(name, c, octave)
     else:
         c = Sim(c)
         for i in range(1, numVoices):
             self.assignMusic(name + nums(i), c, octave)
             VoiceSeparator(c)
         self.assignMusic(name + nums(numVoices), c, octave)
     return staff
Пример #3
0
    def build(self):
        p = DrumStaff(self.doc)
        s = Simr(p, multiline = True)

        if self.drumVoices.value() > 1:
            for i in range(1, self.drumVoices.value()+1):
                q = Seq(DrumVoice(s))
                Text(q, '\\voice%s' % nums(i))
                self.assignDrums('drum%s' % nums(i), q)
        else:
            self.assignDrums('drum', s)
        self.addPart(p)
        self.setInstrumentNames(p, *self.instrumentNames)
        i = self.drumStyle.currentItem()
        if i > 0:
            v = ('drums', 'timbales', 'congas', 'bongos', 'percussion')[i]
            p.getWith()['drumStyleTable'] = Scheme(self.doc, '%s-style' % v)
            v = (5, 2, 2, 2, 1)[i]
            Text(p.getWith(), "\\override StaffSymbol #'line-count = #%i\n" % v)
        if self.drumStems.isChecked():
            Text(p.getWith(), "\\override Stem #'stencil = ##f\n")
            Text(p.getWith(), "\\override Stem #'length = #3  %% %s"
                % _("keep some distance."))
Пример #4
0
    def build(self):
        # normalize voicing
        staffs = unicode(self.voicing.currentText()).upper()
        # remove unwanted characters
        staffs = re.sub(r'[^SATB-]+', '', staffs)
        # remove double hyphens, and from begin and end
        staffs = re.sub('-+', '-', staffs).strip('-')
        splitStaffs = staffs.split('-')
        p = ChoirStaff(self.doc)
        choir = Sim(p, multiline = True)
        self.addPart(p)
        # print main instrumentName if there are more choirs, and we
        # have more than one staff.
        if self._instr and '-' in staffs and self.num:
            self.setInstrumentNames(p, _("Choir|Ch."), "Coro|C.")
            Text(p.getWith(), '\\consists "Instrument_name_engraver"\n')

        count = dict.fromkeys('SATB', 0)  # dict with count of parts.
        toGo = len(splitStaffs)
        maxLen = max(map(len, splitStaffs))
        lyr, staffNames = [], []
        for staff in splitStaffs:
            toGo -= 1
            # sort the letters in order SATB
            staff = ''.join(i * staff.count(i) for i in 'SATB')
            # Create the staff for the voices
            s = self.newStaff(choir)
            # Build lists of the voices and their instrument names
            instrNames, voices = [], []
            for part in staff:
                if staffs.count(part) > 1:
                    count[part] += 1
                name, octave, (translated, italian) = self.partInfo[part]
                instrNames.append(
                    self.buildInstrumentNames(translated, italian, count[part]))
                voices.append((name, count[part], octave))
            if len(staff) == 1:
                # There is only one voice in the staff. Just set the instrument
                # name directly in the staff.
                s.instrName(*instrNames[0])
                # if *all* staves have only one voice, addlyrics is used.
                # In that case, don't remove the braces.
                mus = maxLen == 1 and Seq(s) or Seqr(s)
            else:
                # There are more instrument names for the staff, stack them in
                # a markup column.
                def mkup(names):
                    # return a markup object with names stacked vertically
                    if max(names):
                        n = Markup(self.doc)
                        # from 2.11.57 and above LilyPond uses center-column
                        from lilykde.version import version
                        if version and version >= (2, 11, 57):
                            m = MarkupEncl(n, 'center-column', multiline=True)
                        else:
                            m = MarkupEncl(n, 'center-align', multiline=True)
                        for i in names:
                            QuotedString(m, i)
                        return n
                s.instrName(*map(mkup, zip(*instrNames)))
                mus = Simr(s, multiline = True)
            # Set the clef for this staff:
            if 'B' in staff:
                Clef(mus, 'bass')
            elif 'T' in staff:
                Clef(mus, 'treble_8')

            stanzas = self.stanzas.value()
            stanzas = stanzas == 1 and [0] or range(1, stanzas + 1)

            # Add the voices
            if len(staff) == 1:
                name, num, octave = voices[0]
                mname = name + (num and nums(num) or '')
                if self.lyrEachDiff.isChecked():
                    lyrName = mname + 'Verse'
                else:
                    lyrName = 'verse'
                if maxLen == 1:
                    # if all staves have only one voice, use \addlyrics...
                    self.assignMusic(mname, mus, octave)
                    if not (self.lyrAllSame.isChecked() and not toGo):
                        for verse in stanzas:
                            Newline(s)
                            lyr.append((lyrName, AddLyrics(s), verse))
                else:
                    # otherwise create explicit Voice and Lyrics contexts.
                    vname = name + str(num or '')
                    v = Seqr(Voice(mus, vname))
                    self.assignMusic(mname, v, octave)
                    if not (self.lyrAllSame.isChecked() and not toGo):
                        for verse in stanzas:
                            lyr.append(
                                (lyrName, LyricsTo(Lyrics(choir), vname), verse))

                if self.ambitus.isChecked():
                    Text(s.getWith(), '\\consists "Ambitus_engraver"\n')
            else:
                # There is more than one voice in the staff.
                # Determine their order (\voiceOne, \voiceTwo etc.)
                if len(staff) == 2:
                    order = 1, 2
                elif staff in ('SSA', 'TTB'):
                    order = 1, 3, 2
                elif staff in ('SAA', 'TBB'):
                    order = 1, 2, 4
                elif staff in ('SSAA', 'TTBB'):
                    order = 1, 3, 2, 4
                else:
                    order = range(1, len(staff) + 1)
                # What name would the staff get if we need to refer to it?
                staffName, snum = staff, 1
                # if a name (like 's' or 'sa') is already in use in this part,
                # just add a number ('ss2' or 'sa2', etc.)
                while staffName in staffNames:
                    snum += 1
                    staffName = staff + str(snum)
                staffNames.append(staffName)
                # We want the staff name (actually context-id) in lower case.
                staffName = staffName.lower()
                # Create the voices and their lyrics.
                for (name, num, octave), vnum in zip(voices, order):
                    mname = name + (num and nums(num) or '')
                    vname = name + str(num or '')
                    v = Voice(mus, vname)
                    # Add ambitus to voice, move to the right if necessary
                    if self.ambitus.isChecked():
                        Text(v.getWith(), '\\consists "Ambitus_engraver"\n')
                        if vnum > 1:
                            Text(v.getWith(),
                                "\\override Ambitus #'X-offset = #%s\n" %
                                ((vnum - 1) * 2.0))
                    v = Seqr(v)
                    Text(v, '\\voice' + nums(vnum))
                    self.assignMusic(mname, v, octave)
                    if self.lyrAllSame.isChecked() and toGo and vnum == 1:
                        lyrName = 'verse'
                        above = False
                    elif self.lyrEachSame.isChecked():
                        lyrName = 'verse'
                        above = vnum & 1
                    elif self.lyrEachDiff.isChecked():
                        lyrName = mname + 'Verse'
                        above = vnum & 1
                    else:
                        continue
                    # Create the lyrics. If they should be above the staff,
                    # give the staff a suitable name, and use alignAboveContext
                    # to align the Lyrics above the staff.
                    if above:
                        s.cid = staffName
                    for verse in stanzas:
                        l = Lyrics(choir)
                        if above:
                            l.getWith()['alignAboveContext'] = staffName
                        lyr.append((lyrName, LyricsTo(l, vname), verse))

        # Assign the lyrics, so their definitions come after the note defs.
        for name, node, verse in lyr:
            self.assignLyrics(name, node, verse)