[xiph-commits] r18274 - trunk/spectrum

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sat May 12 13:16:05 PDT 2012


Author: xiphmont
Date: 2012-05-12 13:16:05 -0700 (Sat, 12 May 2012)
New Revision: 18274

Modified:
   trunk/spectrum/spec_panel.c
   trunk/spectrum/spec_plot.c
   trunk/spectrum/spec_plot.h
   trunk/spectrum/version.h
Log:
Begin re-adding BW modes
fix up decimal dB display so that padx isn't so large


Modified: trunk/spectrum/spec_panel.c
===================================================================
--- trunk/spectrum/spec_panel.c	2012-05-12 09:57:39 UTC (rev 18273)
+++ trunk/spectrum/spec_panel.c	2012-05-12 20:16:05 UTC (rev 18274)
@@ -46,7 +46,9 @@
   GtkWidget *plot;
   GtkWidget *run;
   GtkWidget **chbuttons;
-  
+  GtkWidget *bwtable;
+  GtkWidget *bwbutton;
+  GtkWidget *bwmodebutton;
 } p;
 
 int plot_scale=0;
@@ -56,6 +58,8 @@
 int plot_depth=90;
 int plot_noise=0;
 int plot_last_update=0;
+int plot_bw=0;
+int plot_bwmode=0;
 int *active;
 
 static void replot(struct panel *p){
@@ -431,11 +435,29 @@
   acc_rewind=1;
 }
 
+static void bwchange(GtkWidget *widget,struct panel *p){
+  plot_bw=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+  if(plot_bw==0){
+    gtk_widget_hide(p->bwmodebutton);
+    gtk_container_remove(GTK_CONTAINER(p->bwtable),p->bwbutton);
+    gtk_table_attach_defaults(GTK_TABLE(p->bwtable),p->bwbutton,0,2,0,1);
+  }else{
+    gtk_container_remove(GTK_CONTAINER(p->bwtable),p->bwbutton);
+    gtk_table_attach_defaults(GTK_TABLE(p->bwtable),p->bwbutton,0,1,0,1);
+    gtk_widget_show(p->bwmodebutton);
+  }
+}
+
+static void bwmodechange(GtkWidget *widget,struct panel *p){
+  plot_bwmode=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+}
+
 extern char *version;
 void panel_create(struct panel *panel, int bold){
   int i;
 
   GtkWidget *topplace,*topal,*topalb;
+  GtkWidget *leftplace,*leftal,*leftalb;
 
   GtkWidget *topframe=gtk_frame_new (NULL);
   GtkWidget *toplabel=gtk_label_new (NULL);
@@ -497,8 +519,12 @@
 		    G_CALLBACK (shutdown), NULL);
 
   /* add the spectrum plot box */
+  leftplace=gtk_table_new(1,1,0);
   panel->plot=plot_new(blocksize/2+1,inputs,channels,rate,bold);
-  gtk_box_pack_end(GTK_BOX(leftbox),panel->plot,1,1,0);
+  gtk_table_attach_defaults(GTK_TABLE(leftplace),
+			    panel->plot,0,1,0,1);
+
+  gtk_box_pack_end(GTK_BOX(leftbox),leftplace,1,1,0);
   gtk_box_pack_start(GTK_BOX(mainbox),leftbox,1,1,0);
   
   /*fish */
@@ -560,31 +586,59 @@
 
   /* add the action buttons */
 
