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
9#include <QtQmlIntegration/qqmlintegration.h>
10
11#include <juce_audio_basics/juce_audio_basics.h>
12
13namespace zrythm::dsp
14{
18class Metronome : public QObject, public AudioSampleProcessor
19{
20 Q_OBJECT
21 Q_PROPERTY (float volume READ volume WRITE setVolume NOTIFY volumeChanged)
22 Q_PROPERTY (bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
23 QML_ELEMENT
24 QML_UNCREATABLE ("")
25
26public:
27 Metronome (
28 ProcessorBaseDependencies dependencies,
29 juce::AudioSampleBuffer emphasis_sample,
30 juce::AudioSampleBuffer normal_sample,
31 bool initially_enabled = true,
32 float initial_volume = 1.f,
33 QObject * parent = nullptr);
34
35 // ============================================================================
36 // QML Interface
37 // ============================================================================
38
39 float volume () const { return volume_.load (); }
40 void setVolume (float volume)
41 {
42 if (utils::values_equal_for_qproperty_type (volume_.load (), volume))
43 return;
44
45 volume_.store (volume);
46 Q_EMIT volumeChanged (volume);
47 }
48 Q_SIGNAL void volumeChanged (float volume);
49
50 bool enabled () const { return enabled_.load (); }
51 void setEnabled (bool enabled)
52 {
53 if (utils::values_equal_for_qproperty_type (enabled_.load (), enabled))
54 return;
55
56 enabled_.store (enabled);
57 Q_EMIT enabledChanged (enabled);
58 }
59 Q_SIGNAL void enabledChanged (bool enabled);
60
61 // ============================================================================
62
65 const dsp::ITransport &transport,
66 const dsp::TempoMap &tempo_map) noexcept override;
67
68 void custom_prepare_for_processing (
69 const graph::GraphNode * node,
70 units::sample_rate_t sample_rate,
71 units::sample_u32_t max_block_length) override;
72
73private:
84 void find_and_queue_metronome_samples (
85 const dsp::TempoMap &tempo_map,
86 units::sample_t start_pos,
87 units::sample_t end_pos,
88 units::sample_t loffset);
89
93 void queue_metronome_countin (
95 const dsp::ITransport &transport,
96 const dsp::TempoMap &tempo_map);
97
103 void queue_metronome (
104 bool emphasis,
105 units::sample_t offset,
106 std::source_location loc = std::source_location::current ());
107
108private:
110 juce::AudioSampleBuffer emphasis_sample_buffer_;
111
113 juce::AudioSampleBuffer normal_sample_buffer_;
114
118 std::atomic<float> volume_;
119
120 std::atomic_bool enabled_;
121};
122
123} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:16
void custom_process_block(dsp::graph::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:160
constexpr bool values_equal_for_qproperty_type(const T &a, const T &b)
Helper that checks if 2 values are equal.
Definition qt.h:18
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition graph_node.h:51