Esempio n. 1
0
def counter_i_straight(lib=None):
    return CounterLine(
        ImaginaryPhrase(ImaginaryCell(rhythm=RHYTHM_STRAIGHT,
                                      pitches=(
                                          "R",
                                          5,
                                          0,
                                          -3,
                                      ),
                                      slug="straightup"),
                        ImaginaryCell(rhythm=RHYTHM_STRAIGHT,
                                      pitches=(-3, -3, 0, -5),
                                      slug="straight"),
                        slug="straight"),
        ImaginaryPhrase(
            ImaginaryCell(rhythm=RHYTHM_STRAIGHT,
                          pitches=(
                              "R",
                              -5,
                              -3,
                              2,
                          ),
                          slug="straightup_i"),
            ImaginaryCell(
                rhythm=RHYTHM_STRAIGHT,
                pitches=(0, -3, 2, 0),  # first could also be rest
                slug="straight_i"),
            slug="straight_i"),
        slug="counter_i").autoname("phrases", "cells", prefix="counter_i")
Esempio n. 2
0
def straight_bass(
        input_row,
        phrase_count=2,
        rhythm_tree=(
            (2, 2),
            (2, 2),
        ),
        input_start_beat=0,
):

    beat_counter = input_start_beat
    bass_line = ImaginaryLine()

    for i in range(phrase_count):
        bass_phrase = ImaginaryPhrase()

        for cell_r in rhythm_tree:
            bass_cell = ImaginaryCell()

            for r in cell_r:
                if r > 0:
                    input_event = input_row.event_at_beat(beat_counter)
                    # TO DO... think of being more flexifble to pull either cell/phrase, parent/grandparent
                    input_node = input_event.parent.parent
                    input_pitches = input_node.note_pitch_set
                    my_pitch = chords.get_diatonic_root(input_pitches) - 24
                else:
                    my_pitch = "R"
                bass_cell.append(calliope.Event(beats=r, pitch=my_pitch))
                beat_counter += abs(r)
            bass_phrase.append(bass_cell)
        bass_line.append(bass_phrase)
    return bass_line
Esempio n. 3
0
def high_rhythm(lib=None):
    p = ImaginaryPhrase(
        ImaginaryCell(rhythm=(-0.5, 0.5) * 2 + (1, -1)),
        ImaginaryCell(rhythm=(1, ) + (-0.5, 0.5) * 3),
    )
    p.note_events.setattrs(pitch=12)
    return p
Esempio n. 4
0
 def violins_speed_up(staff_name, pitch, intro_name=None):
     if intro_name:
         b2[staff_name].machine(lib(intro_name))
     b2[staff_name].machine_arrow(ImaginaryCell(rhythm=(2,), pitches=(pitch,)).eps(
         0,"pp", "\\<")(),
         pad_fill=False,
         arrow_beats=4, 
         instruction="markup_column:repeat, speed up (not|necessary with others) until... ")
     b2[staff_name].machine_arrow(ImaginaryCell(rhythm=(0.5,0.5,), pitches=(pitch,pitch)).eps(
         0, "mf")(),
         instruction="markup_column:...eventually matching woodblock's|eighth note pulse")
Esempio n. 5
0
def bass_rhythm(lib=None):
    return ImaginaryPhrase(
        ImaginaryCell(rhythm=(1, 1, -1.5, 0.5),
                      pitches=(
                          -5,
                          (-5, 4),
                          "R",
                          -1,
                      )),
        ImaginaryCell(rhythm=(-2, 1, -1), pitches=("R", (-5, 5), "R")),
    )
Esempio n. 6
0
 def pad(self, beats=1, with_command=True):
     if beats > 0:
         floor_beats = math.floor(beats)
         remainder_beats = beats - floor_beats
         pad_cell = ImaginaryCell(rhythm=(1, ) * floor_beats,
                                  pitches=("S", ) * floor_beats)
         if remainder_beats:
             pad_cell.append(
                 calliope.Event(beats=remainder_beats, pitch="S"))
         if with_command:
             pad_cell.events[0].tag("\\freePad")
         self.append(pad_cell)
         return pad_cell
Esempio n. 7
0
def mid_rhythm(lib=None):
    return ImaginaryPhrase(
        ImaginaryCell(rhythm=(0.25, 0.25, 0.5, -0.5, 0.5, -1, 0.25, 0.25,
                              0.5)),
        ImaginaryCell(rhythm=(
            -1,
            0.5,
            0.5,
            -0.5,
            0.5,
            1,
        )),
    )
Esempio n. 8
0
    def weave(self, staff, index=0, **kwargs):
        pattern = abjad.CyclicTuple(
            (self.event_duration, ) *
            (self.dove_event_count + self.tail_event_count) +
            (0 - self.event_duration, ) *
            ((self.dove_event_count) *
             (self.dove_count - 1) - self.tail_event_count))

        # abjac.CyclicTuple is unhappy about negative slice starts, so
        # reset offset if negative:
        if self.offset < 0:
            self.offset = self.offset % len(pattern)

        start_index = index * (self.dove_count -
                               1) * self.dove_event_count + self.offset

        my_rhythm = list(
            pattern[start_index:start_index +
                    int(self.dovetail_duration / self.event_duration)])

        # DO TO: THIS IS CONFUSING... document or rethink
        initial_tail_index = (start_index -
                              self.dove_event_count) % len(pattern)
        if not self.tail_bookends[
                0] and initial_tail_index < self.tail_event_count:
            for i in range(self.tail_event_count - initial_tail_index):
                my_rhythm[i] = 0 - self.event_duration

        final_tail_index = start_index % len(pattern)
        if not self.tail_bookends[
                1] and final_tail_index <= self.tail_event_count:
            for i in range(final_tail_index):
                my_rhythm[0 - i - 1] = 0 - self.event_duration

        my_line = ImaginaryLine()

        cell_rhythm = []
        last_rest = None
        for r in my_rhythm:
            my_is_rest = r < 0
            if last_rest is not None and my_is_rest != last_rest:
                my_line.append(ImaginaryCell(rhythm=cell_rhythm))
                cell_rhythm = []
            cell_rhythm.append(r)
            last_rest = my_is_rest

        if cell_rhythm:
            my_line.append(ImaginaryCell(rhythm=cell_rhythm))

        return my_line
