Code

Use the terminal in raw mode - ignore terminal control characters
[ncmpc.git] / src / screen.c
1 /* 
2  * $Id$
3  *
4  * (c) 2004 by Kalle Wallin <kaw@linux.se>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <time.h>
26 #include <locale.h>
27 #include <glib.h>
28 #include <ncurses.h>
30 #include "config.h"
31 #include "ncmpc.h"
32 #include "support.h"
33 #include "libmpdclient.h"
34 #include "mpc.h"
35 #include "command.h"
36 #include "options.h"
37 #include "colors.h"
38 #include "wreadln.h"
39 #include "screen.h"
40 #include "screen_play.h"
41 #include "screen_file.h"
42 #include "screen_help.h"
43 #include "screen_search.h"
44 #include "screen_utils.h"
46 #define ENABLE_STATUS_LINE_CLOCK
47 #define ENABLE_SCROLLING
49 #define DEFAULT_CROSSFADE_TIME 10
51 #define STATUS_MESSAGE_TIMEOUT 3
52 #define STATUS_LINE_MAX_SIZE   512
54 #ifdef ENABLE_KEYDEF_SCREEN
55 extern screen_functions_t *get_screen_keydef(void);
56 #endif
57 #ifdef ENABLE_CLOCK_SCREEN
58 extern screen_functions_t *get_screen_clock(void);
59 #endif
62 static gboolean welcome = TRUE;
63 static screen_t *screen = NULL;
64 static screen_functions_t *mode_fn = NULL;
66 static void
67 switch_screen_mode(screen_mode_t new_mode, mpd_client_t *c)
68 {
69   if( new_mode == screen->mode )
70     return;
72   /* close the old mode */
73   if( mode_fn && mode_fn->close )
74     mode_fn->close();
76   /* get functions for the new mode */
77   switch(new_mode)
78     {
79     case SCREEN_PLAY_WINDOW:
80       mode_fn = get_screen_playlist();
81       break;
82     case SCREEN_FILE_WINDOW:
83       mode_fn = get_screen_file();
84       break;
85     case SCREEN_HELP_WINDOW:
86       mode_fn = get_screen_help();
87       break;
88 #ifdef ENABLE_KEYDEF_SCREEN
89     case SCREEN_KEYDEF_WINDOW:
90       mode_fn = get_screen_keydef();
91       break;
92 #endif
93 #ifdef ENABLE_CLOCK_SCREEN
94     case SCREEN_CLOCK_WINDOW:
95       mode_fn = get_screen_clock();
96       break;
97 #endif
99     default:
100       break;
101     }
103  screen->mode = new_mode;
104  screen->painted = 0;
106  /* open the new mode */
107  if( mode_fn && mode_fn->open )
108    mode_fn->open(screen, c);
112 static void
113 paint_top_window(char *header, mpd_client_t *c, int clear)
115   char flags[4];
116   static int prev_volume = -1;
117   static int prev_header_len = -1;
118   WINDOW *w = screen->top_window.w;
120   if(prev_header_len!=strlen(header))
121     {
122       prev_header_len = strlen(header);
123       clear = 1;
124     }
126   if(clear)
127     {
128       wmove(w, 0, 0);
129       wclrtoeol(w);
130     }
132   if(prev_volume!=c->status->volume || clear)
133     {
134       char buf[32];
136       if( header[0] )
137         {
138           colors_use(w, COLOR_TITLE_BOLD);
139           mvwaddstr(w, 0, 0, header);
140         }
141       else
142         {
143           colors_use(w, COLOR_TITLE_BOLD);
144           waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
145           colors_use(w, COLOR_TITLE);
146           waddstr(w, _(":Help  "));
147           colors_use(w, COLOR_TITLE_BOLD);
148           waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
149           colors_use(w, COLOR_TITLE);
150           waddstr(w, _(":Playlist  "));
151           colors_use(w, COLOR_TITLE_BOLD);
152           waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
153           colors_use(w, COLOR_TITLE);
154           waddstr(w, _(":Browse"));
155         }
156       if( c->status->volume==MPD_STATUS_NO_VOLUME )
157         {
158           snprintf(buf, 32, _("Volume n/a "));
159         }
160       else
161         {
162           snprintf(buf, 32, _(" Volume %d%%"), c->status->volume); 
163         }
164       colors_use(w, COLOR_TITLE);
165       mvwaddstr(w, 0, screen->top_window.cols-strlen(buf), buf);
167       flags[0] = 0;
168       if( c->status->repeat )
169         strcat(flags, "r");
170       if( c->status->random )
171         strcat(flags, "z");
172       if( c->status->crossfade )
173         strcat(flags, "x");
174       if( c->status->updatingDb )
175         strcat(flags, "U");
176       colors_use(w, COLOR_LINE);
177       mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
178       if( flags[0] )
179         {
180           wmove(w,1,screen->top_window.cols-strlen(flags)-3);
181           waddch(w, '[');
182           colors_use(w, COLOR_LINE_BOLD);
183           waddstr(w, flags);
184           colors_use(w, COLOR_LINE);
185           waddch(w, ']');
186         }
187       wnoutrefresh(w);
188     }
191 static void
192 paint_progress_window(mpd_client_t *c)
194   double p;
195   int width;
196   int elapsedTime = c->status->elapsedTime;
198   if( c->status==NULL || IS_STOPPED(c->status->state) )
199     {
200       mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE, 
201                screen->progress_window.cols);
202       wnoutrefresh(screen->progress_window.w);
203       return;
204     }
206   if( c->seek_song_id == c->song_id )
207     elapsedTime = c->seek_target_time;
209   p = ((double) elapsedTime) / ((double) c->status->totalTime);
210   
211   width = (int) (p * (double) screen->progress_window.cols);
212   mvwhline(screen->progress_window.w, 
213            0, 0,
214            ACS_HLINE, 
215            screen->progress_window.cols);
216   whline(screen->progress_window.w, '=', width-1);
217   mvwaddch(screen->progress_window.w, 0, width-1, 'O');
218   wnoutrefresh(screen->progress_window.w);
221 static void 
222 paint_status_window(mpd_client_t *c)
224   WINDOW *w = screen->status_window.w;
225   mpd_Status *status = c->status;
226   mpd_Song *song   = c->song;
227   int elapsedTime = c->status->elapsedTime;
228   int x = 0;
230   if( time(NULL) - screen->status_timestamp <= STATUS_MESSAGE_TIMEOUT )
231     return;
232   
233   
234   wmove(w, 0, 0);
235   wclrtoeol(w);
236   colors_use(w, COLOR_STATUS_BOLD);
237   
238   switch(status->state)
239     {
240     case MPD_STATUS_STATE_PLAY:
241       waddstr(w, _("Playing:"));
242       break;
243     case MPD_STATUS_STATE_PAUSE:
244       waddstr(w, _("[Paused]"));
245       break;
246     case MPD_STATUS_STATE_STOP:
247     default:
248       break;
249     }
250   x += 9;
252   /* create time string */
253   memset(screen->buf, 0, screen->buf_size);
254   if( IS_PLAYING(status->state) || IS_PAUSED(status->state) )
255     {
256       if( status->totalTime > 0 )
257         {
258           if( c->seek_song_id == c->song_id )
259             elapsedTime = c->seek_target_time;
260           snprintf(screen->buf, screen->buf_size, 
261                    " [%i:%02i/%i:%02i]",
262                    elapsedTime/60, elapsedTime%60,
263                    status->totalTime/60,   status->totalTime%60 );
264         }
265       else
266         {
267           snprintf(screen->buf, screen->buf_size,  " [%d kbps]", status->bitRate );
268         }
269     }
270 #ifdef ENABLE_STATUS_LINE_CLOCK
271   else
272     {
273       time_t timep;
275       time(&timep);
276       /* Note: setlocale(LC_TIME,"") should be used first */
277       //strftime(screen->buf, screen->buf_size, "%x  - %X ",localtime(&timep));
278       strftime(screen->buf, screen->buf_size, "%X ",localtime(&timep));
279     }
280 #endif
282   /* display song */
283   if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) &&  song )
284     {
285       char *songname = mpc_get_song_name(song);
286       int width = COLS-x-strlen(screen->buf);
288       colors_use(w, COLOR_STATUS);
289 #ifdef ENABLE_SCROLLING
290       if( strlen(songname) > width )
291         {
292           static  scroll_state_t st = { 0, 0 };
293           char *tmp = strscroll(songname, " *** ", width, &st);
295           strcpy(songname, tmp);
296           g_free(tmp);    
297         }
298 #endif
299       mvwaddnstr(w, 0, x, songname, width);
300     } 
302   /* distplay time string */
303   if( screen->buf[0] )
304     {
305       x = screen->status_window.cols - strlen(screen->buf);
306       colors_use(w, COLOR_STATUS_TIME);
307       mvwaddstr(w, 0, x, screen->buf);
308     }
310   wnoutrefresh(w);
313 GList *
314 screen_free_string_list(GList *list)
316   GList *l = g_list_first(list);
317   
318   while(l)
319     {
320       g_free(l->data);
321       l->data = NULL;
322       l=l->next;
323     }
324   g_list_free(list);
325   return NULL;
328 int
329 screen_exit(void)
331   endwin();
332   if( screen )
333     {
334       GList *list = g_list_first(screen->screen_list);
336       /* close and exit all screens (playlist,browse,help...) */
337       while( list )
338         {
339           screen_functions_t *mode_fn = list->data;
341           if( mode_fn && mode_fn->close )
342             mode_fn->close();
343           if( mode_fn && mode_fn->exit )
344             mode_fn->exit();
345           list->data = NULL;
346           list=list->next;
347         }
348       g_list_free(screen->screen_list);
349       screen_free_string_list(screen->find_history);
350       g_free(screen->buf);
351       g_free(screen->findbuf);
352       
353       g_free(screen);
354       screen = NULL;
355     }
356   return 0;
359 void
360 screen_resize(void)
362   GList *list;
364 #ifdef DEBUG
365   fprintf(stderr, "Resize rows %d->%d, cols %d->%d\n",
366           screen->rows, LINES,
367           screen->cols, COLS);
368 #endif
369       
370   if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
371     {
372       screen_exit();
373       fprintf(stderr, _("Error: Screen to small!\n"));
374       exit(EXIT_FAILURE);
375     }
377   resizeterm(LINES, COLS);
379   screen->cols = COLS;
380   screen->rows = LINES;
382   /* top window */
383   screen->top_window.cols = screen->cols;
384   wresize(screen->top_window.w, 2, screen->cols);
386   /* main window */
387   screen->main_window.cols = screen->cols;
388   screen->main_window.rows = screen->rows-4;
389   wresize(screen->main_window.w, screen->main_window.rows, screen->cols);
390   wclear(screen->main_window.w);
392   /* progress window */
393   screen->progress_window.cols = screen->cols;
394   wresize(screen->progress_window.w, 1, screen->cols);
395   mvwin(screen->progress_window.w, screen->rows-2, 0);
397   /* status window */
398   screen->status_window.cols = screen->cols;
399   wresize(screen->status_window.w, 1, screen->cols);
400   mvwin(screen->status_window.w, screen->rows-1, 0);
402   screen->buf_size = screen->cols;
403   g_free(screen->buf);
404   screen->buf = g_malloc(screen->cols);
406   list = g_list_first(screen->screen_list);
407   while( list )
408     {
409       screen_functions_t *mode_fn = list->data;
411       if( mode_fn && mode_fn->resize )
412         mode_fn->resize(screen->main_window.cols, screen->main_window.rows);
414       list=list->next;
415     }
417   /* ? - without this the cursor becomes visible with aterm & Eterm */
418   curs_set(1);
419   curs_set(0);     
421   screen->painted = 0;
424 void 
425 screen_status_message(char *msg)
427   WINDOW *w = screen->status_window.w;
429   wmove(w, 0, 0);
430   wclrtoeol(w);
431   colors_use(w, COLOR_STATUS_ALERT);
432   waddstr(w, msg);
433   wnoutrefresh(w);
434   screen->status_timestamp = time(NULL);
437 void 
438 screen_status_printf(char *format, ...)
440   char buffer[STATUS_LINE_MAX_SIZE];
441   va_list ap;
442   
443   va_start(ap,format);
444   vsnprintf(buffer,sizeof(buffer),format,ap);
445   va_end(ap);
446   screen_status_message(buffer);
449 int
450 screen_init(void)
452   GList *list;
454   /* initialize the curses library */
455   initscr();
456   /* initialize color support */
457   colors_start();
458   /* tell curses not to do NL->CR/NL on output */
459   nonl();          
460   /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
461   raw();
462   /* don't echo input */
463   noecho();    
464   /* set cursor invisible */     
465   curs_set(0);     
466   /* enable extra keys */
467   keypad(stdscr, TRUE);  
468   /* return from getch() without blocking */
469   timeout(SCREEN_TIMEOUT);
470   
472   if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
473     {
474       fprintf(stderr, _("Error: Screen to small!\n"));
475       exit(EXIT_FAILURE);
476     }
478   screen = g_malloc(sizeof(screen_t));
479   memset(screen, 0, sizeof(screen_t));
480   screen->mode = SCREEN_PLAY_WINDOW;
481   screen->cols = COLS;
482   screen->rows = LINES;
483   screen->buf  = g_malloc(screen->cols);
484   screen->buf_size = screen->cols;
485   screen->findbuf = NULL;
486   screen->painted = 0;
487   screen->start_timestamp = time(NULL);
488   screen->input_timestamp = time(NULL);
489   screen->last_cmd = CMD_NONE;
491   /* create top window */
492   screen->top_window.rows = 2;
493   screen->top_window.cols = screen->cols;
494   screen->top_window.w = newwin(screen->top_window.rows, 
495                                   screen->top_window.cols,
496                                   0, 0);
497   leaveok(screen->top_window.w, TRUE);
498   keypad(screen->top_window.w, TRUE);  
500   /* create main window */
501   screen->main_window.rows = screen->rows-4;
502   screen->main_window.cols = screen->cols;
503   screen->main_window.w = newwin(screen->main_window.rows, 
504                                  screen->main_window.cols,
505                                  2, 
506                                  0);
508   //  leaveok(screen->main_window.w, TRUE); temporary disabled
509   keypad(screen->main_window.w, TRUE);  
511   /* create progress window */
512   screen->progress_window.rows = 1;
513   screen->progress_window.cols = screen->cols;
514   screen->progress_window.w = newwin(screen->progress_window.rows, 
515                                      screen->progress_window.cols,
516                                      screen->rows-2, 
517                                      0);
518   leaveok(screen->progress_window.w, TRUE);
519   
520   /* create status window */
521   screen->status_window.rows = 1;
522   screen->status_window.cols = screen->cols;
523   screen->status_window.w = newwin(screen->status_window.rows, 
524                                    screen->status_window.cols,
525                                    screen->rows-1, 
526                                    0);
528   leaveok(screen->status_window.w, FALSE);
529   keypad(screen->status_window.w, TRUE);  
531   if( options.enable_colors )
532     {
533       /* set background attributes */
534       wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); 
535       wbkgd(screen->main_window.w,     COLOR_PAIR(COLOR_LIST));
536       wbkgd(screen->top_window.w,      COLOR_PAIR(COLOR_TITLE));
537       wbkgd(screen->progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
538       wbkgd(screen->status_window.w,   COLOR_PAIR(COLOR_STATUS));
539       colors_use(screen->progress_window.w, COLOR_PROGRESSBAR);
540     }
542   /* initialize screens */
543   screen->screen_list = NULL;
544   screen->screen_list = g_list_append(screen->screen_list, 
545                                       (gpointer) get_screen_playlist());
546   screen->screen_list = g_list_append(screen->screen_list, 
547                                       (gpointer) get_screen_file());
548   screen->screen_list = g_list_append(screen->screen_list, 
549                                       (gpointer) get_screen_help());
550 #ifdef ENABLE_KEYDEF_SCREEN
551   screen->screen_list = g_list_append(screen->screen_list, 
552                                       (gpointer) get_screen_keydef());
553 #endif
554 #ifdef ENABLE_CLOCK_SCREEN
555   screen->screen_list = g_list_append(screen->screen_list, 
556                                       (gpointer) get_screen_clock());
557 #endif
559   list = screen->screen_list;
560   while( list )
561     {
562       screen_functions_t *fn = list->data;
563       
564       if( fn && fn->init )
565         fn->init(screen->main_window.w, 
566                  screen->main_window.cols,
567                  screen->main_window.rows);
568       
569       list = list->next;
570     }
572   mode_fn = get_screen_playlist();
574   /* initialize wreadln */
575   wrln_resize_callback = screen_resize;
576   wrln_max_history_length = 16;
578   return 0;
581 void 
582 screen_paint(mpd_client_t *c)
584   /* paint the title/header window */
585   if( mode_fn && mode_fn->get_title )
586     paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 1);
587   else
588     paint_top_window("", c, 1);
590   /* paint the main window */
591   if( mode_fn && mode_fn->paint )
592     mode_fn->paint(screen, c);
593   
594   paint_progress_window(c);
595   paint_status_window(c);
596   screen->painted = 1;
597   wmove(screen->main_window.w, 0, 0);  
598   wnoutrefresh(screen->main_window.w);
600   /* tell curses to update */
601   doupdate();
604 void 
605 screen_update(mpd_client_t *c)
607   static int repeat = -1;
608   static int random = -1;
609   static int crossfade = -1;
610   static int dbupdate = -1;
611   list_window_t *lw = NULL;
613   if( !screen->painted )
614     return screen_paint(c);
616   /* print a message if mpd status has changed */
617   if( repeat<0 )
618     {
619       repeat = c->status->repeat;
620       random = c->status->random;
621       crossfade = c->status->crossfade;
622       dbupdate = c->status->updatingDb;
623     }
624   if( repeat != c->status->repeat )
625     screen_status_printf(c->status->repeat ? 
626                          _("Repeat is on") :
627                          _("Repeat is off"));
628   if( random != c->status->random )
629     screen_status_printf(c->status->random ?
630                          _("Random is on") :
631                          _("Random is off"));
632                          
633   if( crossfade != c->status->crossfade )
634     screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
635   if( dbupdate && dbupdate != c->status->updatingDb )
636     screen_status_printf(_("Database updated!"));
638   repeat = c->status->repeat;
639   random = c->status->random;
640   crossfade = c->status->crossfade;
641   dbupdate = c->status->updatingDb;
643   /* update title/header window */
644   if( welcome && screen->last_cmd==CMD_NONE &&
645       time(NULL)-screen->start_timestamp <= SCREEN_WELCOME_TIME)
646     paint_top_window("", c, 0);
647   else if( mode_fn && mode_fn->get_title )
648     {
649       paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 0);
650       welcome = FALSE;
651     }
652   else
653     paint_top_window("", c, 0);
655   /* update the main window */
656   if( mode_fn && mode_fn->paint )
657     mode_fn->update(screen, c);
659   if( mode_fn && mode_fn->get_lw )
660     lw = mode_fn->get_lw();
662   /* update progress window */
663   paint_progress_window(c);
665   /* update status window */
666   paint_status_window(c);
668   /* move the cursor to the selected row in the main window */
669   if( lw )
670     wmove(screen->main_window.w, LW_ROW(lw), 0);   
671   else
672     wmove(screen->main_window.w, 0, 0);   
673   wnoutrefresh(screen->main_window.w);
675   /* tell curses to update */
676   doupdate();
679 void
680 screen_idle(mpd_client_t *c)
682   if( c->seek_song_id ==  c->song_id &&
683       (screen->last_cmd == CMD_SEEK_FORWARD || 
684        screen->last_cmd == CMD_SEEK_BACKWARD) )
685     {
686       mpd_sendSeekCommand(c->connection, 
687                           c->seek_song_id, 
688                           c->seek_target_time);
689       mpd_finishCommand(c->connection);
690     }
692   screen->last_cmd = CMD_NONE;
693   c->seek_song_id = -1;
696 void 
697 screen_cmd(mpd_client_t *c, command_t cmd)
699   int n = 0;
700   screen_mode_t new_mode = screen->mode;
702   screen->input_timestamp = time(NULL);
703   screen->last_cmd = cmd;
704   welcome = FALSE;
706   if( mode_fn && mode_fn->cmd && mode_fn->cmd(screen, c, cmd) )
707     return;
709   switch(cmd)
710     {
711     case CMD_PLAY:
712       if( screen->mode == SCREEN_PLAY_WINDOW )
713         n = play_get_selected();
714       else
715         n = -1;
716       mpd_sendPlayCommand(c->connection, n);
717       mpd_finishCommand(c->connection);
718       break;
719     case CMD_PAUSE:
720       mpd_sendPauseCommand(c->connection);
721       mpd_finishCommand(c->connection);
722       break;
723     case CMD_STOP:
724       mpd_sendStopCommand(c->connection);
725       mpd_finishCommand(c->connection);
726       break;
727     case CMD_SEEK_FORWARD:
728       if( !IS_STOPPED(c->status->state) )
729         {
730           if( c->seek_song_id != c->song_id )
731             {
732               c->seek_song_id = c->song_id;
733               c->seek_target_time = c->status->elapsedTime;
734             }
735           c->seek_target_time++;
736           if( c->seek_target_time < c->status->totalTime )
737             break;
738           c->seek_target_time=0;
739         }
740       /* fall through... */
741     case CMD_TRACK_NEXT:
742       if( !IS_STOPPED(c->status->state) )
743         {
744           mpd_sendNextCommand(c->connection);
745           mpd_finishCommand(c->connection);
746         }
747       break;
748     case CMD_SEEK_BACKWARD:
749       if( !IS_STOPPED(c->status->state) )
750         {
751           if( c->seek_song_id != c->song_id )
752             {
753               c->seek_song_id = c->song_id;
754               c->seek_target_time = c->status->elapsedTime;
755             }
756           c->seek_target_time--;
757           if( c->seek_target_time < 0 )
758             c->seek_target_time=0;
759         }
760       break;
761     case CMD_TRACK_PREVIOUS:
762       if( !IS_STOPPED(c->status->state) )
763         {
764           mpd_sendPrevCommand(c->connection);
765           mpd_finishCommand(c->connection);
766         }
767       break;   
768     case CMD_SHUFFLE:
769       mpd_sendShuffleCommand(c->connection);
770       mpd_finishCommand(c->connection);
771       screen_status_message(_("Shuffled playlist!"));
772       break;
773     case CMD_CLEAR:
774       mpd_sendClearCommand(c->connection);
775       mpd_finishCommand(c->connection);
776       file_clear_highlights(c);
777       screen_status_message(_("Cleared playlist!"));
778       break;
779     case CMD_REPEAT:
780       n = !c->status->repeat;
781       mpd_sendRepeatCommand(c->connection, n);
782       mpd_finishCommand(c->connection);
783       break;
784     case CMD_RANDOM:
785       n = !c->status->random;
786       mpd_sendRandomCommand(c->connection, n);
787       mpd_finishCommand(c->connection);
788       break;
789     case CMD_CROSSFADE:
790       if( c->status->crossfade )
791         n = 0;
792       else
793         n = DEFAULT_CROSSFADE_TIME;
794       mpd_sendCrossfadeCommand(c->connection, n);
795       mpd_finishCommand(c->connection);
796       break;
797     case CMD_DB_UPDATE:
798       if( !c->status->updatingDb )
799         {
800           mpd_sendUpdateCommand(c->connection);
801           n = mpd_getUpdateId(c->connection);
802           mpd_finishCommand(c->connection);
803           if( !mpc_error(c) )
804             screen_status_printf(_("Database update started [%d]"), n);
805         }
806       else
807         screen_status_printf(_("Database update running..."));
808       break;
809     case CMD_VOLUME_UP:
810       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
811         {
812           c->status->volume=c->status->volume+1;
813           mpd_sendSetvolCommand(c->connection, c->status->volume  );
814           mpd_finishCommand(c->connection);
815         }
816       break;
817     case CMD_VOLUME_DOWN:
818       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
819         {
820           c->status->volume=c->status->volume-1;
821           mpd_sendSetvolCommand(c->connection, c->status->volume  );
822           mpd_finishCommand(c->connection);
823         }
824       break;
825     case CMD_TOGGLE_FIND_WRAP:
826       options.find_wrap = !options.find_wrap;
827       screen_status_printf(options.find_wrap ? 
828                            _("Find mode: Wrapped") :
829                            _("Find mode: Normal"));
830       break;
831     case CMD_TOGGLE_AUTOCENTER:
832       options.auto_center = !options.auto_center;
833       screen_status_printf(options.auto_center ?
834                            _("Auto center mode: On") :
835                            _("Auto center mode: Off"));
836       break;
837     case CMD_SCREEN_PREVIOUS:
838       if( screen->mode > SCREEN_PLAY_WINDOW )
839         new_mode = screen->mode - 1;
840       else
841         new_mode = SCREEN_HELP_WINDOW-1;
842       switch_screen_mode(new_mode, c);
843       break;
844     case CMD_SCREEN_NEXT:
845       new_mode = screen->mode + 1;
846       if( new_mode >= SCREEN_HELP_WINDOW )
847         new_mode = SCREEN_PLAY_WINDOW;
848       switch_screen_mode(new_mode, c);
849       break;
850     case CMD_SCREEN_PLAY:
851       switch_screen_mode(SCREEN_PLAY_WINDOW, c);
852       break;
853     case CMD_SCREEN_FILE:
854       switch_screen_mode(SCREEN_FILE_WINDOW, c);
855       break;
856     case CMD_SCREEN_SEARCH:
857       switch_screen_mode(SCREEN_SEARCH_WINDOW, c);
858       break;
859     case CMD_SCREEN_HELP:
860       switch_screen_mode(SCREEN_HELP_WINDOW, c);
861       break;
862 #ifdef ENABLE_KEYDEF_SCREEN 
863     case CMD_SCREEN_KEYDEF:
864       switch_screen_mode(SCREEN_KEYDEF_WINDOW, c);
865       break;
866 #endif
867 #ifdef ENABLE_CLOCK_SCREEN 
868     case CMD_SCREEN_CLOCK:
869       switch_screen_mode(SCREEN_CLOCK_WINDOW, c);
870       break;
871 #endif
872     case CMD_QUIT:
873       exit(EXIT_SUCCESS);
874     default:
875       break;
876     }