def alloc_voice(self, chan, note): """ Return None if there are no available voices or if """ if self.m_voices: voice = self.m_voices.pop() else: return None # first, if NOTE is already playing on channel CHAN, we need # to stop it and free the voice used for that. if note in self.m_channel_dict[chan]: solfege_c_midi.seq_stop_note(self.m_devnum, self.m_channel_dict[chan][note], note, 100) self.free_voice(chan, note) # the instrumnet we want the voice to use p = self.m_channel_patches[chan] if self.m_voice_patches[voice] != p: # we need to set the patch for this voice solfege_c_midi.seq_set_patch(self.m_devnum, voice, p) self.m_voice_patches[voice] = p assert note not in self.m_channel_dict[chan] self.m_channel_dict[chan][note] = voice return voice
def reset(self): # list of available voices, number depends on the soundcard. # AWE32 and GUS has 32, OPL3: 18, OPL2: 9 self.m_voices = list(range(self.m_num_voices)) # dictionary remembering what instrument we have set on the # different channels. There are by definition NUM_CHANNELS channels self.m_channel_patches = {} for c in range(self.NUM_CHANNELS): self.m_channel_patches[c] = 0 # dictionary remembering what instrument has been set for all # the voices. self.m_voice_patches = {} for n in range(self.m_num_voices): self.m_voice_patches[n] = 0 solfege_c_midi.seq_set_patch(self.m_devnum, n, 0) # self.m_channel_dict = {} for x in range(self.NUM_CHANNELS): self.m_channel_dict[x] = {}