Key Plane

Example script (scamp_extensions): examples/Interactivity & visualization/Keyboard input/key_plane_example.py

Download: key_plane_example.py

Requires the scamp_extensions package (pip install scamp_extensions).

Maps the computer keyboard onto a 2D grid of pitches with scamp_extensions’ KeyPlane; each key press starts a flute note whose pitch and volume come from its row and column.

Topics: Interactivity & visualization › Keyboard input

from scamp_extensions.interaction import KeyPlane
from scamp_extensions.utilities import remap
from scamp import *

s = Session()

flute = s.new_part("flute")

notes = {}


def callback(coordinates, press_or_release, modifiers):
    if press_or_release == "press":
        print("Press at:", coordinates, "with modifiers", modifiers)
        notes[coordinates] = flute.start_note(remap(coordinates[0], 60, 96, 0, 1), remap(coordinates[1], 0.3, 1, 0, 1))
    else:
        print("Release at:", coordinates, "with modifiers", modifiers)
        if notes[coordinates]:
            notes[coordinates].end()


KeyPlane(callback, normalize_coordinates=True).start(blocking=True, suppress=True)