summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e87293c)
raw | patch | inline | side by side (parent: e87293c)
author | Max Kellermann <max@duempel.org> | |
Mon, 28 Sep 2009 15:47:45 +0000 (17:47 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 28 Sep 2009 15:47:45 +0000 (17:47 +0200) |
Makefile.am | patch | blob | history | |
src/player_command.c | [new file with mode: 0644] | patch | blob |
src/player_command.h | [new file with mode: 0644] | patch | blob |
src/screen.c | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index b5dccf880530fd22d4405836ee38a3ef5c1d6acb..a39d435dfaa7bcc6e77a64eeff159f16c5071b8d 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
src/conf.h \
src/command.h \
src/ncu.h \
+ src/player_command.h \
src/screen.h \
src/screen_list.h \
src/screen_play.h \
src/options.c \
src/command.c \
src/ncu.c \
+ src/player_command.c \
src/screen.c \
src/screen_list.c \
src/screen_utils.c \
diff --git a/src/player_command.c b/src/player_command.c
--- /dev/null
+++ b/src/player_command.c
@@ -0,0 +1,133 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "player_command.h"
+#include "mpdclient.h"
+#include "options.h"
+#include "screen.h"
+#include "i18n.h"
+
+#define IS_PLAYING(s) (s==MPD_STATE_PLAY)
+#define IS_PAUSED(s) (s==MPD_STATE_PAUSE)
+#define IS_STOPPED(s) (!(IS_PLAYING(s) | IS_PAUSED(s)))
+
+int seek_id = -1;
+int seek_target_time = 0;
+
+int
+handle_player_command(struct mpdclient *c, command_t cmd)
+{
+ if (c->connection == NULL || c->status == NULL)
+ return 0;
+
+ switch(cmd) {
+ /*
+ case CMD_PLAY:
+ mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
+ break;
+ */
+ case CMD_PAUSE:
+ mpdclient_cmd_pause(c, !IS_PAUSED(mpd_status_get_state(c->status)));
+ break;
+ case CMD_STOP:
+ mpdclient_cmd_stop(c);
+ break;
+ case CMD_CROP:
+ mpdclient_cmd_crop(c);
+ break;
+ case CMD_SEEK_FORWARD:
+ if (!IS_STOPPED(mpd_status_get_state(c->status))) {
+ if (c->song != NULL &&
+ seek_id != (int)mpd_song_get_id(c->song)) {
+ seek_id = mpd_song_get_id(c->song);
+ seek_target_time = mpd_status_get_elapsed_time(c->status);
+ }
+ seek_target_time+=options.seek_time;
+ if (seek_target_time < (int)mpd_status_get_total_time(c->status))
+ break;
+ seek_target_time = mpd_status_get_total_time(c->status);
+ /* seek_target_time=0; */
+ }
+ break;
+ /* fall through... */
+ case CMD_TRACK_NEXT:
+ if (!IS_STOPPED(mpd_status_get_state(c->status)))
+ mpdclient_cmd_next(c);
+ break;
+ case CMD_SEEK_BACKWARD:
+ if (!IS_STOPPED(mpd_status_get_state(c->status))) {
+ if (seek_id != (int)mpd_song_get_id(c->song)) {
+ seek_id = mpd_song_get_id(c->song);
+ seek_target_time = mpd_status_get_elapsed_time(c->status);
+ }
+ seek_target_time-=options.seek_time;
+ if (seek_target_time < 0)
+ seek_target_time=0;
+ }
+ break;
+ case CMD_TRACK_PREVIOUS:
+ if (!IS_STOPPED(mpd_status_get_state(c->status)))
+ mpdclient_cmd_prev(c);
+ break;
+ case CMD_SHUFFLE:
+ if (mpdclient_cmd_shuffle(c) == 0)
+ screen_status_message(_("Shuffled playlist"));
+ break;
+ case CMD_CLEAR:
+ if (mpdclient_cmd_clear(c) == 0)
+ screen_status_message(_("Cleared playlist"));
+ break;
+ case CMD_REPEAT:
+ mpdclient_cmd_repeat(c, !mpd_status_get_repeat(c->status));
+ break;
+ case CMD_RANDOM:
+ mpdclient_cmd_random(c, !mpd_status_get_random(c->status));
+ break;
+ case CMD_SINGLE:
+ mpdclient_cmd_single(c, !mpd_status_get_single(c->status));
+ break;
+ case CMD_CONSUME:
+ mpdclient_cmd_consume(c, !mpd_status_get_consume(c->status));
+ break;
+ case CMD_CROSSFADE:
+ if (mpd_status_get_crossfade(c->status))
+ mpdclient_cmd_crossfade(c, 0);
+ else
+ mpdclient_cmd_crossfade(c, options.crossfade_time);
+ break;
+ case CMD_DB_UPDATE:
+ if (!mpd_status_get_update_id(c->status)) {
+ if( mpdclient_cmd_db_update(c,NULL)==0 )
+ screen_status_printf(_("Database update started"));
+ } else
+ screen_status_printf(_("Database update running..."));
+ break;
+ case CMD_VOLUME_UP:
+ mpdclient_cmd_volume_up(c);
+ break;
+ case CMD_VOLUME_DOWN:
+ mpdclient_cmd_volume_down(c);
+ break;
+
+ default:
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/src/player_command.h b/src/player_command.h
--- /dev/null
+++ b/src/player_command.h
@@ -0,0 +1,33 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NCMPC_PLAYER_COMMAND_H
+#define NCMPC_PLAYER_COMMAND_H
+
+#include "command.h"
+
+struct mpdclient;
+
+extern int seek_id;
+extern int seek_target_time;
+
+int
+handle_player_command(struct mpdclient *c, command_t cmd);
+
+#endif
diff --git a/src/screen.c b/src/screen.c
index 1e6d87b4e790153465a78e2707dd77d8092e8ef1..0545bd079c4b8cb2f11595ae397ce5e58e2e669c 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
#include "options.h"
#include "colors.h"
#include "strfsong.h"
+#include "player_command.h"
#ifndef NCMPC_MINI
#include "hscroll.h"
struct screen screen;
static const struct screen_functions *mode_fn = &screen_playlist;
static const struct screen_functions *mode_fn_prev = &screen_playlist;
-static int seek_id = -1;
-static int seek_target_time = 0;
gboolean
screen_is_visible(const struct screen_functions *sf)
}
#endif
-static int
-screen_client_cmd(struct mpdclient *c, command_t cmd)
-{
- if (c->connection == NULL || c->status == NULL)
- return 0;
-
- switch(cmd) {
- /*
- case CMD_PLAY:
- mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
- break;
- */
- case CMD_PAUSE:
- mpdclient_cmd_pause(c, !IS_PAUSED(mpd_status_get_state(c->status)));
- break;
- case CMD_STOP:
- mpdclient_cmd_stop(c);
- break;
- case CMD_CROP:
- mpdclient_cmd_crop(c);
- break;
- case CMD_SEEK_FORWARD:
- if (!IS_STOPPED(mpd_status_get_state(c->status))) {
- if (c->song != NULL &&
- seek_id != (int)mpd_song_get_id(c->song)) {
- seek_id = mpd_song_get_id(c->song);
- seek_target_time = mpd_status_get_elapsed_time(c->status);
- }
- seek_target_time+=options.seek_time;
- if (seek_target_time < (int)mpd_status_get_total_time(c->status))
- break;
- seek_target_time = mpd_status_get_total_time(c->status);
- /* seek_target_time=0; */
- }
- break;
- /* fall through... */
- case CMD_TRACK_NEXT:
- if (!IS_STOPPED(mpd_status_get_state(c->status)))
- mpdclient_cmd_next(c);
- break;
- case CMD_SEEK_BACKWARD:
- if (!IS_STOPPED(mpd_status_get_state(c->status))) {
- if (seek_id != (int)mpd_song_get_id(c->song)) {
- seek_id = mpd_song_get_id(c->song);
- seek_target_time = mpd_status_get_elapsed_time(c->status);
- }
- seek_target_time-=options.seek_time;
- if (seek_target_time < 0)
- seek_target_time=0;
- }
- break;
- case CMD_TRACK_PREVIOUS:
- if (!IS_STOPPED(mpd_status_get_state(c->status)))
- mpdclient_cmd_prev(c);
- break;
- case CMD_SHUFFLE:
- if (mpdclient_cmd_shuffle(c) == 0)
- screen_status_message(_("Shuffled playlist"));
- break;
- case CMD_CLEAR:
- if (mpdclient_cmd_clear(c) == 0)
- screen_status_message(_("Cleared playlist"));
- break;
- case CMD_REPEAT:
- mpdclient_cmd_repeat(c, !mpd_status_get_repeat(c->status));
- break;
- case CMD_RANDOM:
- mpdclient_cmd_random(c, !mpd_status_get_random(c->status));
- break;
- case CMD_SINGLE:
- mpdclient_cmd_single(c, !mpd_status_get_single(c->status));
- break;
- case CMD_CONSUME:
- mpdclient_cmd_consume(c, !mpd_status_get_consume(c->status));
- break;
- case CMD_CROSSFADE:
- if (mpd_status_get_crossfade(c->status))
- mpdclient_cmd_crossfade(c, 0);
- else
- mpdclient_cmd_crossfade(c, options.crossfade_time);
- break;
- case CMD_DB_UPDATE:
- if (!mpd_status_get_update_id(c->status)) {
- if( mpdclient_cmd_db_update(c,NULL)==0 )
- screen_status_printf(_("Database update started"));
- } else
- screen_status_printf(_("Database update running..."));
- break;
- case CMD_VOLUME_UP:
- mpdclient_cmd_volume_up(c);
- break;
- case CMD_VOLUME_DOWN:
- mpdclient_cmd_volume_down(c);
- break;
-
- default:
- return 0;
- }
-
- return 1;
-}
-
void
screen_cmd(struct mpdclient *c, command_t cmd)
{
if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
return;
- if (screen_client_cmd(c, cmd))
+ if (handle_player_command(c, cmd))
return;
switch(cmd) {