Abjad / abjad

Abjad is a Python API for building LilyPond files. Use Abjad to make PDFs of music notation.
https://abjad.github.io
GNU General Public License v3.0
234 stars 41 forks source link

Parsing Error with '##' Symbol in Abjad Scheme #1578

Closed jacopogrecodalceo closed 3 months ago

jacopogrecodalceo commented 5 months ago

I am currently developing a Csound to score conversion tool using Abjad. The implementation involves using the syntax f"s4*##e{onset} {note} 4*##e{dur}" inside Abjad in order to create a proportional notation score. However, attempting to use this syntax results in a parsing error:

File "/opt/homebrew/lib/python3.11/site-packages/abjad/parsers/scheme.py", line 340, in p_variable__IDENTIFIER
    raise Exception(p, "AAA")
Exception: (<ply.yacc.YaccProduction object at 0x102e3a410>, 'AAA’)

It seems that Abjad is having trouble parsing the '##' symbol. Could you confirm this issue and provide guidance on resolving or working around this parsing problem? Thanks.

Code exemple:

import abjad

onset = 1.14
note = abjad.Note(60, (1, 2)).written_pitch.name
dur = 3

voice = abjad.Voice(f's4*##e{onset} {note} 4*##e{dur}')
staff = abjad.Staff([voice])
score = abjad.Score([staff])

abjad.show(score)
trevorbaca commented 3 months ago

Abjad containers are things like abjad.Voice, abjad.Staff, abjad.Score.

There are a couple of different ways of initializing Abjad containers.

You can make Abjad notes, rests, chords and pass those into Abjad containers:

note = abjad.Note("c'4")
voice = abjad.Voice([note])

You can also type LilyPond code into a string, and pass that string into an Abjad container:

voice = abjad.Voice("c'4")

This works because the string "c'4" is valid LilyPond input.

But this breaks ...

voice = abjad.Voice(f's4*##e{onset} {note} 4*##e{dur}')

... because the string f's4*##e{onset} {note} 4*##e{dur}' isn't valid LilyPond input.

jacopogrecodalceo commented 3 months ago

Thank you very much @trevorbaca for your answer!!

Maybe I'm wrong on something, but this lilypond file works for me:

\version "2.24.0"

\score {
    \new Voice {
        s4*##e0.0 g 4*##e0.534 _"-10.82¢"
        }
}