Example #1
0
    def __init__(self):
        print('Using ALSA MIDI interface')

        alsaseq.client('Simple', 1, 1, False) # name, ninputports, noutputports, createqueue
        alsaseq.connectfrom(0, CLIENT, 0) # inputport, src_client, src_port

        self.binds = {}
Example #2
0
    def main():

        se = ServoEvent()
        parser = MusicParser()
        alsaseq.client('RoboWhistle PassThrough', 1, 1,
                       False)  # Set up a new ALSA channel
        alsaseq.connectfrom(
            1, 129, 0)  # Midi file input needs to be sent in to channel 129
        # Backup ALSA channel to run on port 128. Can use either a virtual synth (e.g. Timidity or a physical MIDI keyboard)
        alsaseq.connectto(1, 128, 0)

        srv = ServoEvent()
        srv.ResetServoEvent()

        #To enter FreePlay mode provide any argument when running the program; if left blank AutoPlay will proceed automaticlly
        if len(sys.argv) is 2:
            print "Entering FreePlay Mode"
            play = FreePlay()
            play.ManualPlay()
        else:
            print str(len(sys.argv))
            while 1:
                if alsaseq.inputpending():  # ALSA queue
                    event = alsaseq.input()  # Pop event from top of the queue
                    eventPitch = event[7][
                        1]  # Pitch of the note that needs to be played

                    parsedNote = parser.AnalyseSingleNote(eventPitch % 12)

                    if parsedNote is None:
                        alsaseq.output(
                            event
                        )  # Event is unplayable by the whistle, forward it to the synthesiser
                    else:
                        se.PlayNoteEvent(parsedNote)  # Pass item for playing
Example #3
0
 def init_alsa(self):
     # prepare alsaseq
     device_no = self.options[
         "midi_device_no"]  # find out using aconnect or aconnectgui
     alsaseq.client('Recorder', 1, 0, True)
     alsaseq.connectfrom(0, device_no, 0)
     alsaseq.start()
Example #4
0
    def Open(self, src_list=[], dest_list=[]):
        ''' src_list is a list of src ports to connect to. From -i#,#
        dest_list is a list of dest ports to connect to.  From -o#,#,
        '''
        print('opening alsaseq client')
        junk_None = alsaseq.client(
           'midiroute', # name of virtual client
           1, #num in ports
           1, #num out ports
           False) # create_queue Y/N - rx buf?

        # there is also connectto(), connectfrom() funcs...
        # these appear to be for connecting client() to other ports

        # following input port, output port appear to be 0 for input,
        # 1 for output.
        for src_i in src_list:
            print('in:%d' % (src_i))
            alsaseq.connectfrom(0, # input port
                                src_i, # src client
                                0) # src port

        for dest_i in dest_list:
            print('out:%d' % (dest_i))
            alsaseq.connectto(1, # output port(first one of ours?)
                              dest_i, # dest client
                              0) # dest port

        # connect ins and outs based on string comparisons:
        # see ourAlsaIn()/Out() above for setting your string connect matches
        #if len(src_list) == 0 and len(dest_list) == 0:
        if self.auto_midi_conn: # -a[0|1] option, default 1 on
            print('scanning Alsa Midi Inputs')
            lst = AlsaSeq_List(0) # list inputs(Midi Keys for ex)
            for m in lst:
                if ourAlsaIn(m):
                    print('connect input client %3d %-26s port %d %s' % (m.client_id,m.client_name, m.port_id,m.port_name))
                    alsaseq.connectfrom(m.port_id, # our port, first input is 0
                                        m.client_id, # 28 for example
                                        m.port_id) # 0 for example
            print('scanning Alsa Midi Outputs')
            lst = AlsaSeq_List(1) # list outputs(synth ex)
            for m in lst:
                if ourAlsaOut(m):
                    print('connect output client %3d %-26s port %d %s' % (m.client_id,m.client_name, m.port_id,m.port_name))
                    alsaseq.connectto(1, # our first output port is 1 now
                                        m.client_id, # 28 for example
                                        m.port_id)   # 0 for example

        # how do we tell if successful?  This is returning None?
        #   it calls exit(1) if fails, I guess client is not expected
        #   to fail...
        self.mDevIn = True
        if self.mDevIn != None:
            return True # ok
        print('fail!')
        return False # no open
