tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_WaveDeviceDescription.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14//==============================================================================
16
18 : indexInDevice (index), channel (c)
19{
20}
21
22bool ChannelIndex::operator== (const ChannelIndex& other) const { return indexInDevice == other.indexInDevice && channel == other.channel; }
23bool ChannelIndex::operator!= (const ChannelIndex& other) const { return ! operator== (other); }
24
26{
28 bool isFirst = true;
29
30 for (const auto& ci : channels)
31 {
32 if (! isFirst)
33 desc << ", ";
34 else
35 isFirst = false;
36
37 desc << ci.indexInDevice << " (" << juce::AudioChannelSet::getAbbreviatedChannelTypeName (ci.channel) << ")";
38 }
39
40 return desc.toString();
41}
42
44{
45 juce::AudioChannelSet channelSet;
46
47 for (const auto& ci : channels)
48 channelSet.addChannel (ci.channel);
49
50 return channelSet;
51}
52
54{
55 struct NamedChannelTypeCache
56 {
57 NamedChannelTypeCache()
58 {
59 for (int i = 0; i < juce::AudioChannelSet::discreteChannel0; ++i)
60 {
61 const auto channelType = static_cast<juce::AudioChannelSet::ChannelType> (i);
63
64 if (name.isNotEmpty())
65 map[name] = channelType;
66 }
67 }
68
70 };
71
72 static NamedChannelTypeCache cache;
73 const auto result = cache.map.find (abbreviatedName);
74
75 if (result != cache.map.end())
76 return result->second;
77
79}
80
82{
84
85 for (auto& channel : juce::StringArray::fromTokens (arrangement, false))
86 {
87 const auto ct = channelTypeFromAbbreviatedName (channel);
88
90 cs.addChannel (ct);
91 }
92
93 return cs;
94}
95
96//==============================================================================
98
99WaveDeviceDescription::WaveDeviceDescription (const juce::String& nm, int l, int r, bool isEnabled)
100 : name (nm), enabled (isEnabled)
101{
102 if (l >= 0) channels.push_back (ChannelIndex (l, juce::AudioChannelSet::left));
103 if (r >= 0) channels.push_back (ChannelIndex (r, juce::AudioChannelSet::right));
104}
105
106WaveDeviceDescription::WaveDeviceDescription (const juce::String& nm, const ChannelIndex* chans, int numChans, bool isEnabled)
107 : name (nm), channels (chans, chans + numChans), enabled (isEnabled)
108{}
109
110bool WaveDeviceDescription::operator== (const WaveDeviceDescription& other) const
111{
112 return name == other.name && enabled == other.enabled && channels == other.channels;
113}
114
115bool WaveDeviceDescription::operator!= (const WaveDeviceDescription& other) const
116{
117 return ! operator== (other);
118}
119
120}} // namespace tracktion { inline namespace engine
void addChannel(ChannelType newChannelType)
static String JUCE_CALLTYPE getAbbreviatedChannelTypeName(ChannelType)
String toString() const
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
juce::AudioChannelSet createChannelSet(const std::vector< ChannelIndex > &channels)
Creates an AudioChannelSet for a list of ChannelIndexes.
juce::AudioChannelSet::ChannelType channelTypeFromAbbreviatedName(const juce::String &abbreviatedName)
Returns the ChannelType for an abbreviated name.
juce::String createDescriptionOfChannels(const std::vector< ChannelIndex > &channels)
Creates a String description of the channels.
juce::AudioChannelSet channelSetFromSpeakerArrangmentString(const juce::String &arrangement)
Creates an AudioChannelSet from a list of abbreviated channel names.
Describes a channel of a WaveInputDevice or WaveOutputDevice by specifying the channel index in the g...
ChannelIndex()
Creates a default, invalid ChannelIndex.
Describes a WaveDevice from which the WaveOutputDevice and WaveInputDevice lists will be built.
WaveDeviceDescription()
Creates an invalid device description.