From 9bd3ae311f206ce5cac8f8471f75f6fc02206173 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 20 May 2015 13:26:36 +0200 Subject: 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. --- player/command.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'player') 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) -- cgit v1.2.3