RotaryView:
Filter:
Classes (extension) | GUI > Views

RotaryView : ValueView : View : QObject : Object
ExtensionExtension

A UI view that mimics a rotary-style encoder.

An example of a series of RotaryViews in a layout.

Description

A GUI view that mimics a rotary-style encoder, similar to Knob, but fully customizable, including optionally a full 360-degree continuous range.

The view works in much the same was at other SC widgets, but has additional capabilities to notify dependents of changes, and the appearance is extensively customizable via numerous drawing layers with settable properties.

Class Methods

RotaryView.new(parent, bounds, spec, initVal, startAngle: 0, sweepLength: 6.2831853071796, innerRadiusRatio: 0.25, outerRadiusRatio: 1, direction: 'cw')

Create a new RotaryView.

Arguments:

parent

A Window or View, in which to embed this view. If nil, a window will be created to hold the view.

bounds

A Rect describing the bounds of this view within its parent. If parent is nil, the Rect specifies the dimensions of the newly created Window and its location on the screen.

spec

A ControlSpec that will control the range and warping of your value. -input is the unmapped -value. If nil, a \unipolar spec is created.

NOTE: : The step of the provided ControlSpec will determine the step resolution of the rotary when changing the value with a mouse or arrow key (default is 0, i.e. highest step resolution possible). See RotaryView: Example: radio dial.
initVal

The initial -value within range of the spec when the view is first drawn.

startAngle

The angular position of the start of the rotary's range, in radians. Default is 0. Can be negative. Reference 0 position is up, 12 o'clock, and advances according to direction (default clockwise).

sweepLength

The range of motion of the rotary, in radians. Default is 2pi.

innerRadiusRatio

A value from (0..1) determining radius of the the inner edge of the rotary. Default is 0.

outerRadiusRatio

A value from (0..1) determining radius of the the outer edge of the rotary, where 1 is the maximum radius given the size of the view. Default is 1.

direction

A Symbol, \cw or \ccw, clockwise and counterclockwise, respectively, indicating the direction of positive movement, for both value changes as well as affecting how startAngle is determined.

Returns:

Inherited class methods

Instance Methods

.value

.value = val

From superclass: ValueView

Get/set the value held by the view, which is the mapped counterpart of the -input (via the -spec).

The new value and corresponding -input will be broadcast to dependents, via \value and \iinput messages, respectively, every time either is set, unless -broadcastNewOnly is true, in which case the values are only broadcast if they differ from their previous state.

Arguments:

val

A Number. The number will either be constrained or wrapped within the view's -spec, depending on the state of -wrap (default is false, i.e. constrained to the spec.).

.input

.input = normValue

From superclass: ValueView

Get/set the input held by the view, which is the unmapped counterpart of the -value (via the -spec), i.e. a value from (0..1). This is useful for updating other UI elements which are often set through normalized values, like Sliders.

The new input and corresponding -value will be broadcast to dependents, via \input and \value messages, respectively, every time either is set, unless -broadcastNewOnly is true, in which case the values are only broadcast if they differ from their previous state.

Arguments:

normValue

A Number in the range (0..1), which will be mapped by the -spec to set the value.

.valueAction = val

From superclass: ValueView

Set the value of the view and perform the -action. This also updates the -input by unmapping from the -spec.

Arguments:

val

A Number in the range of the -spec. Out-of-range values will be clipped to the range of the -spec, unless -wrap is true, in which case the val is wrapped into range.

.inputAction = normValue

From superclass: ValueView

Set the input value of the view and perform the -action. This also updates the -value by mapping through the -spec.

Arguments:

normValue

A Number in the range of (0..1). Out-of-range inputs will be clipped to the range, unless -wrap is true, in which case the normValue is wrapped into range.

.doAction(newValue: true)

From superclass: ValueView

Perform the -action. Usually called through -valueAction or -inputAction.

Arguments:

newValue

A Boolean determining whether the actions is performed. Default is true. (In the underlying implementation of -valueAction and -inputAction, this argument is passed the result of newValue != oldValue, i.e. whether the value has changed to signal whether the action should be suppressed according to -supressRepearedAction, hence the name newValue. When calling this method directly, the argument is redundant.)

