def __init__(
     self,
     time_signatures=None,
     divisions=None,
     rh_rhythm_maker=None,
     lh_rhythm_maker=None,
     rh_pitch_range=None,
     lh_pitch_range=None,
     include_layout_ly=None,
     ):
     import abjad
     from abjad.tools import rhythmmakertools
     SegmentMaker.__init__(self)
     time_signatures = time_signatures or []
     time_signatures = [abjad.TimeSignature(_) for _ in time_signatures]
     self._time_signatures = time_signatures
     self._divisions = divisions
     if rh_rhythm_maker is None:
         rh_rhythm_maker = rhythmmakertools.NoteRhythmMaker()
     assert isinstance(rh_rhythm_maker, rhythmmakertools.RhythmMaker)
     self._rh_rhythm_maker = rh_rhythm_maker
     if lh_rhythm_maker is None:
         lh_rhythm_maker = rhythmmakertools.NoteRhythmMaker()
     assert isinstance(lh_rhythm_maker, rhythmmakertools.RhythmMaker)
     self._lh_rhythm_maker = lh_rhythm_maker
     rh_pitch_range = rh_pitch_range or '[C4, C6]'
     rh_pitch_range = abjad.PitchRange(rh_pitch_range)
     self._rh_pitch_range = rh_pitch_range
     lh_pitch_range = lh_pitch_range or '[C2, C4)'
     lh_pitch_range = abjad.PitchRange(lh_pitch_range)
     self._lh_pitch_range = lh_pitch_range
     if include_layout_ly is not None:
         include_layout_ly = bool(include_layout_ly)
     self._include_layout_ly = include_layout_ly
Beispiel #2
0
 def automatic_clefs(self, select: abjad.Selection, material_name: str):
     """Attach appropriate clef for selection."""
     clefs = [
         abjad.Clef("treble^15"),
         abjad.Clef("treble^8"),
         abjad.Clef("treble"),
         abjad.Clef("bass"),
         abjad.Clef("bass_8"),
     ]
     ranges = [
         abjad.PitchRange("[G#7, +inf]"),
         abjad.PitchRange("[G6, G7]"),
         abjad.PitchRange("[E4, E5]"),
         abjad.PitchRange("[A1, G3]"),
         abjad.PitchRange("[-inf, C1]"),
     ]
     if material_name is None:
         selection = select(self.container)
     else:
         selection = select(
             self.select_material(self.container, material_name))
     for element in selection:
         for clef, range_ in zip(clefs, ranges):
             if element.written_pitch in range_:
                 abjad.attach(clef, element)
