Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gamepad module #1223

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add Gamepad module #1223

wants to merge 6 commits into from

Conversation

nkymut
Copy link

@nkymut nkymut commented Nov 26, 2024

Adds gamepad support for Strudel, allowing users to use game controllers as expressive input devices for live coding music.

Examples

const pad = gamepad(0) //initialize gemepad

// Use button values to control amplitude
$: sequence([
  s("bd").gain(pad.X),    // X button controls gain
  s("[hh oh]").gain(pad.tglY),    // Y button toggles gain
]);

// Use analog stick for continuous control
$: note("c4*4".add(pad.y1_2.range(-24,24))) // Left stick Y controls pitch shift
  .pan(pad.x1_2);          // Left stick X controls panning

// Define button sequences
const HADOKEN = [
  'd',               // Down
  'r',               // Right
  'a',               // A
];

const KONAMI = 'uuddlrlrba' //Konami Code ↑↑↓↓←→←→BA

// Add these lines to enable buttons(but why?)
$:pad.D.segment(16).gain(0)
$:pad.R.segment(16).gain(0)
$:pad.A.segment(16).gain(0)

// Check button sequence (returns 1 when detected, 0 when not within last 1 second)
$: sound("hadoken").gain(pad.checkSequence(HADOKEN))

Testing Done

  • Tested with Logitech Gamepad F310
  • Tested with Xbox controller
  • Tested with PS4/PS5 controller
  • Tested with Nintendo Switch controller

@nkymut nkymut changed the title Add GamePad Module Add Gamepad module Nov 26, 2024
@felixroos
Copy link
Collaborator

this is super cool, I have to test this. I especially like that you can do sequences!
I can test it with my gamepads as well. A docs page for this would also be very good (similar to the README).

@nkymut
Copy link
Author

nkymut commented Dec 17, 2024

Thanks! I’m glad you liked the key sequences.
I’ve added a documentation page, and I’m hoping that other input methods—such as MIDI-in or serial input—can also be documented on the same page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants