<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Definition of Controls</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Writing an ALSA Driver" /><link rel="up" href="ch06.html" title="Chapter 6. Control Interface" /><link rel="prev" href="ch06.html" title="Chapter 6. Control Interface" /><link rel="next" href="ch06s03.html" title="Control Names" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Definition of Controls</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Control Interface</th><td width="20%" align="right"> <a accesskey="n" href="ch06s03.html">Next</a></td></tr></table><hr /></div><div class="section" title="Definition of Controls"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="control-interface-definition"></a>Definition of Controls</h2></div></div></div><p> To create a new control, you need to define the following three callbacks: <em class="structfield"><code>info</code></em>, <em class="structfield"><code>get</code></em> and <em class="structfield"><code>put</code></em>. Then, define a struct <span class="structname">snd_kcontrol_new</span> record, such as: </p><div class="example"><a id="id2948748"></a><p class="title"><b>Example 6.1. Definition of a Control</b></p><div class="example-contents"><pre class="programlisting"> static struct snd_kcontrol_new my_control __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Switch", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0xffff, .info = my_control_info, .get = my_control_get, .put = my_control_put }; </pre></div></div><p><br class="example-break" /> </p><p> Most likely the control is created via <code class="function">snd_ctl_new1()</code>, and in such a case, you can add the <em class="parameter"><code>__devinitdata</code></em> prefix to the definition as above. </p><p> The <em class="structfield"><code>iface</code></em> field specifies the control type, <code class="constant">SNDRV_CTL_ELEM_IFACE_XXX</code>, which is usually <code class="constant">MIXER</code>. Use <code class="constant">CARD</code> for global controls that are not logically part of the mixer. If the control is closely associated with some specific device on the sound card, use <code class="constant">HWDEP</code>, <code class="constant">PCM</code>, <code class="constant">RAWMIDI</code>, <code class="constant">TIMER</code>, or <code class="constant">SEQUENCER</code>, and specify the device number with the <em class="structfield"><code>device</code></em> and <em class="structfield"><code>subdevice</code></em> fields. </p><p> The <em class="structfield"><code>name</code></em> is the name identifier string. Since ALSA 0.9.x, the control name is very important, because its role is classified from its name. There are pre-defined standard control names. The details are described in the <a class="link" href="ch06s03.html" title="Control Names"><em class="citetitle"> Control Names</em></a> subsection. </p><p> The <em class="structfield"><code>index</code></em> field holds the index number of this control. If there are several different controls with the same name, they can be distinguished by the index number. This is the case when several codecs exist on the card. If the index is zero, you can omit the definition above. </p><p> The <em class="structfield"><code>access</code></em> field contains the access type of this control. Give the combination of bit masks, <code class="constant">SNDRV_CTL_ELEM_ACCESS_XXX</code>, there. The details will be explained in the <a class="link" href="ch06s04.html" title="Access Flags"><em class="citetitle"> Access Flags</em></a> subsection. </p><p> The <em class="structfield"><code>private_value</code></em> field contains an arbitrary long integer value for this record. When using the generic <em class="structfield"><code>info</code></em>, <em class="structfield"><code>get</code></em> and <em class="structfield"><code>put</code></em> callbacks, you can pass a value through this field. If several small numbers are necessary, you can combine them in bitwise. Or, it's possible to give a pointer (casted to unsigned long) of some record to this field, too. </p><p> The <em class="structfield"><code>tlv</code></em> field can be used to provide metadata about the control; see the <a class="link" href="ch06s08.html" title="Metadata"> <em class="citetitle">Metadata</em></a> subsection. </p><p> The other three are <a class="link" href="ch06s05.html" title="Callbacks"><em class="citetitle"> callback functions</em></a>. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. Control Interface </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Control Names</td></tr></table></div></body></html>