aboutsummaryrefslogtreecommitdiff
path: root/src/mixer.c
diff options
context:
space:
mode:
authorTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 18:35:24 -0800
committerTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 18:35:24 -0800
commit94c7c83c01a1d00a5e36cc77bc1b71a8ebdcd1e9 (patch)
treeb75d400fb85322ee54892cff55cd9196f673bb5e /src/mixer.c
parent7dc7d83ed7305edacdd46a3f4bd9d711c5c4c4ff (diff)
Added function, mixer_get_num_ctls_by_name
This function is used to get the number of mixer controls by a given name. It was added for use with mixer_get_ctl_by_name_and_index so that client code can expect the last valid index to pass.
Diffstat (limited to 'src/mixer.c')
-rw-r--r--src/mixer.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mixer.c b/src/mixer.c
index 4bb1756..9e661c5 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -194,6 +194,30 @@ unsigned int mixer_get_num_ctls(const struct mixer *mixer)
return mixer->count;
}
+/** Gets the number of mixer controls, that go by a specified name, for a given mixer.
+ * @param mixer An initialized mixer handle.
+ * @param name The name of the mixer control
+ * @returns The number of mixer controls, specified by @p name, for the given mixer.
+ * @ingroup libtinyalsa-mixer
+ */
+unsigned int mixer_get_num_ctls_by_name(const struct mixer *mixer, const char *name)
+{
+ unsigned int n;
+ unsigned int count = 0;
+ struct mixer_ctl *ctl;
+
+ if (!mixer)
+ return 0;
+
+ ctl = mixer->ctl;
+
+ for (n = 0; n < mixer->count; n++)
+ if (!strcmp(name, (char*) ctl[n].info.id.name))
+ count++;
+
+ return count;
+}
+
/** Gets a mixer control handle, by the mixer control's id.
* For non-const access, see @ref mixer_get_ctl
* @param mixer An initialized mixer handle.