A CVCenterKeyboard consists of a collection of SynthDefs and provides a convenient way to play them on a MIDI keyboard.
CVCenterKeyboard lets you create a MIDI keyboard layout instantly from either a SynthDef whose instances free themselves (e.g. for percussive instruments having an envelop defined in an EnvGen that has the parameter doneAction
set to 2
or Done.freeSelf) or a SynthDef that provides a \gate
key, meaning that a Synth that has been instanced upon receiving a note-on message gets finished when it gets a not-off message from an external MIDI keyboard. That allows for playing sustained notes that can be controlled through asr
or adsr
envelopes. A SynthDef with a "gated" envelope should answer true
on executing the following line:
MIDI NoteOff
messages they will clog the server, eventually making it unresponsive!Beyond the that you may add an arbitrary number of other SynthDefs. You may switch between these SynthDefs or play more than one at a time by calling -setSynthDef. Playing the keyboard should immediately play generated nodes using the selected SynthDefs.
Setting up the keyboard basically involves two steps: First instancing a keyboard (through *new or *newSynthDef) and then setting up the keyboard for a given SynthDef through -setUpControls (will boot the Server).
You can assign four arbitray controls from your SynthDef to the following standard parameters:
\freq
(Hertz).0-127
). These will be converted to frequencies in Hertz internally.ControlSpec(0.midicps.neg, 0.midicps, \lin, 0, 0, " hz")
)All other controls you may have defined in your SynthDef will automatically be picked up by the setup process and get assigned appropriate widgets automatically.
Additionally an output proxy - a NodeProxy or an Ndef - can be added through -addOutProxy which allows you to build an effects chain and to do other kinds of NodeProxy trickery.
Instanciate a new keyboard under keyboardName
. The keyboard will be accessible under CVCenterKeyboard.all[keyboardName]
keyboardDefName | |
srcID |
Optional - an Integer corresponding to the unique ID of the MIDI device. If omitted the keyboard will be usable on any currently connected MIDI keyboard. To find out the unique numeric ID of your MIDI device you could use thefollowing code: (See also: Using MIDI: MIDIFunc and MIDIdef: Filtering based on device or message data) |
chan |
Optional - an Integer denoting the MIDI channel the keyboard should use. If omitted the keyboard can be played on any MIDI channel (See also: Using MIDI: MIDIFunc and MIDIdef: Filtering based on device or message data) |
addRecorder |
Optional - this argument will be set to |
touchOSCAddr |
Optional - a NetAddr instance, refering to an installation of a TouchOSC app on a mobile phone or tablet computer. The device must be in the same network as the computer. The IP address must be the device' IP address, the port is the "incoming" port as set in TouchOSC's OSC setup. Included with the distribution of this class (library) you should find a TouchOSC layout that can be edited in the TouchOSCEditor - download at https://hexler.net/touchosc-mk1#resources . The layout is built for a resolution of 800 x 1280 pixels, so you might have to adapt it to the resolution of your device. NOTE: You might want to use a different OSC app for control, using different OSC command names. Though the class is named CVCenterKeyboardTouchOSC it is not necessarily bound to the TouchOSC app. You should be able to set your own command names, either in the class or one of its instances. See CVCenterKeyboardTouchOSC: Predefined OSC commands or CVCenterKeyboardTouchOSC: Predefined OSC commands in instances |
Instantiate a new CVCenterKeyboard holding the SynthDef denoted by synthDefName
. The SynthDef must have beem compiled in advance.
synthDefName |
A Symbol or a String denoting the SynthDef that should be added to the keyboard. Note that the SynthDef must have a gated envelope (i.e. executing |
keyboardDefName | |
srcID |
Optional - an Integer corresponding to the unique ID of the MIDI device. If omitted the keyboard will be usable on any currently connected MIDI keyboard. See *new for how to determine the unique ID of your MIDI device. (See also: Using MIDI: MIDIFunc and MIDIdef: Filtering based on device or message data) |
chan |
Optional - an Integer denoting the MIDI channel the keyboard should use. If omitted the keyboard can be played on any MIDI channel (See also: Using MIDI: MIDIFunc and MIDIdef: Filtering based on device or message data) |
addRecorder |
Optional - this argument will be set to |
touchOSCAddr |
Optional - a NetAddr instance, refering to an installation of a TouchOSC app on a mobile phone or tablet computer. For detailed description see *new argument |
A simple convenience method, same as CVCenterKeyboard.all[keyboardDefName]
except for the fact that keyboardDefName
can be given as String as well (will be converted to a Symbol internally).
keyboardDefName |
A String or Symbol denoting the name of the CVCenterKeyboard instance. |
The CVCenterKeyboard instance under the given name if it exists or nil
.
an Event, containing all CVCenterKeyboard instances.
Add a new SynthDef to an existing CVCenterKeyboard instance. The SynthDef must already have been compiled and contain a gated envelope.
synthDefName |
Whenever a new SynthDef is added, either by creating a new instance by calling *newSynthDef or adding a SynthDef with -addSynthDef, the CVCenterKeyboard instance must be set up for the new SynthDef. This will configure outControl
, keyboardControl
, velocControl
and bendControl
as well as it will create CVWidgets for all other controls in the SynthDef. It should be possible to call this method repeatedly, so you can update an existing SynthDef while it's already being used.
synthDefName | |
prefix |
An optional Symbol or String for CVCenter, to make sure the resulting widgets get a unique name. |
pitchControl |
A Symbol or String referencing the keyboard key, incoming note. Default: |
velocControl |
A Symbol or String referencing velocity (the physical pressure on a keyboard key) coming with the note. Default: |
bendControl |
A Symbol or String referencing the control to be set by the pitch bend wheel. Default: |
outControl |
A Symbol or String referencing the output bus. Default: |
tuning |
An ControlSpec. If set the given SynthDef may be 'tuned' using an extra CVWidget. The given ControlSpec determines the range of possible tuning. |
theServer |
Optional - the Server to run the Synths on produced with every keystroke. |
outbus |
Optional - an Integer denoting a default output bus (can be set in the SynthDef beforehand as well). |
deactivateDefaultWidgetActions |
When CVWidgets are created from a running |
tab |
Optional - a Symbol or String denoting the tab in which the CVWidgets for the Synth instances will appear. If none is given the tab name will default the the SynthDef's name. |
setSynthDef |
A Boolean. If set to |
This method may be called implicitly for every new SynthDef in -setUpControls by adding an argument setSynthDef
set to true
or it may be called explicitly to switch between currently stored SynthDefs or to play more than one SynthDef at the same time within the CVCenterKeyboard instance.
... synthDefName |
One or more Strings or a Symbols, denoting the SynthDef(s) to be selected. If more than one SynthDef is given the keys triggering one of the SynthDefs will be equally distributed over the -keysBlockSize. I.e. by default the -keysBlockSize will extend over 24 keys on the keyboard (two octaves). The keys triggering one of the given SynthDefs will (more or less) be equally distributed over the given block (the |
As you may already have recognized you can use more than one SynthDef on one physical keyboard. When doing so by calling -setSynthDef with more than one SynthDef the keys are being equally distributed over a predefined block of keys (by default 24 keys or two octaves). The blocks will repeat over the full range of 128 MIDI notes, beginning at MIDI note 0
. Here are some schematic examples using two SynthDefs on a three-octaves keyboard1 :
This method lets you either read or set the number of keys over which two or more SynthDefs are being distributed that have been set by calling -setSynthDef. By default it will be 24 (two octaves). You can set a new value at any time and the CVCenterKeyboard instance should pick up the new value immediately.
an Integer
By default keys for different SynthDefs in a CVCenterKeyboard instance that has been set to more than one SynthDef by calling -setSynthDef will be distributed (more or less) equally over the given -keysBlockSize. This method, however, allows you to set the number of keys for the SynthDefs unequally. If you e.g. have two SynthDefs distributed over 24 keys each of them will occupy twelve keys within that -keysBlockSize. You can change that by executing
~kb.keysDistribution_([8, 16])
to eight keys for the first SynthDef and 16 keys for the second SynthDef. If the given array sums to the -keysBlockSize it should be guaranteed that the number of keys playing one of the SynthDefs is exactly equal to the number given in the array ratios
. If you change the -keysBlockSize later, however, the ratio of the keys should be kept. I.e. executing the following to line will first change the -keysBlockSize and subsequently change the number of keys for the first SynthDef to 4 and the number of keys for the second SynthDef to 8.
If ratios
sums up to an even number and -keysBlockSize is set to an odd number, the ratio of the number of keys will be approximated.
Clear one or more SynthDef(s) from a CVCenterKeyboard instance but don't remove it from the keyboard. This is used internally by -setSynthDef before switching to a new SynthDef. You will usually not call this method directly.
... synthDefName |
One or more Strings or a Symbols, denoting the SynthDef(s) to be cleared. |
Free the CVCenterKeyboard instance. You will not be able to use the CVCenterKeyboard instance any longer after calling this method.
Frees all currently playing Nodes (Synth instances) on the Server belonging to the CVCenterKeyboard instance. This can be useful if, for some reason, a note "hangs" after releasing a key on the keyboard which could happen e.g. if the server is under heavy load. A CVCenterKeyboard instance will create all its Synths in a dedicated Group (respectively ParGroup if supernova is used as audio engine) which allows control the playing nodes via the group's interface.
Assosciate an instance of CVCenterKeyboardTouchOSC which allows the CVCenterKeyboard instance and an assigned CVCenterKeyboardRecorder instance (if it exists. See also: -addRecorder) to be controlled via pre-defined OSC commands comming and gong to TouchOSC or a different OSC control app installed on some external device within the current network. The CVCenterKeyboardTouchOSC instance can also be created by passing a NetAddr in the argument touchOSC
when calling *new or *newSynthDef. The CVCenterKeyboardTouchOSC instance will be accessible by calling -touchOSC.
addr |
A class NetAddr |
The default noteOn function, added when creating a new CVCenterKeyboard instance. By default the function will only hold some debug code that gets executed when -debug is set to true
.
The default noteOff function, added when creating a new CVCenterKeyboard instance. By default the function will only hold some debug code that gets executed when -debug is set to true
.
The default bend function, added when creating a new CVCenterKeyboard instance. By default the function will only hold some debug code that gets executed when -debug is set to true
.
The following three variables all implement an Event, holding the individual noteOn
, noteOff
and bend
Functions at a key identical to the corresponding SynthDef. When calling MIDIFunc instance when calling setSynthDef(\mySynthDef) the corresponding Function in the Event will be added to the CVCenterKeyboard instance's default MIDIFunc instance (-on, -off or -bend).
The functions to be executed for a noteOn
. To each of these functions the arguments veloc
(velocity), num
(the MIDI value for the key played on the keyboard), chan
(the MIDI channel, if defined) and src
(the MIDI device' unique ID, if defined) will be passed. If -debug has been set to true
the following output will be posted:
num
) of the currently played keychan
)src
)The functions to be executed for a noteOff
. To each of these functions the arguments veloc
(velocity), num
(the MIDI value for the key played on the keyboard), chan
(the MIDI channel, if defined) and src
(the MIDI device' unique ID, if defined) will be passed. If -debug has been set to true
the following output will be posted:
num
) of the currently played keychan
)src
)The functions to be executed for a bend
(when moving the the bend wheel). To each of these functions the arguments bendVal
(the value coming from the bend wheel), chan
(the MIDI channel, if defined) and src
(the MIDI device' unique ID, if defined) will be passed. If -debug has been set to true
the following output will be posted:
bend
) coming from the bend wheelchan
)src
)Acttivate or deactivate debugging. If set to true
various output from noteOn
, noteOff
and bend
events will be posted.
An Event holding all ControlNames of all currently stored SynthDefs within a CVCenterKeyboard instance.
A List, filled with the names of the SynthDefs currently stored with the CVCenterKeyboard instance.
A Symbol representing the name of the CVCenterKeyboard instance. The name can will be set in *new or *newSynthDef. If no name has been given it will default to \keyboard
.
An Event, holding a List with the CVWidget instance names, the ControlNames and the CVs of all SynthDefs currently stored with the CVCenterKeyboard instance. Usually this will not be of any use for the user but it is needed for sampling keyboard sequences. Hence, this variable must be public and can be used for introspection.
Set or get the ControlSpec for the pitch bend wheel. By default:
An Array containing all controls and CV instances of the currently used SynthDef (see: -currentSynthDef) that appear in CVCenter.
An Array containing all controls and their current values of the SynthDef (see: -currentSynthDef) that appear in CVCenter.
The Server used by the CVCenterKeyboard instance.
The CVCenterKeyboardTouchOSC instance associated with the CVCenterKeyboard instance if it exists.
Building an effects chain is accomplished by adding a NodeProxy or an Ndef catching the output of the Synths played with the keyboard. These can then be filtered by using NodeProxy roles. Only adding the NodeProxy or Ndef by calling -addOutProxy will have no audible effect - the keyboard should just play as before adding the proxy.
Add a NodeProxy or an Ndef, catching the audio output of the CVCenterKeyboard instance.
numChannels |
An Integer representing the number of output channels. Default: |
useNdef |
If set to |
transbus |
Optional - an Integer represeting a Bus allowing the user to isolate effects and filters. This is handled by setting output bus of the CVCenterKeyboard instance to this bus. Ideally one will use a private bus, e.g: |
outbus |
Optional - an Integer represeting the Bus on which the filtered sound of the CVCenterKeyboard shall play. By default this will be the out bus of the CVCenterKeyboard instance. |
Remove the NodeProxy or Ndef added by -addOutProxy.
outbus |
If the argument |
The proxy created by calling -addOutProxy.
To be able to record keystrokes on the keyboard a CVCenterKeyboardRecorder has to be assigned. By default this is already done when calling *new or *newSynthDef if the argument addRecorder
hasn't explicitly been set to false
(given that CVCenterKeyboardRecorder is installed, which should be the case as its part of the CVCenterKeyboard library).
A convenience method, calling CVCenterKeyboardRecorder: -record. Start or stop recording keyboard sequences. The CVCenterKeyboardRecorder instance should keep track of its state internally (is currently it recording or not), so, the argument onOff
should be optional. However, it might be convenient to tell the recorder explicitly to start or stop in some situations.
onOff |
Optional - by default the CVCenterKeyboardRecorder should remember its internal state (is it currently sampling or not). The parameter allows you to set the state explicitly. |
The CVCenterKeyboardRecorder instance, giving access to all methods of the CVCenterKeyboardRecorder instance.
Controls within Synth instances created when playing the keyboard may also be controlled through busses.
Map a Bus to a Synth control. The bus can be control
or audio
rate.
ctrlname |
A Symbol referencing the control in the Synth that shall be set by the Bus. |
bus |
The audio or control rate Bus that will set the control in the Synth instance. |
The opposite to -mapBus - delegate control over the given ControlName back to manual control by the user.
ctrlname |
A Symbol referencing the ControlName whose control should be delegated to the user again. |
An Event holding all currently mapped busses. The keys will be ControlNames that get set by the bus(ses) referenced by the assigned bus indexes.