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#include "structure/project/project.h"
7#include "utils/app_settings.h"
8#include "utils/io_utils.h"
9
10#include "helpers/mock_hardware_audio_interface_threaded.h"
11#include "helpers/mock_settings_backend.h"
12#include "helpers/scoped_juce_qapplication.h"
13
14#include <gtest/gtest.h>
15#include <juce_audio_processors/juce_audio_processors.h>
16
17namespace zrythm::test_helpers
18{
19
25class ProjectTestFixture : public ::testing::Test, protected ScopedJuceQApplication
26{
27protected:
28 void SetUp () override
29 {
30 temp_dir_obj_ = utils::io::make_tmp_dir ();
31 project_dir_ =
32 utils::Utf8String::from_qstring (temp_dir_obj_->path ()).to_path ();
33
34 hw_interface_ = std::make_unique<ThreadedMockHardwareAudioInterface> ();
35
36 plugin_format_manager_ = std::make_shared<juce::AudioPluginFormatManager> ();
37 juce::addDefaultFormatsToManager (*plugin_format_manager_);
38
39 auto mock_backend = std::make_unique<MockSettingsBackend> ();
40 mock_backend_ptr_ = mock_backend.get ();
41
42 ON_CALL (*mock_backend_ptr_, value (testing::_, testing::_))
43 .WillByDefault (testing::Return (QVariant ()));
44
45 app_settings_ =
46 std::make_unique<utils::AppSettings> (std::move (mock_backend));
47
48 port_registry_ = std::make_unique<dsp::PortRegistry> (nullptr);
49 param_registry_ = std::make_unique<dsp::ProcessorParameterRegistry> (
50 *port_registry_, nullptr);
51 monitor_fader_ = utils::make_qobject_unique<dsp::Fader> (
53 .port_registry_ = *port_registry_,
54 .param_registry_ = *param_registry_,
55 },
56 dsp::PortType::Audio,
57 true, // hard_limit_output
58 false, // make_params_automatable
59 [] () -> utils::Utf8String { return u8"Test Control Room"; },
60 [] (bool fader_solo_status) { return false; });
61
62 juce::AudioSampleBuffer emphasis_sample (2, 512);
63 juce::AudioSampleBuffer normal_sample (2, 512);
64 metronome_ = utils::make_qobject_unique<dsp::Metronome> (
66 .port_registry_ = *port_registry_,
67 .param_registry_ = *param_registry_,
68 },
69 emphasis_sample, normal_sample, true, 1.0f, nullptr);
70 }
71
72 void TearDown () override
73 {
74 // Intentionally empty — let RAII destroy members in the correct order
75 // (derived class destructor runs first, freeing the project that
76 // references these objects, then base destructor frees them).
77 }
78
79 std::unique_ptr<structure::project::Project> create_minimal_project (
80 structure::tracks::TrackRecordingCallback recording_callback =
81 [] (
83 units::sample_t,
84 const dsp::ITransport &,
86 std::optional<structure::tracks::TrackProcessor::ConstStereoPortPair>) {
87 })
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 auto project = std::make_unique<Project> (
101 *app_settings_, path_provider, *hw_interface_, plugin_format_manager_,
102 window_factory, *metronome_, *monitor_fader_);
103 project->install_recording_callback (std::move (recording_callback));
104 return project;
105 }
106
107 std::unique_ptr<QTemporaryDir> temp_dir_obj_;
108 std::filesystem::path project_dir_;
109 std::unique_ptr<dsp::IHardwareAudioInterface> hw_interface_;
110 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
111 MockSettingsBackend * mock_backend_ptr_{};
112 std::unique_ptr<utils::AppSettings> app_settings_;
113 std::unique_ptr<dsp::PortRegistry> port_registry_;
114 std::unique_ptr<dsp::ProcessorParameterRegistry> param_registry_;
117};
118
119} // namespace zrythm::test_helpers
Interface for transport.
Definition itransport.h:16
A lock-free thread-safe vector of MidiEvents.
Definition midi_event.h:74
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