File: eqwindow.h

package info (click to toggle)
eq10q 2.2~repack0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,236 kB
  • ctags: 1,390
  • sloc: cpp: 8,036; ansic: 1,776; makefile: 6
file content (399 lines) | stat: -rw-r--r-- 15,780 bytes parent folder | download | duplicates (5)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/***************************************************************************
 *   Copyright (C) 2009 by Pere Ràfols Soler                               *
 *   sapista2@gmail.com                                                    *
 *                                                                         *
 *   This program 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 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef EQ_MAIN_WIN_H
  #define EQ_MAIN_WIN_H

#include <iostream>
#include <string>


#include <gtkmm/alignment.h>
#include <gtkmm/box.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/image.h>

#include <cmath>

//LV2 UI header
#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
#include <lv2/lv2plug.in/ns/ext/atom/forge.h>
#include <lv2/lv2plug.in/ns/ext/atom/util.h>
#include <lv2/lv2plug.in/ns/ext/urid/urid.h>
#include "../../uris.h"

#include "mainwidget.h"
#include "bandctl.h"
#include "vuwidget.h"
#include "knob2.h"
#include "eqparams.h"
#include "bodeplot.h"
#include "button.h"
#include "toggle_button.h"
#include "abbutton.h"
#include "sidechainbox.h"

//Include eq definition
#include "../eq_defines.h"

#define IMAGE_LOGO_PATH "icons/logoeq10q.png"
#define TIMER_VALUE_MS 100

//Test print information, comment out for the final release
//#define PRINT_DEBUG_INFO

using namespace sigc;

class EqMainWindow : public MainWidget
{
  public:
    EqMainWindow(int iAudioChannels, int iNumBands, const char *uri, const char *bundlePath, const LV2_Feature *const *features);
    virtual ~EqMainWindow();   
    void request_sample_rate();
        
    // Informing GUI about changes in the control ports
    void gui_port_event(LV2UI_Handle ui, uint32_t port, uint32_t buffer_size, uint32_t format, const void * buffer)
    {     
      //Atom event from DSP
      if((int)port == (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands + 2*m_iNumOfChannels))
      {
         
          const LV2_Atom* atom = (const LV2_Atom*)buffer;               
          
          if (format == uris.atom_eventTransfer && atom->type == uris.atom_Object)
          {           
            const LV2_Atom_Object* obj = (const LV2_Atom_Object*)atom;
            
            if(obj->body.otype == uris.atom_sample_rate_response)
            {
                const LV2_Atom* samplerate_val = NULL;
                const int n_props  = lv2_atom_object_get(obj, uris.atom_sample_rate_key, &samplerate_val, NULL);

              if (n_props != 1 ||   samplerate_val->type != uris.atom_Double)
              {
                std::cout<<"Atom Object does not have the required properties (sample-rate) with correct types"<<std::endl;
              }
              else
              {
                SampleRate = ((const LV2_Atom_Double*)samplerate_val)->body;
                m_Bode->setSampleRate(SampleRate);
              }
            }
            
            else if(obj->body.otype == uris.atom_fft_data_event)
            {
              const LV2_Atom* fftdata_val = NULL;      
              const int n_props  = lv2_atom_object_get(obj, uris.atom_fft_data_key, &fftdata_val, NULL);

              if (n_props != 1 || fftdata_val->type != uris.atom_Vector)
              {
                std::cout<<"Atom Object does not have the required properties (fft-data) with correct types"<<std::endl;
              }
              else
              {
                const LV2_Atom_Vector* vec = (const LV2_Atom_Vector*)fftdata_val; 
                if (vec->body.child_type != uris.atom_Double) 
                {
                   std::cout<<"Atom fft Vector has incorrect element type"<<std::endl;
                }
                else
                {
                  // Number of elements = (total size - header size) / element size
                  const size_t n_elem = ((fftdata_val->size - sizeof(LV2_Atom_Vector_Body))/ sizeof(double));
      
                  //std::cout<<"N Elem "<<n_elem << std::endl;
                  
                  //Copy data to bodeplot
                  if(n_elem == ((FFT_N/2) + 1)) 
                  {
                    // Double elements immediately follow the vector body header
                    m_Bode->setFftData((double*)(&vec->body + 1));
                  }                 
                }
              }
            }
          }
      }//End of Atom ports reading
      
      
      //Standard LV2 ports handling
      float data = * static_cast<const float*>(buffer);
      
      #ifdef PRINT_DEBUG_INFO
	std::cout<<"gui_port_event Entring....... "<<std::endl;
      #endif
      
        // Checking if params are the same as specified in the LV2 documentation for no-atom ports
        if (format != 0) {
	    #ifdef PRINT_DEBUG_INFO
	      std::cout<<"\t-- Return Format != 0"<<std::endl;
	    #endif
            return;
        }
        if (buffer_size != 4) {  
	    #ifdef PRINT_DEBUG_INFO
	      std::cout<<"\t-- Return buffer_size != 4"<<std::endl;
	    #endif  
            return;
        }

        // Updating values in GUI ========================================================
	switch (port)
	{
	  case EQ_BYPASS:
	    m_bypassValue = data > 0.5 ? 1 : 0;
	    m_port_event_Bypass = true; //Marck port even boolean
	    ///m_BypassButton.set_active(data > 0.5);
	    #ifdef PRINT_DEBUG_INFO
	      std::cout<<"\t-- BYPASS"<<std::endl;
	    #endif  
	  break;

	  case EQ_INGAIN:
	    //m_InGainValue = data;
	    m_CurParams->setInputGain(data);
	    m_port_event_InGain = true; //Marck port even boolean
	    ///m_InGain->setGain(data);
	    
	    #ifdef PRINT_DEBUG_INFO
	      std::cout<<"\t-- Input Gain"<<std::endl;
	    #endif  
	  break;

	  case EQ_OUTGAIN:
	    //m_OutGainValue = data;
	    m_CurParams->setOutputGain(data);
	    m_port_event_OutGain = true; //Marck port even boolean
	    ///m_OutGain->setGain(data);
	    #ifdef PRINT_DEBUG_INFO
	      std::cout<<"\t-- Out Gain"<<std::endl;
	    #endif  
	  break;

	  default:
	    //Connect BandGain ports
	    if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + m_iNumOfBands))
	    {
	      ///m_BandCtlArray[(int)port - PORT_OFFSET - 2*m_iNumOfChannels]->setGain(data);
	      ///m_Bode->setBandGain((int)port - PORT_OFFSET - 2*m_iNumOfChannels, data);
	      m_CurParams->setBandGain((int)port - PORT_OFFSET - 2*m_iNumOfChannels, data);
	      m_port_event_Curve = true; //Marck port even boolean
	      m_port_event_Curve_Gain[(int)port - PORT_OFFSET - 2*m_iNumOfChannels] = true;
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Band Gain"<<std::endl;
	      #endif  
	    }

	    //Connect BandFreq ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + m_iNumOfBands) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 2*m_iNumOfBands))
	    {
	      ///m_BandCtlArray[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - m_iNumOfBands]->setFreq(data);
	      ///m_Bode->setBandFreq((int)port - PORT_OFFSET - 2*m_iNumOfChannels - m_iNumOfBands, data);
	      m_CurParams->setBandFreq((int)port - PORT_OFFSET - 2*m_iNumOfChannels - m_iNumOfBands, data);
	      m_port_event_Curve = true; //Marck port even boolean
	      m_port_event_Curve_Freq[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - m_iNumOfBands] = true;
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Band Freq"<<std::endl;
	      #endif  
	    }

	    //Connect BandParam ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + 2*m_iNumOfBands) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 3*m_iNumOfBands))
	    {
	      ///m_BandCtlArray[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - 2*m_iNumOfBands]->setQ(data);
	      ///m_Bode->setBandQ((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 2*m_iNumOfBands, data);
	      m_CurParams->setBandQ((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 2*m_iNumOfBands, data);
	      m_port_event_Curve = true; //Marck port even boolean
	      m_port_event_Curve_Q[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - 2*m_iNumOfBands] = true;
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Band Q"<<std::endl;
	      #endif  
	    }

	    //Connect BandType ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + 3*m_iNumOfBands) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 4*m_iNumOfBands))
	    {
	      ///m_BandCtlArray[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - 3*m_iNumOfBands]->setFilterType(data);
	      ///m_Bode->setBandType((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 3*m_iNumOfBands, data);
	      m_CurParams->setBandType((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 3*m_iNumOfBands, ((int)data) & 0xFF);
	      m_port_event_Curve = true; //Marck port even boolean
	      m_port_event_Curve_Type[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - 3*m_iNumOfBands] = true;
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Band Type"<<std::endl;
	      #endif  
	    }

	    //Connect BandEnabled ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + 4*m_iNumOfBands) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands))
	    {
	      ///m_BandCtlArray[(int)port - PORT_OFFSET - 2*m_iNumOfChannels - 4*m_iNumOfBands]->setEnabled(data > 0.5);
	      ///m_Bode->setBandEnable((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 4*m_iNumOfBands, data > 0.5);

              int iMidSide = (int)data >> 1;
              const int sel_band = (int)port - PORT_OFFSET - 2*m_iNumOfChannels - 4*m_iNumOfBands;
              switch(iMidSide)
              {
                case 0: 
		  m_BandCtlArray[sel_band]->setStereoState(BandCtl::DUAL);
		  if(m_iNumOfChannels == 1)
		  {
		    m_Bode->setStereoState(sel_band, PlotEQCurve::MONO);
		  }
		  else
		  {
		    m_Bode->setStereoState(sel_band, PlotEQCurve::DUAL);
		  }
                  break;
                  
                case 1:
                  m_BandCtlArray[sel_band]->setStereoState(BandCtl::ML);
                  m_Bode->setStereoState(sel_band, PlotEQCurve::ML);
                  break;
                  
                case 2:
                  m_BandCtlArray[sel_band]->setStereoState(BandCtl::SR);
                  m_Bode->setStereoState(sel_band, PlotEQCurve::SR);
                  break;
              }
              
              int iEnable = (int)data & 0x01;
	      m_CurParams->setBandEnabled(sel_band, iEnable > 0);
	      m_port_event_Curve = true; //Marck port even boolean
	      m_port_event_Curve_Enable[sel_band] = true;
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Band Enabled"<<std::endl;
	      #endif  
	    }

	    //Connect VuInput ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands + m_iNumOfChannels))
	    {
              m_VuMeterIn->setValue((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 5*m_iNumOfBands,data);
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Vu input"<<std::endl;
	      #endif  
	    }

	    //Connect VuOutput ports
	    else if((int)port >= (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands + m_iNumOfChannels) && (int)port < (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands + 2*m_iNumOfChannels))
	    {
              m_VuMeterOut->setValue((int)port - PORT_OFFSET - 2*m_iNumOfChannels - 5*m_iNumOfBands - m_iNumOfChannels, data);
	      #ifdef PRINT_DEBUG_INFO
		std::cout<<"\t-- Vu output"<<std::endl;
	      #endif  
	    }
	      
	    //Connect Stereo Mode port
            else if((int)port == (PORT_OFFSET + 2*m_iNumOfChannels + 5*m_iNumOfBands + 2*m_iNumOfChannels + 2))
            {
              setStereoMode( data > 0.5);
              #ifdef PRINT_DEBUG_INFO
                std::cout<<"\t-- Mid Side"<<std::endl;
              #endif  
            }
            
	    //No more ports here
	    else
	    {
	      #ifdef PRINT_DEBUG_INFO	    
		std::cout<<"\t--  Return port index is out of range"<<std::endl;
	      #endif
	      return;
	    }
	  break;
	}       
        
	#ifdef PRINT_DEBUG_INFO	    
	  std::cout<<"\t--  Return OK"<<std::endl;
	#endif
	
    }

    LV2UI_Controller controller;
    LV2UI_Write_Function write_function;
    Eq10qURIs uris;
    LV2_URID_Map*  map;
    LV2_Atom_Forge forge;

  protected:
    EqParams *m_AParams, *m_BParams, *m_CurParams;
    BandCtl **m_BandCtlArray; 
    Gtk::HBox m_BandBox, m_ABFlatBox, m_GainEqBox, m_PlotBox;
    Gtk::VBox m_CurveBypassBandsBox, m_MainBox, m_InGainBox, m_OutGainBox, m_FftCtlVBox, m_dBScaleBox, m_FftdBBox, m_StereoBox;
    ToggleButton m_BypassButton, m_FftRtaActive, m_FftSpecActive, m_dB10Scale, m_dB25Scale, m_dB50Scale, m_LRStereoMode, m_MSStereoMode;
    AbButton m_AButton;
    Gtk::Alignment m_FlatAlign, m_ABAlign, m_ButtonAAlign, m_BypassAlign, m_LoadAlign, m_SaveAlign, m_FftAlign, m_FftAlignInner, m_FftAlngGain, m_FftAlngRange, m_dBScaleAlign, m_dBScaleAlignInner, m_StereoInnerAlng, m_StereAlng;
    Button m_FlatButton, m_SaveButton, m_LoadButton, m_FftHold;
    Gtk::Alignment m_MainWidgetAlign;
    PlotEQCurve *m_Bode;
    Gtk::Image *image_logo_center;
    KnobWidget2 *m_GainFaderIn, *m_GainFaderOut, *m_FftGain, *m_FftRange;
    VUWidget *m_VuMeterIn, *m_VuMeterOut;
    SideChainBox *m_FftBox, *m_dBScaleFrame, *m_MidSideBox;
    
    void loadEqParams();
    void changeAB(EqParams *toBeCurrent);
    void saveToFile();
    void loadFromFile();
    void sendAtomFftOn(bool fft_activated);
    void setStereoMode(bool isMidSide);
    
    //Signal Handlers
    void onButtonA();
    void onButtonFlat();
    void onButtonBypass();
    void onBandChange(int iBand, int iField, float fValue);
    void onInputGainChange();
    void onOutputGainChange();
    void onCurveChange(int band_ix, float Gain, float Freq, float Q);
    void onCurveBandEnable(int band_ix, bool IsEnabled);
    bool on_timeout();
    void onButtonFftRta();
    void onButtonFftSpc();
    void onHoldFft_press();
    void onHoldFft_release();
    void onFftGainScale();
    void onFftRangeScale();
    void onBodeSelectBand(int band);
    void onBodeUnselectBand();
    void onBandCtlSelectBand(int band);
    void onBandCtlUnselectBand();
    void onBandCtlMidSideChanged(int band);
    
    void onDbScale10Changed();
    void onDbScale25Changed();
    void onDbScale50Changed();
    
    void onLeftRightModeSelected();
    void onMidSideModeSelected();

        
  private:
    double SampleRate;
    float m_bypassValue;   
    const int m_iNumOfChannels;
    const int m_iNumOfBands;
    bool m_bMutex, m_port_event_InGain, m_port_event_OutGain, m_port_event_Bypass, m_port_event_Curve;
    bool *m_port_event_Curve_Gain, *m_port_event_Curve_Freq, *m_port_event_Curve_Q, *m_port_event_Curve_Type, *m_port_event_Curve_Enable;
    std::string m_pluginUri;
    std::string m_bundlePath;
};

#endif