Example #5
0
        elif letra in "0123456789":
            nritmo = int(letra)
            print("{:2} {}".format(nritmo, ritmos[nritmo][0]))
        elif letra == "n":
            number = int(input())
            if number < len(ritmos):
                nritmo = number
                print("{:2} {}".format(nritmo, ritmos[nritmo][0]))
        elif letra == "t":
            tempo = int(input())
            print("tempo:", tempo)


rechazados = (alsaseq.SND_SEQ_EVENT_CLOCK, alsaseq.SND_SEQ_EVENT_SENSING)
alsaseq.client("ReproductorGrabador", 1, 1, 1)
alsaseq.connectfrom(0, source_cliente, 0)
alsaseq.connectto(1, dest_cliente, 0)
alsaseq.start()
pgmchangevoz1 = alsamidi.pgmchangeevent(0, voz1)
pgmchangevoz2 = alsamidi.pgmchangeevent(1, voz2)
alsaseq.output(pgmchangevoz1)
if voz2:
    alsaseq.output(pgmchangevoz2)

nlibres = 100
import kbhit

kbhit.unbuffer_stdin()
vivo = 1
seq = alsamidi.Seq()
try:
Example #6
0
import alsaseq, serial
alsaseq.client( 'Recorder', 1, 0, True )
alsaseq.connectfrom( 1, 129, 0 )
alsaseq.start()
events = []

EV_KEYDOWN = 6
EV_KEYUP = 7

s = serial.Serial("/dev/ttyUSB0", 115200)

ch = 1

def sendmsg(chan,note,vel):
    print "msg going",chan,note
    onoff = 0x40 if note >= 0 else 0
    note = abs(note)
    s.write(chr(0x80 | chan | onoff))
    s.write(chr(0x60 | (note  >> 4)))
    s.write(chr(0x50 | (note & 0xf)))
    s.write(chr(0x20 | (vel   >> 4)))
    s.write(chr(0x10 | (vel  & 0xf)))

while 1:
    if alsaseq.inputpending():
        ch = int(open("ch.txt", "r").read())
        event = alsaseq.input()
        evtype = event[0]
        if evtype == EV_KEYDOWN:
            sendmsg(ch, event[7][1], event[7][2])
        elif evtype == EV_KEYUP:
Example #7
0
# ============================================================================

args = sys.argv[1:]
args.append("-m")
# args.append('20:14:12:17:01:67')
args.append('20:14:12:17:02:47')
params = parseArgs(args)

# initialize ALSA 
alsaseq.client( 'MidiCube', 1, 1, False )
if params.alsaOut is not None:
    (client, port) = params.alsaOut
    alsaseq.connectto(0, client, port)
if params.alsaIn is not None:
    (client, port) = params.alsaIn
    alsaseq.connectfrom(0, client, port)

# connect to bluetooth device
sock = com.connect(params.btMAC)
if not sock:
    logging.error('connection to MIDI cube failed')
    exit(-1)

listener = Listener(sock, params.btMAC)
scheduler = Scheduler(params)
alsain = alsaInput()

scheduler.start()
listener.start()
time.sleep(1)
import alsaseq, time, dev_board as pi

alsaseq.client( 'Python', 1, 0, False )
alsaseq.connectfrom( 0, 14, 0 )
alsaseq.start()

playChannels = [0 for x in range(16)]
pinChannels = [0,0,0,0]
pinNotes = [0,0,0,0]

def midi_process(ev):
  global pinNotes
  global pinChannels
  if (ev[0] == alsaseq.SND_SEQ_EVENT_PGMCHANGE):
    
    #clear pins state
    clearPinChannels()
    clearPinNotes()
    
    print "PGMCHANGE: channel ", ev[7][0], " ", ev[7][5]
    
    #filter out base, percussion, or synth
    if (ev[7][5] >= 8 and ev[7][5] <= 15) or (ev[7][5] >= 32 and ev[7][5] <= 39) or (ev[7][5] >= 88 and ev[7][5] <= 103):
      setPlayChannel(ev[7][0], 0)
    else:
      setPlayChannel(ev[7][0], 1)
    
    #if event is NOTEON(6) or NOTEOFF(7)
  elif (ev[0] == 6) or (ev[0] == 7):
    #print "GOT NOTE_X"
    if isPlayChannel(ev[7][0]):
Example #9
0
from queue import Queue, Empty

from pyseq.events import parse_event
from pyseq.midiin import MidiInCtrl
from pyseq.model import SequencerModel
from pyseq.view import SequencerView


FROM = [(28, 0), (32, 0)]
TO = [(129, 0), (32, 0)]


