-
Notifications
You must be signed in to change notification settings - Fork 7
/
bufferoverride-base.h
114 lines (91 loc) · 2.83 KB
/
bufferoverride-base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*------------------------------------------------------------------------
Copyright (C) 2001-2022 Sophia Poirier and Tom Murphy VII
This file is part of Buffer Override.
Buffer Override is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Buffer Override is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Buffer Override. If not, see <http:https://www.gnu.org/licenses/>.
To contact the author, use the contact form at http:https://destroyfx.org
------------------------------------------------------------------------*/
#pragma once
#include <atomic>
#include <type_traits>
#include "dfxdefines.h"
#include "dfxmisc.h"
#include "dfxpluginproperties.h"
//-----------------------------------------------------------------------------
// these are the plugin parameters:
enum : dfx::ParameterID
{
kDivisor,
kBufferSize_MS,
kBufferSize_Sync,
kBufferTempoSync,
kBufferInterrupt,
kDivisorLFORate_Hz,
kDivisorLFORate_Sync,
kDivisorLFODepth,
kDivisorLFOShape,
kDivisorLFOTempoSync,
kBufferLFORate_Hz,
kBufferLFORate_Sync,
kBufferLFODepth,
kBufferLFOShape,
kBufferLFOTempoSync,
kSmooth,
kDryWetMix,
kPitchBendRange,
kMidiMode,
kTempo,
kTempoAuto,
kNumParameters
};
enum
{
kMidiMode_Nudge,
kMidiMode_Trigger,
kNumMidiModes
};
enum : dfx::PropertyID
{
kBOProperty_LastViewDataTimestamp = dfx::kPluginProperty_EndOfList,
kBOProperty_ViewData
};
// Current effective buffer/divisor/etc. after LFOs. Used for
// the visualization.
struct BufferOverrideViewData
{
struct Segment
{
float mForcedBufferSeconds {};
float mMinibufferSeconds {};
} mPreLFO, mPostLFO;
};
static_assert(dfx::IsTriviallySerializable<BufferOverrideViewData>);
namespace detail
{
using UnifiedT = std::atomic<BufferOverrideViewData>;
// where 16-byte lock-free atomics are not supported, we slice it into halves (Clang can but GCC cannot)
struct CompositeT
{
using SegmentT = std::atomic<BufferOverrideViewData::Segment>;
SegmentT mPreLFO, mPostLFO;
static_assert(SegmentT::is_always_lock_free);
void store(BufferOverrideViewData value, std::memory_order order) noexcept
{
mPreLFO.store(value.mPreLFO, order);
mPostLFO.store(value.mPostLFO, order);
}
BufferOverrideViewData load(std::memory_order order) const noexcept
{
return {.mPreLFO = mPreLFO.load(order), .mPostLFO = mPostLFO.load(order)};
}
};
} // namespace detail
using AtomicBufferOverrideViewData = std::conditional_t<detail::UnifiedT::is_always_lock_free, detail::UnifiedT, detail::CompositeT>;