deverbpanel.c 9.07 KB
Newer Older
1 2 3 4
/*
 *
 *  postfish
 *    
Monty Montgomery's avatar
Monty Montgomery committed
5
 *      Copyright (C) 2002-2005 Monty
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
 *
 *  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"
32 33
#include "deverb.h"
#include "deverbpanel.h"
34
#include "config.h"
35 36 37 38

typedef struct {
  GtkWidget *cslider;
  Readout *readoutc;
39
  struct deverb_panel_state *sp;
40
  sig_atomic_t *v;
41 42 43
  int number;
} tbar;

44
typedef struct{
45
  Multibar *s;
46 47 48 49
  Readout *r0;
  Readout *r1;
  sig_atomic_t *v0;
  sig_atomic_t *v1;
50
} callback_arg_rv2;
51

52
typedef struct deverb_panel_state{
53 54 55
  subpanel_generic *panel;

  GtkWidget        *link;
56
  callback_arg_rv2  timing;
57 58
  tbar              bars[deverb_freqs];
} deverb_panel_state;
59

60
static deverb_panel_state *channel_panel;
61

62 63 64 65 66 67
void deverbpanel_state_to_config(int bank){
  config_set_vector("deverbpanel_active",bank,0,0,0,input_ch,deverb_channel_set.active);
  config_set_vector("deverbpanel_ratio",bank,0,0,0,deverb_freqs,deverb_channel_set.ratio);
  config_set_integer("deverbpanel_set",bank,0,0,0,0,deverb_channel_set.linkp);
  config_set_integer("deverbpanel_set",bank,0,0,0,1,deverb_channel_set.smooth);
  config_set_integer("deverbpanel_set",bank,0,0,0,3,deverb_channel_set.release);
68 69
}

70
void deverbpanel_state_from_config(int bank){
71 72
  int i;

73
  config_get_vector("deverbpanel_active",bank,0,0,0,input_ch,deverb_channel_set.active);
74 75 76 77
  if(channel_panel)
    for(i=0;i<input_ch;i++)
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(channel_panel->panel->subpanel_activebutton[i]),
                                   deverb_channel_set.active[i]);
78

79
  config_get_vector("deverbpanel_ratio",bank,0,0,0,deverb_freqs,deverb_channel_set.ratio);
80 81 82 83
  if(channel_panel)
    for(i=0;i<deverb_freqs;i++)
      multibar_thumb_set(MULTIBAR(channel_panel->bars[i].cslider),
                         1000./deverb_channel_set.ratio[i],0);
84

85
  config_get_sigat("deverbpanel_set",bank,0,0,0,0,&deverb_channel_set.linkp);
86 87
  if(channel_panel)
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(channel_panel->link),deverb_channel_set.linkp);
88
  
89
  config_get_sigat("deverbpanel_set",bank,0,0,0,1,&deverb_channel_set.smooth);
90 91
  if(channel_panel)
    multibar_thumb_set(MULTIBAR(channel_panel->timing.s),deverb_channel_set.smooth*.1,0);
92

93
  config_get_sigat("deverbpanel_set",bank,0,0,0,3,&deverb_channel_set.release);
94 95
  if(channel_panel)
    multibar_thumb_set(MULTIBAR(channel_panel->timing.s),deverb_channel_set.release*.1,1);
96 97
}

98 99 100 101 102 103 104 105
static void compand_change(GtkWidget *w,gpointer in){
  char buffer[80];
  tbar *bar=(tbar *)in;
  float val=multibar_get_value(MULTIBAR(w),0);

  if(val==1.){
    sprintf(buffer,"   off");
  }else 
106
    sprintf(buffer,"  %4.2f",val);
107 108 109

  readout_set(bar->readoutc,buffer);
  
110
  *bar->v=1000./val;
111 112 113
}

static void timing_change(GtkWidget *w,gpointer in){
114
  callback_arg_rv2 *ca=(callback_arg_rv2 *)in;
115 116
  char buffer[80];
  float smooth=multibar_get_value(MULTIBAR(w),0);
117
  float release=multibar_get_value(MULTIBAR(w),1);
118 119 120 121 122 123 124 125 126 127
  
  if(smooth<100){
    sprintf(buffer,"%4.1fms",smooth);
  }else if (smooth<1000){
    sprintf(buffer,"%4.0fms",smooth);
  }else if (smooth<10000){
    sprintf(buffer," %4.2fs",smooth/1000.);
  }else{
    sprintf(buffer," %4.1fs",smooth/1000.);
  }
128
  readout_set(ca->r0,buffer);
129 130 131 132 133 134 135 136 137 138

  if(release<100){
    sprintf(buffer,"%4.1fms",release);
  }else if (release<1000){
    sprintf(buffer,"%4.0fms",release);
  }else if (release<10000){
    sprintf(buffer," %4.2fs",release/1000.);
  }else{
    sprintf(buffer," %4.1fs",release/1000.);
  }
139
  readout_set(ca->r1,buffer);
140

141
  *ca->v0=rint(smooth*10.);
142
  *ca->v1=rint(release*10.);
143 144
}

145
static void deverb_link(GtkToggleButton *b,gpointer in){
146
  int mode=gtk_toggle_button_get_active(b);
147
  *((sig_atomic_t *)in)=mode;
148 149
}

150
static deverb_panel_state *deverbpanel_create_helper(postfish_mainpanel *mp,
151
							 subpanel_generic *panel,
152
							 deverb_settings *sset){
153 154
  int i;
  float compand_levels[5]={1,1.5,2,3,5};
155
  char  *compand_labels[5]={"","1.5","2","3","5"};
156

157 158
  float timing_levels[5]={10, 40, 100, 400, 1000};
  char  *timing_labels[5]={"","40ms","     100ms","400ms","1s"};
159

160 161
  GtkWidget *table=gtk_table_new(deverb_freqs+4,4,0);
  GtkWidget *timinglabel=gtk_label_new("deverberator filter timing");
162 163
  GtkWidget *releaselabel=gtk_label_new("release");
  GtkWidget *smoothlabel=gtk_label_new("smooth");
164
  GtkWidget *compandlabel=gtk_label_new("deverb depth");
165 166 167 168 169

  GtkWidget *linkbutton=
    gtk_check_button_new_with_mnemonic("_link channels into single image");
  GtkWidget *linkbox=gtk_hbox_new(0,0);

170
  deverb_panel_state *ps=calloc(1,sizeof(deverb_panel_state));
171
  ps->panel=panel;
172

173 174 175 176 177 178 179 180 181 182 183 184
  gtk_container_add(GTK_CONTAINER(panel->subpanel_box),table);

  gtk_box_pack_end(GTK_BOX(linkbox),linkbutton,0,0,0);

  gtk_table_attach(GTK_TABLE(table),timinglabel,0,2,0,1,
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,5);
  gtk_table_attach(GTK_TABLE(table),smoothlabel,2,3,0,1,
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,0);
185
  gtk_table_attach(GTK_TABLE(table),releaselabel,3,4,0,1,
186 187 188
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,0);
189
  gtk_table_attach(GTK_TABLE(table),compandlabel,0,3,2,3,
190 191 192 193
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,5);
  if(input_ch>1)
194 195
    gtk_table_attach(GTK_TABLE(table),linkbox,0,4,deverb_freqs+3,
		     deverb_freqs+4,GTK_FILL|GTK_EXPAND,0,0,10);
196 197 198 199 200 201 202 203 204 205 206 207 208

  gtk_table_set_row_spacing(GTK_TABLE(table),1,5);
  
  gtk_misc_set_alignment(GTK_MISC(timinglabel),0,1.);
  gtk_widget_set_name(timinglabel,"framelabel");
  gtk_misc_set_alignment(GTK_MISC(smoothlabel),.5,1.);
  gtk_widget_set_name(smoothlabel,"scalemarker");
  gtk_misc_set_alignment(GTK_MISC(releaselabel),.5,1.);
  gtk_widget_set_name(releaselabel,"scalemarker");
  gtk_misc_set_alignment(GTK_MISC(compandlabel),0,1.);
  gtk_widget_set_name(compandlabel,"framelabel");

  g_signal_connect (G_OBJECT (linkbutton), "clicked",
209
		    G_CALLBACK (deverb_link), &sset->linkp);
210
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(linkbutton),1);
211
  ps->link=linkbutton;
212 213 214

  /* timing controls */
  {
215
    GtkWidget *slider=multibar_slider_new(5,timing_labels,timing_levels,2);
216

217 218
    ps->timing.s=MULTIBAR(slider);

219 220 221 222
    ps->timing.r0=READOUT(readout_new("10.0ms"));
    ps->timing.r1=READOUT(readout_new("10.0ms"));

    ps->timing.v0=&sset->smooth;
223
    ps->timing.v1=&sset->release;
224 225

    multibar_callback(MULTIBAR(slider),timing_change,&ps->timing);
226
    
227
    multibar_thumb_set(MULTIBAR(slider),40,0);
228
    multibar_thumb_set(MULTIBAR(slider),400,1);
229 230 231

    gtk_table_attach(GTK_TABLE(table),slider,1,2,1,2,
		     GTK_FILL|GTK_EXPAND,GTK_EXPAND,5,0);
232
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->timing.r0),2,3,1,2,
233
		     0,0,0,0);
