#pip install mido python-rtmidi pyfluidsynth

import mido
import fluidsynth

inputs = mido.get_input_names()
print('INPUTS ', inputs)
print('OUTPUTS ', mido.get_output_names())

# connect to your controller
port = mido.open_input('USB Axiom 25 Port 1')


#play with fluidsynth
fs = fluidsynth.Synth()
fs.start() #driver="coreaudio") 

sfid = fs.sfload("FluidR3_GM.sf2")
fs.program_select(0, sfid, 0, 42)
fs.program_select(9, sfid, 128, 0)

## convert mido messages to fs messages
while True:
    for msg in port.iter_pending():
        print(msg)
        
        if msg.type == 'note_on':
            fs.noteon(msg.channel, msg.note, msg.velocity)
        elif msg.type == 'note_off':
            fs.noteoff(msg.channel, msg.note)
        elif msg.type =='pitchwheel':
            fs.pitch_bend(msg.channel, msg.pitch)
        elif msg.type == 'control_change':
            fs.cc(msg.channel, msg.control, msg.value)
        elif msg.type == 'aftertouch':
            fs.channel_pressure(msg.channel, msg.value)
        ## do the same for the remaining messages
        