Last active
August 9, 2020 19:47
-
-
Save asus4/1435b835ea0903c5ff96083b3e02778b to your computer and use it in GitHub Desktop.
Show message on APC mini.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: UTF-8 | |
''' | |
Setup apc mini colors without Ablton Live | |
---------- | |
> brew install portmidi | |
requirements.txt | |
mido | |
# https://github.com/olemb/mido | |
---------- | |
API mini cheetsheet | |
http://community.akaipro.com/akai_professional/topics/midi-information-for-apc-mini | |
''' | |
import os | |
import sys | |
import time | |
from itertools import chain | |
import mido | |
alphabet = { | |
'A': [ | |
0, 1, 1, 0, | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'B': [ | |
1, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 0, | |
], | |
'C': [ | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
], | |
'D': [ | |
1, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 0, | |
], | |
'E': [ | |
1, 1, 1, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 1, 1, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 1, 1, 1, | |
], | |
'F': [ | |
1, 1, 1, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 1, 1, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
], | |
'G': [ | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 1, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 1, | |
], | |
'H': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'I': [ | |
1, 1, 1, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
1, 1, 1, | |
], | |
'J': [ | |
0, 0, 0, 1, | |
0, 0, 0, 1, | |
0, 0, 0, 1, | |
0, 0, 0, 1, | |
0, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
], | |
'K': [ | |
1, 0, 0, 1, | |
1, 0, 1, 0, | |
1, 0, 1, 0, | |
1, 1, 0, 0, | |
1, 1, 0, 0, | |
1, 0, 1, 0, | |
1, 0, 1, 0, | |
1, 0, 0, 1, | |
], | |
'L': [ | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 1, 1, 1, | |
], | |
'M': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 1, | |
1, 1, 1, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'N': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 0, 1, | |
1, 1, 0, 1, | |
1, 0, 1, 1, | |
1, 0, 1, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'O': [ | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
], | |
'P': [ | |
1, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 1, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
1, 0, 0, 0, | |
], | |
'Q': [ | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 0, 1, | |
1, 0, 1, 0, | |
0, 1, 0, 1, | |
], | |
'R': [ | |
1, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 1, 1, 1, | |
1, 0, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'S': [ | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 0, | |
0, 1, 1, 0, | |
0, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
], | |
'T': [ | |
1, 1, 1, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
0, 1, 0, | |
], | |
'U': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
], | |
'V': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
0, 1, 1, 0, | |
0, 1, 1, 0, | |
], | |
'W': [ | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 1, 0, 1, | |
1, 0, 1, 0, 1, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
], | |
'X': [ | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
0, 1, 1, 0, | |
0, 1, 1, 0, | |
0, 1, 1, 0, | |
1, 0, 0, 1, | |
1, 0, 0, 1, | |
], | |
'Y': [ | |
0, 1, 0, 1, | |
0, 1, 0, 1, | |
0, 1, 0, 1, | |
0, 1, 0, 1, | |
0, 0, 1, 0, | |
0, 0, 1, 0, | |
0, 0, 1, 0, | |
0, 0, 1, 0, | |
], | |
'Z': [ | |
1, 1, 1, 1, | |
0, 0, 0, 1, | |
0, 0, 1, 0, | |
0, 0, 1, 0, | |
0, 1, 0, 0, | |
0, 1, 0, 0, | |
1, 0, 0, 0, | |
1, 1, 1, 1, | |
], | |
' ': [ | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
] | |
} | |
def print_data(data, clear=True): | |
# clear console | |
if clear: | |
os.system('cls' if os.name == 'nt' else 'clear') | |
# print to console | |
lines = [' '.join([('.' if x == 0 else 'x') for x in line]) | |
for line in data] | |
print('\n'.join(lines)) | |
def send_data(output, data): | |
l = list(chain.from_iterable(reversed(data))) | |
for i, color in enumerate(l): | |
msg = mido.Message('note_on', note=i, velocity=color) | |
output.send(msg) | |
# time.sleep(0.001) # wait 1ms | |
def initialize(debug=False): | |
# correct data [[0,0,0],[0,0,0]] style | |
for char, data in alphabet.iteritems(): | |
alphabet[char] = zip(*[iter(data)] * (len(data) / 8)) | |
if debug: | |
for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': | |
print('\n=== %s ===' % char) | |
print_data(alphabet[char], False) | |
def next(data, char_data, index): | |
for i, line in enumerate(data): | |
line.pop(0) | |
line.append(char_data[i][index]) | |
def space(data, width=1): | |
for line in data: | |
line.pop(0) | |
line.append(0) | |
def show_banner(message, device='APC MINI'): | |
message = message.upper() + ' ' | |
output = mido.open_output(device) | |
# make blank data | |
data = [[0] * 8 for i in range(8)] | |
for character in message: | |
cData = alphabet[character] | |
for i in range(0, len(cData[0])): | |
next(data, cData, i) | |
print_data(data) | |
send_data(output, data) | |
time.sleep(0.2) # wait 1ms | |
space(data) | |
print_data(data) | |
send_data(output, data) | |
time.sleep(0.15) # wait 0.1 sec | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser(description='APC mini display') | |
parser.add_argument('message', | |
type=str, | |
nargs='?', | |
default='ABCDEFGHIJKLMNOPQRSTUVWXYZ', | |
help='Message to show') | |
parser.add_argument('-d', '--device', | |
type=str, | |
default='APC MINI', | |
help='MIDI device name') | |
args = parser.parse_args() | |
initialize() | |
show_banner(args.message, args.device) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./apcmini_display.py hellow