summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorRobin <robin007bond@gmail.com>2015-05-20 13:26:36 +0200
committerwm4 <wm4@nowhere>2015-05-20 22:59:19 +0200
commit9bd3ae311f206ce5cac8f8471f75f6fc02206173 (patch)
treeea4938cd84d7872edfe7a53bce21fffe599588b5 /player/command.c
parent0e78424842513b14867ebc82e628da7c4eac8580 (diff)
downloadmpv-9bd3ae311f206ce5cac8f8471f75f6fc02206173.tar.bz2
mpv-9bd3ae311f206ce5cac8f8471f75f6fc02206173.tar.xz
command: refactor if/else statements to switch
The code checking for the type of seeking contained some if else statements. To improve readability, I decided to refactor those statements to a switch statement.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/player/command.c b/player/command.c
index 7d9049d89d..5862881d8e 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4114,24 +4114,32 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
if (!mpctx->num_sources)
return -1;
mark_seek(mpctx);
- if (abs == 2) { // Absolute seek to a timestamp in seconds
+ switch (abs) {
+ case 0: { // Relative seek
+ queue_seek(mpctx, MPSEEK_RELATIVE, v, precision, false);
+ set_osd_function(mpctx, (v > 0) ? OSD_FFW : OSD_REW);
+ break;
+ }
+ case 1: { // Absolute seek by percentage
+ double ratio = v / 100.0;
+ double cur_pos = get_current_pos_ratio(mpctx, false);
+ queue_seek(mpctx, MPSEEK_FACTOR, ratio, precision, false);
+ set_osd_function(mpctx, cur_pos < ratio ? OSD_FFW : OSD_REW);
+ break;
+ }
+ case 2: { // Absolute seek to a timestamp in seconds
queue_seek(mpctx, MPSEEK_ABSOLUTE, v, precision, false);
set_osd_function(mpctx,
v > get_current_time(mpctx) ? OSD_FFW : OSD_REW);
- } else if (abs == 3) { // Relative seeking by percentage
+ break;
+ }
+ case 3: { // Relative seek by percentage
queue_seek(mpctx, MPSEEK_FACTOR,
get_current_pos_ratio(mpctx, false) + v / 100.0,
precision, false);
set_osd_function(mpctx, v > 0 ? OSD_FFW : OSD_REW);
- } else if (abs) { // Absolute seek by percentage
- double ratio = v / 100.0;
- double cur_pos = get_current_pos_ratio(mpctx, false);
- queue_seek(mpctx, MPSEEK_FACTOR, ratio, precision, false);
- set_osd_function(mpctx, cur_pos < ratio ? OSD_FFW : OSD_REW);
- } else {
- queue_seek(mpctx, MPSEEK_RELATIVE, v, precision, false);
- set_osd_function(mpctx, (v > 0) ? OSD_FFW : OSD_REW);
- }
+ break;
+ }}
if (bar_osd)
mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR;
if (msg_or_nobar_osd)