Package: lpminimk3
lpminimk3Python API for theNovation Launchpad Mini MK3The goals of this project are as follows:Intuitive, object-oriented designConvenient for use in script and shellAccess to all (or most) of the Launchpad Mini MK3 MIDI featuresInstallationTo install the most stable version of this package, run:$pipinstalllpminimk3To test the installation, connect your Launchpad to your computer and run:$python-mlpminimk3.examples.helloUsage exampleMake sure your Launchpad is connected to your computer.In scriptControl LEDs individually:"""Display a random array of colors for 5 seconds."""fromlpminimk3importMode,find_launchpadsimportrandomimporttimelp=find_launchpads()[0]# Get the first available launchpadlp.open()# Open device for reading and writing on MIDI interface (by default)lp.mode=Mode.PROG# Switch to the programmer modeforledinlp.panel.led_range():# Loop through all LEDsled.color=random.randint(1,127)# Set LED to a random colortime.sleep(5)# Keep LEDs on for a whileforledinlp.panel.led_range():delled.color# Turn off LEDRender text on Launchpad's surface:"""Scroll text from right to left across the Launchpad's surface."""fromlpminimk3importMode,find_launchpadsfromlpminimk3.graphicsimportTextlp=find_launchpads()[0]# Get the first available launchpadlp.open()# Open device for reading and writing on MIDI interface (by default)lp.mode=Mode.PROG# Switch to the programmer modelp.grid.render(Text(' Hello, world!').scroll())# Scroll text onceSee more exampleshere.In shellStart by finding a connected device and opening the device for reading and writing:$python
>>>importlpminimk3
>>>lp=lpminimk3.find_launchpads()[0]>>>lp.open()Query the device to ensure we can read and write to it:>>>lp.device_inquiry()# Query deviceMidiEvent(message=[240,0,32,41,2,13,14,1,247],deltatime=150.938086752)Switch toprogrammermode to start manipulating button LEDs:>>>lp.mode='prog'# Switch to programmer mode>>>lp.grid.led(0).color=10# Set color of LED at grid position 0 to yellow (Valid values: 0 - 127)>>>lp.grid.led(1,0).color=lpminimk3.colors.ColorPalette.Red.SHADE_1# Set from palette>>>lp.grid.led('0x1').color=lpminimk3.colors.WebColor("amethyst")# Set color from web colors>>>lp.panel.led('logo').color='violet'# Set logo LED color to violet>>>lp.panel.led('drums').color='green2'# Set 'Drums' LED color to second shade of green>>>lp.panel.led('stop').color='w1'# Set 'Stop/Solo/Mute' LED color to first shade of white>>>lp.panel.led('mute').color='o3'# Set 'Stop/Solo/Mute' LED color to third shade of orange>>>lp.panel.led('mute').color='r0'# Invalid but okay, will default to 'r1'>>>lp.panel.led('scene_launch_1').color='#ff0000'# Set color to red using hex>>>lp.panel.led('scene_launch_2').color=(0,0,255)# Set color to blue using rgb>>>lp.panel.led('mute').color=0# Turn off LED>>>lp.panel.led('logo').reset()# Another way to turn off LED>>>dellp.panel.led('stop').color# Another way to turn off LED>>>lp.panel.reset()# Turn off all LEDsNote in the above snippet thatlp.gridonly contains thegridbuttons
(i.e. the translucent, faceless buttons) andlp.panelcontains all buttons
(including thelogoLED at the top right corner).Wait for and respond to button presses and releases:>>>ev=lp.panel.buttons().poll_for_event()# Block until any button is pressed/released>>>evButtonEvent(button='7x5',type='press',deltatime=0.0)Or only button releases instead:>>>ev=lp.panel.buttons().poll_for_event(type='release')# Block until released>>>evButtonEvent(button='up',type='release',deltatime=0.0)Pass button names as arguments to wait for specific button events:>>>lp.panel.buttons('up','0x0','stop').poll_for_event()RenderAon Launchpad's surface:>>>fromlpminimk3.graphicsimportText>>>lp.grid.render(Text('A'))PrintAin console:>>>Text('A').print()XXXXXXXXXXXXXXXXXXXXXXXXXXXXScrollHello, world!on Launchpad's surface indefinitely:>>>lp.grid.render(Text(' Hello, world!').scroll(count=-1))Extended graphics supportlpminimk3is also capable of rendering graphics frombitmapsandmovies. These are JSON files that describe the rendering data in a high-level format. Data in these files are grouped asframes. Aframeis a sequence of bits and their color configurations. Abitmapfile consists of a single frame while amoviefile consists of a sequence of frames.Syncing with LP SketchIf you want to create and edit bitmaps and/or movies with a graphical tool, tryLP Sketch. LP Sketch is a free online Launchpad editor specifically designed for use withlpminimk3. You can also sync your Launchpad with LP Sketch by startinglpminimk3's sync server:$python-mlpminimk3.graphics.syncOnce the server is running, visit theLP Sketchwebsite to start creating bitmaps and movies live.Rendering bitmaps and moviesRendersmiley.bitmap.jsonon Launchpad's surface:"""Render "Smiley" bitmap."""fromlpminimk3importMode,find_launchpadsfromlpminimk3.graphicsimportBitmapfromlpminimk3.graphics.artimportBitmapslp=find_launchpads()[0]# Get the first available launchpadlp.open()# Open device for reading and writing on MIDI interface (by default)lp.mode=Mode.PROG# Switch to the programmer modelp.grid.render(Bitmap(Bitmaps.SMILEY))# Display bitmap# OR# lp.grid.render(Bitmap("/path/to/smiley.bitmap.json"))Renderping_pong.movie.jsonon Launchpad's surface:"""Render "Ping/Pong" movie."""fromlpminimk3importMode,find_launchpadsfromlpminimk3.graphicsimportMoviefromlpminimk3.graphics.artimportMovieslp=find_launchpads()[0]# Get the first available launchpadlp.open()# Open device for reading and writing on MIDI interface (by default)lp.mode=Mode.PROG# Switch to the programmer modelp.grid.render(Movie(Movies.PING_PONG).play())# Play movie once# OR# lp.grid.render(Movie("/path/to/ping_pong.movie.json").play())For convenience, you can use the render script,render.py:$python-mlpminimk3.graphics.render-f/path/to/bitmap/or/movie.jsonrender.pycan be used to render text, bitmaps and movies on the Launchpad and on the console. For more options, run:$python-mlpminimk3.graphics.render-hLicenseMIT