[xiph-commits] r17664 - trunk/squishyball

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sat Nov 27 06:36:53 PST 2010


Author: xiphmont
Date: 2010-11-27 06:36:53 -0800 (Sat, 27 Nov 2010)
New Revision: 17664

Modified:
   trunk/squishyball/main.c
   trunk/squishyball/squishyball.1
   trunk/squishyball/tty.c
Log:
more ui hookup work


Modified: trunk/squishyball/main.c
===================================================================
--- trunk/squishyball/main.c	2010-11-27 13:11:25 UTC (rev 17663)
+++ trunk/squishyball/main.c	2010-11-27 14:36:53 UTC (rev 17664)
@@ -1422,12 +1422,13 @@
           "   ! @ #   : Choose sample 1, 2, or 3 for X/X/Y trial result.\n"
           "<ins> <del>: Undo/redo last trial result selection.\n"
           "  <enter>  : Choose current sample for this trial\n"
-          "   <- ->   : seek back/forward two seconds, +shift for 10 seconds\n"
+          "   <- ->   : Seek back/forward two seconds, +shift for 10 seconds\n"
+          " <up/down> : Select sample from list (casual mode)\n"
           "  <space>  : Pause/resume playback\n"
           " <backspc> : Reset playback to start point\n"
           "     e     : set end playback point to current playback time.\n"
           "     E     : reset end playback time to end of sample\n"
-          "     F     : Toggle through beep-flip/mark-flip/seamless-flip modes.\n"
+          "     f     : Toggle through beep-flip/mark-flip/seamless-flip modes.\n"
           "     r     : Toggle through restart-after/restart-every/no-restart.\n"
           "     s     : set start playback point to current playback time.\n"
           "     S     : reset start playback time to 0:00:00.00\n"
@@ -2124,8 +2125,8 @@
     int bpf=ch*bps;
     int rate=pcm[0]->rate;
     int size=pcm[0]->size;
-    off_t start_pos=rint(start*rate);
-    off_t end_pos=(end>0?rint(end*rate):size);
+    off_t start_pos=rint(start*rate*bpf);
+    off_t end_pos=(end>0?rint(end*rate*bpf):size);
     off_t current_pos;
     int paused=0;
 
@@ -2147,6 +2148,7 @@
       int c;
       if(state.exiting) break;
 
+      /* seeks and some other ops are batched */
       if(state.key_waiting && !do_flip && !do_pause && !do_select){
         /* service keyboard */
         c=state.key_waiting;
@@ -2155,13 +2157,22 @@
         case ERR:
           break;
         case 3:
-          /* control-c */
-
+          /* control-c == quit */
           pthread_mutex_lock(&state.mutex);
           state.exiting=1;
           pthread_mutex_unlock(&state.mutex);
           break;
-
+        case KEY_UP:
+          if(current_choice>0){
+            flip_to=current_choice-1;
+            do_flip=1;
+          }
+          break;
+        case KEY_DOWN:
+          flip_to=current_choice+1;
+          do_flip=1;
+          /* range checking enforced later */
+          break;
         case '0': case '9': case '8': case '7': case '6':
         case '5': case '4': case '3': case '2': case '1':
           flip_to=c-'1';
@@ -2226,6 +2237,31 @@
           seek_to=start_pos;
           do_seek=1;
           break;
+        case 'f':
+          beep_mode++;
+          if(beep_mode>3)beep_mode=1;
+          break;
+        case 'r':
+          restart_mode++;
+          if(test_mode==3 && restart_mode==1)restart_mode++;
+          if(restart_mode>2)restart_mode=0;
+          break;
+        case 's':
+          if(current_pos<end_pos)
+            start_pos=current_pos;
+          break;
+        case 'S':
+          start_pos=0;
+          break;
+        case 'e':
+          if(current_pos>start_pos)
+            end_pos=current_pos;
+          break;
+        case 'E':
+          end_pos=pcm[0]->size;
+          break;
+        case '?':
+          break;
         }
 
         if(do_flip && flip_to==current_choice) do_flip=0;
