eqpanel.c 5.23 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
/*
 *
 *  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 "freq.h"
#include "eq.h"

extern int input_ch;
extern int input_size;
extern int input_rate;

39 40 41
extern eq_settings eq_master_set;
extern eq_settings *eq_channel_set;

42 43 44
typedef struct {
  GtkWidget *slider;
  GtkWidget *readout;
45
  eq_settings *s;
46 47 48
  int number;
} bar;

49 50
static bar *m_bars;
static bar **c_bars;
51 52 53 54

static void slider_change(GtkWidget *w,gpointer in){
  char buffer[80];
  bar *b=(bar *)in;
55
  float val=multibar_get_value(MULTIBAR(b->slider),0);
56
  
57
  sprintf(buffer,"%+3.0fdB",val);
58 59
  readout_set(READOUT(b->readout),buffer);
  
60
  eq_set(b->s,b->number,val);
61 62 63

}

64 65 66 67
static bar *eqpanel_create_helper(postfish_mainpanel *mp,
			   subpanel_generic *panel,
			   eq_settings *es){

68
  int i;
69
  char *labels[16]={"","110","100","90","80","70","60","50","40",
70 71
		    "30","20","10","0","+10","+20","+30"};
  float levels[16]={-120,-110,-100,-90,-80,-70,-60,-50,-40,
72 73
		     -30,-20,-10,0,10,20,30};

74
  GtkWidget *slidertable=gtk_table_new(eq_freqs,3,0);
75 76
  bar *bars=calloc(eq_freqs,sizeof(*bars));
  
77 78
  for(i=0;i<eq_freqs;i++){
    const char *labeltext=eq_freq_labels[i];
79
    
80
    GtkWidget *label=gtk_label_new(labeltext);
81 82
    gtk_widget_set_name(label,"smallmarker");

83
    bars[i].readout=readout_new("+00dB");
84
    bars[i].slider=multibar_new(16,labels,levels,1,
85
				LO_DECAY|HI_DECAY|LO_ATTACK|HI_ATTACK);
86
    bars[i].number=i;
87
    bars[i].s=es;
88 89 90

    multibar_callback(MULTIBAR(bars[i].slider),slider_change,bars+i);
    multibar_thumb_set(MULTIBAR(bars[i].slider),0.,0);
91
    multibar_thumb_bounds(MULTIBAR(bars[i].slider),-60,30);
Monty Montgomery's avatar
Monty Montgomery committed
92
    multibar_thumb_increment(MULTIBAR(bars[i].slider),1,10);
93 94 95 96 97

    gtk_misc_set_alignment(GTK_MISC(label),1,.5);

    gtk_table_attach(GTK_TABLE(slidertable),label,0,1,i,i+1,
		     GTK_FILL,0,10,0);
98
    gtk_table_attach(GTK_TABLE(slidertable),bars[i].readout,2,3,i,i+1,
99
		     GTK_FILL,0,0,0);
100
    gtk_table_attach(GTK_TABLE(slidertable),bars[i].slider,1,2,i,i+1,
101 102 103 104
		     GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,0,0);
  }

  gtk_box_pack_start(GTK_BOX(panel->subpanel_box),slidertable,1,1,4);
105
  subpanel_show_all_but_toplevel(panel);
106

107
  return bars;
108 109
}

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
void eqpanel_create_master(postfish_mainpanel *mp,
                                GtkWidget *windowbutton,
                                GtkWidget *activebutton){

  char *shortcut[]={" e "};
  subpanel_generic *panel=subpanel_create(mp,windowbutton,&activebutton,
					  &eq_master_set.panel_active,
					  &eq_master_set.panel_visible,
					  "_Equalizer (master)",shortcut,
					  0,1);
  
  m_bars=eqpanel_create_helper(mp,panel,&eq_master_set);
}

void eqpanel_create_channel(postfish_mainpanel *mp,
				 GtkWidget **windowbutton,
				 GtkWidget **activebutton){
  int i;
128
  c_bars=malloc(input_ch*sizeof(*c_bars));
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

  /* a panel for each channel */
  for(i=0;i<input_ch;i++){
    subpanel_generic *panel;
    char buffer[80];

    sprintf(buffer,"_Equalizer (channel %d)",i+1);

    panel=subpanel_create(mp,windowbutton[i],activebutton+i,
			  &eq_channel_set[i].panel_active,
			  &eq_channel_set[i].panel_visible,
			  buffer,0,i,1);
  
    c_bars[i]=eqpanel_create_helper(mp,panel,eq_channel_set+i);
  }
}


147 148
static float **peakfeed=0;
static float **rmsfeed=0;
149

Monty Montgomery's avatar
Monty Montgomery committed
150
void eqpanel_feedback(int displayit){
151
  int i,j;
152
  if(!peakfeed){
153 154
    peakfeed=malloc(sizeof(*peakfeed)*eq_freqs);
    rmsfeed=malloc(sizeof(*rmsfeed)*eq_freqs);
155

156
    for(i=0;i<eq_freqs;i++){
157 158
      peakfeed[i]=malloc(sizeof(**peakfeed)*max(input_ch,OUTPUT_CHANNELS));
      rmsfeed[i]=malloc(sizeof(**rmsfeed)*max(input_ch,OUTPUT_CHANNELS));
159 160
    }
  }
161
  
162
  if(pull_eq_feedback_master(peakfeed,rmsfeed)==1)
163
    for(i=0;i<eq_freqs;i++)
164
      multibar_set(MULTIBAR(m_bars[i].slider),rmsfeed[i],peakfeed[i],
165
		   OUTPUT_CHANNELS,(displayit && eq_master_set.panel_visible));
166
  
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

  if(pull_eq_feedback_channel(peakfeed,rmsfeed)==1){
    for(j=0;j<input_ch;j++){
      for(i=0;i<eq_freqs;i++){
	float rms[input_ch];
	float peak[input_ch];
	
	memset(rms,0,sizeof(rms));
        memset(peak,0,sizeof(peak));
        rms[j]=rmsfeed[i][j];
        peak[j]=peakfeed[i][j];
	
	multibar_set(MULTIBAR(c_bars[j][i].slider),rms,peak,
		     input_ch,(displayit && eq_channel_set[j].panel_visible));
      }
    }
  }
184 185 186
}

void eqpanel_reset(void){
187 188 189 190
  int i,j;
  for(i=0;i<eq_freqs;i++)
    multibar_reset(MULTIBAR(m_bars[i].slider));
  
191
  for(i=0;i<eq_freqs;i++)
192 193
    for(j=0;j<input_ch;j++)
      multibar_reset(MULTIBAR(c_bars[j][i].slider));
194
}
195