25template<
typename SampleType>
40 virtual void prepare (
double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames) = 0;
52 HART_DEPRECATED (
"This method is deprecated. Switch to the one that uses AnalysisContext instead.")
56 return match (analysisContext);
68 return match (analysisContext.inputAudio(), analysisContext.outputAudio());
104 virtual void represent (std::ostream& stream)
const = 0;
136 return this->m_channelsToMatch[channel];
144 return this->m_channelsToMatch;
153 prepare (sampleRateHz
, numInputChannels
, numOutputChannels
, maxBlockSizeFrames
);
160 this->represent (stream);
165 stream <<
".atChannels (";
186template<
typename SampleType,
typename Derived>
196 return hart::make_unique<Derived> (
static_cast<
const Derived&> (*
this));
203 return hart::make_unique<Derived> (std::move (
static_cast<Derived&> (*
this)));
213 Derived&
atChannels (std::initializer_list<size_t> channelsToMatch) &
215 _atChannels (channelsToMatch);
216 return static_cast<Derived&> (*
this);
226 Derived&&
atChannels (std::initializer_list<size_t> channelsToMatch) &&
228 _atChannels (channelsToMatch);
229 return static_cast<Derived&&> (*
this);
242 _atChannel (channelToMatch);
243 return static_cast<Derived&> (*
this);
256 _atChannel (channelToMatch);
257 return static_cast<Derived&&> (*
this);
267 return static_cast<Derived&> (*
this);
277 return static_cast<Derived&&> (*
this);
289 _atAllChannelsExcept (channelsToSkip);
290 return static_cast<Derived&> (*
this);
302 _atAllChannelsExcept (channelsToSkip);
303 return static_cast<Derived&&> (*
this);
307 void _atChannels (std::initializer_list<size_t> channelsToMatch)
309 this->m_channelsToMatch.setAllTo (
false);
311 for (size_t channel : channelsToMatch)
313 if (channel >=
this->m_channelsToMatch.size())
316 this->m_channelsToMatch[channel] =
true;
320 void _atChannel (size_t channelToMatch)
322 if (channelToMatch >=
this->m_channelsToMatch.size())
325 this->m_channelsToMatch.setAllTo (
false);
326 this->m_channelsToMatch[channelToMatch] =
true;
329 void _atAllChannels()
331 this->m_channelsToMatch.setAllTo (
true);
334 void _atAllChannelsExcept (std::initializer_list<size_t> channelsToSkip)
336 this->m_channelsToMatch.setAllTo (
true);
338 for (size_t channel : channelsToSkip)
340 if (channel >=
this->m_channelsToMatch.size())
343 this->m_channelsToMatch[channel] =
false;
351template <
typename SampleType>
352inline std::ostream& operator<< (std::ostream& stream,
const MatcherBase<SampleType>& matcher)
354 matcher.representWithActiveChannels (stream);
361#define HART_MATCHER_DECLARE_ALIASES_FOR(ClassName)
362 namespace aliases_float{
363 using ClassName = hart::ClassName<float>;
365 namespace aliases_double{
366 using ClassName = hart::ClassName<double>;
Contains audio-related artefacts useful for analysis by matchers.
Container for audio data.
A set of boolean flags mapped to each audio channel.
bool allTrue() const noexcept
Checks if all flags are set to true
ChannelFlags(bool defaultValues=true, size_t numChannels=m_maxChannels)
Creates a new channel flags object.
void resize(size_t newNumChannels)
Resizes the container.
void representAsInitializerList(std::ostream &stream) const
Makes text representation of itself as a initializer list of active channels.
Polymorphic base for all matchers.
bool appliesToChannel(size_t channel)
Indicates whether this matcher should check a specific channel.
virtual std::unique_ptr< MatcherBase< SampleType > > copy() const =0
Returns a smart pointer with a copy of this object.
void representWithActiveChannels(std::ostream &stream) const
Makes a text representation of this Matcher with optional "atChannels" appendix.
virtual void represent(std::ostream &stream) const =0
Makes a text representation of this Matcher for test failure outputs.
virtual bool canOperatePerBlock() const =0
Tells the host if it can operate on a block-by-block basis.
virtual bool supportsChannelLayout(size_t, size_t) const
Tells the host whether this Matcher is capable of operating on audio with a specific number of channe...
virtual void reset()
Resets the matcher to its initial state.
virtual MatcherFailureDetails getFailureDetails() const =0
Returns a description of why the match has failed.
void prepareWithActiveChannels(double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames)
Prepare for processing, meant to be called by a host.
virtual bool supportsSampleRate(double) const
Tells whether this Matcher supports given sample rate.
const AudioBuffer< SampleType > & observedOutputAudio
virtual std::unique_ptr< MatcherBase< SampleType > > move()=0
Returns a smart pointer with a moved instance of this object.
ChannelFlags getChannelFlags() const
Returns flags for the channels that the matcher should apply to.
virtual void prepare(double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames)=0
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
virtual ~MatcherBase()=default
virtual bool match(AnalysisContext< SampleType > analysisContext)
Tells the host if the piece of audio satisfies Matcher's condition or not.
ChannelFlags m_channelsToMatch
Derived & atChannels(std::initializer_list< size_t > channelsToMatch) &
Makes this matcher check only specific channels, and ignore the rest.
Derived && atChannels(std::initializer_list< size_t > channelsToMatch) &&
Makes this matcher check only specific channels, and ignore the rest.
virtual std::unique_ptr< MatcherBase< SampleType > > copy() const override
Returns a smart pointer with a copy of this object.
Derived && atChannel(size_t channelToMatch) &&
Makes this matcher check only one specific channel, and ignore the rest.
Derived & atChannel(size_t channelToMatch) &
Makes this matcher check only one specific channel, and ignore the rest.
Derived & atAllChannelsExcept(std::initializer_list< size_t > channelsToSkip) &
Makes this matcher check only specific channels, and ignore the rest.
Derived & atAllChannels() &
Makes this matcher check all channels.
virtual std::unique_ptr< MatcherBase< SampleType > > move() override
Returns a smart pointer with a moved instance of this object.
Derived && atAllChannels() &&
Makes this matcher check all channels.
Derived && atAllChannelsExcept(std::initializer_list< size_t > channelsToSkip) &&
Makes this matcher check only specific channels, and ignore the rest.
Thrown when an inappropriate value is encountered.
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns otherwise.
#define HART_DEPRECATED(msg)
Details about matcher failure.