2#include <Media/AudioDecoder.hpp>
3#include <Media/SndfileDecoder.hpp>
4#include <Media/WaveformSummary.hpp>
6#include <score/tools/std/StringHash.hpp>
8#include <ossia/audio/drwav_handle.hpp>
9#include <ossia/detail/hash_map.hpp>
10#include <ossia/detail/nullable_variant.hpp>
11#include <ossia/detail/small_vector.hpp>
15#include <nano_signal_slot.hpp>
16#include <score_plugin_media_export.h>
28struct DocumentContext;
33class SoundComponentSetup;
34static constexpr inline int64_t abs_max(int64_t f1, int64_t f2)
noexcept
36 return f2 >= 0 ? f1 < f2 ? f2 : f1 : f1 < -f2 ? f2 : f1;
39static constexpr inline float abs_max(
float f1,
float f2)
noexcept
41 const int mul = (f2 >= 0.f) ? 1 : -1;
48static constexpr inline float abs_max(
float f1,
float f2)
noexcept
50 return f2 >= 0.f ? f1 < f2 ? f2 : f1 : f1 < -f2 ? f2 : f1;
54enum class DecodingMethod
66 QString absoluteFilePath;
67 DecodingMethod method{};
71struct SCORE_PLUGIN_MEDIA_EXPORT
AudioFile final :
public QObject
74 static bool isSupported(
const QFile& f);
75 static bool isSupportedVideo(
const QFile& f);
86 QString
fileName()
const {
return m_fileName; }
91 int sampleRate()
const {
return m_sampleRate; }
93 int64_t decodedSamples()
const;
96 int64_t samples()
const;
97 int64_t channels()
const;
99 bool empty()
const {
return channels() == 0 || samples() == 0; }
103 return m_fullyDecoded.load(std::memory_order_acquire);
114 std::shared_ptr<const WaveformSummary> waveformSummary() const noexcept;
117 ossia::audio_array getAudioArray() const;
119 Nano::Signal<
void()> on_mediaChanged;
120 Nano::Signal<
void()> on_newData;
121 Nano::Signal<
void()> on_finishedDecoding;
125 std::shared_ptr<QFile> file;
127 ossia::drwav_handle wav;
132 ossia::audio_handle handle;
133 ossia::small_vector<ossia::audio_sample*, 8> data;
156 using libav_ptr = std::shared_ptr<LibavReader>;
161 = ossia::nullable_variant<mmap_ptr, libav_ptr, sndfile_ptr, libav_stream_ptr>;
166 ossia::drwav_handle wav;
171 std::shared_ptr<ossia::libav_handle> handle;
176 ossia::small_vector<audio_sample*, 8> data;
181 using impl_t::impl_t;
183 : impl_t{std::move(ptr)}
187 : impl_t{std::move(ptr)}
191 : impl_t{std::move(ptr)}
195 : impl_t{std::move(ptr)}
200 ((impl_t&)*
this) = std::move(ptr);
203 Handle& operator=(libav_ptr&& ptr)
205 ((impl_t&)*
this) = std::move(ptr);
210 ((impl_t&)*
this) = std::move(ptr);
215 ((impl_t&)*
this) = std::move(ptr);
220 using view_impl_t = ossia::nullable_variant<MmapView, RAMView, StreamView>;
223 using view_impl_t::view_impl_t;
226 void frame(int64_t start_frame, ossia::small_vector<float, 8>& out)
noexcept;
228 int64_t start_frame, int64_t end_frame,
229 ossia::small_vector<float, 8>& out)
noexcept;
231 int64_t start_frame, int64_t end_frame,
232 ossia::small_vector<FloatPair, 8>& out)
noexcept;
236 std::shared_ptr<const WaveformSummary>
summary;
239 bool supports_summary() const noexcept;
246 int64_t start_frame, int64_t end_frame,
247 ossia::small_vector<
FloatPair, 8>& out) noexcept;
249 int64_t start_frame, int64_t end_frame,
250 ossia::small_vector<
FloatPair, 8>& out) noexcept;
254 ViewHandle handle() const noexcept {
return m_impl; }
256 const Handle& unsafe_handle() const noexcept {
return m_impl; }
258 std::optional<double> knownTempo() const noexcept;
261 void load_libav(
int rate);
262 void load_libav_stream();
268 QString m_originalFile;
275 std::atomic_bool m_fullyDecoded{};
277 mutable std::mutex m_summaryMutex;
278 mutable std::shared_ptr<const WaveformSummary> m_summary;
279 mutable bool m_summaryUnavailable{};
291 std::shared_ptr<AudioFile>
294 std::shared_ptr<AudioFile> get(
const QString& absolutePath,
int stream);
301 std::size_t operator()(
const StreamInfo& f)
const noexcept
303 constexpr const QtPrivate::QHashCombine combine{
304#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
309 h = combine(h, f.file);
310 h = combine(h, f.stream);
314 bool operator==(
const StreamInfo& other)
const noexcept
316 return file == other.file && stream == other.stream;
321 ossia::hash_map<StreamInfo, std::shared_ptr<AudioFile>, StreamInfo::hash> m_handles;
327SCORE_PLUGIN_MEDIA_EXPORT
328void writeAudioArrayToFile(
const QString& path,
const ossia::audio_array& arr,
int fs);
330std::optional<double> estimateTempo(
const AudioFile& file);
331std::optional<double> estimateTempo(
const QString& filePath);
333SCORE_PLUGIN_MEDIA_EXPORT std::optional<AudioInfo> probe(
const QString& path);
337Q_DECLARE_METATYPE(std::shared_ptr<Media::AudioFile>)
338W_REGISTER_ARGTYPE(std::shared_ptr<Media::AudioFile>)
Base toolkit upon which the software is built.
Definition Application.cpp:108
Definition DocumentContext.hpp:18