-
Notifications
You must be signed in to change notification settings - Fork 0
Sections
The pattern should be familiar by now - Note
s into Measure
s into Voice
s, and now, Voice
s into Section
s. 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.
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 Section
s so that they do start at the same time in the new second Section
).
As always:
print(section.get_number_of_voices()) # 3
retrieved_voice = section.get_voice_at_index(1) # retrieved_voice is voice_two
Similar to Voice
s, we can set unique names to our Section
s:
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 Section
s is also how you are able to create tempo changes.
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
.