コード例 #1
0
    def run(self):
        global DEFAULT_BUS
        rtmidi = mido.Backend('mido.backends.rtmidi')
        #Will have to be passed to the function
        busname = self._bus_name
        current_active_busses = rtmidi.get_input_names()
        if busname == DEFAULT_BUS:
            src_bus = current_active_busses[0]
        else:
            if busname not in current_active_busses: return
            src_bus = busname

        logging.info("Igniting midi event loop")
        with rtmidi.open_input(src_bus) as port:
            for message in port:
                note = {
                    'note': getattr(message, 'note', None),
                    'velocity': getattr(message, 'velocity', None),
                    'type': getattr(message, 'type', None),
                    'channel': getattr(message, 'channel', None),
                    'bus': busname
                }

                if str(note.get("channel")) in self._channels:
                    self._results_queue.put(note)
                    logging.info("%s" % note)

                if self._exit_loop:
                    logger.info("Exiting loop for bus " + busname)
                    break

        if port.closed:
            print("Yup, it's closed.")
コード例 #2
0
    def run(self):
        global DEFAULT_BUS
        logging.info("Started MIDI thread")
        #can start multiple, listening to various busses
        if len(self._active_processes):
            for t in self._active_processes:
                t.join()
            self._active_processes = []

        results_queue = multiprocessing.Queue()
        for bus, channels in self._active_channels_data.iteritems():
            #Default bus is the first one of the active busses
            rtmidi = mido.Backend('mido.backends.rtmidi')

            midi_loop_process = MidiBusProcess(results_queue, channels, bus)
            self._active_processes.append(midi_loop_process)
            midi_loop_process.start()

        try:
            while (True):
                logging.info("Waiting for note")
                latest_note = results_queue.get(True, 10)
                logging.info("Note received")
                self._on_midi_note(latest_note)
        except Empty:
            logging.warning("Stopping MIDI processes")
            for process in self._active_processes:
                process.join()
            logging.warning("Processes stopped")

        logging.warning("Stopping MIDI thread")
コード例 #3
0
ファイル: midiMonitor.py プロジェクト: hw9603/Easy-Sing
 def run(self):
     try:
         rtmidi = mido.Backend('mido.backends.rtmidi')
         input = rtmidi.open_input()
         output = connect('localhost', 8080)
         for message in input:
             output.send(message)
     except:
         print("No input device detected!")
コード例 #4
0
def get_rtmidi_backends():
    """Return available full (backend + api) mido rtmidi configuration
    options as a list of strings.
    """
    try:
        rtmidi = mido.Backend('mido.backends.rtmidi', load=True)
        return ['mido.backends.rtmidi/' + b for b in rtmidi.module.get_api_names()]
    except ImportError:
        return []
コード例 #5
0
    def __init__(self):
        # Register the settings widget
        AppSettings.register_settings_widget(MIDISettings)

        bk_name = config['MIDI']['Backend']
        try:
            # Load the backend and set as current mido backend
            mido.set_backend(mido.Backend(bk_name, load=True))
        except Exception:
            raise RuntimeError('Backend loading failed: {0}'.format(bk_name))
コード例 #6
0
def get_mido_backend():
    """Create the mido backend from environment. Note: if not configured
    in environment it will return the first available API for rtmidi.
    """
    log.debug("MIDO_BACKEND from env: {}".format(os.environ.get('MIDO_BACKEND')))
    if not 'MIDO_BACKEND' in os.environ:
        rtmidi_apis = get_rtmidi_backends()
        if rtmidi_apis:
            os.environ['MIDO_BACKEND'] = rtmidi_apis[0]
    if 'MIDO_BACKEND' in os.environ:
        backend = mido.Backend(os.environ.get('MIDO_BACKEND'), load=True)
        log.debug("Using backend {}.".format(backend))
        return backend
    else:
        return mido
コード例 #7
0
ファイル: midilights.py プロジェクト: bookdude13/midilights
def main():
    # Parse arguments
    arguments = docopt(help_text)
    
    backend = mido.Backend(arguments['<backend>'])

    if (arguments['list']):
        inputs = backend.get_input_names()
        print(inputs)
    elif (arguments['run']):
        input_name = arguments['<midi-input>']
        mapper = get_mapper(arguments)
        (out_fn, cleanup_fn) = get_run_type_functions(arguments)

        run(input_name, mapper, backend, out_fn, cleanup_fn)
    else:
        print("How did we get here?? (docopt failed us or command not accounted for)")
コード例 #8
0
 def __init__(self):
     self.backend = mido.Backend('mido.backends.rtmidi')
     try:
         self.input = self.backend.open_input('QU-32 MIDI Out')
         self.output = self.backend.open_output('QU-32 MIDI In')
     except:
         self.input = self.backend.open_input()
         self.output = self.backend.open_output()
         print('WARNING - Not connected to sound board!!!')
     self.header = b'\xF0\x00\x00\x1A\x50\x11\x01\x00\x00'
     self.parser = mido.Parser()
     self.last_message = None
     self.messages = [None]
     self.patches = {
         'cesar': 39,
         'ruben': 40,
         'helen': 42,
         'naylor': 34,
         'naylor2': 36,
         'doc': 34,
         'sherrif': 35,
         'father': 35,
         'woman': 36,
         'carlos': 41,
         'rfk': 35,
         'gray': 34,
         'leads': 16,
         'choir': 17,
         'band': 19,
         'fx': 0,
         'god': 33,
         'tomas': 32,
         'usher': 32,
         'old': 32,
         'dolores': 32,
         'fred': 34,
         'jim': 42,
         'danny': 32,
         'charles': 32,
         'reporter': 32,
         'maricella': 37,
         'monica': 36,
         'ernesto': 37,
         'god': 33
     }
コード例 #9
0
from MusiStrata import *
import mido
import pygame

from dataclasses import dataclass

rtmidi = mido.Backend('mido.backends.rtmidi')

freq = 44100  # audio CD quality
bitsize = -16  # unsigned 16 bit
channels = 2  # 1 is mono, 2 is stereo
buffer = 1024  # number of samples
pygame.mixer.init(freq, bitsize, channels, buffer)


@dataclass
class SongData:
    Tempo: int = 80


@dataclass
class TrackData:
    Name: str = "Unnamed"
    Volume: float = 0.8
    RhythmicModel: str = "Standard"
    MelodicModel: str = "Random"
    Instrument: str = "Grand Piano"


class StateMachine(object):
    def __init__(self):
コード例 #10
0
ファイル: io.py プロジェクト: brendanaaa/Learnbgame
#################################

import mido

##############VARS##############

input_list = None

################################


##############INIT##############

print("starting Nimbus MIDI....")
print("Starting mido, loading rtmidi backend...")
try: mido.Backend(load = True) #loads default backend, rt_midi
except ModuleNotFoundError:
    print("rtmidi not installed! This is a bug!!")
    raise Exception('LIB MISSING!!')
print("Backend loaded.")
print("Getting device list...")
print("...inputs...")

input_list = Input.getNames() ###Sets var with some defaults
print(input_list)

print("...outputs...")

output_list = Output.getNames) ###Sets var with some defaults
print(output_list()
コード例 #11
0
ファイル: midiparser.py プロジェクト: kaosbeat/123piprint
import mido
import musicconcepts as mc

mido.Backend('mido.backends.rtmidi/UNIX_JACK')

# print("getting input ports")
print(mido.get_input_names())
inport = mido.open_input('MidiSport 1x1:MidiSport 1x1 MIDI 1')
inport.callback = mc.dostuff