How to use scamp - 10 common examples

To help you get started, we’ve selected a few scamp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcTheSpark / scamp / scamp / score.py View on Github external
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")
github MarcTheSpark / scamp / scamp / score.py View on Github external
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")
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
# if there's a colon, it represents a key / value pair, e.g. "articulation: staccato"
                if ":" in note_property:
                    colon_index = note_property.index(":")
                    key, value = note_property[:colon_index].replace(" ", "").lower(), \
                                 note_property[colon_index+1:].strip().lower()
                else:
                    # otherwise, leave the key undecided for now
                    key = None
                    value = note_property.strip().lower()

                # split values into a list based on the slash delimiter
                values = [x.strip() for x in value.split("/")]

                if key is None:
                    # if we weren't given a key/value pair, try to find it now
                    if values[0] in PlaybackAdjustmentsDictionary.all_articulations:
                        key = "articulations"
                    elif values[0] in PlaybackAdjustmentsDictionary.all_noteheads:
                        key = "noteheads"
                    elif values[0] in PlaybackAdjustmentsDictionary.all_notations:
                        key = "notations"
                    elif values[0] in ("#", "b", "sharps", "flats"):
                        key = "spelling_policy"
                    elif "volume" in values[0] or "pitch" in values[0] or "length" in values[0]:
                        key = "playback_adjustments"
                    else:
                        raise ValueError("Note property {} not understood".format(note_property))

                if key in "articulations":  # note that this allows the singular "articulation" too
                    for value in values:
                        if value in PlaybackAdjustmentsDictionary.all_articulations:
                            properties_dict["articulations"].append(value)
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
def from_list(cls, properties_list):
        assert isinstance(properties_list, (list, tuple))
        properties_dict = cls()

        for note_property in properties_list:
            if isinstance(note_property, NotePlaybackAdjustment):
                properties_dict["playback_adjustments"].append(note_property)
            elif isinstance(note_property, str):
                # if there's a colon, it represents a key / value pair, e.g. "articulation: staccato"
                if ":" in note_property:
                    colon_index = note_property.index(":")
                    key, value = note_property[:colon_index].replace(" ", "").lower(), \
                                 note_property[colon_index+1:].strip().lower()
                else:
                    # otherwise, leave the key undecided for now
                    key = None
                    value = note_property.strip().lower()

                # split values into a list based on the slash delimiter
                values = [x.strip() for x in value.split("/")]

                if key is None:
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def _play_thread(child_clock):
            note_iterator = self.get_note_iterator(start_beat, stop_beat, selected_voices)
            self.get_note_iterator(start_beat, stop_beat)
            try:
                current_note = next(note_iterator)
            except StopIteration:
                return

            child_clock.wait(current_note.start_beat - start_beat)

            while True:
                assert isinstance(current_note, PerformanceNote)
                if note_filter is not None:
                    note_filter(current_note).play(instrument, clock=child_clock, blocking=False)
                else:
                    current_note.play(instrument, clock=child_clock, blocking=False)

                try:
                    next_note = next(note_iterator)
                    child_clock.wait(next_note.start_beat - current_note.start_beat)

                    current_note = next_note
                except StopIteration:
                    # when done, wait for the children to finish
                    child_clock.wait(current_note.length_sum())
                    return
github MarcTheSpark / scamp / scamp / score.py View on Github external
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:
github MarcTheSpark / scamp / scamp / score.py View on Github external
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
github MarcTheSpark / scamp / scamp / score.py View on Github external
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())
github MarcTheSpark / scamp / scamp / score.py View on Github external
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)
github MarcTheSpark / scamp / scamp / score.py View on Github external
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