Loading...
Searching...
No Matches
SoundSet.hpp
1#pragma once
2#include <Media/AudioArray.hpp>
3
4#include <halp/sound_set.hpp>
5
6#include <QDateTime>
7#include <QFileSystemWatcher>
8#include <QObject>
9#include <QStringList>
10#include <QTimer>
11
12#include <score_plugin_avnd_export.h>
13
14#include <atomic>
15#include <functional>
16#include <memory>
17#include <string>
18#include <vector>
19
20namespace oscr
21{
23{
24 QStringList extensions;
25 bool recursive{};
26 halp::sound_decoding decoding{};
27 int rate{};
28};
29
33{
34 QString path;
35 std::string name;
36 QDateTime modified;
37 qint64 size{};
38
39 Media::audio_array data;
40 std::vector<const float*> channels;
41 int rate{};
42 halp::sound_status status{};
43
44 std::atomic<int32_t> pins{0};
45 std::atomic<bool> requested{false};
46};
47
50{
51 std::vector<std::shared_ptr<SoundSetEntry>> entries;
52 std::vector<halp::sound_view> views;
53 std::string folder;
54 uint64_t generation{};
55
58 std::atomic<bool> superseded{false};
59
60 void make_views();
61 halp::sound_set_view view() const noexcept
62 {
63 return {views, folder, generation};
64 }
65};
66
77class SCORE_PLUGIN_AVND_EXPORT SoundSetLoader final : public QObject
78{
79public:
81 using publish_function = std::function<void(
82 std::shared_ptr<SoundSetSnapshot> next, SoundSetSnapshot* previous)>;
86 = std::function<void(std::vector<std::shared_ptr<SoundSetSnapshot>>)>;
87
90 QObject* parent);
92
94 void setPath(const QString& path);
95
96 const std::shared_ptr<SoundSetSnapshot>& current() const noexcept { return m_current; }
97 std::size_t retiredCount() const noexcept { return m_retired.size(); }
98
100 void reap();
101
102private:
103 void scheduleScan();
104 void scan();
105 void scanned(uint64_t token, std::shared_ptr<SoundSetSnapshot> snapshot);
106 void decodeRequested();
107 void decoded(uint64_t token, std::shared_ptr<SoundSetEntry> entry);
108 void publishSnapshot(std::shared_ptr<SoundSetSnapshot> snapshot);
109 void rewatch();
110
111 SoundSetOptions m_opts;
112 publish_function m_publish;
113 dispose_function m_dispose;
114
115 QString m_folder;
116 uint64_t m_token{};
117 uint64_t m_generation{};
118
119 std::shared_ptr<SoundSetSnapshot> m_current;
120 std::vector<std::shared_ptr<SoundSetSnapshot>> m_retired;
121 std::vector<std::shared_ptr<SoundSetEntry>> m_decoding;
122
123 QFileSystemWatcher m_watcher;
124 QTimer m_rescan;
125 QTimer m_reaper;
126 QTimer m_requests;
127};
128
130SCORE_PLUGIN_AVND_EXPORT QStringList soundSetExtensions(std::string_view exts);
131}
Definition SoundSet.hpp:78
std::function< void(std::vector< std::shared_ptr< SoundSetSnapshot > >)> dispose_function
Definition SoundSet.hpp:86
std::function< void(std::shared_ptr< SoundSetSnapshot > next, SoundSetSnapshot *previous)> publish_function
Swaps next in, then flags previous as superseded, on the audio thread.
Definition SoundSet.hpp:82
Definition Controls.hpp:30
QStringList soundSetExtensions(std::string_view exts)
The extensions a sound_set port lists, from its extensions() string.
Definition SoundSet.cpp:138
Definition SoundSet.hpp:33
QString path
Absolute.
Definition SoundSet.hpp:34
std::string name
Relative to the folder.
Definition SoundSet.hpp:35
Definition SoundSet.hpp:23
QStringList extensions
Lowercase, without the dot; empty = every audio file.
Definition SoundSet.hpp:24
The set as the processor sees it between two changes.
Definition SoundSet.hpp:50
std::atomic< bool > superseded
Definition SoundSet.hpp:58