LMMS
Loading...
Searching...
No Matches
juce_AbstractFifo.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
26//==============================================================================
73{
74public:
75 //==============================================================================
77 AbstractFifo (int capacity) noexcept;
78
79 //==============================================================================
81 int getTotalSize() const noexcept;
82
84 int getFreeSpace() const noexcept;
85
87 int getNumReady() const noexcept;
88
90 void reset() noexcept;
91
96 void setTotalSize (int newSize) noexcept;
97
98 //==============================================================================
138 void prepareToWrite (int numToWrite, int& startIndex1, int& blockSize1, int& startIndex2, int& blockSize2) const noexcept;
139
143 void finishedWrite (int numWritten) noexcept;
144
183 void prepareToRead (int numWanted, int& startIndex1, int& blockSize1, int& startIndex2, int& blockSize2) const noexcept;
184
188 void finishedRead (int numRead) noexcept;
189
190 //==============================================================================
191
192private:
193 enum class ReadOrWrite
194 {
197 };
198
199public:
201 template <ReadOrWrite mode>
203 {
204 public:
206 ScopedReadWrite() = default;
207
214 {
215 prepare (*fifo, num);
216 }
217
220
221 ScopedReadWrite& operator= (const ScopedReadWrite&) = delete;
223
228 {
229 if (fifo != nullptr)
231 }
232
236 template <typename FunctionToApply>
237 void forEach (FunctionToApply&& func) const
238 {
239 for (auto i = startIndex1, e = startIndex1 + blockSize1; i != e; ++i) func (i);
240 for (auto i = startIndex2, e = startIndex2 + blockSize2; i != e; ++i) func (i);
241 }
242
244
245 private:
246 void prepare (AbstractFifo&, int) noexcept;
247 static void finish (AbstractFifo&, int) noexcept;
248 void swap (ScopedReadWrite&) noexcept;
249
250 AbstractFifo* fifo = nullptr;
251 };
252
255
276 ScopedRead read (int numToRead) noexcept;
277
298 ScopedWrite write (int numToWrite) noexcept;
299
300private:
301 //==============================================================================
304
306};
307
308template <>
310{
311 f.finishedRead (num);
312}
313
314template <>
316{
317 f.finishedWrite (num);
318}
319
320template <>
325
326template <>
331
332
333} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
Definition juce_AbstractFifo.h:203
void swap(ScopedReadWrite &) noexcept
Definition juce_AbstractFifo.cpp:151
AbstractFifo * fifo
Definition juce_AbstractFifo.h:250
ScopedReadWrite(AbstractFifo &f, int num) noexcept
Definition juce_AbstractFifo.h:213
int startIndex1
Definition juce_AbstractFifo.h:243
void forEach(FunctionToApply &&func) const
Definition juce_AbstractFifo.h:237
int blockSize2
Definition juce_AbstractFifo.h:243
ScopedReadWrite(ScopedReadWrite &&) noexcept
Definition juce_AbstractFifo.cpp:133
int blockSize1
Definition juce_AbstractFifo.h:243
static void finish(AbstractFifo &, int) noexcept
ScopedReadWrite(const ScopedReadWrite &)=delete
int startIndex2
Definition juce_AbstractFifo.h:243
void reset() noexcept
Definition juce_AbstractFifo.cpp:41
void prepareToWrite(int numToWrite, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Definition juce_AbstractFifo.cpp:55
Atomic< int > validEnd
Definition juce_AbstractFifo.h:303
ScopedReadWrite< ReadOrWrite::read > ScopedRead
Definition juce_AbstractFifo.h:253
int getTotalSize() const noexcept
Definition juce_AbstractFifo.cpp:31
ScopedRead read(int numToRead) noexcept
Definition juce_AbstractFifo.cpp:163
ReadOrWrite
Definition juce_AbstractFifo.h:194
void prepareToRead(int numWanted, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Definition juce_AbstractFifo.cpp:93
AbstractFifo(int capacity) noexcept
Definition juce_AbstractFifo.cpp:26
void finishedRead(int numRead) noexcept
Definition juce_AbstractFifo.cpp:119
int getFreeSpace() const noexcept
Definition juce_AbstractFifo.cpp:32
Atomic< int > validStart
Definition juce_AbstractFifo.h:303
void finishedWrite(int numWritten) noexcept
Definition juce_AbstractFifo.cpp:81
ScopedWrite write(int numToWrite) noexcept
Definition juce_AbstractFifo.cpp:164
ScopedReadWrite< ReadOrWrite::write > ScopedWrite
Definition juce_AbstractFifo.h:254
int getNumReady() const noexcept
Definition juce_AbstractFifo.cpp:34
int bufferSize
Definition juce_AbstractFifo.h:302
void setTotalSize(int newSize) noexcept
Definition juce_AbstractFifo.cpp:47
* e
Definition inflate.c:1404
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void(* func)(const char *))
Definition juce_linux_JackAudio.cpp:67
Definition juce_Atomic.h:42
read(f, &c, 1)
#define const
Definition zconf.h:137