aboutsummaryrefslogtreecommitdiff
path: root/src/mixer.c
diff options
context:
space:
mode:
authorTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 21:39:53 -0800
committerTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 21:39:53 -0800
commit053a009cab9ad0e440e511a1546e9cba415565d7 (patch)
tree8c9ee73c50c8eaba24c87389e0eb7d1754f492c8 /src/mixer.c
parentf42051ce4de1a3b2655c2cab778338fe66ee9580 (diff)
parent6860acb720fcc5d67639b72aa349b16e1fc6acc6 (diff)
Merge branch 'develop'
This merges all the changes for the 1.1.0 release to the master branch.
Diffstat (limited to 'src/mixer.c')
-rw-r--r--src/mixer.c70
1 files changed, 55 insertions, 15 deletions
diff --git a/src/mixer.c b/src/mixer.c
index 0fe9c99..9e661c5 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -176,7 +176,7 @@ fail:
* @returns The name of the mixer's card.
* @ingroup libtinyalsa-mixer
*/
-const char *mixer_get_name(struct mixer *mixer)
+const char *mixer_get_name(const struct mixer *mixer)
{
return (const char *)mixer->card_info.name;
}
@@ -186,7 +186,7 @@ const char *mixer_get_name(struct mixer *mixer)
* @returns The number of mixer controls for the given mixer.
* @ingroup libtinyalsa-mixer
*/
-unsigned int mixer_get_num_ctls(struct mixer *mixer)
+unsigned int mixer_get_num_ctls(const struct mixer *mixer)
{
if (!mixer)
return 0;
@@ -194,7 +194,47 @@ unsigned int mixer_get_num_ctls(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.
+ * @param id The control's id in the given mixer.
+ * @returns A handle to the mixer control.
+ * @ingroup libtinyalsa-mixer
+ */
+const struct mixer_ctl *mixer_get_ctl_const(const struct mixer *mixer, unsigned int id)
+{
+ if (mixer && (id < mixer->count))
+ return mixer->ctl + id;
+
+ return NULL;
+}
+
/** Gets a mixer control handle, by the mixer control's id.
+ * For const access, see @ref mixer_get_ctl_const
* @param mixer An initialized mixer handle.
* @param id The control's id in the given mixer.
* @returns A handle to the mixer control.
@@ -263,7 +303,7 @@ void mixer_ctl_update(struct mixer_ctl *ctl)
* On error, UINT_MAX is returned instead.
* @ingroup libtinyalsa-mixer
*/
-unsigned int mixer_ctl_get_id(struct mixer_ctl *ctl)
+unsigned int mixer_ctl_get_id(const struct mixer_ctl *ctl)
{
if (!ctl)
return UINT_MAX;
@@ -280,7 +320,7 @@ unsigned int mixer_ctl_get_id(struct mixer_ctl *ctl)
* On error, NULL.
* @ingroup libtinyalsa-mixer
*/
-const char *mixer_ctl_get_name(struct mixer_ctl *ctl)
+const char *mixer_ctl_get_name(const struct mixer_ctl *ctl)
{
if (!ctl)
return NULL;
@@ -294,7 +334,7 @@ const char *mixer_ctl_get_name(struct mixer_ctl *ctl)
* On failure, it returns @ref MIXER_CTL_TYPE_UNKNOWN
* @ingroup libtinyalsa-mixer
*/
-enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl)
+enum mixer_ctl_type mixer_ctl_get_type(const struct mixer_ctl *ctl)
{
if (!ctl)
return MIXER_CTL_TYPE_UNKNOWN;
@@ -315,7 +355,7 @@ enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl)
* @returns On success, a string describing type of mixer control.
* @ingroup libtinyalsa-mixer
*/
-const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl)
+const char *mixer_ctl_get_type_string(const struct mixer_ctl *ctl)
{
if (!ctl)
return "";
@@ -336,7 +376,7 @@ const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl)
* @returns The number of values in the mixer control
* @ingroup libtinyalsa-mixer
*/
-unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl)
+unsigned int mixer_ctl_get_num_values(const struct mixer_ctl *ctl)
{
if (!ctl)
return 0;
@@ -344,7 +384,7 @@ unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl)
return ctl->info.count;
}
-static int percent_to_int(struct snd_ctl_elem_info *ei, int percent)
+static int percent_to_int(const struct snd_ctl_elem_info *ei, int percent)
{
if ((percent > 100) || (percent < 0)) {
return -EINVAL;
@@ -355,7 +395,7 @@ static int percent_to_int(struct snd_ctl_elem_info *ei, int percent)
return ei->value.integer.min + (range * percent) / 100;
}
-static int int_to_percent(struct snd_ctl_elem_info *ei, int value)
+static int int_to_percent(const struct snd_ctl_elem_info *ei, int value)
{
int range = (ei->value.integer.max - ei->value.integer.min);
@@ -372,7 +412,7 @@ static int int_to_percent(struct snd_ctl_elem_info *ei, int value)
* On failure, -EINVAL is returned.
* @ingroup libtinyalsa-mixer
*/
-int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id)
+int mixer_ctl_get_percent(const struct mixer_ctl *ctl, unsigned int id)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
return -EINVAL;
@@ -403,7 +443,7 @@ int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent)
* On failure, -EINVAL is returned.
* @ingroup libtinyalsa-mixer
*/
-int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
+int mixer_ctl_get_value(const struct mixer_ctl *ctl, unsigned int id)
{
struct snd_ctl_elem_value ev;
int ret;
@@ -449,7 +489,7 @@ int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
* On failure, non-zero.
* @ingroup libtinyalsa-mixer
*/
-int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
+int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count)
{
struct snd_ctl_elem_value ev;
int ret = 0;
@@ -634,7 +674,7 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
* On failure, -EINVAL.
* @ingroup libtinyalsa-mixer
*/
-int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
+int mixer_ctl_get_range_min(const struct mixer_ctl *ctl)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
return -EINVAL;
@@ -650,7 +690,7 @@ int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
* On failure, -EINVAL.
* @ingroup libtinyalsa-mixer
*/
-int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
+int mixer_ctl_get_range_max(const struct mixer_ctl *ctl)
{
if (!ctl || (ctl->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER))
return -EINVAL;
@@ -663,7 +703,7 @@ int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
* @returns The number of enumerated items in the control.
* @ingroup libtinyalsa-mixer
*/
-unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
+unsigned int mixer_ctl_get_num_enums(const struct mixer_ctl *ctl)
{
if (!ctl)
return 0;