~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-security

« back to all changes in this revision

Viewing changes to src/effects/BassBoost.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2007-05-17 02:36:41 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517023641-5yjqt9434cbcb6ph
Tags: 1.3.2-4
* debian/patches:
   - desktop_file.patch: fixed broken Category entry
* debian/audacity.mime:
   - added entry for application/x-audacity-project

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
  Dominic Mazzoni (with the help of wxDesigner)
12
12
  Vaughan Johnson (Preview)
13
13
 
14
 
**********************************************************************/
15
 
 
16
 
#include <math.h>
17
 
 
18
 
#include <wx/msgdlg.h>
19
 
#include <wx/intl.h>
 
14
*******************************************************************//**
 
15
 
 
16
\class EffectBassBoost
 
17
\brief An EffectSimpleMono
 
18
 
 
19
*//****************************************************************//**
 
20
 
 
21
\class BassBoostDialog
 
22
\brief Dialog for EffectBassBoost
 
23
 
 
24
*//*******************************************************************/
 
25
 
 
26
#include "../Audacity.h"
20
27
 
21
28
#include "BassBoost.h"
22
29
#include "../WaveTrack.h"
23
30
 
 
31
#include <wx/button.h>
 
32
#include <wx/msgdlg.h>
 
33
#include <wx/sizer.h>
 
34
#include <wx/stattext.h>
 
35
#include <wx/textctrl.h>
 
36
#include <wx/valtext.h>
 
37
 
 
38
#include <math.h>
 
39
 
24
40
//
25
41
// EffectBassBoost
26
42
//
34
50
wxString EffectBassBoost::GetEffectDescription() { 
35
51
   // Note: This is useful only after values have been set. 
36
52
   return wxString::Format(_("Applied effect: %s frequency = %.0f Hz, boost = %.0f dB"), 
37
 
                           (const char *)(this->GetEffectName()), frequency, dB_boost); 
 
53
                           this->GetEffectName().c_str(), frequency, dB_boost); 
38
54
39
55
 
40
56
bool EffectBassBoost::NewTrackSimpleMono()
66
82
 
67
83
bool EffectBassBoost::PromptUser()
68
84
{
69
 
   BassBoostDialog dlog(this, mParent, -1, _("Bass Boost"));
 
85
   BassBoostDialog dlog(this, mParent);
70
86
   dlog.freq = frequency;
71
87
   dlog.boost = dB_boost;
72
88
   dlog.TransferDataToWindow();
73
89
   dlog.CentreOnParent();
74
90
   dlog.ShowModal();
75
91
 
76
 
   if (!dlog.GetReturnCode())
 
92
   if (dlog.GetReturnCode() == wxID_CANCEL)
77
93
      return false;
78
94
 
79
95
   frequency = dlog.freq;
82
98
   return true;
83
99
}
84
100
 
 
101
bool EffectBassBoost::TransferParameters( Shuttle & shuttle )
 
102
{  
 
103
   shuttle.TransferFloat(wxT("Boost"),dB_boost,0.0);
 
104
   shuttle.TransferFloat(wxT("Freq"),frequency,0.0);
 
105
   return true;
 
106
}
 
107
 
85
108
bool EffectBassBoost::ProcessSimpleMono(float *buffer, sampleCount len)
86
109
{
87
110
   /* initialise the filter */
113
136
// BassBoostDialog
114
137
//----------------------------------------------------------------------------
115
138
 
 
139
const static wxChar *numbers[] =
 
140
{
 
141
   wxT("0"), wxT("1"), wxT("2"), wxT("3"), wxT("4"),
 
142
   wxT("5"), wxT("6"), wxT("7"), wxT("8"), wxT("9")
 
143
};
 
144
 
 
145
// Declare window functions                                                                                                         
 
146
                                                                                                                                    
 
147
#define ID_FREQ_TEXT    10001
 
148
#define ID_FREQ_SLIDER  10002
 
149
#define ID_BOOST_TEXT   10003
 
150
#define ID_BOOST_SLIDER 10004
 
151
 
 
152
// Declare ranges
 
153
 
116
154
#define FREQ_MIN 1
117
155
#define FREQ_MAX 1000
118
156
#define BOOST_MIN 0
119
157
#define BOOST_MAX 36
120
158
 
121
 
BEGIN_EVENT_TABLE(BassBoostDialog, wxDialog)
122
 
    EVT_BUTTON(ID_BUTTON_PREVIEW, BassBoostDialog::OnPreview)
123
 
    EVT_BUTTON(wxID_OK, BassBoostDialog::OnOk)
124
 
    EVT_BUTTON(wxID_CANCEL, BassBoostDialog::OnCancel)
 
159
BEGIN_EVENT_TABLE(BassBoostDialog, EffectDialog)
125
160
    EVT_SLIDER(ID_FREQ_SLIDER, BassBoostDialog::OnFreqSlider)
126
161
    EVT_SLIDER(ID_BOOST_SLIDER, BassBoostDialog::OnBoostSlider)
127
162
    EVT_TEXT(ID_FREQ_TEXT, BassBoostDialog::OnFreqText)
128
163
    EVT_TEXT(ID_BOOST_TEXT, BassBoostDialog::OnBoostText)
 
164
    EVT_BUTTON(ID_EFFECT_PREVIEW, BassBoostDialog::OnPreview)
129
165
END_EVENT_TABLE()
130
166
 
131
167
BassBoostDialog::BassBoostDialog(EffectBassBoost *effect,
132
 
                                 wxWindow * parent, wxWindowID id,
133
 
                                 const wxString & title,
134
 
                                 const wxPoint & position,
135
 
                                 const wxSize & size,
136
 
                                 long style):
137
 
   wxDialog(parent, id, title, position, size, style),
 
168
                                 wxWindow * parent):
 
