API to control the Maschine Mikro MK3
Project description
About
Python module to control the Maschine Mikro MK3. It allows you to use this maschine not only to create music, but also to control a home automation or a robot or any other creative stuff.
It uses directly the USB HID protocol, as a result there is no dependency on a product specific driver and it can run on any operating system. Furthermore, this gives you access to the full capabilities of this hardware which makes it even more fun to use.
Usage
import pymikro
maschine = pymikro.MaschineMikroMk3()
# control LEDs
lState = {
'button': {
'stop': {'val': 1}
},
'strip': {
1: {'val': 3, 'color': 'blue'}
},
'pad': {
1: {'val': 3, 'color': 'purple'}
}
}
maschine.setLights(lState)
maschine.setLight('pad', 6, 3, 'orange')
maschine.setLight('strip', 5, 3, 'green')
maschine.setLight('button', 'notes', 4)
maschine.updLights()
# control screen
maschine.setScreen("Hello World!\nIt's working")
# get button and pad updates
while True:
cmd = maschine.readCmd()
if cmd:
if cmd['cmd'] == 'pad':
print('Pad number {} pressed: {}'.format(cmd['pad_nb'], cmd['pad_val']))
if cmd['cmd'] == 'btn':
print('Buttons pressed: {}'.format(cmd['btn_pressed']))
Setup
Linux
Install the hid driver
sudo apt-get install libhidapi-hidraw0
Install the package
pip3 install pymikro
Set permissions for the device
cd /tmp
wget https://raw.githubusercontent.com/flokapi/pymikro/main/50-ni-maschine.rules
sudo cp 50-ni-maschine.rules /etc/udev/rules.d/
Plug or re-plug the maschine mikro USB cable.
Windows
Install the hid driver:
-
Donwload the latest version of
hidapi-win.zip
from https://github.com/libusb/hidapi/releases -
Extract the zip file and copy the
hidapi.dll
corresponding to your architecture toC:\Users\<Username>\AppData\Local\Programs\Python
Install the package
pip3 install pymikro
Plug or re-plug the maschine mikro USB cable.
About
Supported hardware features
Overall, there is actually more feature than the manufacturer uses :)
Pads:
- Set color (17 possible values) and intensity
- Get pressure value
- Info whether pressed, touched, or released
Buttons:
- get buttons being pressed
- set light brightness
Encoder:
- get value of the encoder (1 byte), and how much it moved
- whether it's being touched (not pressed)
Touch strip:
- get position of up to 2 fingers
- set color and brightness of each LED
Screen:
- set text with adjustable size, on 1 or 2 lines
Supported operating systems
Tested on Linux & Windows
Should also work on OSX by installing the hid api. See https://pypi.org/project/hid/
API
Connection
import pymikro
maschine = pymikro.MaschineMikroMk3()
maschine.showConnInfo()
Inputs
LEDs:
-
The state of the LEDs for the pads/touch strip/buttons is defined in a single data-structure which can be accessed and modified using the
getLights
andsetLights
methods. The LEDs can also be set individually usingsetLight
. -
To apply the changes,
updLights
must be called. Using a separate command allows to apply all the changes in a single write procedure (about 15ms) and increases the reactivity. -
Example:
maschine.setLights({}) # set empty dictionary to disable all LEDs maschine.updLights() time.sleep(1) lState = { 'button': { 'stop': {'val': 1} # Button brighness value must be between 0 }, 'strip': { 1: {'val': 4, 'color': 'blue'} # Touch Strip LED brightness value must be between 0 and 3 }, 'pad': { 1: {'val': 3, 'color': 'purple'} # Pad brightness value must be between 0 and 3 } } maschine.setLights(lState) maschine.setLight('pad', 6, 3, 'orange') # pad nb 6, brightness 3. maschine.setLight('strip', 5, 3, 'green') # strip led nb 5, brightness 3. maschine.setLight('button', 'notes', 4) # button 'notes', brightness 4. maschine.updLights()
Screen
-
Example
maschine.setScreen("Hello", 24) # Font size set to 24 maschine.setScreen(f"Hello World!\nIt's working") # Printing text on both lines with '\n'. # Default font size is 14
Outputs
Output commands can be read in a nonblocking way using the readCmd
method, which returns:
None
if no new command is available- A dictionary which content differs depending on the
cmd
key value (btn
orpad
) - Example:
cmd = maschine.readCmd()
Pads
-
The pad command is only sent when the state of a pad is being changed (pressed/touched/released). The pad command is sent for a single pad at the time.
-
Example
{ 'cmd': 'pad', 'pad_nb': 5, 'pad_val': 1360, # between 0 and 4095 'touched': True, # finger in contact with the pad 'pressed': False, # finger just pressed the pad (not 100% reliable) 'released': False # finger just released the pad (not 100% reliable) }
Buttons:
-
The button command is only sent when the state of the buttons/touch strip/encoder changed (including button release). The command contains the full state of the button group.
-
Example
{ 'cmd': 'btn', 'btn_pressed': ['group', 'pattern', 'enter'], # currently pressed buttons 'encoder_pos': 10, # byte, cyclic value between 0 and 15 'encoder_move': 1, # encoded moved to the right (+1) or left (-1) 'encoder_touched': True, # finger in contact with the encoder 'strip_pos_1': 123, # value of the strip if one finger touching 'strip_pos_2': 0 # second value if another finger is on the strip }
Alternatives
- Built for Linux only
- Makes the Maschine Mikro available through a midi interface
- Coded in Rust
Midi mode
-
Windows/OSX only (midi interface emulated by the driver)
-
press
shift
andproject
to enter midi mode -
you can use mido or any other software to handle the midi commands
-
limited features/customization
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymikro-0.0.16.tar.gz
.
File metadata
- Download URL: pymikro-0.0.16.tar.gz
- Upload date:
- Size: 398.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 361b0ce943b40848c57601d0fd3b471e4f29b7423e67665acbd7f3fad91eb07b |
|
MD5 | 2a63fd6dc6b00bc5c6ab5fb04b4982ff |
|
BLAKE2b-256 | c310afb15d346d12ff78c339ec645f811d22680e9d8e6549a9895e144aacc7c2 |
File details
Details for the file pymikro-0.0.16-py3-none-any.whl
.
File metadata
- Download URL: pymikro-0.0.16-py3-none-any.whl
- Upload date:
- Size: 395.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2bb952bc40c7abc576b1a574a8e49c6d643879097d8ad472ecee1066846b9da |
|
MD5 | 44e01a31675cd2293dca59243c1a4ed1 |
|
BLAKE2b-256 | 81e074ceb7f971cd2d3f28d6ce7d919954610d4c7c8fb3c725b0a9df53fe243a |