示例#1
0
def present(eighths, staves, startMeasure = 1):
    pairs = [(n, 8) if n == int(n) else (int(n * 2), 16) for n in eighths]
    durations = [Fraction(*p) for p in pairs]
    directives = [r'\time %s/%s' % (p[0], p[1]) for p in pairs]
    measuresPerLine = sequencetools.group_by_weights(eighths, [10],
        fill = 'less', cyclic = True, overhang = False)
    measuresPerLine = [len(x) for x in measuresPerLine]
    measuresWithBreaks = [
        m - 1 for m in sequencetools.cumulative_sums(measuresPerLine)]
    measuresWithSpacing = [0] + [m + 1 for m in measuresWithBreaks][:-1]
    pageHeight = 300
    systemsPerPage = 2
    systemHeight = pageHeight / systemsPerPage
    staffSep = 60
    curSystem = 1
    breaks = []
    for i, d in enumerate(durations):
        try:
            new = Skip(d.pair)
        except ValueError:
            new = Skip((1, 1))
            new.multiplier = d.pair
        if i in measuresWithSpacing:
                new.formatter.before.append(
                    r'\overrideProperty #"Score.NonMusicalPaperColumn" ')
                new.formatter.before.append("#'line-break-system-details")
                systemOffset = systemHeight * (curSystem % systemsPerPage)
                staffOffsets = '0 -24   -54 -76   -106 -124'
                text = "#'((Y-offset . %s)" % systemOffset
                new.formatter.before.append(text)
                text = '(alignment-offsets . (%s)))' % staffOffsets
                new.formatter.before.append(text)
        if i in measuresWithBreaks:
            if curSystem % systemsPerPage == systemsPerPage - 1:
                new.formatter.right.append(r'\pageBreak')
            else:
                new.formatter.right.append(r'\break')
            curSystem += 1
        breaks.append(new)
    breaks[-1].formatter.right.append(r'\bar "|." ')
    breaksVoice = Voice(breaks)
    breaksVoice.name = 'breaks voice'

    for st in staves:
        voices = instances(st, 'Voice')
        for v in voices:
            before = "#(set-accidental-style 'forget)"
            v.leaves[0].formatter.before.append(before)

    measures_voice = lidercfeny.transforms.make_measures_voice(pairs)
    for i, measure in enumerate(measures_voice):
        measure[0].formatter.left.append(directives[i])
    mm = instances(measures_voice, 'Skip')

    override = r"\set Score.currentBarNumber = #%s" % startMeasure
    instances(st, '_Leaf')[0].formatter.before.append(override)

    barText = r"\once \override Score.BarLine #'color = #red"
    spanBarText = r"\once \override Score.SpanBar #'color = #red"
    for (n, start, stop, description) in sections:
        if startMeasure <= start:
            sectionText = r'^ \markup \fontsize #2 \with-color #red \italic '
            sectionText += '{ %s. %s }' % (n, description)
            try:
                mm[start - startMeasure].formatter.before.extend(
                    [barText, spanBarText])
                instances(mm[start - startMeasure], '_Leaf')[0].formatter.right.append(
                    sectionText)
            except:
                pass

    flute = Staff([staves[0], staves[1]])
    flute.invocation = 'Flute'
    flute.brackets = 'double-angle'
    violin = Staff([staves[2], staves[3]])
    violin.invocation = 'Violin'
    violin.brackets = 'double-angle'
    piano = Staff([staves[4], staves[5]])
    piano.invocation = 'PianoStaff'
    piano.brackets = 'double-angle'

    sc = Score([flute, violin, piano])
    sc['pitches-fl staff'].insert(0, breaksVoice)
    sc['pitches-fl staff'].brackets = 'double-angle'

    ly = Lily([sc])
    layout = '/Users/trevorbaca/Documents/work/lidercfeny/layout-score.ly'
    ly.includes.append(layout)

    return ly
示例#2
0
def visualize(eighths, staves):
    pairs = [(n, 8) if n == int(n) else (int(n * 2), 16) for n in eighths]
    durations = [Fraction(*p) for p in pairs]
    directives = [r'\time %s/%s' % (p[0], p[1]) for p in pairs]
    measuresPerLine = listools.group_by_weights(eighths, [10],
        fill = 'less', cyclic = True, overhang = False)
    measuresPerLine = [len(x) for x in measuresPerLine]
    measuresWithBreaks = [
        m - 1 for m in sequencetools.cumulative_sums(measuresPerLine)]
    measuresWithSpacing = [0] + [m + 1 for m in measuresWithBreaks][:-1]
    pageHeight = 240
    systemsPerPage = 2
    systemHeight = pageHeight / systemsPerPage
    staffSep = 10
    curSystem = 1
    breaks = []
    for i, d in enumerate(durations):
        new = skip.Skip(d.n, d.d)
        if i in measuresWithSpacing:
                new.before.append(
                    r'\overrideProperty #"Score.NonMusicalPaperColumn" ')
                new.before.append("#'line-break-system-details")
                systemOffset = systemHeight * (curSystem % systemsPerPage)
                #staffOffsets = ' '.join([
                #   str(-staffSep * n) for n in range(len(staves))])
                staffOffsets = '0 -15   -39 -57   -81 -96'
                text = "#'((Y-offset . %s)" % systemOffset
                new.before.append(text)
                text = '(alignment-offsets . (%s)))' % staffOffsets
                new.before.append(text)
        if i in measuresWithBreaks:
            if curSystem % systemsPerPage == systemsPerPage - 1:
                new.right.append(r'\pageBreak')
            else:
                new.right.append(r'\break')
            curSystem += 1
        breaks.append(new)
    breaks[-1].right.append(r'\bar "|." ')
    breaksVoice = voice.Voice(breaks, name = 'breaks voice')

    mm = [measure.Measure([skip.Skip(*p)], p) for p in pairs]
    for i, m in enumerate(mm):
        m.music[0].left.append(directives[i])
    measures_voice = voice.Voice(mm, name = 'measures voice')
    mm = instances(measures_voice, 'Skip')

    '''
    barText = r"\once \override Score.BarLine #'color = #red"
    spanBarText = r"\once \override Score.SpanBar #'color = #red"

    for (n, start, stop, description) in sections:
        sectionText = r'^ \markup \fontsize #2 \with-color #red \italic '
        sectionText += '{ %s. %s }' % (n, description)
        try:
            mm[start - 1].before.extend([barText, spanBarText])
            instances(mm[start - 1], '_Leaf')[0].right.append(sectionText)
        except:
            pass
    '''

    flute  = staff.GrandStaff([staves[0], staves[1]], name = 'flute group')
    violin = staff.GrandStaff([staves[2], staves[3]], name = 'violin group')
    piano  = staff.PianoStaff([staves[4], staves[5]], name = 'piano group')

    flute.during.extend([
        r'instrumentName = \markup { \fontsize #3 \hcenter-in #18 "Flauta" }',
        r'shortInstrumentName = \markup { \fontsize #3 \hcenter-in #8 "Fl." }'])
    violin.during.extend([
        r'instrumentName = \markup { \fontsize #3 \hcenter-in #18 "Violino" }',
        r'shortInstrumentName = \markup { \fontsize #3 \hcenter-in #8 "Vn." }'])
    piano.during.extend([
        r'instrumentName = \markup { \fontsize #3 \hcenter-in #18 "Pianoforte" }',
        r'shortInstrumentName = \markup { \fontsize #3 \hcenter-in #8 "Pf." }'])

    sc = score.Score([flute, violin, piano], name = 'score')
    sc.instances('Staff')[0].music.insert(0, measures_voice)
    sc.instances('Staff')[0].music.insert(0, breaksVoice)

    ly = lily.Lily([sc], name = 'file')
    ly.includes.append(
        '/Users/trevorbaca/Documents/work/lidercfeny/layout-rhythm.ly')

    return ly