Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project_fixture.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6// clang-format off
7// Needs to be included before project.h
8#include "utils/format_qt.h"
9// clang-format on
10#include "structure/project/project.h"
11#include "utils/app_settings.h"
12#include "utils/io_utils.h"
13
14#include "helpers/mock_hardware_audio_interface_threaded.h"
15#include "helpers/mock_settings_backend.h"
16#include "helpers/scoped_juce_qapplication.h"
17
18#include <gtest/gtest.h>
19#include <juce_audio_processors/juce_audio_processors.h>
20
21namespace zrythm::test_helpers
22{
23
29class ProjectTestFixture : public ::testing::Test, protected ScopedJuceQApplication
30{
31protected:
32 void SetUp () override
33 {
34 temp_dir_obj_ = utils::io::make_tmp_dir ();
35 project_dir_ =
36 utils::Utf8String::from_qstring (temp_dir_obj_->path ()).to_path ();
37
38 hw_interface_ = std::make_unique<ThreadedMockHardwareAudioInterface> ();
39
40 plugin_format_manager_ = std::make_shared<juce::AudioPluginFormatManager> ();
41 juce::addDefaultFormatsToManager (*plugin_format_manager_);
42
43 auto mock_backend = std::make_unique<MockSettingsBackend> ();
44 mock_backend_ptr_ = mock_backend.get ();
45
46 ON_CALL (*mock_backend_ptr_, value (testing::_, testing::_))
47 .WillByDefault (testing::Return (QVariant ()));
48
49 app_settings_ =
50 std::make_unique<utils::AppSettings> (std::move (mock_backend));
51
52 port_registry_ = std::make_unique<dsp::PortRegistry> (nullptr);
53 param_registry_ = std::make_unique<dsp::ProcessorParameterRegistry> (
54 *port_registry_, nullptr);
55 monitor_fader_ = utils::make_qobject_unique<dsp::Fader> (
57 .port_registry_ = *port_registry_,
58 .param_registry_ = *param_registry_,
59 },
60 dsp::PortType::Audio,
61 true, // hard_limit_output
62 false, // make_params_automatable
63 [] () -> utils::Utf8String { return u8"Test Control Room"; },
64 [] (bool fader_solo_status) { return false; });
65
66 juce::AudioSampleBuffer emphasis_sample (2, 512);
67 juce::AudioSampleBuffer normal_sample (2, 512);
68 metronome_ = utils::make_qobject_unique<dsp::Metronome> (
70 .port_registry_ = *port_registry_,
71 .param_registry_ = *param_registry_,
72 },
73 emphasis_sample, normal_sample, true, 1.0f, nullptr);
74 }
75
76 void TearDown () override
77 {
78 metronome_.reset ();
79 monitor_fader_.reset ();
80 param_registry_.reset ();
81 port_registry_.reset ();
82 app_settings_.reset ();
83 plugin_format_manager_.reset ();
84 hw_interface_.reset ();
85 }
86
87 std::unique_ptr<structure::project::Project> create_minimal_project ()
88 {
89 using namespace zrythm::structure::project;
90 using namespace zrythm::plugins;
91
92 Project::ProjectDirectoryPathProvider path_provider =
93 [this] (bool for_backup) {
94 return for_backup ? project_dir_ / "backups" : project_dir_;
95 };
96
97 PluginHostWindowFactory window_factory =
98 [] (Plugin &) -> std::unique_ptr<IPluginHostWindow> { return nullptr; };
99
100 return std::make_unique<Project> (
101 *app_settings_, path_provider, *hw_interface_, plugin_format_manager_,
102 window_factory, *metronome_, *monitor_fader_);
103 }
104
105 std::unique_ptr<QTemporaryDir> temp_dir_obj_;
106 std::filesystem::path project_dir_;
107 std::unique_ptr<dsp::IHardwareAudioInterface> hw_interface_;
108 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
109 MockSettingsBackend * mock_backend_ptr_{};
110 std::unique_ptr<utils::AppSettings> app_settings_;
111 std::unique_ptr<dsp::PortRegistry> port_registry_;
112 std::unique_ptr<dsp::ProcessorParameterRegistry> param_registry_;
115};
116
117} // namespace zrythm::test_helpers
DSP processing plugin.
Definition plugin.h:46
Shared test fixture providing a minimal project environment (temp directory, mock hardware,...
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:37