Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
metronome.h
1// SPDX-FileCopyrightText: © 2019-2021, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/audio_sample_processor.h"
7#include "dsp/tempo_map.h"
8#include "utils/types.h"
9
10#include <QtQmlIntegration/qqmlintegration.h>
11
12#include <juce_wrapper.h>
13
14namespace zrythm::dsp
15{
19class Metronome : public QObject, public AudioSampleProcessor
20{
21 Q_OBJECT
22 Q_PROPERTY (float volume READ volume WRITE setVolume NOTIFY volumeChanged)
23 Q_PROPERTY (bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
24 QML_ELEMENT
25 QML_UNCREATABLE ("")
26
27public:
28 Metronome (
29 ProcessorBaseDependencies dependencies,
30 juce::AudioSampleBuffer emphasis_sample,
31 juce::AudioSampleBuffer normal_sample,
32 bool initially_enabled = true,
33 float initial_volume = 1.f,
34 QObject * parent = nullptr);
35
36 // ============================================================================
37 // QML Interface
38 // ============================================================================
39
40 float volume () const { return volume_.load (); }
41 void setVolume (float volume)
42 {
43 if (utils::values_equal_for_qproperty_type (volume_.load (), volume))
44 return;
45
46 volume_.store (volume);
47 Q_EMIT volumeChanged (volume);
48 }
49 Q_SIGNAL void volumeChanged (float volume);
50
51 bool enabled () const { return enabled_.load (); }
52 void setEnabled (bool enabled)
53 {
54 if (utils::values_equal_for_qproperty_type (enabled_.load (), enabled))
55 return;
56
57 enabled_.store (enabled);
58 Q_EMIT enabledChanged (enabled);
59 }
60 Q_SIGNAL void enabledChanged (bool enabled);
61
62 // ============================================================================
63
65 EngineProcessTimeInfo time_nfo,
66 const dsp::ITransport &transport,
67 const dsp::TempoMap &tempo_map) noexcept override;
68
69 void custom_prepare_for_processing (
70 const graph::GraphNode * node,
71 units::sample_rate_t sample_rate,
72 nframes_t max_block_length) override;
73
74private:
85 void find_and_queue_metronome_samples (
86 const dsp::TempoMap &tempo_map,
87 units::sample_t start_pos,
88 units::sample_t end_pos,
89 units::sample_t loffset);
90
94 void queue_metronome_countin (
95 const EngineProcessTimeInfo &time_nfo,
96 const dsp::ITransport &transport,
97 const dsp::TempoMap &tempo_map);
98
104 void queue_metronome (
105 bool emphasis,
106 units::sample_t offset,
107 std::source_location loc = std::source_location::current ());
108
109private:
111 juce::AudioSampleBuffer emphasis_sample_buffer_;
112
114 juce::AudioSampleBuffer normal_sample_buffer_;
115
119 std::atomic<float> volume_;
120
121 std::atomic_bool enabled_;
122};
123
124} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:17
void custom_process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept override
Custom processor logic after processing all owned parameters.
Represents a node in a DSP graph.
Definition graph_node.h:131
uint32_t nframes_t
Frame count.
Definition types.h:58
constexpr bool values_equal_for_qproperty_type(const T &a, const T &b)
Helper that checks if 2 values are equal.
Definition qt.h:20
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:133