Esempio n. 9
0
def drum_dark(lib):
    c = ImaginaryCell(rhythm=(
        0.25,
        0.25,
        0.5,
        0.5,
        0.5,
        0.5,
        0.5,
        0.5,
        0.25,
        0.25,
    ),
                      pitches=(
                          (
                              -8,
                              -5,
                              -1,
                          ),
                          -1,
                          -1,
                          -8,
                          5,
                          -8,
                          4,
                          -8,
                          (
                              -5,
                              5,
                          ),
                          4,
                      ))
    c.events[0, 3, 5, 7].tag("note_head:0:cross")
    return c
Esempio n. 10
0
    def weave(self, staff, index=0, **kwargs):
        my_rhythm = []
        my_stagger = self.swell_staggers[index % len(self.swell_staggers)]
        my_split_ratio = self.swell_split_ratios[index %
                                                 len(self.swell_split_ratios)]
        if my_stagger[0] > 0:
            my_rhythm.append(0 - my_stagger[0])

        # split duration rounded to nearest 16th note:
        my_rhythm.append(
            int((self.swell_duration - sum(my_stagger)) * my_split_ratio * 4) /
            4)
        my_rhythm.append(self.swell_duration - sum(my_stagger) - my_rhythm[-1])

        if my_stagger[1] > 0:
            my_rhythm.append(0 - my_stagger[1])

        my_cell = ImaginaryCell(rhythm=my_rhythm)

        if self.low_dynamic:
            my_cell.note_events[0].tag(self.low_dynamic)

        if self.swell_dynamic:
            my_cell.note_events[1].tag(self.swell_dynamic)

        if self.low_dynamic and self.swell_dynamic:
            my_cell.note_events[0].tag("\\<")
            my_cell.note_events[1].tag("\\>")
            # my_cell.events[-1].tag("!<>\\pp")

        return my_cell
Esempio n. 11
0
 def arrow(
     self,
     beats=8,
     pad_beats=2,
     with_repeat=True,
     instruction="",
     text_length_on=False,
 ):
     arrow_cell = ImaginaryCell(rhythm=(1, ) * beats,
                                pitches=("S", ) * beats)
     arrow_cell.events[0].tag("\\freeContinue")
     if with_repeat:
         arrow_cell.events[0].tag("\\bar \":|.\"")
     arrow_cell.events[1, -1].setattrs(rest=True)
     arrow_cell.events[1].tag("\\once \\hide Rest")
     arrow_cell.events[-1].tag("\\freePad", "\\freeRestArrow")
     if instruction:
         arrow_cell[0].tag(instruction)
         arrow_cell.events[0].tag(
             "\\once \\override TextScript.extra-offset = #'( 1 . 0 )")
         if text_length_on:
             arrow_cell.events[0].tag("\\textLengthOn")
             arrow_cell.events[-1].tag("\\textLengthOff")
     self.append(arrow_cell)
     if pad_beats:
         self.pad(pad_beats, with_command=False)
     return arrow_cell
Esempio n. 12
0
def drum_rock_out(lib):
    c = ImaginaryCell(rhythm=(
        0.5,
        0.5,
        0.5,
        0.5,
        0.5,
        0.25,
        0.25,
        0.5,
        0.5,
    ),
                      pitches=(
                          (-5, 9),
                          (9, -8),
                          (-5, 9, 2),
                          (9, -8),
                          (-5, 9),
                          (9, 4, -8),
                          2,
                          (-5, 9, 2),
                          (9, -8),
                      ))
    c.events[1, 3, 5, 8].tag("note_head:0:cross")
    c.events[0, 1, 2, 3, 4, 5, 7, 8].tag("note_head:-1:cross")
    return c
Esempio n. 13
0
def high_rhythm_ii(lib=None):
    p = ImaginaryPhrase(
        ImaginaryCell(rhythm=(0.25, 0.25, 0.5, -0.5, 0.5, -0.5, 0.5, 0.25,
                              0.25, 0.5)),
        # ImaginaryCell(rhythm=(0.25,0.25, 0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 0.5,)),
    )
    p.note_events.setattrs(pitch=(0, 12))
    return p
Esempio n. 14
0
def counter(lib=None):
    return CounterLine(ImaginaryPhrase(
        ImaginaryCell(rhythm=RHYTHM_DOWN, pitches=(
            0,
            -1,
        ), slug="down"),
        ImaginaryCell(rhythm=RHYTHM_MIST, pitches=(5, 4, -3), slug="mist"),
        slug="mistify",
    ),
                       ImaginaryPhrase(ImaginaryCell(rhythm=RHYTHM_DOWN,
                                                     pitches=(
                                                         5,
                                                         4,
                                                     ),
                                                     slug="down_i"),
                                       ImaginaryCell(rhythm=RHYTHM_MIST,
                                                     pitches=(4, 9, 7),
                                                     slug="mist_i"),
                                       slug="mistify_i"),
                       ImaginaryPhrase(ImaginaryCell(rhythm=(
                           -1,
                           2,
                           0.5,
                           0.5,
                       ),
                                                     pitches=(
                                                         "R",
                                                         5,
                                                         4,
                                                         2,
                                                     ),
                                                     slug="fast"),
                                       ImaginaryCell(rhythm=(-0.5, 0.5, 0.5,
                                                             0.5, -2),
                                                     pitches=(9, 9, 7, 5, "R"),
                                                     slug="fast_i"),
                                       slug="fast"),
                       ImaginaryPhrase(ImaginaryCell(rhythm=(-1, 1),
                                                     pitches=("R", 7),
                                                     slug="shortend"),
                                       ImaginaryCell(rhythm=(
                                           0.5,
                                           5.5,
                                       ),
                                                     pitches=(
                                                         12,
                                                         9,
                                                     ),
                                                     slug="longend"),
                                       slug="end"),
                       slug="counter").autoname("phrases",
                                                "cells",
                                                prefix="counter")
