示例#1
0
 def __init__(self, usb_device_name, app):
     self._log = logging.getLogger(__name__)
     self._midi_in, self._midi_out = RtMidiIn(), RtMidiOut()
     self._connect_midi(usb_device_name)
     self._midi_in.setCallback(self._midi_message_cb)
     self._app = app
     self.enabled = True
示例#2
0
class Writer:
    def __init__(self, port_index):
        self.device = RtMidiOut()
        self.device_name = self.device.getPortName(port_index)
        print("[Device] Output:", self.device_name)
        self.device.openPort(port_index)

    def send_cc_momentary(self, channel, cc, label=None):
        if label:
            print('[Virtual] send_cc_momentary:', label)
        self.send_cc_raw(channel, cc, 127)
        self.send_cc_raw(channel, cc, 0)

    def send_cc_raw(self, channel, cc, v, label=None):
        if label:
            print('[Virtual] send_cc_raw:', label)
        # see: https://github.com/patrickkidd/pyrtmidi/blob/master/rtmidi/randomout.py
        msg = MidiMessage.controllerEvent(channel, cc, v)
        self.device.sendMessage(msg)
示例#3
0
    def __init__(self, midi_controller):
        self._midi_in, self._midi_out = RtMidiIn(), RtMidiOut()
        self._connect_midi(midi_controller)
        self._midi_in.setCallback(self._midi_message_cb)
        self._osc_client = udp_client.SimpleUDPClient('127.0.0.1', 5005)
        self._osc_client.send_message('/ping', '1')

        # This part needs to be configurable per mode/user config/DIP switches/etc
        # At the moment, Arduino Micro MIDI device should do:
        # --------------
        # | 5  6  7  8 |
        # | 1  2  3  4 |
        # --------------
        #    Press         Press         Press         Long
        #    Preset        Stomp         Looper        Press
        #    Mode          Mode          Mode
        # 1) Preset 1[10]  Stomp1En[20]  Undo[30]     PresetMod[40]
        # 2) Preset 2[11]  Stomp2En[21]  Record[31]   StompMode[41]
        # 3) Preset 3[12]  Stomp3En[22]  Overdub[32]  LooperMod[42]
        # 4) Preset 4[13]  Stomp4En[23]               Tuner[43]
        # 5) Stomp1En[14]  Stomp5En[24]               Stomp1Sel[44]
        # 6) Stomp2En[15]  Stomp6En[25]               Stomp2Sel[45]
        # 7) Stomp3En[16]  Stomp7En[26]               Stomp3Sel[46]
        # 8) Stomp4En[17]  TapTempo[27]               Stomp4Sel[47]
        self._cc_osc_translation = {
            # Presets
            10: '/preset/1', 11: '/preset/2', 12: '/preset/3', 13: '/preset/4',
            14: '/stomp/1/enable', 15: '/stomp/2/enable', 16: '/stomp/3/enable', 17: '/stomp/4/enable',

            # Stompboxes
            20: '/stomp/1/enable', 21: '/stomp/2/enable', 22: '/stomp/3/enable', 23: '/stomp/4/enable',
            24: '/stomp/5/enable', 25: '/stomp/6/enable', 26: '/stomp/7/enable', 27: '/stomp/8/enable',

            # Looper
            30: '/looper/undo', 31: '/looper/record', 32: '/looper/overdub', 33: '/looper/mute_trigger',
            34: '/looper/redo', 35: '/looper/insert', 36: '/looper/multiply', 37: '/looper/pause',

            # Metronome
            40: '/metronome/pause', 41: '/metronome/dec_bpm', 42: '/metronome/inc_bpm', 43: '/metronome/tap',
            44: '', 45: '', 46: '', 47: '',

            # Long press
            100: '/mode/preset', 101: '/mode/stomp', 102: '/mode/looper', 103: '/mode/metronome',
            104: '/stomp/1/select', 105: '/stomp/2/select', 106: '/stomp/3/select', 107: '/stomp/4/select'
        }