alsaseq.client("pyseq", 1, 1, 0)

for midiin in FROM:
    alsaseq.connectfrom(0, midiin[0], midiin[1])

for midiout in TO:
    alsaseq.connectto(1, midiout[0], midiout[1])



def main():
    logging.basicConfig(filename="debug.log", level=logging.DEBUG)
    midi_receiver = MidiInCtrl()
    view = SequencerView()
    sequencer = SequencerModel()

    # MidiIN -> Sequencer
    # MidiIN -> View
    midi_receiver.subscribe(sequencer.in_q)
Example #10
0
# signal.signal(signal.SIGTERM, sigterm_handler)

args = sys.argv[1:]
args.append("-m")
args.append('20:14:12:17:01:67')
#args.append('20:14:12:17:02:47')
params = parseArgs(args)

# initialize ALSA
alsaseq.client('LaserGun', 1, 1, False)
if params.alsaOut is not None:
    (client, port) = params.alsaOut
    alsaseq.connectto(0, client, port)
if params.alsaIn is not None:
    (client, port) = params.alsaIn
    alsaseq.connectfrom(0, client, port)

# connect to bluetooth device
sock = com.connect(params.btMAC)
if not sock:
    logging.error('connection to laser gun failed')
    exit(2)

listener = Listener(sock)
scheduler = Scheduler(params)
alsain = alsaInput()

scheduler.start()
listener.start()
alsain.start()
time.sleep(1)
Example #11
0
import alsaseq, serial
alsaseq.client('Recorder', 1, 0, True)
alsaseq.connectfrom(1, 129, 0)
alsaseq.start()
events = []

EV_KEYDOWN = 6
EV_KEYUP = 7

s = serial.Serial("/dev/ttyUSB0", 115200)

ch = 1


def sendmsg(chan, note, vel):
    print "msg going", chan, note
    onoff = 0x40 if note >= 0 else 0
    note = abs(note)
    s.write(chr(0x80 | chan | onoff))
    s.write(chr(0x60 | (note >> 4)))
    s.write(chr(0x50 | (note & 0xf)))
    s.write(chr(0x20 | (vel >> 4)))
    s.write(chr(0x10 | (vel & 0xf)))


while 1:
    if alsaseq.inputpending():
        ch = int(open("ch.txt", "r").read())
        event = alsaseq.input()
        evtype = event[0]
        if evtype == EV_KEYDOWN:
Example #12
0
import os
import yaml
import alsaseq
import pygame

STANDARD_VOLUME = .25

SOUND_KEY_RANGE_MIN = 53
SOUND_KEY_RANGE_MAX = 84

alsaseq.client('Recorder', 1, 0, True)
alsaseq.connectfrom(0, 20, 0)
alsaseq.start()
events = []
pygame.mixer.init()
pygame.mixer.music.set_volume(STANDARD_VOLUME)

config = {}

with open('/etc/soundboard.conf', 'r') as config_file:
    config = yaml.load(config_file)
sound_mappings = config['sound_mappings']


def play_sound(sound, volume):
    path = os.path.join(config['sounds_dir'], sound)
    print "About to play ", path
    print "At volume ", volume
    pygame.mixer.music.set_volume(volume)
    pygame.mixer.music.load(path)
    pygame.mixer.music.play()
Example #13
0
        elif letra in '0123456789':
            nritmo = int(letra)
            print('{:2} {}'.format(nritmo, ritmos[nritmo][0]))
        elif letra == 'n':
            number = int(input())
            if number < len(ritmos):
                nritmo = number
                print('{:2} {}'.format(nritmo, ritmos[nritmo][0]))
        elif letra == 't':
            tempo = int(input())
            print('tempo:', tempo)


rechazados = (alsaseq.SND_SEQ_EVENT_CLOCK, alsaseq.SND_SEQ_EVENT_SENSING)
alsaseq.client('ReproductorGrabador', 1, 1, 1)
alsaseq.connectfrom(0, source_cliente, 0)
alsaseq.connectto(1, dest_cliente, 0)
alsaseq.start()
pgmchangevoz1 = alsamidi.pgmchangeevent(0, voz1)
pgmchangevoz2 = alsamidi.pgmchangeevent(1, voz2)
alsaseq.output(pgmchangevoz1)
if voz2:
    alsaseq.output(pgmchangevoz2)

nlibres = 100
import kbhit
kbhit.unbuffer_stdin()
vivo = 1
seq = alsamidi.Seq()
try:
    fd = alsaseq.fd()