Endless encoder

Encoder creates an endless rotary encoder similar to those found in certain well-known hardware samplers. Unlike regular sliders, encoder doesn't typically have a start and stop point. By setting a very small slider increment these widgets can offer a level of fine grain control not possible with regular sliders. Note that these sliders do not use the range() identifier. But you can set min and max values using min() and max().

encoder increment(val), max(val), min(val), outlineColour("colour"), trackerColour("colour"), textBox(on/off), textColour("colour"), text("string"), active(val), alpha(val), automatable(val), bounds(x, y, width, height), caption("string"), channel("chan"), colour("colour"), fontColour("colour"), identChannel("channel"), parent(val), popup(val), presetIgnore(val), rotate(radians, pivotx, pivoty), valuePrefix("valuePrefix"), valuePostfix("valuePostfix"), visible(val), toFront(), moveBehind("widgetName"), widgetArray("chan", number),

Specific Identifiers

increment(val) Set the incremental step size for the encoder.

max(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), max() will set the default maximum position of the maximum thumb controller. The absolute maximum is set using the range identifier. See above.

min(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), min() will set the default minimum position of the minimum thumb controller. The absolute minimum is set using the range identifier. See above.

outlineColour("colour") Sets the colour of a button outline, or a rotary slider`s tracker outline. In the case of rslider's this is the line that is drawn around the rslider's tracker. If you don't wish to display the tracker outline set the colour to something with an alpha value of 0. See above for details on valid colours.

trackerColour("colour") Sets the colour of the slider's tracker. This is the line that follows the slider when you move it.

textBox(on/off) textBox takes a 0 or a 1. 1 will cause a text box to appear with the sliders values. Leaving this out will result in the numbers appearing automatically when you hover over the sliders with your mouse.

textColour("colour") This set the colour of the text passed to text(). If you wish to change the colour of the numbers being displayed use fontColour(). See below. See above for details on valid colours.

text("string") "string" will be the text that appears on the widget. button widgets take two strings, one for on and one for off.

Common Identifiers

active(val) Will deactivate a control if 0 is passed. Controls which are deactivate can still be updated from Csound.

alpha(val) A value between 0 and 1 will set the alpha blend value for the entire component. Can be useful if you need to fade widgets in and out.

automatable(val) Default 1. Determines if a widget is automatable by a DAW host. Automatable widgets show up as plug-in parameters in the host. Non-automatable widgets still communicate with Csound but are not accessible by the host. Note that hosts don't allow this parameter to change dynamically -- the plugin will have to be reloaded for any changes to take effect.

bounds(x, y, width, height) integer values that set position and size on screen(in pixels).

caption("string") The string passed to caption will be the string that appears on the main application window.

channel("chan") or channel("chan1", "chan2") in the case of widgets that accept two channels such as xypad, soundfiler and range widgets. channel() accepts a string/s that names the channel/s that Cabbage will communicate with Csound on. The current value of this widget can be retrieved in Csound using a chnget, or a cabbageGetValue opcode. Its value can be set using the cabbageSet, or cabbageSetValue opcodes. hrange, vrange, xypad, and soundfiler all take two channels:

hrange, vrange : channel("min", "max") - min and max values

xypad : channel("x", "y") - x and y values

soundfiler : channel("start", "length") - start time and length of user selection, in samples

Channels named should start with a letter and cannot have any white spaces. Note that all widgets should have a unique channel name.

colour("colour") This sets the main colour. Any CSS or HTML colour string can be passed to this identifier. The colour identifier can also be passed an RBG, or RGBA value. All channel values must be between 0 and 255. For instance colour(0, 0, 255) will create a blue, while colour(0, 255, 0, 255) will create a green with an alpha channel set to full.

fontColour("colour") Sets the colour of the font. In the case of slider this sets teh colour of the font in the value textBox if it is shown.

identChannel("channel") [!!! DEPRECATED !!!] Although identifier channels still work, they are no longer supported. Please use the new guiMode("queue") system and the cabbageGet and cabbageSet opcodes instead. They are far more efficient then identifiers channel.

parent(val) This identifier is can be to set a widget's parent. It should only be used when creating widgets dynamically using the cabbageCreate opcode. See plants for more details.

popup(val) This identifier, used with an image or groupbox will convert the plant into a popup plant. The plant will not be shown on the instrument's main interface, but will instead appear when the user sets visible to 1. < DAWs treat popup dialogue windows in different ways. As a result, you may notice inconsistent behaviour when running your instruments as plugins across a variety of different hosts.

presetIgnore(val) Defaults to 0. Set this to 1 to ignore this widget's value when a preset is taken.

rotate(radians, pivotx, pivoty) Rotates the widget by a number of radians(2xPI=full rotation). pivotx and pivoty will determine the rotation pivot points, where 0, 0 represents the component's top-left position.

value(val) value sets the initial state of the widget. In the case of a keyboard widget, it sets the leftmost ky to appear.

valuePrefix("valuePrefix") Sets the prefix that is prepended to parameter values when displayed in the host and the plugin GUI. Defaults to "". xypad widgets take two strings, one of the x values, and one for the y values.

valuePostfix("valuePostfix") Sets the postfix that is appended to parameter values when displayed in the host and the plugin GUI. This can be helpful to make the units of parameters clear to the user (e.g. "Hz", "dB", etc.). Defaults to "". xypad widgets take two strings, one of the x values, and one for the y values.

visible(val) A value of 0 will cause the widget to become invisible. Widgets have their visibility set to 1 by default.

toFront() Brings a widget to the front of the z order. This identifier takes no arguments and is only intended for use within the Csound orchestra. it makes no sense to call it when declaring the widget.

moveBehind("widgetName") Moves a widget directly behind another. This identifier should only ever be called from your Csound orchestra using a cabbageSet opcode.

This only works with widgets or plants that have the same parent.

widgetArray("chan", number) [!!! DEPRECATED !!!] Deprecated. Please see the section on Managing large numbers of widgets


form caption("Encoder Example") size(380, 500), guiMode("queue"), colour(2, 145, 209) pluginId("def1")

texteditor bounds(18, 281, 341, 204) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)

soundfiler bounds(18, 16, 339, 182), channel("soundfiler1"), file("Guitar3.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 0)
button bounds(18, 218, 84, 32) corners(5), channel("play"), text("Play", "Stop")

encoder bounds(296, 204, 60, 60) channel("detune"), popupPrefix("Detune Amount: "), increment(0.001)
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
; Initialize the global variables. 
ksmps = 16
nchnls = 2
0dbfs = 1

; Rory Walsh 2021 
; License: CC0 1.0 Universal
; You can copy, modify, and distribute this file, 
; even for commercial purposes, all without asking permission. 

instr 1

    SText  = "A rotary controller can provide a high degree of precision, and offer fine tunings over certain parameters. In this example two diskin2 opcode are playing back the same sound file. When we move the endless encoder we can detune one of the samples by manipulating its playback speed. This gives a quick and simple chorus effect.\n\nThe popup value of the encoder is prefixed with \"detune Amount\" to provide more information to the user. All widget can have popup text appear when you hover over them. Only sliders offer popupPrefix and popupPostFix options."    
    cabbageSet "infoText", "text", SText

    ;trigger playback of sample
    kPlayState, kPlayTrig cabbageGetValue "play"
    if kPlayTrig == 1 then
        if kPlayState == 1 then
            event "i", "SamplePlayback", 0, -1
            turnoff2 nstrnum("SamplePlayback"), 0, 0


instr SamplePlayback

    SFilename = "Guitar3.wav"
    kDetune, kTrig cabbageGetValue "detune"    
    iLen = filelen(SFilename)*sr
    kScrubber phasor 1/(iLen/sr)
    cabbageSet metro(20), "soundfiler1", "scrubberPosition", kScrubber*iLen
    a1, a2 diskin2 SFilename, 1, 0, 1
    a3, a4 diskin2 SFilename, 1+kDetune, 0, 1
    aLeft = a1 + a3
    aRight = a2 + a4
    outs aLeft/2, aRight/2    


;causes Csound to run for about 7000 years...
i1 0 z