Skip to main content

A Python library to drive an AKAI LPD8 pad controller

Project description

lpd8

A Python library to interface an AKAI LPD8 pad device

AKAI LPD8

This little library is designed to help the integration of an AKAI LPD8 pad into a Python program. It is easy to integrate and simple to use. Based on the rtmidi library, it uses MIDI messages to communicate with the LPD8 device and reads messages coming from it. In PAD mode, it allows some pads to blink or to have an ON (light on) and OFF (light off) state. It allows the use of 4 programs and has a sticky mode for knob controls, meaning that the library stores knob states for each program and only reacts to a knob if its value is set to its previous state for a given program. Knob limits and behaviours are configurable, so are pads. It uses a subscription mechanism for each event, allowing triggering of specific methods of objects. These methods may then implement other MIDI or OSC events or pilot a visual interface.

Example of use

from lpd8.lpd8 import LPD8
from lpd8.programs import Programs
from lpd8.pads import Pad, Pads
from lpd8.knobs import Knobs
from lpd8.pgm_chg import Pgm_Chg
from consummer import Consummer
from time import sleep

# This object is created to test different callbacks from LPD8 class
consummer = Consummer()

# Create an LPD8 object and try to start it (open MIDI in and out communication)
lpd8 = LPD8()
lpd8.start()

# In normal times, a control knob is meant to be sticky. That means that if we change program and then knob
# value, knob will not react when we return to original program until last stored value for this program
# will be reached. It will then follow changes normally
# Note that we can define sticky mode for a single knob, an array of knobs or all knobs
lpd8.set_not_sticky_knob(Programs.PGM_4, [Knobs.KNOB_1, Knobs.KNOB_2])

# In all following settings, we will define limits / actions for PROGRAM 4
# Define control knob 1 limits from -1 to 1 and set increments to float values
# Define control knob 2 limits from 0 to 100 with 10 steps (limit values to 0, 10, 20, ..., 90, 100)
# Define control knob 3 limits from 0 to 10000 with linear scale (default)
# Define control knob 4 limits from 0 to 10000 with exponential scale (slow increments at the beginning)
# Knobs that have no definition range from 0..127 with integer increments of 1 (default MIDI behaviour)
lpd8.set_knob_limits(Programs.PGM_4, Knobs.KNOB_1, -1, 1, is_int=False)
lpd8.set_knob_limits(Programs.PGM_4, Knobs.KNOB_2, 0, 100, steps=10)
lpd8.set_knob_limits(Programs.PGM_4, Knobs.KNOB_3, 0, 10000)
lpd8.set_knob_limits(Programs.PGM_4, Knobs.KNOB_4, 0, 10000, is_exp=True)

# Set An initial value for knob 3 and knob 4 to 5000
lpd8.set_knob_value(Programs.PGM_4, Knobs.KNOB_3, 5000)
lpd8.set_knob_value(Programs.PGM_4, Knobs.KNOB_4, 5000)

# Set different modes for pads
# Note that we can define modes for a single pad, an array of pads or all pads
# Pads 1 and two will blink and will be in switch mode (every push changes state between 0 and 1)
# Pad 3 won't blink but will be in switch mode too
# Pad 4 will be in push mode, sending a 1 at every NOTE ON event and a 0 at every NOTE OFF event
# Pads that have no definition are set in classical pad mode with NOTE ON / NOTE OFF events and velocity values
lpd8.set_pad_mode(Programs.PGM_4, [Pads.PAD_1, Pads.PAD_2], Pad.SWITCH_MODE + Pad.BLINK_MODE)
lpd8.set_pad_mode(Programs.PGM_4, Pads.PAD_3, Pad.SWITCH_MODE)
lpd8.set_pad_mode(Programs.PGM_4, Pads.PAD_4, Pad.PUSH_MODE)

# For a pad of type SWITCH, sets the initial state of pad
# Note that we can define modes for a single pad, an array of pads or all pads
lpd8.set_pad_switch_state(Programs.PGM_4, [Pads.PAD_1, Pads.PAD_3], Pad.ON)

# Subscribe to different events and map them to a method in test object
# Note that we can subscribe events for a single object, an array of objects or all objects of a group
lpd8.subscribe(consummer.ctrl_value, Programs.PGM_4, LPD8.CTRL, Knobs.ALL_KNOBS)
lpd8.subscribe(consummer.note_on_value, Programs.PGM_4, LPD8.NOTE_ON, Pads.ALL_PADS)
lpd8.subscribe(consummer.note_off_value, Programs.PGM_4, LPD8.NOTE_OFF, Pads.ALL_PADS)
lpd8.subscribe(consummer.pgm_change, Programs.PGM_4, LPD8.PGM_CHG, Pgm_Chg.PGM_CHG_4)
lpd8.subscribe(consummer.pgm_change, Programs.PGM_4, LPD8.PGM_CHG, Pgm_Chg.PGM_CHG_4)

# We loop as long as test class allows it
while consummer.is_running():

    # Every loop, we update pads status (blink, ON or OFF)
    # This method returns True if LPD8 pad is still running, False otherwise
    if lpd8.pad_update():
        sleep(.5)
    else:

        # If LPD8 pad is not running anymore, we leave the loop
        consummer.stop()

# We tidy up things and kill LPD8 process
lpd8.stop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lpd8-1.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lpd8-1.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file lpd8-1.1.1.tar.gz.

File metadata

  • Download URL: lpd8-1.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.6.1 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.5

File hashes

Hashes for lpd8-1.1.1.tar.gz
Algorithm Hash digest
SHA256 32bef669e805f5927c59e32806c1b99a1018a88b343bec4a16e8978adbcc20dd
MD5 69f9b6ca4662e0c6c1e708bd1bb96753
BLAKE2b-256 2680a17c043ad4fa5c60c0faa5b80c0b19597cfe9f135fd7201a12c8cef56b24

See more details on using hashes here.

File details

Details for the file lpd8-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: lpd8-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.6.1 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.5

File hashes

Hashes for lpd8-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c79dd545a838db5f969eefefc6b5bfbe963f0e617affd8b72076c2f02d05e92f
MD5 846840acebc7490cbbb5df705b56a422
BLAKE2b-256 f33ebe0b01679b398e6819a4275fa8ce83de8b58b2111d0309c7515a5a392772

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page