Skip to content
charlies-world edited this page Oct 31, 2021 · 5 revisions

So we've learned how to group Notes into Measures, and now we're going to group Measures in a similar fashion - into Sections.

Adding Measures to a Voice

The process is identical to adding a Note to a Measure:

#create Notes...

measure_one = Measure()
measure_two = Measure()
measure_three = Measure()

#add Notes to the Measures...

voice = Voice()
voice.add_measure(measure_one)
voice.add_measure(measure_two)
voice.add_measure(measure_three)

And in the same way as Notes in Measures, the Measures will be written in the order they were added to the Voice.

Other Functions

Again we see parallels to the additional functions in a Measure. Using the Voice we made above:

print(voice.get_number_of_measures()) # 3

retrieved_measure = voice.get_measure_at_index(2)
print(retrieved_measure.get_number_of_beats()) # prints the number of notes and rests in the third measure added

A new set of functions relate to a new field on Voice: name. This is not required, but we are able to set a unique name to each Voice. When the MIDI file is placed into to a DAW, the name we set will show up as the name for the MIDI track, so it can be useful to quickly identify what each Voice is.

voice_one.set_name('Trombone')
voice_two.set_name('that really quirky sound')

print(voice_one.get_name()) # Trombone
print(voice_two.get_name()) # that really quirky sound

Moving On

Now we know how to make Notes, how to group Notes into Measures, and how to group Measures into a Voice. In the next section, we will be - you guessed it - grouping Voices together into one unit: a Section.

Next section - Sections