LMMS
Loading...
Searching...
No Matches
juce_Reservoir.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
30{
66 template <typename Index, typename GetBufferedRange, typename ReadFromReservoir, typename FillReservoir>
68 GetBufferedRange&& getBufferedRange,
69 ReadFromReservoir&& readFromReservoir,
70 FillReservoir&& fillReservoir)
71 {
72 while (! rangeToRead.isEmpty())
73 {
74 const auto bufferedRange = getBufferedRange();
75
76 if (bufferedRange.contains (rangeToRead.getStart()))
77 {
78 const auto rangeToReadInBuffer = rangeToRead.getIntersectionWith (getBufferedRange());
79 readFromReservoir (rangeToReadInBuffer);
80 rangeToRead.setStart (rangeToReadInBuffer.getEnd());
81 }
82 else
83 {
84 fillReservoir (rangeToRead.getStart());
85
86 const auto newRange = getBufferedRange();
87
88 if (newRange.isEmpty() || ! newRange.contains (rangeToRead.getStart()))
89 break;
90 }
91 }
92
93 return rangeToRead;
94 }
95};
96
97} // namespace juce
Definition juce_Range.h:40
constexpr ValueType getStart() const noexcept
Definition juce_Range.h:80
constexpr bool isEmpty() const noexcept
Definition juce_Range.h:89
JUCE_NODISCARD constexpr Range getIntersectionWith(Range other) const noexcept
Definition juce_Range.h:234
void setStart(const ValueType newStart) noexcept
Definition juce_Range.h:96
Definition carla_juce.cpp:31
Definition juce_Reservoir.h:30
static Range< Index > doBufferedRead(Range< Index > rangeToRead, GetBufferedRange &&getBufferedRange, ReadFromReservoir &&readFromReservoir, FillReservoir &&fillReservoir)
Definition juce_Reservoir.h:67