@@ -2266,8 +2302,23 @@
 
       /* update terminal */
       {
-        double current = (double)current_pos/(pcm[0]->ch*(pcm[0]->bits+7)/8*pcm[0]->rate);
+        double base = 1.f/(rate*bpf);
+        double current = current_pos*base;
+        double start = start_pos*base;
+        double len = pcm[0]->size*base;
+        double end = end_pos>0?end_pos*base:len;
+
+        pthread_mutex_unlock(&state.mutex);
+        panel_update_start(start);
         panel_update_current(current);
+        panel_update_end(end);
+        panel_update_pause(paused);
+        panel_update_playing(current_choice);
+        panel_update_repeat_mode(restart_mode);
+        panel_update_flip_mode(beep_mode);
+        //panel_update_trials(trial_list);
+        min_flush();
+        pthread_mutex_lock(&state.mutex);
       }
 
       if(state.fragment_size==0 && !state.exiting){

Modified: trunk/squishyball/squishyball.1
===================================================================
--- trunk/squishyball/squishyball.1	2010-11-27 13:11:25 UTC (rev 17663)
+++ trunk/squishyball/squishyball.1	2010-11-27 14:36:53 UTC (rev 17664)
@@ -111,6 +111,8 @@
 Indicate the 'odd sample out' as sample 1, 2, or 3 (X/X/Y testing mode)
 .IP "\fB<-\fR, \fB->"
 Seek back/forward two seconds, \fB+shift \fRfor ten seconds.
+.IP "\fB<up/down>"
+Select sample in sample list (casual mode).
 .IP "\fB<space>"
 Pause/resume playback.
 .IP "\fB<backspace>"
@@ -119,7 +121,7 @@
 Set end playback point to current playback time (see also -e above).
 .IP "\fBE"
 Reset end playback time to end of sample.
-.IP "\fBF"
+.IP "\fBf"
 Toggle through beep-flip/mark-flip/seamless-flip modes (see \fB-B\fR, \fB-M\fR, and \fB-S \fRabove).
 .IP "\fBr"
 Toggle through restart-after/restart-every/no-restart modes (see \fB-r \fRand \fB-R \fRabove).

Modified: trunk/squishyball/tty.c
===================================================================
--- trunk/squishyball/tty.c	2010-11-27 13:11:25 UTC (rev 17663)
+++ trunk/squishyball/tty.c	2010-11-27 14:36:53 UTC (rev 17664)
@@ -34,6 +34,7 @@
 #include "main.h"
 #include "mincurses.h"
 
+static int force=0;
 static int p_tm,p_ch,p_b,p_r,p_fm,p_rm,pcm_n,p_tr,p_tn,p_pau,p_pl;
 static double p_st,p_cur,p_end,p_len;
 static char *p_tl;
@@ -279,6 +280,7 @@
   draw_playbar(i++);
   draw_timebar(i++);
   draw_topbar(1);
+  force=1;
   panel_update_pause(p_pau);
   panel_update_playing(p_pl);
   panel_update_start(p_st);
@@ -288,6 +290,7 @@
   panel_update_flip_mode(p_fm);
   if(p_tm!=3)
     panel_update_trials(p_tl);
+  force=0;
   min_flush();
 }
 
