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

counter

Keep count based on bang messages

Description

Outputs the current count of bang message constrained to a specified range. Can be set to count up, down, or up-then-down.

Examples

Keep track of how many events have occurred, or create a continuous loop

Arguments

options [int]

Optional

If there is only one argument, it sets an initial maximum count value for counter. If there are two arguments, the first number sets an initial minimum value, and the second number sets an initial maximum value. If there are three arguments, the first number specifies the direction of the count, the second number is the minimum, and the third number is the maximum. If there are no arguments, the direction is up, the minimum is 0, and the maximum is 2,147,483,647 (the largest possible 32-bit signed integer).

Attributes

carryflag [int]

Sets the type of data output from the third outlet (numbers or bangs).

Possible values:

0 = 'Numeric'
1 = 'Bang'

compatmode [int]

Provides compatibility when importing patches created with versions 3.x and earlier of Max. When "Ancient" is selected, sending an int to inlets 3 and 4 will change the min count instead of just resetting it temporarily (which causes the fourth inlet to behave exactly as thought the min message were sent to the counter object).

Possible values:

0 = 'Current'
1 = 'Ancient'

Common Box Attributes

annotation [symbol]

Sets the text that will be displayed in the Clue window when the user moves the mouse over the object.

background [int] (default: 0)

Adds or removes the object from the patcher's background layer. background 1 adds the object to the background layer, background 0 removes it. Objects in the background layer are shown behind all objects in the default foreground layer.

color [4 floats]

Sets the color for the object box outline.

fontface [int]

Sets the type style used by the object. The options are:

plain
bold
italic
bold italic

Possible values:

0 = 'regular'
1 = 'bold'
2 = 'italic'
3 = 'bold italic'

fontname [symbol]

Sets the object's font.

fontsize [float]

Sets the object's font size (in points).

Possible values:

'8'
'9'
'10'
'11'
'12'
'13'
'14'
'16'
'18'
'20'
'24'
'30'
'36'
'48'
'64'
'72'

hidden [int] (default: 0)

Toggles whether an object is hidden when the patcher is locked.

hint [symbol]

Sets the text that will be displayed in as a pop-up hint when the user moves the mouse over the object in a locked patcher.

ignoreclick [int] (default: 0)

Toggles whether an object ignores mouse clicks in a locked patcher.

patching_rect [4 floats] (default: 0. 0. 100. 0.)

Sets the position and size of the object in the patcher window.

position [2 floats]

g/s(set)

Sets the object's x and y position in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its size unchanged.

presentation [int] (default: 0)

Sets whether an object belongs to the patcher's presentation.

presentation_rect [4 floats] (default: 0. 0. 0. 0.)

Sets the x and y position and width and height of the object in the patcher's presentation, leaving its patching position unchanged.

rect [4 floats]

g/s(set)