示例#4
0
def do_SenderProc(iq, oq, portName):
    DEBUG = 0

    def wait_for(x):
        s = iq.get(block=True, timeout=2)
        if s != x:
            print("%s: OH SHIT (wait_for() %s != %s)" % (__name__, s, x))

    device = RtMidiOut()
    if DEBUG:
        print('%s: OPENING %s' % (__name__, portName))
    device.openVirtualPort(portName)

    oq.put('init')  # the port is open

    wait_for('start')
    total = 0
    # note on
    for i in range(128):
        for j in range(1, 128):
            if DEBUG:
                print("%s: Note %i %i" % (__name__, i, j))
            m = MidiMessage.noteOn(1, i, j)
            device.sendMessage(m)
            wait_for('next')
            total += 1
    # controller
    for i in range(128):
        for j in range(128):
            if DEBUG:
                print("%s: CC %i %i" % (__name__, i, j))
            m = MidiMessage.controllerEvent(1, i, j)
            device.sendMessage(m)
            wait_for('next')
            total += 1

    wait_for('done')
    print('%s: sent %i messages' % (__name__, total))
示例#5
0
class WiiMidi():
    def __init__(self):
        self.last = {'wii_btn': ButtonSet(), 'roll': 0, 'pitch': 0}
        self.midiout = RtMidiOut()
        self.midiout.openVirtualPort(MIDIPORT_NAME)
    
    @staticmethod
    def is_pressed(btncode, pressed):
        return (btncode & pressed) == btncode

    def send_midi(self, midi):
        data = tuple([x for x in [midi.status, midi.data1, midi.data2] if x])
        self.midiout.sendMessage(*data)
    
    def process_btn(self, wiidevice, mesg_btn, btnmap):
        current = self.last['wii_btn']
        
        #Check for new pressed buttons and send the associated midi messages
        for button in [btn for btn in btnmap.sensitive_buttons(mesg_btn) \
                if not btn in self.last['wii_btn'] and \
                self.is_pressed(btn.btncode, mesg_btn)]:
            current.add(button)
            if button.press_action:
                self.send_midi(button.get_press_action())

        #Check for new released buttons and send the associated midi messages
        for button in [btn for btn in self.last['wii_btn'] \
                if not self.is_pressed(btn.btncode, mesg_btn)]:
            current.remove(button)
            if button.release_action:
                self.send_midi(button.get_release_action())
       
        self.last['wii_btn'] = current

    def process_acc(self, wiidevice, mesg_acc, axis):
        axis.set_acc(mesg_acc)
        
        roll = convert(axis.roll, math.pi, 127)
        pitch = convert(axis.pitch, 1.55, 16)
        
        if roll != self.last['roll']:
            self.last['roll'] = roll
            self.midiout.sendMessage(0xE0, 10, roll)
        
        if pitch != self.last['pitch']:
            self.last['pitch'] = pitch
示例#6
0
def do_SenderProc(iq, oq, portName):
    DEBUG = 0

    def wait_for(x):
        s = iq.get(block=True, timeout=2)
        if s != x:
            print("%s: OH SHIT (wait_for() %s != %s)" % (__name__, s, x))

    device = RtMidiOut()
    if DEBUG:
        print('%s: OPENING %s' % (__name__, portName))
    device.openVirtualPort(portName)

    oq.put('init')  # the port is open

    wait_for('start')
    total = 0
    # note on
    for i in range(128):
        for j in range(1, 128):
            if DEBUG:
                print("%s: Note %i %i" % (__name__, i, j))
            m = MidiMessage.noteOn(1, i, j)
            device.sendMessage(m)
            wait_for('next')
            total += 1
    # controller
    for i in range(128):
        for j in range(128):
            if DEBUG:
                print("%s: CC %i %i" % (__name__, i, j))
            m = MidiMessage.controllerEvent(1, i, j)
            device.sendMessage(m)
            wait_for('next')
            total += 1

    wait_for('done')
    print('%s: sent %i messages' % (__name__, total))
# /Users/macbook/miniconda3/envs/AIP/bin/pip install rtmidi
from rtmidi import MidiMessage, RtMidiIn, RtMidiOut
import time
import midi_tools

midiout = RtMidiOut()
midiout.openPort(2)

midiin = RtMidiIn()
midiin.openPort(2)

midi_tools.print_ports(midiin)
midi_tools.print_ports(midiout)


class MidiConnection:
    def __init__(self, _channel, _DEBUG=False, _port=0):
        self.port = _port
        self.channel = _channel
        self.DEBUG = _DEBUG

    def output(self, m):
        midiout.sendMessage(m)
        if (self.DEBUG):
            midi_tools.print_message(m)

    def sendNoteSignal(self, note, vel, wait=.1):
        m = MidiMessage.noteOn(self.channel, note, vel)
        self.output(m)
        time.sleep(wait)
        m = MidiMessage.noteOff(self.channel, note)
示例#8
0
文件: server.py 项目: pbeckman/gEcho
            msg.getNoteNumber()), msg.getVelocity()
    elif msg.isNoteOff():
        print '%s: OFF:' % port, msg.getNoteNumber(), "=", msg.getMidiNoteName(
            msg.getNoteNumber())
    elif msg.isController():
        print '%s: CONTROLLER' % port, msg.getControllerNumber(
        ), msg.getControllerValue()


if __name__ == '__main__':
    # increase stack size to avoid segfault
    resource.setrlimit(resource.RLIMIT_CORE,
                       (resource.RLIM_INFINITY, resource.RLIM_INFINITY))

    midi_in = RtMidiIn()
    midi_out = RtMidiOut()

    print "AVAILABLE PORTS:"
    for i in range(midi_in.getPortCount()):
        print "  ", i, midi_in.getPortName(i)

    in_port = raw_input("INPUT PORT  (1): ")
    in_port = 1 if in_port.strip() == "" else int(in_port)
    out_port = raw_input("OUTPUT PORT (0): ")
    out_port = 0 if out_port.strip() == "" else int(out_port)

    server = Server(midi_in, in_port, midi_out, out_port)
    server.start()

    print 'HIT ENTER TO EXIT'
    sys.stdin.read(1)
示例#9
0
 def __init__(self):
     self.last = {'wii_btn': ButtonSet(), 'roll': 0, 'pitch': 0}
     self.midiout = RtMidiOut()
     self.midiout.openVirtualPort(MIDIPORT_NAME)
示例#10
0
 def __init__(self, port_index):
     self.device = RtMidiOut()
     self.device_name = self.device.getPortName(port_index)
     print("[Device] Output:", self.device_name)
     self.device.openPort(port_index)
示例#11
0
if __name__ == '__main__':
    say("Listening.")  # Shows that speech synthesis isn't blocked.
    parser = argparse.ArgumentParser(description="A MIDI/Keyboard signal router.")
    parser.add_argument('-v', '--volume', dest="volume",
                        help='Listen for volume key.', action='store_true', required=False)
    parser.add_argument('-a', '--accent', dest="accent",
                        help='Listen for accent key.', action='store_true', required=False)
    parser.add_argument('-r', '--record', dest="send_midi_record",
                        help='Send synthetic MIDI record/stop/new', action='store_true', required=False)
    parser.add_argument('-p', '--play', dest="send_midi_play",
                        help='Send synthetic MIDI play/stop', action='store_true', required=False)
    ARGS = parser.parse_args()

    #listen_to_all_keys()
    listen_to_hot_keys()

    for i in range(RtMidiIn().getPortCount()):
        Reader(i)

    fake_out = RtMidiOut()
    for i in range(fake_out.getPortCount()):
        if fake_out.getPortName(i) == VIRTUAL_OUTPUT_NAME:
            VIRTUAL_OUTPUT = Writer(i)


    while True:
        # print("HI")
        time.sleep(100)
        #gevent.sleep(1.0)
        #gevent.spawn_later(0.1, call_obs_api)