Modality Tutorial:
Filter:
Modality-toolkit/Tutorials (extension) | Libraries > Modality | External Control

Modality Tutorial
ExtensionExtension

Learning how to use Modality

Finding present devices

NOTE: If you have one of the example devices used here (a Korg nanoKontrol2 faderbox or a Thrustmaster RunNDrive gamepad) at hand, plug it in now and use a real interface device. If not, you can substitute with their guis to step through this tutorial.

The first step is to discover which devices are available for use:

This will find all currently available devices, all the known info on them, and post instructions with example lines of code for several possible cases:

Copy the code line for the device you want to use from the post window to a text document and change its nickname to one you like:

You can see the output from all elements by doing

The same for a Thrustmaster RunNDrive gamepad:

Elements and Groups

Each control (i.e. knob, slider, button, etc) on the device is represented by an MKtlElement. All elements are contained in the elementGroup in a hierarchical order:

The elementGroup is an (MKtlElementGroup) and usually contains some nested groups, where the final node is always an MKtlElement. The structure of the groups follows a meaningful order, e.g. the spatial arrangement on the device (rows, columns, areas) or a logical order (pages, function groups, etc). (One can create custom orders of elements as well, see Creating_Custom_Elements_and_Groups.

This organization is defined in an MKtlDesc file for the device, which are provided for many devices already.

NOTE: when using devices with hardware pages (like the nanoKONTROL 1), there may be separate desc files for each page, or a single desc with all pages. When using such a single desc, the page name or index will be used in the access code, e.g. the button on page 4 row 2 and column 5 would be at:

The pages can also be in the top layer, and element names below them:

Using actions

Actions for an element (or group) are defined using the "action_" or the "addAction" methods of MKtlElement. These methods take a function as argument which receives a single argument, the MKtlElement it belongs to. One can get the current value of the element by ".value". The value returned by an MKtlElement is always between 0 and 1.

Controlling a very simple sound process

... Now you can control four parameters of synth z.

Using named elements for actions

For more flexibility and clarity, one can give the elements names for their functions, and use those:

Controlling the same process from a different device

And now run the same function setting code as above for the gamepad controller! For a full example of this approach, see Substituting_MKtls.

Using multiple actions

For very flexible use of multiple actions, see also MFunc in the "adclib" Quark.

Output elements

Some devices can be set to specific values, e.g. setting motorfaders or LED rings around encoder knobs to the corresponding values.