File: SampleRatePrefs.cpp

package info (click to toggle)
audacity 0.98-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,896 kB
  • ctags: 4,089
  • sloc: cpp: 26,099; ansic: 4,961; sh: 2,465; makefile: 156; perl: 23
file content (110 lines) | stat: -rw-r--r-- 2,558 bytes parent folder | download
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
/**********************************************************************

  Audacity: A Digital Audio Editor

  SampleRatePrefs.cpp

  Joshua Haberman

**********************************************************************/

#include <wx/window.h>
#include <wx/statbox.h>
#include <wx/sizer.h>

#include "../Prefs.h"
#include "SampleRatePrefs.h"

int rates[] = { 8000,
   11025,
   16000,
   22050,
   44100,
   48000
};

wxString stringRates[] = { "8000",
   "11025",
   "16000",
   "22050",
   "44100",
   "48000"
};

// Don't forget to change the size of the mSampleRates array in
// SampleRatePrefs.h when you change this
#define NUM_RATES 6

SampleRatePrefs::SampleRatePrefs(wxWindow * parent):
PrefsPanel(parent)
{
   int rate =
       gPrefs->Read("/SamplingRate/DefaultProjectSampleRate", 44100);

   int pos = 4;     // Fall back to 44100 if it doesn't match anything else
   for (int i = 0; i < NUM_RATES; i++)
      if (rate == rates[i]) {
         pos = i;
         break;
      }

    topSizer = new wxStaticBoxSizer(
      new wxStaticBox(this, -1, "Sample Rate Preferences"), 
      wxVERTICAL );

   {
      wxStaticBoxSizer *defProjSizer = new wxStaticBoxSizer(
         new wxStaticBox(this, -1, "Default Project Sample Rate"),
         wxVERTICAL );

      mSampleRates[0] = new wxRadioButton(this, -1, stringRates[0],
                                          wxDefaultPosition, wxDefaultSize,
                                          wxRB_GROUP);
      mSampleRates[0]->SetValue(false);

      defProjSizer->Add(
         mSampleRates[0], 0, wxGROW | wxLEFT | wxRIGHT, RADIO_BUTTON_BORDER);

      for(int j = 1; j < NUM_RATES; j++) {
         mSampleRates[j] = new wxRadioButton(this, -1, stringRates[j]);
         mSampleRates[j]->SetValue(false);
         defProjSizer->Add(
            mSampleRates[j], 0, wxGROW| wxLEFT | wxRIGHT, RADIO_BUTTON_BORDER);
      }

      mSampleRates[pos]->SetValue(true);

      topSizer->Add( defProjSizer, 0, wxGROW|wxALL, TOP_LEVEL_BORDER );
   }

   SetAutoLayout(true);
   topSizer->Fit(this);
   topSizer->SetSizeHints(this);
   SetSizer(topSizer);
}

bool SampleRatePrefs::Apply()
{
   long rate;

   for(int i = 0; i < NUM_RATES; i++)
      if(mSampleRates[i]->GetValue()) {
         rate = rates[i];
         break;
      }

   gPrefs->Write("/SamplingRate/DefaultProjectSampleRate", rate);

   /* Audacity will automatically re-read this value whenever a new project
    * is created, so don't bother making it do so now... */

   return true;

}


SampleRatePrefs::~SampleRatePrefs()
{
}