FLbutton
Prev | Orchestra Opcodes and Operators | Next

## FLbutton

FLbutton — A FLTK widget opcode that creates a button.

## Description

A FLTK widget opcode that creates a button.

## Syntax

    kout, ihandle FLbutton "label", ion, ioff, itype, iwidth, iheight, ix, \
          iy, iopcode [, kp1] [, kp2] [, kp3] [, kp4] [, kp5] [....] [, kpN]

## Initialization

ihandle -- a handle value (an integer number) that unequivocally references a corresponding widget. This is used by other opcodes that modify a widget's properties (see Modifying FLTK Widget Appearance). It is automatically output by FLbutton and must not be set by the user label. (The user label is a double-quoted string containing some user-provided text placed near the widget.)

“label” -- a double-quoted string containing some user-provided text, placed near the corresponding widget.

Notice that with FLbutton, it is not necessary to call the FLsetTextType opcode at all in order to use a symbol. In this case, it is sufficient to set a label starting with “@” followed by the proper formatting string.

The following symbols are supported:

FLTK label supported symbols.

The @ sign may be followed by the following optional “formatting” characters, in this order:

1. “#” forces square scaling rather than distortion to the widget's shape.

2. +[1-9] or -[1-9] tweaks the scaling a little bigger or smaller.

3. [1-9] rotates by a multiple of 45 degrees. “6” does nothing, the others point in the direction of that key on a numeric keypad.

ion -- value output when the button is checked.

ioff -- value output when the button is unchecked.

itype -- an integer number denoting the appearance of the widget.

Several kind of buttons are possible, according to the value of itype argument:

- 1 - normal button

- 2 - light button

- 3 - check button

- 4 - round button

You can add 20 to the value to create a "plastic" type button. (Note that there is no Platic Round button. i.e. if you set type to 24 it will look exactly like type 23).

This is the appearance of the buttons:

FLbutton.

iwidth -- width of widget.

iheight -- height of widget.

ix -- horizontal position of upper left corner of the valuator, relative to the upper left corner of corresponding window (expressed in pixels).

iy -- vertical position of upper left corner of the valuator, relative to the upper left corner of corresponding window (expressed in pixels).

iopcode -- score opcode type. You have to provide the ascii code of the letter corresponding to the score opcode. At present time only “i” (ascii code 105) score statements are supported. A zero value refers to a default value of “i”. So both 0 and 105 activates the i opcode. A value of -1 disables this opcode feature.

## Performance

kout -- output value

kp1, kp2, ..., kpN -- arguments of the activated instruments.

Buttons of type 2, 3, and 4 also output (kout argument) the value contained in the ion argument when checked, and that contained in ioff argument when unchecked.

By adding 10 to itype argument (i.e. by setting 11 for type 1, 12 for type 2, 13 for type 3 and 14 for type 4) it is possible to skip the button value when getting/setting snapshots (see later section). FLbutton not only outputs a value, but can also activate (or schedule) an instrument provided by the user each time a button is pressed. You can also add 10 to "plastic" button types (31 for type 1, 32 for type 2, etc.)

If the iopcode argument is set to a negative number, no instrument is activated. So this feature is optional. In order to activate an instrument, iopcode must be set to 0 or to 105 (the ascii code of character “i”, referring to the i score opcode).

P-fields of the activated instrument are kp1 (instrument number), kp2 (action time), kp3 (duration) and so on with user p-fields. Notice that in dual state buttons (light button, check button and round button), the instrument is activated only when button state changes from unchecked to checked (not when passing from checked to unchecked).

## Examples

Here is an example of the FLbutton opcode. It uses the file FLbutton.csd, and beats.wav.

Example 238. Example of the FLbutton opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o FLbutton.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Using FLbuttons to create on screen controls for play,
    ; stop, fast forward and fast rewind of a sound file
    ; This example also makes use of a preset graphic for buttons.

    sr = 44100
    kr = 44100
    ksmps = 1
    nchnls = 2

    FLpanel "Buttons", 240, 400, 100, 100
        ion = 0
        ioff = 0
        itype = 1
        iwidth = 50
        iheight = 50
        ix = 10
        iy = 10
        iopcode = 0
        istarttim = 0
        idur = -1  ;Turn instruments on idefinitely

        ; Normal speed forwards
        gkplay, ihb1 FLbutton "@>", ion, ioff, itype, iwidth, iheight, ix, iy, iopcode, 1, istarttim, idur, 1
        ; Stationary
        gkstop, ihb2 FLbutton "@square", ion,ioff, itype, iwidth, iheight, ix+55, iy, iopcode, 2, istarttim, idur
        ; Double speed backwards
        gkrew, ihb3 FLbutton "@<<", ion, ioff, itype, iwidth, iheight, ix + 110, iy, iopcode, 1, istarttim, idur, -2
        ; Double speed forward
        gkff, ihb4 FLbutton "@>>", ion, ioff, itype, iwidth, iheight, ix+165, iy, iopcode, 1, istarttim, idur, 2
        ; Type 1
        gkt1, iht1 FLbutton "1-Normal Button", ion, ioff, 1, 200, 40, ix, iy + 65, -1
        ; Type 2
        gkt2, iht2 FLbutton "2-Light Button", ion, ioff, 2, 200, 40, ix, iy + 110, -1
        ; Type 3
        gkt3, iht3 FLbutton "3-Check Button", ion, ioff, 3, 200, 40, ix, iy + 155, -1
        ; Type 4
        gkt4, iht4 FLbutton "4-Round Button", ion, ioff, 4, 200, 40, ix, iy + 200, -1
        ; Type 21
        gkt5, iht5 FLbutton "21-Plastic Button", ion, ioff, 21, 200, 40, ix, iy + 245, -1
        ; Type 22
        gkt6, iht6 FLbutton "22-Plastic Light Button", ion, ioff, 22, 200, 40, ix, iy + 290, -1
        ; Type 23
        gkt7, iht7 FLbutton "23-Plastic Check Button", ion, ioff, 23, 200, 40, ix, iy + 335, -1
    FLpanelEnd
    FLrun

    ; Ensure that only 1 instance of instr 1
    ; plays even if the play button is clicked repeatedly
    insnum = 1
    icount = 1
    maxalloc insnum, icount

    instr 1
        asig diskin2 "beats.wav", p4, 0, 1
        outs asig, asig
    endin

    instr 2
        turnoff2 1, 0, 0   ;Turn off instr 1
        turnoff   ;Turn off this instrument
    endin

    </CsInstruments>
    <CsScore>

    ; Real-time performance for 1 hour.
    f 0 3600
    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

FLbox, FLbutBank, FLprintk, FLprintk2, FLvalue

## Credits

Author: Gabriel Maldonado

New in version 4.22

Example written by Iain McCurdy, edited by Kevin Conder.

Prev | Up | Next
FLbutBank | Home | FLcloseButton