Code

Added support for (auto) center/focus playlists.
authorKalle Wallin <kaw@linux.se>
Mon, 5 Apr 2004 08:56:50 +0000 (08:56 +0000)
committerKalle Wallin <kaw@linux.se>
Mon, 5 Apr 2004 08:56:50 +0000 (08:56 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@604 09075e82-0dd4-0310-85a5-a0d7c8717e4f

command.c
command.h
conf.c
doc/ncmpcrc.sample
screen.c
screen_help.c
screen_play.c

index e165aa466b9c09297a104ea91a09231a24ecf2c0..f3e129f043a9a0b1b289475c7276fbcdae6d1384 100644 (file)
--- a/command.c
+++ b/command.c
@@ -51,7 +51,8 @@ static command_definition_t cmds[] =
   { { '+', RGHT,  0 }, CMD_VOLUME_UP, "Increase volume" },
   { { '-', LEFT,  0 }, CMD_VOLUME_DOWN, "Decrease volume" },
 
-  { { 'w',   0,   0 }, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" },
+  { { 'w',   0,   0 }, CMD_TOGGLE_FIND_WRAP,  "Toggle find mode" },
+  { { 'U',   0,   0 }, CMD_TOGGLE_AUTOCENTER, "Toggle auto center mode" },
 
   { { ' ',   0,   0 }, CMD_SELECT, "Select/deselect song in playlist" },
   { { DEL,  'd',  0 }, CMD_DELETE, "Delete song from playlist" },
index a7e08555b6cc0f35867536f45e806521f8b61e70..ba8de80c98059cc2086b67532999454efc1bf077 100644 (file)
--- a/command.h
+++ b/command.h
@@ -17,6 +17,7 @@ typedef enum
   CMD_VOLUME_DOWN,
   CMD_SAVE_PLAYLIST,
   CMD_TOGGLE_FIND_WRAP,
+  CMD_TOGGLE_AUTOCENTER,
   CMD_LIST_PREVIOUS,
   CMD_LIST_NEXT,
   CMD_LIST_FIRST,
diff --git a/conf.c b/conf.c
index 5969c85baf806949cd896196376900134a51b897..6def7b638388863bed664b181a87227706ad3c2a 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -28,6 +28,9 @@
 
 /* configuration field names */
 #define CONF_ENABLE_COLORS           "enable_colors"
+#define CONF_AUTO_CENTER             "auto_center"
+
+/* configuration field names - colors */
 #define CONF_COLOR_BACKGROUND        "background_color"
 #define CONF_COLOR_TITLE             "title_color"
 #define CONF_COLOR_LINE              "line_color"
@@ -65,24 +68,6 @@ str2color(char *str)
     return COLOR_CYAN;
   else if( !strcasecmp(str,"white") )
     return COLOR_WHITE;
-#if 0
-   else if( !strcasecmp(str,"grey") ) 
-     return COLOR_BLACK | A_BOLD;
-  else if( !strcasecmp(str,"brightred") )
-    return COLOR_RED | A_BOLD;
-  else if( !strcasecmp(str,"brightgreen") )
-    return COLOR_GREEN | A_BOLD;
-  else if( !strcasecmp(str,"brightyellow") )
-    return COLOR_YELLOW | A_BOLD;
-  else if( !strcasecmp(str,"brightblue") )
-    return COLOR_BLUE | A_BOLD;
-  else if( !strcasecmp(str,"brightmagenta") )
-    return COLOR_MAGENTA | A_BOLD;
-  else if( !strcasecmp(str,"brightcyan") )
-    return COLOR_CYAN | A_BOLD;
-  else if( !strcasecmp(str,"brightwhite") )
-    return COLOR_WHITE | A_BOLD;
-#endif
   fprintf(stderr,"Warning: unknown color %s\n", str);
   return -1;
 }
@@ -181,6 +166,12 @@ read_rc_file(char *filename, options_t *options)
                  options->enable_colors = str2bool(value);
                  match_found = 1;
                }
+             /* auto center */
+             else if( !strcasecmp(CONF_AUTO_CENTER, name) )
+               {
+                 options->auto_center = str2bool(value);
+                 match_found = 1;
+               }
              /* background color */
              else if( !strcasecmp(CONF_COLOR_BACKGROUND, name) )
                {
index 98d34c69958ad7df3896087af87c004eec6e1c8f..bebae08171c416e6828b3ab32a152fe55eb89121 100644 (file)
@@ -1,21 +1,23 @@
-#
-# Configuration file for ncmpc (~/.ncmpcrc)
-# 
+##
+## Configuration file for ncmpc (~/.ncmpcrc)
+## 
 
+## auto center (center the playing track in the playlist)
+#auto_center = no
 
-#
-# Color configuration
-#
-# colors: black,red,green,yellow,blue,magenta,cyan,white 
-#
+##
+## Color configuration
+##
+## colors: black,red,green,yellow,blue,magenta,cyan,white 
+##
 
-# enable/disable colors
-enable_colors = yes
+## enable/disable colors
+#enable_colors = yes
 
-# background color
+## background color
 #background_color = blue
 
-# text colors
+## text colors
 #title_color    = white
 #line_color     = green
 #list_color     = yellow
@@ -24,16 +26,16 @@ enable_colors = yes
 #alert_color    = yellow
 
 
-#
-# Key bindings - NOT IMPLEMENTED
-#
+##
+## Key bindings - NOT IMPLEMENTED
+##
 # key_up = 13
 
 
-#
-# Key names - NOT IMPLEMENTED
-#
+##
+## Key names - NOT IMPLEMENTED
+##
 #key_name  13  Enter
-#
+
 
 
index aabc6f0334b5b53e3a2fd46cef6730f832ec9e20..efd93d1fec9e76f903b3229626bb3aa9a9c700f7 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -79,7 +79,8 @@ paint_top_window(char *header, int volume, int clear)
 
   if(clear)
     {
-      wclear(w);
+      wmove(w, 0, 0);
+      wclrtoeol(w);
     }
 
   if(prev_volume!=volume || clear)
@@ -99,11 +100,24 @@ paint_top_window(char *header, int volume, int clear)
        }
       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);
