def test_scoretools_Inspection_get_effective_staff_02():
    r'''Staff changes work on middle notes of a staff.
    '''

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.is_simultaneous = True
    staff_group[0].name = 'RH'
    staff_group[1].name = 'LH'
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange(staff_group[0])
    abjad.attach(staff_change, staff_group[0][2])

    assert format(staff_group) == abjad.String.normalize(r'''
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                d'8
                \change Staff = RH
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        ''')

    assert abjad.inspect(staff_group).is_well_formed()
    assert abjad.inspect(
        staff_group[0][0]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[0][1]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[0][2]).get_effective_staff() is staff_group[0]
    assert abjad.inspect(
        staff_group[0][3]).get_effective_staff() is staff_group[0]
    assert abjad.inspect(
        staff_group[1][0]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][1]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][2]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][3]).get_effective_staff() is staff_group[1]
def test_Inspection_effective_staff_02():
    """
    Staff changes work on middle notes of a staff.
    """

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = "PianoStaff"
    staff_group.simultaneous = True
    staff_group[0].name = "RH"
    staff_group[1].name = "LH"
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange(staff_group[0])
    abjad.attach(staff_change, staff_group[0][2])

    assert format(staff_group) == abjad.String.normalize(
        r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                d'8
                \change Staff = RH
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """
    )

    assert abjad.inspect(staff_group).wellformed()
    assert abjad.inspect(staff_group[0][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][2]).effective_staff() is staff_group[0]
    assert abjad.inspect(staff_group[0][3]).effective_staff() is staff_group[0]
    assert abjad.inspect(staff_group[1][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][2]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][3]).effective_staff() is staff_group[1]
예제 #3
0
def test_get_staff_04():
    """
    Redudant staff changes are allowed.
    """

    staff_group = abjad.StaffGroup(
        [abjad.Staff("c'8 d'8 e'8 f'8"),
         abjad.Staff("c'8 d'8 e'8 f'8")])
    staff_group.lilypond_type = "PianoStaff"
    staff_group.simultaneous = True
    staff_group[0].name = "RH"
    staff_group[1].name = "LH"
    staff_change = abjad.StaffChange("LH")
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange("LH")
    abjad.attach(staff_change, staff_group[0][1])

    assert abjad.lilypond(staff_group) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                \change Staff = LH
                d'8
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """)

    assert abjad.wf.wellformed(staff_group)
    assert abjad.get.effective_staff(staff_group[0][0]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][1]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][2]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][3]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][0]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][1]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][2]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][3]) is staff_group[1]
def test_Inspection_effective_staff_04():
    """
    Redudant staff changes are allowed.
    """

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.is_simultaneous = True
    staff_group[0].name = 'RH'
    staff_group[1].name = 'LH'
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][1])

    assert format(staff_group) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                \change Staff = LH
                d'8
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """)

    assert abjad.inspect(staff_group).wellformed()
    assert abjad.inspect(staff_group[0][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][2]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][3]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][2]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][3]).effective_staff() is staff_group[1]
예제 #5
0
def post_process_voice_one(voice_one, score):
    print("post processing voice one")

    voice_one[-2] = abjad.Skip((3, 4))
    voice_one[-1] = abjad.Skip((3, 4))

    # change staff
    voice_one = score['RH_Voice_One']
    rh_staff = score['Piano_Staff'][0]
    lh_staff = score['Piano_Staff'][1]

    staff_change1 = abjad.StaffChange(lh_staff)
    staff_change2 = abjad.StaffChange(rh_staff)
    abjad.attach(staff_change1, voice_one[6][0])

    # change clef
    clef1 = abjad.Clef("bass")
    abjad.attach(clef1, voice_one[8])

    # tempos
    lento = abjad.MetronomeMark(None, None, "Lento")
    quasi_statico = abjad.MetronomeMark(None, None, "Quasi Statico")
    # metronome mark I
    abjad.attach(lento, voice_one[0])
    # metronome mark II
    abjad.attach(quasi_statico, voice_one[8])
    # metronome mark III
    abjad.attach(lento, voice_one[15][0])

    # metronome mark IV
    abjad.attach(abjad.MetronomeMark(None, None, "subito Quasi Statico"),
                 voice_one[18])
    # metronome mark V
    abjad.attach(lento, voice_one[22])
    # metronome mark VI
    abjad.attach(abjad.MetronomeMark(None, None, "più mosso"), voice_one[25])

    # rehearsal mark
    markI = abjad.RehearsalMark(number=3)
    abjad.attach(markI, voice_one[0])
    scheme = abjad.Scheme("format-mark-box-alphabet")
    abjad.setting(score).markFormatter = scheme
    return voice_one
예제 #6
0
def test_get_staff_03():
    """
    Staff changes work on the last note of a staff.
    """

    staff_group = abjad.StaffGroup(
        [abjad.Staff("c'8 d'8 e'8 f'8"),
         abjad.Staff("c'8 d'8 e'8 f'8")])
    staff_group.lilypond_type = "PianoStaff"
    staff_group.simultaneous = True
    staff_group[0].name = "RH"
    staff_group[1].name = "LH"
    staff_change = abjad.StaffChange("LH")
    abjad.attach(staff_change, staff_group[0][-1])

    assert abjad.lilypond(staff_group) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                c'8
                d'8
                e'8
                \change Staff = LH
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """)

    assert abjad.wf.wellformed(staff_group)
def test_Inspection_effective_staff_03():
    """
    Staff changes work on the last note of a staff.
    """

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.is_simultaneous = True
    staff_group[0].name = 'RH'
    staff_group[1].name = 'LH'
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][-1])

    assert format(staff_group) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                c'8
                d'8
                e'8
                \change Staff = LH
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """)

    assert abjad.inspect(staff_group).wellformed()
def post_process_voice_four(voice_four, score):
    print("post processing voice four")
    # delete and change durations
    voice_four[-2].written_duration = (1, 4)
    del voice_four[-1]
    voice_four[-1].written_duration = (3, 8)
    # abjad.mutate(voice_four[17]).transpose(-12)

    # numbered leaves
    selection = abjad.select(voice_four).leaves()
    for i, leaf in enumerate(selection):
        # abjad.attach(abjad.Markup(i), leaf)
        pass
        
    # change staff
    rh_staff = score['Piano_Staff'][0]
    lh_staff = score['Piano_Staff'][1]
    voice_four = score['LH_Voice_Four']

    staff_change1 = abjad.StaffChange(lh_staff)
    staff_change2 = abjad.StaffChange(rh_staff)
    abjad.attach(staff_change2, voice_four[-5])
    abjad.attach(staff_change1, voice_four[-2])
    
    voice_four[-3].written_pitch = "f''''"
    voice_four[-4].written_pitch = "g''"
    voice_four[14].written_pitch = "c'''"
    
    

    abjad.attach(abjad.Fermata(), voice_four[-1])

    clef3 = abjad.Clef("treble^8")
    clef3_range = abjad.pitch.PitchRange("[C6, +inf]")
    clef2 = abjad.Clef("treble")
    clef2_range = abjad.pitch.PitchRange("[D4, +inf]")
    clef1 = abjad.Clef("bass")
    clef1_range = abjad.pitch.PitchRange("[C1, C#4]")
    selection = abjad.select(voice_four).leaves()
    for i, leaf in enumerate(selection):
        # test3 = leaf in clef3_range
        test2 = leaf in clef2_range
        test1 = leaf in clef1_range
        test_note = not isinstance(leaf, abjad.Rest)
        # if test_note is True and test3 is True:
            # abjad.attach(clef3, voice_four[i])
        if test_note is True and test2 is True:
            abjad.attach(clef2, voice_four[i])
        if test_note is True and test1 is True:
            abjad.attach(clef1, voice_four[i])

    abjad.Accidental.respell_with_sharps(voice_four[8:9])
    abjad.Accidental.respell_with_sharps(voice_four[19:22])
    
    
    # REGISTER TRANSPOSITION
    abjad.mutate(voice_four).transpose(-12)
    #[:-7]

    # slurs
    start_slur = abjad.StartSlur()
    start_slur_down = abjad.StartSlur(direction=abjad.Down)
    stop_slur = abjad.StopSlur()

    abjad.attach(start_slur, voice_four[6])
    abjad.attach(stop_slur, voice_four[8])

    abjad.attach(start_slur, voice_four[12])
    abjad.attach(stop_slur, voice_four[15])

    abjad.attach(start_slur_down, voice_four[18])
    abjad.attach(stop_slur, voice_four[21])

    abjad.attach(start_slur_down, voice_four[-4])
    abjad.attach(stop_slur, voice_four[-3])

    # metronome mark IV
    abjad.attach(
        abjad.MetronomeMark(None, None, "meno mosso"), voice_four[-4])

    return voice_four
예제 #9
0
for staff in abjad.select(score['Staff Group']).components(abjad.Staff):
    abjad.override(staff).text_script.staff_padding = 4

for voice in abjad.iterate(score['Staff Group']).components(abjad.Voice):
    voice.consists_commands.append('Horizontal_bracket_engraver')
    abjad.override(voice).horizontal_bracket.staff_padding = 3
    abjad.override(voice).text_script.staff_padding = 2
hexachord = abjad.select(score['Staff 1']).leaves(pitched=True)[3:9]
abjad.horizontal_bracket(hexachord[:])
staff = abjad.select(score['Staff 1']).components(abjad.Staff)
print(hexachord)
abjad.label([hexachord]).with_set_classes()

for leaf in abjad.iterate(score['Staff Group']).leaves(pitched=True):
    staff_change = abjad.StaffChange(score['Staff 2'])
    staff_return = abjad.StaffChange(score['Staff 1'])
    if abjad.NamedPitch(leaf.written_pitch) < 0:
        abjad.attach(staff_change, leaf)
        abjad.override(leaf).stem.direction = abjad.Up
    elif abjad.NamedPitch(leaf.written_pitch) > 0:
        abjad.attach(staff_return, leaf)
        abjad.override(leaf).stem.direction = abjad.Down
    else:
        continue

on = abjad.LilyPondLiteral(r'\ottava #-1')
off = abjad.LilyPondLiteral(r'\ottava #0')
abjad.attach(on, abjad.select(score).leaves(pitched=True)[0])
abjad.attach(off, abjad.select(score).leaves(pitched=True)[4])
예제 #10
0
    def __illustrate__(self):
        r"""
        Illustrates pitch range.

        ..  container:: example

            >>> pitch_range = abjad.PitchRange('[C3, C7]')
            >>> abjad.show(pitch_range) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = pitch_range.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Score])
                \new Score
                \with
                {
                    \override BarLine.stencil = ##f
                    \override Glissando.thickness = #2
                    \override SpanBar.stencil = ##f
                    \override TimeSignature.stencil = ##f
                }
                <<
                    \new PianoStaff
                    <<
                        \context Staff = "Treble Staff"
                        {
                            \clef "treble"
                            s1 * 1/4
                            s1 * 1/4
                        }
                        \context Staff = "Bass Staff"
                        {
                            \clef "bass"
                            c1 * 1/4
                            \glissando
                            \change Staff = "Treble Staff"
                            c''''1 * 1/4
                        }
                    >>
                >>

        Returns LilyPond file.
        """
        import abjad
        start_pitch_clef = abjad.Clef.from_selection(self.start_pitch)
        stop_pitch_clef = abjad.Clef.from_selection(self.stop_pitch)
        start_note = abjad.Note(self.start_pitch, 1)
        stop_note = abjad.Note(self.stop_pitch, 1)
        glissando = abjad.Glissando()
        if start_pitch_clef == stop_pitch_clef:
            if start_pitch_clef == abjad.Clef('bass'):
                bass_staff = abjad.Staff()
                abjad.attach(abjad.Clef('bass'), bass_staff)
                bass_staff.extend([start_note, stop_note])
                bass_leaves = abjad.select(bass_staff).leaves()
                abjad.attach(glissando, bass_leaves)
                score = abjad.Score([bass_staff])
            else:
                treble_staff = abjad.Staff()
                abjad.attach(abjad.Clef('treble'), treble_staff)
                treble_staff.extend([start_note, stop_note])
                treble_leaves = abjad.select(treble_staff).leaves()
                abjad.attach(glissando, treble_leaves)
                score = abjad.Score([treble_staff])
        else:
            result = abjad.Score.make_piano_score()
            score, treble_staff, bass_staff = result
            bass_staff.extend([start_note, stop_note])
            treble_staff.extend(abjad.Skip(1) * 2)
            bass_leaves = abjad.select(bass_staff).leaves()
            abjad.attach(glissando, bass_leaves)
            abjad.attach(abjad.StaffChange(treble_staff), bass_staff[1])
            abjad.attach(abjad.Clef('treble'), treble_staff[0])
            abjad.attach(abjad.Clef('bass'), bass_staff[0])
        for leaf in abjad.iterate(score).leaves():
            abjad.attach(abjad.Multiplier(1, 4), leaf)
        abjad.override(score).bar_line.stencil = False
        abjad.override(score).span_bar.stencil = False
        abjad.override(score).glissando.thickness = 2
        abjad.override(score).time_signature.stencil = False
        lilypond_file = abjad.LilyPondFile.new(score)
        return lilypond_file
예제 #11
0
selector = abjad.select(measures).leaves()
selector
select = selector.group_by_measure()
for time, measure in zip(time_signatures, measures):
    abjad.mutate(measure).rewrite_meter(
        time,
        maximum_dot_count=2,
    )

score = organi.ScoreTemplate()
score = score()
this = score['Piano_Staff'][0][1]
this.append("c,,4")
abjad.attach(abjad.TimeSignature((3, 4)), this[0])

staff_change = abjad.StaffChange(score['LH_Staff'])
abjad.attach(staff_change, rh_staff[i])
abjad.f(this)

staff_group = abjad.StaffGroup()
staff1 = abjad.Staff("e4 f g f e")
staff2 = abjad.Staff("c4 d e d c")
staff_group.extend([staff1, staff2])
selection = abjad.select(staff_group[1]).leaves().logical_ties(pitched=True)
length = len(selection)
for lo, i in zip(selection, range(length)):
    pass


def _make(music):
    del music[-1]
예제 #12
0
def post_process_voice_four(voice_four, score):
    print("post processing voice four")
    rh_staff = score['Piano_Staff'][0]
    lh_staff = score['Piano_Staff'][1]
    voice_four = score['LH_Voice_Four']

    staff_change1 = abjad.StaffChange(lh_staff)
    staff_change2 = abjad.StaffChange(rh_staff)
    abjad.attach(staff_change2, voice_four[5])

    abjad.attach(staff_change1, voice_four[-5])
    abjad.attach(staff_change2, voice_four[-2])
    abjad.attach(staff_change1, voice_four[-1])

    # REGISTER TRANSPOSITION
    selection_reg = abjad.select(voice_four).leaves()
    register_range = abjad.pitch.PitchRange("[C4, +inf]")
    for leaf in selection_reg:
        test_resgister = leaf in register_range
        if test_resgister is True:
            abjad.mutate(leaf).transpose(-12)

    clef3 = abjad.Clef("treble^8")
    clef3_range = abjad.pitch.PitchRange("[A#6, +inf]")
    clef2 = abjad.Clef("treble")
    clef2_range = abjad.pitch.PitchRange("[D4, G6]")
    clef1 = abjad.Clef("bass")
    clef1_range = abjad.pitch.PitchRange("[C1, C#4]")
    selection = abjad.select(voice_four).leaves()
    for i, leaf in enumerate(selection):
        test3 = leaf in clef3_range
        test2 = leaf in clef2_range
        test1 = leaf in clef1_range
        test_note = not isinstance(leaf, abjad.Rest)

        if test_note is True and test3 is True:
            abjad.attach(clef3, voice_four[i])
        if test_note is True and test2 is True:
            abjad.attach(clef2, voice_four[i])
        if test_note is True and test1 is True:
            abjad.attach(clef1, voice_four[i])

    # slurs
    start_slur = abjad.StartSlur()
    start_slur_down = abjad.StartSlur(direction=abjad.Down)
    stop_slur = abjad.StopSlur()

    abjad.attach(start_slur, voice_four[6])
    abjad.attach(stop_slur, voice_four[9])

    abjad.attach(start_slur, voice_four[12])
    abjad.attach(stop_slur, voice_four[16])

    abjad.attach(start_slur, voice_four[18])
    abjad.attach(stop_slur, voice_four[21])

    abjad.attach(start_slur, voice_four[23])
    abjad.attach(stop_slur, voice_four[27])

    abjad.attach(start_slur, voice_four[-4])
    abjad.attach(stop_slur, voice_four[-2])

    # metronome mark VII
    quasi_statico = abjad.MetronomeMark(None, None, "Quasi Statico")
    abjad.attach(quasi_statico, voice_four[-4])

    # accelerando mark
    accel_text_span = abjad.LilyPondLiteral(
        r'\once \override TextSpanner.bound-details.left.text = "accelerando"'
        + " " + r"\once \override TextSpanner.style = #'dashed-line")
    start_accel = abjad.LilyPondLiteral(r"\startTextSpan")
    abjad.attach(accel_text_span, voice_four[13])
    abjad.attach(start_accel, voice_four[13])
    stop_accel_text_span = abjad.StopTextSpan(command=r"\stopTextSpan")
    abjad.attach(stop_accel_text_span, voice_four[16])

    return voice_four