Zrythm v2.0.0-alpha.1
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_hardware_midi_interface.h"
12#include "helpers/mock_settings_backend.h"
13#include "helpers/scoped_juce_qapplication.h"
14
15#include <gtest/gtest.h>
16#include <juce_audio_processors/juce_audio_processors.h>
17
18namespace zrythm::test_helpers
19{
20
26class ProjectTestFixture : public ::testing::Test, protected ScopedJuceQApplication
27{
28protected:
29 void SetUp () override
30 {
31 temp_dir_obj_ = utils::io::make_tmp_dir ();
32 project_dir_ =
33 utils::Utf8String::from_qstring (temp_dir_obj_->path ()).to_path ();
34
35 hw_interface_ = std::make_unique<ThreadedMockHardwareAudioInterface> ();
36
37 plugin_format_manager_ = std::make_shared<juce::AudioPluginFormatManager> ();
38 juce::addDefaultFormatsToManager (*plugin_format_manager_);
39
40 auto mock_backend = std::make_unique<MockSettingsBackend> ();
41 mock_backend_ptr_ = mock_backend.get ();
42
43 ON_CALL (*mock_backend_ptr_, value (testing::_, testing::_))
44 .WillByDefault (testing::Return (QVariant ()));
45
46 app_settings_ =
47 std::make_unique<utils::AppSettings> (std::move (mock_backend));
48
49 registry_ = std::make_unique<utils::ObjectRegistry> (nullptr);
50 monitor_fader_ = utils::make_qobject_unique<dsp::Fader> (
51 *registry_, dsp::PortType::Audio,
52 true, // hard_limit_output
53 false, // make_params_automatable
54 [] () -> utils::Utf8String { return u8"Test Control Room"; },
55 [] (bool fader_solo_status) { return false; });
56
57 juce::AudioSampleBuffer emphasis_sample (2, 512);
58 juce::AudioSampleBuffer normal_sample (2, 512);
59 metronome_ = utils::make_qobject_unique<dsp::Metronome> (
60 *registry_, emphasis_sample, normal_sample, true, 1.0f, nullptr);
61 }
62
63 void TearDown () override
64 {
65 // Intentionally empty — let RAII destroy members in the correct order
66 // (derived class destructor runs first, freeing the project that
67 // references these objects, then base destructor frees them).
68 }
69
70 std::unique_ptr<structure::project::Project> create_minimal_project (
71 structure::tracks::TrackRecordingCallback recording_callback =
72 [] (
74 units::sample_t,
75 const dsp::ITransport &,
76 std::optional<std::span<const dsp::MidiEvent>>,
77 std::optional<structure::tracks::TrackProcessor::ConstStereoPortPair>,
78 units::sample_u32_t) { })
79 {
80 using namespace zrythm::structure::project;
81 using namespace zrythm::plugins;
82
83 Project::ProjectDirectoryPathProvider path_provider =
84 [this] (bool for_backup) {
85 return for_backup ? project_dir_ / "backups" : project_dir_;
86 };
87
88 PluginHostWindowFactory window_factory =
89 [] (Plugin &) -> std::unique_ptr<IPluginHostWindow> { return nullptr; };
90
91 auto project = std::make_unique<Project> (
92 *app_settings_, path_provider, *hw_interface_, midi_interface_,
93 plugin_format_manager_, window_factory, *metronome_, *monitor_fader_);
94 project->install_recording_callback (std::move (recording_callback));
95 return project;
96 }
97
98 std::unique_ptr<QTemporaryDir> temp_dir_obj_;
99 std::filesystem::path project_dir_;
100 std::unique_ptr<dsp::IHardwareAudioInterface> hw_interface_;
102 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
103 MockSettingsBackend * mock_backend_ptr_{};
104 std::unique_ptr<utils::AppSettings> app_settings_;
105 std::unique_ptr<utils::ObjectRegistry> registry_;
108};
109
110} // namespace zrythm::test_helpers
Interface for transport.
Definition itransport.h:16
DSP processing plugin.
Definition plugin.h:44
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