def _get_value_from_pattern(patterns, current_stage, last):
     if last is None:
         start = Handler._cycle_next(patterns, current_stage)
     else:
         start = last
     end = Handler._cycle_next(patterns, current_stage)
     return start, end
 def _get_value_from_pattern(patterns, current_stage, last):
     if last is None:
         start = Handler._cycle_next(patterns, current_stage)
     else:
         start = last
     end = Handler._cycle_next(patterns, current_stage)
     return start, end
    def __init__(self,
                 music_maker,
                 number_of_staff_lines=15,
                 show_rhythmic_notation=True):

        Handler.__init__(self,
                         music_maker=music_maker,
                         show_rhythmic_notation=show_rhythmic_notation)
        self._number_of_staff_lines = number_of_staff_lines
Exemple #4
0
 def _handle_rhythm_voice(self, rhythm_voice, current_stage):
     if (self._height_envelopes is None
             or self._height_envelopes[current_stage] is None):
         return
     # previous_string_index = None
     for tie, offset_start, offset_end, i, count in \
             Handler._iterate_logical_ties(rhythm_voice):
         # hide leaves if necessary
         if not self._show_rhythmic_notation:
             for leaf in tie:
                 Handler._hide_leaf(leaf)
    def __init__(self,
                 music_maker,
                 number_of_staff_lines=15,
                 show_rhythmic_notation=True):

        Handler.__init__(
            self,
            music_maker=music_maker,
            show_rhythmic_notation=show_rhythmic_notation
        )
        self._number_of_staff_lines = number_of_staff_lines
Exemple #6
0
    def setUp(self):
        stages = (0, )
        instrument = abjad.instrumenttools.Contrabass()
        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)

        self.handler = Handler(music_maker)
 def _attach_string_index(string_index, tie):
     if string_index is not None:
         markup = Handler._make_text_markup(
             string_index,
             direction=Down,
             enclosure='circle'
         )
         abjad.attach(markup, tie.head)
 def _attach_direction(direction, tie):
     if direction is not None:
         markup = Handler._make_text_markup(
             direction,
             direction=Up,
             enclosure='box'
         )
         abjad.attach(markup, tie.head)
 def test__create_cycles(self):
     patterns = [
         [0],
         [0, 1],
         [0, 1, 2]
     ]
     cycles = Handler._create_cycles(patterns)
     for cycle in cycles:
         self.assertIsInstance(cycle, Cycle)
 def _add_jete(note):
     markup = Handler._make_text_markup(
         "…",
         direction=Up,
         font_size=2,
     )
     markup = markup.pad_around(0.5)
     markup = markup.box()
     abjad.attach(markup, note)
 def _add_jete(note):
     markup = Handler._make_text_markup(
         "…",
         direction=Up,
         font_size=2,
     )
     markup = markup.pad_around(0.5)
     markup = markup.box()
     abjad.attach(markup, note)
 def _attach_notehead(tie, intensity, size=0.75, outline=True):
     gray = Handler._intensity_to_grayscale(intensity)
     fill = Handler._make_circle_markup(size, gray)
     if outline:
         outline = Handler._make_circle_outline_markup(size)
         circle = abjad.Markup.combine([fill, outline])
         Handler._markup_to_notehead(tie.head, circle)
     else:
         Handler._markup_to_notehead(tie.head, fill)
 def _attach_notehead(tie, intensity, size=0.75, outline=True):
     gray = Handler._intensity_to_grayscale(intensity)
     fill = Handler._make_circle_markup(size, gray)
     if outline:
         outline = Handler._make_circle_outline_markup(size)
         circle = abjad.Markup.combine([fill, outline])
         Handler._markup_to_notehead(tie.head, circle)
     else:
         Handler._markup_to_notehead(tie.head, fill)
    def __init__(self,
                 music_maker=None,
                 height_envelope_patterns=None,
                 height_envelopes=None,
                 height_envelopes_release=None,
                 pressure_envelope_patterns=None,
                 pressure_envelopes=None,
                 staccato_patterns=None,
                 string_index_patterns=None,
                 tremolo_patterns=None,
                 jete_patterns=None,
                 sweep_patterns=None,
                 direction_patterns=None,
                 number_of_staff_lines=31,
                 show_rhythmic_notation=True):

        EnvelopeHandler.__init__(
            self,
            music_maker=music_maker,
            number_of_staff_lines=number_of_staff_lines,
            show_rhythmic_notation=show_rhythmic_notation
        )

        self._height_envelope_patterns = \
            Handler._create_cycles(height_envelope_patterns)

        self._height_envelopes = height_envelopes

        if height_envelopes_release is None:
            self._height_envelopes_release = height_envelopes
        else:
            self._height_envelopes_release = height_envelopes_release

        self._pressure_envelope_patterns = \
            Handler._create_cycles(pressure_envelope_patterns)

        self._pressure_envelopes = pressure_envelopes

        self._staccato_patterns = Handler._create_cycles(staccato_patterns)

        self._string_index_patterns = \
            Handler._create_cycles(string_index_patterns)

        self._tremolo_patterns = Handler._create_cycles(tremolo_patterns)

        self._jete_patterns = Handler._create_cycles(jete_patterns)

        self._sweep_patterns = Handler._create_cycles(sweep_patterns)

        self._direction_patterns = Handler._create_cycles(direction_patterns)
    def __init__(self,
                 music_maker=None,
                 height_envelope_patterns=None,
                 height_envelopes=None,
                 height_envelopes_release=None,
                 pressure_envelope_patterns=None,
                 pressure_envelopes=None,
                 staccato_patterns=None,
                 string_index_patterns=None,
                 tremolo_patterns=None,
                 jete_patterns=None,
                 sweep_patterns=None,
                 direction_patterns=None,
                 number_of_staff_lines=31,
                 show_rhythmic_notation=True):

        EnvelopeHandler.__init__(self,
                                 music_maker=music_maker,
                                 number_of_staff_lines=number_of_staff_lines,
                                 show_rhythmic_notation=show_rhythmic_notation)

        self._height_envelope_patterns = \
            Handler._create_cycles(height_envelope_patterns)

        self._height_envelopes = height_envelopes

        if height_envelopes_release is None:
            self._height_envelopes_release = height_envelopes
        else:
            self._height_envelopes_release = height_envelopes_release

        self._pressure_envelope_patterns = \
            Handler._create_cycles(pressure_envelope_patterns)

        self._pressure_envelopes = pressure_envelopes

        self._staccato_patterns = Handler._create_cycles(staccato_patterns)

        self._string_index_patterns = \
            Handler._create_cycles(string_index_patterns)

        self._tremolo_patterns = Handler._create_cycles(tremolo_patterns)

        self._jete_patterns = Handler._create_cycles(jete_patterns)

        self._sweep_patterns = Handler._create_cycles(sweep_patterns)

        self._direction_patterns = Handler._create_cycles(direction_patterns)
    def setUp(self):
        stages = (0,)
        instrument = abjad.instrumenttools.Contrabass()
        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)

        self.handler = Handler(music_maker)
Exemple #17
0
    def __init__(
        self,
        music_maker=None,
        height_envelope_patterns=None,
        height_envelopes=None,
        height_envelopes_release=None,
        pressure_envelope_patterns=None,
        pressure_envelopes=None,
        tremolo_patterns=None,
        vibrato_patterns=None,
        number_of_staff_lines=31,
        show_rhythmic_notation=True,
    ):
        EnvelopeHandler.__init__(self,
                                 music_maker=music_maker,
                                 number_of_staff_lines=number_of_staff_lines,
                                 show_rhythmic_notation=show_rhythmic_notation)

        self._height_envelope_patterns = \
            Handler._create_cycles(height_envelope_patterns)

        self._height_envelopes = height_envelopes

        if height_envelopes_release is None:
            self._height_envelopes_release = height_envelopes
        else:
            self._height_envelopes_release = height_envelopes_release

        self._pressure_envelope_patterns = \
            Handler._create_cycles(pressure_envelope_patterns)

        self._pressure_envelopes = pressure_envelopes

        self._tremolo_patterns = Handler._create_cycles(tremolo_patterns)

        self._vibrato_patterns = Handler._create_cycles(vibrato_patterns)
    def __init__(self,
                 music_maker=None,
                 air_pressure_envelope_patterns=None,
                 air_pressure_envelopes=None,
                 air_pressure_envelopes_release=None,
                 lip_pressure_envelope_patterns=None,
                 lip_pressure_envelopes=None,
                 consonant_patterns=None,
                 fluttertongue_patterns=None,
                 direction_patterns=None,
                 staccato_patterns=None,
                 vibrato_patterns=None,
                 vowel_patterns=None,
                 number_of_staff_lines=15,
                 show_rhythmic_notation=True):
        EnvelopeHandler.__init__(self,
                                 music_maker=music_maker,
                                 number_of_staff_lines=number_of_staff_lines,
                                 show_rhythmic_notation=show_rhythmic_notation)
        self._air_pressure_envelope_patterns = \
            Handler._create_cycles(air_pressure_envelope_patterns)

        self._air_pressure_envelopes = air_pressure_envelopes

        self._air_pressure_envelopes_release = air_pressure_envelopes_release

        self._lip_pressure_envelope_patterns = \
            Handler._create_cycles(lip_pressure_envelope_patterns)

        self._lip_pressure_envelopes = lip_pressure_envelopes

        self._consonant_patterns = Handler._create_cycles(consonant_patterns)

        self._direction_patterns = Handler._create_cycles(direction_patterns)

        self._fluttertongue_patterns = \
            Handler._create_cycles(fluttertongue_patterns)

        self._staccato_patterns = Handler._create_cycles(staccato_patterns)

        self._vibrato_patterns = Handler._create_cycles(vibrato_patterns)

        self._vowel_patterns = Handler._create_cycles(vowel_patterns)
    def _handle_rhythm_voice(self, rhythm_voice, current_stage):
        if (self._height_envelopes is None or
            self._height_envelopes[current_stage] is None) and \
                (self._height_envelope_patterns is None or
                 self._height_envelope_patterns[current_stage] is None):
            return

        previous_string_index = None
        for tie, offset_start, offset_end, i, count in \
                self._iterate_logical_ties(rhythm_voice):
            # hide leaves if necessary
            if not self._show_rhythmic_notation:
                for leaf in tie:
                    Handler._hide_leaf(leaf)

            if tie.is_pitched:
                tremolo = Handler._cycle_next(
                    self._tremolo_patterns,
                    current_stage
                )

                string_index = Handler._cycle_next(
                    self._string_index_patterns,
                    current_stage
                )

                direction = Handler._cycle_next(
                    self._direction_patterns,
                    current_stage
                )

                if string_index != previous_string_index:
                    BowingHandler._attach_string_index(string_index, tie)

                if direction:
                    BowingHandler._attach_direction(direction, tie)

                if tremolo:
                    Handler._add_stem_tremolo(tie)

                previous_string_index = string_index
            else:
                previous_string_index = None
 def test__cycle_next(self):
     patterns = [
         [0],
         [0, 1],
     ]
     cycles = Handler._create_cycles(patterns)
     next_cycle = Handler._cycle_next(cycles, 0)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 0)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 1)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 0)
Exemple #21
0
 def test__cycle_next(self):
     patterns = [
         [0],
         [0, 1],
     ]
     cycles = Handler._create_cycles(patterns)
     next_cycle = Handler._cycle_next(cycles, 0)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 0)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 0)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 1)
     next_cycle = Handler._cycle_next(cycles, 1)
     self.assertEqual(next_cycle, 0)
    def _handle_rhythm_voice(self, rhythm_voice, current_stage):
        if (self._height_envelopes is None or
            self._height_envelopes[current_stage] is None) and \
                (self._height_envelope_patterns is None or
                 self._height_envelope_patterns[current_stage] is None):
            return

        previous_string_index = None
        for tie, offset_start, offset_end, i, count in \
                self._iterate_logical_ties(rhythm_voice):
            # hide leaves if necessary
            if not self._show_rhythmic_notation:
                for leaf in tie:
                    Handler._hide_leaf(leaf)

            if tie.is_pitched:
                tremolo = Handler._cycle_next(self._tremolo_patterns,
                                              current_stage)

                string_index = Handler._cycle_next(self._string_index_patterns,
                                                   current_stage)

                direction = Handler._cycle_next(self._direction_patterns,
                                                current_stage)

                if string_index != previous_string_index:
                    BowingHandler._attach_string_index(string_index, tie)

                if direction:
                    BowingHandler._attach_direction(direction, tie)

                if tremolo:
                    Handler._add_stem_tremolo(tie)

                previous_string_index = string_index
            else:
                previous_string_index = None
    def _handle_voice(self, voice, current_stage):
        if (self._height_envelopes is None or
            self._height_envelopes[current_stage] is None) and \
                (self._height_envelope_patterns is None or
                 self._height_envelope_patterns[current_stage] is None):
            return

        last_height = None
        last_pressure = None

        for tie, offset_start, offset_end, i, count in \
                Handler._iterate_logical_ties(voice):

            if tie.is_pitched:
                height_start, height_end = \
                    EnvelopeHandler._get_value(
                        self._height_envelopes,
                        self._height_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_height,
                    )

                pressure_start, pressure_end = \
                    EnvelopeHandler._get_value(
                        self._pressure_envelopes,
                        self._pressure_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_pressure,
                    )

                staccato = Handler._cycle_next(self._staccato_patterns,
                                               current_stage)

                if not staccato:
                    sweep = Handler._cycle_next(self._sweep_patterns,
                                                current_stage)

                    tremolo = Handler._cycle_next(self._tremolo_patterns,
                                                  current_stage)

                    if sweep:
                        style = 'zigzag'
                    elif tremolo:
                        style = 'dashed-line'
                    else:
                        style = None

                    Handler._attach_glissando(
                        tie.head,
                        style=style,
                        color=scheme_rgb_color(
                            grayscale_to_rgb(
                                Handler._intensity_to_grayscale(
                                    pressure_start))),
                    )

                    Handler._hidden_grace_after(tie.tail)

                    grace_container = abjad.inspect(tie.tail)\
                        .get_after_grace_container()

                if grace_container is not None and \
                        len(grace_container) > 0:
                    self._set_y_offset(grace_container[0], height_end)
                    if count - 1 != i:
                        Handler._attach_glissando(
                            grace_container[0],
                            style=style,
                            color=scheme_rgb_color(
                                grayscale_to_rgb(
                                    Handler._intensity_to_grayscale(
                                        pressure_start))),
                        )

                jete = Handler._cycle_next(self._jete_patterns, current_stage)

                if jete:
                    BowingHandler._add_jete(tie.head)

                self._set_y_offset(tie.head, height_start)
                EnvelopeHandler._attach_notehead(tie, pressure_start)

                if not tie.is_trivial:
                    for note in tie[1:]:
                        Handler._add_gliss_skip(note)
                        Handler._hide_note_head(note)

                last_height = height_end
                last_pressure = pressure_end
            else:
                last_height = None
                last_pressure = None
Exemple #24
0
class TestHandler(unittest.TestCase):
    def setUp(self):
        stages = (0, )
        instrument = abjad.instrumenttools.Contrabass()
        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)

        self.handler = Handler(music_maker)

    def test__add_stem_tremolo(self):
        voice = abjad.Voice("c'1")
        tie = abjad.inspect(voice[0]).get_logical_tie()
        self.handler._add_stem_tremolo(tie, tremolo_flags=32)
        prototype = abjad.StemTremolo(32)
        self.assertEqual(
            prototype,
            abjad.inspect(voice[0]).get_indicator(prototype=prototype))

    def test__add_gliss_skip(self):
        note = abjad.Note("c'1")
        self.handler._add_gliss_skip(note)

    def test__attach_glissando(self):
        note = abjad.Note("c'1")
        self.handler._attach_glissando(note)

    def test__create_cycles(self):
        patterns = [[0, 1, 2, 3], [True, False]]
        cycles = self.handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__get_consecutive_note_groups(self):
        voice = abjad.Voice("c'4 c'4 r4 c'4")
        groups = self.handler._get_consecutive_note_groups(voice)
        self.assertEqual(len(groups[0]), 2)
        self.assertEqual(len(groups[1]), 1)

    def test__hidden_grace_after(self):
        note = abjad.Note("c'1")
        self.handler._hidden_grace_after(note)
        grace_container = abjad.inspect(note).get_after_grace_container()
        self.assertEqual(str(grace_container[0]),
                         str(abjad.Note(0, abjad.Duration(1, 16))))

    def test__hide_and_skip_tied_notes(self):
        voice = abjad.Voice("c'4 ~ c'16 r8.")
        for tie in abjad.iterate(voice).by_logical_tie(pitched=True):
            self.handler._hide_and_skip_tied_notes(tie)

    def test__hide_note_head(self):
        note = abjad.Note("c'1")
        self.handler._hide_note_head(note)
        chord = abjad.Chord("<c' e' g'>4")
        self.handler._hide_note_head(chord)

    def test__iterate_logical_ties(self):
        voice = abjad.Voice("c'4 ~ c'16 c'8. c'2")
        for tie, offset_start, offset_end, i, count in \
                self.handler._iterate_logical_ties(voice):
            self.assertIsInstance(tie, abjad.selectiontools.LogicalTie)
            self.assertIsInstance(offset_start, float)
            self.assertIsInstance(offset_end, float)

    def test__make_circle_markup(self):
        markup = self.handler._make_circle_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_circle_outline_markup(self):
        markup = self.handler._make_circle_outline_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_half_circle_markup(self):
        markup = self.handler._make_half_circle_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_text_markup(self):
        markup = self.handler._make_text_markup('x')
        self.assertIsInstance(markup, abjad.Markup)

    def test_markup_to_note_head(self):
        note = abjad.Note("c'1")
        markup = self.handler._make_text_markup('x')
        self.handler._markup_to_notehead(note, markup)

    def test__name_voices(self):
        voice = abjad.Voice("c'1")
        rhythm_voice = abjad.Voice("c'1")
        self.handler._name_voices(voice, rhythm_voice)

    def test_integer_to_roman_numeral(self):
        self.assertEqual(Handler.integer_to_roman_numeral(1), 'I')

    def test__create_cycles(self):
        patterns = [[0], [0, 1], [0, 1, 2]]
        cycles = Handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__create_cycles(self):
        patterns = [[0], [0, 1], [0, 1, 2]]
        cycles = Handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__cycle_next(self):
        patterns = [
            [0],
            [0, 1],
        ]
        cycles = Handler._create_cycles(patterns)
        next_cycle = Handler._cycle_next(cycles, 0)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 0)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 1)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 0)
Exemple #25
0
 def test__create_cycles(self):
     patterns = [[0], [0, 1], [0, 1, 2]]
     cycles = Handler._create_cycles(patterns)
     for cycle in cycles:
         self.assertIsInstance(cycle, Cycle)
Exemple #26
0
 def test_integer_to_roman_numeral(self):
     self.assertEqual(Handler.integer_to_roman_numeral(1), 'I')
 def _name_voices(self, voice, rhythm_voice, lifeline_voice):
     Handler._name_voices(self, voice, rhythm_voice)
     lifeline_voice.name = self._music_maker.name + ' Lifeline'
 def _attach_string_index(string_index, tie):
     if string_index is not None:
         markup = Handler._make_text_markup(string_index,
                                            direction=Down,
                                            enclosure='circle')
         abjad.attach(markup, tie.head)
    def _handle_voice(self, voice, current_stage):
        if (self._height_envelopes is None or
            self._height_envelopes[current_stage] is None) and \
                (self._height_envelope_patterns is None or
                 self._height_envelope_patterns[current_stage] is None):
            return

        last_height = None
        last_pressure = None

        for tie, offset_start, offset_end, i, count in \
                Handler._iterate_logical_ties(voice):

            if tie.is_pitched:
                height_start, height_end = \
                    EnvelopeHandler._get_value(
                        self._height_envelopes,
                        self._height_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_height,
                    )

                pressure_start, pressure_end = \
                    EnvelopeHandler._get_value(
                        self._pressure_envelopes,
                        self._pressure_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_pressure,
                    )

                staccato = Handler._cycle_next(self._staccato_patterns,
                                               current_stage)

                if not staccato:
                    sweep = Handler._cycle_next(self._sweep_patterns,
                                                current_stage)

                    tremolo = Handler._cycle_next(self._tremolo_patterns,
                                                  current_stage)

                    if sweep:
                        style = 'zigzag'
                    elif tremolo:
                        style = 'dashed-line'
                    else:
                        style = None

                    Handler._attach_glissando(
                        tie.head,
                        style=style,
                        color=scheme_rgb_color(
                            grayscale_to_rgb(
                                Handler._intensity_to_grayscale(pressure_start)
                            )
                        ),
                    )

                    Handler._hidden_grace_after(tie.tail)

                    grace_container = abjad.inspect(tie.tail)\
                        .get_after_grace_container()

                if grace_container is not None and \
                        len(grace_container) > 0:
                    self._set_y_offset(grace_container[0], height_end)
                    if count - 1 != i:
                        Handler._attach_glissando(
                            grace_container[0],
                            style=style,
                            color=scheme_rgb_color(
                                grayscale_to_rgb(
                                    Handler._intensity_to_grayscale(
                                        pressure_start)
                                )
                            ),
                        )

                jete = Handler._cycle_next(self._jete_patterns, current_stage)

                if jete:
                    BowingHandler._add_jete(tie.head)

                self._set_y_offset(tie.head, height_start)
                EnvelopeHandler._attach_notehead(tie, pressure_start)

                if not tie.is_trivial:
                    for note in tie[1:]:
                        Handler._add_gliss_skip(note)
                        Handler._hide_note_head(note)

                last_height = height_end
                last_pressure = pressure_end
            else:
                last_height = None
                last_pressure = None
class TestHandler(unittest.TestCase):

    def setUp(self):
        stages = (0,)
        instrument = abjad.instrumenttools.Contrabass()
        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)

        self.handler = Handler(music_maker)

    def test__add_stem_tremolo(self):
        voice = abjad.Voice("c'1")
        tie = abjad.inspect(voice[0]).get_logical_tie()
        self.handler._add_stem_tremolo(tie, tremolo_flags=32)
        prototype = abjad.StemTremolo(32)
        self.assertEqual(
            prototype,
            abjad.inspect(voice[0]).get_indicator(prototype=prototype)
        )

    def test__add_gliss_skip(self):
        note = abjad.Note("c'1")
        self.handler._add_gliss_skip(note)

    def test__attach_glissando(self):
        note = abjad.Note("c'1")
        self.handler._attach_glissando(note)

    def test__create_cycles(self):
        patterns = [[0, 1, 2, 3], [True, False]]
        cycles = self.handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__get_consecutive_note_groups(self):
        voice = abjad.Voice("c'4 c'4 r4 c'4")
        groups = self.handler._get_consecutive_note_groups(voice)
        self.assertEqual(len(groups[0]), 2)
        self.assertEqual(len(groups[1]), 1)

    def test__hidden_grace_after(self):
        note = abjad.Note("c'1")
        self.handler._hidden_grace_after(note)
        grace_container = abjad.inspect(note).get_after_grace_container()
        self.assertEqual(
            str(grace_container[0]),
            str(abjad.Note(0, abjad.Duration(1, 16)))
        )

    def test__hide_and_skip_tied_notes(self):
        voice = abjad.Voice("c'4 ~ c'16 r8.")
        for tie in abjad.iterate(voice).by_logical_tie(pitched=True):
            self.handler._hide_and_skip_tied_notes(tie)

    def test__hide_note_head(self):
        note = abjad.Note("c'1")
        self.handler._hide_note_head(note)
        chord = abjad.Chord("<c' e' g'>4")
        self.handler._hide_note_head(chord)

    def test__iterate_logical_ties(self):
        voice = abjad.Voice("c'4 ~ c'16 c'8. c'2")
        for tie, offset_start, offset_end, i, count in \
                self.handler._iterate_logical_ties(voice):
            self.assertIsInstance(tie, abjad.selectiontools.LogicalTie)
            self.assertIsInstance(offset_start, float)
            self.assertIsInstance(offset_end, float)

    def test__make_circle_markup(self):
        markup = self.handler._make_circle_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_circle_outline_markup(self):
        markup = self.handler._make_circle_outline_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_half_circle_markup(self):
        markup = self.handler._make_half_circle_markup(1)
        self.assertIsInstance(markup, abjad.Markup)

    def test__make_text_markup(self):
        markup = self.handler._make_text_markup('x')
        self.assertIsInstance(markup, abjad.Markup)

    def test_markup_to_note_head(self):
        note = abjad.Note("c'1")
        markup = self.handler._make_text_markup('x')
        self.handler._markup_to_notehead(note, markup)

    def test__name_voices(self):
        voice = abjad.Voice("c'1")
        rhythm_voice = abjad.Voice("c'1")
        self.handler._name_voices(voice, rhythm_voice)

    def test_integer_to_roman_numeral(self):
        self.assertEqual(Handler.integer_to_roman_numeral(1), 'I')

    def test__create_cycles(self):
        patterns = [
            [0],
            [0, 1],
            [0, 1, 2]
        ]
        cycles = Handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__create_cycles(self):
        patterns = [
            [0],
            [0, 1],
            [0, 1, 2]
        ]
        cycles = Handler._create_cycles(patterns)
        for cycle in cycles:
            self.assertIsInstance(cycle, Cycle)

    def test__cycle_next(self):
        patterns = [
            [0],
            [0, 1],
        ]
        cycles = Handler._create_cycles(patterns)
        next_cycle = Handler._cycle_next(cycles, 0)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 0)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 0)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 1)
        next_cycle = Handler._cycle_next(cycles, 1)
        self.assertEqual(next_cycle, 0)
