# -*- encoding: utf-8 -*-
from abjad import *


def test_rhythmmakertools_BurnishSpecifier_burnish_divisions_01():

    burnish_specifier = rhythmmakertools.BurnishSpecifier(
        burnish_divisions=True,
        lefts=(-1,),
        middles=(0,),
        rights=(-1,),
        left_lengths=(2,),
        right_lengths=(1,),
        )

    talea = rhythmmakertools.Talea(
        counts=(1, 1, 2, 4),
        denominator=32,
        )

    maker = rhythmmakertools.TaleaRhythmMaker(
        talea=talea,
        burnish_specifier=burnish_specifier,
        extra_counts_per_division=(0,),
        )

    divisions = [(5, 16), (6, 16)]
    music = maker(divisions)

    music = sequencetools.flatten_sequence(music)
    staff = Staff(scoretools.make_spacer_skip_measures(divisions))
    mutate(staff).replace_measure_contents(music)

    assert systemtools.TestManager.compare(
        staff,
        r'''
        \new Staff {
            {
                \time 5/16
                {
                    r32
                    r32
                    c'16 [
                    c'8
                    c'32 ]
                    r32
                }
            }
            {
                \time 6/16
                {
                    r16
                    r8
                    c'32 [
                    c'32
                    c'16 ]
                    r16
                }
            }
        }
        '''
        )


def test_rhythmmakertools_BurnishSpecifier_burnish_divisions_02():

    burnish_specifier = rhythmmakertools.BurnishSpecifier(
        burnish_divisions=True,
        lefts=(0,),
        middles=(-1,),
        rights=(0,),
        left_lengths=(2,),
        right_lengths=(1,),
        )

    talea = rhythmmakertools.Talea(
        counts=(1, 1, 2, 4),
        denominator=32,
        )

    maker = rhythmmakertools.TaleaRhythmMaker(
        talea=talea,
        extra_counts_per_division=(0,),
        burnish_specifier=burnish_specifier,
        )

    divisions = [(5, 16), (6, 16)]
    music = maker(divisions)

    music = sequencetools.flatten_sequence(music)
    staff = Staff(scoretools.make_spacer_skip_measures(divisions))
    mutate(staff).replace_measure_contents(music)

    assert systemtools.TestManager.compare(
        staff,
        r'''
        \new Staff {
            {
                \time 5/16
                {
                    c'32 [
                    c'32 ]
                    r16
                    r8
                    r32
                    c'32
                }
            }
            {
                \time 6/16
                {
                    c'16 [
                    c'8 ]
                    r32
                    r32
                    r16
                    c'16
                }
            }
        }
        '''
        )


def test_rhythmmakertools_BurnishSpecifier_burnish_divisions_03():

    burnish_specifier = rhythmmakertools.BurnishSpecifier(
        burnish_divisions=True,
        lefts=(0,),
        middles=(-1,),
        rights=(0,),
        left_lengths=(2,),
        right_lengths=(1,),
        )

    talea= rhythmmakertools.Talea(
        counts=(1, 1, 2, 4,),
        denominator=32,
        )

    maker = rhythmmakertools.TaleaRhythmMaker(
        talea=talea,
        extra_counts_per_division=(3,),
        burnish_specifier=burnish_specifier,
        )

    divisions = [(5, 16), (6, 16)]
    music = maker(divisions)

    music = sequencetools.flatten_sequence(music)
    staff = Staff(scoretools.make_spacer_skip_measures(divisions))
    mutate(staff).replace_measure_contents(music)

    assert systemtools.TestManager.compare(
        staff,
        r'''
        \new Staff {
            {
                \time 5/16
                \tweak #'text #tuplet-number::calc-fraction-text
                \times 10/13 {
                    c'32 [
                    c'32 ]
                    r16
                    r8
                    r32
                    r32
                    r16
                    c'32 ~
                }
            }
            {
                \time 6/16
                \times 4/5 {
                    c'16. [
                    c'32 ]
                    r32
                    r16
                    r8
                    r32
                    r32
                    c'16
                }
            }
        }
        '''
        )


def test_rhythmmakertools_BurnishSpecifier_burnish_divisions_04():

    burnish_specifier = rhythmmakertools.BurnishSpecifier(
        burnish_divisions=True,
        lefts=(-1,),
        middles=(0,),
        rights=(-1,),
        left_lengths=(1,),
        right_lengths=(1,),
        )

    talea = rhythmmakertools.Talea(
        counts=(1, 1, 2, 4),
        denominator=32,
        )

    maker = rhythmmakertools.TaleaRhythmMaker(
        talea=talea,
        extra_counts_per_division=(0, 3),
        burnish_specifier=burnish_specifier,
        )

    divisions = [(5, 16), (6, 16)]
    music = maker(divisions)

    music = sequencetools.flatten_sequence(music)
    staff = Staff(scoretools.make_spacer_skip_measures(divisions))
    mutate(staff).replace_measure_contents(music)

    assert systemtools.TestManager.compare(
        staff,
        r'''
        \new Staff {
            {
                \time 5/16
                {
                    r32
                    c'32 [
                    c'16
                    c'8
                    c'32 ]
                    r32
                }
            }
            {
                \time 6/16
                \times 4/5 {
                    r16
                    c'8 [
                    c'32
                    c'32
                    c'16
                    c'8 ]
                    r32
                }
            }
        }
        '''
        )


def test_rhythmmakertools_BurnishSpecifier_burnish_divisions_05():

    burnish_specifier = rhythmmakertools.BurnishSpecifier(
        burnish_divisions=True,
        lefts=(-1,),
        middles=(0,),
        rights=(-1,),
        left_lengths=(1,),
        right_lengths=(1,),
        )

    talea = rhythmmakertools.Talea(
        counts=(1, 1, 2, 4),
        denominator=32,
        )

    maker = rhythmmakertools.TaleaRhythmMaker(
        talea=talea,
        extra_counts_per_division=(0, 3),
        burnish_specifier=burnish_specifier,
        split_divisions_by_counts=(14,),
        )

    divisions = [(5, 16), (6, 16)]
    music = maker(divisions)

    music = sequencetools.flatten_sequence(music)
    staff = Staff(scoretools.make_spacer_skip_measures(divisions))
    mutate(staff).replace_measure_contents(music)

    assert systemtools.TestManager.compare(
        staff,
        r'''
        \new Staff {
            {
                \time 5/16
                {
                    r32
                    c'32 [
                    c'16
                    c'8
                    c'32 ]
                    r32
                }
            }
            {
                \time 6/16
                \times 4/7 {
                    r16
                    c'8
                    r32
                }
                {
                    r32
                    c'16 [
                    c'8 ]
                    r32
                }
            }
        }
        '''
        )