Beispiel #3
0
def test_Hocketer_19():
    random.seed(66191)
    container = abjad.Container(r"c' d' e f' g a' b' c''")
    hocketer = auxjad.Hocketer(container,
                               n_voices=3,
                               pitch_ranges=[abjad.PitchRange("[C4, C5]"),
                                             abjad.PitchRange("[C4, C5]"),
                                             abjad.PitchRange("[C3, B3]"),
                                             ])
    hocketer()
    score = abjad.Score()
    for selection in hocketer[:]:
        staff = abjad.Staff(selection)
        score.append(staff)
    abjad.attach(abjad.Clef('bass'), abjad.select(score[2]).leaf(0))
    assert abjad.lilypond(score) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                c'4
                d'4
                r4
                f'4
                r4
                a'4
                r2
            }
            \new Staff
            {
                R1
                r2
                b'4
                c''4
            }
            \new Staff
            {
                \clef "bass"
                r2
                e4
                r4
                g4
                r2.
            }
        >>
        """
    )
Beispiel #4
0
    def create_named_pitch_set_in_pitch_range(self, pitch_range):
        r'''Creates named pitch-set in `pitch_range`.

        Returns pitch-set.
        '''
        import abjad
        if not isinstance(pitch_range, abjad.PitchRange):
            pitch_range = abjad.PitchRange(
                float(abjad.NamedPitch(pitch_range[0])),
                float(abjad.NamedPitch(pitch_range[1])))
        low = pitch_range.start_pitch.octave.number
        high = pitch_range.stop_pitch.octave.number
        pitches = []
        octave = low
        while octave <= high:
            for x in self:
                pitch = abjad.NamedPitch((x.name, octave))
                if (pitch_range.start_pitch <= pitch
                        and pitch <= pitch_range.stop_pitch):
                    pitches.append(pitch)
            octave += 1
        return abjad.PitchSet(
            items=pitches,
            item_class=abjad.NamedPitch,
        )
Beispiel #5
0
 def __init__(
     self,
     allowable_clefs=None,
     context=None,
     hide=None,
     markup=None,
     middle_c_sounding_pitch=None,
     name=None,
     pitch_range=None,
     short_name=None,
     short_markup=None,
 ):
     import abjad
     self._context = context or 'Staff'
     if name is not None:
         name = str(name)
     self._name = name
     if markup is not None:
         markup = abjad.Markup(markup)
     self._name_markup = markup
     if short_name is not None:
         short_name = str(short_name)
     self._short_name = short_name
     if short_markup is not None:
         short_markup = abjad.Markup(short_markup)
     self._short_name_markup = short_markup
     allowable_clefs = allowable_clefs or ('treble', )
     self._allowable_clefs = allowable_clefs
     if isinstance(pitch_range, str):
         pitch_range = abjad.PitchRange(pitch_range)
     elif isinstance(pitch_range, abjad.PitchRange):
         pitch_range = copy.copy(pitch_range)
     elif pitch_range is None:
         pitch_range = abjad.PitchRange()
     else:
         raise TypeError(pitch_range)
     self._pitch_range = pitch_range
     middle_c_sounding_pitch = (middle_c_sounding_pitch
                                or abjad.NamedPitch("c'"))
     middle_c_sounding_pitch = abjad.NamedPitch(middle_c_sounding_pitch)
     self._middle_c_sounding_pitch = middle_c_sounding_pitch
     self._is_primary_instrument = False
     self._performer_names = ['instrumentalist']
     self._starting_clefs = copy.copy(allowable_clefs)
     if hide is not None:
         hide = bool(hide)
     self._hide = hide
Beispiel #6
0
def test_Hocketer_22():
    random.seed(91776)
    container = abjad.Container(
        r"<c' e' g'>4 <d' f' a'>4 <e' g' b'>4 <f' a' c''>4"
    )
    hocketer = auxjad.Hocketer(container,
                               n_voices=3,
                               explode_chords=True,
                               pitch_ranges=[abjad.PitchRange("[E4, C5]"),
                                             abjad.PitchRange("[E4, C5]"),
                                             abjad.PitchRange("[C4, F4]"),
                                             ],
                               )
    hocketer()
    score = abjad.Score()
    for selection in hocketer[:]:
        staff = abjad.Staff(selection)
        score.append(staff)
    assert abjad.lilypond(score) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                e'4
                f'4
                g'4
                c''4
            }
            \new Staff
            {
                g'4
                a'4
                b'4
                a'4
            }
            \new Staff
            {
                c'4
                d'4
                e'4
                f'4
            }
        >>
        """
    )
Beispiel #7
0
 def pitch_range_filter(self, pitch_range):
     """Todo."""
     rangein = abjad.PitchRange(pitch_range)
     for chord in self.container:
         pitches = []
         for note in chord.written_pitches:
             if note in rangein:
                 pitches.append(note)
             else:
                 pass
             chord.written_pitches = pitches
     return self.container
Beispiel #8
0
def create_pitch_contour_reservoir():
    """
    Creates pitch contour reservoir.
    """
    scale = abjadext.tonality.Scale(("a", "minor"))
    pitch_ranges = {
        "First Violin": abjad.PitchRange("[C4, A6]"),
        "Second Violin": abjad.PitchRange("[A3, A5]"),
        "Viola": abjad.PitchRange("[E3, A4]"),
        "Cello": abjad.PitchRange("[A2, A3]"),
        "Bass": abjad.PitchRange("[C3, A3]"),
    }
    reservoir = {}
    for name, pitch_range in pitch_ranges.items():
        pitch_set = scale.create_named_pitch_set_in_pitch_range(pitch_range)
        pitches = sorted(pitch_set, reverse=True)
        pitch_descents = []
        for i in range(len(pitches)):
            descent = tuple(pitches[:i + 1])
            pitch_descents.append(descent)
        reservoir[name] = tuple(pitch_descents)
    return reservoir
