-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioFile.hpp
28 lines (22 loc) · 864 Bytes
/
AudioFile.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <juce_audio_formats/juce_audio_formats.h>
#include <juce_core/juce_core.h>
namespace ta
{
template<typename ExpectedFormat>
auto fileHasFormat(juce::AudioFormatManager& formatManager, juce::File const& file) -> bool
{
static_assert(std::is_base_of<juce::AudioFormat, ExpectedFormat>::value,
"ExpectedFormat must be a subclass of AudioFormat");
auto reader = std::unique_ptr<juce::AudioFormatReader>(formatManager.createReaderFor(file));
if (reader == nullptr) { return false; }
return dynamic_cast<ExpectedFormat*>(reader.get()) != nullptr;
}
template<typename ExpectedFormat>
auto fileHasFormat(juce::File const& file) -> bool
{
juce::AudioFormatManager formatManager{};
formatManager.registerBasicFormats();
return fileHasFormat<ExpectedFormat>(formatManager, file);
}
} // namespace ta