169
   EffectDialog(parent, _("BassBoost"), PROCESS_EFFECT),
138
170
   mEffect(effect)
139
171
{
140
 
   MakeBassBoostDialog(this, TRUE, TRUE);
 
172
   Init();
141
173
}
142
174
 
143
 
bool BassBoostDialog::Validate()
 
175
void BassBoostDialog::PopulateOrExchange(ShuttleGui & S)
144
176
{
145
 
   return TRUE;
 
177
   wxTextValidator vld(wxFILTER_INCLUDE_CHAR_LIST);
 
178
   vld.SetIncludes(wxArrayString(10, numbers));
 
179
 
 
180
   S.StartHorizontalLay(wxCENTER, false);
 
181
   {
 
182
      S.AddTitle(_("by Nasca Octavian Paul"));
 
183
   }
 
184
   S.EndHorizontalLay();
 
185
 
 
186
   S.StartHorizontalLay(wxCENTER, false);
 
187
   {
 
188
      // Add a little space
 
189
   }
 
190
   S.EndHorizontalLay();
 
191
 
 
192
   S.StartMultiColumn(3, wxEXPAND);
 
193
   S.SetStretchyCol(2);
 
194
   {
 
195
      // Frequency
 
196
      mFreqT = S.Id(ID_FREQ_TEXT).AddTextBox(_("Frequency (Hz):"),
 
197
                                             wxT(""),
 
198
                                             10);
 
199
      mFreqT->SetValidator(vld);
 
200
 
 
201
      S.SetStyle(wxSL_HORIZONTAL);
 
202
      mFreqS = S.Id(ID_FREQ_SLIDER).AddSlider(wxT(""),
 
203
                                              0,
 
204
                                              FREQ_MAX);
 
205
      mFreqS->SetRange(FREQ_MIN, FREQ_MAX);
 
206
 
 
207
      // Boost
 
208
      mBoostT = S.Id(ID_BOOST_TEXT).AddTextBox(_("Boost (dB):"),
 
209
                                               wxT(""),
 
210
                                               10);
 
211
      mBoostT->SetValidator(vld);
 
212
 
 
213
      S.SetStyle(wxSL_HORIZONTAL);
 
214
      mBoostS = S.Id(ID_BOOST_SLIDER).AddSlider(wxT(""),
 
215
                                                0,
 
216
                                                BOOST_MAX);
 
217
      mBoostS->SetRange(BOOST_MIN, BOOST_MAX);
 
218
   }
 
219
   S.EndMultiColumn();
 
220
   return;
146
221
}
147
222
 
148
223
bool BassBoostDialog::TransferDataToWindow()
149
224
{
150
 
   wxSlider *slider;
151
 
 
152
 
   slider = GetBoostSlider();
153
 
   if (slider)
154
 
      slider->SetValue((int)boost);
155
 
 
156
 
   slider = GetFreqSlider();
157
 
   if (slider)
158
 
      slider->SetValue((int)freq);
159
 
 
160
 
   wxTextCtrl *text = GetBoostText();
161
 
   if (text) {
162
 
      wxString str;
163
 
      str.Printf("%d", (int) boost);
164
 
      text->SetValue(str);
165
 
   }
166
 
 
167
 
   text = GetFreqText();
168
 
   if (text) {
169
 
      wxString str;
170
 
      str.Printf("%d", (int) freq);
171
 
      text->SetValue(str);
172
 
   }
173
 
 
174
 
   return TRUE;
 
225
   mBoostS->SetValue((int)boost);
 
226
   mFreqS->SetValue((int)freq);
 
227
 
 
228
   mBoostT->SetValue(wxString::Format(wxT("%d"), (int) boost));
 
229
   mFreqT->SetValue(wxString::Format(wxT("%d"), (int) freq));
 
230
 
 
231
   return true;
175
232
}
176
233
 
