[linux-audio-user] mono synth, note allocation scheme

Peter Brinkmann brinkman at math.TU-Berlin.DE
Tue Aug 23 20:54:06 EDT 2005


On Tue, Aug 23, 2005 at 10:01:20PM +0200, Atte André Jensen wrote:
> 
> Christoph Eckert wrote:
> 
> >Not only useful, such abiilities define the style of a solo.
> 
> It's actually a showstopper for me in certain areas. Pads and other 
> stuff work ok, but monosynths are no-go in most linux softsynths for me...

I suppose you can guess what I'm going to say, but I'll go ahead anyway:
The behavior you want is easy to implement in a few lines of Python code,
as a MIDI filter that sits between the keyboard and the softsynth.
A tentative version is attached. I haven't tested it a lot, but it should
be okay as well as easy to extend to give more sophisticated behavior.
    Peter

-------------- next part --------------
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)



More information about the Linux-audio-user mailing list