deverbpanel.c 8.92 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
/*
 *
 *  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"
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
  for(i=0;i<input_ch;i++)
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(channel_panel->panel->subpanel_activebutton[i]),
76
				 deverb_channel_set.active[i]);
77

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

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

89 90
  config_get_sigat("deverbpanel_set",bank,0,0,0,3,&deverb_channel_set.release);
  multibar_thumb_set(MULTIBAR(channel_panel->timing.s),deverb_channel_set.release*.1,1);
91 92
}

93 94 95 96 97 98 99 100
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 
101
    sprintf(buffer,"  %4.2f",val);
102 103 104

  readout_set(bar->readoutc,buffer);
  
105
  *bar->v=1000./val;
106 107 108
}

static void timing_change(GtkWidget *w,gpointer in){
109
  callback_arg_rv2 *ca=(callback_arg_rv2 *)in;
110 111
  char buffer[80];
  float smooth=multibar_get_value(MULTIBAR(w),0);
112
  float release=multibar_get_value(MULTIBAR(w),1);
113 114 115 116 117 118 119 120 121 122
  
  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.);
  }
123
  readout_set(ca->r0,buffer);
124 125 126 127 128 129 130 131 132 133

  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.);
  }
134
  readout_set(ca->r1,buffer);
135

136
  *ca->v0=rint(smooth*10.);
137
  *ca->v1=rint(release*10.);
138 139
}

140
static void deverb_link(GtkToggleButton *b,gpointer in){
141
  int mode=gtk_toggle_button_get_active(b);
142
  *((sig_atomic_t *)in)=mode;
143 144
}

145
static deverb_panel_state *deverbpanel_create_helper(postfish_mainpanel *mp,
146
							 subpanel_generic *panel,
147
							 deverb_settings *sset){
148 149
  int i;
  float compand_levels[5]={1,1.5,2,3,5};
150
  char  *compand_labels[5]={"","1.5","2","3","5"};
151

152 153
  float timing_levels[5]={10, 40, 100, 400, 1000};
  char  *timing_labels[5]={"","40ms","     100ms","400ms","1s"};
154

155 156
  GtkWidget *table=gtk_table_new(deverb_freqs+4,4,0);
  GtkWidget *timinglabel=gtk_label_new("deverberator filter timing");
157 158
  GtkWidget *releaselabel=gtk_label_new("release");
  GtkWidget *smoothlabel=gtk_label_new("smooth");
159
  GtkWidget *compandlabel=gtk_label_new("deverb depth");
160 161 162 163 164

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

165
  deverb_panel_state *ps=calloc(1,sizeof(deverb_panel_state));
166
  ps->panel=panel;
167

168 169 170 171 172 173 174 175 176 177 178 179
  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);
180
  gtk_table_attach(GTK_TABLE(table),releaselabel,3,4,0,1,
181 182 183
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,0);
184
  gtk_table_attach(GTK_TABLE(table),compandlabel,0,3,2,3,
185 186 187 188
		   GTK_EXPAND|GTK_FILL,
		   GTK_EXPAND|GTK_FILL,
		   0,5);
  if(input_ch>1)
189 190
    gtk_table_attach(GTK_TABLE(table),linkbox,0,4,deverb_freqs+3,
		     deverb_freqs+4,GTK_FILL|GTK_EXPAND,0,0,10);
191 192 193 194 195 196 197 198 199 200 201 202 203

  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",
204
		    G_CALLBACK (deverb_link), &sset->linkp);
205
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(linkbutton),1);
206
  ps->link=linkbutton;
207 208 209

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

212 213
    ps->timing.s=MULTIBAR(slider);

214 215 216 217
    ps->timing.r0=READOUT(readout_new("10.0ms"));
    ps->timing.r1=READOUT(readout_new("10.0ms"));

    ps->timing.v0=&sset->smooth;
218
    ps->timing.v1=&sset->release;
219 220

    multibar_callback(MULTIBAR(slider),timing_change,&ps->timing);
221
    
222 223
    multibar_thumb_set(MULTIBAR(slider),100,0);
    multibar_thumb_set(MULTIBAR(slider),400,1);
224 225 226

    gtk_table_attach(GTK_TABLE(table),slider,1,2,1,2,
		     GTK_FILL|GTK_EXPAND,GTK_EXPAND,5,0);
227
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->timing.r0),2,3,1,2,
228
		     0,0,0,0);
229
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->timing.r1),3,4,1,2,
230 231 232 233 234
		     0,0,0,0);
  }

  /* threshold controls */

235 236
  for(i=0;i<deverb_freqs;i++){
    GtkWidget *label=gtk_label_new(deverb_freq_labels[i]);
237 238
    gtk_widget_set_name(label,"scalemarker");
    
239
    ps->bars[i].readoutc=READOUT(readout_new("1.55:1"));
240
    ps->bars[i].cslider=multibar_slider_new(5,compand_labels,compand_levels,1);
241 242 243 244 245
    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);
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264

    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;
    }

265 266 267 268 269
    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);

270
    gtk_table_attach(GTK_TABLE(table),ps->bars[i].cslider,1,3,i+3,i+4,
271
		     GTK_FILL|GTK_EXPAND,GTK_EXPAND,5,0);
272
    gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(ps->bars[i].readoutc),3,4,
273 274 275 276
		     i+3,i+4,0,0,0,0);
  }
  subpanel_show_all_but_toplevel(panel);

277
  return ps;
278 279
}

280
void deverbpanel_create_channel(postfish_mainpanel *mp,
281 282 283 284
				  GtkWidget **windowbutton,
				  GtkWidget **activebutton){
	     
  subpanel_generic *panel=subpanel_create(mp,windowbutton[0],activebutton,
285 286
					  deverb_channel_set.active,
					  &deverb_channel_set.panel_visible,
287 288 289
					  "De_verberation filter",0,
					  0,input_ch);
  
290
  channel_panel=deverbpanel_create_helper(mp,panel,&deverb_channel_set);
291
}