File: AudioIOPrefs.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 (700 lines) | stat: -rw-r--r-- 20,588 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
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/**********************************************************************

  Audacity: A Digital Audio Editor

  AudioIOPrefs.cpp

  Joshua Haberman

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

#ifdef __WXMAC__
#include <Sound.h>
#include <TextUtils.h>
#endif

#include <wx/window.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/gdicmn.h>
#include <wx/statbox.h>
#include <wx/msgdlg.h>
#include <wx/button.h>
#include <wx/utils.h>
#include <wx/sizer.h>

#ifdef __WXMSW__
extern "C" {
#include <windows.h>
#include <mmsystem.h>
}
#endif

#include "../Audacity.h"

#include "../Prefs.h"
#include "AudioIOPrefs.h"

enum {
   PlaybackTestID = 1000,
   PlaybackDefaultID,
   RecordingTestID,
   RecordingDefaultID,
   RecordingDeviceChoiceID,
   RecordingInputChoiceID,
   PlaybackDeviceChoiceID,
   RecordingVolumeID,
   PlaybackVolumeID
};

BEGIN_EVENT_TABLE(AudioIOPrefs, wxPanel)
   EVT_BUTTON(PlaybackTestID, AudioIOPrefs::TestPlaybackDevice)
   EVT_BUTTON(PlaybackDefaultID, AudioIOPrefs::SetPlaybackDeviceDefault)
   EVT_BUTTON(RecordingTestID, AudioIOPrefs::TestRecordingDevice)
   EVT_BUTTON(RecordingDefaultID, AudioIOPrefs::SetRecordingDeviceDefault)
   EVT_CHOICE(RecordingDeviceChoiceID, AudioIOPrefs::OnRecordingDeviceChoice)   
END_EVENT_TABLE()

AudioIOPrefs::AudioIOPrefs(wxWindow * parent):
PrefsPanel(parent)
{
#ifdef __WXGTK__
   wxString defaultPlaybackDevice = "/dev/dsp";
   wxString defaultRecordingDevice = "/dev/dsp";
#endif // __WXGTK__

#ifdef __WXMSW__
   wxString defaultPlaybackDevice = "";
   wxString defaultRecordingDevice = "";
#endif // __WXMSW__

#ifdef __WXMAC__
   wxString defaultPlaybackDevice = "Built-in";
   Handle iconH;
   Str255 name;
   SPBGetIndexedDevice(0, name, &iconH);
   CopyPascalStringToC((const unsigned char *)name, (char *)name);
   wxString defaultRecordingDevice = name;
   defaultRecordingDevice += "\n";
   defaultRecordingDevice += "Built-in Mic";
#endif // __WXMAC__

   /* read prefs all at once, then set up the dialog */
   gPrefs->SetPath("/AudioIO");
   mPlayDevice = gPrefs->Read("PlaybackDevice", defaultPlaybackDevice);
   mRecDevice = gPrefs->Read("RecordingDevice", defaultRecordingDevice);
   bool recordStereo;
   gPrefs->Read("RecordStereo", &recordStereo, false);
   bool duplex;
   gPrefs->Read("Duplex", &duplex, false);
   gPrefs->SetPath("/");

   topSizer = new wxStaticBoxSizer(
      new wxStaticBox(this,
                      -1,
                     "Audio I/O Settings"),
      wxVERTICAL);

