MKtl:
Filter:
Modality-toolkit/Classes (extension) | Libraries > Modality | External Control

MKtl
ExtensionExtension

A class for creating and accessing external controllers

Description

NOTE: For a guided tour, start reading at Modality, for a tutorial on most of what MKtl does, see ModalityTutorial, for how to add your own controllers, see How_to_create_a_description_file

MKtl provides an easy to use interface for devices you can connect to your computer through MIDI, HID, OSC and possibly later Serial and other protocols. Beyond that, you will be able to use it for GUI based controllers.

MKtl.find; searches for all controllers connected to your machine, and returns a list of available devices. Or, if you already know which controller you want to use, you can create it directly by name, and MKtl will find and return that controller. If it does not find it, e.g. because the physical controller is not there, it creates a virtual MKtl, which can be used to open a GUI that replaces the controller.

For most devices, this requires that someone has made a description file for the device; if there is none, it is easy to make one following the instructions here: How_to_create_a_description_file

MKtls can also be nested by composing several MKtls; for instance, the iControl ... creates both MIDI and HID devices for communication. For an example and background, see CompMKtl.

Class Methods

.all

all currently available MKtls.

.find

Find all currently connected controllers. This method calls the find method on all of MKtlDevice's subclasses, and will post a list of available MKtl devices.

.protocols

.deviceTypes

.elementTypesUsed

the currently supported protocols, deviceTypes, and elementTypes used in loaded description files.

.new

Accesses an existing instance of MKtl with the given name, or creates a new instance with that name. As with e.g. JITLib proxies like Ndef, Tdef, Pdef, or OSCdef, MIDIdef etc.

Arguments:

name

The name of the controller as you want to refer to it.

lookupNameOrDesc

The device description or lookupName to be used. This can be:

  • a String - the file name of a description file (without extension, possibly with wildcards)
  • a Symbol the lookupName of a device that was found by MKtl.find (useful when no desc file exists),
  • an MKtlDesc object, or
  • a dictionary that is a well-formed MKtlDesc full description dict, see How_to_create_a_description_file
lookForNew

a flag whether or not to look for newly attached devices or newly added device descriptions. Default is false. Will always look for devices and device descriptions the first time you open an MKtl.

multiIndex

if several devices of identical make are present, multiIndex is the index within this array of identical devices. The order is alphabetical by deviceLookupName, and will be reproduceable if the same set of devices is connected.

tryOpenDevice

if true, MKtl will try to open the physical device if present.

Using specs in MKtl

.globalSpecs

A class dictionary of all preset ControlSpecs used by various controller elements.

.addSpec

.getSpec

add and access by name a ControlSpec in MKtl's dictionary of specs

Arguments:

key

the name by which to store the spec

spec

The ControlSpec or a symbol or array that can be converted to a spec.

Description files and MKtlDesc

These methods are all redirected to MKtlDesc.

.postLoadableDescs

post the filenames of all loadable device descriptions. For more details on using description files, see MKtlDesc

.postLoadedDescs

post all currently loaded device descriptions.

.descFolders

the folder(s) where MKtlDesc finds description files.

.openDescFolder

open folder(s) at index containing description files.

.loadDescsMatching

load device description file(s) matching with name from indicated folder(s).

.descIsFaulty

test whether the given desc is faulty.

miscellaneous

.postPossible

post all possible (i.e. currently connected or known) devices for the protocol(s) given. MKtl.postPossible;

.makeLookupName

make a lookupName for a device based on (typically) its protocol, id number and productName.

Instance Methods

.name

get and set the name (a Symbol) of the MKtl. This also changes the name under which the MKtl is stored in Mktl.all.

.gui

Open a gui representation for the MKtl, which shows the state of the MKtl's elements and can do all their actions.

.specs

.addLocalSpec

.addSpec

.getSpec

a local dict for special specs to use with this MKtl's elements or groups.

MKtl description

.desc

the MKtlDesc object that holds the device information from the description file. It is used to build the elements and groups of this MKtl.

For more, see MKtlDesc

.rebuild

Rebuild all elements of the MKtl based on the new description file given.

WARNING: This will also remove any actions defined for the MKtl elements and groups! Only use rebuild when you are sure that you want to replace the device description with a new one.

Devices

.openDevice

Open the hardware device for this MKtl if it was not opened already. It will look automatically for an appropriate device.

Arguments:

