midisender.ck

Main ChucK page

The midisender class provides a wrapper to most common MIDI output functions from ChucK. This should provide all necessary MIDI control for modern synths without requiring the user to look at the MIDI protocol specification.

This documentation is a work in progress. It will be updated to reflect the new features added to the interface as they come up.

Notes:

  1. MIDI channels are always specified by the user in human readable 1-16 format which matches that displayed by synths.
  2. Ranges for most parameters vary from 0-127, this is part of the MIDI spec.

Functions

int open(int portnum)
int open(name)

Opens a midiport for this midisender object. Specify the port by either its integer ID (see --probe command), or by a name which must match the port name string exactly. Note: If you have multiple devices attached to a port, this will fail unless you specify a string like "Virus C, JD990".

Returns 0 on error, non-zero on success.

set_channel(int chan)

Sets the default channel. All the functions which require a channel argument can be called without it, and this channel will be supplied. Defaults to 1 on class creation.

stop_hanging_notes()
stop_hanging_notes(int chan)

As notes are started and stopped by this class, it keeps track of which notes have been followed correctly by a noteoff of some kind. Any notes which have

clear_note_counts()
clear_note_counts(int chan)

Clears the notecount array for the current or specified channel. This might used as part of a reset script. Same behavior as clear_hanging_notes for channel == -1.

MIDI spec functions

noteon(int note)
noteon(int note, int vel)
noteon(int note, int vel, int chan)

Sends a MIDI note-on message with the specified MIDI note number and velocity.

noteoff(int note)
noteoff(int note, int chan)

Sends a MIDI note-off message (using a zero-velocity note on). This is standard for most MIDI devices, since they don't understand release velocity.

noteoff_velocity(int note, int vel)
noteoff_velocity(int note, int vel, int chan)

Sends a MIDI note-off message with the specified MIDI note number and velocity. Most synths don't treat this any differently to a normal note-off message

aftertouch(int note, int level)
aftertouch(int note, int level, int chan)

Sends a polyphonic aftertouch message to the synth. This represents pressure being placed on a single key. Most synths don't implement this.

controller(int cnum, int value)
controller(int cnum, int value, int chan)

Sends a controller-change message to the specified controller. This is used by synths to control various controls as well as some specific things such as volume or bank select (see the convenince functions below)

program_change(int program)
program_change(int program, int chan)

Sends a program change message. For most synths, you'll need to experiment with what combination of program change message and bank select messages are needed to get to each program. The MIDI documentation for your synth can come in handy for this.

channel_pressure(int pressure)
channel_pressure(int pressure, int chan)

This is how most synths implement aftertouch. From the spec, this permits the general level of pressure on the synth keyboard to be transmitted, any sound changes will be applied to all playing notes.

pitchbend(int bend)
pitchbend(int bend, int chan)

Sends a standard pitchbend to the system, this only sends a coarse pitchbend and expects the bend parameter to vary from -64 to 63, with 0 being the centre position. For finer control, see the pitchbend_fine function.

Just like with a keyboard, some things remember where the pitchbend used to be and some don't. There's a reason why the pitchwheel normally has a spring on it! Set it back to 0 when you've finished with it.

pitchbend_fine(float bend)
pitchbend_fine(float bend, int chan)

This sends both coarse and fine bend messages to the synth. The float parameter can vary between -1 (lowest bend) to 1 (highest bend) with the center position at 0. You can safely mix calls to the coarse and fine pitchbend functions.

Convenience functions

These functions can be implemented with calls to the other MIDI functions with magic number parameters. I don't want to remember magic numbers.

all_notes_off()
all_notes_off(int chan)

Sends a MIDI all-notes-off panic message. For most synths, this will result in all currently playing notes stopping. Not everything implements this cleanly so you're better off using the hanging notes functions except in emergencies.

all_sound_off()
all_sound_off(int chan)

This should stop all sound immediately rather than just issuing effective note-offs. Even fewer synths implement this correctly

select_bank(int bank)
select_bank(int bank, int chan)
select_subbank(int bank)
select_subbank(int bank, int chan)

Unfortunately, there is absolutely no standard for how to get particular programs or banks uses combinations of these commands and program_change(). You're best off reading the documentation because the values and even the order of calling can be critical.

volume(int volume)
volume(int volume, int chan)

This should be obvious.

These interfaces should be fairly stable going forward, thanks to ChucK's polymorphism. From here, mostly just new functionality will be added.