11namespace tracktion {
inline namespace engine
21 void updateStreamTime (
TimePosition editTime,
int numSamples)
override
23 const double blockLength = numSamples / modifier.
getSampleRate();
27 const auto syncTypeThisBlock =
juce::roundToInt (modifier.syncTypeParam->getCurrentValue());
28 const auto rateTypeThisBlock = getTypedParamValue<ModifierCommon::RateType> (*modifier.rateTypeParam);
30 const float rateThisBlock = modifier.rateParam->getCurrentValue();
32 if (rateTypeThisBlock == ModifierCommon::hertz)
34 const float durationPerPattern = 1.0f / rateThisBlock;
35 ramp.setDuration (durationPerPattern);
37 if (syncTypeThisBlock == ModifierCommon::transport)
40 modifier.setPhase (ramp.getProportion());
43 ramp.process ((
float) blockLength);
47 tempoSequence.
set (editTime);
48 const auto currentTempo = tempoSequence.
getTempo();
50 const auto proportionOfBar = ModifierCommon::getBarFraction (rateTypeThisBlock);
52 if (syncTypeThisBlock == ModifierCommon::transport)
55 const auto bars = (editTimeInBeats / currentTimeSig.numerator) * rateThisBlock;
57 if (rateTypeThisBlock >= ModifierCommon::fourBars && rateTypeThisBlock <= ModifierCommon::sixtyFourthD)
59 const double virtualBars = bars / proportionOfBar;
60 modifier.setPhase ((
float)
std::fmod (virtualBars, 1.0f));
65 const double bpm = (currentTempo * rateThisBlock) / proportionOfBar;
66 const double secondsPerBeat = 60.0 / bpm;
67 const float secondsPerStep =
static_cast<float> (secondsPerBeat * currentTimeSig.numerator);
68 const float secondsPerPattern = secondsPerStep;
69 ramp.setDuration (secondsPerPattern);
71 modifier.setPhase (ramp.getProportion());
74 ramp.process ((
float) blockLength);
79 void resync (
double duration)
81 if (
juce::roundToInt (modifier.syncTypeParam->getCurrentValue()) == ModifierCommon::note)
83 ramp.setPosition (0.0f);
84 modifier.setPhase (0.0f);
87 ramp.process ((
float) duration);
102 auto um = &edit.getUndoManager();
104 type.referTo (
state, IDs::type, um, random);
105 shape.referTo (
state, IDs::shape, um);
106 syncType.referTo (
state, IDs::syncType, um,
float (ModifierCommon::free));
107 rate.referTo (
state, IDs::rate, um, 1.0f);
108 rateType.referTo (
state, IDs::rateType, um,
float (ModifierCommon::bar));
109 depth.referTo (
state, IDs::depth, um, 1.0f);
110 stepDepth.referTo (
state, IDs::stepDepth, um, 1.0f);
111 smooth.referTo (
state, IDs::smooth, um);
112 bipolar.referTo (
state, IDs::bipolar, um);
119 addAutomatableParameter (p);
120 p->attachToCurrentValue (val);
130 valueRange.setSkewForCentre (centreVal);
132 addAutomatableParameter (p);
133 p->attachToCurrentValue (val);
138 using namespace ModifierCommon;
139 typeParam = addDiscreteParam (
"type",
TRANS(
"Type"), { 0.0f, (
float) getTypeNames().size() - 1 }, type, getTypeNames());
140 shapeParam = addParam (
"shape",
TRANS(
"Shape"), { 0.0f, 1.0f }, 0.5f, shape, {});
141 syncTypeParam = addDiscreteParam (
"syncType",
TRANS(
"Sync type"), { 0.0f, (
float) getSyncTypeChoices().
size() - 1 }, syncType, getSyncTypeChoices());
142 rateParam = addParam (
"rate",
TRANS(
"Rate"), { 0.01f, 50.0f }, 1.0f, rate, {});
143 rateTypeParam = addDiscreteParam (
"rateType",
TRANS(
"Rate Type"), { 0.0f, (
float) getRateTypeChoices().
size() - 1 }, rateType, getRateTypeChoices());
144 depthParam = addParam (
"depth",
TRANS(
"Depth"), { 0.0f, 1.0f }, 0.5f, depth, {});
145 stepDepthParam = addParam (
"stepDepth",
TRANS(
"Step Depth"),{ 0.0f, 1.0f }, 0.5f, stepDepth, {});
146 smoothParam = addParam (
"smooth",
TRANS(
"Smooth"), { 0.0f, 1.0f }, 0.5f, smooth, {});
147 bipolarParam = addDiscreteParam (
"biopolar",
TRANS(
"Bipoloar"), { 0.0f, 1.0f }, bipolar, {
NEEDS_TRANS(
"Uni-polar"),
NEEDS_TRANS(
"Bi-polar") });
149 changedTimer.setCallback ([
this]
151 changedTimer.stopTimer();
158RandomModifier::~RandomModifier()
161 notifyListenersOfDeletion();
165 for (
auto p : getAutomatableParameters())
166 p->detachFromCurrentValue();
168 deleteAutomatableParameters();
209 randomModifierID (rm.
itemID)
213bool RandomModifier::Assignment::isForModifierSource (
const ModifierSource& source)
const
216 return mod->itemID == randomModifierID;
221RandomModifier::Ptr RandomModifier::Assignment::getRandomModifier()
const
223 if (
auto mod = findModifierTypeForID<RandomModifier> (edit, randomModifierID))
237void RandomModifier::setPhase (
float newPhase)
239 const float s = smoothParam->getCurrentValue();
240 newPhase = ((1.0f - s) * newPhase) + (s * AudioFadeCurve::SCurve::get (newPhase));
242 while (newPhase >= 1.0f) newPhase -= 1.0f;
243 while (newPhase < 0.0f) newPhase += 1.0f;
247 previousRandom = currentRandom;
250 const float sd = stepDepthParam->getCurrentValue() * (bp ? 1.0f : 0.5f);
254 currentRandom =
juce::jmap (rand.
nextFloat(), randomRange.getStart(), randomRange.getEnd());
255 jassert (randomRange.contains (currentRandom));
256 randomDifference = currentRandom - previousRandom;
262 auto newValue = [
this, newPhase, s = shapeParam->getCurrentValue()]
264 if (newPhase < (1.0f - s))
265 return previousRandom;
268 const float skewedPhase = ((newPhase - 1.0f) / s) + 1.0f;
269 return (randomDifference * skewedPhase) + previousRandom;
272 newValue *= depthParam->getCurrentValue();
277void RandomModifier::valueTreeChanged()
float nextFloat() noexcept
constexpr Range getIntersectionWith(Range other) const noexcept
int size() const noexcept
void startTimerHz(int timerFrequencyHz) noexcept
bool isTimerRunning() const noexcept
void addListener(Listener *listener)
void removeListener(Listener *listener)
void restoreChangedParametersFromState()
Restores the value of any explicitly set parameters.
void updateParameterStreams(TimePosition)
Updates all the parameter streams to their positions at this time.
const EditItemID itemID
Every EditItem has an ID which is unique within the edit.
The Tracktion Edit class!
void removeModifierTimer(ModifierTimer &)
Removes a ModifierTimer previously added.
TempoSequence tempoSequence
The global TempoSequence of this Edit.
void addModifierTimer(ModifierTimer &)
Adds a ModifierTimer to be updated each block.
float getCurrentValue() override
Returns the current value of the LFO.
void applyToBuffer(const PluginRenderContext &) override
Sub classes should implement this to process the Modifier.
AutomatableParameter::ModifierAssignment * createAssignment(const juce::ValueTree &) override
Must return a new ModifierAssignment for a given state.
float getCurrentPhase() const noexcept
Returns the current phase between 0 & 1.
void initialise() override
Call this once after construction to connect it to the audio graph.
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
#define TRANS(stringLiteral)
#define NEEDS_TRANS(stringLiteral)
constexpr Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
int roundToInt(const FloatType value) noexcept
tempo::Sequence::Position createPosition(const TempoSequence &s)
Creates a Position to iterate over the given TempoSequence.
bool getBoolParamValue(const AutomatableParameter &ap)
Returns a bool version of an AutomatableParameter.
constexpr double inBeats() const
Returns the position as a number of beats.
Represents a position in real-life time.
constexpr double inSeconds() const
Returns the TimePosition as a number of seconds.
A Sequence::Position is an iterator through a Sequence.
TimeSignature getTimeSignature() const
Returns the current TimeSignature of the Position.
BeatPosition getBeats() const
Returns the current beats of the Position.
void set(TimePosition)
Sets the Position to a new time.
double getTempo() const
Returns the current tempo of the Position.
Connects a modifier source to an AutomatableParameter.
Base class for objects which need to know about the global Edit time every block.
Bass class for parameter Modifiers.
juce::ValueTree state
Modifier internal state.
void setEditTime(TimePosition newEditTime)
Subclasses can call this to update the edit time of the current value.
double getSampleRate() const
Returns the sample rate the Modifier has been initialised with.
The context passed to plugin render methods to provide it with buffers to fill.
int bufferNumSamples
The number of samples to write into the audio buffer.
MidiMessageArray * bufferForMidiMessages
A buffer of MIDI events to process.
A ramp which goes between 0 and 1 over a set duration.