limitpanel.c 5.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/*
 *
 *  postfish
 *    
 *      Copyright (C) 2002-2004 Monty
 *
 *  Postfish is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  Postfish is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

#include "postfish.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "readout.h"
#include "multibar.h"
#include "mainpanel.h"
#include "subpanel.h"
#include "feedback.h"
#include "limit.h"
#include "limitpanel.h"

extern sig_atomic_t limit_active;
extern sig_atomic_t limit_visible;
extern int input_size;
extern int input_rate;

extern limit_settings limitset;

static GtkWidget *t_slider;
static GtkWidget *a_slider;

static void limit_change(GtkWidget *w,gpointer in){
  char buffer[80];
  Readout *r=(Readout *)in;
  float val=multibar_get_value(MULTIBAR(w),0);

  sprintf(buffer,"%+5.1fdB",val);
  readout_set(r,buffer);
  
  limitset.thresh=rint(val*10.);
}

static void depth_change(GtkWidget *w,gpointer in){
  char buffer[80];
  Readout *r=(Readout *)in;
  float val=multibar_get_value(MULTIBAR(w),0);

  sprintf(buffer,"%+5.1fdB",val);
  readout_set(r,buffer);
  
  limitset.depth=rint(val*10.);
}

static void decay_change(GtkWidget *w,gpointer in){
  char buffer[80];
  Readout *r=(Readout *)in;
  float v=multibar_get_value(MULTIBAR(w),0);


  if(v<10){
    sprintf(buffer," %4.2fms",v);
  }else if(v<100){
    sprintf(buffer," %4.1fms",v);
  }else if (v<1000){
    sprintf(buffer," %4.0fms",v);
  }else if (v<10000){
    sprintf(buffer," %4.2fs",v/1000.);
  }else{
    sprintf(buffer," %4.1fs",v/1000.);
  }

  readout_set(READOUT(r),buffer);

  limitset.decay=rint(v*10.);
}

void limitpanel_create(postfish_mainpanel *mp,
		       GtkWidget *windowbutton,
		       GtkWidget *activebutton){


95
  char *labels[9]={"","-80","-60","-40","-20","-10","-6","-3","+0"};
96 97
  float levels[9]={-80,-60,-50,-40,-30,-10,-6,-3,0};

98
  char *labels2[5]={"","-20","-10","-3","0"};
99 100
  float levels2[5]={-30,-20,-10,-3,0};
  
101
  char *rlabels[4]={"","6","   20","40"};
102 103 104
  float rlevels[4]={0,3,10,20};

  float timing_levels[6]={.1,1,10,100,1000,10000};
105
  char  *timing_labels[6]={"","1ms","10ms","100ms","1s","10s"};
106

107 108 109
  char *shortcut[]={" l "};

  subpanel_generic *panel=subpanel_create(mp,windowbutton,&activebutton,
110 111
					  &limit_active,
					  &limit_visible,
112 113
					  "Hard _Limiter",shortcut,
					  0,1);
114 115 116
  
  GtkWidget *slidertable=gtk_table_new(4,4,0);

117
  GtkWidget *label1=gtk_label_new("knee bend");
118 119 120 121 122 123 124 125
  GtkWidget *label2=gtk_label_new("knee depth");
  GtkWidget *label3=gtk_label_new("decay speed");
  GtkWidget *label4=gtk_label_new("attenuation");

  GtkWidget *readout1=readout_new("+XXXXdB");
  GtkWidget *readout2=readout_new("+XXXXdB");
  GtkWidget *readout3=readout_new("+XXXXms");

126 127
  GtkWidget *slider2=multibar_slider_new(5,labels2,levels2,1);
  GtkWidget *slider3=multibar_slider_new(6,timing_labels,timing_levels,1);
128

129 130
  t_slider=multibar_new(9,labels,levels,1,HI_DECAY);
  a_slider=multibar_new(4,rlabels,rlevels,0,0);
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

  gtk_misc_set_alignment(GTK_MISC(label1),1,.5);
  gtk_misc_set_alignment(GTK_MISC(label2),1,.5);
  gtk_misc_set_alignment(GTK_MISC(label3),1,.5);
  gtk_widget_set_name(label4,"scalemarker");

  gtk_table_attach(GTK_TABLE(slidertable),label1,0,1,1,2,GTK_FILL,GTK_FILL|GTK_EXPAND,2,0);
  gtk_table_attach(GTK_TABLE(slidertable),label2,0,1,2,3,GTK_FILL,GTK_FILL|GTK_EXPAND,2,0);
  gtk_table_attach(GTK_TABLE(slidertable),label3,0,1,3,4,GTK_FILL,GTK_FILL|GTK_EXPAND,2,0);
  gtk_table_attach(GTK_TABLE(slidertable),label4,3,4,0,1,GTK_FILL,GTK_FILL|GTK_EXPAND,0,0);
 
  gtk_table_attach(GTK_TABLE(slidertable),t_slider,1,2,1,2,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,0,0);
  gtk_table_attach(GTK_TABLE(slidertable),a_slider,3,4,1,2,GTK_FILL,GTK_FILL|GTK_EXPAND,0,0);
  gtk_table_attach(GTK_TABLE(slidertable),slider2,1,2,2,3,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,0,4);
  gtk_table_attach(GTK_TABLE(slidertable),slider3,1,2,3,4,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,0,0);

  gtk_table_attach(GTK_TABLE(slidertable),readout1,2,3,1,2,GTK_FILL,GTK_FILL|GTK_EXPAND,0,0);
  gtk_table_attach(GTK_TABLE(slidertable),readout2,2,3,2,3,GTK_FILL,GTK_FILL|GTK_EXPAND,0,4);
  gtk_table_attach(GTK_TABLE(slidertable),readout3,2,3,3,4,GTK_FILL,GTK_FILL|GTK_EXPAND,0,0);

  gtk_container_add(GTK_CONTAINER(panel->subpanel_box),slidertable);

  multibar_callback(MULTIBAR(t_slider),limit_change,readout1);
  multibar_callback(MULTIBAR(slider2),depth_change,readout2);
  multibar_callback(MULTIBAR(slider3),decay_change,readout3);

  multibar_thumb_set(MULTIBAR(t_slider),0.,0);
  multibar_thumb_set(MULTIBAR(slider2),0.,0);
  multibar_thumb_set(MULTIBAR(slider3),10.,0);
  
  subpanel_show_all_but_toplevel(panel);

}

static float *peakfeed=0;
static float *attfeed=0;
static float *zerofeed=0;

void limitpanel_feedback(int displayit){
  if(!peakfeed){
    int i;
172 173 174 175
    peakfeed=malloc(sizeof(*peakfeed)*OUTPUT_CHANNELS);
    attfeed=malloc(sizeof(*attfeed)*OUTPUT_CHANNELS);
    zerofeed=malloc(sizeof(*zerofeed)*OUTPUT_CHANNELS);
    for(i=0;i<OUTPUT_CHANNELS;i++)zerofeed[i]=-150.;
176 177 178 179
  }
  
  if(pull_limit_feedback(peakfeed,attfeed)==1){
    multibar_set(MULTIBAR(t_slider),zerofeed,peakfeed,
180
		 OUTPUT_CHANNELS,(displayit && limit_visible));
181
    multibar_set(MULTIBAR(a_slider),zerofeed,attfeed,
182
		 OUTPUT_CHANNELS,(displayit && limit_visible));
183 184 185 186 187 188 189 190
  }
}

void limitpanel_reset(void){
  multibar_reset(MULTIBAR(t_slider));
  multibar_reset(MULTIBAR(a_slider));
}