Changing notes to rests
=======================


Making a repeating pattern of notes
-----------------------------------

It is easy to make a repeating pattern of notes.

Multiplying the list ``[0, 2, 4, 9, 7]`` by ``4`` creates a new list of twenty
pitch numbers.

The call to ``notetools.make_notes()`` creates our notes:

<abjad>
pitch_numbers = 4 * [0, 2, 4, 9, 7]
duration = Duration(1, 8)
notes = notetools.make_notes(pitch_numbers, duration)
staff = Staff(notes)
show(staff)
</abjad>


Iterating the notes in a staff
------------------------------

Use ``iterationtools`` to iterate the notes in any expression:

<abjad>
for note in iterationtools.iterate_notes_in_expr(staff):
    note
</abjad>


Enumerating the notes in a staff
--------------------------------

Use Python's built-in ``enumerate()``
function to enumerate the elements in any iterable:

<abjad>
generator = iterationtools.iterate_notes_in_expr(staff)
for i, note in enumerate(generator):
    i, note
</abjad>


Changing notes to rests by index
--------------------------------

We can change every sixth note in a our score to a rest like this:

<abjad>
generator = iterationtools.iterate_notes_in_expr(staff)
for i, note in enumerate(generator):
    if i % 6 == 5:
        rest = Rest('r8')
        staff[i] = rest
</abjad>

<abjad>
show(staff)
</abjad>


Changing notes to rests by pitch
--------------------------------

Let's make a new staff:

<abjad>
pitch_numbers = 4 * [0, 2, 4, 9, 7]
duration = Duration(1, 8)
notes = notetools.make_notes(pitch_numbers, duration)
staff = Staff(notes)
show(staff)
</abjad>

Now we can change every D4 to a rest like this:

<abjad>
generator = iterationtools.iterate_notes_in_expr(staff)
for i, note in enumerate(generator):
    if note.sounding_pitch == "d'":
        rest = Rest('r8')
        staff[i] = rest
</abjad>

<abjad>
show(staff)
</abjad>
