Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_manager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2020-2021, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
9
10#ifndef TEST_HELPERS_PLUGIN_MANAGER_H
11#define TEST_HELPERS_PLUGIN_MANAGER_H
12
13#include "zrythm-test-config.h"
14
15#include "gui/backend/backend/zrythm.h"
16#include "gui/backend/plugin_manager.h"
17#include "structure/project/project.h"
18#include "structure/tracks/tracklist.h"
19#include "utils/gtest_wrapper.h"
20#include "utils/io_utils.h"
21
22#include "tests/helpers/zrythm_helper.h"
23
29
33PluginConfiguration
35 const char * pl_bundle,
36 const char * pl_uri,
37 bool with_carla);
38
47int
49 const char * pl_bundle,
50 const char * pl_uri,
51 bool is_instrument,
52 bool with_carla,
53 int num_tracks = 1);
54
61PluginConfiguration
63 const char * pl_bundle,
64 const char * pl_uri,
65 bool with_carla)
66{
67 {
68 auto basename = io_path_get_basename (pl_bundle);
69 char * tmpdir = g_dir_make_tmp ("zrythm_vst_XXXXXX", nullptr);
70 auto dest_path = Glib::build_filename (tmpdir, basename);
71 if (g_str_has_suffix (pl_bundle, "vst3"))
72 {
73 EXPECT_NO_THROW (io_copy_dir (dest_path, pl_bundle, true, true));
74 }
75 else if (pl_uri)
76 {
77 EXPECT_NO_THROW (io_copy_dir (dest_path, &pl_bundle[7], true, true));
78 }
79 else
80 {
81 GFile * pl_bundle_file = NULL;
82 pl_bundle_file = g_file_new_for_path (pl_bundle);
83 GFile * pl_bundle_file_in_tmp = g_file_new_for_path (dest_path.c_str ());
84 GError * err = NULL;
85 EXPECT_TRUE (g_file_copy (
86 pl_bundle_file, pl_bundle_file_in_tmp, G_FILE_COPY_NONE, nullptr,
87 nullptr, nullptr, &err));
88 // g_object_unref (pl_bundle_file);
89 // g_object_unref (pl_bundle_file_in_tmp);
90 }
91 g_setenv ("VST3_PATH", tmpdir, true);
92 g_setenv ("LV2_PATH", tmpdir, true);
93 g_setenv ("VST_PATH", tmpdir, true);
94 g_free (tmpdir);
95 }
96
97 bool scan_finished = false;
98 zrythm::gui::old_dsp::plugins::PluginManager::get_active_instance ()
99 ->clear_plugins ();
100 zrythm::gui::old_dsp::plugins::PluginManager::get_active_instance ()
101 ->begin_scan (1.0, nullptr, [&scan_finished] () { scan_finished = true; });
102 while (!scan_finished)
103 {
104 g_main_context_iteration (nullptr, true);
105 }
106 EXPECT_NONEMPTY (
107 zrythm::gui::old_dsp::plugins::PluginManager::get_active_instance ()
108 ->plugin_descriptors_);
109
110 std::optional<PluginDescriptor> descr;
111 for (
112 const auto &cur_descr :
113 zrythm::gui::old_dsp::plugins::PluginManager::get_active_instance ()
114 ->plugin_descriptors_)
115 {
116 if (pl_uri)
117 {
118 if (cur_descr.uri_ == pl_uri)
119 {
120 descr = cur_descr;
121 }
122 }
123 else if (cur_descr.protocol_ != ProtocolType::LV2)
124 {
125 auto basename = io_path_get_basename (pl_bundle);
126 auto descr_basename = io_path_get_basename (cur_descr.path_);
127 if (descr_basename == basename)
128 {
129 descr = cur_descr;
130 }
131 }
132 }
133 EXPECT_HAS_VALUE (descr);
134
135 PluginConfiguration setting (descr.value ());
136
137 /* always open with carla */
138 setting.open_with_carla_ = true;
139#if 0
140 /* open with carla if requested */
141 setting->open_with_carla_ = with_carla;
142#endif
143
144 setting.validate ();
145
146 /* run the logger to avoid too many messages being queued */
147 // TODO?
148 // log_idle_cb (LOG);
149
150 return setting;
151}
152
161int
163 const char * pl_bundle,
164 const char * pl_uri,
165 bool is_instrument,
166 bool with_carla,
167 int num_tracks)
168{
169 PluginConfiguration setting =
170 test_plugin_manager_get_plugin_setting (pl_bundle, pl_uri, with_carla);
171
172 Track::Type track_type = Track::Type::AudioBus;
173 if (is_instrument)
174 {
175 /* fix the descriptor (for some reason lilv reports it as Plugin instead
176 * of Instrument if you don't do lilv_world_load_all) */
177 setting.descr_.category_ = PluginCategory::INSTRUMENT;
178 setting.descr_.category_str_ =
179 PluginDescriptor::category_to_string (setting.descr_.category_);
180 track_type = Track::Type::Instrument;
181 }
182
183 /* create a track from the plugin */
184 EXPECT_NO_THROW (
185 Track::create_with_action (
186 track_type, &setting, nullptr, nullptr, TRACKLIST->get_num_tracks (),
187 num_tracks, -1, nullptr));
188
189 return TRACKLIST->get_num_tracks () - 1;
190}
191
195
196#endif
int test_plugin_manager_create_tracks_from_plugin(const char *pl_bundle, const char *pl_uri, bool is_instrument, bool with_carla, int num_tracks=1)
Creates num_tracks tracks for the given plugin.
PluginConfiguration test_plugin_manager_get_plugin_setting(const char *pl_bundle, const char *pl_uri, bool with_carla)
Get a plugin setting clone from the given URI in the given bundle.