Forums > MaxMSP

Triggering sound using my computer's keyboard

Jul 12 2011 | 9:50 pm


Relatively new user. I’m a little lost as to how I can play sounds (like a simple sine wave using the cycle~ function) using different keys on my keyboard. I used the key function to figure out the number of the keys (ex: B is 98, A is 97) but I’m not sure how to connect them so they play the sound. I know the select function has something to do with this too as I was looking at some built-in tutorials.


Jul 12 2011 | 10:05 pm

you’re almost there, but you don’t specify exactly what you wish to do with the keystrokes. To control frequency, for example, use [key] to identify ascii numbers, then send its left outlet to [* 10]. Send the result to the [cycle~] left inlet. Now you’re controlling frequency with the keys. [select] will issue bangs depending on the arguments you specify, so [select 49 50] will give a bang for keys "1" and "2".

Right/ctrl clicking on any object in edit mode brings up a helpfile patcher.


Jul 12 2011 | 10:22 pm

The last post has a QWERTY keyboard MIDI controller. Put the pitch output from the patcher into a mtof and feed it into a cycle~. Not sure if thats what yr after but – it’s handy and will do something like what you want one way or another.

Jul 12 2011 | 10:27 pm

Also available as part of my MaxMSP Library download available here in the Code section. It comes with some other abstractions you might find useful and updated help files.

Jul 12 2011 | 11:16 pm

Thanks everyone. I’m getting there, slowly. I connected the key to the B and when I hit B on my keyboard, the button goes yellow so that means it’s working. But I’m having troubles attaching or getting sound out of it.

Check attachment please.

edit: Sorry, the attachments don’t seem to be working. One moment…

edit 2: See here –

  1. maxmsp.jpg


Jul 12 2011 | 11:24 pm

Download the library I just linked to, pop it somewhere in your max search path (or add it under Options > File Preferences) and then try this super simple patch. The object basically makes your computer keyboard mimic a MIDI keyboard. The example patch turns the MIDI notes to frequency values with [mtof], generates a sine wave at this pitch with [cycle~] and finally sends it to your speakers.

-- Pasted Max Patch, click to expand. --

Jul 12 2011 | 11:59 pm

Is there a simpler way? I just want different sounds to be produced (of sine waves) when I press certain keys on my keyboard. I was getting sound before but wasn’t sure how to connect it to the button so the keys would trigger it. Yeah, I’m struggling. Sorry to be a pain.

Here’s what I have right now – But I don’t know how to make it so the sound triggers only when those keys are pressed. And I need to product different sounds (sine wave) for each key.

Jul 13 2011 | 12:55 am

Like this:
(copy all the text below, and go File/New From Clipboard; then go here:
and here:

— Pasted Max Patch, click to expand. —
Viewing 8 posts - 1 through 8 (of 8 total)

Forums > MaxMSP