Beispiel #9
0
def test_Hocketer_03():
    container = abjad.Container(r"\time 3/4 c'4 d'4 e'4 \time 2/4 f'4 g'4")
    hocketer = auxjad.Hocketer(container,
                               n_voices=3,
                               weights=[1, 2, 5],
                               k=2,
                               force_k_voices=True,
                               explode_chords=True,
                               pitch_ranges=[abjad.PitchRange("[C4, D6]"),
                                             abjad.PitchRange("[C2, A4]"),
                                             abjad.PitchRange("[C1, E3]"),
                                             ],
                               disable_rewrite_meter=True,
                               use_multimeasure_rests=False,
                               omit_time_signatures=True,
                               boundary_depth=0,
                               maximum_dot_count=1,
                               rewrite_tuplets=False,
                               )
    assert hocketer.n_voices == 3
    assert hocketer.weights == [1, 2, 5]
    assert hocketer.k == 2
    assert hocketer.force_k_voices
    assert hocketer.explode_chords
    assert hocketer.pitch_ranges == [abjad.PitchRange("[C4, D6]"),
                                     abjad.PitchRange("[C2, A4]"),
                                     abjad.PitchRange("[C1, E3]"),
                                     ]
    assert hocketer.disable_rewrite_meter
    assert not hocketer.use_multimeasure_rests
    assert hocketer.omit_time_signatures
    assert hocketer.boundary_depth == 0
    assert hocketer.maximum_dot_count == 1
    assert not hocketer.rewrite_tuplets
    hocketer.n_voices = 5
    hocketer.weights = [1, 1, 1, 2, 7]
    hocketer.k = 3
    hocketer.force_k_voices = False
    hocketer.explode_chords = False
    hocketer.pitch_ranges = None
    hocketer.disable_rewrite_meter = False
    hocketer.use_multimeasure_rests = True
    hocketer.omit_time_signatures = False
    hocketer.boundary_depth = 1
    hocketer.maximum_dot_count = 2
    hocketer.rewrite_tuplets = True
    assert hocketer.n_voices == 5
    assert hocketer.weights == [1, 1, 1, 2, 7]
    assert hocketer.k == 3
    assert not hocketer.force_k_voices
    assert not hocketer.explode_chords
    assert hocketer.pitch_ranges is None
    assert not hocketer.disable_rewrite_meter
    assert hocketer.use_multimeasure_rests
    assert not hocketer.omit_time_signatures
    assert hocketer.boundary_depth == 1
    assert hocketer.maximum_dot_count == 2
    assert hocketer.rewrite_tuplets
Beispiel #10
0
def test_Hocketer_18():
    random.seed(97813)
    container = abjad.Container(r"c4 d8 e'8 f'4 g'8 a8")
    hocketer = auxjad.Hocketer(container,
                               n_voices=2,
                               pitch_ranges=[abjad.PitchRange("[C4, B5]"),
                                             abjad.PitchRange("[C3, B3]"),
                                             ])
    hocketer()
    score = abjad.Score()
    for selection in hocketer[:]:
        staff = abjad.Staff(selection)
        score.append(staff)
    abjad.attach(abjad.Clef('bass'), abjad.select(score[1]).leaf(0))
    assert abjad.lilypond(score) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                r4.
                e'8
                f'4
                g'8
                r8
            }
            \new Staff
            {
                \clef "bass"
                c4
                d8
                r8
                r4.
                a8
            }
        >>
        """
    )
Beispiel #11
0
def create_pitch_contour_reservoir():
    """
    Creates pitch contour reservoir.
    """
    import abjadext.tonality
    scale = abjadext.tonality.Scale(('a', 'minor'))
    pitch_ranges = {
        'First Violin': abjad.PitchRange('[C4, A6]'),
        'Second Violin': abjad.PitchRange('[A3, A5]'),
        'Viola': abjad.PitchRange('[E3, A4]'),
        'Cello': abjad.PitchRange('[A2, A3]'),
        'Bass': abjad.PitchRange('[C3, A3]'),
    }
    reservoir = {}
    for name, pitch_range in pitch_ranges.items():
        pitch_set = scale.create_named_pitch_set_in_pitch_range(pitch_range)
        pitches = sorted(pitch_set, reverse=True)
        pitch_descents = []
        for i in range(len(pitches)):
            descent = tuple(pitches[:i + 1])
            pitch_descents.append(descent)
        reservoir[name] = tuple(pitch_descents)
    return reservoir
Beispiel #12
0
    def pitch_range(self):
        """
        Gets pitch range of octave.

        ..  container:: example

            >>> abjad.Octave(5).pitch_range
            PitchRange('[C5, C6)')

        Returns pitch range.
        """
        import abjad

        return abjad.PitchRange("[C{}, C{})".format(self.number,
                                                    self.number + 1))
Beispiel #13
0
def test_Hocketer_23():
    container = abjad.Container(r"\time 3/4 c'4 d'4 e'4 \time 2/4 f'4 g'4")
    hocketer = auxjad.Hocketer(container,
                               n_voices=3,
                               pitch_ranges=[abjad.PitchRange("[C4, D6]"),
                                             abjad.PitchRange("[C2, A4]"),
                                             abjad.PitchRange("[C1, E3]"),
                                             ],
                               )
    assert hocketer.pitch_ranges == [abjad.PitchRange("[C4, D6]"),
                                     abjad.PitchRange("[C2, A4]"),
                                     abjad.PitchRange("[C1, E3]"),
                                     ]
    hocketer.n_voices = 4
    assert hocketer.pitch_ranges is None
# NO MICROTONAL
for item, i in zip(num_pitches, range(len(num_pitches))):
    if isinstance(item, float):
        item = item - 0.5
        num_pitches[i] = item

# num_pitches.sort()
maker = abjad.LeafMaker()
num_pitches_notes = maker(num_pitches, (1, 1))
num_pitches_notes = abjad.Staff(num_pitches_notes)
num_pitches_score = abjad.LilyPondFile.new(music=num_pitches_notes)
abjad.f(num_pitches_score)

pitches_up = []
pitches_down = []
pitch_range = abjad.PitchRange("[C2, G7]")
treble_range = abjad.pitch.PitchRange("[C4, +inf]")
for note in num_pitches:
    test1 = note in pitch_range
    test2 = note in treble_range
    if test1 is True and test2 is True:
        pitches_up.append(note)
    if test1 is True and test2 is False:
        pitches_down.append(note)


random.seed(0)
random.shuffle(pitches_up)

pitches_down.pop(7)
pitches_down.pop(3)
Beispiel #15
0
def test_Hocketer_20():
    random.seed(81742)
    container = abjad.Container(r"c'8 d'8 e8 f'8 g8 a'8 b'8 c''8")
    hocketer = auxjad.Hocketer(container,
                               n_voices=4,
                               k=2,
                               force_k_voices=True,
                               pitch_ranges=[abjad.PitchRange("[C4, C5]"),
                                             abjad.PitchRange("[C4, C5]"),
                                             abjad.PitchRange("[E3, G4]"),
                                             abjad.PitchRange("[E3, G4]"),
                                             ])
    hocketer()
    score = abjad.Score()
    for selection in hocketer[:]:
        staff = abjad.Staff(selection)
        score.append(staff)
    abjad.attach(abjad.Clef('bass'), abjad.select(score[2]).leaf(0))
    abjad.attach(abjad.Clef('bass'), abjad.select(score[3]).leaf(0))
    assert abjad.lilypond(score) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                r2
                r8
                a'8
                b'8
                c''8
            }
            \new Staff
            {
                c'8
                d'8
                r4
                r8
                a'8
                b'8
                c''8
            }
            \new Staff
            {
                \clef "bass"
                r8
                d'8
                e8
                f'8
                g8
                r4.
            }
            \new Staff
            {
                \clef "bass"
                c'8
                r8
                e8
                f'8
                g8
                r4.
            }
        >>
        """
    )
