<?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>Constructor</title><meta name="generator" content="DocBook XSL Stylesheets V1.76.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-callbacks.html" title="Callbacks" /><link rel="next" href="control-interface-change-notification.html" title="Change Notification" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Constructor</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="control-interface-callbacks.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-change-notification.html">Next</a></td></tr></table><hr /></div><div class="section" title="Constructor"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="control-interface-constructor"></a>Constructor</h2></div></div></div><p> When everything is ready, finally we can create a new control. To create a control, there are two functions to be called, <code class="function">snd_ctl_new1()</code> and <code class="function">snd_ctl_add()</code>. </p><p> In the simplest way, you can do like this: </p><div class="informalexample"><pre class="programlisting"> err = snd_ctl_add(card, snd_ctl_new1(&my_control, chip)); if (err < 0) return err; </pre></div><p> where <em class="parameter"><code>my_control</code></em> is the struct <span class="structname">snd_kcontrol_new</span> object defined above, and chip is the object pointer to be passed to kcontrol->private_data which can be referred to in callbacks. </p><p> <code class="function">snd_ctl_new1()</code> allocates a new <span class="structname">snd_kcontrol</span> instance (that's why the definition of <em class="parameter"><code>my_control</code></em> can be with the <em class="parameter"><code>__devinitdata</code></em> prefix), and <code class="function">snd_ctl_add</code> assigns the given control component to the card. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="control-interface-callbacks.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-change-notification.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Callbacks </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Change Notification</td></tr></table></div></body></html>