From 7f61f4984192a1d551f8a1ca1cf3d1197c5df226 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Fri, 22 Oct 2010 19:19:19 +1100 Subject: [PATCH] Add cheap count support to :playernext and :playerprev. --- melodactyl/NEWS | 1 + melodactyl/content/player.js | 38 ++++++++++++++++++++---------- melodactyl/locale/en-US/player.xml | 8 +++---- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/melodactyl/NEWS b/melodactyl/NEWS index a046e63a..2bbbde98 100755 --- a/melodactyl/NEWS +++ b/melodactyl/NEWS @@ -1,4 +1,5 @@ 0.1a1pre: + * :playerprev and :playernext and equivalent mappings now accept a count. * :displaypane arguments changed to "leftservice", "bottomservice", "bottomcontent" or "rightsidebar" * asciidoc is no longer required to build Melodactyl diff --git a/melodactyl/content/player.js b/melodactyl/content/player.js index df3bf825..51f83011 100644 --- a/melodactyl/content/player.js +++ b/melodactyl/content/player.js @@ -122,17 +122,25 @@ const Player = Module("player", { }, /** - * Plays the next media item in the current media view. + * Plays the *count*th next media item in the current media view. + * + * @param {number} count */ - next: function next() { - ["cmd_control_next", "cmd_find_current_track"].forEach(gSongbirdWindowController.doCommand); + next: function next(count) { + for (let i = 0; i < count; i++) + gSongbirdWindowController.doCommand("cmd_control_next"); + gSongbirdWindowController.doCommand("cmd_find_current_track"); }, /** - * Plays the previous media item in the current media view. + * Plays the *count*th previous media item in the current media view. + * + * @param {number} count */ - previous: function previous() { - ["cmd_control_previous", "cmd_find_current_track"].forEach(gSongbirdWindowController.doCommand); + previous: function previous(count) { + for (let i = 0; i < count; i++) + gSongbirdWindowController.doCommand("cmd_control_previous"); + gSongbirdWindowController.doCommand("cmd_find_current_track"); }, /** @@ -494,11 +502,13 @@ const Player = Module("player", { commands.add(["playern[ext]"], "Play next track", - function () { player.next(); }); + function (args) { player.next(Math.max(args.count, 1)); }, + { count: true }); commands.add(["playerpr[ev]"], "Play previous track", - function () { player.previous(); }); + function (args) { player.previous(Math.max(args.count, 1)); }, + { count: true }); commands.add(["players[top]"], "Stop track", @@ -671,23 +681,25 @@ const Player = Module("player", { mappings: function () { mappings.add([modes.PLAYER], ["x"], "Play track", - function () { player.play(); }); + function () { ex.playerplay(); }); mappings.add([modes.PLAYER], ["z"], "Previous track", - function () { player.previous(); }); + function (count) { ex.playerprev({ "#": count }); }, + { count: true }); mappings.add([modes.PLAYER], ["c"], "Pause/unpause track", - function () { player.togglePlayPause(); }); + function () { ex.playerpause(); }); mappings.add([modes.PLAYER], ["b"], "Next track", - function () { player.next(); }); + function (count) { ex.playernext({ "#": count }); }, + { count: true }); mappings.add([modes.PLAYER], ["v"], "Stop track", - function () { player.stop(); }); + function () { ex.playerstop(); }); mappings.add([modes.PLAYER], ["Q"], "Queue tracks by artist/album/track", diff --git a/melodactyl/locale/en-US/player.xml b/melodactyl/locale/en-US/player.xml index 7951276c..c3ff24ab 100644 --- a/melodactyl/locale/en-US/player.xml +++ b/melodactyl/locale/en-US/player.xml @@ -21,8 +21,8 @@ p_x :playerp :playerplay - :playerplay - x + :countplayerplay + countx

Play the current track. @@ -32,8 +32,8 @@ p_z :playerpr :playerprev - :playerprev - z + :countplayerprev + countz

Play the previous track.