8#include "matchers/hart_matcher.hpp"
41template<
typename SampleType>
56 m_matcherFunctionForInputAndOutput (std::move (matcherFunction)),
69 m_matcherFunctionForOutputOnly (std::move (matcherFunction)),
76 if (m_matcherFunctionForOutputOnly !=
nullptr)
78 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
80 m_condition = std::move (m_matcherFunctionForOutputOnly (observedOutputAudio));
81 return m_condition.getResult();
84 if (m_matcherFunctionForInputAndOutput !=
nullptr)
86 const AudioBuffer<SampleType>& inputAudio = context.inputAudio();
87 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
89 m_condition = std::move (m_matcherFunctionForInputAndOutput (inputAudio, observedOutputAudio));
90 return m_condition.getResult();
101 std::ostringstream descriptionStream;
103 if (m_condition.hasDetailedMetadata())
105 hassert (m_condition.getLine() >= 0);
106 hassert (m_condition.getFile() !=
nullptr);
107 hassert (m_condition.getFile()[0] !=
'\0');
110 <<
"Location: " << m_condition.getFile()
111 <<
':' << m_condition.getLine()
113 m_condition.representWithTokens (descriptionStream);
114 descriptionStream <<
"\nEvaluated: ";
115 m_condition.representWithStringRepresentations (descriptionStream);
119 descriptionStream <<
"Matcher function (" << (m_label.empty() ?
"no label" : m_label) <<
") has evaluated to false";
128 stream <<
"MatcherFunction (<function>, \"" << m_label <<
"\")";
132 void prepare (
double , size_t , size_t , size_t )
override {}
136 const std::function <
Condition (
const AudioBuffer<SampleType>&)> m_matcherFunctionForOutputOnly =
nullptr;
137 const std::string m_label;
Contains audio-related artefacts useful for analysis by matchers.
Container for audio data.
A class representing some condition.
Matcher defined by a user-provided function.
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.