@@ -326,220 +329,226 @@
 }
 
 void panel_update_start(double time){
-  p_st=time;
-  min_mvcur(columns/2-21,timerow);
-  min_putchar(' ');
-  if(p_st<=0.f){
-    min_fg(COLOR_CYAN);
-    min_putstr("xx:xx:xx.xx");
-    min_fg(-1);
-  }else{
-    char *time=make_time_string(p_st,1);
-    min_putstr(time);
+  if(force || p_st!=time){
+    p_st=time;
+    min_mvcur(columns/2-21,timerow);
+    min_putchar(' ');
+    if(p_st<=0.f){
+      min_fg(COLOR_CYAN);
+      min_putstr("xx:xx:xx.xx");
+      min_fg(-1);
+    }else{
+      char *time=make_time_string(p_st,1);
+      min_putstr(time);
+    }
+    min_putchar(' ');
+    draw_playbar(playrow);
   }
-  min_putchar(' ');
-  draw_playbar(playrow);
-  min_flush();
 }
 
 void panel_update_current(double time){
-  int was = rint(p_cur/(p_len-1)*columns);
-  int now = rint(time/(p_len-1)*columns);
-  p_cur=time;
-  min_mvcur(columns/2-7,timerow);
-  min_putchar(' ');
-  {
-    char *time=make_time_string(p_cur,1);
-    min_putstr(time);
-  }
-  min_putchar(' ');
+  if(force || p_cur!=time){
+    int was = rint(p_cur/(p_len-1)*columns);
+    int now = rint(time/(p_len-1)*columns);
+    p_cur=time;
+    min_mvcur(columns/2-7,timerow);
+    min_putchar(' ');
+    {
+      char *time=make_time_string(p_cur,1);
+      min_putstr(time);
+    }
+    min_putchar(' ');
 
-  if(was!=now){
-    int pre = rint(p_st/p_len*columns);
-    int post = rint((p_len-p_end)/p_len*columns);
+    if(was!=now){
+      int pre = rint(p_st/p_len*columns);
+      int post = rint((p_len-p_end)/p_len*columns);
 
-    min_bold(1);
-    min_gfx(1);
+      min_bold(1);
+      min_gfx(1);
 
-    min_mvcur(was,playrow);
-    if(was<pre || (columns-was)<post){
-      min_color(COLOR_YELLOW,COLOR_CYAN);
-    }else{
-      min_color(COLOR_YELLOW,COLOR_BLACK);
-    }
-    min_putchar(' ');
+      min_mvcur(was,playrow);
+      if(was<pre || (columns-was)<post){
+        min_color(COLOR_YELLOW,COLOR_CYAN);
+      }else{
+        min_color(COLOR_YELLOW,COLOR_BLACK);
+      }
+      min_putchar(' ');
 
-
-    min_mvcur(now,playrow);
-    if(now<pre || (columns-now)<post){
-      min_bg(COLOR_CYAN);
-    }else{
-      min_bg(COLOR_BLACK);
+      min_mvcur(now,playrow);
+      if(now<pre || (columns-now)<post){
+        min_bg(COLOR_CYAN);
+      }else{
+        min_bg(COLOR_BLACK);
+      }
+      min_putchar(ACS_VLINE);
     }
-    min_putchar(ACS_VLINE);
+    min_unset();
   }
-  min_unset();
-  min_flush();
 }
 
 void panel_update_end(double time){
-  p_end=time;
-  min_mvcur(columns/2+7,timerow);
-  min_putchar(' ');
-  if(p_end>=p_len){
-    min_fg(COLOR_CYAN);
-    min_putstr("xx:xx:xx.xx");
-    min_fg(-1);
-  }else{
-    char *time=make_time_string(p_end,1);
-    min_putstr(time);
+  if(force || p_end!=time){
+    p_end=time;
+    min_mvcur(columns/2+7,timerow);
+    min_putchar(' ');
+    if(p_end+1.e-6>=p_len){
+      min_fg(COLOR_CYAN);
+      min_putstr("xx:xx:xx.xx");
+      min_fg(-1);
+    }else{
+      char *time=make_time_string(p_end,1);
+      min_putstr(time);
+    }
+    min_putchar(' ');
+    draw_playbar(playrow);
   }
-  min_putchar(' ');
-  draw_playbar(playrow);
-  min_flush();
 }
 
 void panel_update_repeat_mode(int mode){
-  int i;
-  min_mvcur(columns-31,fliprow);
-  p_rm=mode;
-  switch(p_rm){
-  case 0:
-    min_fg(COLOR_CYAN);
-    min_gfx(1);
-    for(i=0;i<15;i++)
-      min_putchar(ACS_HLINE);
-    min_unset();
-    break;
-  case 1:
-    min_putstr(" RESTART AFTER ");
-    break;
-  case 2:
-    min_mvcur(columns-31,fliprow+2);
-    min_putstr(" RESTART EVERY ");
-    break;
+  if(p_rm!=mode){
+    int i;
+    min_mvcur(columns-30,fliprow);
+    p_rm=mode;
+    switch(p_rm){
+    case 0:
+      min_fg(COLOR_CYAN);
+      min_gfx(1);
+      for(i=0;i<15;i++)
+        min_putchar(ACS_HLINE);
+      min_unset();
+      break;
+    case 1:
+      min_putstr(" RESTART AFTER ");
+      break;
+    case 2:
+      min_putstr(" RESTART EVERY ");
+      break;
+    }
   }
-  min_flush();
 }
 
 void panel_update_flip_mode(int mode){
-  min_mvcur(columns-14,fliprow);
-  min_fg(COLOR_CYAN);
-  min_gfx(1);
-  min_putchar(ACS_HLINE);
-  min_putchar(ACS_HLINE);
-  min_unset();
+  if(force || p_fm!=mode){
+    min_mvcur(columns-14,fliprow);
+    min_fg(COLOR_CYAN);
+    min_gfx(1);
+    min_putchar(ACS_HLINE);
+    min_putchar(ACS_HLINE);
+    min_unset();
 
-  p_fm=mode;
-  switch(p_fm){
-  case 1:
-    min_mvcur(columns-12,fliprow);
-    min_putstr(" MARK FLIP ");
-    break;
-  case 2:
-    min_mvcur(columns-12,fliprow);
-    min_putstr(" BEEP FLIP ");
-    break;
-  case 3:
-    min_mvcur(columns-14,fliprow);
-    min_putstr(" SILENT FLIP ");
-    break;
+    p_fm=mode;
+    switch(p_fm){
+    case 1:
+      min_mvcur(columns-12,fliprow);
+      min_putstr(" MARK FLIP ");
+      break;
+    case 2:
+      min_mvcur(columns-12,fliprow);
+      min_putstr(" BEEP FLIP ");
+      break;
+    case 3:
+      min_mvcur(columns-14,fliprow);
+      min_putstr(" SILENT FLIP ");
+      break;
+    }
   }
-  min_flush();
 }
 
 static int old_p_tl_len=-1;
 void panel_update_trials(char *trial_list){
-  char buf[columns+1];
-  int k,l = strlen(trial_list);
-  if(p_tl)free(p_tl);
-  p_tl=strdup(trial_list);
-  min_mvcur(1,boxrow+1);
+  if(force || strcmp(p_tl,trial_list)){
+    char buf[columns+1];
+    int k,l = strlen(trial_list);
+    if(p_tl)free(p_tl);
+    p_tl=strdup(trial_list);
+    min_mvcur(1,boxrow+1);
 
-  sprintf(buf," %d/%d trials: ",l,p_tn);
-  min_putstr(buf);
+    sprintf(buf," %d/%d trials: ",l,p_tn);
+    min_putstr(buf);
 
-  l+=strlen(buf);
-  if(l>columns-4){
-    min_putstr("...");
-    min_putstr(p_tl+l-columns-7);
-    l+=strlen(p_tl+l-columns-7);
-  }else{
-    min_putstr(p_tl);
-    l+=strlen(p_tl);
+    l+=strlen(buf);
+    if(l>columns-4){
+      min_putstr("...");
+      min_putstr(p_tl+l-columns-7);
+      l+=strlen(p_tl+l-columns-7);
+    }else{
+      min_putstr(p_tl);
+      l+=strlen(p_tl);
+    }
+    {
+      k=l;
+      while(k++<old_p_tl_len)
+        min_putchar(' ');
+      old_p_tl_len=l;
+    }
   }
-  {
-    k=l;
-    while(k++<old_p_tl_len)
-      min_putchar(' ');
-    old_p_tl_len=l;
-  }
-  min_flush();
 }
 
 void panel_update_playing(int n){
-  if(p_tm==3){
-    min_mvcur(1,boxrow+1+p_pl);
-    min_putchar(' ');
-    if(strlen(pcm_p[p_pl]->path)>columns-4)
-      min_putstr(pcm_p[p_pl]->path+strlen(pcm_p[p_pl]->path)-columns+4);
-    else
-      min_putstr(pcm_p[p_pl]->path);
+  if(force || n!=p_pl){
+    if(p_tm==3){
+      min_mvcur(1,boxrow+1+p_pl);
+      min_putchar(' ');
+      if(strlen(pcm_p[p_pl]->path)>columns-4)
+        min_putstr(pcm_p[p_pl]->path+strlen(pcm_p[p_pl]->path)-columns+4);
+      else
+        min_putstr(pcm_p[p_pl]->path);
 
-    min_mvcur(1,boxrow+1+n);
-    min_putchar('>');
-    min_bold(1);
-    if(strlen(pcm_p[n]->path)>columns-4)
-      min_putstr(pcm_p[n]->path+strlen(pcm_p[n]->path)-columns+4);
-    else
-      min_putstr(pcm_p[n]->path);
-    min_unset();
-  }
+      min_mvcur(1,boxrow+1+n);
+      min_putchar('>');
+      min_bold(1);
+      if(strlen(pcm_p[n]->path)>columns-4)
+        min_putstr(pcm_p[n]->path+strlen(pcm_p[n]->path)-columns+4);
+      else
+        min_putstr(pcm_p[n]->path);
+      min_unset();
+    }
 
-  p_pl=n;
-  if(!p_pau){
-    min_mvcur(8,timerow);
-    switch(p_tm){
-    case 0: /* AB */
-    case 1: /* ABX */
-      min_putchar(p_pl+'A');
-      break;
-    case 2: /* XXY*/
-    case 3: /* Casual */
-      min_putchar(p_pl+'1');
-      break;
+    p_pl=n;
+    if(!p_pau){
+      min_mvcur(8,timerow);
+      switch(p_tm){
+      case 0: /* AB */
+      case 1: /* ABX */
+        min_putchar(p_pl+'A');
+        break;
+      case 2: /* XXY*/
+      case 3: /* Casual */
+        min_putchar(p_pl+'1');
+        break;
+      }
     }
   }
-  min_flush();
 }
 
 void panel_update_pause(int flag){
-  p_pau=flag;
-  min_mvcur(0,timerow);
-  if(p_pau){
-    min_blink(1);
-    min_putstr("PAUSED ");
-    min_blink(0);
-  }else{
-    min_putstr("PLAYING ");
-    switch(p_tm){
-    case 0: /* AB */
-    case 1: /* ABX */
-      min_putchar(p_pl+'A');
-      break;
-    case 2: /* XXY*/
-    case 3: /* Casual */
-      min_putchar(p_pl+'1');
-      break;
+  if(flag!=p_pau || force){
+    p_pau=flag;
+    min_mvcur(0,timerow);
+    if(p_pau){
+      min_blink(1);
+      min_putstr("PAUSED ");
+      min_blink(0);
+    }else{
+      min_putstr("PLAYING ");
+      switch(p_tm){
+      case 0: /* AB */
+      case 1: /* ABX */
+        min_putchar(p_pl+'A');
+        break;
+      case 2: /* XXY*/
+      case 3: /* Casual */
+        min_putchar(p_pl+'1');
+        break;
+      }
+      min_putchar(' ');
     }
+
+    min_gfx(1);
+    min_fg(COLOR_CYAN);
+    min_putchar(ACS_HLINE);
+    min_putchar(ACS_HLINE);
+    min_putchar(ACS_HLINE);
+    min_unset();
   }
-  min_putchar(' ');
-
-  min_gfx(1);
-  min_fg(COLOR_CYAN);
-  min_putchar(ACS_HLINE);
-  min_putchar(ACS_HLINE);
-  min_putchar(ACS_HLINE);
-  min_unset();
-  min_flush();
 }



More information about the commits mailing list