6#include "utils/units.h"
10#include <juce_audio_basics/juce_audio_basics.h>
22class TimelineDataCache :
public QObject
27 using IntervalType = std::pair<units::sample_t, units::sample_t>;
29 explicit TimelineDataCache (QObject * parent =
nullptr) : QObject (parent) { }
31 ~TimelineDataCache ()
override;
65 finalize_changes_impl ();
92 return a.second > b.first && a.first < b.second;
96 virtual void clear_impl () = 0;
97 virtual void finalize_changes_impl () = 0;
102 virtual std::vector<IntervalType> compute_cached_sample_ranges ()
const = 0;
111class MidiTimelineDataCache :
public TimelineDataCache
114 explicit MidiTimelineDataCache (QObject * parent =
nullptr)
115 : TimelineDataCache (parent)
126 IntervalType interval,
127 const juce::MidiMessageSequence &sequence);
136 return merged_midi_events_;
143 void clear_impl ()
override;
144 void finalize_changes_impl ()
override;
145 std::vector<IntervalType> compute_cached_sample_ranges ()
const override;
152 std::map<IntervalType, juce::MidiMessageSequence> midi_sequences_;
160 juce::MidiMessageSequence merged_midi_events_;
169class AudioTimelineDataCache :
public TimelineDataCache
172 explicit AudioTimelineDataCache (QObject * parent =
nullptr)
173 : TimelineDataCache (parent)
203 IntervalType interval,
204 const juce::AudioSampleBuffer &audio_buffer);
213 return audio_regions_;
220 void clear_impl ()
override;
221 void finalize_changes_impl ()
override;
222 std::vector<IntervalType> compute_cached_sample_ranges ()
const override;
229 std::vector<AudioRegionEntry> audio_regions_;
238class AutomationTimelineDataCache :
public TimelineDataCache
241 explicit AutomationTimelineDataCache (QObject * parent =
nullptr)
242 : TimelineDataCache (parent)
272 IntervalType interval,
273 const std::vector<float> &automation_values);
282 return automation_sequences_;
289 void clear_impl ()
override;
290 void finalize_changes_impl ()
override;
291 std::vector<IntervalType> compute_cached_sample_ranges ()
const override;
298 std::vector<AutomationCacheEntry> automation_sequences_;
303Q_DECLARE_METATYPE (std::vector<zrythm::dsp::TimelineDataCache::IntervalType>)
void add_audio_region(IntervalType interval, const juce::AudioSampleBuffer &audio_buffer)
Adds an audio region for the given interval.
void remove_sequences_matching_interval(IntervalType interval) override
Removes cached data for intervals that truly overlap with the given interval.
const std::vector< AudioRegionEntry > & get_audio_regions() const
Gets the cached audio regions.
bool has_content() const override
Checks if the cache has any content.
void add_automation_sequence(IntervalType interval, const std::vector< float > &automation_values)
Adds an automation sequence for the given interval.
void remove_sequences_matching_interval(IntervalType interval) override
Removes cached data for intervals that truly overlap with the given interval.
bool has_content() const override
Checks if the cache has any content.
const std::vector< AutomationCacheEntry > & get_automation_sequences() const
Gets the cached automation sequences.
const juce::MidiMessageSequence & get_midi_events() const
Gets the cached MIDI events.
void add_midi_sequence(IntervalType interval, const juce::MidiMessageSequence &sequence)
Adds a MIDI sequence for the given interval.
void remove_sequences_matching_interval(IntervalType interval) override
Removes cached data for intervals that truly overlap with the given interval.
bool has_content() const override
Checks if the cache has any content.
void finalize_changes()
Finalizes changes, prepares cached data for access, and emits cachedRangesChanged.
virtual bool has_content() const =0
Checks if the cache has any content.
Q_SIGNAL void cachedRangesChanged(std::vector< IntervalType > ranges) const
Emitted when the cache content changes (after finalize_changes or clear).
static bool intervals_overlap(IntervalType a, IntervalType b) noexcept
Returns true if two intervals truly overlap (adjacent intervals do not count).
virtual void remove_sequences_matching_interval(IntervalType interval)=0
Removes cached data for intervals that truly overlap with the given interval.
void clear()
Clears all cached data and emits cachedRangesChanged.
Audio region entry for caching.
units::sample_t end_sample
End position in samples.
juce::AudioSampleBuffer audio_buffer
Copy of the audio sample buffer.
units::sample_t start_sample
Start position in samples.
Automation cache entry for caching.
units::sample_t end_sample
End position in samples.
units::sample_t start_sample
Start position in samples.
std::vector< float > automation_values
Automation values for the parameter.