A newer version of Max is available. Click here to access the latest version of this document.

matrixctrl

Matrix switch control

Description

matrixctrl is a user interface object that consists of a rectangular grid of switch-like controls called cells. All of the cells in a matrixctrl object have the same appearance and behavior. Each cell has two or more states. By default, the cells have two states, representing "off" and "on." You can create cells with any number of states. Clicking on a cell increases its state by one. After a cell reaches its last state, it returns to its zero state when clicked again--thus, a cell with only two states will toggle back and forth between these states with each mouse click.

matrixctrl was originally constructed to control the MSP object matrix~, but is useful for other user interface applications, such as groups of switches, groups of visual indicators, and drum-machine-oriented sequencers.

Note: The matrixctrl object customarily uses images saved in Portable Network Graphics (.png) format. If you are using Max on Windows, we recommend that you install QuickTime and choose a complete install of all optional components to work with images other than PNG or PICT files.

Arguments

None.

Messages

bang A bang causes matrixctrl to dump its current state in lists of three values for each cell pair, in the format

horizontal-coordinate vertical-coordinate value
list cell-coordinates and values [list]
A list of ints sets cells in the matrixctrl object using the format <horizontal-coordinate vertical-coordinate value>. Multiple triplets of values can be used to set more than one cell. Coordinates for the cells start at 0 in the upper-left hand corner and the values for each cell start at 0 and go up to the value range minus one, set by the object's inspector. Substituting the symbols inc and dec in place of the value will increment or decrement that cell coordinate by a value of one. Changing the cell state with a list causes the list to be output from matrixctrl.
cellpicture name-of-graphic-file [symbol]
This is a legacy message - it has been superseded by the cellpict attribute.
clear The word clear will set the value of all cells to 0.
bkgndpicture name-of-graphic-file [symbol]
This is a legacy message - it has been superseded by the bkgndpict attribute.
enablecell cell-coordinates [list]
The word enablecell, followed by a list of number pairs which specify the horizontal and vertical coordinates of a cell or cells, will set any designated cell or cells which have been disabled using the disablecell message to respond to mouse clicks again. The enablecell message expects at least one pair of numbers, but more may be added to enable multiple cells (e.g., enable 1 1 1 2 2 2).
disable cell-coordinates [list]
Performs the same as disablecell.
disablecell cell-coordinates [list]
The word disablecell, followed by a list of number pairs which specify the horizontal and vertical coordinates of a cell or cells, sets the designated cell or cells so that they do not respond to mouse clicks. The disablecell message expects at least one pair of numbers, but more may be added to disable multiple cells (e.g., disable 0 0 3 4 9 12). Although disabled cells will ignore mouse clicks, their values can be set using messages.
getcolumn column-number [int]
The word getcolumn, followed by a number, sends the values of the cells in the column designated by the number out its right outlet.
getrow row-number [int]
The word getrow, followed by a number, sends the values of the cells in the row designated by the number out its right outlet.
(mouse) A mouse click on a cell will increase its value by one. Values in matrixctrl will wrap back to 0 once they have reached their maximum possible state. Dragging across several cells will set their values to that of the first cell clicked. Dragging across cells while holding down the Shift key will allow you to drag in straight horizontal or vertical lines only.
set cell-coordinates and values [list]
The word set, followed by a list as described above, changes the state of matrixctrl without echoing the values to the output.
readanycell filename [list]
The word readanycell followed by the name of a file will read any type of file into the matrixctrl object and attempt to interpret it as a cell image.
readanybkgnd filename [list]
The word readanybkgnd followed by the name of a file will read any type of file into the matrixctrl object and attempt to interpret it as a background image.

Attributes

