command: use the step size for "add volume" commands

The step argument for "add volume <step>" was ignored until now. Fix it.

There is one problem: by defualt, "add volume" should use the value set
with --volstep. This value is 3 by default. Since the default volue for
the step argument is always 1 (and we don't really want to make the
generic code more complicated by introducing custom step sizes), we
simply multiply the step argument with --volstep to keep it compatible.

The --volstep option should probably be just removed in the future.
This commit is contained in:
wm4 2014-02-27 01:07:46 +01:00
parent b4fb71634c
commit 14607f27ef
3 changed files with 4 additions and 18 deletions

View File

@ -172,21 +172,11 @@ bool mixer_getmute(struct mixer *mixer)
return mixer->muted;
}
static void addvolume(struct mixer *mixer, float d)
void mixer_addvolume(struct mixer *mixer, float step)
{
float vol_l, vol_r;
mixer_getvolume(mixer, &vol_l, &vol_r);
mixer_setvolume(mixer, vol_l + d, vol_r + d);
}
void mixer_incvolume(struct mixer *mixer)
{
addvolume(mixer, mixer->opts->volstep);
}
void mixer_decvolume(struct mixer *mixer)
{
addvolume(mixer, -mixer->opts->volstep);
mixer_setvolume(mixer, vol_l + step, vol_r + step);
}
void mixer_getbalance(struct mixer *mixer, float *val)

View File

@ -39,8 +39,7 @@ void mixer_uninit_audio(struct mixer *mixer);
bool mixer_audio_initialized(struct mixer *mixer);
void mixer_getvolume(struct mixer *mixer, float *l, float *r);
void mixer_setvolume(struct mixer *mixer, float l, float r);
void mixer_incvolume(struct mixer *mixer);
void mixer_decvolume(struct mixer *mixer);
void mixer_addvolume(struct mixer *mixer, float step);
void mixer_getbothvolume(struct mixer *mixer, float *b);
void mixer_setmute(struct mixer *mixer, bool mute);
bool mixer_getmute(struct mixer *mixer);

View File

@ -931,10 +931,7 @@ static int mp_property_volume(m_option_t *prop, int action, void *arg,
if (!mixer_audio_initialized(mpctx->mixer))
return M_PROPERTY_ERROR;
struct m_property_switch_arg *sarg = arg;
if (sarg->inc <= 0)
mixer_decvolume(mpctx->mixer);
else
mixer_incvolume(mpctx->mixer);
mixer_addvolume(mpctx->mixer, mpctx->opts->volstep * sarg->inc);
return M_PROPERTY_OK;
}
}