-
Notifications
You must be signed in to change notification settings - Fork 7
/
scrubby.h
167 lines (123 loc) · 4.4 KB
/
scrubby.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*------------------------------------------------------------------------
Copyright (C) 2002-2024 Sophia Poirier
This file is part of Scrubby.
Scrubby 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.
Scrubby 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 Scrubby. 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 <array>
#include <vector>
#include "dfxmath.h"
#include "dfxplugin.h"
#include "dfxsmoothedvalue.h"
#include "iirfilter.h"
#include "temporatetable.h"
//-----------------------------------------------------------------------------
// these are the plugin parameters:
enum : dfx::ParameterID
{
kSeekRange,
kFreeze,
kSeekRate_Hz,
kSeekRate_Sync,
kSeekRateRandMin_Hz,
kSeekRateRandMin_Sync,
kTempoSync,
kSeekDur,
kSeekDurRandMin,
kSpeedMode,
kSplitChannels,
kPitchConstraint,
kPitchStep0,
kPitchStep1,
kPitchStep2,
kPitchStep3,
kPitchStep4,
kPitchStep5,
kPitchStep6,
kPitchStep7,
kPitchStep8,
kPitchStep9,
kPitchStep10,
kPitchStep11,
kOctaveMin,
kOctaveMax,
kTempo,
kTempoAuto,
kPredelay,
kDryLevel,
kWetLevel,
kNumParameters
};
//-----------------------------------------------------------------------------
// constants
constexpr long kOctave_MinValue = -5;
constexpr long kOctave_MaxValue = 7;
// the number of semitones in an octave
constexpr size_t kNumPitchSteps = 12;
#define USE_LINEAR_ACCELERATION 0
enum
{
kSpeedMode_Robot,
kSpeedMode_DJ,
kNumSpeedModes
};
//-----------------------------------------------------------------------------
class Scrubby final : public DfxPlugin
{
public:
explicit Scrubby(TARGET_API_BASE_INSTANCE_TYPE inInstance);
void dfx_PostConstructor() override;
void initialize() override;
void cleanup() override;
void reset() override;
void randomizeparameters() override;
void processparameters() override;
void processaudio(std::span<float const* const> inAudio, std::span<float* const> outAudio, size_t inNumFrames) override;
private:
static constexpr size_t kNumPresets = 16;
static constexpr double kHighpassFilterCutoff = 39.;
void initPresets();
void generateNewTarget(size_t channel);
double processPitchConstraint(double readStep) const;
void checkTempoSyncStuff();
void processMidiNotes();
// the parameters
double mSeekRangeSeconds = 0.0, mSeekDur = 0.0, mSeekDurRandMin = 0.0;
double mSeekRateHz = 0.0, mSeekRateSync = 0.0;
size_t mSeekRateIndex = 0, mSeekRateRandMinIndex = 0;
double mUserTempo = 0.0;
long mSpeedMode = kSpeedMode_Robot, mOctaveMin = 0, mOctaveMax = 0;
bool mFreeze = false, mSplitChannels = false, mPitchConstraint = false, mTempoSync = false, mUseHostTempo = false;
std::array<bool, kNumPitchSteps> mPitchSteps {};
dfx::SmoothedValue<float> mInputGain, mOutputGain;
// generic versions of these parameters for curved randomization
double mSeekRateHz_gen = 0.0, mSeekRateRandMinHz_gen = 0.0;
bool mUseSeekRateRandMin = false, mUseSeekDurRandMin = false;
// buffers and associated position values/counters/etc.
std::vector<std::vector<float>> mAudioBuffers;
long mWritePos = 0;
std::vector<double> mReadPos, mReadStep, mPortamentoStep;
std::vector<long> mMoveCount, mSeekCount;
long mMaxAudioBufferSize = 0; // the maximum size (in samples) of the audio buffer
double mMaxAudioBufferSize_f = 0.0; // for avoiding casting
std::vector<dfx::IIRFilter> mHighpassFilters;
dfx::math::RandomEngine mRandomEngine {dfx::math::RandomSeed::Entropic};
// tempo sync stuff
double mCurrentTempoBPS = 0.0; // tempo in beats per second
std::vector<bool> mNeedResync; // true when playback has just started up again
dfx::TempoRateTable const mTempoRateTable;
// MIDI note control stuff
std::array<long, kNumPitchSteps> mActiveNotesTable {}; // how many voices of each note in the octave are being played
bool mNotesWereAlreadyActive = false; // says whether any notes were active in the previous block
size_t mSineCount = 0;
};