Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
""" 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
You can’t perform that action at this time.