Created
July 5, 2019 19:06
-
-
Save jsheedy/766c63fc443bb376b999ed39636046e5 to your computer and use it in GitHub Desktop.
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
""" quick hack to press the buttons on the Spotify desktop app based on nanoKONTROL transport buttons using cliclick. | |
The volume control on slider 1 is especially janky """ | |
import subprocess | |
import rtmidi | |
midiin = rtmidi.RtMidiIn() | |
def print_message(midi): | |
if midi.isNoteOn(): | |
print('ON: ', midi.getMidiNoteName(midi.getNoteNumber()), midi.getVelocity()) | |
elif midi.isNoteOff(): | |
print('OFF:', midi.getMidiNoteName(midi.getNoteNumber())) | |
elif midi.isController(): | |
print('CONTROLLER', midi.getControllerNumber(), midi.getControllerValue()) | |
for i in range(midiin.getPortCount()): | |
name = midiin.getPortName(i).strip() | |
print(name) | |
if name.startswith('nanoKONTROL'): | |
print('opening nanoKONTROL') | |
midiin.openPort(i) | |
break | |
while True: | |
m = midiin.getMessage(1000) # some timeout in ms | |
if m: | |
print_message(m) | |
if m.isController() and m.getControllerValue() == 127: | |
if m.getControllerNumber() == 45: | |
print('play') | |
cmd = 'cliclick -e 50 m:720,890 c:. m:720,850 c:.' | |
elif m.getControllerNumber() == 46: | |
cmd = 'cliclick -e 50 m:720,890 c:. m:720,850 c:.' | |
print('stop') | |
elif m.getControllerNumber() == 48: | |
cmd = 'cliclick -e 50 m:720,890 c:. m:770,850 c:.' | |
print('next') | |
elif m.getControllerNumber() == 47: | |
cmd = 'cliclick -e 50 m:720,890 c:. m:670,850 c:.' | |
print('prev') | |
elif m.getControllerNumber() == 49: | |
cmd = 'cliclick -e 50 m:720,890 c:. m:820,850 c:.' | |
print('repeat') | |
elif m.isController() and m.getControllerNumber() == 2: | |
# range = 1300, 1380 | |
width = 80 | |
x = 1300 + int(80 * m.getControllerValue()/127) | |
cmd = f'cliclick m:720,890 c:. m:{x},856 c:.' | |
print('vol') | |
else: | |
print('???') | |
continue | |
subprocess.run(cmd.split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment