Merge r14152 from theora-exp.
[xiph/unicode.git] / postfish / deverbpanel.c
blob939f66f6884ee897402305bb37ac3b167ac98143
1 /*
3 * postfish
4 *
5 * Copyright (C) 2002-2005 Monty
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "postfish.h"
25 #include <gtk/gtk.h>
26 #include <gdk/gdkkeysyms.h>
27 #include "readout.h"
28 #include "multibar.h"
29 #include "mainpanel.h"
30 #include "subpanel.h"
31 #include "feedback.h"
32 #include "deverb.h"
33 #include "deverbpanel.h"
34 #include "config.h"
36 typedef struct {
37 GtkWidget *cslider;
38 Readout *readoutc;
39 struct deverb_panel_state *sp;
40 sig_atomic_t *v;
41 int number;
42 } tbar;
44 typedef struct{
45 Multibar *s;
46 Readout *r0;
47 Readout *r1;
48 sig_atomic_t *v0;
49 sig_atomic_t *v1;
50 } callback_arg_rv2;
52 typedef struct deverb_panel_state{
53 subpanel_generic *panel;
55 GtkWidget *link;
56 callback_arg_rv2 timing;
57 tbar bars[deverb_freqs];
58 } deverb_panel_state;
60 static deverb_panel_state *channel_panel;
62 void deverbpanel_state_to_config(int bank){
63 config_set_vector("deverbpanel_active",bank,0,0,0,input_ch,deverb_channel_set.active);
64 config_set_vector("deverbpanel_ratio",bank,0,0,0,deverb_freqs,deverb_channel_set.ratio);
65 config_set_integer("deverbpanel_set",bank,0,0,0,0,deverb_channel_set.linkp);
66 config_set_integer("deverbpanel_set",bank,0,0,0,1,deverb_channel_set.smooth);
67 config_set_integer("deverbpanel_set",bank,0,0,0,3,deverb_channel_set.release);
70 void deverbpanel_state_from_config(int bank){
71 int i;
73 config_get_vector("deverbpanel_active",bank,0,0,0,input_ch,deverb_channel_set.active);
74 for(i=0;i<input_ch;i++)
75 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(channel_panel->panel->subpanel_activebutton[i]),
76 deverb_channel_set.active[i]);
78 config_get_vector("deverbpanel_ratio",bank,0,0,0,deverb_freqs,deverb_channel_set.ratio);
79 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);
83 config_get_sigat("deverbpanel_set",bank,0,0,0,0,&deverb_channel_set.linkp);
84 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(channel_panel->link),deverb_channel_set.linkp);
86 config_get_sigat("deverbpanel_set",bank,0,0,0,1,&deverb_channel_set.smooth);
87 multibar_thumb_set(MULTIBAR(channel_panel->timing.s),deverb_channel_set.smooth*.1,0);
89 config_get_sigat("deverbpanel_set",bank,0,0,0,3,&deverb_channel_set.release);
90 multibar_thumb_set(MULTIBAR(channel_panel->timing.s),deverb_channel_set.release*.1,1);
93 static void compand_change(GtkWidget *w,gpointer in){
94 char buffer[80];
95 tbar *bar=(tbar *)in;
96 float val=multibar_get_value(MULTIBAR(w),0);
98 if(val==1.){
99 sprintf(buffer," off");
100 }else
101 sprintf(buffer," %4.2f",val);
103 readout_set(bar->readoutc,buffer);
105 *bar->v=1000./val;
108 static void timing_change(GtkWidget *w,gpointer in){
109 callback_arg_rv2 *ca=(callback_arg_rv2 *)in;
110 char buffer[80];
111 float smooth=multibar_get_value(MULTIBAR(w),0);
112 float release=multibar_get_value(MULTIBAR(w),1);
114 if(smooth<100){
115 sprintf(buffer,"%4.1fms",smooth);
116 }else if (smooth<1000){
117 sprintf(buffer,"%4.0fms",smooth);
118 }else if (smooth<10000){
119 sprintf(buffer," %4.2fs",smooth/1000.);
120 }else{
121 sprintf(buffer," %4.1fs",smooth/1000.);
123 readout_set(ca->r0,buffer);
125 if(release<100){
126 sprintf(buffer,"%4.1fms",release);
127 }else if (release<1000){
128 sprintf(buffer,"%4.0fms",release);
129 }else if (release<10000){
130 sprintf(buffer," %4.2fs",release/1000.);
131 }else{
132 sprintf(buffer," %4.1fs",release/1000.);
134 readout_set(ca->r1,buffer);
136 *ca->v0=rint(smooth*10.);
137 *ca->v1=rint(release*10.);
140 static void deverb_link(GtkToggleButton *b,gpointer in){
141 int mode=gtk_toggle_button_get_active(b);
142 *((sig_atomic_t *)in)=mode;
145 static deverb_panel_state *deverbpanel_create_helper(postfish_mainpanel *mp,
146 subpanel_generic *panel,
147 deverb_settings *sset){
148 int i;
149 float compand_levels[5]={1,1.5,2,3,5};
150 char *compand_labels[5]={"","1.5","2","3","5"};
152 float timing_levels[5]={10, 40, 100, 400, 1000};
153 char *timing_labels[5]={"","40ms"," 100ms","400ms","1s"};
155 GtkWidget *table=gtk_table_new(deverb_freqs+4,4,0);
156 GtkWidget *timinglabel=gtk_label_new("deverberator filter timing");
157 GtkWidget *releaselabel=gtk_label_new("release");
158 GtkWidget *smoothlabel=gtk_label_new("smooth");
159 GtkWidget *compandlabel=gtk_label_new("deverb depth");
161 GtkWidget *linkbutton=
162 gtk_check_button_new_with_mnemonic("_link channels into single image");
163 GtkWidget *linkbox=gtk_hbox_new(0,0);
165 deverb_panel_state *ps=calloc(1,sizeof(deverb_panel_state));
166 ps->panel=panel;
168 gtk_container_add(GTK_CONTAINER(panel->subpanel_box),table);
170 gtk_box_pack_end(GTK_BOX(linkbox),linkbutton,0,0,0);
172 gtk_table_attach(GTK_TABLE(table),timinglabel,0,2,0,1,
173 GTK_EXPAND|GTK_FILL,
174 GTK_EXPAND|GTK_FILL,
175 0,5);
176 gtk_table_attach(GTK_TABLE(table),smoothlabel,2,3,0,1,
177 GTK_EXPAND|GTK_FILL,
178 GTK_EXPAND|GTK_FILL,
179 0,0);
180 gtk_table_attach(GTK_TABLE(table),releaselabel,3,4,0,1,
181 GTK_EXPAND|GTK_FILL,
182 GTK_EXPAND|GTK_FILL,
183 0,0);
184 gtk_table_attach(GTK_TABLE(table),compandlabel,0,3,2,3,
185 GTK_EXPAND|GTK_FILL,
186 GTK_EXPAND|GTK_FILL,
187 0,5);
188 if(input_ch>1)
189 gtk_table_attach(GTK_TABLE(table),linkbox,0,4,deverb_freqs+3,
190 deverb_freqs+4,GTK_FILL|GTK_EXPAND,0,0,10);
192 gtk_table_set_row_spacing(GTK_TABLE(table),1,5);
194 gtk_misc_set_alignment(GTK_MISC(timinglabel),0,1.);
195 gtk_widget_set_name(timinglabel,"framelabel");
196 gtk_misc_set_alignment(GTK_MISC(smoothlabel),.5,1.);
197 gtk_widget_set_name(smoothlabel,"scalemarker");
198 gtk_misc_set_alignment(GTK_MISC(releaselabel),.5,1.);
199 gtk_widget_set_name(releaselabel,"scalemarker");
200 gtk_misc_set_alignment(GTK_MISC(compandlabel),0,1.);
201 gtk_widget_set_name(compandlabel,"framelabel");
203 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;
208 /* timing controls */
210 GtkWidget *slider=multibar_slider_new(5,timing_labels,timing_levels,2);
212 ps->timing.s=MULTIBAR(slider);
214 ps->timing.r0=READOUT(readout_new("10.0ms"));
215 ps->timing.r1=READOUT(readout_new("10.0ms"));
217 ps->timing.v0=&sset->smooth;
218 ps->timing.v1=&sset->release;
220 multibar_callback(MULTIBAR(slider),timing_change,&ps->timing);
222 multibar_thumb_set(MULTIBAR(slider),40,0);
223 multibar_thumb_set(MULTIBAR(slider),400,1);
225 gtk_table_attach(GTK_TABLE(table),slider,1,2,1,2,
226 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 0,0,0,0);
233 /* threshold controls */
235 for(i=0;i<deverb_freqs;i++){
236 GtkWidget *label=gtk_label_new(deverb_freq_labels[i]);
237 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 ps->bars[i].sp=ps;
242 ps->bars[i].v=sset->ratio+i;
243 ps->bars[i].number=i;
245 multibar_callback(MULTIBAR(ps->bars[i].cslider),compand_change,ps->bars+i);
247 switch(i){
248 case 0:
249 multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.,0);
250 break;
251 case 1:
252 multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.3,0);
253 break;
254 case 2:case 3: case 4: case 5:
255 multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.7,0);
256 break;
257 case 6:
258 multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1.3,0);
259 break;
260 case 7:
261 multibar_thumb_set(MULTIBAR(ps->bars[i].cslider),1,0);
262 break;
265 gtk_misc_set_alignment(GTK_MISC(label),1,.5);
267 gtk_table_attach(GTK_TABLE(table),label,0,1,i+3,i+4,
268 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 i+3,i+4,0,0,0,0);
275 subpanel_show_all_but_toplevel(panel);
277 return ps;
280 void deverbpanel_create_channel(postfish_mainpanel *mp,
281 GtkWidget **windowbutton,
282 GtkWidget **activebutton){
284 subpanel_generic *panel=subpanel_create(mp,windowbutton[0],activebutton,
285 deverb_channel_set.active,
286 &deverb_channel_set.panel_visible,
287 "De_verberation filter",0,
288 0,input_ch);
290 channel_panel=deverbpanel_create_helper(mp,panel,&deverb_channel_set);