-  /* scale */
   {
-    GtkWidget *menu=gtk_combo_box_new_text();
-    char *entries[]={"log frequency","ISO frequency","linear frequency"};
+  /* bandwidth mode */
+    GtkWidget *tbox=panel->bwtable=gtk_table_new(2,2,0);
+
+    GtkWidget *menu=panel->bwbutton=gtk_combo_box_new_text();
+    char *entries[]={"native","display"};
+    //"1Hz","3Hz","10Hz","30Hz","100Hz","300Hz","1kHz",
+    //"1/24oct","1/12oct","1/6oct","1/3oct"};
+
+    for(i=0;i<2;i++)
+      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), entries[i]);
+    //gtk_combo_box_set_active(GTK_COMBO_BOX(menu),0);
+    
+    g_signal_connect (G_OBJECT (menu), "changed",
+    		      G_CALLBACK (bwchange), panel);
+
+    GtkWidget *menu2=panel->bwmodebutton=gtk_combo_box_new_text();
+    char *entries2[]={"RBW","VBW"};
+    for(i=0;i<2;i++)
+      gtk_combo_box_append_text (GTK_COMBO_BOX (menu2), entries2[i]);
+    
+    g_signal_connect (G_OBJECT (menu2), "changed",
+    		      G_CALLBACK (bwmodechange), panel);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(menu2),0);
+
+    gtk_table_attach_defaults(GTK_TABLE(tbox),menu,0,1,0,1);
+    gtk_table_attach_defaults(GTK_TABLE(tbox),menu2,1,2,0,1);
+
+    /* scale */
+    /* depth */
+
+    GtkWidget *menu3=gtk_combo_box_new_text();
+    char *entries3[]={"log freq","ISO freq","linear freq"};
     for(i=0;i<3;i++)
-      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), entries[i]);
-    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),plot_scale);
+      gtk_combo_box_append_text (GTK_COMBO_BOX (menu3), entries3[i]);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(menu3),plot_scale);
     plot_setting(PLOT(panel->plot),plot_scale,plot_mode,plot_link,plot_depth,plot_noise);
-    gtk_box_pack_start(GTK_BOX(bbox),menu,0,0,0);
     
-    g_signal_connect (G_OBJECT (menu), "changed",
+    g_signal_connect (G_OBJECT (menu3), "changed",
 		      G_CALLBACK (scalechange), panel);
-  }
-  
-  /* depth */
-  {
-    GtkWidget *menu=gtk_combo_box_new_text();
-    char *entries[]={"1dB","10dB","20dB","45dB","90dB","140dB","200dB"};
+
+    GtkWidget *menu4=gtk_combo_box_new_text();
+    char *entries4[]={"1dB","10dB","20dB","45dB","90dB","140dB","200dB"};
     for(i=0;i<7;i++)
-      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), entries[i]);
-    gtk_box_pack_start(GTK_BOX(bbox),menu,0,0,0);
+      gtk_combo_box_append_text (GTK_COMBO_BOX (menu4), entries4[i]);
     
-    g_signal_connect (G_OBJECT (menu), "changed",
+    g_signal_connect (G_OBJECT (menu4), "changed",
 		      G_CALLBACK (depthchange), panel);
-    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),4);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(menu4),4);
+
+    gtk_table_attach_defaults(GTK_TABLE(tbox),menu3,0,1,1,2);
+    gtk_table_attach_defaults(GTK_TABLE(tbox),menu4,1,2,1,2);
+    gtk_box_pack_start(GTK_BOX(bbox),tbox,0,0,0);
   }
   
   /* mode */
@@ -612,6 +666,7 @@
 		      G_CALLBACK (linkchange), panel);
   }
   
+
   {
     GtkWidget *sep=gtk_hseparator_new();
     gtk_box_pack_start(GTK_BOX(bbox),sep,0,0,4);
@@ -686,6 +741,7 @@
 
     
   gtk_widget_show_all(panel->toplevel);
+  gtk_combo_box_set_active(GTK_COMBO_BOX(panel->bwbutton),0);
   //gtk_window_set_resizable(GTK_WINDOW(panel->toplevel),0);
 
 }

Modified: trunk/spectrum/spec_plot.c
===================================================================
--- trunk/spectrum/spec_plot.c	2012-05-12 09:57:39 UTC (rev 18273)
+++ trunk/spectrum/spec_plot.c	2012-05-12 20:16:05 UTC (rev 18274)
@@ -248,6 +248,20 @@
     gdk_gc_set_line_attributes(p->dashes, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_MITER);
     gdk_gc_set_dashes(p->dashes,0,(signed char *)"\002\002",2);
   }
