aboutsummaryrefslogtreecommitdiff
path: root/src/mixer.c
diff options
context:
space:
mode:
authorTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 18:24:44 -0800
committerTaylor Holberton <taylorcholberton@gmail.com>2016-12-01 18:24:44 -0800
commit7dc7d83ed7305edacdd46a3f4bd9d711c5c4c4ff (patch)
tree72cce744d670cf7a6c10ef90d03aba47f2512250 /src/mixer.c
parentf3d6c67db4f5eea516d2d4fcbc2edd75f33d48a4 (diff)
parenta94295b6cf85fceb6b06db42b27c88131f1a18b0 (diff)
Merge branch 'const-correctness' into develop
This merge adds the changes made to the mixer API.
Diffstat (limited to 'src/mixer.c')
-rw-r--r--src/mixer.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/mixer.c b/src/mixer.c
index 0fe9c99..4bb1756 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;
@@ -195,6 +195,22 @@ unsigned int mixer_get_num_ctls(struct mixer *mixer)
}
/** 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 +279,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 +296,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 +310,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 +331,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 +352,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 +360,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 +371,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 +388,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 +419,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 +465,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 +650,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 +666,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 +679,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;