lookAgain

Whether or not to look for newly attached hardware devices.

multiIndex

Needed when using multiple identical devices to identify which one to create.

.hasDevice

test whether MKtl has a device (a MIDI/HID/OSCMKtlDevice)

.closeDevice

Closes the hardware device if it was open.

.device

.mktlDevice

The instance of MKtlDevice that this MKtl uses. (mktlDevice is a deprecated alias for device)

.free

Frees the MKtl again and forgets about its existence. If there was an device, this closes it.

.resetActions

Reset all actions of the elements in this MKtl to nil.

Arguments:

includeGroups

if true, also actions of contained groups are reset.

.trace

set the flag whether incoming data are posted or not, default true.

.traceRunning

the flag whether incoming data are posted or not.

.enable

.disable

enable and disable this MKtl, so one can make multiple MKtls (with different setups of elements) for the same physical device.

.sync

send all current MKtl values to the physical device, e.g. to move all motorfaders to a freshly recalled preset.

Elements of the MKtl

.elementGroup

.elements

All the control elements (MKtlElement) on the device you may want to listen or talk to. this returns an MKtlElementGroup containing a hierarchical tree of MKtlElements, organised via MKtlElementGroup. (elements is a deprecated alias of elementGroup).

.namedDict

A dict for adding elements or groups by name, so they can be accessed by name. For example, this can be used to reorganize the elements of a fader box into channels as on a mixer. See Creating_Named_Groups and Coding_for_Modal_Flexibility

.elementNames

An alphabetical list of all elementNames in the MKtl. m = MKtl(\funky); m.elementNames;

.postElements

A pretty printed hierarchical list of the names and indices of all elements

.elementsDict

all elements in one flat event so they can be accessed very fast by name.

.inputElements

.outputElements

.elementsOfType

.elementsNotOfType

return all elements that are of the type given, or not

.elementsLabeled

return all elements which have been given a label

Accessing elements and groups

.elAt

.elementAt

Access an element or group in the elementGroup or in groups by hierarchical indices or names. Supports nil and \all as wildcards, and multi-expands correctly.

.dictAt

Access an element in the elementsDict directly by its full name. This is a very fast lookup. MKtl(\mynano2).dictAt(\sl_1);

.collAt

Access an element in the collectivesDict by hierarchical name.

.at

Access an element in the top elementGroup by index. MKtl(\mynano2).at(0);

Getting and setting element values

.valueAt

.deviceValueAt

Access an element's value and deviceValue (in the deviceSpec range) by the direct element key

.setValueAt

.setDeviceValueAt

Set an element's value or deviceValue directly by element key

Getting and setting multiple elements

.getKeysValues

get multiple key/value pairs for a list of element keys. this is intended for more robust storage of presets.

.setKeysValues

set multiple key/value pairs from a list of key/value arrays.

.setKVAction

same as setKeysValues, but with doAction of the elements being set

.set

set multiple key/value pairs from a list of key, value arguments. m.set(\joy_l_x, 1.0.rand, \joy_l_y, 1.0.rand, \joy_r_x,1.0.rand, \joy_r_y, 1.0.rand); m.gui;

.setAction

same as set, but with doAction of the elements being set

.send

Send the value of the element to the hardware device; called if you set the value of an MKtlElement that is an output.

Exploration of a device

See How_to_create_a_description_file for a full discussion on this.

.explore

When a device doesn't have a description file yet, explore can be used to help in creating one.

.exploring

Returns a Boolean whether or not a device is currently being explored.

.createDescriptionFile

When a device doesn't have a description file yet, this method can be used to create a description file.

.specialMessages

a dict of special messages for this device, typically to change setup on a MIDI device by sending it a sysex message.

.sendSpecialMessage

send specialMessage with that name to the device

Adding named groups and elements

One can add named elements to an MKtl and access them by name. For a full discussion, see Creating_Named_Groups.

.addNamed

add an element or group to the mktl's namedDict, so they can be accessed by user given names.

This can be used to name single elements by the same function name across different devices - e.g. call one button \play, another \stop, no matter what its name in the device description may be:

Collectives

.collectivesDict

.collectiveDescriptionFor

These are mainly used internally in OSCMKtlDevice, see How_to_create_a_description_file_for_OSC

Methods for finding info on available devices in MKtlLookup.

.lookupInfo

.lookupName

.updateLookupInfo