Esempio n. 15
0
def shake_swell_arrow(seg,
                      pitches,
                      start_dynamic="p",
                      end_dynamic="mp",
                      *args,
                      **kwargs):
    e_count = len(seg.events) + 1
    seg.machine_arrow(
        ImaginaryCell(rhythm=(4, ), pitches=(pitches, )).eps(0, "tremolo:3")())
    return seg.eps(e_count, e_count + 5, start_dynamic,
                   "\\<")(e_count + 3, end_dynamic, "\\>")()
Esempio n. 16
0
def drum_hits(lib):
    c = ImaginaryCell(rhythm=(1, -3),
                      pitches=((
                          -8,
                          -5,
                          2,
                          11,
                      ), "R", "R", "R"))
    c.events[0].tag("note_head:0:cross")
    c.events[0].tag("note_head:3:cross")
    return c
Esempio n. 17
0
def drum_on_off(lib):
    # TO DO: vary this up ... make it more interesting
    c = ImaginaryCell(
        rhythm=(0.5, ) * 4 + (0.5, 0.25, 0.25) + (0.5, 0.5) +
        (0.25, 0.25, 0.5) * 3 + (0.5, 0.25, 0.25),
        pitches=(-5, (-8, -5), 2, (-8), "R", (-8, 4), 4, 2, (-8, -5), (2, 9),
                 9, -8, (2, 9), 9, -8, 9, 9, -8, (9, 2), (-8, -5, 4), -1),
    )
    c.events[1, 3, 5, 8, 11, 14, 17, 19].tag("note_head:0:cross")
    c.events[9, 10, 12, 13, 15, 16, 18].tag("note_head:-1:cross")
    return c
Esempio n. 18
0
    def fill_rests(self, beats=None, fill_to=None, **kwargs):
        segs = list(self.segments)
        segs_beats = [s.beats for s in segs]

        if fill_to:
            beats = beats or self.segments[fill_to].beats

        beats = beats or max(segs_beats)

        for seg, seg_beats in zip(segs, segs_beats):
            if seg_beats < beats:
                seg.append(ImaginaryCell(rhythm=(seg_beats - beats, )))
Esempio n. 19
0
def rhythm1(lib):
    c1 = ImaginaryCell(rhythm=(0.25, 0.25, 0.5, 0.5, 0.5, -1, 0.25, 0.25, 0.5),
                       pitches=((5, -5), 5, -8, (-5, 2, 4), -8, "R", 5, 4,
                                (-1, -8))).eps(2, 4, 8, "note_head:0:cross")()
    c2 = ImaginaryCell(rhythm=(
        -1,
        0.5,
        0.5,
        0.5,
        0.5,
        1,
    ),
                       pitches=(
                           "R",
                           9,
                           (-8, 9),
                           (-5, 2, 5),
                           -8,
                           2,
                       )).eps(1, 2, 4,
                              "note_head:0:cross")(2, "note_head:1:cross")()
    return ImaginaryPhrase(c1, c2)
Esempio n. 20
0
def gliss_up_block(rest_beats=-1,
                   low_beats=3,
                   high_beats=4,
                   transpose=0,
                   tags=()):
    return calliope.SegmentBlock(
        ImaginarySegment(
            ImaginaryCell(
                rhythm=(rest_beats, low_beats, high_beats),
                pitches=("R", 16 + transpose, 27 + transpose),
                respell="sharps",
            ).eps(
                0,
                "speed up into tremolo",
            )(1, "!\\glissando :8", "\\<", *tags)(2, "ff", ":32")()))
Esempio n. 21
0
def drum_quick_off2(lib):
    c = ImaginaryCell(rhythm=(
        0.25,
        0.25,
        0.5,
        1,
        0.5,
        0.25,
        0.25,
        0.5,
        0.5,
    ),
                      pitches=(9, 2, 2, -8, 9, 2, 2, (2, -5, -8), 9))
    c.events[0, 3, 4, 7, 8].tag("note_head:0:cross")
    return c
Esempio n. 22
0
def cell_shake(lib=None):
    return ImaginaryCell(rhythm=(2, 2, 1, 2, 1),
                         pitches=(
                             -11,
                             (-11, -10),
                             -10,
                             (-11, -10),
                             -11,
                         )).eps(
                             0,
                             "pp",
                             "\\<",
                         )(1, "tremolo:3")(2, "mp", "\\>")(3, "tremolo:3")(
                             4,
                             "\\!",
                         )()
Esempio n. 23
0
def rhythm2(lib=None):
    c = ImaginaryCell(rhythm=(
        -0.5,
        0.5,
        0.5,
        0.5,
        -0.5,
        0.5,
        0.5,
        0.5,
    ),
                      pitches=(
                          "R",
                          9,
                          2,
                          9,
                          "R",
                          9,
                          2,
                          9,
                      )).eps(1, 3, 5, 7, "note_head:0:cross")()
    return ImaginaryPhrase(c, )
Esempio n. 24
0
def drum_du_du(lib):
    c = ImaginaryCell(
        rhythm=(0.25, ) * 12 + (0.5, 0.5),
        pitches=(
            (-8, 5),
            5,
            5,
            5,
            (-8, 4),
            4,
            "R",
            4,
            -8,
            4,
            "R",
            4,
            (-8, -1),
            (5, -1, 2),
        ),
    )
    c.events[0, 4, 8, 16].tag("note_head:0:cross")
    return c
Esempio n. 25
0
def drum_off_short(lib):

    c = ImaginaryCell(
        rhythm=(
            0.25,
            0.25,
            -0.5,
        ) + (
            0.5,
            0.5,
            -1,
            0.5,
            0.5,
        ),
        pitches=(
            (-8, 9),
            9,
            "R",
        ) + (9, -8, "R", 9, -8),
    )
    c.note_events.tag("note_head:0:cross")
    c.note_events.tag("note_head:1:cross")
    return c
Esempio n. 26
0
def drum_quick_off(lib):
    c = ImaginaryCell(rhythm=(
        0.25,
        0.25,
        0.5,
        1,
        0.5,
        0.25,
        0.25,
        1,
    ),
                      pitches=(
                          9,
                          9,
                          9,
                          -8,
                          9,
                          9,
                          9,
                          -8,
                      ))
    c.events.tag("note_head:0:cross")
    return c
Esempio n. 27
0
def score1(lib):
    s = score.ImaginaryScore()
    sb = lib("integrate_block1")

    s = sb().annotate(slur_cells=True, label=(
        "phrases",
        "cells",
    )).to_score(s)

    # drum_off_cell.note_events[1].tag("brushes")
    # drum_on_off_cell.note_events.tag("note_head:0:cross")
    # drum_on_off_cell.note_events.tag("note_head:1:cross")

    drum_set = ImaginarySegment(
        lib("drum_on_off"),
        get_improv_line(rhythm=(1, ) * 8, times=7).ops("cells")(6, "\\<")(),
        get_improv_line(instruction="improv, solo",
                        rhythm=(0.5, ) * 8,
                        times=1).eps(0, "mf")(),
    )
    s.staves["ooa_drum_set"].append(drum_set)

    string_staves = (
        "ooa_violin1",
        "ooa_violin2",
        "ooa_cello1",
        "ooa_cello2",
        "cco_violin_i",
        "cco_violin_ii",
        "cco_viola",
        "cco_cello",
    )

    s.extend_from(
        pulse_on_off_beat.PulseOnOffBeat(
            sb,
            fabric_staves=string_staves,
            phrase_beats=(8, ) * 8,
            ranges=pitch_ranges.LOW_TO_HIGHISH_RANGES,
        ), )

    # CCO cello and viola come in first ... then
    for st in s.staves["ooa_cello1", "ooa_cello2"]:
        st.segments[0].mask("cells", 0, 1)
    for st in s.staves["cco_violin_i", "cco_violin_ii", ]:
        st.segments[0].mask(
            "cells",
            0,
            1,
            2,
            3,
        )
    for st in s.staves["ooa_violin1", "ooa_violin2"]:
        st.segments[0].mask("cells", 0, 1, 2, 3, 4, 5)

    timp_seg = s.staves["cco_cello"].segments[0]()
    for n in timp_seg.note_events:
        if not n.pitch in (-22, -15, -10):
            n.pitch = "R"
    timp_seg.cells[12, 13].note_events.tag(">")
    timp_seg.transformed(calliope.StandardDurations()).eps(
        0, "\\timpStaff", "timpani", "p")()
    s.staves["cco_percussion"].append(timp_seg)

    for st in s.staves[string_staves]:
        st.note_events[0].tag("arco", "p")
        st.phrases[3].e_smear_after(0, cover_notes=True,
                                    extend_beats=3.5).eps(0, "\\<")()
        st.cells[7].tag("mf")
        st.cells[13].e_smear_after(0, extend_beats=2.5,
                                   cover_notes=True).eps(0, "\\mp", "\\<")()()
        st.cells[13].eps(1, "mf", ">", ".")()
        st.cells[14].eps(0, ">", ".")()

    bass_seg = s.staves["cco_cello"].segments[0]()
    for n in bass_seg.cells[4:].note_events:
        n.pitch = sb.pitches_at(n.beats_before(bass_seg))[0] + 12
    for c in bass_seg.cells[14:]:
        c.t(1)
    s.staves["cco_bass"].append(bass_seg)

    s.extend_from(
        lambda_segment.LambdaSegments(
            sb.with_only("bass_line", ),
            fabric_staves=("ooa_bassoon", "cco_bassoon"),
            funcs=(
                lambda x: x.crop_chords(indices=(0, 1)).crop("cells", 0, 1),
                lambda x: x.crop_chords(indices=(1, 0)).crop("cells", 0, 1),
            ),
            tag_all_note_events=("-", )))
    s.extend_from(
        lambda_segment.LambdaSegments(
            sb.with_only("melody_line1"),
            fabric_staves=("harp1", "harp2"),
            funcs=(
                lambda x: x.crop_chords(indices=(1, )).ops("note_events")
                (0, "mp")(),
                lambda x: x.crop_chords(indices=(0, )).t(-12),
            ),
        ))

    # s.extend_from(
    #     lambda_segment.LambdaSegments(
    #         sb.with_only("counter_line"),
    #         # assign_pitches_from_selectable = True,
    #         fabric_staves = ("piano1","piano2"),
    #         func = lambda x: x.transformed(
    #                 calliope.StandardDurations(
    #                     min_duration=0.25,
    #                     standard_duration=0.5,)
    #                 ).e_smear_after(4, cover_notes=True, extend_beats=1
    #                 ).e_smear_after(6, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(8, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(10, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(16, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(19, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(22, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(29, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(33, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(35, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(46, cover_notes=True, extend_beats=0.5
    #                 ).e_smear_after(86, cover_notes=True, extend_beats=0.5
    #                 ).mask("events",24,25,27,31
    #                 ).mask("cells",26,27,29,31).slur_cells(#).label("events","cells"
    #                 ),
    #         funcs = (
    #             lambda x: x.crop_chords(indices=(1,)).transformed(
    #                 calliope.SmartRange(
    #                     smart_range = (12,26),
    #                     )
    #                 ),
    #             lambda x: x.crop_chords(indices=(0,)).t(-12).transformed(
    #             ),
    #         )
    #         )
    #     )
    # harp_piano_combo = calliope.CompositeChordsLine(
    #     calliope.LineBlock(
    #         ImaginaryLine(*s.staves["harp2"].cells.copy()),
    #         ImaginaryLine(*s.staves["piano2"].cells.copy())),
    #     ).transformed(artics.GroupByBeats())
    # s.staves["ooa_mallets"].append(ImaginarySegment(harp_piano_combo))

    # s.extend_from(
    #     lambda_segment.LambdaSegments(
    #         sb.with_only("melody_line2"),
    #         fabric_staves = ("piano1","piano2"),
    #         funcs = (
    #             lambda x: x.crop_chords(indices=(1,)),
    #             lambda x: x.crop_chords(indices=(0,)).t(-12),
    #             ),
    #         )
    #     )
    guitars = osti.Osti(
        sb.with_only("bass_drones"),
        fabric_staves=(
            "ooa_bass_guitar",
            "ooa_guitar",
        ),
        ranges=pitch_ranges.MID_RANGES,
        osti_pulse_duration=1,
        osti_cell_length=16,
        osti_cell_count=4,
    )
    s.extend_from(
        staggered_swell.StaggeredSwells(
            sb.with_only("high_drones"),
            fabric_staves=("ooa_flute", "cco_flute1", "cco_flute2"),
            low_dynamic="p",
            swell_dynamic="mf",
            swell_duration=8,
            cell_count=2,
            phrase_count=4,
        ),
        guitars,
    )

    harp_lh = s.staves["harp2"].segments[0]
    for n in harp_lh.note_events:
        pitches_at_sb = sb.pitches_at(n.beats_before(harp_lh))
        n.pitch = (pitches_at_sb[1], pitches_at_sb[-4])
    harp_lh.smart_ranges([(-14, 4)])
    # now remove dupes
    for n in harp_lh.note_events:
        n.pitch = set(n.pitch)
    for c in harp_lh.cells:
        c.mask("note_events", -1, -2)
    harp_lh.transformed(calliope.StandardDurations())

    piano_rh = ImaginarySegment(
        ImaginaryLine(
            ImaginaryCell(rhythm=(-4, )),
            ImaginaryPhrase(
                ImaginaryCell(rhythm=(0.25, 1.75) * 2),
                ImaginaryCell(rhythm=(2, ) * 4),
            ) * 4,
        ))
    piano_lh = harp_lh()

    mallets = piano_rh()
    for n in mallets.note_events:
        n.pitch = sb.pitches_at(n.beats_before(mallets))[-3]
    s.staves["ooa_mallets"].append(mallets)
    mallets.eps(1, "mp")(8, 16, 22, 24, 30, ":32")()

    for n in piano_rh.note_events:
        if n.beats == 0.25:
            n.pitch = sb.pitches_at(n.beats_before(piano_rh))[-2]
            n.tag("(")
        elif n.beats == 1.75:
            n.pitch = sb.pitches_at(n.beats_before(piano_rh))[-1]
            n.tag(")")
        else:
            n.pitch = set(sb.pitches_at(n.beats_before(piano_rh))[-2:])
    for n in piano_lh.note_events:
        n.pitch = sb.pitches_at(n.beats_before(piano_lh))[1]
    piano_lh.fuse().slur_cells()
    for n in piano_lh.note_events:
        n.pitch = set(sb.pitches_at(n.beats_before(piano_lh))[1:3])

    s.staves["piano1"].append(piano_rh)
    s.staves["piano2"].append(piano_lh)

    s.fill_rests(beats=15 * 4)
    final_swell_sax_brass = swell_hit.SwellHit(
        sb.with_only("chords"),
        fabric_staves=instrument_groups.get_instruments(
            "sax",
            "brass",
        ),
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=15 * 4,
        low_dynamic="p",
        hit_dynamic="mf",
        swell_duration=7,
        hit_duration=1,
        hit_rest=0,
        hit_articulations=("-", ))
    s.extend_from(final_swell_sax_brass)

    s.fill_rests(beats=16 * 4)
    final_swell_winds_strings = swell_hit.SwellHit(
        sb.with_only("chords"),
        fabric_staves=instrument_groups.get_instruments(
            "winds",
            "strings",
        ),
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=16 * 4,
        low_dynamic="mp",
        hit_dynamic="f",
        swell_duration=3,
        hit_duration=1,
        hit_rest=0,
        hit_articulations=("-", ))
    s.extend_from(final_swell_winds_strings)

    # s.extend_from(final_block)

    s.fill_rests(fill_to="cco_violin_i")

    # s.only_staves("piano1", "piano2")
    # s.as_rhythm_and_short()

    # s.only_staves(*instrument_groups.get_instruments("cco_strings"))

    s.fill_rests()
    s.remove(s.staff_groups["short_score"])

    # s.lines.apply(lambda x:x.auto_respell())
    # s.phrases.apply(lambda x:x.auto_respell())

    for staff in s.staves:
        # staff.phrases.transformed(calliope.Label())
        # staff.lines.transformed(calliope.Label())

        # TO DO: WHY DOESN'T THIS WORK?????
        if segs := staff.segments:
            main_seg = segs[0]
            for next_seg in list(segs[1:]):
                main_seg.extend(next_seg)
                next_seg.parent.remove(next_seg)
            main_seg.rehearsal_mark_number = 11
            main_seg.compress_full_bar_rests = True