Sets the x and y position and width and height of the object in both patching and presentation modes (if the object belongs to its patcher's presentation).

size [2 floats]

g/s(set)

Sets the object's width and height in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its position unchanged.

textcolor [float]

Sets the color for the object's text in RGBA format.

textjustification [int]

Text Justification

Possible values:

0 = 'left'
1 = 'center'
2 = 'right'

varname [symbol]

Sets the patcher's scripting name, which can be used to address the object by name in pattr, scripting messages to thispatcher, and the js object.

Messages

bang

In left inlet: Sends out the current count of the bang messages received in the left inlet.

In left-middle inlet: Changes the direction of the count.

In middle inlet: Resets the count to its specified minimum value, which will be sent out the next time a bang is received in the left inlet.

In right-middle inlet: Resets the count to its specified minimum value, and sends out that value immediately.

In right inlet: Resets the count to its specified maximum value, which is sent out immediately.

int

Arguments

input [int]
In left inlet: Same effect as bang.

In left-middle inlet: Sets the direction of the count. 0 causes counter to count up, 1 causes it to count down, and 2 causes it to count up and down.

In middle inlet: The number sets the counter to a new value, to be sent out the next time a bang is received in the left inlet. If the number is less than the current minimum value, the minimum will be reset to that number. If the number is greater than the current maximum value, the counter will be set to that number, but the maximum value actually remains the same and the minimum is set equal to the maximum.

In middle-right inlet: The number sets the counter to a new value and sends it out immediately. If the number is less than the current minimum value, the minimum will be reset to that number. If the number is greater than the current maximum value, the number is sent out, but the maximum value actually remains the same and the minimum is set equal to the maximum.

In right inlet: Resets the maximum value sent out by counter. If the number is less than the current minimum, the maximum is equal to the minimum. If the minimum is subsequently changed to a value below the maximum value you input, the counter objects retains the correct maximum value it received through this inlet. Unlike a bang message, an int in this inlet does not cause the counter object to output anything.

float

Arguments

input [float]
In all other inlets: Converted to int.

dec

In left inlet: Decrements the counter (downward) and sends out the new value, regardless of the direction in which the object has been set to count ordinarily.

down

In left inlet: Sets the counter to count in a downward direction.

carrybang

In left inlet: Causes counter to send a bang out the right-middle outlet when the count is going upward and reaches its maximum limit, and causes counter to send a bang out the left-middle outlet when the count is going downward and reaches its minimum limit. (By default, counter sends out the number 1 in those situations, instead of bang.) The state of the carrybang message is saved along with the patcher it is used in.

carryint

In left inlet: Undoes the effect of a previously received carrybang message. Resets the counter to send the numbers 1 and 0 out the left-middle and right-middle outlets (instead of bang) to signal when the counter reaches and leaves its minimum and maximum values. The state of the carryint message is saved along with the patcher it is used in.

goto

Arguments

input [int]
In left inlet: Same effect as set.

flags

Arguments

carry-mode [int]
minimum-mode [int]
The flags message followed by two numbers will set the Underflow/Carry Mode and set the Minimum-Mode resetting capability. If the first number is 0, counter will output a 1 when it hits the maximum or else output a 0. If the first number is 1, counter will output a bang when it hits the maximum. If the second number is 0, an integer in inlets 3 and 4 will override the minimum count temporarily. If the second number is 1, an integer in inlets 3 and 4 will change the minimum count permanently.

inc

In left inlet: Increments the counter (upward) and sends out the new value, regardless of the direction in which the object has been set to count ordinarily.

jam

Arguments

input [int]
In left inlet: The word jam, followed by a number, sets the counter to that number and sends the number out immediately. If the number is outside the minimum and maximum count range, this message is ignored.

next

In left inlet: Same as bang.

max

Arguments

maximum [int]
In left inlet: The word max followed by a number, resets the maximum value of counter to that number. If the number is less than the current minimum value, the maximum is considered to be equal to the minimum, although the actual maximum value you set is stored inside the counter object.

min

Arguments

minimum [int]
In left inlet: The word min followed by a number, resets the minimum value of counter to that number, and causes the counter object to set itself to that number and output immediately. If the number is greater than the current maximum value, the minimum is set equal to the maximum.

set

Arguments

input [int]
In left inlet: The word set, followed by a number, sets the counter to that number, which will be sent out the next time a bang is received in the left inlet.

setmin

Arguments

minimum [int]
In left inlet: The word setmin, followed by a number, sets the counter object's minimum count without affecting its current count value or causing any output.

state

The message state will cause the counter object to report its current state to the Max Console.

up

In left inlet: Sets the counter to count in an upward direction.

updown

In left inlet: Sets the counter object's direction so that it counts upward until it reaches the specified maximum, then counts down until it reaches the specified minimum, then up, then down, and so on.

Output

bang

Out left-middle outlet: If a carrybang message has been received in the left inlet, then when the count is moving downward and reaches the minimum limit, a bang is sent out (instead of the number 1 which is sent out by default). When the count leaves the minimum limit, nothing is sent out.

Out right-middle outlet: If a carrybang message has been received in the left inlet, then when the count is moving upward and reaches the maximum limit, a bang is sent out (instead of the number 1 which is sent out by default). When the count leaves the maximum limit, nothing is sent out.

int

Out left outlet: When bang, next, inc, dec, or a number is received in the left inlet, the current count is sent out, within the minimum and maximum limits specified. If the direction of the count is both up and down, the count is folded back in the other direction when it reaches the specified limits. If the count is in only one direction, up or down, the count is wrapped around to the opposite extreme when it reaches its limit.

When the direction is up, or up and down, counter, begins counting from the specified minimum value. When the direction is down, counter begins from the maximum value.

Out left-middle outlet: When the count is moving downward and reaches the minimum limit, the number 1 is sent out. When the count leaves the minimum limit, 0 is sent out.

Out right-middle outlet: When the count is moving upward and reaches the maximum limit, the number 1 is sent out. When the count leaves the maximum limit, 0 is sent out.

Out right outlet: An additional count is kept of the number of times counter reaches its maximum limit. Each time the maximum is reached, that count is sent out.

See Also

Name Description
tempo Output numbers at a metronomic tempo
Max Basic Tutorial 11: Procedural Drawing Max Basic Tutorial 11: Procedural Drawing