def test_making_chord(self):
        durations = [
            Tune.Duration.SIXTEENTH, Tune.Duration.EIGHTH,
            Tune.Duration.QUARTER, Tune.Duration.HALF, Tune.Duration.WHOLE
        ]

        testTune = Tune.Tune()
        chords = []
        # make a chord for all possible durations
        for duration in durations:
            pitch1 = Tune.Pitch()
            pitch1.letter = 'a'
            pitch1.accidental = Tune.Accidental.FLAT
            pitch1.octave = 5

            pitch2 = Tune.Pitch()
            pitch2.letter = 'd'
            pitch2.accidental = Tune.Accidental.SHARP
            pitch2.octave = 6

            pitch3 = Tune.Pitch()
            pitch3.letter = 'g'
            pitch3.octave = 3

            pitches = [pitch1, pitch2, pitch3]

            # make a chord in impromptu backend
            chord = Tune.Chord()
            chord.setPitch(pitches)
            chord.duration = duration

            chords.append(chord)

        testTune.setEventsList(chords)

        # test calling tuneToNotes and make sure a lilypond file can be created with no error
        notesA = tuneToNotes(testTune)
        staff = abjad.Staff()
        for measure in notesA:
            m = abjad.Measure(abjad.TimeSignature(tune.getTimeSignature()),
                              measure)
            d = m._preprolated_duration
            if d == abjad.TimeSignature(tune.getTimeSignature()).duration:
                staff.append(m)
        abjad.lilypondfiletools.make_basic_lilypond_file(staff)
def test_TimeSignature_with_power_of_two_denominator_02():
    """
    Make n/14 time_signatures into n/8 time_signatures, where possible.
    """

    assert abjad.TimeSignature((1, 14)).with_power_of_two_denominator() == (
        1,
        14,
    )
    assert abjad.TimeSignature((2, 14)).with_power_of_two_denominator() == (
        2,
        14,
    )
    assert abjad.TimeSignature((3, 14)).with_power_of_two_denominator() == (
        3,
        14,
    )
    assert abjad.TimeSignature((4, 14)).with_power_of_two_denominator() == (
        4,
        14,
    )
    assert abjad.TimeSignature((5, 14)).with_power_of_two_denominator() == (
        5,
        14,
    )
    assert abjad.TimeSignature((6, 14)).with_power_of_two_denominator() == (
        6,
        14,
    )
    assert abjad.TimeSignature((7, 14)).with_power_of_two_denominator() == (
        4,
        8,
    )
Beispiel #3
0
def test_quantizationtools_MeasurewiseQSchema___init___02():

    schema = quantizationtools.MeasurewiseQSchema()

    assert len(schema.items) == 0
    assert schema.search_tree == quantizationtools.UnweightedSearchTree()
    assert schema.tempo == abjad.MetronomeMark((1, 4), 60)
    assert schema.time_signature == abjad.TimeSignature((4, 4))
    assert schema.use_full_measure == False
def test_scoretools_Measure__duration_to_time_signature_03():
    r'''Make time signature literally from time_signature.
    '''

    time_signature = abjad.Measure._duration_to_time_signature(
        abjad.Duration(3, 2),
        )

    assert time_signature == abjad.TimeSignature((3, 2))
Beispiel #5
0
def test_MeasurewiseQSchema___init___02():

    schema = abjadext.nauert.MeasurewiseQSchema()

    assert len(schema.items) == 0
    assert schema.search_tree == abjadext.nauert.UnweightedSearchTree()
    assert schema.tempo == abjad.MetronomeMark((1, 4), 60)
    assert schema.time_signature == abjad.TimeSignature((4, 4))
    assert schema.use_full_measure is False