Exemple #31
0
    def _handle_voice(self, voice, current_stage):
        last_force = None
        last_position = None
        last_string_index = None

        for tie, offset_start, offset_end, i, count \
            in self._iterate_logical_ties(voice):

            if tie.is_pitched:
                force_start, force_end = \
                    PickingHandler._get_value(
                        self._force_envelopes,
                        self._force_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_force,
                    )

                position_start, position_end = \
                    PickingHandler._get_value(
                        self._position_envelopes,
                        self._position_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_position,
                    )

                scrape = self._cycle_next(self._scrape_patterns, current_stage)

                tremolo = self._cycle_next(self._tremolo_patterns,
                                           current_stage)

                if tremolo:
                    style = 'dashed-line'
                elif scrape:
                    style = 'dotted-line'
                else:
                    style = None

                if tremolo or scrape:
                    EnvelopeHandler._attach_glissando(
                        tie.head,
                        style=style,
                        color=scheme_rgb_color(
                            grayscale_to_rgb(
                                Handler._intensity_to_grayscale(force_start))),
                    )

                    self._hidden_grace_after(tie.tail)

                    grace_container = \
                        abjad.inspect(tie.tail).get_after_grace_container()

                    if grace_container is not None and \
                            len(grace_container) > 0:
                        self._set_y_offset(grace_container[0], position_end)
                        if count - 1 != i:
                            Handler._attach_glissando(
                                grace_container[0],
                                style=style,
                                color=scheme_rgb_color(
                                    grayscale_to_rgb(
                                        Handler._intensity_to_grayscale(
                                            force_start))),
                            )

                self._set_y_offset(tie.head, position_start)

                PickingHandler._attach_notehead(tie, force_start)

                if not tie.is_trivial:
                    for note in tie[1:]:
                        if tremolo or scrape:
                            self._add_gliss_skip(note)
                        self._hide_note_head(note)

                string_index = self._cycle_next(self._string_index_patterns,
                                                current_stage)

                if last_string_index and string_index != last_string_index:
                    self._attach_string_index(string_index, tie)

                last_force = force_end
                last_position = position_end
                last_string_index = string_index
            else:
                last_force = None
                last_position = None
                last_string_index = None
    def _handle_voice(self, voice, current_stage):
        # skip if no data
        if (self._air_pressure_envelopes is None or
            self._air_pressure_envelopes[current_stage] is None) and \
                (self._air_pressure_envelope_patterns is None or
                 self._air_pressure_envelope_patterns[current_stage] is None):
            return

        last_air_pressure = None
        last_lip_pressure = None

        for tie, offset_start, offset_end, i, count in \
                Handler._iterate_logical_ties(voice):

            if tie.is_pitched:
                air_pressure_start, air_pressure_end = \
                    EnvelopeHandler._get_value(
                        self._air_pressure_envelopes,
                        self._air_pressure_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_air_pressure,
                    )

                lip_pressure_start, lip_pressure_end = \
                    EnvelopeHandler._get_value(
                        self._lip_pressure_envelopes,
                        self._lip_pressure_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_lip_pressure,
                    )

                staccato = EmbouchureHandler._cycle_next(
                    self._staccato_patterns, current_stage)

                if not staccato:
                    vibrato = EmbouchureHandler._cycle_next(
                        self._vibrato_patterns, current_stage)

                    fluttertongue = EmbouchureHandler._cycle_next(
                        self._fluttertongue_patterns, current_stage)

                    if vibrato:
                        style = 'zigzag'
                    elif fluttertongue:
                        style = 'dashed-line'
                    else:
                        style = None

                    # create lines
                    EnvelopeHandler._attach_glissando(
                        tie.head,
                        style=style,
                        color=scheme_rgb_color(
                            grayscale_to_rgb(
                                Handler._intensity_to_grayscale(
                                    lip_pressure_start))),
                    )

                    EnvelopeHandler._hidden_grace_after(tie.tail)

                    grace_container = abjad.inspect(tie.tail)\
                        .get_after_grace_container()

                    if grace_container is not None and \
                            len(grace_container) > 0:
                        self._set_y_offset(grace_container[0],
                                           air_pressure_end)
                        if count - 1 != i:
                            Handler._attach_glissando(
                                grace_container[0],
                                style=style,
                                color=scheme_rgb_color(
                                    grayscale_to_rgb(
                                        Handler._intensity_to_grayscale(
                                            lip_pressure_start))),
                            )

                self._set_y_offset(tie.head, air_pressure_start)
                EnvelopeHandler._attach_notehead(tie, lip_pressure_start)

                if not tie.is_trivial:
                    for note in tie[1:]:
                        EmbouchureHandler._add_gliss_skip(note)
                        EmbouchureHandler._hide_note_head(note)

                last_air_pressure = air_pressure_end
                last_lip_pressure = lip_pressure_end
            else:
                last_air_pressure = None
                last_lip_pressure = None
    def _handle_voice(self, voice, current_stage):
        last_force = None
        last_position = None
        last_string_index = None

        for tie, offset_start, offset_end, i, count \
            in self._iterate_logical_ties(voice):

            if tie.is_pitched:
                force_start, force_end = \
                    PickingHandler._get_value(
                        self._force_envelopes,
                        self._force_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_force,
                    )

                position_start, position_end = \
                    PickingHandler._get_value(
                        self._position_envelopes,
                        self._position_envelope_patterns,
                        current_stage,
                        offset_start,
                        offset_end,
                        last_position,
                    )

                scrape = self._cycle_next(self._scrape_patterns, current_stage)

                tremolo = self._cycle_next(self._tremolo_patterns,
                                           current_stage)

                if tremolo:
                    style = 'dashed-line'
                elif scrape:
                    style = 'dotted-line'
                else:
                    style = None

                if tremolo or scrape:
                    EnvelopeHandler._attach_glissando(
                        tie.head,
                        style=style,
                        color=scheme_rgb_color(
                            grayscale_to_rgb(
                                Handler._intensity_to_grayscale(force_start)
                            )
                        ),
                    )

                    self._hidden_grace_after(tie.tail)

                    grace_container = \
                        abjad.inspect(tie.tail).get_after_grace_container()

                    if grace_container is not None and \
                            len(grace_container) > 0:
                        self._set_y_offset(grace_container[0], position_end)
                        if count - 1 != i:
                            Handler._attach_glissando(
                                grace_container[0],
                                style=style,
                                color=scheme_rgb_color(
                                    grayscale_to_rgb(
                                        Handler._intensity_to_grayscale(
                                            force_start)
                                    )
                                ),
                            )

                self._set_y_offset(tie.head, position_start)

                PickingHandler._attach_notehead(tie, force_start)

                if not tie.is_trivial:
                    for note in tie[1:]:
                        if tremolo or scrape:
                            self._add_gliss_skip(note)
                        self._hide_note_head(note)

                string_index = self._cycle_next(
                    self._string_index_patterns,
                    current_stage
                )

                if last_string_index and string_index != last_string_index:
                    self._attach_string_index(string_index, tie)

                last_force = force_end
                last_position = position_end
                last_string_index = string_index
            else:
                last_force = None
                last_position = None
                last_string_index = None
 def test_integer_to_roman_numeral(self):
     self.assertEqual(Handler.integer_to_roman_numeral(1), 'I')
 def _attach_direction(direction, tie):
     if direction is not None:
         markup = Handler._make_text_markup(direction,
                                            direction=Up,
                                            enclosure='box')
         abjad.attach(markup, tie.head)