+
+      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);
     }
@@ -115,7 +129,7 @@ paint_progress_window(mpd_client_t *c)
   double p;
   int width;
 
-  if( c->status==NULL || !IS_PLAYING(c->status->state) )
+  if( c->status==NULL || IS_STOPPED(c->status->state) )
     {
       mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE, 
               screen->progress_window.cols);
@@ -320,6 +334,7 @@ screen_init(void)
   screen->buf_size = screen->cols;
   screen->findbuf = NULL;
   screen->painted = 0;
+  screen->input_timestamp = time(NULL);
 
   /* create top window */
   screen->top_window.rows = 2;
@@ -472,6 +487,7 @@ screen_cmd(mpd_client_t *c, command_t cmd)
   int n;
   screen_mode_t new_mode = screen->mode;
 
+  screen->input_timestamp = time(NULL);
   switch(screen->mode)
     {
     case SCREEN_PLAY_WINDOW:
@@ -564,6 +580,11 @@ screen_cmd(mpd_client_t *c, command_t cmd)
       screen_status_printf("Find mode: %s", 
                           options.find_wrap ? "Wrapped" : "Normal");
       break;
+    case CMD_TOGGLE_AUTOCENTER:
+      options.auto_center = !options.auto_center;
+      screen_status_printf("Auto center mode: %s", 
+                          options.auto_center ? "On" : "Off");
+      break;
     case CMD_SCREEN_PREVIOUS:
       if( screen->mode > SCREEN_PLAY_WINDOW )
        new_mode = screen->mode - 1;
index 09349a361b1242a037af9bb5d6d5b05bd59d263a..d2e8086af345659eb3bbf8e3fcd998409808d12b 100644 (file)
@@ -53,6 +53,8 @@ static help_text_row_t help_text[] =
   { 0, CMD_SAVE_PLAYLIST,  "Save playlist" },
   { 0, CMD_REPEAT,         "Toggle repeat mode" },
   { 0, CMD_RANDOM,         "Toggle random mode" },
+  { 0, CMD_SCREEN_UPDATE,  "Center playing track" },
+  { 0, CMD_TOGGLE_AUTOCENTER, "Toggle auto center" },
   { 0, CMD_NONE, " " },
   { 0, CMD_NONE, " " },
   { 1, CMD_NONE, "    Keys - Browse screen " },
index 151402def525c6ea38c5f4581ed1386b03ea209d..c9fd248ebea50f172bf432d1530099413164582a 100644 (file)
@@ -4,6 +4,7 @@
 #include <ncurses.h>
 
 #include "config.h"
+#include "options.h"
 #include "support.h"
 #include "libmpdclient.h"
 #include "mpc.h"
@@ -36,6 +37,33 @@ list_callback(int index, int *highlight, void *data)
   return mpc_get_song_name(song);
 }
 
+static int
+center_playing_item(screen_t *screen, mpd_client_t *c)
+{
+  list_window_t *lw = screen->playlist;
+  int length = c->playlist_length;
+  int offset = lw->selected-lw->start;
+  
+  if( !lw || length<lw->rows || !IS_PLAYING(c->status->state) )
+    return 0;
+
+  /* try to center the song that are playing */
+  lw->start = c->song_id-(lw->rows/2);
+  if( lw->start+lw->rows > length )
+    lw->start = length-lw->rows;
+  if( lw->start<0 )
+    lw->start=0;
+
+  /* make sure the cursor is in the window */
+  lw->selected = lw->start+offset;
+  list_window_check_selected(lw, length);
+
+  lw->clear = 1;
+  lw->repaint = 1;
+
+  return 0;
+}
+
 static int
 handle_save_playlist(screen_t *screen, mpd_client_t *c)
 {
@@ -103,6 +131,17 @@ play_paint(screen_t *screen, mpd_client_t *c)
 void
 play_update(screen_t *screen, mpd_client_t *c)
 {
+  if( options.auto_center )
+    {
+      static int prev_song_id = 0;
+      
+      if( prev_song_id != c->song_id ) 
+       {
+         center_playing_item(screen, c);
+         prev_song_id = c->song_id;
+       }
+    }
+
   if( c->playlist_updated )
     {
       if( screen->playlist->selected >= c->playlist_length )
@@ -142,6 +181,9 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
     case CMD_SAVE_PLAYLIST:
       handle_save_playlist(screen, c);
       return 1;
+    case CMD_SCREEN_UPDATE:
+      center_playing_item(screen, c);
+      return 1;
     case CMD_LIST_FIND:
     case CMD_LIST_RFIND:
     case CMD_LIST_FIND_NEXT: