summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bc7ff93)
raw | patch | inline | side by side (parent: bc7ff93)
author | Kalle Wallin <kaw@linux.se> | |
Wed, 21 Apr 2004 08:34:30 +0000 (08:34 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Wed, 21 Apr 2004 08:34:30 +0000 (08:34 +0000) |
screen.c | patch | blob | history |
diff --git a/screen.c b/screen.c
index 940f98b9da5802f2556b52037e385e563c61567c..ea5cc36253e83a290bd281d99b2f74506c24aec5 100644 (file)
--- a/screen.c
+++ b/screen.c
#include "screen_search.h"
#include "screen_utils.h"
-#ifdef ENABLE_KEYDEF_SCREEN
-extern screen_functions_t *get_screen_keydef(void);
-#endif
+#define ENABLE_MP_FLAGS_DISPLAY
+#undef ENABLE_STATUS_LINE_CLOCK
+
+#define DEFAULT_CROSSFADE_TIME 10
#define STATUS_MESSAGE_TIMEOUT 3
#define STATUS_LINE_MAX_SIZE 512
+#ifdef ENABLE_KEYDEF_SCREEN
+extern screen_functions_t *get_screen_keydef(void);
+#endif
+
static screen_t *screen = NULL;
static screen_functions_t *mode_fn = NULL;
}
static void
-paint_top_window(char *header, int volume, int clear)
+paint_top_window(char *header, mpd_client_t *c, int clear)
{
static int prev_volume = -1;
static int prev_header_len = -1;
wclrtoeol(w);
}
- if(prev_volume!=volume || clear)
+ if(prev_volume!=c->status->volume || clear)
{
char buf[12];
wattroff(w, A_BOLD);
waddstr(w, ":Browse");
}
- if( volume==MPD_STATUS_NO_VOLUME )
+ if( c->status->volume==MPD_STATUS_NO_VOLUME )
{
snprintf(buf, 12, "Volume n/a ");
}
else
{
- snprintf(buf, 12, "Volume %3d%%", volume);
+ snprintf(buf, 12, "Volume %3d%%", c->status->volume);
}
mvwaddstr(w, 0, screen->top_window.cols-12, buf);
-#if 1
- if( options.enable_colors )
- wattron(w, LINE_COLORS);
- mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
- if( options.enable_colors )
- wattroff(w, LINE_COLORS);
-#else
if( options.enable_colors )
wattron(w, LINE_COLORS);
+#ifdef ENABLE_MP_FLAGS_DISPLAY
+ {
+ char buf[4];
+
+ buf[0] = 0;
+ if( c->status->repeat )
+ strcat(buf, "r");
+ if( c->status->random )
+ strcat(buf, "z");
+ if( c->status->crossfade )
+ strcat(buf, "x");
+
+ mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
+ if( buf[0] )
+ {
+ wmove(w,1,screen->top_window.cols-strlen(buf)-3);
+ waddch(w, '[');
+ wattron(w, A_BOLD);
+ waddstr(w, buf);
+ wattroff(w, A_BOLD);
+ waddch(w, ']');
+ }
+ }
+#else
mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
- wmove(w,1,screen->top_window.cols-6);
- waddstr(w, "[rzx]");
-
- if( options.enable_colors )
- wattroff(w, LINE_COLORS);
-
#endif
wnoutrefresh(w);
{
double p;
int width;
+ int elapsedTime = c->status->elapsedTime;
if( c->status==NULL || IS_STOPPED(c->status->state) )
{
return;
}
- p = ((double) c->status->elapsedTime) / ((double) c->status->totalTime);
+ if( c->seek_song_id == c->song_id )
+ elapsedTime = c->seek_target_time;
+
+ p = ((double) elapsedTime) / ((double) c->status->totalTime);
width = (int) (p * (double) screen->progress_window.cols);
mvwhline(screen->progress_window.w,
mvwaddstr(w, 0, x, screen->buf);
}
-#if 0
+#ifdef ENABLE_STATUS_LINE_CLOCK
else if( c->status->state == MPD_STATUS_STATE_STOP )
{
time_t timep;
- x = screen->status_window.cols - strlen(screen->buf);
-
+
+ /* Note: setlocale(LC_TIME,"") should be used first */
time(&timep);
- //strftime(screen->buf, screen->buf_size, "%X ", localtime(&timep));
- strftime(screen->buf, screen->buf_size, "%R ", localtime(&timep));
+ strftime(screen->buf, screen->buf_size, "%X ", localtime(&timep));
+ x = screen->status_window.cols - strlen(screen->buf) ;
mvwaddstr(w, 0, x, screen->buf);
}
#endif
screen->buf_size = screen->cols;
screen->findbuf = NULL;
screen->painted = 0;
+ screen->start_timestamp = time(NULL);
screen->input_timestamp = time(NULL);
screen->last_cmd = CMD_NONE;
{
/* paint the title/header window */
if( mode_fn && mode_fn->get_title )
- paint_top_window(mode_fn->get_title(), c->status->volume, 1);
+ paint_top_window(mode_fn->get_title(), c, 1);
else
- paint_top_window("", c->status->volume, 1);
+ paint_top_window("", c, 1);
/* paint the main window */
if( mode_fn && mode_fn->paint )
static int repeat = -1;
static int random = -1;
static int crossfade = -1;
+ static int welcome = 1;
list_window_t *lw = NULL;
if( !screen->painted )
crossfade = c->status->crossfade;
/* update title/header window */
- if( screen->last_cmd==CMD_NONE &&
- time(NULL)-screen->input_timestamp <= SCREEN_WELCOME_TIME)
- paint_top_window("", c->status->volume, 0);
+ if( welcome && screen->last_cmd==CMD_NONE &&
+ time(NULL)-screen->start_timestamp <= SCREEN_WELCOME_TIME)
+ paint_top_window("", c, 0);
else if( mode_fn && mode_fn->get_title )
- paint_top_window(mode_fn->get_title(), c->status->volume, 0);
+ {
+ paint_top_window(mode_fn->get_title(), c, 0);
+ welcome = 0;
+ }
else
- paint_top_window("", c->status->volume, 0);
+ paint_top_window("", c, 0);
/* update the main window */
if( mode_fn && mode_fn->paint )
doupdate();
}
+void
+screen_idle(mpd_client_t *c)
+{
+ if( c->seek_song_id == c->song_id &&
+ (screen->last_cmd == CMD_SEEK_FORWARD ||
+ screen->last_cmd == CMD_SEEK_BACKWARD) )
+ {
+ mpd_sendSeekCommand(c->connection,
+ c->seek_song_id,
+ c->seek_target_time);
+ mpd_finishCommand(c->connection);
+ }
+
+ screen->last_cmd = CMD_NONE;
+ c->seek_song_id = -1;
+}
+
void
screen_cmd(mpd_client_t *c, command_t cmd)
{
mpd_sendStopCommand(c->connection);
mpd_finishCommand(c->connection);
break;
+ case CMD_SEEK_FORWARD:
+ if( !IS_STOPPED(c->status->state) )
+ {
+ if( c->seek_song_id != c->song_id )
+ {
+ c->seek_song_id = c->song_id;
+ c->seek_target_time = c->status->elapsedTime;
+ }
+ c->seek_target_time++;
+ if( c->seek_target_time < c->status->totalTime )
+ break;
+ c->seek_target_time=0;
+ }
+ /* fall through... */
case CMD_TRACK_NEXT:
- if( IS_PLAYING(c->status->state) )
+ if( !IS_STOPPED(c->status->state) )
{
mpd_sendNextCommand(c->connection);
mpd_finishCommand(c->connection);
}
break;
+ case CMD_SEEK_BACKWARD:
+ if( !IS_STOPPED(c->status->state) )
+ {
+ if( c->seek_song_id != c->song_id )
+ {
+ c->seek_song_id = c->song_id;
+ c->seek_target_time = c->status->elapsedTime;
+ }
+ c->seek_target_time--;
+ if( c->seek_target_time < 0 )
+ c->seek_target_time=0;
+ }
+ break;
case CMD_TRACK_PREVIOUS:
- if( IS_PLAYING(c->status->state) )
+ if( !IS_STOPPED(c->status->state) )
{
mpd_sendPrevCommand(c->connection);
mpd_finishCommand(c->connection);
}
- break;
+ break;
case CMD_SHUFFLE:
mpd_sendShuffleCommand(c->connection);
mpd_finishCommand(c->connection);
mpd_sendRandomCommand(c->connection, n);
mpd_finishCommand(c->connection);
break;
+ case CMD_CROSSFADE:
+ if( c->status->crossfade )
+ n = 0;
+ else
+ n = DEFAULT_CROSSFADE_TIME;
+ mpd_sendCrossfadeCommand(c->connection, n);
+ mpd_finishCommand(c->connection);
+ break;
case CMD_VOLUME_UP:
if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
{