From 467b422e1b015a7b8bd94a03d61aa2a6843464a9 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 18 Nov 2012 21:29:27 +0100 Subject: hotkeys for seeking --- plugins/hotkeys/hotkeys.c | 96 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c index c516385e..451f1d4c 100644 --- a/plugins/hotkeys/hotkeys.c +++ b/plugins/hotkeys/hotkeys.c @@ -606,14 +606,66 @@ action_play_random_cb (struct DB_plugin_action_s *action, int ctx) { } int -action_seek_forward_cb (struct DB_plugin_action_s *action, int ctx) { - deadbeef->playback_set_pos (deadbeef->playback_get_pos () + 5); +action_seek_5p_forward_cb (struct DB_plugin_action_s *action, int ctx) { + deadbeef->pl_lock (); + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (it) { + float dur = deadbeef->pl_get_item_duration (it); + if (dur > 0) { + float pos = deadbeef->streamer_get_playpos (); + deadbeef->sendmessage (DB_EV_SEEK, 0, (pos + dur * 0.05f) * 1000, 0); + } + deadbeef->pl_item_unref (it); + } + deadbeef->pl_unlock (); + return 0; +} + +int +action_seek_5p_backward_cb (struct DB_plugin_action_s *action, int ctx) { + deadbeef->pl_lock (); + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (it) { + float dur = deadbeef->pl_get_item_duration (it); + if (dur > 0) { + float pos = deadbeef->streamer_get_playpos (); + deadbeef->sendmessage (DB_EV_SEEK, 0, (pos - dur * 0.05f) * 1000, 0); + } + deadbeef->pl_item_unref (it); + } + deadbeef->pl_unlock (); + return 0; +} + +int +action_seek_1p_forward_cb (struct DB_plugin_action_s *action, int ctx) { + deadbeef->pl_lock (); + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (it) { + float dur = deadbeef->pl_get_item_duration (it); + if (dur > 0) { + float pos = deadbeef->streamer_get_playpos (); + deadbeef->sendmessage (DB_EV_SEEK, 0, (pos + dur * 0.01f) * 1000, 0); + } + deadbeef->pl_item_unref (it); + } + deadbeef->pl_unlock (); return 0; } int -action_seek_backward_cb (struct DB_plugin_action_s *action, int ctx) { - deadbeef->playback_set_pos (deadbeef->playback_get_pos () - 5); +action_seek_1p_backward_cb (struct DB_plugin_action_s *action, int ctx) { + deadbeef->pl_lock (); + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (it) { + float dur = deadbeef->pl_get_item_duration (it); + if (dur > 0) { + float pos = deadbeef->streamer_get_playpos (); + deadbeef->sendmessage (DB_EV_SEEK, 0, (pos - dur * 0.01f) * 1000, 0); + } + deadbeef->pl_item_unref (it); + } + deadbeef->pl_unlock (); return 0; } @@ -879,20 +931,36 @@ static DB_plugin_action_t action_play_random = { .next = &action_play_pause }; -static DB_plugin_action_t action_seek_forward = { - .title = "Playback/Seek Forward", - .name = "seek_fwd", +static DB_plugin_action_t action_seek_1p_forward = { + .title = "Playback/Seek 1% forward", + .name = "seek_1p_fwd", .flags = DB_ACTION_COMMON, - .callback = action_seek_forward_cb, + .callback = action_seek_1p_forward_cb, .next = &action_play_random }; -static DB_plugin_action_t action_seek_backward = { - .title = "Playback/Seek Backward", - .name = "seek_back", +static DB_plugin_action_t action_seek_1p_backward = { + .title = "Playback/Seek 1% backward", + .name = "seek_1p_back", + .flags = DB_ACTION_COMMON, + .callback = action_seek_1p_backward_cb, + .next = &action_seek_1p_forward +}; + +static DB_plugin_action_t action_seek_5p_forward = { + .title = "Playback/Seek 5% forward", + .name = "seek_5p_fwd", + .flags = DB_ACTION_COMMON, + .callback = action_seek_5p_forward_cb, + .next = &action_seek_1p_backward +}; + +static DB_plugin_action_t action_seek_5p_backward = { + .title = "Playback/Seek 5% backward", + .name = "seek_5p_back", .flags = DB_ACTION_COMMON, - .callback = action_seek_backward_cb, - .next = &action_seek_forward + .callback = action_seek_5p_backward_cb, + .next = &action_seek_5p_forward }; static DB_plugin_action_t action_volume_up = { @@ -900,7 +968,7 @@ static DB_plugin_action_t action_volume_up = { .name = "volume_up", .flags = DB_ACTION_COMMON, .callback = action_volume_up_cb, - .next = &action_seek_backward + .next = &action_seek_5p_backward }; static DB_plugin_action_t action_volume_down = { -- cgit v1.2.3