234
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->timing.r1),3,4,1,2,
235 236 237 238 239
		     0,0,0,0);
  }

  /* threshold controls */

240 241
  for(i=0;i<deverb_freqs;i++){
    GtkWidget *label=gtk_label_new(deverb_freq_labels[i]);
242 243
    gtk_widget_set_name(label,"scalemarker");
    
244
    ps->bars[i].readoutc=READOUT(readout_new("1.55:1"));
245
    ps->bars[i].cslider=multibar_slider_new(5,compand_labels,compand_levels,1);
246 247 248 249 250
    ps->bars[i].sp=ps;
    ps->bars[i].v=sset->ratio+i;
    ps->bars[i].number=i;

    multibar_callback(MULTIBAR(ps->bars[i].cslider),compand_change,ps->bars+i);
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

    switch(i){
    case 0:
      multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.,0);
      break;
    case 1:
      multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.3,0);
      break;
    case 2:case 3: case 4: case 5: 
      multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.7,0);
      break;
    case 6:
      multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.3,0);
      break;
    case 7:
      multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1,0);
      break;
    }

270 271 272 273 274
    gtk_misc_set_alignment(GTK_MISC(label),1,.5);
      
    gtk_table_attach(GTK_TABLE(table),label,0,1,i+3,i+4,
		     GTK_FILL,0,0,0);

275
    gtk_table_attach(GTK_TABLE(table),ps->bars[i].cslider,1,3,i+3,i+4,
276
		     GTK_FILL|GTK_EXPAND,GTK_EXPAND,5,0);
277
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->bars[i].readoutc),3,4,
278 279 280 281
		     i+3,i+4,0,0,0,0);
  }
  subpanel_show_all_but_toplevel(panel);

282
  return ps;
283 284
}

285
void deverbpanel_create_channel(postfish_mainpanel *mp,
286 287 288 289
				  GtkWidget **windowbutton,
				  GtkWidget **activebutton){
	     
  subpanel_generic *panel=subpanel_create(mp,windowbutton[0],activebutton,
290 291
					  deverb_channel_set.active,
					  &deverb_channel_set.panel_visible,
292 293 294
					  "De_verberation filter",0,
					  0,input_ch);
  
295
  channel_panel=deverbpanel_create_helper(mp,panel,&deverb_channel_set);
296
}