177
234
bool BassBoostDialog::TransferDataFromWindow()
178
235
{
179
 
   wxTextCtrl *c = GetBoostText();
180
 
   if (c) {
181
 
      long b;
182
 
 
183
 
      wxString val = c->GetValue();
184
 
      val.ToLong(&b);
185
 
      boost = TrapLong(b, BOOST_MIN, BOOST_MAX);
186
 
   }
187
 
 
188
 
   c = GetFreqText();
189
 
   if (c) {
190
 
      long f;
191
 
 
192
 
      wxString val = c->GetValue();
193
 
      val.ToLong(&f);
194
 
      freq = TrapLong(f, FREQ_MIN, FREQ_MAX);
195
 
   }
196
 
 
197
 
   return TRUE;
 
236
   boost = TrapLong(mBoostS->GetValue(), BOOST_MIN, BOOST_MAX);
 
237
   freq = TrapLong(mFreqS->GetValue(), FREQ_MIN, FREQ_MAX);
 
238
 
 
239
   return true;
198
240
}
199
241
 
200
242
// WDR: handler implementations for BassBoostDialog
201
243
 
202
244
void BassBoostDialog::OnBoostText(wxCommandEvent & event)
203
245
{
204
 
   wxTextCtrl *c = GetBoostText();
205
 
   if (c) {
206
 
      long boost;
207
 
 
208
 
      c->GetValue().ToLong(&boost);
209
 
      boost = TrapLong(boost, BOOST_MIN, BOOST_MAX);
210
 
 
211
 
      wxSlider *slider = GetBoostSlider();
212
 
      if (slider)
213
 
         slider->SetValue(boost);
214
 
   }
 
246
   long val;
 
247
 
 
248
   mBoostT->GetValue().ToLong(&val);
 
249
   mBoostS->SetValue(TrapLong(val, BOOST_MIN, BOOST_MAX));
215
250
}
216
251
 
217
252
void BassBoostDialog::OnFreqText(wxCommandEvent & event)
218
253
{
219
 
   wxTextCtrl *c = GetFreqText();
220
 
   if (c) {
221
 
      long freq;
222
 
 
223
 
      c->GetValue().ToLong(&freq);
224
 
      freq = TrapLong(freq, FREQ_MIN, FREQ_MAX);
225
 
 
226
 
      wxSlider *slider = GetFreqSlider();
227
 
      if (slider)
228
 
         slider->SetValue(freq);
229
 
   }
 
254
   long val;
 
255
 
 
256
   mFreqT->GetValue().ToLong(&val);
 
257
   mFreqS->SetValue(TrapLong(val, FREQ_MIN, FREQ_MAX));
230
258
}
231
259
 
232
260
void BassBoostDialog::OnBoostSlider(wxCommandEvent & event)
233
261
{
234
 
   wxString str;
235
 
   str.Printf("%d", GetBoostSlider()->GetValue());
236
 
   GetBoostText()->SetValue(str);
 
262
   mBoostT->SetValue(wxString::Format(wxT("%d"), mBoostS->GetValue()));
237
263
}
238
264
 
239
265
void BassBoostDialog::OnFreqSlider(wxCommandEvent & event)
240
266
{
241
 
   wxString str;
242
 
   long freq = GetFreqSlider()->GetValue();
243
 
   freq = ((freq + 5) / 10) * 10;       // round to nearest multiple of 10
244
 
   str.Printf("%ld", freq);
245
 
   GetFreqText()->SetValue(str);
 
267
   mFreqT->SetValue(wxString::Format(wxT("%d"), mFreqS->GetValue()));
246
268
}
247
269
 
248
270
void BassBoostDialog::OnPreview(wxCommandEvent & event)
253
275
   mEffect->Preview();
254
276
}
255
277
 
256
 
void BassBoostDialog::OnOk(wxCommandEvent & event)
257
 
{
258
 
   TransferDataFromWindow();
259
 
 
260
 
   if (Validate())
261
 
      EndModal(true);
262
 
   else {
263
 
      event.Skip();
264
 
   }
265
 
}
266
 
 
267
 
void BassBoostDialog::OnCancel(wxCommandEvent & event)
268
 
{
269
 
   EndModal(false);
270
 
}
271
 
 
272
 
wxSizer *BassBoostDialog::MakeBassBoostDialog(wxWindow * parent, bool call_fit,
273
 
                                              bool set_sizer)
274
 
