8#include "matchers/hart_matcher.hpp"
41template<
typename SampleType>
56 m_matcherFunctionForAnalysisContext (std::move (matcherFunction)),
69 MatcherFunction (std::function <
Condition (
const AudioBuffer<SampleType>&,
const AudioBuffer<SampleType>&)> matcherFunction,
const std::string& label = {}) :
70 m_matcherFunctionForInputAndOutput (std::move (matcherFunction)),
83 m_matcherFunctionForOutputOnly (std::move (matcherFunction)),
90 if (m_matcherFunctionForOutputOnly !=
nullptr)
92 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
94 m_condition = std::move (m_matcherFunctionForOutputOnly (observedOutputAudio));
95 return m_condition.getResult();
98 if (m_matcherFunctionForInputAndOutput !=
nullptr)
100 const AudioBuffer<SampleType>& inputAudio = context.inputAudio();
101 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
103 m_condition = std::move (m_matcherFunctionForInputAndOutput (inputAudio, observedOutputAudio));
104 return m_condition.getResult();
107 if (m_matcherFunctionForAnalysisContext !=
nullptr)
109 m_condition = std::move (m_matcherFunctionForAnalysisContext (context));
110 return m_condition.getResult();
121 std::ostringstream descriptionStream;
123 if (m_condition.hasDetailedMetadata())
125 hassert (m_condition.getLine() >= 0);
126 hassert (m_condition.getFile() !=
nullptr);
127 hassert (m_condition.getFile()[0] !=
'\0');
130 <<
"Location: " << m_condition.getFile()
131 <<
':' << m_condition.getLine()
133 m_condition.representWithTokens (descriptionStream);
134 descriptionStream <<
"\nEvaluated: ";
135 m_condition.representWithStringRepresentations (descriptionStream);
139 descriptionStream <<
"Matcher function (" << (m_label.empty() ?
"no label" : m_label) <<
") has evaluated to false";
148 stream <<
"MatcherFunction (<function>, \"" << m_label <<
"\")";
152 void prepare (
double , size_t , size_t , size_t )
override {}
156 const std::function <
Condition (
const AudioBuffer<SampleType>&,
const AudioBuffer<SampleType>&)> m_matcherFunctionForInputAndOutput =
nullptr;
157 const std::function <
Condition (
const AudioBuffer<SampleType>&)> m_matcherFunctionForOutputOnly =
nullptr;
158 const std::string m_label;
Contains audio-related artefacts useful for analysis by matchers.
A class representing some condition.
Matcher defined by a user-provided function.
MatcherFunction(std::function< Condition(AnalysisContext< SampleType > analysisContext)> matcherFunction, const std::string &label={})
Constructs a matcher from a function that has access to the entire analysis context.
MatcherFunction(std::function< Condition(const AudioBuffer< SampleType > &, const AudioBuffer< SampleType > &)> matcherFunction, const std::string &label={})
Creates a matcher from a function that compares input and output.
void represent(std::ostream &stream) const override
Makes a text representation of this Matcher for test failure outputs.
void prepare(double, size_t, size_t, size_t) override
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
bool match(AnalysisContext< SampleType > context) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
bool canOperatePerBlock() const override
Tells the host if it can operate on a block-by-block basis.
virtual MatcherFailureDetails getFailureDetails() const override
Returns a description of why the match has failed.
MatcherFunction(std::function< Condition(const AudioBuffer< SampleType > &)> matcherFunction, const std::string &label={})
Constructs a matcher from a function that inspects only the output.
Thrown when a nullptr could be handled gracefully.
#define hassert(condition)
Triggers a HartAssertException if the condition is false
#define HART_THROW_OR_RETURN(ExceptionType, message, returnValue)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns a specified ...
#define HART_MATCHER_DECLARE_ALIASES_FOR(ClassName)
Details about matcher failure.
size_t channel
Index of channel at which the failure was detected.
std::string description
Readable description of why the match has failed.
size_t frame
Index of frame at which the match has failed.