summaryrefslogtreecommitdiff
path: root/portaudio/bindings/cpp/source/portaudiocpp/Device.cxx
blob: 7b21b03ca5293c06bbbfbef171eebe58b84e8b7d (plain)
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
#include "portaudiocpp/Device.hxx"

#include <cstddef>

#include "portaudiocpp/HostApi.hxx"
#include "portaudiocpp/System.hxx"
#include "portaudiocpp/Exception.hxx"

namespace portaudio
{

		// -------------------------------------------------------------------------------

		Device::Device(PaDeviceIndex index) : index_(index)
		{
			if (index == paNoDevice)
				info_ = NULL;
			else
				info_ = Pa_GetDeviceInfo(index);
		}

		Device::~Device()
		{
		}

		PaDeviceIndex Device::index() const
		{
			return index_;
		}

		const char *Device::name() const
		{
			if (info_ == NULL)
				return "";

			return info_->name;
		}

		int Device::maxInputChannels() const
		{
			if (info_ == NULL)
				return 0;

			return info_->maxInputChannels;
		}

		int Device::maxOutputChannels() const
		{
			if (info_ == NULL)
				return 0;

			return info_->maxOutputChannels;
		}

		PaTime Device::defaultLowInputLatency() const
		{
			if (info_ == NULL)
				return static_cast<PaTime>(0.0);

			return info_->defaultLowInputLatency;
		}

		PaTime Device::defaultHighInputLatency() const
		{
			if (info_ == NULL)
				return static_cast<PaTime>(0.0);

			return info_->defaultHighInputLatency;
		}

		PaTime Device::defaultLowOutputLatency() const
		{
			if (info_ == NULL)
				return static_cast<PaTime>(0.0);

			return info_->defaultLowOutputLatency;
		}

		PaTime Device::defaultHighOutputLatency() const
		{
			if (info_ == NULL)
				return static_cast<PaTime>(0.0);

			return info_->defaultHighOutputLatency;
		}

		double Device::defaultSampleRate() const
		{
			if (info_ == NULL)
				return 0.0;

			return info_->defaultSampleRate;
		}

		// -------------------------------------------------------------------------------

		bool Device::isInputOnlyDevice() const
		{
			return (maxOutputChannels() == 0);
		}

		bool Device::isOutputOnlyDevice() const
		{
			return (maxInputChannels() == 0);
		}

		bool Device::isFullDuplexDevice() const
		{
			return (maxInputChannels() > 0 && maxOutputChannels() > 0);
		}

		bool Device::isSystemDefaultInputDevice() const
		{
			return (System::instance().defaultInputDevice() == *this);
		}

		bool Device::isSystemDefaultOutputDevice() const
		{
			return (System::instance().defaultOutputDevice() == *this);
		}

		bool Device::isHostApiDefaultInputDevice() const
		{
			return (hostApi().defaultInputDevice() == *this);
		}

		bool Device::isHostApiDefaultOutputDevice() const
		{
			return (hostApi().defaultOutputDevice() == *this);
		}

		// -------------------------------------------------------------------------------

		bool Device::operator==(const Device &rhs) const
		{
			return (index_ == rhs.index_);
		}

		bool Device::operator!=(const Device &rhs) const
		{
			return !(*this == rhs);
		}

		// -------------------------------------------------------------------------------

		HostApi &Device::hostApi()
		{
			// NOTE: will cause an exception when called for the null device
			if (info_ == NULL)
				throw PaException(paInternalError);

			return System::instance().hostApiByIndex(info_->hostApi);
		}

		const HostApi &Device::hostApi() const
		{
			// NOTE; will cause an exception when called for the null device
			if (info_ == NULL)
				throw PaException(paInternalError);

			return System::instance().hostApiByIndex(info_->hostApi);
		}

		// -------------------------------------------------------------------------------

} // namespace portaudio