note = abjad.Note("d''2.")

abjad.show(note)

"""
Explanation: An object-oriented, containerized model of music notation
Abjad extends the Python programming language with an object-oriented, containerized model of common practice music notation. Let's explore the notes, rests and chords that make up the simplest part of Abjad's object model.
Notes
First we'll make a note. It will be a D5 with the duration of a dotted half:
End of explanation
"""


note.written_pitch

note.written_duration

"""
Explanation: Now we can inspect different attributes of our note.
Notice how a dot chains together our note and its attributes:
End of explanation
"""


note.written_pitch = "cs''"

abjad.show(note)

"""
Explanation: We can change our note's pitch like this:
End of explanation
"""


note.written_duration = (1, 2)

abjad.show(note)

"""
Explanation: We can do the same with our note's duration:
End of explanation
"""


rest = abjad.Rest()

abjad.show(rest)

"""
Explanation: Abjad 3.2 implements 311 classes, all documented in the Abjad API.
To look up abjad.Note in the API, open the API.
Then use your browser's search function to look up "Note."
This will bring you to the reference page for abjad.Note.
Rest and chords
We can make rests and chords the same way we made our note:
End of explanation
"""


rest = abjad.Rest("r8..")

abjad.show(rest)

"""
Explanation: We get a default value of a quarter rest.
We can pass in a different duration as a string:
End of explanation
"""


rest = abjad.Rest((7, 32))

abjad.show(rest)

"""
Explanation: Or as a pair of numbers equal to a fraction:
End of explanation
"""


chord = abjad.Chord("<c' e' g'>8.")

abjad.show(chord)

"""
Explanation: Chords work similarly:
End of explanation
"""


skip = abjad.Skip("s8.")

skip

"""
Explanation: LilyPond skips (invisible rests) are also available:
End of explanation
"""


rest.written_duration

chord.written_duration

skip.written_duration

"""
Explanation: And remember, we can get back to the attributes of our leaves using dot chaining syntax.
End of explanation
"""


staff_1 = abjad.Staff("c' d' e' f'")
staff_2 = abjad.Staff("f' e' d' c'")
group = abjad.StaffGroup([staff_1, staff_2])
score = abjad.Score([group])
abjad.show(score)

"""
Explanation: A containerized model of music notation
Abjad implements a containerized model of music notation:
https://abjad.github.io/core_concepts/containerized_model.html
In summary: notes, rests and chords are contained in tuplets, voices, staves and scores; containers may contain each other; and the other elements of music notation are modeled as indicators that attach to notes, rests and chords.
Let's explore.
We'll start by looking at the way notes can be contained in staves, which themselves can be contained in a staff group, itself contained in a score:
End of explanation
"""


start_slur = abjad.StartPhrasingSlur()
stop_slur = abjad.StopPhrasingSlur()
abjad.attach(start_slur, staff_1[0])
abjad.attach(stop_slur, staff_1[3])
abjad.show(score)

"""
Explanation: All other elements of notation are modeled as indicators. We create phrasing slurs, for example, by attaching an abjad.StartPhrasingSlur to one note and a matching abjad.StopPhrasinSlur to another note. Both classes are indicators:
End of explanation
"""


staccato = abjad.Articulation("staccato")
abjad.attach(staccato, staff_2[1])
abjad.show(score)

"""
Explanation: Some indicators are really simple, like abjad.Articulation. Here we use indexing to attach a staccato to the note "at index 1" in staff two. Because Python's indexing starts at 0, it is the second note in staff two that gets the staccato:
End of explanation
"""


for note in staff_1[1:]:
    staccato = abjad.Articulation("staccato")
    abjad.attach(staccato, note)
abjad.show(score)

"""
Explanation: It might be the case that we want to apply the same indicator to a consecutive series of leaves. Note that we can use iteration to do the same thing to multiple components sequentially. Here we use slice notation to attach a staccato to every leaf in staff one, starting with the note "to the right of slice index 1":
End of explanation
"""


notes = [abjad.Note(x, (1, 8)) for x in range(24 + 1)]

staff = abjad.Staff(notes)

abjad.show(staff)

"""
Explanation: Making many notes
We can use anything in Python -- from built-in libraries to any of its thousands of external libraries -- to make notes, rests and chords. Python's list comprehensions allow us to describe collections of objects easily. The following list comprehension means "a list of eighth notes with pitch values from 0 through 24":
End of explanation
"""


numbers = [random.randrange(0,25) for x in range(100)]

"""
Explanation: We can use external libraries, too. Here we generate a hundred random numbers and use them as pitch values. Import Python's built-in random module if you haven't already:
End of explanation
"""


numbers = numbers[:10]

numbers

"""
Explanation: That's a lot of numbers. Let's just use a few of them. We can use list slicing syntax to take the portion of our list. The slice [:10] means "from the beginning up to slice index 10":
End of explanation
"""


notes = [abjad.Note(x, (1, 8)) for x in numbers]
staff = abjad.Staff(notes)
abjad.show(staff)

"""
Explanation: Then we can turn numbers into notes with a list comprehension once again:
End of explanation
"""


half_numbers = [x / 2.0 for x in numbers]

half_numbers

notes = [abjad.Note(x, (1, 8)) for x in half_numbers]
staff = abjad.Staff(notes)
abjad.show(staff)

"""
Explanation: Quartertones are possible, too:
End of explanation
"""


