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/in_memory_settings_backend.h"
11#include "helpers/mock_hardware_audio_interface_threaded.h"
12#include "helpers/mock_hardware_midi_interface.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 settings_backend = std::make_unique<InMemorySettingsBackend> ();
41 app_settings_ =
42 std::make_unique<utils::AppSettings> (std::move (settings_backend));
43
44 registry_ = std::make_unique<utils::ObjectRegistry> (nullptr);
45 monitor_fader_ = utils::make_qobject_unique<dsp::Fader> (
46 *registry_, dsp::PortType::Audio,
47 true, // hard_limit_output
48 false, // make_params_automatable
49 [] () -> utils::Utf8String { return u8"Test Control Room"; },
50 [] (bool fader_solo_status) { return false; });
51
52 juce::AudioSampleBuffer emphasis_sample (2, 512);
53 juce::AudioSampleBuffer normal_sample (2, 512);
54 metronome_ = utils::make_qobject_unique<dsp::Metronome> (
55 *registry_, emphasis_sample, normal_sample, true, 1.0f, nullptr);
56 }
57
58 void TearDown () override
59 {
60 // Intentionally empty — let RAII destroy members in the correct order
61 // (derived class destructor runs first, freeing the project that
62 // references these objects, then base destructor frees them).
63 }
64
65 std::unique_ptr<structure::project::Project> create_minimal_project (
66 structure::tracks::TrackRecordingCallback recording_callback =
67 [] (
69 units::sample_t,
70 const dsp::ITransport &,
72 std::optional<structure::tracks::TrackProcessor::ConstStereoPortPair>,
73 units::sample_u32_t) { })
74 {
75 using namespace zrythm::structure::project;
76 using namespace zrythm::plugins;
77
78 Project::ProjectDirectoryPathProvider path_provider =
79 [this] (bool for_backup) {
80 return for_backup ? project_dir_ / "backups" : project_dir_;
81 };
82
83 PluginHostWindowFactory window_factory =
84 [] (Plugin &) -> std::unique_ptr<IPluginHostWindow> { return nullptr; };
85
86 auto project = std::make_unique<Project> (
87 *app_settings_, path_provider, *hw_interface_, midi_interface_,
88 plugin_format_manager_, window_factory, *metronome_, *monitor_fader_);
89 project->install_recording_callback (std::move (recording_callback));
90 return project;
91 }
92
93 std::unique_ptr<QTemporaryDir> temp_dir_obj_;
94 std::filesystem::path project_dir_;
95 std::unique_ptr<dsp::IHardwareAudioInterface> hw_interface_;
97 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
98 std::unique_ptr<utils::AppSettings> app_settings_;
99 std::unique_ptr<utils::ObjectRegistry> registry_;
102};
103
104} // namespace zrythm::test_helpers
Interface for transport.
Definition itransport.h:47
Packed contiguous buffer for RT MIDI events.
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