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

VoicerMIDISocket
ExtensionExtension

Directs note-on/off messages to a Voicer object
Location: NOT INSTALLED!

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.

Inherited class methods

Instance Methods

.free

Remove the socket completely from the ddwMIDI hierarchy.

.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

.parent

Returns:

The socket's parent MIDIChannel object. From this, you can get information about the device and channel from which the socket is receiving messages.

.enable

Move the socket to the parent MIDIChannel's list of enabled sockets. The socket will then respond to incoming messages.

.disable

Move the socket to the parent MIDIChannel's list of disabled sockets. The socket will not respond to incoming messages, but it remains intact so that you can reenable it at any time.

.active

Returns:

Boolean: true if the socket's destination exists and is active; false otherwise.

.clear

Subclasses may implement clear to keep the socket registered in the hierarchy, but become inactive.

.noteOn

This method is called in response to note-on messages. In normal use, you do not need to call this method. You may call it directly for testing or debugging.

Arguments:

note

The MIDI note number (0-127).

vel

Velocity (0-127).

.noteOff

This method is called in response to note-off messages. In normal use, you do not need to call this method. You may call it directly for testing or debugging.

Arguments:

note

The MIDI note number (0-127).

vel

Velocity (0-127).

Inherited instance methods

Examples