| 1 |
|
| 2 |
<section id="ControlFltkIntro"> |
| 3 |
<title>FLTK Widgets and GUI controllers</title> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
<para> |
| 10 |
Widgets allow the design of a custom Graphical User Interface (GUI) to control an orchestra in real-time. |
| 11 |
They are derived from the open-source library FLTK (Fast Light Tool Kit). This library is one of the |
| 12 |
fastest graphic libraries available, supports OpenGL and should be source compatible with different |
| 13 |
platforms (Windows, Linux, Unix and Mac OS). The subset of FLTK implemented in Csound provides the |
| 14 |
following types of objects: |
| 15 |
<variablelist> |
| 16 |
<varlistentry><term>Containers</term> |
| 17 |
<listitem> |
| 18 |
<para> |
| 19 |
<link linkend="ControlFltkContainers"><citetitle>FLTK Containers</citetitle></link> are widgets |
| 20 |
that contain other widgets such as panels, windows, etc. Csound provides the following container |
| 21 |
objects: |
| 22 |
<itemizedlist> |
| 23 |
<listitem><simpara>Panels</simpara></listitem> |
| 24 |
<listitem><simpara>Scroll areas</simpara></listitem> |
| 25 |
<listitem><simpara>Pack</simpara></listitem> |
| 26 |
<listitem><simpara>Tabs</simpara></listitem> |
| 27 |
<listitem><simpara>Groups</simpara></listitem> |
| 28 |
</itemizedlist> |
| 29 |
</para> |
| 30 |
</listitem> |
| 31 |
</varlistentry> |
| 32 |
<varlistentry><term>Valuators</term> |
| 33 |
<listitem> |
| 34 |
<para> |
| 35 |
The most useful objects are named |
| 36 |
<link linkend="ControlFltkValuators"><citetitle>FLTK Valuators</citetitle></link>. These objects |
| 37 |
allow the user to vary synthesis parameter values in real-time. Csound provides the following |
| 38 |
valuator objects: |
| 39 |
<itemizedlist> |
| 40 |
<listitem><simpara>Sliders</simpara></listitem> |
| 41 |
<listitem><simpara>Knobs</simpara></listitem> |
| 42 |
<listitem><simpara>Rollers</simpara></listitem> |
| 43 |
<listitem><simpara>Text fields</simpara></listitem> |
| 44 |
<listitem><simpara>Joysticks</simpara></listitem> |
| 45 |
<listitem><simpara>Counters</simpara></listitem> |
| 46 |
</itemizedlist> |
| 47 |
</para> |
| 48 |
</listitem> |
| 49 |
</varlistentry> |
| 50 |
<varlistentry> |
| 51 |
<term>Other widgets</term> |
| 52 |
<listitem> |
| 53 |
<para> |
| 54 |
There are <link linkend="ControlFltkOther"><citetitle>other FTLK widgets</citetitle></link> |
| 55 |
that are not valuators nor containers: |
| 56 |
<itemizedlist> |
| 57 |
<listitem><simpara>Buttons</simpara></listitem> |
| 58 |
<listitem><simpara>Button banks</simpara></listitem> |
| 59 |
<listitem><simpara>Labels</simpara></listitem> |
| 60 |
<listitem><simpara>Keyboard and Mouse sensing</simpara></listitem> |
| 61 |
</itemizedlist> |
| 62 |
</para> |
| 63 |
</listitem> |
| 64 |
</varlistentry> |
| 65 |
</variablelist> |
| 66 |
</para> |
| 67 |
|
| 68 |
<para> |
| 69 |
Also there are some other opcodes useful to modify the |
| 70 |
<link linkend="ControlFltkAppearance"><citetitle>widget appearance</citetitle></link>: |
| 71 |
<itemizedlist> |
| 72 |
<listitem><simpara>Updating widget value.</simpara></listitem> |
| 73 |
<listitem><simpara>Setting primary and selection colors of a widget.</simpara></listitem> |
| 74 |
<listitem><simpara>Setting font type, size and color of widgets.</simpara></listitem> |
| 75 |
<listitem><simpara>Resizing a widget.</simpara></listitem> |
| 76 |
<listitem><simpara>Hiding and showing a widget.</simpara></listitem> |
| 77 |
</itemizedlist> |
| 78 |
</para> |
| 79 |
|
| 80 |
<para> |
| 81 |
There are also these <link linkend="ControlFltkGeneral"><citetitle>general opcodes</citetitle></link> that allow the following actions: |
| 82 |
<itemizedlist> |
| 83 |
<listitem><simpara>Running the widget thread: |
| 84 |
<link linkend="FLrun"><citetitle>FLrun</citetitle></link></simpara> |
| 85 |
</listitem> |
| 86 |
<listitem><simpara>Loading snapshots containing the status of all valuators of an orchestra: |
| 87 |
<link linkend="FLgetsnap"><citetitle>FLgetsnap</citetitle></link> and |
| 88 |
<link linkend="FLloadsnap"><citetitle>FLloadsnap</citetitle></link>.</simpara> |
| 89 |
</listitem> |
| 90 |
<listitem><simpara>Saving snapshots containing the status of all valuators of an orchestra: |
| 91 |
<link linkend="FLsavesnap"><citetitle>FLsavesnap</citetitle></link> and |
| 92 |
<link linkend="FLsetsnap"><citetitle>FLsetsnap</citetitle></link></simpara> |
| 93 |
</listitem> |
| 94 |
<listitem><simpara>Setting the snapshot group of a declared valuator: |
| 95 |
<link linkend="FLsetSnapGroup"><citetitle>FLsetSnapGroup</citetitle></link></simpara> |
| 96 |
</listitem> |
| 97 |
</itemizedlist> |
| 98 |
</para> |
| 99 |
|
| 100 |
<para> |
| 101 |
Below is a simple example of Csound code to create a window. Notice that all opcodes are init-rate and |
| 102 |
must be called only once per session. The best way to use them is to place them in the header section of |
| 103 |
an orchestra, before any instrument. Even though placing them inside an instrument is not prohibited, |
| 104 |
unpredictable results can occur if that instrument is called more than once. |
| 105 |
</para> |
| 106 |
|
| 107 |
<para> |
| 108 |
Each container is made up of a couple of opcodes: the first indicating the start of the container block and the last indicating the end of that container block. Some container blocks can be nested but they must not be crossed. After defining all containers, a widget thread must be run by using the special FLrun opcode that takes no arguments. |
| 109 |
</para> |
| 110 |
|
| 111 |
<para> |
| 112 |
<informalexample> |
| 113 |
<programlisting> |
| 114 |
<emphasis role="csdtag"><CsoundSynthesizer></emphasis> |
| 115 |
<emphasis role="csdtag"><CsOptions></emphasis> |
| 116 |
<emphasis role="comment">; Select audio/midi flags here according to platform</emphasis> |
| 117 |
<emphasis role="comment">; Audio out Audio in No messages</emphasis> |
| 118 |
-odac -iadc -d <emphasis role="comment">;;;RT audio I/O</emphasis> |
| 119 |
<emphasis role="comment">; For Non-realtime ouput leave only the line below:</emphasis> |
| 120 |
<emphasis role="comment">; -o linseg.wav -W ;;; for file output any platform</emphasis> |
| 121 |
<emphasis role="csdtag"></CsOptions></emphasis> |
| 122 |
<emphasis role="csdtag"><CsInstruments></emphasis> |
| 123 |
<emphasis role="comment">;*******************************</emphasis> |
| 124 |
<emphasis role="ohdr">sr</emphasis><emphasis role="op">=</emphasis>48000 |
| 125 |
<emphasis role="ohdr">kr</emphasis><emphasis role="op">=</emphasis>480 |
| 126 |
<emphasis role="ohdr">ksmps</emphasis><emphasis role="op">=</emphasis>100 |
| 127 |
<emphasis role="ohdr">nchnls</emphasis><emphasis role="op">=</emphasis>1 |
| 128 |
|
| 129 |
<emphasis role="comment">;*** It is recommended to put almost all GUI code in the</emphasis> |
| 130 |
<emphasis role="comment">;*** header section of an orchestra</emphasis> |
| 131 |
|
| 132 |
<emphasis role="opc">FLpanel</emphasis> "Panel1",450,550 <emphasis role="comment">;***** start of container</emphasis> |
| 133 |
<emphasis role="comment">; some widgets should contained here</emphasis> |
| 134 |
<emphasis role="opc">FLpanelEnd</emphasis> <emphasis role="comment">;***** end of container</emphasis> |
| 135 |
|
| 136 |
<emphasis role="opc">FLrun</emphasis> <emphasis role="comment">;***** runs the widget thread, it is always required!</emphasis> |
| 137 |
<emphasis role="oblock">instr</emphasis> 1 |
| 138 |
<emphasis role="comment">;put some synthesis code here</emphasis> |
| 139 |
<emphasis role="oblock">endin</emphasis> |
| 140 |
<emphasis role="comment">;*******************************</emphasis> |
| 141 |
<emphasis role="csdtag"></CsInstruments></emphasis> |
| 142 |
<emphasis role="csdtag"><CsScore></emphasis> |
| 143 |
<emphasis role="stamnt">f</emphasis> 0 3600 <emphasis role="comment">;dummy table for realtime input</emphasis> |
| 144 |
<emphasis role="stamnt">e</emphasis> |
| 145 |
|
| 146 |
<emphasis role="csdtag"></CsScore></emphasis> |
| 147 |
<emphasis role="csdtag"></CsoundSynthesizer></emphasis></programlisting> |
| 148 |
</informalexample> |
| 149 |
|
| 150 |
The previous code simply creates a panel (an empty window because no widgets are defined inside the container). |
| 151 |
|
| 152 |
</para> |
| 153 |
|
| 154 |
<para> |
| 155 |
The following example creates two panels and inserts a slider inside each of them: |
| 156 |
|
| 157 |
<informalexample> |
| 158 |
<programlisting> |
| 159 |
<emphasis role="csdtag"><CsoundSynthesizer></emphasis> |
| 160 |
<emphasis role="csdtag"><CsOptions></emphasis> |
| 161 |
<emphasis role="comment">; Select audio/midi flags here according to platform</emphasis> |
| 162 |
<emphasis role="comment">; Audio out Audio in No messages</emphasis> |
| 163 |
-odac -iadc <emphasis role="comment">; -d ;;;RT audio I/O</emphasis> |
| 164 |
<emphasis role="comment">; For Non-realtime ouput leave only the line below:</emphasis> |
| 165 |
<emphasis role="comment">; -o linseg.wav -W ;;; for file output any platform</emphasis> |
| 166 |
<emphasis role="csdtag"></CsOptions></emphasis> |
| 167 |
<emphasis role="csdtag"><CsInstruments></emphasis> |
| 168 |
<emphasis role="comment">;*******************************</emphasis> |
| 169 |
<emphasis role="ohdr">sr</emphasis><emphasis role="op">=</emphasis>48000 |
| 170 |
<emphasis role="ohdr">kr</emphasis><emphasis role="op">=</emphasis>480 |
| 171 |
<emphasis role="ohdr">ksmps</emphasis><emphasis role="op">=</emphasis>100 |
| 172 |
<emphasis role="ohdr">nchnls</emphasis><emphasis role="op">=</emphasis>1 |
| 173 |
|
| 174 |
<emphasis role="opc">FLpanel</emphasis> "Panel1",450,550,100,100 <emphasis role="comment">;***** start of container</emphasis> |
| 175 |
gk1,iha <emphasis role="opc">FLslider</emphasis> "FLslider 1", 500, 1000, 0 ,1, -1, 300,15, 20,50 |
| 176 |
<emphasis role="opc">FLpanelEnd</emphasis> <emphasis role="comment">;***** end of container</emphasis> |
| 177 |
|
| 178 |
<emphasis role="opc">FLpanel</emphasis> "Panel2",450,550,100,100 <emphasis role="comment">;***** start of container</emphasis> |
| 179 |
gk2,ihb <emphasis role="opc">FLslider</emphasis> "FLslider 2", 100, 200, 0 ,1, -1, 300,15, 20,50 |
| 180 |
<emphasis role="opc">FLpanelEnd</emphasis> <emphasis role="comment">;***** end of container</emphasis> |
| 181 |
|
| 182 |
<emphasis role="opc">FLrun</emphasis> <emphasis role="comment">;***** runs the widget thread, it is always required!</emphasis> |
| 183 |
|
| 184 |
<emphasis role="oblock">instr 1</emphasis> |
| 185 |
<emphasis role="comment">; gk1 and gk2 variables that contain the output of valuator</emphasis> |
| 186 |
<emphasis role="comment">; widgets previously defined, can be used inside any instrument</emphasis> |
| 187 |
<emphasis role="opc">printk2</emphasis> gk1 |
| 188 |
<emphasis role="opc">printk2</emphasis> gk2 <emphasis role="comment">;print the values of the valuators whenever they change</emphasis> |
| 189 |
<emphasis role="oblock">endin</emphasis> |
| 190 |
<emphasis role="comment">;*******************************</emphasis> |
| 191 |
<emphasis role="csdtag"></CsInstruments></emphasis> |
| 192 |
<emphasis role="csdtag"><CsScore></emphasis> |
| 193 |
<emphasis role="stamnt">f</emphasis> 0 3600 <emphasis role="comment">;dummy table for realtime input</emphasis> |
| 194 |
<emphasis role="stamnt">e</emphasis> |
| 195 |
|
| 196 |
<emphasis role="csdtag"></CsScore></emphasis> |
| 197 |
<emphasis role="csdtag"></CsoundSynthesizer></emphasis></programlisting> |
| 198 |
</informalexample> |
| 199 |
</para> |
| 200 |
|
| 201 |
<para> |
| 202 |
All widget opcodes are init-rate opcodes, even if valuators output k-rate variables. This happens because an independent thread is run based on a callback mechanism. It consumes very few processing resources since there is no need of polling. (This differs from other MIDI based controller opcodes.) So you can use any number of windows and valuators without degrading the real-time performance. |
| 203 |
</para> |
| 204 |
|
| 205 |
&controlfltkcontainers; |
| 206 |
&controlfltkvaluators; |
| 207 |
&controlfltkother; |
| 208 |
&controlfltkappearance; |
| 209 |
&controlfltkgeneral; |
| 210 |
|
| 211 |
</section> |