annotations, identifiers, tags, names

16 views
Skip to first unread message

Davi Raubach Tuchtenhagen

unread,
May 4, 2021, 10:07:15 AM5/4/21
to abjad...@googlegroups.com
Hello,
I am working on my Abjad library and I need to have an argument that identifies different timespans, durations, rmakers stack (makers) and containers.
The idea is, for example, to check if the durations' argument is the same as maker's argument, if true the function appends the generated rhythm maker(durations) to a container identified with the same argument. I am using this type of comparison in different methods. For example, to write different pitches to different materials.
The thing is that I am using different types of arguments:

  • abjad.AnnotatedTimespan.annotation;
  • my own Duration class that is a child of abjad.Duration and adds an annotation argument;
  • rmakers.stack.tag
  • abjad.Container.tag (maybe I should use identifier or name here)
  • for pitches I put them in a dictionary:
pitches = {
    "material_01": abjad.PitchSegment("c' d'"),
    "material_02": abjad.PitchSegment("e' f'"),}
and I use the dictionary key to access the identified pitches.

It seems to me that use tag is the wrongest.
I don’t know if this is too bad. Anyway, I think you may have some insights about it. Should I standardize? How?
Thank you,
Davi Raubach

Trevor Bača

unread,
May 4, 2021, 3:59:05 PM5/4/21
to abjad...@googlegroups.com
Hi Davi,

It sounds like the challenge is making a type of comparison? Can you send a MWE showing an example of comparison that you can't get to work?

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/CABcTPwMKa0-tdUZRuWrcvBXwrod%2BQKWJKcp4DK3xxpuZSxmrCw%40mail.gmail.com.


--

Davi Raubach Tuchtenhagen

unread,
May 4, 2021, 4:48:47 PM5/4/21
to abjad...@googlegroups.com
Sure.
I will try an example.
I said "arguments" but I think what I mean is "attribute" (I am not used to the programming terms).
Here I compare annotation and tag. It sounds like a bad idea since this is not exactly the function of the tag I think.

import abjad
import muda  # my library
from abjadext import rmakers

rmaker01 = rmakers.stack(
    rmakers.talea([2, -1], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
    tag=abjad.Tag("mat01"),)
rmaker02 = rmakers.stack(
    rmakers.talea([1, -2], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
    tag=abjad.Tag("mat02"),)
makers = [rmaker01, rmaker02]

annotated_divisions = [
    muda.AnnotatedDuration((1, 2), annotation="mat01"),
    muda.AnnotatedDuration((1, 2), annotation="mat02")
]

container = abjad.Container()
for division in annotated_divisions:
    for maker in makers:
        if maker.tag.string == division.annotation:
            selection = maker([division])
            container.append(abjad.Container(selection, tag=maker.tag))
lilypond_file = abjad.LilyPondFile(items=[container])
abjad.persist.as_ly(lilypond_file, "example.ly")


\version "2.20.0"   %! abjad.LilyPondFile._get_format_pieces()
\language "english" %! abjad.LilyPondFile._get_format_pieces()

{
    { %! mat01
        \times 8/9 { %! mat01
            c'8 %! mat01
            r16 %! mat01
            c'8 %! mat01
            r16 %! mat01
            c'8 %! mat01
            r16 %! mat01
        } %! mat01
    } %! mat01
    { %! mat02
        \times 8/9 { %! mat02
            c'16 %! mat02
            r8 %! mat02
            c'16 %! mat02
            r8 %! mat02
            c'16 %! mat02
            r8 %! mat02
        } %! mat02
    } %! mat02
}

It's working. But, my question is about it being a good idea to use the tag as an identifier or as an annotation.
Maybe there is something I am missing about identify elements in the score.
Thank you!
Davi

Davi Raubach Tuchtenhagen

unread,
May 4, 2021, 4:59:14 PM5/4/21
to abjad...@googlegroups.com
Just to make it reproducible:

import abjad
from abjadext import rmakers

class AnnotatedDuration(abjad.Duration):
    def __new__(cls, *arguments, **kwargs):
        return super().__new__(cls, arguments[0])

    def __init__(self, *arguments, **kwargs):
        self.arguments = arguments
        self.annotation = kwargs.get('annotation')

rmaker01 = rmakers.stack(
    rmakers.talea([2, -1], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
    tag=abjad.Tag("mat01"),)
rmaker02 = rmakers.stack(
    rmakers.talea([1, -2], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
    tag=abjad.Tag("mat02"),)
makers = [rmaker01, rmaker02]

annotated_divisions = [
    AnnotatedDuration((1, 2), annotation="mat01"),
    AnnotatedDuration((1, 2), annotation="mat02")
]

container = abjad.Container()
for division in annotated_divisions:
    for maker in makers:
        if maker.tag.string == division.annotation:
            selection = maker([division])
            container.append(abjad.Container(selection, tag=maker.tag))
lilypond_file = abjad.LilyPondFile(items=[container])
abjad.persist.as_ly(lilypond_file, "example.ly")

Trevor Bača

unread,
May 5, 2021, 11:19:07 AM5/5/21
to abjad...@googlegroups.com

Hi Davi,

You can make things really easy by just ignoring Abjad’s tags and annotations. They’re not really fully documented features anyway. No need to subclass anything either. Just use Python’s built-in lists, dictionaries and tuples. One example might look like this:

maker_01 = rmakers.stack(
    rmakers.talea([2, -1], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
)

maker_02 = rmakers.stack(
    rmakers.talea([1, -2], 16, extra_counts=[1]),
    rmakers.extract_trivial(),
)

makers = {
    "01": maker_01,
    "02": maker_02,
}

commands = [
    ((1, 2), "01"),
    ((1, 2), "02"),
]

voice = abjad.Voice(name="Voice_1")
for command in commands:
    duration, name = command
    maker = makers[name]
    selection = maker([duration])
    voice.append(selection)

Then:

lilypond_file = abjad.LilyPondFile(items=[voice])
string = abjad.lilypond(lilypond_file)
print(string)
\version "2.23.1"
\language "english"

\context Voice = "Voice_1"
{
    \times 8/9
    {
        c'8
        r16
        c'8
        r16
        c'8
        r16
    }
    \times 8/9
    {
        c'16
        r8
        c'16
        r8
        c'16
        r8
    }
}

And:

abjad.show(lilypond_file)

makers.png


--
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.

Davi Raubach Tuchtenhagen

unread,
May 5, 2021, 1:26:29 PM5/5/21
to abjad...@googlegroups.com
Hi Trevor, 

That’s much better.
Thank you very much!

Davi

<makers.png>

Reply all
Reply to author
Forward
0 new messages