Name Type g/s Description
active int
def.:1
Toggles matrixctrl to ignore or respond to mouse clicks, respectively. By default, matrixctrl responds to mouse clicks.
autosize int
def.:0
Toggles automatically resizing to rows and columns for the matrixctrl object's display area when a cell picture is added.
bkgndpict symbol
def.:<default>
Designates the graphics file that the matrixctrl object will use for the matrix background image. By convention, the matrixctrl object uses images saved in Portable Network Graphics (.png) format. If you are using Max on Windows and want to to work with images other than PNG or PICT files, we recommend that you install QuickTime and choose a complete install of all optional components. The symbol used as a filename must either be the name of a file in Max's current search path, or an absolute pathname for the file (e.g. "MyDisk:/Documents/UI Pictures/CoolBkgnd.png"). The word bkgndpicture by itself puts up a standard Open Document dialog box.
cellpict symbol
def.:<default>
Designates the graphics file that the matrixctrl object will use for each cell. By convention, the matrixctrl object uses images saved in Portable Network Graphics (.png) format. If you are using Max on Windows and want to to work with images other than PNG or PICT files, we recommend that you install QuickTime and choose a complete install of all optional components. The symbol used as a filename must either be the name of a file in Max's current search path, or an absolute pathname for the file (e.g. "MyDisk:/Documents/UI Pictures/Cell.png").
clickedimage int
def.:1
Specifies that the graphics file used by the matrixctrl object contains an additional image to be displayed when a cell is clicked.
clickvalue int
def.:-1
Toggles the click value mode. If the clickvalue message is followed by a zero or a positive number, clicking on a cell sets its value to the given number. If clickvalue is followed by a negative number, the matrixctrl object reverts to its default behavior in which clicking a cell increments its value. The clickvalue message allows the use of the matrixctrl object to create grid editors by creating graphics files which contain a sequence of images, each of which is assigned to a different value; as you click through the sequence of images, the cell image will change to reflect velocity, note, etc.
columns int
def.:8
Sets the number of columns in the matrixctrl object's display.
dialmode int
def.:0
Toggles causing the object to behave like a matrix of dials where a cell will need to be clicked and dragged on to change its value. dialmode 0 will allow cells within the matrix to react to a simple click.
dialtracking int
def.:0
Sets whether or not the matrixctrl object will use vertical mouse tracking while it is in dialmode.
horizontalmargin int
def.:1
Sets a horizontal margin (in pixels) between the outermost cells and the edge of the matrixctrl object's bounding box.
horizontalspacing int
def.:0
Sets the horizontal distance (in pixels) between adjacent cells in the matrixctrl object.
imagemask int
def.:0
Specifies that the matrixctrl cell graphics file has additional rows of images for use as image masks. This attribute is present for legacy support - it has been superseded by the use of alpha channels in images.
inactiveimage int
def.:1
Specifies that the matrixctrl cell graphics file has additional rows of images for use in an inactive state (set with an active 0 message).
invisiblebkgnd int
def.:0
Specifies that the matrixctrl will be drawn without a background image, and its cells will be superimposed over any underlying Max objects. invisiblebkgnd 0 disables this feature.
one/column int
def.:0
Toggles only allowing one cell per column to have a non-zero state. Setting any cell in a column to a non-zero state causes any other non-zero cells to change to the zero state. one/column 0 removes this constraint.
one/matrix int
def.:0
Toggles only allowing one cell in the entire object to have a non-zero state. Setting any other cell in the matrix to a non-zero state causes any other non-zero cells to change to the zero state. one/matrix 0 removes this constraint.
one/row int
def.:0
Toggles only allowing one cell per row to have a non-zero state. Setting any cell in a row to a non-zero state causes any other non-zero cells to change to the zero state. one/row 0 removes this constraint.
range int
def.:2
Sets the number of possible states each cell can have. It must be set to a value of at least 2 (for states 0 and 1).
rows int
def.:4
Sets the number of rows in the matrixctrl object's display.
scale int
def.:1
Toggles scaling graphics when the matrixctrl object's display area is resized.
verticalmargin int
def.:1
Sets a vertical margin (in pixels) between the outermost cells and the edge of the matrixctrl object's bounding box.
verticalspacing int
def.:0
Sets the vertical distance (in pixels) between adjacent cells in the matrixctrl object.

Information for box attributes common to all objects

Picture File Format

Specifications: The background pictures the matrixctrl object uses are, by convention, saved in Portable Network Graphics (.png) format. If you are using Max on Windows and want to to work with images other than PNG or PICT files, we recommend that you install QuickTime and choose a complete install of all optional components. The symbol used as a filename must either be the name of a file in Max's current search path, or an absolute pathname for the file (e.g. "MyDisk:/Documents/UI Pictures/Cell.png"). If the matrixctrl is larger than the chosen picture, copies of the picture will be added to fill the object.

Cell picture files must be in the following format:





The picture is made up of a grid of images. All images have the same width and height. Each column of images represents one cell state. The picture must have at least two columns, since cells must have at least two states.

The first row of images is used for the idle (or "not clicked") appearance of the cells. The first row of images is mandatory; all subsequent rows are optional. The second row are images for the clicked appearance; these images will be used to draw the cell when it is clicked. The appearance of the cell reverts to its idle image when the mouse is released. The third row of images are used when the matrixctrl is in its inactive state, i.e. when it has received an active 0 message.

Image masks can be used to create cells with non-rectangular outlines. These masks are in the lower rows of the picture file. If you wish to use masks for any of the cell images, you must provide masks for all of them--each row of images will have a corresponding row of masks. Like all masks for Max's picture-based controls, black pixels create areas of the corresponding image that will be drawn, and while pixels create invisible areas.

Output

list: When a cell changes state in response to a mouse click, a list is sent out the matrixctrl object's left outlet. The list contains the column, row, and value (state) of the clicked control. Individual cells can also be set by sending lists to the object's left inlet. Rows and columns are numbered starting with zero, at the upper-left corner of the matrix.

The numbers received in the inlet are compared with the arguments. If the numbers are the same, and in the same order, they are sent out the outlet as a list.

Examples

matrixctrl can be used to control multiple gates and switches at once

See Also

Name Description
dial Output numbers by moving a dial onscreen
kslider Output numbers from a keyboard onscreen
pictctrl Picture-based control
pictslider Picture-based slider control
router matrixctrl-compatible Max message router
rslider Display or change a range of numbers
slider Output numbers by moving a slider onscreen
ubutton Transparent button, sends a bang
Max Basic Tutorial 21: Controlling Data Flow Max Basic Tutorial 21: Controlling Data Flow
Tutorial 26: MIDI Control of Video Tutorial 26: MIDI Control of Video