Skip to content

Commit

Permalink
Support for sending MIDI notes as keys (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerego committed Oct 1, 2021
1 parent 7a26697 commit 83ebf8e
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 4 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,43 @@ example from the
- Macros for Blender, Safari, generic number pad and Zoom
- Support for HID consumer control codes
- Support for mouse buttons
- Support for sending MIDI notes
- When no HID connection is present (power only), keep LEDs off and provide a message
- Mount filesystem as read-only unless the encoder button is pressed on boot
- Refactored the code to make it (maybe) easier to modify


## Using

You use the Macropad Hotkeys much like the original
[Adafruit version](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/LICENSE),
with a few differences.

Use the dial to select the macro template you would like to use. The macros appear
in the order specified within each config file (see [Configuration](#configuration) below for details).
Once you have the macro you like selected, you are free to hammer away at the keys.

Click the rotary dial to turn off the display & LEDs - click it again to turn it back on.
Note the keys continue to respond even when they are not lit.


## Configuration

The `macros/` folder has a list of macro templates to chose from, all of which
can be altered at your whim. First make sure to mount your Macropad in read/write
mode (see [Updating](#updating)) and then open up the `.py` examples in the
`macros/` folder. Note that each has a list of settings, including:

- The name that will show at the top of the OLED display
- The sequential order that it will be shown when rotating the encoder dial
- A list of macros, sorted by row

Each macro consists of an LED color, a label to appear on the OLED display,
and a sequence of keys. A "key" can be text, a keyboard key, a consumer control
key (like play/pause), a mouse action, or a MIDI note. More than one key can
be specified in a sequence.


## Installing

When installing for the first time, extract the latest
Expand All @@ -25,6 +58,7 @@ into the CIRCUITPY drive that appears when you plug in your Macropad.
Ensure that the contents of the `lib/` subdirectory are also copied - these are
the precompiled Adafruit libraries that power the Macropad.


## Updating

After you first install this version of Macropad Hotkeys and reboot the Macropad,
Expand Down
3 changes: 3 additions & 0 deletions keyfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from mouse import Mouse
from sleeper import Sleep
from keyboard import Keyboard
from midi import Midi

def get(item):
if isinstance(item, Toolbar):
return item
elif isinstance(item, Mouse):
return item
elif isinstance(item, Midi):
return item
elif isinstance(item, float):
return Sleep(item)
else:
Expand Down
2 changes: 1 addition & 1 deletion macros/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

app = {
'name' : 'Blender',
'order': 2,
'order': 1,
'macros' : [
# COLOR LABEL KEY SEQUENCE
# 1st row ----------
Expand Down
28 changes: 28 additions & 0 deletions macros/drumkit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MACROPAD Hotkeys: Drum Kit
# https://en.wikipedia.org/wiki/General_MIDI#Percussion

from midi import Midi

app = {
'name' : 'Drum Kit',
'order': 3,
'macros' : [
# COLOR LABEL KEY SEQUENCE
# 1st row ----------
(0x544408, 'HatFot', [Midi(44)]),
(0x544408, 'HatCls', [Midi(42)]),
(0x544408, 'HatOpn', [Midi(46)]),
# 2nd row ----------
(0x04541B, 'XStick', [Midi(37)]),
(0x095E06, 'Snare', [Midi(38)]),
(0x04541B, 'Rod', [Midi(91)]),
# 3rd row ----------
(0x000754, 'FlorTom', [Midi(43)]),
(0x000754, 'LowTom', [Midi(47)]),
(0x000754, 'HiTom', [Midi(48)]),
# 4th row ----------
(0x540908, 'Bass', [Midi(35)]),
(0x540908, 'Kick', [Midi(36)]),
(0x04541B, 'Cowbell', [Midi(56)])
]
}
2 changes: 1 addition & 1 deletion macros/mac-safari.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

app = {
'name' : 'MacOS Safari',
'order': 3,
'order': 4,
'macros' : [
# COLOR LABEL KEY SEQUENCE
# 1st row ----------
Expand Down
2 changes: 1 addition & 1 deletion macros/nms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

app = {
'name' : 'No Man\'s Sky',
'order': 4,
'order': 5,
'macros' : [
# COLOR LABEL KEY SEQUENCE
# 1st row ----------
Expand Down
2 changes: 1 addition & 1 deletion macros/numpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

app = {
'name' : 'Numpad',
'order': 1,
'order': 2,
'macros' : [
# COLOR LABEL KEY SEQUENCE
# 1st row ----------
Expand Down
15 changes: 15 additions & 0 deletions midi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
VELOCITY = 127

class Midi:
def __init__(self, note):
self.note = note

def press(self, macropad):
if self.note < 0:
macropad.midi.send(macropad.NoteOff(self.note, 0))
else:
macropad.midi.send(macropad.NoteOn(self.note, VELOCITY))

def release(self, macropad):
if self.note >= 0:
macropad.midi.send(macropad.NoteOff(self.note, 0))

0 comments on commit 83ebf8e

Please sign in to comment.