.suppressRepeatedAction

.suppressRepeatedAction = value

From superclass: ValueView

Get/set the Boolean which determines if the -action is performed only when a newly set value differs from its previous state. This applies when calling -valueAction, -inputAction, or -doAction. Default is true (repeated actions are suppressed). See RotaryView: Example: radio dial.

.spec

.spec_(controlSpec, updateValue: true)

From superclass: ValueView

Get/set the ControlSpec used to both map the -input and constrain the -value. Note: the step of the provided controlSpec will determine the step resolution of the rotary.

Arguments:

controlSpec

A ControlSpec.

updateValue

A Boolean specifying whether the -value(and -input) should be updated when the new controlSpec is set. Default is true.

User interaction

.continuous

.continuous = bool

A Boolean which determines if the rotary behaves like a continuous encoder, wrapping values around its -spec range when crossing min/max values. Useful for full 2pi range rotary controls. Synonym for -wrap. Default is false (values are clipped to range).

NOTE: If -dragMode is \circular the rotary behavior is always continuous, even if -continuous is false.

.clickMode = value

Set how mouse clicking changes the rotary position:

Arguments:

(value)
\absolutejumps to the value where it is clicked
\relativethe value changes relative to the

mouse movement once clicked.

.dragMode

.dragMode = vertHorizOrCirc: 'vertical'

Set how mouse dragging changes moves the rotary position.

NOTE: If -dragMode is \circular the rotary behavior is always continuous, even if -continuous is false.

Arguments:

vertHorizOrCirc
\verticalvalue changes according to vertical mouse movement
\horizontalvalue changes according to horizontal mouse movement
\circularvalue follows the radial movement around the rotary

.rangeInPixels

.rangeInPixels = px

From superclass: ValueView

Get/set the sensitivity of mouse interaction (and output resolution) by specifying the number of pixels over which the whole view's value range can be covered. Default is 200, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -valuePerPixel.

.valuePerPixel

.valuePerPixel = value

From superclass: ValueView

Get/set the sensitivity of mouse interaction (and output resolution) by specifying the value change per pixel when interacting with the view through mouse movement. Default is spec.range / 200, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -rangeInPixels.

.scroll

.scroll = value

From superclass: ValueView

Get/set the Boolean indicating whether the value changes with mouse scrolling. Default is true.

.scrollStep

.scrollStep = value

From superclass: ValueView

Get/set the step amount when scrolling. Default is 100.reciprocal.

.xScrollDir

.xScrollDir = value

From superclass: ValueView

Get/set the x scroll direction. 1 is left to right scrolling (default), -1 is the reverse.

.yScrollDir

.yScrollDir = value

From superclass: ValueView

Get/set the y scroll direction. -1 is "natural" scrolling (default), 1 is the reverse.

.keyStep

.keyStep = value

From superclass: ValueView

Get/set the step amount of each arrow key press, as a percentage of the range of the spec. E.g. keyStep of 30.reciprocal (the default) means it takes 30 key strokes to cover the full value range (warped according to the -spec).

.keyDirLR

.keyDirLR = value

From superclass: ValueView

Get/set the step direction of Left/Right arrow keys. 1 = right increments, left decrements (default). -1 = left increments, right decrements.

.keyDirUD

.keyDirUD = value

From superclass: ValueView

Get/set the step direction of Up/Down arrow keys. 1 = up increments, down decrements (default). -1 = down increments, up decrements.

Bipolar mode

.bipolar

.bipolar = bool

Get/set how the rotary fills the color up to the current value. If false, the color is always filled from the minumum value in the range up to the current value. If true, the color is filled from the -centerValue to the current value. See RotaryView: Example: bipolar mode and Example: continuous encoder.

Arguments:

bool

A Boolean.

.centerValue

.centerValue = value

Get/set the Number that is the "center" of the bipolar axis. See RotaryView: Example: bipolar mode and Example: continuous encoder.

Arguments:

value

A Number in the range of the -spec.

Ticks

.numTicks_(num, majorEvery: 2, startAndEnd: true)

Set the number of ticks to be displayed evenly across the full range of the rotary. See Examples: radio dial and Example: continuous encoder.