Esempio n. 28
0
def sus_maker(
        input_row,
        inversions=(0, ),
        root_offsets=(0, ),  # based on SCALE step (not chromatic pitch)
        allowed_thirds=None,  # TO DO, consider dropping this
        rhythm=(
            1,
            1,
            1,
            1,
        ),
        input_t=0,
        truncate_to_input=True,
        input_start_beat=0,
        **kwargs):

    sus_interval_preference = (0, 4, 8, 3, 9, 7, 5, 2, 10, 1, 11, 6)

    # # TO DO MAYBE: could automate this... but worth it?
    # if prefer = "thirds":
    #     sus_interval_preference = (0, 4, 8, 3, 9, 7, 5, 2, 10, 1, 11, 6)
    # else:
    #     sus_interval_preference = (0, 4, 8, 3, 9, 7, 5, 2, 10, 1, 11, 6)

    cell_inventory = {}

    for select_attr, di in kwargs.items():
        input_select = getattr(input_row, select_attr)

        for select_index, di2 in sorted(di.items()):
            input_node = input_select[select_index]
            input_beats_before = input_node.beats_before(
                input_row) - input_start_beat
            input_beats = input_node.beats

            my_input_t = di2.get("input_t", kwargs.get("input_t", input_t))
            input_pitches = [p + my_input_t for p in input_node.note_pitch_set]
            input_chord_root = get_diatonic_root(input_pitches)

            my_scale = calliope.Scale(root=input_chord_root)
            my_root_offsets = di2.get("root_offsets", root_offsets)
            my_inversions = di2.get("inversions", inversions)
            my_rhythm = di2.get("rhythm", rhythm)
            my_allowed_thirds = di2.get("allowed_thirds", allowed_thirds)
            my_truncate_to_input = di2.get("truncate_to_input",
                                           truncate_to_input)
            my_octave_t = di2.get("octave", 0) * 12

            beat_counter = 0
            i = 0  # counting manually since only indexing note events
            sus_pitches = []
            sus_rhythm = []
            # print()
            # print(di2, input_beats, my_rhythm)

            while i < len(my_rhythm) and (beat_counter < input_beats
                                          or not truncate_to_input):
                # print("   ", beat_counter)
                my_beats = my_rhythm[i]

                if my_beats > 0:
                    my_root_offset = my_root_offsets[i % len(my_root_offsets)]
                    my_chord_root = my_scale[my_root_offset]

                    my_inversion = my_inversions[i % len(my_inversions)] % 3
                    my_inverted_root = my_chord_root if my_inversion == 0 else my_chord_root + 12

                    input_event = input_row.event_at_beat(beat_counter +
                                                          input_beats_before)
                    input_pitches = input_event.note_pitch_set

                    allowed_thirds = [
                        my_scale[i + 1 + my_root_offset] for i in range(3)
                    ]

                    my_sus = min(allowed_thirds,
                                 key=lambda x: sum([
                                     sus_interval_preference.index(
                                         (x - p) % 12) for p in input_pitches
                                 ]))
                    # print("ROOT:", allowed_thirds, my_sus)

                    if my_inversion == 2:
                        my_sus += 12

                    sus_pitches.append(
                        sorted([
                            my_inverted_root + my_octave_t,
                            my_sus + my_octave_t,
                            my_scale[my_root_offset + 4] + my_octave_t
                        ]))

                else:
                    sus_pitches.append("R")

                if beat_counter + abs(
                        my_beats) > input_beats and my_truncate_to_input:
                    # print(beat_counter, input_beats)
                    sus_rhythm.append(beat_counter - input_beats)
                else:
                    sus_rhythm.append(my_beats)

                beat_counter += abs(my_beats)
                i += 1

            # print(sus_rhythm)
            sus_cell = ImaginaryCell(rhythm=sus_rhythm, pitches=sus_pitches)
            # if i == 0:
            # print(input_beats_before, sus_cell)
            cell_inventory[input_beats_before] = sus_cell

    # print("-----------------------------------------------------")

    sus_line = ImaginaryLine()
    current_beats_before = 0

    for beats_before, cell in sorted(cell_inventory.items()):
        if beats_before > current_beats_before:
            sus_line.append(
                ImaginaryCell(rhythm=(current_beats_before - beats_before, )))
            current_beats_before += beats_before - current_beats_before
        sus_line.append(cell)
        # print(cell)
        # print("==========")
        current_beats_before += cell.beats
    # print(cell_inventory[0])

    print("-----------------------------------------------------")
    # print(sus_line.cells)

    return sus_line
Esempio n. 29
0
    ImaginaryLine,
    ImaginaryPhrase,
    ImaginaryCell,
)
from imaginary.stories import library

# TO DO: consider using accent pattern
# also TO DO: consider replacing these with auto sus generation (below)
_OSTI_PITCHES = (
    "R",
    (2, 5, 10),
    (2, 5, 10),
    (2, 5, 9),
    (4, 7, 12),
)
_OSTI_2_CELL = ImaginaryCell(rhythm=(2, ), pitches=((5, 7, 12), ))

_CHORD_PHRASE_1 = ImaginaryPhrase(
    ImaginaryCell(rhythm=(-0.5, 1, 0.5, 1, 1), pitches=_OSTI_PITCHES),
    _OSTI_2_CELL,
)

_CHORD_PHRASE_2 = ImaginaryPhrase(
    ImaginaryCell(rhythm=(-0.5, 1, 1, 0.5, 1), pitches=_OSTI_PITCHES),
    _OSTI_2_CELL,
)


def get_chord_phrase1():
    return _CHORD_PHRASE_1()
Esempio n. 30
0
def score2(lib):
    s = score.ImaginaryScore()
    sb = lib("rock_block2")
    s = sb().annotate(slur_cells=True, label=("phrases", "cells")).to_score(s)

    rim_shots = ImaginaryCell(rhythm=(1, 1, 1, 1), pitches=(2, 2, 2, 2))
    rim_shots.note_events.tag("\\withSlash")

    drum_rhythm2 = lambda_segment.LambdaSegment(
        calliope.SegmentBlock(
            ImaginarySegment(
                lib("rock_rhythm2"),
                get_improv_line(times=8),
                rim_shots,
                get_improv_line(times=6),
                lib("drum_hits") * 3,
            )),
        fabric_staves=("ooa_drum_set", ),
        func=lambda x: x,
    )

    cco_perc1 = osti.Osti(fabric_staves=("cco_percussion", ),
                          osti_pulse_duration=0.5,
                          osti_cell_length=8,
                          osti_cell_count=9,
                          func=lambda x: x.eps(0, "mf")())
    cco_perc2 = lambda_segment.LambdaSegment(
        sb.with_only("high_rhythm"),
        fabric_staves=("cco_percussion", ),
        func=lambda x: x.with_only("cells", 9, 10, 11, 12, 13, 14, 15),
    )
    cco_perc3 = osti.Osti(fabric_staves=("cco_percussion", ),
                          osti_pulse_duration=0.5,
                          osti_cell_length=8,
                          osti_cell_count=3,
                          func=lambda x: x.eps(0, "mf")())
    cco_perc1.note_events.setattrs(pitch=0)
    cco_perc2.note_events.setattrs(pitch=0)
    cco_perc3.note_events.setattrs(pitch=0)
    cco_perc3.cells[-2].note_events[0].tag("\\<")
    cco_perc3.note_events[-1].tag("f")
    s.extend_from(cco_perc1, cco_perc2, cco_perc3)

    riffs_block = short_block.ChordsToSegmentBlock(
        selectable=sb.with_only("riff", ).segments[0],
        sort_chords=True,
    )

    # TO DO: add ranges
    # =======================================================

    trumpet_mute_outs = ImaginarySegment(
        ImaginaryCell(rhythm=(-4, )).eps(0, "mute out")())
    s.staves["ooa_trumpet"].append(trumpet_mute_outs())
    s.staves["cco_trumpet"].append(trumpet_mute_outs())

    harp1_riff = lambda_segment.LambdaSegment(
        sb.with_only("riff", ),
        fabric_staves=("harp1", ),
        tag_events={0: ("mf", )},
        func=lambda x: x,
    )
    harp1_riff.cells[:16].setattrs(respell="sharps")

    # TO DO: model this pattern... already used multiple times!
    poke_harp1 = []
    next_include = False
    for i, e in enumerate(harp1_riff.events):
        e_pitch = e.pitch
        if len(e_pitch) > 1 and abs(e_pitch[0] - e_pitch[1]) == 12:
            next_include = True
            poke_harp1.append(i)
        elif next_include:
            poke_harp1.append(i)
            next_include = False
        else:
            next_include = False
    harp1_riff.segments[0].poke("events", *poke_harp1)

    piano_riff = lambda_segment.LambdaSegment(
        sb.with_only("riff"),
        fabric_staves=(
            "piano1",
            "piano2",
        ),
        tag_all_note_events=(".", ),
        ranges=pitch_ranges.LOW_TO_HIGH_RANGES,
        assign_pitches_from_selectable=True,
        func=lambda x: x.eps(0, "bass")(),
        funcs=(
            lambda x: x.eps(40, "treble")(136, "8va")(151, "8va!")(),
            lambda x: x.eps(0, "8vb")(23, "8vb!")(112, "treble")(),
        ))
    piano_riff.staves["piano1"].note_events[-1].pitch += 12
    piano_riff.staves["piano1"].phrases[:8].apply(lambda x: x.t(12))
    piano_riff.staves["piano2"].phrases[8:].apply(lambda x: x.t(-12))

    pizz = lambda_segment.LambdaSegment(
        sb.with_only("chords"),
        ranges=pitch_ranges.LOW_TO_HIGH_RANGES,
        fabric_staves=instrument_groups.get_instruments("cco_strings"),
        mask_staves=("cco_bass", ),
        assign_pitches_from_selectable=True,
        func=lambda x: x.transformed(calliope.StandardDurations()))
    pizz.staves["cco_viola"].note_events[0].tag("pizz")

    constant_pluck = osti.Osti(
        sb,
        fabric_staves=instrument_groups.get_instruments(
            "ooa_guitar", "ooa_strings"),
        ranges=pitch_ranges.LOW_TO_HIGH_RANGES,
        osti_pulse_duration=1,
        osti_cell_length=4,
        osti_cell_count=9,
    )
    for st in constant_pluck.staves:
        st.segments[0].eps(0, "mf", "pizz, distorted")()

    s.extend_from(
        harp1_riff,
        piano_riff,
        pizz,
        drum_rhythm2,
        constant_pluck,
    )
    # =======================================================

    # BARS 1-6

    opening_bass = lambda_segment.LambdaSegment(
        sb.with_only("bass_line"),
        assign_pitches_from_selectable=True,
        # ranges=pitch_ranges.PitchRanges(pitch_ranges.BOTTOM_SEQ),
        fabric_staves=("ooa_bassoon", "cco_bassoon", "ooa_trombone",
                       "cco_trombone", "ooa_bass_guitar", "cco_bass"),
        # tag_events = {0:("mf", "pizz")},
        # func = lambda x: x.only_first("cells",7).bookend_pad(0,3),
        # func = lambda x: x.crop("cells",1),
        func=lambda x: x.only_first("cells", 14).transformed(
            calliope.StandardDurations()),
        funcs=(
            lambda x: bass_artics(x),
            lambda x: bass_artics(x),
            lambda x: bass_artics(x.poke("cells", 7, 8, 10, 11)),
            lambda x: bass_artics(x.poke("cells", 7, 8, 10, 11)),
            lambda x: x,
            lambda x: x.eps(1, "pizz")(),
        ))
    for st in opening_bass.staves:
        st.note_events[0].tag("f")

    s.extend_from(opening_bass, )

    # # =======================================================
    wind_cloud_4_5 = lambda_segment.LambdaSegment(
        lib("rock_grid_g2_c4_5"),
        fabric_staves=(
            "ooa_flute",
            "cco_flute1",
            "cco_flute2",
            "ooa_clarinet",
            "cco_clarinet1",
            "cco_clarinet2",
        ),
        # tag_events = {0:("mp", "\\<",), 7:("mf",)},
        # assign_pitches_from_selectable = True,
        # selectable_start_beat = 16*4,
        # func = lambda x: x.slur_cells().bookend_pad(2,3),
        # func = lambda x: x.crop("cells",1),
        bookend_beats=(7, 0),
        tag_all_note_events=("-", ),
        tag_events={
            0: ("mp", "\\<"),
            -1: (".", "f")
        },
        func=lambda x: x,
    )
    sax_opening_driving = driving_off.DrivingOff(
        sb,
        ranges=pitch_ranges.HIGH_TO_LOW_RANGES,
        fabric_staves=instrument_groups.get_instruments("sax", ),
        bookend_beats=(6, 3),
    )

    s.extend_from(
        wind_cloud_4_5,
        sax_opening_driving,
    )

    s.fill_rests(beats=7 * 4)
    # # =======================================================
    cloud_16_17 = lib("rock_grid_g2_c16_17")
    wind_cloud_16_17 = lambda_segment.LambdaSegment(
        cloud_16_17,
        fabric_staves=(
            "ooa_flute",
            "ooa_clarinet",
            "ooa_alto_sax1",
            "ooa_alto_sax2",
            "ooa_tenor_sax",
            "ooa_bari_sax",
        ),
        tag_all_note_events=("-", ),
        tag_events={
            1: ("mp", "\\<"),
            -1: (".", "f")
        },
        func=lambda x: x.bookend_pad(3, 0),
    )
    brass_midpoint_driving = driving_off.DrivingOff(
        sb,
        selectable_start_beat=(7 * 4),
        ranges=pitch_ranges.MID_RANGES,
        fabric_staves=instrument_groups.get_instruments("brass", ),
        bookend_beats=(2, 0),
    )

    s.extend_from(
        wind_cloud_16_17,
        brass_midpoint_driving,
    )

    s.fill_rests(beats=9 * 4)
    # # =======================================================
    # BAR 10+
    # # =======================================================
    mallets_improv1 = improv.Improv(
        sb,
        fabric_staves=("ooa_mallets", ),
        improv_times=3,
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=9 * 4,
        # pitch_selectable_indices = (
        #     (0,1,3,5),
        #     ),
    )
    mallets_improv2 = improv.Improv(
        sb,
        instruction="",
        fabric_staves=("ooa_mallets", ),
        improv_times=4,
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=12 * 4,
        # pitch_selectable_indices = (
        #     (0,2,4,5),
        #     ),
    )
    mallets_improv3 = improv.Improv(
        sb,
        instruction="",
        fabric_staves=("ooa_mallets", ),
        improv_times=3,
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=16 * 4,
        # pitch_selectable_indices = (
        #     (0,2,4,5),
        #     ),
    )
    s.extend_from(mallets_improv1, mallets_improv2, mallets_improv3)

    flute_high_swells = staggered_swell.StaggeredSwells(
        sb,
        low_dynamic="mp",
        swell_dynamic="mf",
        cell_count=1,
        phrase_count=5,
        swell_duration=8,
        selectable_start_beat=9 * 4,
        # swell_split_ratios = (
        #     1/2,
        #     )
        swell_staggers=(
            (0, 4),
            (2, 2),
            (3, 1),
            # (0.5,0.5),
            # (1,0)
        ),
        fabric_staves=(
            "cco_flute1",
            "cco_flute2",
            "ooa_flute",
        ),
    )
    s.extend_from(flute_high_swells, )

    s.fill_rests(beats=12 * 4)
    # # =======================================================
    cloud_26_31 = lib("rock_grid_g2_c26_31")
    wind_cloud_26_31 = lambda_segment.LambdaSegment(
        cloud_26_31,
        fabric_staves=(
            "ooa_clarinet",
            "ooa_alto_sax1",
            "ooa_alto_sax2",
            "ooa_tenor_sax",
            "ooa_bari_sax",
            "ooa_bassoon",
        ),
        tag_all_note_events=("-", ),
        tag_events={
            0: ("mf", "\\<"),
            -1: (".", "f")
        },
        bookend_beats=(3, 1))

    s.extend_from(wind_cloud_26_31, )

    # # =======================================================
    # BAR 16+
    # s.fill_rests(beats=15*4)

    hits_final = lambda_segment.LambdaSegment(
        sb.with_only("chords"),
        ranges=pitch_ranges.HIGHISH_TO_MID_RANGES,
        fabric_staves=instrument_groups.get_instruments(
            "ooa_brass", "ooa_strings") + ("ooa_guitar", "ooa_bass_guitar"),
        assign_pitches_from_selectable=True,
        selectable_start_beat=15 * 4,
        func=lambda x: x.with_only("cells", 32, 33).bookend_pad(3, 1),
        tag_all_note_events=(">", ))
    for st in hits_final.staves["ooa_violin1", "ooa_violin2", "ooa_cello1",
                                "ooa_cello2"]:
        st.note_events[0].tag("arco, distorted")
    s.extend_from(hits_final)

    s.fill_rests(beats=16 * 4)
    strings_improv = improv.Improv(
        sb.with_only("high_drones"),
        fabric_staves=instrument_groups.get_instruments("ooa_strings", ),
        improv_times=3,
        ranges=pitch_ranges.HIGHISH_RANGES,
        selectable_start_beat=16 * 4,
    )
    s.extend_from(strings_improv)

    # # =======================================================
    # adjust for bass 8va
    for bass_seg in s.staves["cco_bass"].segments:
        bass_seg.transformed(calliope.Transpose(interval=12))

    s.fill_rests()
    # s.remove(s.staff_groups["short_score"])

    for staff in s.staves:
        # staff.phrases.transformed(calliope.Label())
        # staff.lines.transformed(calliope.Label())
        if segs := staff.segments:
            main_seg = segs[0]
            for next_seg in list(segs[1:]):
                main_seg.extend(next_seg)
                next_seg.parent.remove(next_seg)
            main_seg.rehearsal_mark_number = 8
            main_seg.compress_full_bar_rests = True