Torch
Loading...
Searching...
No Matches
SequenceDriver.h
1#pragma once
2
3#ifdef BUILD_UI
4
5#include <memory>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10#include "Companion.h"
11#include "factories/BaseFactory.h"
12#include "ui/audio/SequenceSynth.h"
13
14// Sequence-format drivers: each game/library version interprets its own
15// sequence data into a RenderedAudio. Drivers register by asset type string;
16// SequencePreviewUI provides the playback controls for any registered type.
17namespace UI {
18
19class SequenceDriver {
20public:
21 virtual ~SequenceDriver() = default;
22 virtual bool Render(const ParseResultData& item, int option, RenderedAudio& out) = 0;
23 // Selectable render options (e.g. sound fonts); empty hides the picker.
24 virtual std::vector<std::string> Options(const ParseResultData& item) { return {}; }
25 // Initial option index (e.g. the font the game maps to this sequence).
26 virtual int DefaultOption(const ParseResultData& item) { return 0; }
27};
28
29inline std::unordered_map<std::string, std::shared_ptr<SequenceDriver>>& SequenceDrivers() {
30 static std::unordered_map<std::string, std::shared_ptr<SequenceDriver>> drivers;
31 return drivers;
32}
33
34inline void RegisterSequenceDriver(const std::string& type, std::shared_ptr<SequenceDriver> driver) {
35 SequenceDrivers()[type] = std::move(driver);
36}
37
38inline SequenceDriver* GetSequenceDriver(const std::string& type) {
39 auto& drivers = SequenceDrivers();
40 const auto it = drivers.find(type);
41 return it != drivers.end() ? it->second.get() : nullptr;
42}
43
44// Playback row (play/stop, volume, seek) for any asset type with a driver.
45class SequencePreviewUI : public BaseFactoryUI {
46public:
47 float GetItemHeight(const ParseResultData& data) override;
48 void DrawUI(const ParseResultData& data) override;
49};
50
51} // namespace UI
52
53#endif // BUILD_UI