+  if(!p->graygc){
+    GdkColor rgb_bg;
+    GdkColor rgb_fg;
+    GdkGCValues v;
+    p->graygc=gdk_gc_new(p->backing);
+    gdk_gc_copy(p->graygc, p->drawgc);
+    gdk_gc_get_values(p->graygc,&v);
+    gdk_colormap_query_color(gdk_gc_get_colormap(p->graygc),v.foreground.pixel,&rgb_fg);
+    gdk_colormap_query_color(gdk_gc_get_colormap(p->graygc),v.background.pixel,&rgb_bg);
+    rgb_fg.red = (rgb_fg.red*3 + rgb_bg.red*2)/5;
+    rgb_fg.green = (rgb_fg.green*3 + rgb_bg.green*2)/5;
+    rgb_fg.blue = (rgb_fg.blue*3 + rgb_bg.blue*2)/5;
+    gdk_gc_set_rgb_fg_color(p->graygc,&rgb_fg);
+  }
 
   {
     const GdkRectangle clip = {p->padx,0,width-p->padx,height-p->pady};
@@ -462,28 +476,84 @@
     ymin = (p->disp_ymax - p->disp_depth)*1000;
     yval = rint((p->disp_ymax*1000/majordel)+1)*majordel;
 
-    while(1){
-      float ydel = (yval - ymin)/(p->disp_depth*1000);
-      int ymid = rint(height-p->pady-1 - (height-p->pady) * ydel);
+    {
+      int px,py,pxdB,pxN,pxMAX;
+      pango_layout_get_pixel_size(p->db_layoutN,&pxN,&py);
+      pango_layout_get_pixel_size(p->db_layoutdB,&pxdB,&py);
+      pango_layout_get_pixel_size(p->db_layout[0],&pxMAX,&py);
+      pxMAX+=pxdB;
 
-      if(ymid>=height-p->pady)break;
+      while(1){
+        float ydel = (yval - ymin)/(p->disp_depth*1000);
+        int ymid = rint(height-p->pady-1 - (height-p->pady) * ydel);
 
-      if(ymid>=0){
-        int px,py;
-        int label = yval/100+2000;
+        if(ymid>=height-p->pady)break;
 
-        if(label>=0 && label<=4000  && ymid+py/2 < height-p->pady){
-          pango_layout_get_pixel_size(p->db_layout[yval/100+2000],&px,&py);
+        if(ymid>=0){
+          int do_dB=0;
+          int label = yval/100+2000;
 
-          gdk_draw_layout (p->backing,
-                           widget->style->black_gc,
-                           padx-px-2, ymid-py/2,
-                           p->db_layout[yval/100+2000]);
+          if(label>=0 && label<=4000 /* in range check */
+             && (p->scale<2 || ymid+py/2 < height-p->pady) /* don't collide with DC label */
+             ){
+
+            if(label%10){ /* fractional (decimal) dB */
+              int sofar=0;
+              /*  -.9dB
+                 -9.9dB
+                  -99.9
+                 -999.9 */
+
+              if(fabsf(yval*.001)<9.98){
+                gdk_draw_layout (p->backing,
+                                 p->graygc,
+                                 padx-pxdB-2, ymid-py/2,
+                                 p->db_layoutdB);
+                sofar+=pxdB;
+              }
+
+              pango_layout_get_pixel_size(p->db_layout1[abs(yval/100)%10],&px,&py);
+              sofar+=px;
+              gdk_draw_layout (p->backing,
+                               p->graygc,
+                               padx-sofar-2, ymid-py/2,
+                               p->db_layout1[abs(yval/100)%10]);
+
+              if(yval/1000!=0){ /* no leading zero please */
+                pango_layout_get_pixel_size(p->db_layout[yval/1000+200],&px,&py);
+                sofar+=px;
+                gdk_draw_layout (p->backing,
+                                 p->graygc,
+                                 padx-sofar-2, ymid-py/2,
+                                 p->db_layout[yval/1000+200]);
+              }else{
+                if(yval<0){
+                  /* need to explicitly place negative */
+                  sofar+=pxN;
+                  gdk_draw_layout (p->backing,
+                                   p->graygc,
+                                   padx-sofar-2, ymid-py/2,
+                                   p->db_layoutN);
+                }
+              }
+            }else{
+              gdk_draw_layout (p->backing,
+                               widget->style->black_gc,
+                               padx-pxdB-2, ymid-py/2,
+                               p->db_layoutdB);
+
+              pango_layout_get_pixel_size(p->db_layout[yval/1000+200],&px,&py);
+
+              gdk_draw_layout (p->backing,
+                               widget->style->black_gc,
+                               padx-px-pxdB-2, ymid-py/2,
+                               p->db_layout[yval/1000+200]);
+            }
+          }
+          gdk_draw_line(p->backing,p->drawgc,padx,ymid,width,ymid);
         }
-
-        gdk_draw_line(p->backing,p->drawgc,padx,ymid,width,ymid);
+        yval-=majordel;
       }
-      yval-=majordel;
     }
   }
 
@@ -706,14 +776,15 @@
   /* find max db layout */
   {
     int max=0;
-    for(i=0;p->db_layout[i];i++){
-      pango_layout_get_pixel_size(p->db_layout[i],&px,&py);
-      if(px>padx)padx=px;
-    }
+    int px2;
+    pango_layout_get_pixel_size(p->db_layoutdB,&px2,&py);
+    pango_layout_get_pixel_size(p->db_layout[0],&px,&py);
+    if(px+px2>padx)padx=px+px2;
     axisy=(max)*8;
     if(axisy<max)axisy=max;
   }
   /* find max imped layout */
+#if 0
   {
     int max=0;
     for(i=0;p->imp_layout[i];i++){
@@ -724,6 +795,8 @@
     axisy=(max)*8;
     if(axisy<max)axisy=max;
   }
+#endif
+
   /* find max phase layout */
   {
     int max=0;
@@ -902,18 +975,28 @@
     for(i=0;i<12;i++)
       p->iso_layout[i]=gtk_widget_create_pango_layout(ret,labels[i]);
   }
-  /* dB Y scale */
+  /* dB Y scale (integer) */
   {
     char buf[10];
-    p->db_layout=calloc(4002,sizeof(*p->db_layout));
-    for(i=-2000;i<=2000;i++){
-      if(i%10==0)
-        snprintf(buf,10,"%ddB",i/10);
-      else
-        snprintf(buf,10,"%.1fdB",i*.1);
-      p->db_layout[i+2000]=gtk_widget_create_pango_layout(ret,buf);
+    p->db_layout=calloc(402,sizeof(*p->db_layout));
+    for(i=-200;i<=200;i++){
+      snprintf(buf,10," %d",i);
+      p->db_layout[i+200]=gtk_widget_create_pango_layout(ret,buf);
     }
   }
+  /* dB Y scale (decimal) */
+  {
+    char buf[10];
+    p->db_layout1=calloc(10,sizeof(*p->db_layout1));
+    for(i=0;i<10;i++){
+      snprintf(buf,10,".%d",i);
+      p->db_layout1[i]=gtk_widget_create_pango_layout(ret,buf);
+    }
+  }
+  /* dB Y scale (dB) */
+  p->db_layoutdB=gtk_widget_create_pango_layout(ret,"dB");
+  /* dB Y scale (-) */
+  p->db_layoutN=gtk_widget_create_pango_layout(ret,"-");
 
   p->ch_active=calloc(ch,sizeof(*p->ch_active));
   p->ch_process=calloc(ch,sizeof(*p->ch_process));

Modified: trunk/spectrum/spec_plot.h
===================================================================
--- trunk/spectrum/spec_plot.h	2012-05-12 09:57:39 UTC (rev 18273)
+++ trunk/spectrum/spec_plot.h	2012-05-12 20:16:05 UTC (rev 18274)
@@ -47,11 +47,15 @@
   GdkPixmap *backing;
   GdkGC     *drawgc;
   GdkGC     *dashes;
+  GdkGC     *graygc;
 
   PangoLayout **lin_layout;
   PangoLayout **log_layout;
   PangoLayout **iso_layout;
   PangoLayout **db_layout;
+  PangoLayout **db_layout1;
+  PangoLayout *db_layoutdB;
+  PangoLayout *db_layoutN;
   PangoLayout **imp_layout;
   PangoLayout **phase_layout;
 

Modified: trunk/spectrum/version.h
===================================================================
--- trunk/spectrum/version.h	2012-05-12 09:57:39 UTC (rev 18273)
+++ trunk/spectrum/version.h	2012-05-12 20:16:05 UTC (rev 18274)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Sat May 12 03:47:45 EDT 2012] */
+/* DO NOT EDIT: Automated versioning hack [Sat May 12 16:14:18 EDT 2012] */



More information about the commits mailing list