11namespace tracktion {
inline namespace engine
14StepClip::Pattern::Pattern (StepClip& c,
const juce::ValueTree& v) noexcept
19StepClip::Pattern::Pattern (
const Pattern& other) noexcept
20 : clip (other.clip), state (other.state)
24juce::String StepClip::Pattern::getName()
const {
return state[IDs::name]; }
27int StepClip::Pattern::getNumNotes()
const {
return state[IDs::numNotes]; }
28void StepClip::Pattern::setNumNotes (
int n) {
state.
setProperty (IDs::numNotes, n, clip.getUndoManager()); }
36 b.parseString (
state.
getChild (channel)[IDs::pattern].toString(), 2);
57 v.ensureStorageAllocated (sa.size());
60 v.add (s.getIntValue());
65void StepClip::Pattern::setVelocities (
int channel,
const juce::Array<int>& va)
77 sa.add (
juce::String (v));
98 v.ensureStorageAllocated (sa.
size());
103 v.add (parseFraction (s));
123 sa.add (
juce::String (g));
132 v.ensureStorageAllocated (pa.size());
135 v.add (p.getFloatValue());
152 sa.add (
juce::String (p));
157bool StepClip::Pattern::getNote (
int channel,
int index)
const noexcept
159 return getChannel (channel) [index];
162void StepClip::Pattern::setNote (
int channel,
int index,
bool value)
164 if (getNote (channel, index) != value
169 b.setBit (index, value);
170 setChannel (channel, b);
174 if (getVelocity (channel, index) == 0)
175 setVelocity (channel, index, defaultNoteValue);
177 if (getGate (channel, index) == 0.0)
178 setGate (channel, index, 1.0);
183int StepClip::Pattern::getVelocity (
int channel,
int index)
const
185 if (! getNote (channel, index))
188 auto velocities = getVelocities (channel);
191 return velocities[index];
193 if (clip.getChannels()[channel] !=
nullptr)
199void StepClip::Pattern::setVelocity (
int channel,
int index,
int value)
204 setNote (channel, index,
true);
206 auto velocities = getVelocities (channel);
207 const int size = velocities.size();
210 velocities.insertMultiple (size, 127, index - size);
212 velocities.set (index, value);
213 setVelocities (channel, velocities);
216double StepClip::Pattern::getGate (
int channel,
int index)
const
218 if (! getNote (channel, index))
221 auto gates = getGates (channel);
229float StepClip::Pattern::getProbability (
int channel,
int index)
const
231 if (! getNote (channel, index))
234 auto p = getProbabilities (channel);
242void StepClip::Pattern::setGate (
int channel,
int index,
double value)
247 setNote (channel, index, value != 0.0);
249 auto gates = getGates (channel);
250 const int size = gates.size();
253 gates.insertMultiple (size, 1.0, index - size);
255 gates.set (index, value);
256 setGates (channel, gates);
259void StepClip::Pattern::setProbability (
int channel,
int index,
float value)
264 setNote (channel, index, value != 0.0);
266 auto p = getProbabilities (channel);
267 const int size = p.size();
270 p.insertMultiple (size, 1.0f, index - size);
272 p.set (index, value);
273 setProbabilities (channel, p);
276void StepClip::Pattern::clear()
281void StepClip::Pattern::clearChannel (
int channel)
286void StepClip::Pattern::insertChannel (
int channel)
291void StepClip::Pattern::removeChannel (
int channel)
296void StepClip::Pattern::randomiseChannel (
int channel)
298 clearChannel (channel);
301 for (
int i = 0; i < getNumNotes(); ++i)
305void StepClip::Pattern::randomiseSteps()
308 const int numChannels = clip.getChannels().size();
309 const int numSteps = getNumNotes();
314 for (
int i = 0; i < numSteps; ++i)
317 for (
int i = 0; i < numChannels; ++i)
321void StepClip::Pattern::shiftChannel (
int channel,
bool toTheRight)
331 setChannel (channel, c);
334void StepClip::Pattern::toggleAtInterval (
int channel,
int interval)
338 for (
int i = 0; i < getNumNotes(); ++i)
339 c.setBit (i, (i % interval) == 0);
341 setChannel (channel, c);
344StepClip::Pattern::CachedPattern::CachedPattern (
const Pattern& p,
int c)
345 : notes (p.getChannel (c)),
346 velocities (p.getVelocities (c)),
347 gates (p.getGates (c)),
348 probabilities (p.getProbabilities (c))
352bool StepClip::Pattern::CachedPattern::getNote (
int index)
const noexcept
357int StepClip::Pattern::CachedPattern::getVelocity (
int index)
const noexcept
359 if (! getNote (index))
363 return velocities[index];
368double StepClip::Pattern::CachedPattern::getGate (
int index)
const noexcept
370 if (! getNote (index))
379float StepClip::Pattern::CachedPattern::getProbability (
int index)
const noexcept
381 if (! getNote (index))
385 return probabilities[index];
391StepClip::Pattern StepClip::PatternInstance::getPattern()
const
393 return clip.getPattern (patternIndex);
396int StepClip::PatternInstance::getSequenceIndex()
const
398 return clip.getPatternSequence().indexOf (
this);
403 return clip.getName() +
" - "
404 +
TRANS(
"Section 123").replace (
"123",
juce::String (getSequenceIndex() + 1)) +
" ("
int size() const noexcept
void insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
ElementType & getReference(int index) noexcept
const String & toString() const noexcept
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
int size() const noexcept
void ensureStorageAllocated(int minNumElements)
int indexOfChar(juce_wchar characterToLookFor) const noexcept
int length() const noexcept
bool containsChar(juce_wchar character) const noexcept
double getDoubleValue() const noexcept
String substring(int startIndex, int endIndex) const
void removeChild(const ValueTree &child, UndoManager *undoManager)
ValueTree getChild(int index) const
int getNumChildren() const noexcept
ValueTree & setProperty(const Identifier &name, const var &newValue, UndoManager *undoManager)
void removeAllChildren(UndoManager *undoManager)
void addChild(const ValueTree &child, int index, UndoManager *undoManager)
juce::ValueTree state
The ValueTree of the Clip state.
#define TRANS(stringLiteral)
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Represents a duration in beats.
constexpr double inBeats() const
Returns the position as a number of beats.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
BeatDuration getNoteLength() const
Returns the length of one step as a fraction of a beat.
void setNoteLength(BeatDuration)
Sets the length of one step as a fraction of a beat.