Skip to content

Sections

charlies-world edited this page Oct 31, 2021 · 3 revisions

The pattern should be familiar by now - Notes into Measures into Voices, and now, Voices into Sections. This next step is exciting because we go from the monophonic lines all of the previous structures gave us, to being able to have multiple musical parts sound at the same time.

Adding Voices to a Section

Again, nothing new here:

# make notes...
# make measures...

voice_one = Voice()
voice_two = Voice()
voice_three = Voice()

# add measures to voices...

section = Section()
section.add_voice(voice_one)
section.add_voice(voice_two)
section.add_voice(voice_three)

When the MIDI file is written, these three voices will be written so that they are sounding at the same time. Since these are written "vertically," it doesn't matter what order they are added in, but know that they will all start sounding immediately (that is, if you don't want the voices to start at the same time, you will either have to buffer the later starting voice(s) with the appropriate amount of rests at the beginning, or divide the Section into two or more Sections so that they do start at the same time in the new second Section).

Other Functions

As always:

print(section.get_number_of_voices()) # 3
retrieved_voice = section.get_voice_at_index(1) # retrieved_voice is voice_two

Similar to Voices, we can set unique names to our Sections:

section_one.set_identifier('A')
section_two.set_identifier('B')
print(section_one.get_identifier()) # A
print(section_two.get_identifier()) # B

This can be used for your own reference, but it will also have a use when we take a look at the MIDIUtility class.

It is also at this level that we will set the tempo:

section.set_quarter_note_bpm(120)

and now when writing to a MIDI file comPoYse will compute the length of every note in seconds for you so that they can be written to the file. Using different Sections is also how you are able to create tempo changes.

Moving On

We've come a long from just making just a Note, and now we're on to our last level of abstraction - with a Composition.

Next section - Compositions