from pyseq import * class MonoFilter(PySeq): def init(self, n=1): self.ports=[self.createInOutPort() for i in range(n)] self.mt=MidiThread(self) self.mt.start() self.e=snd_seq_event() self.current=[] self.recent=None def callback(self, ev): pt=ev.dest.port ev.sendNow(self, pt) if ev.type==SND_SEQ_EVENT_NOTEON or ev.type==SND_SEQ_EVENT_NOTEOFF: dat=ev.getData() self.current=[e for e in self.current if e[1]!=dat.note] if ev.type==SND_SEQ_EVENT_NOTEON and dat.velocity>0: self.current.append((dat.channel, dat.note, dat.velocity)) if self.recent!=None and self.recent!=dat.note: self.e.setNoteOff(dat.channel, self.recent, 0) self.e.sendNow(self, pt) self.recent=dat.note elif self.current and self.recent!=self.current[-1][1]: self.e.setNoteOn(*self.current[-1]) self.e.sendNow(self, pt) self.recent=self.current[-1][1] if __name__=='__main__': import time import sys if len(sys.argv)>1: n=int(sys.argv[1]) else: n=1 MonoFilter('MonoFilter', n) while 1: time.sleep(1)