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

MKtl : Object
ExtensionExtension

A class for creating and accessing external controllers
Source: MKtl.sc
Subclasses: MPush

Description

NOTE: For a guided tour, start reading at Modality, for a tutorial on most of what MKtl does, see Modality Tutorial, 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

MKtl.all

all currently available MKtls.

MKtl.find(protocols)

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.

MKtl.protocols

MKtl.deviceTypes

MKtl.elementTypesUsed

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

MKtl.new(name, lookupNameOrDesc, lookForNew: false, multiIndex, tryOpenDevice: true)

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

MKtl.globalSpecs

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

MKtl.addSpec(key, spec)

MKtl.getSpec(key)

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.

MKtl.postLoadableDescs

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

MKtl.postLoadedDescs

post all currently loaded device descriptions.

MKtl.descFolders

the folder(s) where MKtlDesc finds description files.

MKtl.openDescFolder(index: 0)

open folder(s) at index containing description files.

MKtl.loadDescsMatching(filename, folderIndex)

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

MKtl.descIsFaulty(argDesc)

test whether the given desc is faulty.

miscellaneous

MKtl.postPossible(protocols)

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

MKtl.makeLookupName(prefix, id, prodName)

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

Inherited class methods

Instance Methods

.name

.name = inname

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(parent, bounds)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/Modality-toolkit/Modality/Classes/GUI/MKtlElementGUI.sc

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

.specs

.addLocalSpec(key, spec)

.addSpec(key, spec)

.getSpec(key)

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(descNameOrDict, lookAgain: true, multiIndex)

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(lookAgain: true, multiIndex)

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(includeGroups: false)

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

Arguments:

includeGroups

if true, also actions of contained groups are reset.

.trace(bool: true)

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

.traceRunning

the flag whether incoming data are posted or not.

.enable(sync: true)

.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(type)

.elementsNotOfType(type)

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

.elementsLabeled(label)

return all elements which have been given a label

Accessing elements and groups

.elAt( ... args)

.elementAt( ... args)

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(key)

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

.collAt( ... args)

Access an element in the collectivesDict by hierarchical name.

.at(index)

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

Getting and setting element values

.valueAt(elName)

.deviceValueAt(elName)

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

.setValueAt(elName, val)

.setDeviceValueAt(elName, val)

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

Getting and setting multiple elements

.getKeysValues(keys)

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

.setKeysValues(pairs)

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

.setKVAction(pairs)

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

.set( ... args)

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( ... args)

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

.send(key, val)

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(bool: true)

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(name)

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(name, group)

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(elname)

These are mainly used internally in OSCMKtlDevice, see How to create a description file for an OSC device

Methods for finding info on available devices in MKtlLookup.

.lookupInfo

.lookupName

.updateLookupInfo(newInfo)

Inherited instance methods

Undocumented instance methods

.adaptDesc(descName)

.lastUpdateTime

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/Modality-toolkit/Modality/Classes/MKtl/extLastUpdate.sc

.lastUpdatedElement

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/Modality-toolkit/Modality/Classes/MKtl/extLastUpdate.sc

.openDeviceVia(idInfo, lookAgain: true, multiIndex)

.reload(lookAgain: false)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/Modality-toolkit/Modality/Classes/MKtl/extReload.sc

.reset

.resetAction

.timeSinceLast

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/Modality-toolkit/Modality/Classes/MKtl/extLastUpdate.sc

.toFront( ... pageNames)