From 7ee4c800a96b1fa35c4a1f7bacd5e021454f495e Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 7 Mar 2016 15:43:32 +0000 Subject: [PATCH] Add getChannelIndexForType to AudioChannelSet class --- .../processors/juce_AudioChannelSet.cpp | 14 ++++++++++++++ .../processors/juce_AudioChannelSet.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/modules/juce_audio_processors/processors/juce_AudioChannelSet.cpp b/modules/juce_audio_processors/processors/juce_AudioChannelSet.cpp index 118bfc5166..9e028d4750 100644 --- a/modules/juce_audio_processors/processors/juce_AudioChannelSet.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioChannelSet.cpp @@ -135,6 +135,20 @@ AudioChannelSet::ChannelType AudioChannelSet::getTypeOfChannel (int index) const return static_cast (bit); } +int AudioChannelSet::getChannelIndexForType (AudioChannelSet::ChannelType type) const noexcept +{ + int idx = 0; + for (int bit = channels.findNextSetBit (0); bit >= 0; bit = channels.findNextSetBit (bit + 1)) + { + if (static_cast (bit) == type) + return idx; + + idx++; + } + + return -1; +} + Array AudioChannelSet::getChannelTypes() const { Array result; diff --git a/modules/juce_audio_processors/processors/juce_AudioChannelSet.h b/modules/juce_audio_processors/processors/juce_AudioChannelSet.h index 50be92740b..9475ddf5ec 100644 --- a/modules/juce_audio_processors/processors/juce_AudioChannelSet.h +++ b/modules/juce_audio_processors/processors/juce_AudioChannelSet.h @@ -166,6 +166,10 @@ public: /** Returns the type of one of the channels in the set, by index. */ ChannelType getTypeOfChannel (int channelIndex) const noexcept; + /** Returns the index for a particular channel-type. + Will return -1 if the this set does not contain a channel of this type. */ + int getChannelIndexForType (ChannelType type) const noexcept; + /** Returns a string containing a whitespace-separated list of speaker types corresponding to each channel. For example in a 5.1 arrangement, the string may be "L R C Lfe Ls Rs". If the speaker arrangement is unknown,