[linux-audio-user] alsa midi processor again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Atte,
> I'm not gonna promise anything, but if someone could shoot mi in the 
> right direction regarding alsa, API, example code, documentation, I'm 
> willing to give it a shot...
I've cobbled together a very simple bit of code that splits MIDI events
according to note values. I wouldn't use it in this form in any serious
way, but it should be enough to give you an idea as to how to build MIDI
routers with Python.

In order to use it, say something like
    python midisplit.py 36 60 84
Now midisplit.py will create one MIDI input port and four output ports.
Connect the output ports to soft synths or so, and the input port to a
keyboard. If you hit a key on the keyboard, then midisplit.py will send
it via its first port if the note is between 0 and 35, to the second port
if the note is between 36 and 59, etc. Generally speaking, if you list
n numbers on the command line, you get n+1 output ports, unless you give
no arguments, in which case midisplit will revert to its default behavior
of splitting at note 60.

This code uses MidiKinesis libraries, available at
     http://www.math.tu-berlin.de/~brinkman/software/midikinesis/
Hope this helps,
    Peter

-------------- next part --------------
from pyseq import *

class MidiSplit(PySeq):
    def init(self, sp=None):
        if sp:
            self.splitPoints=sp[:]
        else:
            self.splitPoints=[60]
        self.outports=[]
        for i in range(len(self.splitPoints)+1):
            self.outports.append(self.createOutPort())
        self.inport=self.createInPort()
    def callback(self, ev):
        if ev.type==SND_SEQ_EVENT_NOTEON or ev.type==SND_SEQ_EVENT_NOTEOFF:
            note=ev.getData().note
            index=len([x for x in self.splitPoints if note>=x])
            ev.sendNow(self, self.outports[index])
        return 1

if __name__=='__main__':
    import sys
    seq=MidiSplit('MidiSplit', [int(s) for s in sys.argv[1:]])   
    MidiThread(seq).start()
    raw_input('press return to finish')

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux