Ejemplo n.º 1
0
 def __init__(self, port, controller, default_midi_mapping=None):
     self.controller = controller
     self.midi_server = pymidi_server.Server(port=port)
     self.midi_handler = MidiHandler(self)
     self.midi_server.add_handler(self.midi_handler)
     self.logger = logging.getLogger(self.__class__.__name__)
     self.midi_peers_to_mappings = {}
     self.logger.info('Midi enabled, port={}'.format(port))
     self.default_midi_mapping = default_midi_mapping or MidiMapping(name='default')
Ejemplo n.º 2
0
    logging.basicConfig(
        level=logging.INFO,
        format='[%(asctime)s.%(msecs)03d][%(levelname)s]:\t%(message)s',
        datefmt='%m/%d/%Y %H:%M:%S')
    sc = SerialController('/dev/ttyACM0')
    rail = LinearActuator(sc)
    index = HandServos.format_servo_data('index',
                                         0,
                                         min_angle=0,
                                         max_angle=80,
                                         inverted=True)
    middle = HandServos.format_servo_data('middle',
                                          1,
                                          min_angle=44,
                                          max_angle=100,
                                          inverted=True)
    ring = HandServos.format_servo_data('ring', 2, min_angle=10, max_angle=75)
    pinky = HandServos.format_servo_data('pinky',
                                         3,
                                         min_angle=15,
                                         max_angle=105)

    hs = HandServos([index, middle, ring, pinky])
    hand = Hand(rail, hs)
    port = 5051
    midi_server = server.Server([('::', port)])
    midi_server.add_handler(MIDIHandler(hand))
    # t = threading.Thread(target=loop_runner, daemon=True)
    # t.start()
    midi_server.serve_forever()
Ejemplo n.º 3
0
from pymidi import server

import sys
from importlib import reload
reload(sys)
sys.setdefaultencoding("utf-8")


class MyHandler(server.Handler):
    def on_peer_connected(self, peer):
        print('Peer connected: {}'.format(peer))

    def on_peer_disconnected(self, peer):
        print('Peer disconnected: {}'.format(peer))

    def on_midi_commands(self, peer, command_list):
        for command in command_list:
            if command.command == 'note_on':
                key = command.params.key
                velocity = command.params.velocity
                print('Someone hit the key {} with velocity {}'.format(
                    key, velocity))


if __name__ == "__main__":
    myServer = server.Server([('0.0.0.0', 5051)])
    myServer.add_handler(MyHandler())
    myServer.serve_forever()
Ejemplo n.º 4
0
from pymidi import server
from percussion import PercussionMotor

drum = PercussionMotor(0, 13, 26, 16)


class MIDIHandler(server.Handler):
    def __init__(self):
        self.logger = None

    def on_peer_connected(self, peer):
        print('Peer connected: {}'.format(peer))

    def on_peer_disconnected(self, peer):
        print('Peer disconnected: {}'.format(peer))

    def on_midi_commands(self, peer, command_list):
        for command in command_list:
            if command.command == 'note_on':
                key = command.params.key
                velocity = command.params.velocity
                print('Someone hit the key {} with velocity {}'.format(
                    key, velocity))
                drum.hit()


midi_server = server.Server([('::', 5051)])

midi_server.add_handler(MIDIHandler())
midi_server.serve_forever()
Ejemplo n.º 5
0
 def task():
     self.glockenspiel.init()
     s = server.Server([("0.0.0.0", 5051)])
     s.add_handler(self)
     s.serve_forever()