Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if isinstance(abjad_note_or_chord, abjad().Note):
note_head_style = self.properties.noteheads[0]
if note_head_style != "normal":
lilypond_style = get_lilypond_notehead_name(note_head_style)
# the pipe separates out a bit of comment text, which is used when the
# desired notehead can't be displayed
abjad().tweak(abjad_note_or_chord.note_head).style = lilypond_style.split("|")[0]
if len(lilypond_style.split("|")) > 1:
abjad().attach(abjad().LilyPondComment(lilypond_style.split("|")[1]), abjad_note_or_chord)
elif isinstance(abjad_note_or_chord, abjad().Chord):
for chord_member, note_head_style in enumerate(self.properties.noteheads):
if note_head_style != "normal":
lilypond_style = get_lilypond_notehead_name(note_head_style)
abjad().tweak(abjad_note_or_chord.note_heads[chord_member]).style = lilypond_style.split("|")[0]
if len(lilypond_style.split("|")) > 1:
abjad().attach(abjad().LilyPondComment(lilypond_style.split("|")[1]), abjad_note_or_chord)
else:
raise ValueError("Must be an abjad Note or Chord object")
def _set_abjad_note_head_styles(self, abjad_note_or_chord):
if isinstance(abjad_note_or_chord, abjad().Note):
note_head_style = self.properties.noteheads[0]
if note_head_style != "normal":
lilypond_style = get_lilypond_notehead_name(note_head_style)
# the pipe separates out a bit of comment text, which is used when the
# desired notehead can't be displayed
abjad().tweak(abjad_note_or_chord.note_head).style = lilypond_style.split("|")[0]
if len(lilypond_style.split("|")) > 1:
abjad().attach(abjad().LilyPondComment(lilypond_style.split("|")[1]), abjad_note_or_chord)
elif isinstance(abjad_note_or_chord, abjad().Chord):
for chord_member, note_head_style in enumerate(self.properties.noteheads):
if note_head_style != "normal":
lilypond_style = get_lilypond_notehead_name(note_head_style)
abjad().tweak(abjad_note_or_chord.note_heads[chord_member]).style = lilypond_style.split("|")[0]
if len(lilypond_style.split("|")) > 1:
abjad().attach(abjad().LilyPondComment(lilypond_style.split("|")[1]), abjad_note_or_chord)
else:
raise ValueError("Must be an abjad Note or Chord object")
self._set_abjad_note_head_styles(abjad_object)
last_pitch = abjad_object.written_pitch
grace_points = self._get_grace_points()
for t in grace_points:
grace = abjad().Note(self.properties.spelling_policy.resolve_abjad_pitch(self.pitch.value_at(t)), 1 / 16)
# Set the notehead
self._set_abjad_note_head_styles(grace)
# but first check that we're not just repeating the last grace note pitch
if last_pitch != grace.written_pitch:
grace_notes.append(grace)
last_pitch = grace.written_pitch
else:
# This is a simple note
abjad_object = abjad().Note(self.properties.spelling_policy.resolve_abjad_pitch(self.pitch), duration)
# Set the notehead
self._set_abjad_note_head_styles(abjad_object)
# Now we make, fill, and attach the abjad AfterGraceContainer, if applicable
if len(grace_notes) > 0:
for note in grace_notes:
# this signifier, \stemless, is not standard lilypond, and is defined with
# an override at the start of the score
abjad().attach(abjad().LilyPondLiteral(r"\stemless"), note)
grace_container = abjad().AfterGraceContainer(grace_notes)
abjad().attach(grace_container, abjad_object)
else:
grace_container = None
# this is where we populate the source_id_dict passed down to us from the top level "to_abjad()" call
if source_id_dict is not None:
def to_abjad_lilypond_file(self) -> 'abjad().LilyPondFile':
"""
Convert and wrap as a abjad.LilyPondFile object
"""
assert abjad() is not None, "Abjad is required for this operation."
title = self.title if hasattr(self, "title") else None
composer = self.composer if hasattr(self, "composer") else None
abjad_object = self._to_abjad()
lilypond_code = format(abjad_object)
if r"\glissando" in lilypond_code:
for gliss_override in ScoreComponent._gliss_overrides:
abjad().attach(abjad().LilyPondLiteral(gliss_override), abjad_object, "opening")
abjad_lilypond_file = abjad().LilyPondFile.new(
music=abjad_object
)
# if we're actually producing the lilypond file itself, then we put the simpler
# definition of stemless outside of the main score object.
if r"\stemless" in lilypond_code:
abjad_lilypond_file.items.insert(-1, ScoreComponent._outer_stemless_def)
if title is not None:
abjad_lilypond_file.header_block.title = abjad().Markup(title)
if composer is not None:
abjad_lilypond_file.header_block.composer = abjad().Markup(composer)
return abjad_lilypond_file
def show(self) -> None:
"""
Using the abjad.show command, generates and opens a PDF of the music represented by this component
"""
assert abjad() is not None, "Abjad is required for this operation."
abjad().show(self.to_abjad_lilypond_file())
def _to_abjad(self, source_id_dict=None):
if len(self.contents) == 0: # empty voice
return abjad().Voice([abjad().MultimeasureRest(
(self.time_signature.numerator, self.time_signature.denominator)
)])
else:
is_top_level_call = True if source_id_dict is None else False
source_id_dict = {} if source_id_dict is None else source_id_dict
abjad_components = [x._to_abjad(source_id_dict) for x in self.contents]
if is_top_level_call:
for same_source_group in source_id_dict.values():
_join_same_source_abjad_note_group(same_source_group)
return abjad().Voice(abjad_components)
def to_abjad_lilypond_file(self) -> 'abjad().LilyPondFile':
"""
Convert and wrap as a abjad.LilyPondFile object
"""
assert abjad() is not None, "Abjad is required for this operation."
title = self.title if hasattr(self, "title") else None
composer = self.composer if hasattr(self, "composer") else None
abjad_object = self._to_abjad()
lilypond_code = format(abjad_object)
if r"\glissando" in lilypond_code:
for gliss_override in ScoreComponent._gliss_overrides:
abjad().attach(abjad().LilyPondLiteral(gliss_override), abjad_object, "opening")
abjad_lilypond_file = abjad().LilyPondFile.new(
music=abjad_object
)
# if we're actually producing the lilypond file itself, then we put the simpler
# definition of stemless outside of the main score object.
if r"\stemless" in lilypond_code:
abjad_lilypond_file.items.insert(-1, ScoreComponent._outer_stemless_def)
if title is not None:
abjad_lilypond_file.header_block.title = abjad().Markup(title)
if composer is not None:
abjad_lilypond_file.header_block.composer = abjad().Markup(composer)
return abjad_lilypond_file
def _to_abjad(self):
return abjad().StaffGroup([staff._to_abjad() for staff in self.staves])
# abjad().attach(self.time_signature.to_abjad(), abjad_voice[0])
abjad().attach(abjad().LilyPondLiteral(r"\time {}".format(self.time_signature.as_string()), "opening"),
abjad_voice)
if len(self.voices) > 1:
abjad().attach(abjad().LilyPondLiteral(_voice_literals[i]), abjad_voice)
abjad_voice.name = _voice_names[i]
abjad_measure.append(abjad_voice)
abjad_measure.simultaneous = True
if is_top_level_call:
for same_source_group in source_id_dict.values():
_join_same_source_abjad_note_group(same_source_group)
if self.clef is not None:
# attach the clef to the first note of the first voice
abjad().attach(abjad().Clef(self.clef), abjad().select(abjad_measure).leaf(0))
return abjad_measure
if r"\glissando" in lilypond_code:
for gliss_override in ScoreComponent._gliss_overrides:
abjad().attach(abjad().LilyPondLiteral(gliss_override), abjad_object, "opening")
abjad_lilypond_file = abjad().LilyPondFile.new(
music=abjad_object
)
# if we're actually producing the lilypond file itself, then we put the simpler
# definition of stemless outside of the main score object.
if r"\stemless" in lilypond_code:
abjad_lilypond_file.items.insert(-1, ScoreComponent._outer_stemless_def)
if title is not None:
abjad_lilypond_file.header_block.title = abjad().Markup(title)
if composer is not None:
abjad_lilypond_file.header_block.composer = abjad().Markup(composer)
return abjad_lilypond_file