Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def play_midieventstream(self, midieventstream):
     solfege_c_midi.sndctl_seq_reset()
     self.reset()
     solfege_c_midi.seq_start_timer()
     for e in midieventstream:
         if e[0] == midieventstream.TEMPO:
             self.__tempo = (e[1], e[2])
         elif e[0] == midieventstream.NOTE_ON:
             channel, note, vel = e[1:4]
             voice = self.alloc_voice(channel, note)
             if voice is not None:
                 # FIXME ugly hack for percussion. This will break if
                 # we play polyphonic music with very many voices
                 if channel == 9:  # voice == 31:
                     voice = 9
                 solfege_c_midi.seq_start_note(self.m_devnum, voice, note,
                                               vel)
         elif e[0] == midieventstream.NOTE_OFF:
             channel, note, vel = e[1:4]
             voice = self.free_voice(channel, note)
             if voice is not None:
                 # FIXME, see 10 lines up
                 if channel == 9:  # voice == 31:
                     voice = 9
                 solfege_c_midi.seq_stop_note(self.m_devnum, voice, note,
                                              vel)
         elif e[0] == midieventstream.NOTELEN_TIME:
             # 96 is a const, also used in soundcard.initialize that
             # I don't understand.
             solfege_c_midi.seq_delta_time(
                 int(
                     int(96 * e[1]) * 60.0 * self.__tempo[1] /
                     self.__tempo[0]))
         elif e[0] == midieventstream.SET_PATCH:
             self.set_patch(e[1], e[2])
         elif e[0] == midieventstream.BENDER:
             logging.debug("FIXME: DevSequencerSynth.BENDER")
             #solfege_d_midi.seq_bender(self.m_devnum, e[1], e[2])
         elif e[0] == midieventstream.VOLUME:
             logging.debug(
                 "oss_sequencer: seq_set_volume for /dev/sequencer not tested, so it is commented out."
             )
             #m.seq_set_volume(self.m_devnum, e[1], e[2])
         else:
             raise Exception("oss_sequencer: play track error")
     solfege_c_midi.seqbuf_dump()
Ejemplo n.º 3
0
 def play_midieventstream(self, midieventstream):
     solfege_c_midi.sndctl_seq_reset()
     self.reset()
     solfege_c_midi.seq_start_timer()
     for e in midieventstream:
         if e[0] == midieventstream.TEMPO:
             self.__tempo = (e[1], e[2])
         elif e[0] == midieventstream.NOTE_ON:
             channel, note, vel = e[1:4]
             voice = self.alloc_voice(channel, note)
             if voice is not None:
                 # FIXME ugly hack for percussion. This will break if
                 # we play polyphonic music with very many voices
                 if channel == 9:  # voice == 31:
                     voice = 9
                 solfege_c_midi.seq_start_note(self.m_devnum, voice, note, vel)
         elif e[0] == midieventstream.NOTE_OFF:
             channel, note, vel = e[1:4]
             voice = self.free_voice(channel, note)
             if voice is not None:
                 # FIXME, see 10 lines up
                 if channel == 9:  # voice == 31:
                     voice = 9
                 solfege_c_midi.seq_stop_note(self.m_devnum, voice, note, vel)
         elif e[0] == midieventstream.NOTELEN_TIME:
             # 96 is a const, also used in soundcard.initialize that
             # I don't understand.
             solfege_c_midi.seq_delta_time(int(int(96 * e[1]) * 60.0 * self.__tempo[1] / self.__tempo[0]))
         elif e[0] == midieventstream.SET_PATCH:
             self.set_patch(e[1], e[2])
         elif e[0] == midieventstream.BENDER:
             logging.debug("FIXME: DevSequencerSynth.BENDER")
             #solfege_d_midi.seq_bender(self.m_devnum, e[1], e[2])
         elif e[0] == midieventstream.VOLUME:
             logging.debug("oss_sequencer: seq_set_volume for /dev/sequencer not tested, so it is commented out.")
             #m.seq_set_volume(self.m_devnum, e[1], e[2])
         else:
             raise Exception("oss_sequencer: play track error")
     solfege_c_midi.seqbuf_dump()
Ejemplo n.º 4
0
 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