]> git.sesse.net Git - nageru/blob - theme.h
Let settings follow buses when editing the mapping.
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <epoxy/gl.h>
5 #include <lua.hpp>
6 #include <movit/effect_chain.h>
7 #include <movit/deinterlace_effect.h>
8 #include <movit/ycbcr_input.h>
9 #include <stdbool.h>
10 #include <stdio.h>
11 #include <functional>
12 #include <mutex>
13 #include <set>
14 #include <string>
15 #include <utility>
16 #include <vector>
17
18 #include "defs.h"
19 #include "input_state.h"
20 #include "ref_counted_frame.h"
21
22 namespace movit {
23 class ResourcePool;
24 struct ImageFormat;
25 struct YCbCrFormat;
26 }  // namespace movit
27
28 class NonBouncingYCbCrInput : public movit::YCbCrInput {
29 public:
30         NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
31                               const movit::YCbCrFormat &ycbcr_format,
32                               unsigned width, unsigned height,
33                               movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
34             : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
35
36         bool override_disable_bounce() const override { return true; }
37 };
38
39 class Theme {
40 public:
41         Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
42         ~Theme();
43
44         struct Chain {
45                 movit::EffectChain *chain;
46                 std::function<void()> setup_chain;
47
48                 // May have duplicates.
49                 std::vector<RefCountedFrame> input_frames;
50         };
51
52         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
53
54         int get_num_channels() const { return num_channels; }
55         int map_signal(int signal_num);
56         void set_signal_mapping(int signal_num, int card_num);
57         std::string get_channel_name(unsigned channel);
58         int get_channel_signal(unsigned channel);
59         bool get_supports_set_wb(unsigned channel);
60         void set_wb(unsigned channel, double r, double g, double b);
61         std::string get_channel_color(unsigned channel);
62
63         std::vector<std::string> get_transition_names(float t);
64
65         void connect_signal(movit::YCbCrInput *input, int signal_num);
66         void transition_clicked(int transition_num, float t);
67         void channel_clicked(int preview_num);
68
69         movit::ResourcePool *get_resource_pool() const { return resource_pool; }
70
71 private:
72         void register_class(const char *class_name, const luaL_Reg *funcs);
73
74         std::mutex m;
75         lua_State *L;  // Protected by <m>.
76         const InputState *input_state;  // Protected by <m>. Only set temporarily, during chain setup.
77         movit::ResourcePool *resource_pool;
78         int num_channels;
79         unsigned num_cards;
80
81         std::mutex map_m;
82         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
83
84         friend class LiveInputWrapper;
85 };
86
87 class LiveInputWrapper {
88 public:
89         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bool override_bounce, bool deinterlace);
90
91         void connect_signal(int signal_num);
92         movit::Effect *get_effect() const
93         {
94                 if (deinterlace) {
95                         return deinterlace_effect;
96                 } else {
97                         return inputs[0];
98                 }
99         }
100
101 private:
102         Theme *theme;  // Not owned by us.
103         std::vector<movit::YCbCrInput *> inputs;  // Multiple ones if deinterlacing. Owned by the chain.
104         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
105         bool deinterlace;
106 };
107
108 #endif  // !defined(_THEME_H)