Beispiel #16
0
def see_pitches(pitches):
    """Show abjad.PitchSegment in two staffs."""
    G_staff = abjad.Staff()
    F_staff = abjad.Staff()
    staff_group = abjad.StaffGroup([G_staff, F_staff])
    pitch_range = abjad.PitchRange("[C4, +inf]")
    for pitch in pitches:
        test = pitch in pitch_range
        if test is True:
            note = abjad.Note.from_pitch_and_duration(pitch, (1, 1))
            G_staff.append(note)
            F_staff.append(abjad.Skip((1, 1)))
        if test is False:
            note = abjad.Note.from_pitch_and_duration(pitch, (1, 1))
            G_staff.append(abjad.Skip((1, 1)))
            F_staff.append(note)

    for i, note in enumerate(F_staff):
        abjad.attach(abjad.Markup(i), note)

    clef4 = abjad.Clef("treble^15")
    clef4_range = abjad.PitchRange("[G#7, +inf]")
    clef3 = abjad.Clef("treble^8")
    clef3_range = abjad.PitchRange("[G6, G7]")
    clef2 = abjad.Clef("treble")
    clef2_range = abjad.PitchRange("[E4, E5]")
    clef1 = abjad.Clef("bass")
    clef1_range = abjad.PitchRange("[A1, G3]")
    clef0 = abjad.Clef("bass_8")
    clef0_range = abjad.PitchRange("[-inf, C1]")

    selection = abjad.select(G_staff).leaves()
    for i, leaf in enumerate(selection):
        if isinstance(leaf, abjad.Note):
            test4 = leaf.written_pitch in clef4_range
            test3 = leaf.written_pitch in clef3_range
            test2 = leaf.written_pitch in clef2_range
            if test4 is True:
                abjad.attach(clef4, G_staff[i])
            elif test3 is True:
                abjad.attach(clef3, G_staff[i])
            elif test2 is True:
                abjad.attach(clef2, G_staff[i])

    selection2 = abjad.select(F_staff).leaves()
    for i, leaf in enumerate(selection2):
        if isinstance(leaf, abjad.Note):
            test3 = leaf.written_pitch in clef3_range
            test2 = leaf.written_pitch in clef2_range
            test1 = leaf.written_pitch in clef1_range
            test0 = leaf.written_pitch in clef0_range
            if test2 is True:
                abjad.attach(clef2, F_staff[i])
            elif test1 is True:
                abjad.attach(clef1, F_staff[i])
            elif test0 is True:
                abjad.attach(clef0, F_staff[i])

    abjad.show(staff_group)

    return staff_group
Beispiel #17
0
def instruments():
    return dict([(
        "Cello",
        abjad.Cello(pitch_range=abjad.PitchRange("[B1, +inf]")),
    )])