Loading...
Searching...
No Matches
Context.hpp
1#pragma once
2#include <lv2/lv2plug.in/ns/ext/atom/atom.h>
3#include <lv2/lv2plug.in/ns/ext/atom/forge.h>
4#include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
5#include <lv2/lv2plug.in/ns/ext/data-access/data-access.h>
6#include <lv2/lv2plug.in/ns/ext/dynmanifest/dynmanifest.h>
7#include <lv2/lv2plug.in/ns/ext/event/event.h>
8#include <lv2/lv2plug.in/ns/ext/instance-access/instance-access.h>
9#include <lv2/lv2plug.in/ns/ext/log/log.h>
10#include <lv2/lv2plug.in/ns/ext/midi/midi.h>
11#include <lv2/lv2plug.in/ns/ext/morph/morph.h>
12#include <lv2/lv2plug.in/ns/ext/options/options.h>
13#include <lv2/lv2plug.in/ns/ext/parameters/parameters.h>
14#include <lv2/lv2plug.in/ns/ext/patch/patch.h>
15#include <lv2/lv2plug.in/ns/ext/port-groups/port-groups.h>
16#include <lv2/lv2plug.in/ns/ext/port-props/port-props.h>
17#include <lv2/lv2plug.in/ns/ext/presets/presets.h>
18#include <lv2/lv2plug.in/ns/ext/resize-port/resize-port.h>
19#include <lv2/lv2plug.in/ns/ext/state/state.h>
20#include <lv2/lv2plug.in/ns/ext/time/time.h>
21#include <lv2/lv2plug.in/ns/ext/uri-map/uri-map.h>
22#include <lv2/lv2plug.in/ns/ext/urid/urid.h>
23#include <lv2/lv2plug.in/ns/ext/worker/worker.h>
24#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
25
26#include <ossia/detail/hash_map.hpp>
27#include <ossia/detail/lockfree_queue.hpp>
28#include <ossia/detail/small_vector.hpp>
29
30#include <boost/bimap.hpp>
31
32#include <QString>
33
34#include <lilv/lilvmm.hpp>
35
36#include <readerwriterqueue.h>
37
38#include <atomic>
39#include <cstdarg>
40#include <cstdio>
41#include <functional>
42#include <vector>
43
44#include <suil-0/suil/suil.h>
45
46namespace LV2
47{
48struct EffectContext;
49struct GlobalContext;
51{
52 Lilv::Node make_node(const char* desc)
53 {
54 Lilv::Node n{nullptr};
55 n.me = lilv_new_uri(world.me, desc);
56 return n;
57 }
58
59 LV2::GlobalContext* global{};
60 LV2::EffectContext* current{};
61 LV2_Feature const* const* features{};
62 Lilv::World& world;
63
64 LV2_Atom_Forge forge{};
65
66 Lilv::Node input_class{make_node(LILV_URI_INPUT_PORT)};
67 Lilv::Node output_class{make_node(LILV_URI_OUTPUT_PORT)};
68 Lilv::Node control_class{make_node(LILV_URI_CONTROL_PORT)};
69 Lilv::Node audio_class{make_node(LILV_URI_AUDIO_PORT)};
70 Lilv::Node atom_class{make_node(LV2_ATOM__AtomPort)};
71 Lilv::Node atom_object_class{make_node(LV2_ATOM__Object)};
72 Lilv::Node event_class{make_node(LILV_URI_EVENT_PORT)};
73 Lilv::Node midi_event_class{make_node(LILV_URI_MIDI_EVENT)};
74 Lilv::Node cv_class{make_node(LV2_CORE__CVPort)};
75 Lilv::Node work_interface{make_node(LV2_WORKER__interface)};
76 Lilv::Node work_schedule{make_node(LV2_WORKER__schedule)};
77
78 Lilv::Node time_time_class{make_node(LV2_TIME__Time)};
79 Lilv::Node time_Position_class{make_node(LV2_TIME__Position)};
80 Lilv::Node time_rate_class{make_node(LV2_TIME__Rate)};
81 //Lilv::Node time_position_class{make_node(LV2_TIME__position)};
82 Lilv::Node time_barBeat_class{make_node(LV2_TIME__barBeat)};
83 Lilv::Node time_bar_class{make_node(LV2_TIME__bar)};
84 Lilv::Node time_beat_class{make_node(LV2_TIME__beat)};
85 Lilv::Node time_beatUnit_class{make_node(LV2_TIME__beatUnit)};
86 Lilv::Node time_beatsPerBar_class{make_node(LV2_TIME__beatsPerBar)};
87 Lilv::Node time_beatsPerMinute_class{make_node(LV2_TIME__beatsPerMinute)};
88 Lilv::Node time_frame_class{make_node(LV2_TIME__frame)};
89 Lilv::Node time_framesPerSecond_class{make_node(LV2_TIME__framesPerSecond)};
90 Lilv::Node time_speed_class{make_node(LV2_TIME__speed)};
91
92 Lilv::Node optional_feature{make_node(LV2_CORE__optionalFeature)};
93 Lilv::Node fixed_size{make_node(LV2_UI__fixedSize)};
94 Lilv::Node no_user_resize{make_node(LV2_UI__noUserResize)};
95
96 Lilv::Node host_ui_type{make_node("http://lv2plug.in/ns/extensions/ui#Qt6UI")};
97
98 int32_t midi_buffer_size = 2048;
99 LV2_URID midi_event_id{};
100 LV2_URID atom_chunk_id{};
101 LV2_URID atom_sequence_id{};
102 LV2_URID atom_object_id{};
103 LV2_URID null_id{};
104 LV2_URID atom_eventTransfer{};
105
106 LV2_URID time_Time_id{};
107 LV2_URID time_Position_id{};
108 LV2_URID time_rate_id{};
109 // LV2_URID time_position_id{};
110 LV2_URID time_barBeat_id{};
111 LV2_URID time_bar_id{};
112 LV2_URID time_beat_id{};
113 LV2_URID time_beatUnit_id{};
114 LV2_URID time_beatsPerBar_id{};
115 LV2_URID time_beatsPerMinute_id{};
116 LV2_URID time_frame_id{};
117 LV2_URID time_framesPerSecond_id{};
118 LV2_URID time_speed_id{};
119
120 std::vector<char> acquire_worker_data(const char* data, uint32_t s) noexcept
121 {
122 std::vector<char> cp;
123 worker_datas_pool.try_dequeue(cp);
124 cp.assign(data, data + s);
125 return cp;
126 }
127
128 void release_worker_data(std::vector<char>&& v) noexcept
129 {
130 worker_datas_pool.enqueue(std::move(v));
131 }
132
133 ossia::mpmc_queue<std::vector<char>> worker_datas_pool{};
134};
135
137{
138 Lilv::Plugin plugin{nullptr};
139 LilvInstance* instance{};
140 const LV2_Worker_Interface* worker{};
141 LV2_Extension_Data_Feature data{};
142 const LilvUI* ui{};
143 const LilvNode* ui_type{};
144 SuilInstance* ui_instance{};
145
146 ossia::mpmc_queue<std::vector<char>> worker_datas;
147};
148
150{
151public:
152 GlobalContext(int buffer_size, LV2::HostContext& host);
153 void loadPlugins();
154 LV2_Feature const* const* features() const { return lv2_features.data(); }
155
156 using urid_map_t = boost::bimap<std::string, LV2_URID>;
157 LV2::HostContext& host;
158 int sampleRate = 44100;
159
160 std::vector<LV2_Options_Option> options;
161
162 LV2_URID urid_map_cur = 1;
163 ossia::hash_map<std::string, LV2_URID> urid_map_left;
164 ossia::hash_map<LV2_URID, std::string> urid_map_right;
165
166 LV2_URI_Map_Feature uri_map{};
167 LV2_URID uri_map_cur = 1;
168 ossia::hash_map<std::string, LV2_URID> uri_map_left;
169
170 LV2_URID_Map map{};
171 LV2_URID_Unmap unmap{};
172 LV2_Event_Feature event{};
173 LV2_Worker_Schedule worker{};
174 LV2_Worker_Schedule worker_state{};
175
176 LV2_Log_Log logger{};
177 LV2_Extension_Data_Feature ext_data{nullptr};
178
179 LV2_Resize_Port_Resize ext_port_resize{};
180 LV2_State_Make_Path state_make_path{};
181
182 LV2_Feature uri_map_feature{"http://lv2plug.in/ns/ext/uri-map", &uri_map};
183 LV2_Feature map_feature{LV2_URID__map, &map};
184 LV2_Feature unmap_feature{LV2_URID__unmap, &unmap};
185 LV2_Feature event_feature{LV2_EVENT_URI, &event};
186 LV2_Feature options_feature{LV2_OPTIONS__options, nullptr};
187 LV2_Feature worker_feature{LV2_WORKER__schedule, &worker};
188 LV2_Feature worker_state_feature{LV2_WORKER__schedule, &worker};
189 LV2_Feature logger_feature{LV2_LOG__log, &logger};
190 LV2_Feature ext_data_feature{LV2_DATA_ACCESS_URI, &ext_data};
191 LV2_Feature ext_port_resize_feature{LV2_RESIZE_PORT_URI, &ext_port_resize};
192 LV2_Feature state_make_path_feature{LV2_STATE__makePath, &state_make_path};
193
194 LV2_Feature state_load_default_feature{LV2_STATE__loadDefaultState, nullptr};
195 // LV2_Feature
196 // state_thread_safe_restore_feature{LV2_STATE__threadSafeRestore, nullptr};
197
198 LV2_Feature bounded{LV2_BUF_SIZE__boundedBlockLength, nullptr};
199 LV2_Feature pow2{LV2_BUF_SIZE__powerOf2BlockLength, nullptr};
200
201 std::vector<LV2_Feature*> lv2_features;
202
203 SuilHost* ui_host{};
204
205 const LV2_Feature data_feature{LV2_DATA_ACCESS_URI, &ext_data};
206};
207
209{
211
212 ~LV2Data() { }
213
214 LV2::HostContext& host;
215 LV2::EffectContext& effect;
216 ossia::small_vector<int, 4> audio_in_ports, audio_out_ports;
217 ossia::small_vector<int, 8> control_in_ports, control_out_ports, control_other_ports;
218 ossia::small_vector<int, 2> midi_in_ports, midi_out_ports, midi_other_ports, cv_ports;
219 ossia::small_vector<int, 2> atom_in_ports, atom_out_ports;
220
221 ossia::small_vector<int, 2> time_Position_ports{};
222
223 // ossia::small_vector<int, 2> atom_in_ports, atom_out_ports;
224};
225
227{
228 uint32_t index;
229 uint32_t protocol;
230 ossia::small_vector<uint8_t, 32> body;
231};
232
233QString get_lv2_plugin_name(const Lilv::Plugin& node);
234}
Definition Context.hpp:137
Definition Context.hpp:150
Definition Context.hpp:51
Definition Context.hpp:209
Definition Context.hpp:227