1<html><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.78.1"><link rel="home" href="index.html" title="Writing an ALSA Driver"><link rel="up" href="control-interface.html" title="Chapter 6. Control Interface"><link rel="prev" href="control-interface.html" title="Chapter 6. Control Interface"><link rel="next" href="control-interface-control-names.html" title="Control Names"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><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="control-interface.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Control Interface</th><td width="20%" align="right"> <a accesskey="n" href="control-interface-control-names.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="control-interface-definition"></a>Definition of Controls</h2></div></div></div><p> 2 To create a new control, you need to define the 3 following three 4 callbacks: <em class="structfield"><code>info</code></em>, 5 <em class="structfield"><code>get</code></em> and 6 <em class="structfield"><code>put</code></em>. Then, define a 7 struct <span class="structname">snd_kcontrol_new</span> record, such as: 8 9 </p><div class="example"><a name="idp1094164476"></a><p class="title"><b>Example 6.1. Definition of a Control</b></p><div class="example-contents"><pre class="programlisting"> 10 11 static struct snd_kcontrol_new my_control = { 12 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 13 .name = "PCM Playback Switch", 14 .index = 0, 15 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 16 .private_value = 0xffff, 17 .info = my_control_info, 18 .get = my_control_get, 19 .put = my_control_put 20 }; 21 22 </pre></div></div><p><br class="example-break"> 23 </p><p> 24 The <em class="structfield"><code>iface</code></em> field specifies the control 25 type, <code class="constant">SNDRV_CTL_ELEM_IFACE_XXX</code>, which 26 is usually <code class="constant">MIXER</code>. 27 Use <code class="constant">CARD</code> for global controls that are not 28 logically part of the mixer. 29 If the control is closely associated with some specific device on 30 the sound card, use <code class="constant">HWDEP</code>, 31 <code class="constant">PCM</code>, <code class="constant">RAWMIDI</code>, 32 <code class="constant">TIMER</code>, or <code class="constant">SEQUENCER</code>, and 33 specify the device number with the 34 <em class="structfield"><code>device</code></em> and 35 <em class="structfield"><code>subdevice</code></em> fields. 36 </p><p> 37 The <em class="structfield"><code>name</code></em> is the name identifier 38 string. Since ALSA 0.9.x, the control name is very important, 39 because its role is classified from its name. There are 40 pre-defined standard control names. The details are described in 41 the <a class="link" href="control-interface-control-names.html" title="Control Names"><em class="citetitle"> 42 Control Names</em></a> subsection. 43 </p><p> 44 The <em class="structfield"><code>index</code></em> field holds the index number 45 of this control. If there are several different controls with 46 the same name, they can be distinguished by the index 47 number. This is the case when 48 several codecs exist on the card. If the index is zero, you can 49 omit the definition above. 50 </p><p> 51 The <em class="structfield"><code>access</code></em> field contains the access 52 type of this control. Give the combination of bit masks, 53 <code class="constant">SNDRV_CTL_ELEM_ACCESS_XXX</code>, there. 54 The details will be explained in 55 the <a class="link" href="control-interface-access-flags.html" title="Access Flags"><em class="citetitle"> 56 Access Flags</em></a> subsection. 57 </p><p> 58 The <em class="structfield"><code>private_value</code></em> field contains 59 an arbitrary long integer value for this record. When using 60 the generic <em class="structfield"><code>info</code></em>, 61 <em class="structfield"><code>get</code></em> and 62 <em class="structfield"><code>put</code></em> callbacks, you can pass a value 63 through this field. If several small numbers are necessary, you can 64 combine them in bitwise. Or, it's possible to give a pointer 65 (casted to unsigned long) of some record to this field, too. 66 </p><p> 67 The <em class="structfield"><code>tlv</code></em> field can be used to provide 68 metadata about the control; see the 69 <a class="link" href="control-interface-tlv.html" title="Metadata"> 70 <em class="citetitle">Metadata</em></a> subsection. 71 </p><p> 72 The other three are 73 <a class="link" href="control-interface-callbacks.html" title="Callbacks"><em class="citetitle"> 74 callback functions</em></a>. 75 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="control-interface.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="control-interface.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="control-interface-control-names.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> 76