#ifdef __WXGTK__

   #if USE_AUDIO_NONE
   wxString msg = 
      "This version of Audacity was compiled without any "
      "Audio I/O support.";
   topSizer->Add(new wxStaticText(this, -1, msg),
                 0, wxALL|wxGROW, TOP_LEVEL_BORDER);
   #elif USE_ARTS
   wxString msg = 
      "This version of Audacity was compiled to use the KDE/aRts "
      "soundserver.\n"
      "Please use your KDE control panel to configure audio I/O.";
   topSizer->Add(new wxStaticText(this, -1, msg),
                 0, wxALL|wxGROW, TOP_LEVEL_BORDER);
   #else

   {      
      wxStaticBoxSizer *playbackSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Playback Device"),
            wxVERTICAL);

      {
         wxBoxSizer *pFileSizer = new wxBoxSizer(wxHORIZONTAL);

         mPlaybackDeviceCtrl = new wxTextCtrl(this, -1, mPlayDevice);

         pFileSizer->Add(
            new wxStaticText(this, -1, "Device:"), 0, 
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         pFileSizer->Add(mPlaybackDeviceCtrl, 1, 
            wxGROW|wxALL|wxALIGN_CENTER_VERTICAL, GENERIC_CONTROL_BORDER);

         playbackSizer->Add(pFileSizer, 0,
            wxGROW|wxALL, GENERIC_CONTROL_BORDER);
      }


      {
         wxBoxSizer *pButtonsSizer = new wxBoxSizer(wxHORIZONTAL);

         //mPlaybackDeviceTest = new wxButton(this, PlaybackTestID, "Test");
         mPlaybackDeviceDefault = new wxButton(this,
                                               PlaybackDefaultID,
                                               "Default");

         /* pButtonsSizer->Add(
            mPlaybackDeviceTest, 0,
            wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER); */

         pButtonsSizer->Add(
            mPlaybackDeviceDefault, 0,
            wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         playbackSizer->Add(pButtonsSizer, 0,
            wxALIGN_RIGHT|wxLEFT|wxRIGHT, GENERIC_CONTROL_BORDER);
      }

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

   }

   {
      wxStaticBoxSizer *recordingSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Recording Device"),
            wxVERTICAL);

      {

         wxBoxSizer *rFileSizer = new wxBoxSizer(wxHORIZONTAL);

         mRecordingDeviceCtrl = new wxTextCtrl(this, -1, mRecDevice);

         rFileSizer->Add(
            new wxStaticText(this, -1, "Device:"), 0,
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         rFileSizer->Add(mRecordingDeviceCtrl, 1,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         recordingSizer->Add(rFileSizer, 0,
            wxGROW|wxALL, GENERIC_CONTROL_BORDER);
      }

      {
         wxBoxSizer *rButtonsSizer = new wxBoxSizer(wxHORIZONTAL);

         //mRecordingDeviceTest = new wxButton(this,
         //                                    RecordingTestID, "Test");
         mRecordingDeviceDefault = new wxButton(this,
                                                RecordingDefaultID,
                                                "Default");

         /* rButtonsSizer->Add(
            mRecordingDeviceTest, 0,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER); */

         rButtonsSizer->Add(mRecordingDeviceDefault, 0,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         recordingSizer->Add(rButtonsSizer, 0,
            wxALIGN_RIGHT|wxLEFT|wxRIGHT, GENERIC_CONTROL_BORDER);
      }

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

#endif // OSS

#endif                          // __WXGTK__

#ifdef __WXMAC__

   {
      int count, selected;
      wxString *names;
      wxBoxSizer *choiceSizer;
   
      //
      // Recording Sizer
      //
   
      wxStaticBoxSizer *recordingSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Recording"),
            wxVERTICAL);

      // Recording Device (i.e. built-in, CD)

      choiceSizer = new wxBoxSizer(wxHORIZONTAL);
      
      choiceSizer->Add(
            new wxStaticText(this, -1, "Device: "), 0, 
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT | wxTOP | wxRIGHT, GENERIC_CONTROL_BORDER);

      GetRecordingDevices(&count, &selected, &names);
      
      mRecordingDeviceChoice = new wxChoice(this, RecordingDeviceChoiceID,
                                            wxDefaultPosition, wxDefaultSize,
                                            count, names);
      mRecordingDeviceChoice->SetSelection(selected);
      
      choiceSizer->Add(mRecordingDeviceChoice, 1,
                       wxGROW | wxLEFT | wxTOP | wxRIGHT,
                       GENERIC_CONTROL_BORDER);
      
      recordingSizer->Add(choiceSizer, 1,
                          wxGROW | wxALL, GENERIC_CONTROL_BORDER);

      // Recording Input Source (i.e. Mic, Line In, Modem)

      choiceSizer = new wxBoxSizer(wxHORIZONTAL);
      
      choiceSizer->Add(
            new wxStaticText(this, -1, "Input: "), 0, 
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT | wxBOTTOM | wxRIGHT, GENERIC_CONTROL_BORDER);

      GetRecordingInputs(mRecordingDeviceChoice->GetSelection(), &count, &selected, &names);
      
      mRecordingInputChoice = new wxChoice(this, RecordingInputChoiceID,
                                           wxDefaultPosition, wxDefaultSize,
                                           count, names);
      mRecordingInputChoice->SetSelection(selected);
      
      choiceSizer->Add(mRecordingInputChoice, 1,
                       wxGROW | wxLEFT | wxBOTTOM | wxRIGHT,
                       GENERIC_CONTROL_BORDER);
      
      recordingSizer->Add(choiceSizer, 1,
                          wxGROW | wxALL, GENERIC_CONTROL_BORDER);
                          
      topSizer->Add(recordingSizer, 0, wxALL|wxGROW, TOP_LEVEL_BORDER);

      //
      // Playback sizer
      //

      wxStaticBoxSizer *playbackSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Playback"),
            wxVERTICAL);
      
      // Playback device (i.e. built-in)

      choiceSizer = new wxBoxSizer(wxHORIZONTAL);
      
      choiceSizer->Add(
            new wxStaticText(this, -1, "Device: "), 0, 
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);
            
      GetPlaybackDevices(&count, &selected, &names);
            
      mPlaybackDeviceChoice = new wxChoice(this, PlaybackDeviceChoiceID,
                                            wxDefaultPosition, wxDefaultSize,
                                            count, names);
      mPlaybackDeviceChoice->SetSelection(selected);
      
      choiceSizer->Add(mPlaybackDeviceChoice, 1, wxGROW | wxALL, GENERIC_CONTROL_BORDER);
      
      playbackSizer->Add(choiceSizer, 1,
                         wxGROW | wxALL, GENERIC_CONTROL_BORDER);
                          
      topSizer->Add(playbackSizer, 0, wxALL|wxGROW, TOP_LEVEL_BORDER);
      
      // Cleanup
      
      delete[] names;
   }

#endif                          // __WXMAC__

#ifdef __WXMSW__

   {
      wxStaticBoxSizer *playbackSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Playback Device"),
            wxVERTICAL);

      {
         wxBoxSizer *pFileSizer = new wxBoxSizer(wxHORIZONTAL);

         int numDevices = waveOutGetNumDevs();
         wxString *deviceNames = new wxString[numDevices];
         WAVEOUTCAPS caps;

         for(int j = 0; j < numDevices; j++) {
             waveOutGetDevCaps(j, &caps, sizeof(WAVEOUTCAPS));
             deviceNames[j] = caps.szPname;
         }

         mPlaybackDeviceCtrl = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
             numDevices, deviceNames);
         mPlaybackDeviceCtrl->SetStringSelection(mPlayDevice);
         if(mPlaybackDeviceCtrl->GetSelection() == -1)
             mPlaybackDeviceCtrl->SetSelection(0);

         pFileSizer->Add(
            new wxStaticText(this, -1, "Device:"), 0, 
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         pFileSizer->Add(mPlaybackDeviceCtrl, 1, 
            wxGROW|wxALL|wxALIGN_CENTER_VERTICAL, GENERIC_CONTROL_BORDER);

         playbackSizer->Add(pFileSizer, 0,
            wxGROW|wxALL, GENERIC_CONTROL_BORDER);
      }


      {
         /* Lets hide these until they actually do something 
         wxBoxSizer *pButtonsSizer = new wxBoxSizer(wxHORIZONTAL);

         mPlaybackDeviceTest = new wxButton(this, PlaybackTestID, "Test");
         mPlaybackDeviceVol = new wxButton(this,
                                               PlaybackVolumeID,
                                               "Volume");

         pButtonsSizer->Add(
            mPlaybackDeviceTest, 0,
            wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         pButtonsSizer->Add(
            mPlaybackDeviceVol, 0,
            wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         playbackSizer->Add(pButtonsSizer, 0,
            wxALIGN_RIGHT|wxLEFT|wxRIGHT, GENERIC_CONTROL_BORDER); */
      }

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



   {
      wxStaticBoxSizer *recordingSizer =
          new wxStaticBoxSizer(
            new wxStaticBox(this, -1, "Recording Device"),
            wxVERTICAL);

      {

         wxBoxSizer *rFileSizer = new wxBoxSizer(wxHORIZONTAL);

         
         int numDevices = waveInGetNumDevs();
         wxString *deviceNames = new wxString[numDevices];
         WAVEINCAPS caps;

         for(int j = 0; j < numDevices; j++) {
             waveInGetDevCaps(j, &caps, sizeof(WAVEINCAPS));
             deviceNames[j] = caps.szPname;
         }

         mRecordingDeviceCtrl = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
             numDevices, deviceNames);
         mRecordingDeviceCtrl->SetStringSelection(mRecDevice);
         if(mRecordingDeviceCtrl->GetSelection() == -1)
              mRecordingDeviceCtrl->SetSelection(0);


         rFileSizer->Add(
            new wxStaticText(this, -1, "Device:"), 0,
            wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         rFileSizer->Add(mRecordingDeviceCtrl, 1,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

         recordingSizer->Add(rFileSizer, 0,
            wxGROW|wxALL, GENERIC_CONTROL_BORDER);
      }

      {
         /* Lets hide these until they actually do something
         wxBoxSizer *rButtonsSizer = new wxBoxSizer(wxHORIZONTAL);

         mRecordingDeviceTest = new wxButton(this,
                                             RecordingTestID, "Test");
         mRecordingDeviceVol = new wxButton(this,
                                                RecordingVolumeID,
                                                "Volume");

         rButtonsSizer->Add(
            mRecordingDeviceTest, 0,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         rButtonsSizer->Add(mRecordingDeviceVol, 0,
            wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT,
            GENERIC_CONTROL_BORDER);

         recordingSizer->Add(rButtonsSizer, 0,
            wxALIGN_RIGHT|wxLEFT|wxRIGHT, GENERIC_CONTROL_BORDER);
         */
      }

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

#endif                          // __WXMSW__


   mRecordStereo = new wxCheckBox(this, -1, "Record in Stereo");
   mRecordStereo->SetValue(recordStereo);
   topSizer->Add(mRecordStereo, 0, wxGROW|wxALL, 2);



   mDuplex = new wxCheckBox(this, -1,
                            "Play other tracks while recording new one");
   mDuplex->SetValue(duplex);
   topSizer->Add(mDuplex, 0, wxGROW|wxALL, 2);

   #ifdef __WXGTK__
   topSizer->Add(new wxStaticText(this, -1,
                                  "(Playing while recording does not work "
                                  "on most Unix systems, sorry...)"),
                 0, wxALIGN_LEFT|wxALL,
                 GENERIC_CONTROL_BORDER);   
   #endif

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

}


bool AudioIOPrefs::Apply()
{
   /* Step 1: Validate input */
#ifdef __WXGTK__

#if USE_OSS
   mPlayDevice = mPlaybackDeviceCtrl->GetValue();
   if (!wxFileExists(mPlayDevice) || wxDirExists(mPlayDevice)) {
      wxMessageBox("Invalid playback device.", "Error",
                   wxOK | wxCENTRE | wxICON_EXCLAMATION);
      return false;
   }

   mRecDevice = mRecordingDeviceCtrl->GetValue();
   if (!wxFileExists(mRecDevice) || wxDirExists(mRecDevice)) {
      wxMessageBox("Invalid recording device.", "Error",
                   wxOK | wxCENTRE | wxICON_EXCLAMATION);
      return false;
   }
#endif

#endif                          // __WXGTK__

#ifdef __WXMAC__
   mPlayDevice = mPlaybackDeviceChoice->GetStringSelection();
   mRecDevice = mRecordingDeviceChoice->GetStringSelection() + "\n" +
                mRecordingInputChoice->GetStringSelection();
#endif                          // __WXMAC__

#ifdef __WXMSW__
   mPlayDevice = mPlaybackDeviceCtrl->GetStringSelection();
   mRecDevice = mRecordingDeviceCtrl->GetStringSelection();   
#endif                          // __WXMSW__

   bool recordStereo = mRecordStereo->GetValue();
   bool duplex = mDuplex->GetValue();

   /* Step 2: Write to gPrefs */
   gPrefs->SetPath("/AudioIO");

   gPrefs->Write("PlaybackDevice", mPlayDevice);
   gPrefs->Write("RecordingDevice", mRecDevice);

   gPrefs->Write("RecordStereo", recordStereo);
   gPrefs->Write("Duplex", duplex);
   gPrefs->SetPath("/");

   /* Step 3: Make audio sub-system re-read preferences */

   return true;
}

void AudioIOPrefs::OnRecordingDeviceChoice(wxCommandEvent & event)
{
#ifdef __WXMAC__
   wxString *inputNames;
   int count;
   int x;
   
   GetRecordingInputs(mRecordingDeviceChoice->GetSelection(), &count, &x, &inputNames);
   mRecordingInputChoice->Clear();
   for(int y=0; y<count; y++)
      mRecordingInputChoice->Append(inputNames[y]);
   mRecordingInputChoice->SetSelection(x);
   delete[] inputNames;
#endif
}

void AudioIOPrefs::TestPlaybackDevice(wxCommandEvent & event)
{
}

void AudioIOPrefs::SetPlaybackDeviceDefault(wxCommandEvent & event)
{
   /* TODO: attempt autodetection? */
#ifdef __WXGTK__
   mPlaybackDeviceCtrl->SetValue("/dev/dsp");
#endif                          // __WXGTK__
}

void AudioIOPrefs::TestRecordingDevice(wxCommandEvent & event)
{
}

void AudioIOPrefs::SetRecordingDeviceDefault(wxCommandEvent & event)
{
#ifdef __WXGTK__
   mRecordingDeviceCtrl->SetValue("/dev/dsp");
#endif                          // __WXGTK__
}

AudioIOPrefs::~AudioIOPrefs()
{
}

#ifdef __WXMAC__

//
// Mac-specific methods to get lists of the available recording devices,
// recording input sources, and playback devices.
//

void AudioIOPrefs::GetRecordingDevices(int *theCount, int *theSelected, wxString **theNames)
{
   int count=0, x, selected=0;
   Handle iconH;
   Str255 name;
   while(SPBGetIndexedDevice(count+1, name, &iconH) == 0)
      count++;
      
   wxString selectedDevice = mRecDevice.BeforeFirst('\n');

   wxString *deviceNames = new wxString[count];
   for(x=0; x<count; x++) {
      SPBGetIndexedDevice(x+1, name, &iconH);
      deviceNames[x] = p2cstr(name);
      
      if (deviceNames[x] == selectedDevice)
         selected = x;
   }
   
   *theCount = count;
   *theSelected = selected;
   *theNames = deviceNames;
}

void AudioIOPrefs::GetRecordingInputs(int deviceNum, int *theCount, int *theSelected, wxString **theNames)
{
   OSErr err;
   Handle h;
   Str255 deviceName;
   long refnum;
   SoundInfoList infoList;
   int count;
   short selected;
   wxString *names;
   Handle iconH;

   *theCount = 0;
   *theSelected = 0;
   *theNames = NULL;

   wxString selectedInput = mRecDevice.AfterLast('\n');

   SPBGetIndexedDevice(deviceNum+1, deviceName, &iconH);

   err = SPBOpenDevice(deviceName, siReadPermission, &refnum);

   if (err != 0)
      return;

   SPBGetDeviceInfo (refnum, siInputAvailable, &infoList);
   count = infoList.count;
   
   if (count<0 || count>50)
      return;

   // Get default from OS in case the one in the prefs was not found.
   SPBGetDeviceInfo (refnum, siInputSource, &selected);
   selected--;

   names = new wxString[count];

   char **buffer;
   SPBGetDeviceInfo (refnum, siInputSourceNames, &buffer);
   char *data = buffer[0] + 2;
   
   for(int x=0; x<count; x++) {
      int y = *data++;
      while(y) {
         names[x] += *data++;
         y--;
      }
      if (names[x] == selectedInput)
         selected = x;
   }

   SPBCloseDevice(refnum);
   
   *theCount = count;
   *theNames = names;
   *theSelected = selected;
}

void AudioIOPrefs::GetPlaybackDevices(int *theCount, int *theSelected, wxString **theNames)
{
   int count, x;
   int selected;

   ComponentDescription description;
   description.componentType = kSoundOutputDeviceType;
   description.componentSubType = kAnyComponentSubType;
   description.componentManufacturer = kAnyComponentManufacturer;
   description.componentFlags = 0;
   description.componentFlagsMask = 0;

   count = CountComponents(&description);
   *theSelected = 0;

   wxString *outputNames = new wxString[count];
   
   Component playbackDevice = NULL;      
   for(x=0; x<count; x++) {
      playbackDevice = FindNextComponent(playbackDevice, &description);

      Handle name = NewHandle(256);
      GetComponentInfo(playbackDevice, NULL, name, NULL, NULL);
      HLock(name);
      outputNames[x] = p2cstr((unsigned char *)*name);
      HUnlock(name);
      DisposeHandle(name);
      
      if (outputNames[x] == mPlayDevice)
         *theSelected = x;
   }
   
   *theCount = count;
   *theNames = outputNames;
}

#endif  // __WXMAC__