Exemple #1
0
    def event_write(self, event, direct=False, relative=False, tick=False):
        #print(event.__class__, event)
        ## Event Filter
        if isinstance(event, midi.EndOfTrackEvent):
            return
        seqev = S.snd_seq_event_t()
        ## common
        seqev.dest.client = self.write_dest.client
        seqev.dest.port = self.write_dest.port
        seqev.source.client = self.write_sender.client
        seqev.source.port = self.write_sender.port
        if direct:
            # no scheduling
            seqev.queue = S.SND_SEQ_QUEUE_DIRECT
        else:
            seqev.queue = self.queue
            seqev.flags &= (S.SND_SEQ_TIME_STAMP_MASK|S.SND_SEQ_TIME_MODE_MASK)
            if relative:
                seqev.flags |= S.SND_SEQ_TIME_MODE_REL
            else:
                seqev.flags |= S.SND_SEQ_TIME_MODE_ABS
            if tick:
                seqev.flags |= S.SND_SEQ_TIME_STAMP_TICK
                seqev.time.tick = event.tick
            else:
                seqev.flags |= S.SND_SEQ_TIME_STAMP_REAL
                sec = int(event.msdelay / 1000)
                nsec = int((event.msdelay - (sec * 1000)) * 1000000)
                seqev.time.time.tv_sec = sec
                seqev.time.time.tv_nsec = nsec

        ## Tempo Change
        if isinstance(event, midi.SetTempoEvent):
            adjtempo = int(60.0 * 1000000.0 / event.bpm)
            seqev.type = S.SND_SEQ_EVENT_TEMPO
            seqev.dest.client = S.SND_SEQ_CLIENT_SYSTEM
            seqev.dest.port = S.SND_SEQ_PORT_SYSTEM_TIMER
            seqev.data.queue.queue = self.queue
            seqev.data.queue.param.value = adjtempo
        ## Note Event
        elif isinstance(event, midi.NoteEvent):
            if isinstance(event, midi.NoteOnEvent):
                seqev.type = S.SND_SEQ_EVENT_NOTEON
            if isinstance(event, midi.NoteOffEvent):
                seqev.type = S.SND_SEQ_EVENT_NOTEOFF
            seqev.data.note.channel = event.channel
            seqev.data.note.note = event.pitch
            seqev.data.note.velocity = event.velocity
        ## Control Change
        elif isinstance(event, midi.ControlChangeEvent):
            seqev.type = S.SND_SEQ_EVENT_CONTROLLER
            seqev.data.control.channel = event.channel
            seqev.data.control.param = event.control
            seqev.data.control.value = event.value
        ## Program Change
        elif isinstance(event, midi.ProgramChangeEvent):
            seqev.type = S.SND_SEQ_EVENT_PGMCHANGE
            seqev.data.control.channel = event.channel
            seqev.data.control.value = event.value
        ## Pitch Bench
        elif isinstance(event, midi.PitchWheelEvent):
            seqev.type = S.SND_SEQ_EVENT_PITCHBEND
            seqev.data.control.channel = event.channel
            seqev.data.control.value = event.pitch
        ## Unknown
        else:
            print("Warning :: Unknown event type: %s" % event)
            return None
            
        err = S.snd_seq_event_output(self.client, seqev)
        if (err < 0): self._error(err)
        self.drain()
        return self.output_buffer_size - err
Exemple #2
0
    def event_write(self, event, direct=False, relative=False, tick=False):
        #print event.__class__, event
        ## Event Filter
        if isinstance(event, midi.EndOfTrackEvent):
            return
        seqev = S.snd_seq_event_t()
        ## common
        seqev.dest.client = self.write_dest.client
        seqev.dest.port = self.write_dest.port
        seqev.source.client = self.write_sender.client
        seqev.source.port = self.write_sender.port
        if direct:
            # no scheduling
            seqev.queue = S.SND_SEQ_QUEUE_DIRECT
        else:
            seqev.queue = self.queue
            seqev.flags &= (S.SND_SEQ_TIME_STAMP_MASK|S.SND_SEQ_TIME_MODE_MASK)
            if relative:
                seqev.flags |= S.SND_SEQ_TIME_MODE_REL
            else:
                seqev.flags |= S.SND_SEQ_TIME_MODE_ABS
            if tick:
                seqev.flags |= S.SND_SEQ_TIME_STAMP_TICK
                seqev.time.tick = event.tick
            else:
                seqev.flags |= S.SND_SEQ_TIME_STAMP_REAL
                sec = int(event.msdelay / 1000)
                nsec = int((event.msdelay - (sec * 1000)) * 1000000)
                seqev.time.time.tv_sec = sec
                seqev.time.time.tv_nsec = nsec

        ## Tempo Change
        if isinstance(event, midi.SetTempoEvent):
            adjtempo = int(60.0 * 1000000.0 / event.bpm)
            seqev.type = S.SND_SEQ_EVENT_TEMPO
            seqev.dest.client = S.SND_SEQ_CLIENT_SYSTEM
            seqev.dest.port = S.SND_SEQ_PORT_SYSTEM_TIMER
            seqev.data.queue.queue = self.queue
            seqev.data.queue.param.value = adjtempo
        ## Note Event
        elif isinstance(event, midi.NoteEvent):
            if isinstance(event, midi.NoteOnEvent):
                seqev.type = S.SND_SEQ_EVENT_NOTEON
            if isinstance(event, midi.NoteOffEvent):
                seqev.type = S.SND_SEQ_EVENT_NOTEOFF
            seqev.data.note.channel = event.channel
            seqev.data.note.note = event.pitch
            seqev.data.note.velocity = event.velocity
        ## Control Change
        elif isinstance(event, midi.ControlChangeEvent):
            seqev.type = S.SND_SEQ_EVENT_CONTROLLER
            seqev.data.control.channel = event.channel
            seqev.data.control.param = event.control
            seqev.data.control.value = event.value
        ## Program Change
        elif isinstance(event, midi.ProgramChangeEvent):
            seqev.type = S.SND_SEQ_EVENT_PGMCHANGE
            seqev.data.control.channel = event.channel
            seqev.data.control.value = event.value
        ## Pitch Bench
        elif isinstance(event, midi.PitchWheelEvent):
            seqev.type = S.SND_SEQ_EVENT_PITCHBEND
            seqev.data.control.channel = event.channel
            seqev.data.control.value = event.pitch
        ## Unknown
        else:
            print "Warning :: Unknown event type: %s" % event
            return None
            
        err = S.snd_seq_event_output(self.client, seqev)
        if (err < 0): self._error(err)
        self.drain()
        return self.output_buffer_size - err