Voices
======


Making a voice from a LilyPond input string
-------------------------------------------

You can make an Abjad voice from a LilyPond input string:

<abjad>
voice = Voice("c'8 d'8 e'8 f'8 g'8 a'8 b'4 c''1")
show(voice)
</abjad>


Making a voice from a list of other Abjad components
----------------------------------------------------

You can also make a voice from a list of other Abjad components:

<abjad>
components = [Tuplet(Fraction(2, 3), "c'4 d'4 e'4"), Note("f'2"), Note("g'1")]
voice = Voice(components)
show(voice)
</abjad>


Understanding the interpreter representation of a voice
-------------------------------------------------------

The interpreter representation of an Abjad voice contains three parts:

<abjad>
voice
</abjad>

``Voice`` tells you the voice's class.

``3`` tells you the voice's length (which is the number of
top-level components the voice contains).

Curly braces ``{`` and ``}`` tell you that the music inside the voice is
interpreted sequentially rather than simultaneously.


Inspecting the LilyPond format of a voice
-----------------------------------------

Get the LilyPond input format of any Abjad object with ``lilypond_format``:

<abjad>
voice.lilypond_format
</abjad>

Use ``f()`` as a short-cut to print the LilyPond format of any Abjad object:

<abjad>
f(voice)
</abjad>


Selecting the music in a voice
------------------------------

Slice a voice to select its components:

<abjad>
voice[:]
</abjad>


Inspecting a voice's leaves
---------------------------

Get the leaves in a voice with ``select_leaves()``:

<abjad>
voice.select_leaves()
</abjad>


Getting the length of a voice
-----------------------------

The length of a voice is defined equal to the number of top-level components
the voice contains.

Get the length of a voice with ``len()``:

<abjad>
len(voice)
</abjad>


Inspecting duration
-------------------

Use the inspector to get the duration of a voice:

<abjad>
inspect(voice).get_duration()
</abjad>


Adding one component to the end of a voice
------------------------------------------

Add one component to the end of a voice with ``append()``:

<abjad>
voice.append(Note("af'2"))
show(voice)
</abjad>

You can also use a LilyPond input string:

<abjad>
voice.append("bf'2")
show(voice)
</abjad>


Adding many components to the end of a voice
--------------------------------------------

Add many components to the end of a voice with ``extend()``:

<abjad>
notes = [Note("g'4"), Note("f'4")]
voice.extend(notes)
show(voice)
</abjad>

You can also use a LilyPond input string:

<abjad>
voice.extend("e'4 ef'4")
show(voice)
</abjad>


Finding the index of a component in a voice
-------------------------------------------

Find the index of a component in a voice with ``index()``:

<abjad>
notes[0]
</abjad>

<abjad>
voice.index(notes[0])
</abjad>


Removing a voice component by index
-----------------------------------

Use ``pop()`` to remove the last component of a voice:

<abjad>
voice.pop()
show(voice)
</abjad>


Removing a voice component by reference
---------------------------------------

Remove voice components by reference with ``remove()``:

<abjad>
voice.remove(voice[-1])
show(voice)
</abjad>


Naming voices
-------------

You can name Abjad voices:

<abjad>
voice.name = 'Upper Voice'
</abjad>

Voice names appear in LilyPond input:

<abjad>
f(voice)
</abjad>

But not in notational output:

<abjad>
show(voice)
</abjad>


Changing the context of a voice
-------------------------------

The context of a voice is set to ``'Voice'`` by default:

<abjad>
voice.context_name
</abjad>

But you can change the context of a voice if you want:

<abjad>
voice.context_name = 'SpeciallyDefinedVoice'
</abjad>

<abjad>
voice.context_name
</abjad>

<abjad>
f(voice)
</abjad>

Change the context of a voice when you have defined a new LilyPond context
based on a LilyPond voice.
