VoicerMIDISocket:
Filter:
ddwMIDI/Classes (extension) | External Control > MIDI

VoicerMIDISocket
ExtensionExtension

Directs note-on/off messages to a Voicer object

Description

VoicerMIDISocket makes it convenient to play a Voicer by MIDI keyboard.

There is a strict division of labor:

MIDI note data are sent to the Voicer as follows:

Note number
Converted to frequency in Hz, and passed to the synth's freq argument. The conversion is done by the socket's -midiToFreq function. If this function is not provided, then *defaultMidiToFreq is used.
Velocity
Divided by 127 and passed to the synth's gate argument. The SynthDef can convert this to an amplitude using Latch and some range mapping: e.g., Latch.kr(gate, gate).linlin(0, 1, 0.1, 0.5).

The note data are also provided to an event pattern that supplies arbitrary arguments for each note. See -noteOnArgsPat.

Class Methods

.new

Create a new instance. Arguments are:

chan
The messages' source. See ddwMIDI_Guide: Identifying MIDI channels.
lo
The lowest MIDI note to which this socket will respond.
hi
The highest MIDI note to which this socket will respond.
noteOnPat
See -noteOnArgsPat.
midi2Freq
A custom function to translate MIDI note number into frequency. If not provided, the default function will be used; see *defaultMidiToFreq.

Returns:

The socket instance.

.defaultMidiToFreq

The default function to convert the incoming MIDI note number into frequency (Hz). During library initialization, this is assigned _.midicps. You may change this function at any time, and it will apply to any new VoicerMIDISockets created in the future. It does not retroactively alter existing sockets.

This function must be deterministic. Voicer will fail to release notes correctly if this function returns different frequencies for the same note number.

Instance Methods

.panic

Calls the target Voicer's panic method, shutting off all notes. Purely a convenience.

Member variables

.lowkey

The lowest MIDI note to which this socket will respond. With hikey, this variable supports keyboard splits by creating multiple VoicerMIDISockets on the same channel, with different key ranges.

.hikey

The highest MIDI note to which this socket will respond.

.transpose

A number of semitones to add to the note number, before converting to frequency. May be fractional, in which case it also serves as a tuning parameter.

.midiToFreq

A custom function to translate MIDI note number into frequency. See *defaultMidiToFreq.

.noteOnArgsPat

An event pattern (e.g., Pbind) providing additional argument values to the Voicer. The pattern can access note number and velocity by Pkey(\midinote) and Pkey(\velocity), respectively. All key-value pairs in the pattern's output events will be passed to the Voicer as note-onset synth arguments. Uses:

.noteOnArgsEvent

An Event containing default values to provide to noteOnArgsPat.

Global controls

The following methods interface with global controls in the Voicer. Once a control is mapped globally, it makes sense to set its value using a physical continuous controller.

The connection between MIDI CC and global control is handled by VoicerMIDIController. You may use this class directly. In most cases, though, it's easier if the VoicerMIDISocket "owns" the controllers, so that (for instance) freeing the socket will also release the controllers.

.addControl

Adds a MIDI controller to this socket instance. Two possible cases:

Arguments:

ccnum

The controller number. See ddwMIDI_Guide: Controller_Numbers.

name

The synth argument name (as a Symbol).

value

If a new global control is being created (because none existed), this is the initial value. (If a global control already existed, this is ignored.)

spec

If a new global control is being created (because none existed), this is the ControlSpec. (If a global control already existed, this is ignored.)

overrideChan

By default (if this argument is not given), then MIDI controller will be created on the same MIDI channel as the socket. You may specify a different channel here -- for instance, if you have a full-size keyboard without many continuous controllers, and another device with several knobs, the socket can receive notes from the keyboard, and you can create controller mappings to the other device.

Returns:

The socket instance (not the new MIDI controller object).

.removeControl

Disconnect and remove a VoicerMIDIController.

Arguments:

control

A way to identify the controller to remove. One of the following:

  • A VoicerMIDIController object.
  • A CControl object (referring to the MIDI controller number).
  • A \symbol referring to the synth parameter name.
  • An integer for the MIDI controller number.

Returns:

The socket instance.

.searchControl

Look up a VoicerMIDIController (attached to this socket) by the parameter name.

Arguments:

control

A \symbol referring to the synth parameter name.

Returns:

The VoicerMIDIController instance.

.ccs

An Array, containing the VoicerMIDIControllers attached to this socket.

.searchControlNum

Look up a VoicerMIDIController (attached to this socket) by the controller number.

Arguments:

control

An integer or CControl instance.

Returns:

The VoicerMIDIController instance.

General/inherited methods

Examples