Arguments:

num

An Integer. The total number of ticks (major and minor).

majorEvery

An Integer. Frequency of major ticks. E.g. majorEvery = 3 would make a tick pattern of major-minor-minor-major-minor-minor-etc. See -ticks layer for setting other properties about ticks.

startAndEnd

A Boolean, whether the first and last tick fall at the start and end of the range. E.g. If the -sweepLength is 2pi, you wouldn't want the last tick to fall at the end of the range, as it would overlap with the first. See Example: continuous encoder.

.ticksAt_(majorRadPositions, minorRadPositions)

Set the position of major and minor ticks, in radians.

Arguments:

majorRadPositions

An Array of radian values, relative to -startAngle and -direction, for the major ticks.

minorRadPositions

An Array of radian values, relative to -startAngle and -direction, for the minor ticks.

.ticksAtValues_(majorVals, minorVals)

Set the position of major and minor ticks, in the units of your -spec. See Examples: bipolar mode.

Arguments:

majorVals

An Array of values for the major ticks, within the range of your -spec.

minorVals

An Array of values for the minor ticks, within the range of your -spec.

.ticksEveryVal_(valueHop, majorEvery: 2)

Set the ticks at an even interval, in the units of your -spec, specifying the steps between each major tick. See Example: continuous encoder.

Arguments:

valueHop

A Number specifying the interval, or "hop", between each tick.

majorEvery

An Integer specifying the steps of major ticks.

Layout

.direction

.direction = dir: 'cw'

Get/set the direction of positive movement, for both value changes as well as affecting how -startAngle is determined.

Arguments:

dir

A Symbol, \cw or \ccw, clockwise and counterclockwise, respectively.

.dirFlag

Get the value corresponding to the rotary's direction: clockwise = 1, counterclockwise = -1.

.innerRadiusRatio

.innerRadiusRatio = ratio

Set/get the radius of the the inner edge of the rotary.

Arguments:

ratio

A value from (0..1).

.outerRadiusRatio

.outerRadiusRatio = ratio

Set/get the radius of the the outer edge of the rotary, where 1 is the maximum radius given the size of the view.

Arguments:

ratio

A value from (0..1)

.startAngle

.startAngle = radians: 0

Get/set the angular position of the start of the rotary's range, in radians. Reference 0 position is up, 12 o'clock, and advances according to -direction.

Arguments:

radians

A Number in radians, can be negative.

.sweepLength

.sweepLength = radians: 6.2831853071796

Get/set the range of motion of the rotary, in radians. Default is 2pi.

Arguments:

radians

A A Number in radians.

Drawing layers: fine tuning appearance

The rotary is comprised of multiple layers, each with their own settable properties: range, level, text, ticks, handle, and outline. Each drawing layer has a *properties list (an Event), the keys of which can be accessed as pseudo-methods for getting and setting their values. Setting a property automatically refreshes the view. For example:

.range

The layer showing the range of the rotary. Some parameters apply only for a certain style. If style == \wedge, an annularWedge is drawn for the range. If style == \arc a stroked arc is used.

propertydefaultdescription
showtrueshow the range layer or not
style\wedge\arc or \wedge (an annularWedge); if \arc, the width

follows width, not strokeWidth

radius1(0..1), radius of outer edge of the wedge or arc
width1(0..1) width of range display, relative to wedgeWidth

(outerRadiusRatio - innerRadiusRatio)

filltruefill the range or not
fillColorColor(0.9,0.9,0.9)color to fill the range
strokefalsestroke the range or not
strokeType\aroundif style == \wedge; \inside, \outside, \around, or \insideOutside
strokeColorColorstroke color of the range
strokeWidth1if style == \wedge; if < 1, assumed to be a normalized value

and changes with view size, else treated as a pixel value

joinStyle0if style == \wedge; \miter; \round, \bevel, or

an Integer of the Pen: *joinStyle

capStyle\roundif style == \arc; \butt, \flat, \round, \square, or

an Integer of the Pen: *capStyle

.level

The layer showing the level of the rotary. If style == \wedge, an annularWedge is drawn for the range. If style == \arc a stroked arc is used.

propertydefaultdescription
showtrueshow the level layer or not
style\wedge\arc or \wedge (an annularWedge); if \arc, the width

follows width, not strokeWidth

radius1(0..1), radius of outer edge of the wedge or arc
width1(0..1) width of range display, relative to wedgeWidth
filltruefill the level or not
fillColorColor.whitecolor to fill the level;
stroketruestroke the level or not
strokeType\aroundif style == \wedge; \inside, \outside, \around, or \insideOutside
strokeColorColor.graystroke color of the level
strokeWidth0.025if style == \wedge; if < 1, assumed to be a normalized value
joinStyle0if style == \wedge; \miter; \round, \bevel, or

an Integer of the Pen: *joinStyle

and changes with view size, else treated as a pixel value

capStyle0if style == \arc; \butt, \flat, \round, \square, or

an Integer of the Pen: *capStyle

.text

The layer showing the text of the rotary's current value.

propertydefaultdescription
showtrueshow the text layer or not
align\center\top, \bottom, \center, \left, \right, or a Point on which

to center the text, in a range of (0..1)

where top-left is 0@0, bottom-right is 1@1

round0.1a Number to round the value display to
fontSize0.1font size in pixels, unless < 1, then relative to radius
fontName"Helvetica"a String, the font name
colorColor.grayColor of the text

.ticks

The layer showing the ticks of the rotary. The number and position of ticks are set through -numTicks, -ticksAt, -ticksAtValues, or -ticksEveryVal.

propertydefaultdescription
showfalseshow the tick layer or not
anchor0.97(0..1) position/radius where the ticks are "anchored",

relative to outer edge of rotary

align\insidethe position of the ticks relative to anchor;

\inside, \outside, or \center

majorLength0.25length of major ticks, (0..1) realtive to maxRadius
minorLength0.1length of major ticks, (0..1) realtive to maxRadius
majorWidth0.05width of major tick, in pixels unless < 1,

in which case relative to radius

minorWidth0.025width of major tick, in pixels unless < 1,

in which case relative to radius

majorColorColor.grayColor of the major ticks
minorColorColor.grayColor of the minor ticks
capStyle\round\butt, \flat, \round, \square,

or an Integer of the Pen: *capStyle

.handle

The layer showing the "handle" of the rotary. Some properties are only valid for certain styles.

propertydefaultdescription
showtrueshow the handle layer or not
style'line'\line, \circle, or \arrow
anchor0.9reference radius of for drawing the anchor align, (0..1)
align'inside'\inside, \outside, or \center on the anchor
length0.3if style == \line or == \arrow, (0..1) relative to radius
width0.6if style == \arrow, (0..1) relative to length
stroketrueif style == \circle or == \arrow, stroke the handle or not
strokeColorColor.blackstroke Color of the handle
filltrueif style == \circle or == \arrow, fill the handle or not
fillColorColor.redfill Color of the handle
joinStyle'round'if style == \arrow, \miter, \round, \bevel,

or an Integer of the Pen: *joinStyle

radius0.1if style == \circle, in pixels unless < 1,

in which case relative to radius

capStyle'round'if style == \line, \butt, \flat, \round, \square,

or an Integer of the Pen: *capStyle

strokeWidth0.05width of stroke, in pixels, unless < 1, then relative to radius

in which case relative to radius

.outline

The layer showing the outline of the rotary. It's called "outline", but need not be on the perimeter—it's essentially a circle of variable size/fill that can serve as an outline or visual accent. It's the topmost layer.

propertydefaultdescription
showfalseshow the outline layer or not
radius1(0..1), relative to radius
stroketruestroke or not
strokeColorColor.blackstroke Color of the outline
strokeWidth2in pixels unless < 1,

in which case relative to radius

rangeOnlyfalsea Boolean whether outline is constrained

to the rotary's range, or is a full circle

capStyleflatif rangeOnly == \true, \butt, \flat, \round, \square,

or an Integer of the Pen: *capStyle

fillfalsefill or not
fillColorColor.whitefill Color of the outline layer

Inherited instance methods

Examples

Example: bipolar mode

Example: radio dial

Example: continuous encoder

Example: level dial

Example: panner

Example: in a layout

Multiple rotaries in a layout.