Giter VIP home page Giter VIP logo

rtmidi2's Introduction

rtmidi2

Python wrapper for RtMidi, the lightweight, cross-platform MIDI I/O library. For Linux, Mac OS X and Windows.

Based on rtmidi-python

Installation

pip install rtmidi2

This module is compatible with Python 3 >= 3.7

Documentation

https://rtmidi2.readthedocs.io


Usage Examples

rtmidi2 uses a very similar API as RtMidi

Print all in and out ports

import rtmidi2
print(rtmidi2.get_in_ports())
print(rtmidi2.get_out_ports())

Send messages

import rtmidi2

midi_out = rtmidi2.MidiOut()
# open the first available port
midi_out.open_port(0)
# send C3 with vel. 100 on channel 1
midi_out.send_noteon(0, 48, 100)

Get incoming messages - blocking interface

midi_in = rtmidi.MidiIn()
midi_in.open_port(0)

while True:
    message, delta_time = midi_in.get_message()  # will block until a message is available
    if message:
         print(message, delta_time)

Get incoming messages using a callback -- non blocking

def callback(message, time_stamp):
    print(message, time_stamp)

midi_in = rtmidi2.MidiIn()
midi_in.callback = callback
midi_in.open_port(0)

Open multiple ports at once

# get messages from all available ports
midi_in = MidiInMulti()
midi_in.open_ports("*")

def callback(msg, timestamp):
    msgtype, channel = splitchannel(msg[0])
    print(msgtype2str(msgtype), msg[1], msg[2])

midi_in.callback = callback

You can also get the device which generated the event by changing your callback to:

def callback(src, msg, timestamp):
    # src will hold the name of the device
    print("got message from", src)

Send multiple notes at once

# send a cluster of ALL notes with a duration of 1 second
midi_out = MidiOut()
midi_out.open_port()
notes = range(127)
velocities = [90] * len(notes)
midi_out.send_noteon_many(0, notes, velocities)
time.sleep(1)
midi_out.send_noteon_many(0, notes, [0] * len(notes))

License

rtmidi2 is licensed under the MIT License, see LICENSE.

It uses RtMidi, licensed under a modified MIT License, see RtMidi/RtMidi.h.

rtmidi2's People

Contributors

gesellkammer avatar thequilo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.