Shuffling and fading harmonics
In this example, we will use some of auxjad’s classes to manipulate some musical material using
the auxjad.Shuffler and auxjad.Fader classes.
First, we start by importing both abjad and auxjad.
>>> import abjad
>>> import auxjad
Let’s now create a container with some arbitrary material to be manipulated. Let’s use the class
auxjad.ArtificialHarmonic as well as some chords and rests.
>>> container = abjad.Container([
... auxjad.ArtificialHarmonic(r"<ef' af'>4"),
... auxjad.ArtificialHarmonic(r"<b e'>8."),
... auxjad.ArtificialHarmonic(r"<g c'>16", is_parenthesized=True),
... abjad.Rest(r"r4"),
... abjad.Chord([-5, 8, 9], (1, 8)),
... auxjad.ArtificialHarmonic(r"<d' a'>8", is_parenthesized=True),
... ])
>>> abjad.show(container)
The spelling of the chord <g af' a'> could be improved. This can be done by using
auxjad.mutate.respell_augmented_unisons(). Auxjad automatically adds this mutation as an extension
method to abjad.mutate so it can also be accessed via abjad.mutate.respell_augmented_unisons().
>>> abjad.mutate.respell_augmented_unisons(container[:])
>>> abjad.show(container)
Let’s now use this material as input for auxjad.Shuffler. This class will randomly shuffle
the logical ties of the input container.
>>> shuffler = auxjad.Shuffler(container,
... disable_rewrite_meter=True,
... )
We can now use the method shuffle_n() to generate some measures of shuffled
logical ties.
>>> staff = abjad.Staff()
>>> notes = shuffler.shuffle_n(4)
>>> staff.append(notes)
>>> abjad.show(staff)
We can now grab the last window output by shuffler and use it as the input container of a
auxjad.Fader. When its property mode is set to "out", it will
remove a logical tie one by one at each iteration. Note how auxjad.Fader removes the notes
of chords one by one, but consider an auxjad.ArtificialHarmonic as a single note.
>>> container = abjad.Container(shuffler.current_window)
>>> fader = auxjad.Fader(container, mode="out")
>>> notes = fader.output_all()
>>> staff.append(notes)
>>> abjad.show(staff)
Notice how the time signature has been repeated. While the method output_all()
takes care of repeated time signatures, dynamics, and clefs, consecutive calls may result in
repetitions. But we can simply use auxjad.mutate.remove_repeated_time_signatures() to take care of
that for us. This function is also available as the extension method
abjad.mutate.remove_repeated_time_signatures(), which Auxjad automatically adds to abjad.mutate.
To finalise the score, let’s remove the last empty measure and add a final bar line.
>>> abjad.mutate.remove_repeated_time_signatures(staff[:])
>>> staff.pop(-1)
>>> score = abjad.Score([staff])
>>> score.add_final_bar_line()
>>> abjad.show(score)