Beispiel #6
0
def test_enforce_time_signature_05():
    staff = abjad.Staff(r"c'1 d'1")
    time_signatures = [
        abjad.TimeSignature((3, 4)),
        abjad.TimeSignature((5, 4)),
    ]
    auxjad.mutate.enforce_time_signature(staff, time_signatures)
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 3/4
            c'2.
            ~
            \time 5/4
            c'4
            d'1
        }
        """)
Beispiel #7
0
 def __init__(
     self,
     time_signature=None,
     components=None,
     identifier='% measure',
     implicit_scaling=False,
     ):
     import abjad
     # set time signature adjustment before contents initialization
     self._automatically_adjust_time_signature = False
     time_signature = time_signature or abjad.TimeSignature((4, 4))
     time_signature = abjad.TimeSignature(time_signature)
     self.implicit_scaling = bool(implicit_scaling)
     Container.__init__(self, components, identifier=identifier)
     self._always_format_time_signature = False
     self._measure_number = None
     time_signature = abjad.TimeSignature(time_signature)
     abjad.attach(time_signature, self)
Beispiel #8
0
def test_extract_time_signatures_07():
    container = abjad.Container(r"\time 4/4 c'1 d'1 e'1 f'1")
    time_signatures = auxjad.inspect(container).extract_time_signatures(
        do_not_use_none=True,
        implicit_common_time=False,
    )
    assert time_signatures == [
        abjad.TimeSignature((4, 4)),
        abjad.TimeSignature((4, 4)),
        abjad.TimeSignature((4, 4)),
        abjad.TimeSignature((4, 4)),
    ]
    container = abjad.Container(r"c'1 d'1 e'1 f'1")
    with pytest.raises(ValueError):
        time_signatures = auxjad.inspect(container).extract_time_signatures(
            do_not_use_none=True,
            implicit_common_time=False,
        )
    def setUp(self):
        stages = (0,)
        instrument = guitar
        rhythm_makers = [abjad.rhythmmakertools.NoteRhythmMaker()]
        time_signatures = [
            [abjad.TimeSignature((4, 4)), abjad.TimeSignature((4, 4))]
        ]
        music_maker = MusicMaker(
            stages=stages,
            instrument=instrument,
            name='test',
            rhythm_makers=rhythm_makers,
            time_signatures=time_signatures)

        fret_combinations = [
            FretCombination(
                instrument=guitar,
                fret_placements=[
                    FretPlacement(string=1, fret=0, harmonic=False),
                    FretPlacement(string=2, fret=0, harmonic=False),
                    FretPlacement(string=3, fret=0, harmonic=False),
                    FretPlacement(string=4, fret=0, harmonic=False),
                    FretPlacement(string=5, fret=0, harmonic=False),
                    FretPlacement(string=6, fret=0, harmonic=False),
                ]
            ),
            FretCombination(
                instrument=guitar,
                fret_placements=[
                    FretPlacement(string=1, fret=12, harmonic=True),
                    FretPlacement(string=2, fret=12, harmonic=True),
                    FretPlacement(string=3, fret=12, harmonic=True),
                    FretPlacement(string=4, fret=12, harmonic=True),
                    FretPlacement(string=5, fret=12, harmonic=True),
                    FretPlacement(string=6, fret=12, harmonic=True),
                ]
            )
        ]
        fret_combination_patterns = [[0, 1]]
        self.handler = GuitarFrettingHandler(
            music_maker,
            fret_combinations,
            fret_combination_patterns
        )
Beispiel #10
0
def make_mozart_score():
    """
    Makes Mozart score.
    """
    score_template = abjad.TwoStaffPianoScoreTemplate()
    score = score_template()
    # select the measures to use
    choices = abjad.demos.mozart.choose_mozart_measures()
    # create and populate the volta containers
    treble_volta = abjad.Container()
    bass_volta = abjad.Container()
    for choice in choices[:7]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_volta.append(treble)
        bass_volta.append(bass)
    # abjad.attach indicators to the volta containers
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, treble_volta)
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, bass_volta)
    # append the volta containers to our staves
    score["RH_Voice"].append(treble_volta)
    score["LH_Voice"].append(bass_volta)
    # create and populate the alternative ending containers
    treble_alternative = abjad.Container()
    bass_alternative = abjad.Container()
    for choice in choices[7:9]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_alternative.append(treble)
        bass_alternative.append(bass)
    # abjad.attach indicators to the alternative containers
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, treble_alternative)
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, bass_alternative)
    # append the alternative containers to our staves
    score["RH_Voice"].append(treble_alternative)
    score["LH_Voice"].append(bass_alternative)
    # create the remaining measures
    for choice in choices[9:]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        score["RH_Voice"].append(treble)
        score["LH_Voice"].append(bass)
    # abjad.attach indicators
    time_signature = abjad.TimeSignature((3, 8))
    leaf = abjad.inspect(score["RH_Staff"]).leaf(0)
    abjad.attach(time_signature, leaf)
    bar_line = abjad.BarLine("|.")
    leaf = abjad.inspect(score["RH_Staff"]).leaf(-1)
    abjad.attach(bar_line, leaf)
    # remove the default piano instrument and add a custom one:
    abjad.detach(abjad.Instrument, score["Piano_Staff"])
    klavier = abjad.Piano(name="Katzenklavier", short_name="kk.")
    leaf = abjad.inspect(score["Piano_Staff"]).leaf(0)
    abjad.attach(klavier, leaf)
    return score
def test_MeasurewiseQSchema___getitem___01():

    schema = abjadext.nauert.MeasurewiseQSchema()

    assert (schema[0] == schema[1] == schema[2] == {
        "search_tree": abjadext.nauert.UnweightedSearchTree(),
        "tempo": abjad.MetronomeMark((1, 4), 60),
        "time_signature": abjad.TimeSignature((4, 4)),
        "use_full_measure": False,
    })
Beispiel #12
0
def test_indicatortools_TimeSignature_with_power_of_two_denominator_04():
    r'''Make n/24 time_signatures into n/8 time_signatures, where possible.
    '''

    assert abjad.TimeSignature((1, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (1, 24)
    assert abjad.TimeSignature((2, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (2, 24)
    assert abjad.TimeSignature((3, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (1, 8)
    assert abjad.TimeSignature((4, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (4, 24)
    assert abjad.TimeSignature((5, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (5, 24)
    assert abjad.TimeSignature((6, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (2, 8)
    assert abjad.TimeSignature((7, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (7, 24)
    assert abjad.TimeSignature((8, 24)).with_power_of_two_denominator(abjad.Multiplier(99)) == (8, 24)
Beispiel #13
0
def test_indicatortools_TimeSignature_with_power_of_two_denominator_03():
    r'''Make n/24 time_signatures into n/16 time_signatures, where possible.
    '''

    assert abjad.TimeSignature((1, 24)).with_power_of_two_denominator() == (1, 24)
    assert abjad.TimeSignature((2, 24)).with_power_of_two_denominator() == (2, 24)
    assert abjad.TimeSignature((3, 24)).with_power_of_two_denominator() == (2, 16)
    assert abjad.TimeSignature((4, 24)).with_power_of_two_denominator() == (4, 24)
    assert abjad.TimeSignature((5, 24)).with_power_of_two_denominator() == (5, 24)
    assert abjad.TimeSignature((6, 24)).with_power_of_two_denominator() == (4, 16)
    assert abjad.TimeSignature((7, 24)).with_power_of_two_denominator() == (7, 24)
    assert abjad.TimeSignature((8, 24)).with_power_of_two_denominator() == (8, 24)
def test_time_signature_list_04():
    container = abjad.Container(r"\time 3/4 c'2. d'2. \time 3/4 e'2. f'2.")
    time_signatures = auxjad.get.time_signature_list(container)
    assert time_signatures == [
        abjad.TimeSignature((3, 4)),
        None,
        abjad.TimeSignature((3, 4)),
        None,
    ]
    time_signatures = auxjad.get.time_signature_list(
        container,
        omit_repeated=True,
    )
    assert time_signatures == [
        abjad.TimeSignature((3, 4)),
        None,
        None,
        None,
    ]
Beispiel #15
0
def test_enforce_time_signature_15():
    staff = abjad.Staff(r"\time 3/4 d'8. e'16 ~ e'2 ~ e'4.. c'4 d'16")
    auxjad.mutate.enforce_time_signature(staff, abjad.TimeSignature((3, 4)))
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 3/4
            d'8.
            e'16
            ~
            e'2
            ~
            e'4..
            c'16
            ~
            c'8.
            d'16
        }
        """)
    staff = abjad.Staff(r"\time 3/4 d'8. e'16 ~ e'2 ~ e'4.. c'4 d'16")
    auxjad.mutate.enforce_time_signature(
        staff,
        abjad.TimeSignature((3, 4)),
        maximum_dot_count=1,
    )
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 3/4
            d'8.
            e'16
            ~
            e'2
            ~
            e'4
            ~
            e'8.
            c'16
            ~
            c'8.
            d'16
        }
        """)
Beispiel #16
0
def test_enforce_time_signature_13():
    staff = abjad.Staff(r"c'1 ~ c'4 r8 d'4. e'4")
    time_signatures = [
        abjad.TimeSignature((5, 4)),
        abjad.TimeSignature((3, 4)),
    ]
    auxjad.mutate.enforce_time_signature(staff, time_signatures)
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 5/4
            c'2.
            ~
            c'2
            \time 3/4
            r8
            d'4.
            e'4
        }
        """)
    staff = abjad.Staff(r"c'1 ~ c'4 r8 d'4. e'4")
    time_signatures = [
        abjad.TimeSignature((5, 4)),
        abjad.TimeSignature((3, 4)),
    ]
    auxjad.mutate.enforce_time_signature(
        staff,
        time_signatures,
        disable_rewrite_meter=True,
    )
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 5/4
            c'1
            ~
            c'4
            \time 3/4
            r8
            d'4.
            e'4
        }
        """)
def test_quantizationtools_MeasurewiseQSchema___getitem___01():

    schema = quantizationtools.MeasurewiseQSchema()

    assert schema[0] == schema[1] == schema[2] == {
        'search_tree': quantizationtools.UnweightedSearchTree(),
        'tempo': abjad.MetronomeMark((1, 4), 60),
        'time_signature': abjad.TimeSignature((4, 4)),
        'use_full_measure': False,
    }
def test_metertools_Meter___iter___01():

    bh = abjad.Meter(abjad.TimeSignature((3, 8)))

    result = [x for x in bh]

    assert result == [(abjad.Offset(0, 1), abjad.Offset(1, 8)),
                      (abjad.Offset(1, 8), abjad.Offset(1, 4)),
                      (abjad.Offset(1, 4), abjad.Offset(3, 8)),
                      (abjad.Offset(0, 1), abjad.Offset(3, 8))]
 def _rewrite_meter(self, music, time_signature_pairs):
     time_signatures = []
     for item in time_signature_pairs:
         time_signatures.append(abjad.TimeSignature(item))
     abjad.mutate(music[:]).split(time_signature_pairs, cyclic=True)
     selector = abjad.select(music).leaves()
     measures = selector.group_by_measure()
     for time, measure in zip(time_signatures, measures):
         abjad.mutate(measure).rewrite_meter(time)
     return measures
def test_scoretools_Measure__duration_to_time_signature_01():
    r'''Find only feasible denominator in denominators list.
    '''

    time_signature = abjad.Measure._duration_to_time_signature(
        abjad.Duration(3, 2),
        [5, 6, 7, 8, 9],
        )

    assert time_signature == abjad.TimeSignature((9, 6))
def test_scoretools_Measure__duration_to_time_signature_02():
    r'''Use least feasible denominator in denominators list.
    '''

    time_signature = abjad.Measure._duration_to_time_signature(
        abjad.Duration(3, 2),
        [4, 8, 16, 32],
        )

    assert time_signature == abjad.TimeSignature((6, 4))
def test_enforce_time_signature_12():
    staff = abjad.Staff(r"\time 3/4 d'8. e'16 ~ e'2 ~ e'4.. c'4 d'16")
    auxjad.mutate(staff).enforce_time_signature(abjad.TimeSignature((3, 4)))
    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 3/4
            d'8.
            e'16
            ~
            e'2
            ~
            e'4..
            c'16
            ~
            c'8.
            d'16
        }
        """)
    staff = abjad.Staff(r"\time 3/4 d'8. e'16 ~ e'2 ~ e'4.. c'4 d'16")
    auxjad.mutate(staff).enforce_time_signature(
        abjad.TimeSignature((3, 4)),
        boundary_depth=1,
    )
    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            \time 3/4
            d'8.
            e'16
            ~
            e'2
            ~
            e'4
            ~
            e'8.
            c'16
            ~
            c'8.
            d'16
        }
        """)
Beispiel #23
0
 def _conditionally_adjust_time_signature(self, old_denominator):
     import abjad
     if self.automatically_adjust_time_signature:
         naive_time_signature = self._get_preprolated_duration()
         better_time_signature = \
             abjad.NonreducedFraction(naive_time_signature)
         better_time_signature = \
             better_time_signature.with_denominator(old_denominator)
         better_time_signature = abjad.TimeSignature(better_time_signature)
         abjad.detach(abjad.TimeSignature, self)
         abjad.attach(better_time_signature, self)
Beispiel #24
0
 def make_bell_phrase():
     phrase = []
     for _ in range(3):
         measure = abjad.Container("r2. a'2.")
         abjad.attach(abjad.TimeSignature((6, 4)), measure[0])
         abjad.attach(abjad.LaissezVibrer(), measure[-1])
         phrase.append(measure)
         phrase.append(abjad.Container('R1.'))
     for _ in range(2):
         phrase.append(abjad.Container('R1.'))
     return phrase
def test_Staff_time_signature_03():
    """
    Staff time signature set and then clear.
    """

    staff = abjad.Staff("c'4 c'4 c'4 c'4 c'4 c'4 c'4 c'4")
    time_signature = abjad.TimeSignature((2, 4))
    abjad.attach(time_signature, staff[0])
    abjad.detach(time_signature, staff[0])
    for leaf in staff:
        assert abjad.get.effective(leaf, abjad.TimeSignature) is None
Beispiel #26
0
def test_create_ratios():
    time_signatures = [[  # stage 1
        [  # division 1
            abjad.TimeSignature((4, 4))
        ]
    ]]
    prolaters = [[Prolater()]]
    subdividers = [[Identity()]]
    expected = [[(1, 1, 1, 1)]]
    result = create_ratios(time_signatures, prolaters, subdividers)
    assert expected == result
Beispiel #27
0
 def __init__(
     self,
     time_signatures: typing.Sequence[abjad.TimeSignature] = (
         abjad.TimeSignature((4, 4)), ),
     tempo_envelope: expenvelope.Envelope = None,
 ):
     self._time_signatures = time_signatures
     self._tempo_envelope = tempo_envelope
     self._instrument_id_to_sequential_event_to_abjad_voice_converter = (
         self.
         _make_instrument_id_to_sequential_event_to_abjad_voice_converter())
def test_scoretools_Measure__duration_to_time_signature_04():
    r'''Make time signature literally from time_signature
    because no feasible denomiantors in denominators list.
    '''

    time_signature = abjad.Measure._duration_to_time_signature(
        abjad.Duration(3, 2),
        [7, 11, 13, 19],
        )

    assert time_signature == abjad.TimeSignature((3, 2))
Beispiel #29
0
def test_get_has_indicator_06():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    time_signature = abjad.TimeSignature((4, 8))
    abjad.attach(time_signature, staff[0])

    assert abjad.get.has_indicator(staff[0], abjad.TimeSignature)
    assert not abjad.get.has_indicator(staff[1])
    assert not abjad.get.has_indicator(staff[2])
    assert not abjad.get.has_indicator(staff[3])
    assert not abjad.get.has_indicator(staff)
def test_scoretools_Inspection_has_indicator_06():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    time_signature = abjad.TimeSignature((4, 8))
    abjad.attach(time_signature, staff[0])

    assert abjad.inspect(staff[0]).has_indicator(abjad.TimeSignature)
    assert not abjad.inspect(staff[1]).has_indicator()
    assert not abjad.inspect(staff[2]).has_indicator()
    assert not abjad.inspect(staff[3]).has_indicator()
    assert not abjad.inspect(staff).has_indicator()