/[svn]/linuxsampler/trunk/src/drivers/audio/CAAudioDeviceModel.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/audio/CAAudioDeviceModel.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1832 - (hide annotations) (download) (as text)
Thu Feb 5 17:48:54 2009 UTC (15 years, 2 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 6813 byte(s)
* CoreAudio: Improved hardware detection
* CoreAudio: Added new driver parameter DEVICE
* CoreAudio: Restart the audio queue when the device
  is changed, for example when headphones are plugged

1 iliev 1832 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2009 Grigor Iliev *
6     * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #ifndef __CAAUDIODEVICEMODEL_H__
24     #define __CAAUDIODEVICEMODEL_H__
25    
26     #include <string>
27     #include <vector>
28     #include <CoreAudio/CoreAudio.h>
29    
30     #include "../../EventListeners.h"
31     #include "../../common/Mutex.h"
32    
33     namespace LinuxSampler {
34    
35     class CAAudioStream {
36     private:
37     UInt32 InputStream;
38     UInt32 ChannelNumber;
39    
40     public:
41     CAAudioStream(UInt32 input, UInt32 chns) {
42     InputStream = input, ChannelNumber = chns;
43     }
44    
45     CAAudioStream& operator=(const CAAudioStream& s) {
46     InputStream = s.InputStream;
47     ChannelNumber = s.ChannelNumber;
48     return *this;
49     }
50    
51     CAAudioStream(const CAAudioStream& s) { *this = s; }
52    
53     UInt32 IsInputStream() { return InputStream; }
54     UInt32 GetChannelNumber() { return ChannelNumber; }
55     };
56    
57     class CAAudioDeviceModelListener {
58     public:
59     virtual void DeviceChanged() { }
60     };
61    
62     class CAAudioDeviceListModelListener {
63     public:
64     virtual void DeviceChanged(AudioDeviceID devID) { }
65     virtual void DeviceListChanged() { }
66     virtual void DefaultOutputDeviceChanged(AudioDeviceID newID) { }
67     };
68    
69     class CAAudioDeviceModel : public ListenerList<CAAudioDeviceModelListener*>,
70     public CAAudioDeviceListModelListener {
71    
72     friend class CAAudioDeviceListModel;
73    
74     public:
75     CAAudioDeviceModel(AudioDeviceID Id);
76     CAAudioDeviceModel(const CAAudioDeviceModel& m);
77     ~CAAudioDeviceModel();
78     CAAudioDeviceModel& operator=(const CAAudioDeviceModel& m);
79    
80     AudioDeviceID GetID();
81     std::string GetUID();
82     std::string GetName();
83     int GetChannelNumber();
84     int GetDefaultSamplerate();
85    
86     const std::vector<int> GetNominalSamplerates();
87     std::vector<CAAudioStream> GetAudioStreams();
88    
89     //from CAAudioDeviceListModelListener
90     virtual void DeviceChanged(AudioDeviceID devID);
91    
92     private:
93     AudioDeviceID Id;
94     std::string Uid;
95     std::string Name;
96     int ChannelNumber;
97     int DefaultSamplerate;
98    
99     std::vector<int> NominalSamplerates;
100     std::vector<CAAudioStream> AudioStreams;
101    
102     char* charBuf;
103     UInt32 charBufSize;
104    
105     void Init();
106     std::string GetStr(CFStringRef s);
107     void SetUID(CFStringRef s);
108     void SetName(CFStringRef s);
109     void FireDeviceChangedEvent();
110     };
111    
112     /////////////////////////////////////////////////////
113     ////
114    
115     class CAAudioDeviceListModel : public ListenerList<CAAudioDeviceListModelListener*> {
116     public:
117     ~CAAudioDeviceListModel();
118     static CAAudioDeviceListModel* GetModel();
119    
120     AudioDeviceID GetDefaultOutputDeviceID();
121     UInt32 GetOutputDeviceCount();
122     CAAudioDeviceModel GetOutputDevice(UInt32 Index);
123     CAAudioDeviceModel GetOutputDeviceByID(AudioDeviceID devID);
124     UInt32 GetOutputDeviceIndex(AudioDeviceID devID);
125    
126     private:
127     CAAudioDeviceListModel(); // Forbid instantiation of this class
128     static CAAudioDeviceListModel* pModel;
129     std::vector<CAAudioDeviceModel> inDevices;
130     std::vector<CAAudioDeviceModel> outDevices;
131     AudioDeviceID DefaultOutputDeviceID;
132     Mutex DeviceMutex;
133    
134     void InstallListeners();
135     void UninstallListeners();
136     void InstallDeviceListeners();
137     void InstallDeviceListener(AudioDevicePropertyID id);
138     void UninstallDeviceListeners();
139     void UninstallDeviceListener(AudioDevicePropertyID id);
140     void InstallHardwareListeners();
141     void InstallHardwareListener(AudioHardwarePropertyID id);
142     void UninstallHardwareListeners();
143     void UninstallHardwareListener(AudioHardwarePropertyID id);
144     void RescanDevices();
145     void GetSamplerates(CAAudioDeviceModel* pDev);
146     void GetChannels(CAAudioDeviceModel* pDev);
147     void GetStreams(CAAudioDeviceModel* pDev);
148     void UpdateDefaultOutputDevice();
149     void FireDeviceChangedEvent(AudioDeviceID devID);
150     void FireDeviceListChangedEvent();
151     void FireDefaultOutputDeviceChangedEvent(AudioDeviceID newID);
152    
153     static OSStatus AudioHardwarePropertyListenerCallback (
154     AudioHardwarePropertyID inPropertyID, void* inClientData
155     );
156    
157     static OSStatus AudioDevicePropertyListenerCallback (
158     AudioDeviceID inDevice,
159     UInt32 inChannel,
160     Boolean isInput,
161     AudioDevicePropertyID inPropertyID,
162     void* inClientData
163     );
164     };
165     } // namespace LinuxSampler
166    
167     #endif /* __CAAUDIODEVICEMODEL_H__ */

  ViewVC Help
Powered by ViewVC