2 #include <Media/AudioDecoder.hpp>
3 #include <Media/SndfileDecoder.hpp>
5 #include <score/tools/std/StringHash.hpp>
7 #include <ossia/audio/drwav_handle.hpp>
8 #include <ossia/detail/hash_map.hpp>
9 #include <ossia/detail/nullable_variant.hpp>
10 #include <ossia/detail/small_vector.hpp>
14 #include <nano_signal_slot.hpp>
15 #include <score_plugin_media_export.h>
25 struct DocumentContext;
36 static constexpr
inline int64_t abs_max(int64_t f1, int64_t f2) noexcept
38 return f2 >= 0 ? f1 < f2 ? f2 : f1 : f1 < -f2 ? f2 : f1;
40 #if defined(__clang__)
41 static constexpr
inline float abs_max(
float f1,
float f2) noexcept
43 const int mul = (f2 >= 0.f) ? 1 : -1;
50 static constexpr
inline float abs_max(
float f1,
float f2) noexcept
52 return f2 >= 0.f ? f1 < f2 ? f2 : f1 : f1 < -f2 ? f2 : f1;
56 enum class DecodingMethod
68 QString absoluteFilePath;
69 DecodingMethod method{};
73 struct SCORE_PLUGIN_MEDIA_EXPORT
AudioFile final :
public QObject
76 static bool isSupported(
const QFile& f);
87 QString
fileName()
const {
return m_fileName; }
92 int sampleRate()
const {
return m_sampleRate; }
94 int64_t decodedSamples()
const;
97 int64_t samples()
const;
98 int64_t channels()
const;
100 bool empty()
const {
return channels() == 0 || samples() == 0; }
101 bool finishedDecoding() const noexcept {
return m_fullyDecoded; }
103 const RMSData& rms()
const;
106 ossia::audio_array getAudioArray()
const;
108 Nano::Signal<void()> on_mediaChanged;
109 Nano::Signal<void()> on_newData;
110 Nano::Signal<void()> on_finishedDecoding;
114 std::shared_ptr<QFile> file;
116 ossia::drwav_handle wav;
121 ossia::audio_handle handle;
122 ossia::small_vector<ossia::audio_sample*, 8> data;
145 using libav_ptr = std::shared_ptr<LibavReader>;
150 = ossia::nullable_variant<mmap_ptr, libav_ptr, sndfile_ptr, libav_stream_ptr>;
155 ossia::drwav_handle wav;
160 std::shared_ptr<ossia::libav_handle> handle;
165 ossia::small_vector<audio_sample*, 8> data;
170 using impl_t::impl_t;
172 : impl_t{std::move(ptr)}
176 : impl_t{std::move(ptr)}
180 : impl_t{std::move(ptr)}
184 : impl_t{std::move(ptr)}
189 ((impl_t&)*
this) = std::move(ptr);
192 Handle& operator=(libav_ptr&& ptr)
194 ((impl_t&)*
this) = std::move(ptr);
199 ((impl_t&)*
this) = std::move(ptr);
204 ((impl_t&)*
this) = std::move(ptr);
209 using view_impl_t = ossia::nullable_variant<MmapView, RAMView, StreamView>;
212 using view_impl_t::view_impl_t;
215 void frame(int64_t start_frame, ossia::small_vector<float, 8>& out) noexcept;
217 int64_t start_frame, int64_t end_frame,
218 ossia::small_vector<float, 8>& out) noexcept;
220 int64_t start_frame, int64_t end_frame,
221 ossia::small_vector<FloatPair, 8>& out) noexcept;
225 ViewHandle handle() const noexcept {
return m_impl; }
227 const Handle& unsafe_handle() const noexcept {
return m_impl; }
229 std::optional<double> knownTempo() const noexcept;
232 void load_libav(
int rate);
233 void load_libav_stream();
237 friend class SoundComponentSetup;
239 QString m_originalFile;
246 bool m_fullyDecoded{};
258 std::shared_ptr<AudioFile>
261 std::shared_ptr<AudioFile> get(
const QString& absolutePath,
int stream);
268 std::size_t operator()(
const StreamInfo& f)
const noexcept
270 constexpr
const QtPrivate::QHashCombine combine;
272 h = combine(h, f.file);
273 h = combine(h, f.stream);
277 bool operator==(
const StreamInfo& other)
const noexcept
279 return file == other.file && stream == other.stream;
284 ossia::hash_map<StreamInfo, std::shared_ptr<AudioFile>, StreamInfo::hash> m_handles;
290 SCORE_PLUGIN_MEDIA_EXPORT
291 void writeAudioArrayToFile(
const QString& path,
const ossia::audio_array& arr,
int fs);
293 std::optional<double> estimateTempo(
const AudioFile& file);
294 std::optional<double> estimateTempo(
const QString& filePath);
296 std::optional<AudioInfo> probe(
const QString& path);
300 Q_DECLARE_METATYPE(std::shared_ptr<Media::AudioFile>)
301 W_REGISTER_ARGTYPE(std::shared_ptr<Media::AudioFile>)
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DocumentContext.hpp:18