{
275
 
   wxBoxSizer *item0 = new wxBoxSizer(wxVERTICAL);
276
 
 
277
 
   wxStaticText *item1 =
278
 
       new wxStaticText(parent, -1,
279
 
                        _("Bass Boost by Nasca Octavian Paul"),
280
 
                        wxDefaultPosition, wxDefaultSize, 0);
281
 
   item0->Add(item1, 0, wxALIGN_CENTRE | wxALL, 5);
282
 
 
283
 
   wxFlexGridSizer *item2 = new wxFlexGridSizer(3, 0, 0);
284
 
 
285
 
   wxStaticText *item3 =
286
 
       new wxStaticText(parent, -1, _("Frequency (Hz):"),
287
 
                        wxDefaultPosition, wxDefaultSize, 0);
288
 
   item2->Add(item3, 0, wxALIGN_CENTRE | wxALL, 5);
289
 
 
290
 
   wxTextCtrl *item4 =
291
 
       new wxTextCtrl(parent, ID_FREQ_TEXT, "", wxDefaultPosition,
292
 
                      wxSize(40, -1), 0);
293
 
   item2->Add(item4, 0, wxALIGN_CENTRE | wxALL, 5);
294
 
 
295
 
   wxSlider *item5 =
296
 
       new wxSlider(parent, ID_FREQ_SLIDER, 0, FREQ_MIN, FREQ_MAX,
297
 
                    wxDefaultPosition, wxSize(100, -1), wxSL_HORIZONTAL);
298
 
   //item5->SetValue(200);
299
 
   item2->Add(item5, 0, wxALIGN_CENTRE | wxALL, 5);
300
 
 
301
 
   wxStaticText *item6 =
302
 
       new wxStaticText(parent, -1, _("Boost (dB):"), wxDefaultPosition,
303
 
                        wxDefaultSize, 0);
304
 
   item2->Add(item6, 0, wxALIGN_CENTRE | wxALL, 5);
305
 
 
306
 
   wxTextCtrl *item7 =
307
 
       new wxTextCtrl(parent, ID_BOOST_TEXT, "", wxDefaultPosition,
308
 
                      wxSize(40, -1), 0);
309
 
   item2->Add(item7, 0, wxALIGN_CENTRE | wxALL, 5);
310
 
 
311
 
   wxSlider *item8 =
312
 
       new wxSlider(parent, ID_BOOST_SLIDER, 0, BOOST_MIN, BOOST_MAX,
313
 
                    wxDefaultPosition, wxSize(100, -1), wxSL_HORIZONTAL);
314
 
   //item8->SetValue(12);
315
 
   item2->Add(item8, 0, wxALIGN_CENTRE | wxALL, 5);
316
 
 
317
 
   item0->Add(item2, 0, wxALIGN_CENTRE | wxALL, 5);
318
 
 
319
 
   wxBoxSizer *item9 = new wxBoxSizer(wxHORIZONTAL);
320
 
 
321
 
   wxButton *item9b =
322
 
      new wxButton(parent, ID_BUTTON_PREVIEW, mEffect->GetPreviewName());
323
 
   item9->Add(item9b, 0, wxALIGN_CENTRE | wxALL, 5);
324
 
   item9->Add(20, 5); // horizontal spacer
325
 
 
326
 
   wxButton *item11 =
327
 
       new wxButton(parent, wxID_CANCEL, _("Cancel"), wxDefaultPosition,
328
 
                    wxDefaultSize, 0);
329
 
   item9->Add(item11, 0, wxALIGN_CENTRE | wxALL, 5);
330
 
 
331
 
   wxButton *item10 =
332
 
       new wxButton(parent, wxID_OK, _("OK"), wxDefaultPosition,
333
 
                    wxDefaultSize, 0);
334
 
   item10->SetDefault();
335
 
   item10->SetFocus();
336
 
   item9->Add(item10, 0, wxALIGN_CENTRE | wxALL, 5);
337
 
 
338
 
   item0->Add(item9, 0, wxALIGN_CENTRE | wxALL, 5);
339
 
 
340
 
   if (set_sizer) {
341
 
      parent->SetAutoLayout(TRUE);
342
 
      parent->SetSizer(item0);
343
 
      if (call_fit) {
344
 
         item0->Fit(parent);
345
 
         item0->SetSizeHints(parent);
346
 
      }
347
 
   }
348
 
 
349
 
   return item0;
350
 
}
 
278
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
 
279
// version control system. Please do not modify past this point.
 
280
//
 
281
// Local Variables:
 
282
// c-basic-offset: 3
 
283
// indent-tabs-mode: nil
 
284
// End:
 
285
//
 
286
// vim: et sts=3 sw=3
 
287
// arch-tag: 25dfd7cb-9e1b-4c8d-a188-ed406c2b51b7
 
288