TENOR15 Example - Reconstructed in 3.10 (DEMO)

21 views
Skip to first unread message

Pedro Faria

unread,
Jul 21, 2022, 9:47:02 AM7/21/22
to abjad-user
Hi! I'm still learning Abjad, but I already love the library so much. it's just so powerful.

In my learning journey, I was trying to replicate the 8 staff example in the TENOR15 article by Baca, Oberholtzer, Trevino and Adan, and I think I suceeded. 

I had to look through this forum stuff like BurnishSpecifier, TieSpecifier, rhythmmakertools, etc (which I'm typing here so that, if anyone searches, they can find this thread);

So, this is the code I arrived at. I'm not sure it's optimized, but the output is identical to the example I wanted to replicate:


def rest_selector(argument, first, period):
    result = abjad.select.tuplets(argument)
    result = abjad.select.get(result, [first], period)
    result = result = [abjad.select.leaf(_, 0) for _ in result]
    return result

def tie_selector(argument):
    result = abjad.select.tuplets(argument)
    result = abjad.select.get(result, [0], 1)
    result = [abjad.select.leaf(_, -1) for _ in result]
    return result


def make_stack(extra_counts, talea_count,first,period):
    stack = rmakers.stack(
        rmakers.talea(talea_count, 16,extra_counts=extra_counts),
        rmakers.force_rest(lambda _: rest_selector(_,first,period)),
        rmakers.beam(),
        rmakers.tie(tie_selector),
        rmakers.extract_trivial(),
    )
    return stack


divisions = [(3, 8), (5,16), (1,4), (3,16),(2,16)]
counts = [0,1,1]
talea_count = [1,2,3]
rhythmic_score = abjad.Score()

for i in range(8):
    a, b = divisions.index((3, 8)), divisions.index((1, 4))
    if a > b:
        a, b = b, a
    period = b-a
    selections = make_stack(counts,talea_count,a,period)(divisions)
    measure = abjad.Staff([abjad.mutate.copy(x) for x in selections], name=f"voice_{i+1}", lilypond_type="RhythmicStaff")
    first_leaf = abjad.select.leaves(measure)[0]
    ts = abjad.TimeSignature((5,4))
    abjad.attach(ts, first_leaf)
    rhythmic_score.append(measure)
    divisions = abjad.sequence.rotate(divisions, 1)
    counts = abjad.sequence.rotate(counts, 1)
    t_count = abjad.sequence.rotate(talea_count, 1)


abjad.show(rhythmic_score)

Pedro Faria

unread,
Jul 21, 2022, 11:20:29 AM7/21/22
to abjad-user
One correction: the last line before the abjad.show call should read:

 talea_count = abjad.sequence.rotate(talea_count, 1)

Pedro Faria

unread,
Jul 21, 2022, 10:20:47 PM7/21/22
to abjad-user
Sorry, also:

divisions = [(3, 8), (5,16), (1,4), (3,16),(2,16)] should be divisions = [(3, 8), (5,16), (1,4), (3,16)]
and
ts = abjad.TimeSignature((5,4)) should be  ts = abjad.TimeSignature((9,8))

Trevor Bača

unread,
Aug 16, 2022, 3:10:05 PM8/16/22
to abjad...@googlegroups.com

Hi Pedro,

Great example; I’ve run Python’s “black” on the code (to prettify it a bit), and added a main method:

import abjad
from abjadext import rmakers

def rest_selector(argument, first, period):
    result = abjad.select.tuplets(argument)
    result = abjad.select.get(result, [first], period)
    result = result = [abjad.select.leaf(_, 0) for _ in result]
    return result

def tie_selector(argument):
    result = abjad.select.tuplets(argument)
    result = abjad.select.get(result, [0], 1)
    result = [abjad.select.leaf(_, -1) for _ in result]
    return result

def make_stack(extra_counts, talea_count, first, period):
    stack = rmakers.stack(
        rmakers.talea(talea_count, 16, extra_counts=extra_counts),
        rmakers.force_rest(lambda _: rest_selector(_, first, period)),
        rmakers.beam(),
        rmakers.tie(tie_selector),
        rmakers.extract_trivial(),
    )
    return stack

def main():
    divisions = [(3, 8), (5, 16), (1, 4), (3, 16)]
    counts = [0, 1, 1]
    talea_count = [1, 2, 3]
    rhythmic_score = abjad.Score()
    for i in range(8):
        a, b = divisions.index((3, 8)), divisions.index((1, 4))
        if a > b:
            a, b = b, a
        period = b - a
        selections = make_stack(counts, talea_count, a, period)(divisions)
        measure = abjad.Staff(
            [abjad.mutate.copy(x) for x in selections],
            name=f"voice_{i+1}",
            lilypond_type="RhythmicStaff",
        )
        first_leaf = abjad.select.leaves(measure)[0]
        ts = abjad.TimeSignature((9, 8))
        abjad.attach(ts, first_leaf)
        rhythmic_score.append(measure)
        divisions = abjad.sequence.rotate(divisions, 1)
        counts = abjad.sequence.rotate(counts, 1)
        talea_count = abjad.sequence.rotate(talea_count, 1)
    return rhythmic_score

if __name__ == "__main__":
    rhythmic_score = main()
    abjad.show(rhythmic_score)

TENOR-2015.png
Thanks for the modernized example, and happy composing with Abjad!

Trevor.


--
You received this message because you are subscribed to the Google Groups "abjad-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to abjad-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/abjad-user/2cf7d971-d7d0-4717-b9fd-14327b14dd0bn%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages