Sonic Pi gamepad control is the cheat code that makes coded-music lessons actually fun for nine-year-olds. Sonic Pi already runs in roughly half the UK's primary IT trolleys — Sam Aaron's code-to-make-sound editor is a household name in Year 5 and 6 classrooms. The wall a teacher hits, every time, is that kids can write a live_loop just fine but they then have to keep their hands on the keyboard to change anything. A controller in each kid's hand fixes that: the code runs, and they perform on top of it. This guide is for the teacher rolling Sonic Pi into a classroom and the parent rebuilding the same rig at home.
- What you build: Sonic Pi reading gamepad CCs via
sync :midi_ccand a teacher-mute-all hotkey. - What you need: Sonic Pi 5+, any USB-C gamepad, Universal Controller MIDI (free tier is plenty for one student).
- Cost per seat: ~$30 for a refurbished Xbox controller, $0 for Sonic Pi, $0 for the bridge in free mode.
- Best fit: Year 4 upward in school, age 8+ at home.
Why a gamepad belongs in a Sonic Pi lesson
Kids learn Sonic Pi best when they can hear what they changed within five seconds of changing it. The block-coding gap closes when a stick wiggle re-maps a filter on a running loop, and the kid grins, and the next idea lands. A keyboard breaks that loop — you've got to look at the right key, type the variable, hit run, wait. A gamepad doesn't. They already know which button is X. A child can build a stick → cutoff macro inside one session and remix the same loop for the next ten minutes without typing.
Worth being honest about the cost story too: a refurbished Xbox controller runs about £25 in the UK. A "real" classroom MIDI controller is £150+. Schools buy the controller, the bridge runs in free mode for the one-device-per-laptop case, and the music-tech budget covers the headphones instead.
Classroom rig — the install
Three steps per student laptop, ten minutes total:
- Install Sonic Pi 5+ from the official site.
- Install Universal Controller MIDI. Run it once, accept any OS permissions prompts, switch to Classroom preset.
- Plug a gamepad into the USB-C port. The bridge auto-detects, the icon goes green, and the gamepad shows up as a MIDI source named
Gamepadin Sonic Pi.
That's it. The Classroom preset hides the full mapping editor, locks the layout to the defaults below, and exposes one big "mute all" hotkey for the teacher's controller. No deeper config is necessary or even surfaced.
The first ten-minute lesson
Below is a complete Sonic Pi snippet for the kids to type in (or paste — it's the first session, they'll learn to type it themselves by week three). A live_loop plays a melody. Two sync :midi_cc calls watch for gamepad CC 16 (left stick X) and CC 21 (right trigger) and feed those values into the synth.
use_synth :tb303
# Start at default values — overwritten by the gamepad as soon as it moves
cutoff_val = 80
amp_val = 1.0
# Listen for gamepad CCs in a separate live_loop
live_loop :read_pad do
vals = sync "/midi_cc:gamepad"
cc = vals[0]
val = vals[1]
cutoff_val = val.to_f * 130 / 127 if cc == 16 # left stick X → cutoff
amp_val = val.to_f / 127 if cc == 21 # R2 trigger → volume
end
# The melody loop
live_loop :melody do
play scale(:e3, :minor_pentatonic).choose,
cutoff: cutoff_val,
amp: amp_val,
release: 0.3
sleep 0.25
end
Two minutes of typing and the kid is now performing on a TB-303 patch — sweeping cutoff with the left thumb, volume with the right trigger. Hit the X button (mapped to a :cue :drop in the bridge preset) and the loop ducks. The whole thing fits on the projector screen.
Default classroom CC map
| Gamepad input | CC / note | Sonic Pi suggestion | What kids do with it |
|---|---|---|---|
| Left stick X | CC 16 | cutoff on :tb303 | Squelch sweeps |
| Left stick Y | CC 17 | res on filter | Make it weird |
| Right stick X | CC 18 | pan 0–1 mapped to -1..1 | Pan across headphones |
| Right stick Y | CC 19 | release 0.05–1.0 | Long vs stabby notes |
| R2 trigger | CC 21 | amp | Master volume in their hand |
| L2 trigger | CC 20 | mix on FX | FX wet/dry |
| Cross button | Note 60 | cue :drop in a sync loop | Stinger / drop hit |
| D-pad up/down | Notes 61–62 | cue :up / cue :down | Octave shift |
The teacher controller — one rig to rule them all
Hand the teacher their own gamepad too. The bridge has a Teacher preset that emits a global Mute All SysEx broadcast — every classroom laptop running the bridge listens on the same UDP port (school LAN only, off by default for safety). One click on a teacher controller's right stick click, and every kid's Sonic Pi session goes silent for thirty seconds. Hit it again to release. This is the single feature that makes 24 simultaneous gamepad rigs work in a real room.
If the school's IT policy disallows that UDP broadcast, the fallback is a teacher-only macro that pastes set_volume! 0 into every focused Sonic Pi window via accessibility keystrokes. Slower, but no network involved.
The at-home rig — same files, no headphones war
A child opens the same .rb file at home. Plugs in the gamepad they already use for FIFA. The bridge launches. Sonic Pi launches. The loop runs. The parent in the kitchen does not have to know what Ruby is. For families with a Raspberry Pi 4, the whole stack runs on the Pi with a £40 budget — Pi, microSD, headphones — and the gamepad you've already got. Sonic Pi was originally written for the Pi 4. Sam Aaron is on record about that being the design goal.
For more on why a controller is a great first MIDI device for kids generally, see our earlier post on gamepad as a first MIDI controller. Pair that piece with this one and the case to a head of music writes itself.
Where it leads
The kid who learned Sonic Pi with a gamepad is the kid who graduates into SuperCollider gamepad patterns three years later. Sonic Pi is a stepping stone; the gamepad is the lever that makes the first hour fun enough to come back for the second. Drop Universal Controller MIDI on the trolley, hand the controllers out, and watch a Year 5 class write a techno track in 40 minutes.