{"id":15717459,"url":"https://github.com/patrickkidd/pyrtmidi","last_synced_at":"2025-09-04T13:46:49.409Z","repository":{"id":3713501,"uuid":"4785433","full_name":"patrickkidd/pyrtmidi","owner":"patrickkidd","description":"Realtime MIDI I/O for python.","archived":false,"fork":false,"pushed_at":"2023-07-25T21:41:11.000Z","size":228,"stargazers_count":162,"open_issues_count":9,"forks_count":14,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-26T05:09:11.143Z","etag":null,"topics":["c-plus-plus","linux","macosx","midi","midimessage","python","realtime-midi","rtmidi","thread","windows"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickkidd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.txt","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-06-25T18:20:48.000Z","updated_at":"2025-05-04T17:22:22.000Z","dependencies_parsed_at":"2022-09-16T02:41:33.805Z","dependency_job_id":"e23494e2-7b81-454d-8e16-d1965186e17f","html_url":"https://github.com/patrickkidd/pyrtmidi","commit_stats":{"total_commits":61,"total_committers":5,"mean_commits":12.2,"dds":0.3770491803278688,"last_synced_commit":"143eaf2755b0b7284659dc618e17986b4cf8da57"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/patrickkidd/pyrtmidi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickkidd%2Fpyrtmidi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickkidd%2Fpyrtmidi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickkidd%2Fpyrtmidi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickkidd%2Fpyrtmidi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickkidd","download_url":"https://codeload.github.com/patrickkidd/pyrtmidi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickkidd%2Fpyrtmidi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273619431,"owners_count":25138237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","linux","macosx","midi","midimessage","python","realtime-midi","rtmidi","thread","windows"],"created_at":"2024-10-03T21:50:13.134Z","updated_at":"2025-09-04T13:46:49.374Z","avatar_url":"https://github.com/patrickkidd.png","language":"C++","readme":"pyrtmidi\n========\n\nRealtime MIDI I/O for Python on Windows, OS X, and Linux. Includes comprehensive MidiMessage class, support for virtual ports on OS X and Linux, and multi-threaded lister utility classes.\n\nPyrtmidi provides MIDI I/O for [PKMidiCron](http://vedanamedia.com/our-products/pkmidicron/).\n\nInstallation\n------------\n\nInstall using:\n\n```bash\npip install rtmidi\n```\n\nUsage\n-----\n\npyrtmidi is a Python interface to RtMidi. It provides real-time midi input and output.\n\n```python\n\nimport rtmidi\n\nmidiin = rtmidi.RtMidiIn()\n\ndef print_message(midi):\n    if midi.isNoteOn():\n        print('ON: ', midi.getMidiNoteName(midi.getNoteNumber()), midi.getVelocity())\n    elif midi.isNoteOff():\n        print('OFF:', midi.getMidiNoteName(midi.getNoteNumber()))\n    elif midi.isController():\n        print('CONTROLLER', midi.getControllerNumber(), midi.getControllerValue())\n\nports = range(midiin.getPortCount())\nif ports:\n    for i in ports:\n        print(midiin.getPortName(i))\n    print(\"Opening port 0!\") \n    midiin.openPort(0)\n    while True:\n        m = midiin.getMessage(250) # some timeout in ms\n        if m:\n            print_message(m)\nelse:\n    print('NO MIDI INPUT PORTS!')\n```\n\nThe API is copied *near* verbatim from the C++ code. Refer to the [RtMidi tutorial](http://www.music.mcgill.ca/~gary/rtmidi/), and take into account the following caveats:\n\n*RtMidiIn*\n\n`getMessage(timeout_ms=None)`\n\n * The message argument has been replaced with an optional millisecond timeout value.\n * The function will return a MidiMessage object, or None if no message is available.\n\n`setCallback`\n\n * This function works just as described in the above docs, and takes a python callable object.\n * This method is most useful with a queue.Queue object to communicate between threads.\n\n*MidiMessage*\n\nThis class has been taken from the juce library, and includes an excellent comprehensive set of midi functions. [please check here for available methods](https://www.juce.com/doc/classMidiMessage).\n\n*Recipes*\n\nThe following implements a QObject wrapper for rtmidi.RtMidiIn that emits a 'message()' signal. The essential code is follows:\n\n```python\nclass MidiInput(QThread):\n    def __init__(self, devid, parent=None):\n        QThread.__init__(self, parent)\n        self.device = rtmidi.RtMidiIn()\n        self.device.openPort(devid)\n        self.running = False\n\n    def run(self):\n        self.running = True\n        while self.running:\n            msg = self.device.getMessage(250)\n            if msg:\n                self.msg = msg\n                self.emit(SIGNAL('message(PyObject *)'), self.msg)\n                self.emit(SIGNAL('message()')\n\nmidi = MidiInput(1)\ndef slotMessage(msg):\n   print msg\nQObject.connect(midi, SIGNAL('message(PyObject *)'), slotMessage)\n```\n\nThe following implements a midi echo for all ports.\n\n```python\n\nimport sys\nimport rtmidi\nimport threading\n\ndef print_message(midi, port):\n    if midi.isNoteOn():\n        print '%s: ON: ' % port, midi.getMidiNoteName(midi.getNoteNumber()), midi.getVelocity()\n    elif midi.isNoteOff():\n        print '%s: OFF:' % port, midi.getMidiNoteName(midi.getNoteNumber())\n    elif midi.isController():\n        print '%s: CONTROLLER' % port, midi.getControllerNumber(), midi.getControllerValue()\n\nclass Collector(threading.Thread):\n    def __init__(self, device, port):\n        threading.Thread.__init__(self)\n        self.setDaemon(True)\n        self.port = port\n        self.portName = device.getPortName(port)\n        self.device = device\n        self.quit = False\n\n    def run(self):\n        self.device.openPort(self.port)\n        self.device.ignoreTypes(True, False, True)\n        while True:\n            if self.quit:\n                return\n            msg = self.device.getMessage()\n            if msg:\n                print_message(msg, self.portName)\n\n\ndev = rtmidi.RtMidiIn()\ncollectors = []\nfor i in range(dev.getPortCount()):\n    device = rtmidi.RtMidiIn()\n    print 'OPENING',dev.getPortName(i)\n    collector = Collector(device, i)\n    collector.start()\n    collectors.append(collector)\n\n\nprint 'HIT ENTER TO EXIT'\nsys.stdin.read(1)\nfor c in collectors:\n    c.quit = True\n```\n\n\n\n\nCommon Problems\n-----------------\n\nThis is a commonly reported build error on linux, although I it works for me using python2.7 on ubuntu.\n\n```\n:~/devel/pkaudio/pyrtmidi/tests$ python test_rtmidi.py \nTraceback (most recent call last):\nFile \"test_rtmidi.py\", line 29, in \nimport rtmidi\nImportError: /usr/local/lib/python2.6/dist-packages/rtmidi.so: undefined symbol: _ZN11MidiMessageaSERKS_\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickkidd%2Fpyrtmidi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickkidd%2Fpyrtmidi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickkidd%2Fpyrtmidi/lists"}