Skip to content

Instantly share code, notes, and snippets.

@daffl
Created December 12, 2021 06:08
Show Gist options
  • Save daffl/1a687a48fa38ee878b31612f230fa9eb to your computer and use it in GitHub Desktop.
Save daffl/1a687a48fa38ee878b31612f230fa9eb to your computer and use it in GitHub Desktop.
TapSDK MIDI mapper
from logging import NullHandler
from tapsdk import TapSDK, TapInputMode
from tapsdk.models import AirGestures
import time
import rtmidi
import asyncio
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
if available_ports:
midiout.open_port(0)
else:
midiout.open_virtual_port("My virtual output")
noteMap = {
1: [ 41 ],
2: [ 43 ],
4: [ 45 ],
5: [ 41, 45 ],
8: [ 47 ],
10: [ 45, 48 ],
16: [ 48 ],
20: [ 48, 52 ]
}
lastNotes = []
def OnTapped(identifier, tapcode):
global lastNotes
print("Got tap " + str(tapcode))
for n in lastNotes:
midiout.send_message([0x80, n, 0])
if tapcode in noteMap:
notes = noteMap[tapcode]
for n in notes:
midiout.send_message([0x90, n, 112])
lastNotes = notes
print("Playing note " + str(lastNotes))
async def run(loop=None):
client = TapSDK(None, loop)
if not await client.client.connect_retrieved():
print("Failed to connect the the Device.")
return
print("Connected to {}".format(client.client.address))
await client.register_tap_events(OnTapped)
while True:
await client.set_input_mode(TapInputMode("controller"))
await asyncio.sleep(8.0, loop=loop)
print("re-looping")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment