| 1 | |
| 2 | <refentry id="printks"> |
| 3 | <indexterm id="IndexPrintks"><primary>printks</primary></indexterm> |
| 4 | <refentryinfo><title>Signal I/O:Printing and Display</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>printks</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>printks</refname> |
| 13 | <refpurpose> |
| 14 | Prints at k-rate using a printf() style syntax. |
| 15 | </refpurpose> |
| 16 | </refnamediv> |
| 17 | |
| 18 | <refsect1> |
| 19 | <title>Description</title> |
| 20 | <para> |
| 21 | Prints at k-rate using a printf() style syntax. |
| 22 | </para> |
| 23 | </refsect1> |
| 24 | |
| 25 | <refsect1> |
| 26 | <title>Syntax</title> |
| 27 | <synopsis><command>printks</command> "string", itime [, xval1] [, xval2] [...]</synopsis> |
| 28 | </refsect1> |
| 29 | |
| 30 | <refsect1> |
| 31 | <title>Initialization</title> |
| 32 | <para> |
| 33 | <emphasis>"string"</emphasis> -- the text string to be printed. Can be up to 8192 characters and must be in double quotes. |
| 34 | </para> |
| 35 | |
| 36 | <para> |
| 37 | <emphasis>itime</emphasis> -- time in seconds between printings. |
| 38 | </para> |
| 39 | </refsect1> |
| 40 | |
| 41 | <refsect1> |
| 42 | <title>Performance</title> |
| 43 | <para> |
| 44 | <emphasis>xval1, xval2, ...</emphasis> (optional) -- The k-rate |
| 45 | values to be printed. These are specified in |
| 46 | <emphasis><quote>string</quote></emphasis> with the standard C |
| 47 | value specifier (%f, %d, %s etc.) in the order given. |
| 48 | </para> |
| 49 | |
| 50 | <para> |
| 51 | In Csound version 4.23, you can use as many <emphasis>kval</emphasis> variables as you like. In versions prior to 4.23, you must specify 4 and only 4 kvals (using 0 for unused kvals). |
| 52 | </para> |
| 53 | |
| 54 | <para> |
| 55 | <emphasis>printks</emphasis> prints numbers and text which can be i-time or k-rate values. <emphasis>printks</emphasis> is highly flexible, and if used together with cursor positioning codes, could be used to write specific values to locations in the screen as the Csound processing proceeds. |
| 56 | </para> |
| 57 | |
| 58 | <para> |
| 59 | A special mode of operation allows this <emphasis>printks</emphasis> to convert <emphasis>kval1</emphasis> input parameter into a 0 to 255 value and to use it as the first character to be printed. This enables a Csound program to send arbitrary characters to the console. To achieve this, make the first character of the string a # and then, if desired continue with normal text and format specifiers. |
| 60 | </para> |
| 61 | |
| 62 | <para> |
| 63 | This opcode can be run on every k-cycle it is run in the instrument. To every accomplish this, set <emphasis>itime</emphasis> to 0. |
| 64 | </para> |
| 65 | |
| 66 | <para> |
| 67 | When <emphasis>itime</emphasis> is not 0, the opcode print on the first k-cycle it is called, and subsequently when every <emphasis>itime</emphasis> period has elapsed. The time cycles start from the time the opcode is initialized - typically the initialization of the instrument. |
| 68 | </para> |
| 69 | </refsect1> |
| 70 | |
| 71 | <refsect1> |
| 72 | <title>Print Output Formatting</title> |
| 73 | <para> |
| 74 | All standard C language printf() control characters may be used. For example, if <emphasis>kval1</emphasis> = 153.26789 then some common formatting options are: |
| 75 | |
| 76 | <orderedlist> |
| 77 | <listitem><para>%f prints with full precision: 153.26789</para></listitem> |
| 78 | <listitem><para>%5.2f prints: 153.26</para></listitem> |
| 79 | <listitem><para>%d prints integers-only: 153</para></listitem> |
| 80 | <listitem><para>%c treats <emphasis>kval1</emphasis> as an ascii character code. </para></listitem> |
| 81 | </orderedlist> |
| 82 | </para> |
| 83 | |
| 84 | <para> |
| 85 | In addition to all the printf() codes, printks supports these useful character codes: |
| 86 | |
| 87 | <informaltable frame="all"> |
| 88 | <tgroup cols="2" colsep="1" rowsep="1"> |
| 89 | <thead> |
| 90 | <row> |
| 91 | <entry>printks Code</entry> |
| 92 | <entry>Character Code</entry> |
| 93 | </row> |
| 94 | </thead> |
| 95 | |
| 96 | <tbody> |
| 97 | <row> |
| 98 | <entry>\\r, \\R, %r, or %R</entry> |
| 99 | <entry>return character (\r)</entry> |
| 100 | </row> |
| 101 | |
| 102 | <row> |
| 103 | <entry>\\n, \\N, %n, %N</entry> |
| 104 | <entry>newline character (\n)</entry> |
| 105 | </row> |
| 106 | |
| 107 | <row> |
| 108 | <entry>\\t, \\T, %t, or %T</entry> |
| 109 | <entry>tab character (\t)</entry> |
| 110 | </row> |
| 111 | |
| 112 | <row> |
| 113 | <entry>%!</entry> |
| 114 | <entry>semicolon character (;) This was needed because a <quote>;</quote> is interpreted as an comment.</entry> |
| 115 | </row> |
| 116 | |
| 117 | <row> |
| 118 | <entry>^</entry> |
| 119 | <entry>escape character (0x1B)</entry> |
| 120 | </row> |
| 121 | |
| 122 | <row> |
| 123 | <entry>^ ^</entry> |
| 124 | <entry>caret character (^)</entry> |
| 125 | </row> |
| 126 | |
| 127 | <row> |
| 128 | <entry>˜</entry> |
| 129 | <entry>ESC[ (escape+[ is the escape sequence for ANSI consoles)</entry> |
| 130 | </row> |
| 131 | |
| 132 | <row> |
| 133 | <entry>˜˜</entry> |
| 134 | <entry>tilde (˜)</entry> |
| 135 | </row> |
| 136 | </tbody> |
| 137 | </tgroup> |
| 138 | </informaltable> |
| 139 | </para> |
| 140 | |
| 141 | <para> |
| 142 | For more information about printf() formatting, consult any C language documentation. |
| 143 | </para> |
| 144 | |
| 145 | <note> |
| 146 | <title>Note</title> |
| 147 | <para> |
| 148 | Prior to version 4.23, only the %f format code was supported. |
| 149 | </para> |
| 150 | </note> |
| 151 | </refsect1> |
| 152 | |
| 153 | <refsect1> |
| 154 | <title>Examples</title> |
| 155 | <para> |
| 156 | Here is an example of the printks opcode. It uses the file <ulink url="examples/printks.csd"><citetitle>printks.csd</citetitle></ulink>. |
| 157 | |
| 158 | <example> |
| 159 | <title>Example of the printks opcode.</title> |
| 160 | |
| 161 | |
| 162 | |
| 163 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 164 | <xi:include href="examples-xml/printks.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 165 | </example> |
| 166 | |
| 167 | Its output should include lines like this: |
| 168 | |
| 169 | <screen> |
| 170 | kup = 0.000000, kdown = 30.000000 |
| 171 | kup = 20.010843, kdown = 25.962524 |
| 172 | kup = 40.029991, kdown = 21.925049 |
| 173 | kup = 60.049141, kdown = 17.887573 |
| 174 | kup = 79.933266, kdown = 13.872493 |
| 175 | </screen> |
| 176 | </para> |
| 177 | </refsect1> |
| 178 | |
| 179 | <refsect1> |
| 180 | <title>See also</title> |
| 181 | <para><link linkend="SigioPdisplay"><citetitle>Printing and Display</citetitle></link></para> |
| 182 | </refsect1> |
| 183 | |
| 184 | <refsect1> |
| 185 | <title>Credits</title> |
| 186 | <para> |
| 187 | <simplelist> |
| 188 | <member>Author: Robin Whittle</member> |
| 189 | <member>Australia</member> |
| 190 | <member>May 1997</member> |
| 191 | </simplelist> |
| 192 | </para> |
| 193 | <para>Example written by &namekevin;.</para> |
| 194 | |
| 195 | <para>Thanks goes to &nameluis; for pointing out a mistake with the <emphasis>itime</emphasis> parameter.</para> |
| 196 | <para>Thanks to &namematt;, updated the documentation for version 4.23.</para> |
| 197 | </refsect1> |
| 198 | </refentry> |