Beispiel #1
0
 def getDeviceList(self):
     midiin = MidiIn()
     midiout = MidiOut()
     try:
         return (midiin.get_ports(), midiout.get_ports())
     except Exception as e:
         if DEBUG == True:
             print(e)
         return False
Beispiel #2
0
 def list_ports():
     midi_in = None
     midi_out = None
     try:
         api_out = MidiOut()
         api_in = MidiIn()
         ports = api_in.get_ports()
         return ports
     except:
         print("Unable to open MIDI ports")
     return
Beispiel #3
0
    def __init__(self, interpreters, port):
        super(InStream, self).__init__()
        self.interpreters = interpreters
        self.port = port
        self.wallclock = timenow()

        try:
            self.midiin = MidiIn().open_port(port)
            print("Listening for midi on input port {}".format(port))
        except Exception:
            print("WARNING: failed to open MIDI-in port {0}".format(port))

        self.done = False
        self.run = self.run_bound if Parameters.SP.ATTRACTOR_MODE == 1 else self.run_att
        # print(self.run.__name__)
        self.start()
Beispiel #4
0
    def setup_input(self):
        api_in = MidiIn()
        api_in.ignore_types(sysex=False)
        port_in = self.get_mixer_port(api_in)
        try:
            midi_in, port_name = open_midiinput(port_in, interactive=False)
        except InvalidPortError:
            return
        except NoDevicesError:
            return

        midi_in.ignore_types(sysex=False)
        midi_in.set_callback(self.listener)

        self.api_in = api_in
        self.input = midi_in
        return port_name
Beispiel #5
0
def read_midi():
    alsa_midi = MidiIn(API_LINUX_ALSA)
    print(alsa_midi.get_ports())
    selected_port = int(input("Select port: "))
    with alsa_midi.open_port(selected_port) as open_port:
        timer = time.time()
        try:
            while True:
                message = open_port.get_message()
                if message:
                    message, deltatime = message
                    timer += deltatime
                    print(" @%0.6f %r" % (timer, message))
                    print(message)
        except KeyboardInterrupt:
            print('')
        finally:
            print("Exit.")
 def _open_midi(self):
     """Starts MIDI without opening a port"""
     self.__log.info("Opening MIDI interfaces")
     try:
         self._midi_out = MidiOut()
         self._midi_in = MidiIn()
         #Note: if you need to catch SysEx, MIDI clock, and active sense
         #messages, then use the method: ignore_types as follows:
         #self._midi_in.ignore_types(sysex = False, timing = False,
         #             active_sense = False)
         #They are ignored by default. I don't need this right now, so the
         #standard behaviour is OK for me
     except:
         error = traceback.format_exc()
         self.__log.info(error)
         self._free_midi()
         return False
     self.__log.debug("MIDI interfaces were opened")
     return True
Beispiel #7
0
def get_ports(port_name: str,
              *,
              clock_source: bool = False) -> Tuple[MidiIn, MidiOut]:
    midi_in = MidiIn()
    midi_out = MidiOut()
    midi_in_ports = midi_in.get_ports()
    midi_out_ports = midi_out.get_ports()
    try:
        midi_in.open_port(midi_in_ports.index(port_name))
    except ValueError:
        raise ValueError(port_name) from None

    if clock_source:
        midi_in.ignore_types(timing=False)
    try:
        midi_out.open_port(midi_out_ports.index(port_name))
    except ValueError:
        raise ValueError(port_name) from None

    return midi_in, midi_out
Beispiel #8
0
from miniaudio import Backend, Devices
from rtmidi import MidiIn, MidiOut

print("- Audio devices")
for backend in Backend:
    try:
        devices = Devices([backend]).get_playbacks()
        print(f"  - {backend}")
        for device in devices:
            name = device["name"]
            print(f"    🔊 {name}")
    except:
        pass

print("- MIDI inputs")
for port in MidiIn().get_ports():
    print(f"  🎶 {port}")

print("- MIDI outputs")
for port in MidiOut().get_ports():
    print(f"  🎶 {port}")

print(
    """
Note that this script can display a lot of error or warning messages
from other libraries when trying to open backends that don't exist,
or when probing interfaces on some backends. Pay attention only to
the lines with 🔊 and 🎶!
"""
)
 def __enter__(self):
     self.MIDI_IN = MidiIn()
     self.MIDI_OUT = MidiOut()
     return self
Beispiel #10
0
from serial import Serial
from time import time, sleep
from rtmidi import MidiIn, MidiOut
from _thread import start_new_thread


mode = 0
pir_mode_color = [False, False, True]


open_ports = []
LEDs = []
PIRs = []

m_out = MidiOut().open_virtual_port("Python PIR Output")
melody_in = MidiIn().open_virtual_port("Python Melody Input")
drum_in = MidiIn().open_virtual_port("Python Drum Input")

last_drum = 0
DRUM_TIMEOUT = 0.1
PIR_TIMEOUT = 0.7


stair_modes = [
    [48, 50, 52, 53, 55, 57, 59, 60],
    [
        [48, 52, 55],
        [50, 53, 57],
        [52, 55, 59],
        [53, 57, 60],
        [55, 59, 62],
Beispiel #11
0
                                                       name))
        else:
            check_value(name, value)
            if name == 'data':
                vars(self)['data'] = SysexData(value)
            else:
                vars(self)[name] = value

    __setattr__ = _setattr

    def bytes(self):
        """Encode message and return as a list of integers."""
        return encode_message(vars(self))


midi_in = MidiIn()
midi_out = MidiOut()

in_ports = midi_in.get_ports()
out_ports = midi_out.get_ports()

print("IN ports:", in_ports)
print("OUT ports:", out_ports)

def call_obs_api(command='pause-toggle'):
    url = f'http://localhost:28000/{command}'
    print("Calling:", url)
    response = requests.get(url).json()
    print("OBS RESPONSE:", response)