Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Issue with changing note heads

7 views
Skip to first unread message

Tsubasa Tanaka

unread,
Sep 11, 2024, 9:56:46 AM9/11/24
to abjad-user
Hello,

I'm a beginner in Abjad.
I wonder how to replace the note heads with the notations for harmonics, drum notations, etc.

For example, I refer to the following lilypond document on special note heads:
https://lilypond.org/doc/v2.25/Documentation/notation/special-note-heads.html

Here is the code I have written:
---------------
import abjad

pitches1 = [0, 2, 4]
duration = abjad.Duration(1, 2)
notes1 = [abjad.Note(pitch, duration) for pitch in pitches1]
voice1 = abjad.Voice(notes1, name="Voice1")

for note in notes1:
    abjad.override(note).NoteHead.color = "#red"
    abjad.override(note).NoteHead.style = '#cross'# or harmonics, semipetrucci, DrumNoteHead("snare"), etc.
    note.note_head.is_parenthesized = True

staff = abjad.Staff([voice1])

abjad.show(staff)
---------------
The issue is that setting NoteHead.style doesn't work, although no errors occur.
Could you assist me in resolving this issue? 

Tsubasa Tanaka

Davi Raubach

unread,
Sep 11, 2024, 11:58:42 AM9/11/24
to abjad...@googlegroups.com, Tsubasa Tanaka
Hello Tsubasa Tanaka,

Override is a method to do that. The problem with your example is
that "#cross" should be "#'cross".

#+begin_src python
pitches1 = [0, 2, 4]
duration = abjad.Duration(1, 2)
notes1 = [abjad.Note(pitch, duration) for pitch in pitches1]
voice1 = abjad.Voice(notes1, name="Voice1")

for note in notes1:
abjad.override(note).Voice.NoteHead.style = ("#'cross")

abjad.show(voice1)

#+end_src

You can also use ~tweak~:

#+begin_src python
for note in notes1:
abjad.tweak(note.note_head, r"\tweak style #'harmonic")
#+end_src

Tweak is specially designed to affect specific objects, as you can
read in the LilyPond manual:

#+begin_quote
This should be used when several objects occur at the same musical
moment, but you only want to change the properties of selected
ones, such as a single note within a chord. Using \override would
affect all the notes within a chord, whereas \tweak affects just
the following item in the input stream.
#+end_quote

https://lilypond.org/doc/v2.23/Documentation/learning/tweaking-methods

Best regards,

Davi
Reply all
Reply to author
Forward
0 new messages