(maxmsp) sfplay~ and dropfile

I’ve zipped the example patcher, CtlnAssign, and a couple of sound files into one downloadable folder.


MaxMSP has an excellent tutorial and help patchers. My example doesn’t try to recreate everything you can do with sfplay~. I’m focusing on basic playback, the loading of files, and how to create a useful start/stop mechanism with the spacebar. Most of the advanced features of sfplay~ are better handled with buffer~ and objects like groove~, etc., which will talk more about.

The heart of the patcher is in the blue box. The object uses an argument to specify number of channels (above 1) — it can play up to 8-channel files. sfplay~ takes an open message to bring up a standard file dialog box. A toggle is useful for starting and stopping playback. 1 starts playback from the beginning of the file; 0 stops. When the file is done playing (either by reaching the end of the file, or by having the user stop it manually) the object outputs a bang out its right-most outlet. The [open Cave_Water_Drops.aif] message loads that file for sfplay~ without a dialog box. This message only works if the file is either in the same folder as the patcher, or in anther folder in the MaxMSP search path.

In this example patcher I’m using the space bar to control starting and stopping of playback, much like commercial audio software. The key object leads to [select 32] (32 is the ascii code for the spacebar). The output of select feeds into a gate object so that I can control when the spacebar affects playback (don’t want the file to start when I’m typing new objects).

The toggle that starts and stops file playback also gates whether the stop bang will get sent back to the toggle. If the sound file reaches its end, the gate will be open and the bang will go to the toggle and reverse its state (showing that the file has stopped playing). If the user stops playback the gate is first closed, stopping the bang from reaching the toggle (which would restart playback).


dropfile lets you drag-and-drop files from the finder to load into sfplay~ (or other file-based objects). The right outlet shows the file type that was dropped (could be used as a gate or error check message if you don’t drop a valid sound file). The left outlet gives the full path and name of the file. Sent to an [open $1] message, this will allow you to load that file into sfplay~.


Leave a Reply