tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_StepClip.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14//==============================================================================
17class StepClip : public Clip,
19{
20public:
22 ~StepClip() override;
23
25
26 void cloneFrom (Clip*) override;
27
28 //==============================================================================
29 struct Channel : public Selectable
30 {
32 ~Channel() noexcept override;
33
34 bool operator== (const Channel&) const noexcept;
35
37
38 int getIndex() const;
39 juce::String getDisplayName() const;
40
41 bool usesGrooveStrength() const;
42
43 StepClip& clip;
44 juce::ValueTree state;
45
46 juce::CachedValue<MidiChannel> channel; // MIDI channel. Range: 1 - 16
47 juce::CachedValue<int> noteNumber; // Range: 0 - 127
48 juce::CachedValue<int> noteValue; // Most likely to be ranged from 0 to 127
49 juce::CachedValue<juce::String> grooveTemplate, name;
50 juce::CachedValue<float> grooveStrength;
51
52 private:
54 };
55
56 const juce::Array<Channel*>& getChannels() const noexcept;
57 void removeChannel (int index);
58 void insertNewChannel (int index);
59
60 bool usesProbability();
61
62 //==============================================================================
65 struct Pattern
66 {
67 Pattern (StepClip&, const juce::ValueTree&) noexcept;
68 Pattern (const Pattern&) noexcept;
69
70 juce::String getName() const;
71 void setName (const juce::String&);
72
73 bool getNote (int channel, int index) const noexcept;
74 void setNote (int channel, int index, bool value);
75
76 void clear();
77 void clearChannel (int channel);
78 void insertChannel (int channel);
79 void removeChannel (int channel);
80 void randomiseChannel (int channel);
81 void randomiseSteps();
82 void shiftChannel (int channel, bool toTheRight);
83 void toggleAtInterval (int channel, int interval);
84
85 juce::BigInteger getChannel (int index) const;
86 void setChannel (int index, const juce::BigInteger&);
87
88 int getNumNotes() const;
89 void setNumNotes (int);
90
92 BeatDuration getNoteLength() const;
93
95 void setNoteLength (BeatDuration);
96
97 juce::Array<int> getVelocities (int channel) const;
98 void setVelocities (int channel, const juce::Array<int>&);
99
100 int getVelocity (int channel, int index) const;
101 void setVelocity (int channel, int index, int value);
102
103 juce::Array<double> getGates (int channel) const;
104 void setGates (int channel, const juce::Array<double>&);
105
106 double getGate (int channel, int index) const;
107 void setGate (int channel, int index, double value);
108
109 juce::Array<float> getProbabilities (int channel) const;
110 void setProbabilities (int channel, const juce::Array<float>&);
111
112 float getProbability (int channel, int index) const;
113 void setProbability (int channel, int index, float value);
114
119 {
120 CachedPattern (const Pattern&, int channel);
121
122 bool getNote (int index) const noexcept;
123 int getVelocity (int index) const noexcept;
124 double getGate (int index) const noexcept;
125 float getProbability (int index) const noexcept;
126
127 juce::BigInteger notes;
128 juce::Array<int> velocities;
130 juce::Array<float> probabilities;
132 };
133
134 StepClip& clip;
136
137 private:
138 Pattern& operator= (const Pattern&) = delete;
140 };
141
142 //==============================================================================
147 {
148 PatternInstance (StepClip& c, int index)
149 : clip (c), patternIndex (index) {}
150
151 ~PatternInstance() override
152 {
153 notifyListenersOfDeletion();
154 }
155
157
158 StepClip& clip;
159 int patternIndex;
160
161 Pattern getPattern() const;
162 int getSequenceIndex() const;
163
165
166 private:
167 PatternInstance() = delete;
169 };
170
171 //==============================================================================
172 enum Defaults
173 {
174 defaultNumNotes = 16,
175 defaultNumChannels = 8,
176 defaultMidiChannel = 1,
177 defaultNoteNumber = 60,
178 defaultNoteValue = 96,
179
180 minNumNotes = 2,
181 maxNumNotes = 512,
182
183 minNumChannels = 1,
184 maxNumChannels = 60
185 };
186
187 //==============================================================================
189
190 PatternArray getPatternSequence() const;
191 void setPatternSequence (const PatternArray&);
192
193 void insertVariation (int patternIndex, int insertIndex);
194 void removeVariation (int variationIndex);
195 void removeAllVariations();
196 void createDefaultPatternIfEmpty();
197 void setPatternForVariation (int variationIndex, int newPatternIndex);
198
199 //==============================================================================
200 int insertPattern (const Pattern&, int index);
201 int insertNewPattern (int index);
202 void removePattern (int patternIndex);
203 void removeUnusedPatterns();
204
205 //==============================================================================
206 bool getCell (int patternIndex, int channelIndex, int noteIndex);
207 void setCell (int patternIndex, int channelIndex, int noteIndex, bool value);
208
209 //==============================================================================
210 Pattern getPattern (int index);
211 int getNumPatterns() const;
212 juce::Array<Pattern> getPatterns();
213
214 //==============================================================================
215 float getVolumeDb() const { return level->dbGain.get(); }
216 void setVolumeDb (float v) { level->dbGain = juce::jlimit (-100.0f, 0.0f, v); }
217
218 //==============================================================================
227 bool convertToSeconds = true,
228 PatternInstance* instance = nullptr);
229
237 juce::MidiMessageSequence generateMidiSequence (MidiList::TimeBase, PatternInstance* instance = nullptr);
238
239 juce::Array<BeatPosition> getBeatTimesOfPatternStarts() const;
240
241 BeatPosition getStartBeatOf (PatternInstance*);
242 BeatPosition getEndBeatOf (PatternInstance*);
243
244 int getBeatsPerBar();
245
246 void resizeClipForPatternInstances();
247
248 //==============================================================================
249 bool canBeAddedTo (ClipOwner&) override;
251 juce::Colour getDefaultColour() const override;
252
253 bool isMidi() const override { return false; }
254 bool beatBasedLooping() const override { return true; }
255 bool isMuted() const override { return level->mute.get(); }
256 void setMuted (bool m) override { level->mute = m; }
257
258 LiveClipLevel getLiveClipLevel();
259
260 juce::CachedValue<bool> repeatSequence;
261
262 //==============================================================================
266 bool canLoop() const override;
267
269 ClipPosition getPosition() const override;
271 bool isLooping() const override { return canLoop() && loopLengthBeats > 0_bd; }
273 void setNumberOfLoops (int) override;
275 void disableLooping() override;
277 void setLoopRange (TimeRange) override;
279 void setLoopRangeBeats (BeatRange) override;
281 BeatPosition getLoopStartBeats() const override { return canLoop() ? loopStartBeats : 0_bp; }
283 BeatDuration getLoopLengthBeats() const override { return canLoop() ? loopLengthBeats : 0_bd; }
285 TimePosition getLoopStart() const override;
287 TimeDuration getLoopLength() const override;
288
292 void setUsesGlobalLaunchQuatisation (bool useGlobal) override { useClipLaunchQuantisation = ! useGlobal; }
294 bool usesGlobalLaunchQuatisation() override { return ! useClipLaunchQuantisation; }
298 FollowActions* getFollowActions() override;
299
300private:
301 void generateMidiSequenceForChannels (juce::MidiMessageSequence&, bool convertToSeconds,
302 const Pattern&, BeatPosition startBeat,
303 BeatPosition clipStartBeat, BeatPosition clipEndBeat, const TempoSequence&);
304
305 //==============================================================================
306 struct ChannelList;
308 PatternArray patternInstanceList;
310 juce::CachedValue<BeatPosition> loopStartBeats;
311 juce::CachedValue<BeatDuration> loopLengthBeats, originalLength;
313 juce::CachedValue<bool> useClipLaunchQuantisation;
314 std::unique_ptr<LaunchQuantisation> launchQuantisation;
315 std::unique_ptr<FollowActions> followActions;
316
317 const PatternInstance::Ptr getPatternInstance (int index, bool repeatSequence) const;
318 void updatePatternList();
319
320 void valueTreePropertyChanged (juce::ValueTree&, const juce::Identifier&) override;
321 void valueTreeChildAdded (juce::ValueTree&, juce::ValueTree&) override;
322 void valueTreeChildRemoved (juce::ValueTree&, juce::ValueTree&, int) override;
323 void valueTreeChildOrderChanged (juce::ValueTree&, int, int) override;
324
325 //==============================================================================
326 StepClip() = delete;
328};
329
330}} // namespace tracktion { inline namespace engine
ReferenceCountedObject & operator=(const ReferenceCountedObject &) noexcept
Base class for items that can contain clips.
A clip in an edit.
virtual juce::String getName() const override
Returns the name of the clip.
juce::ValueTree state
The ValueTree of the Clip state.
void setName(const juce::String &newName)
Sets a new name for a clip.
TimeBase
Determines MIDI event timing.
Base class for things that can be selected, and whose properties can appear in the properties panel.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
bool canBeAddedTo(ClipOwner &) override
Tests whether this clip can go on the given parent.
std::shared_ptr< LaunchHandle > getLaunchHandle() override
Some clip types can be launched, if that's possible, this returns a handle to trigger starting/stoppi...
bool isMidi() const override
Returns true if this is a MidiClip.
void setUsesGlobalLaunchQuatisation(bool useGlobal) override
Some clip types can be launched, if that's possible, this sets whether the clip's quantisation or the...
void setLoopRange(TimeRange) override
Sets the loop range the clip should use in seconds.
void generateMidiSequence(juce::MidiMessageSequence &result, bool convertToSeconds=true, PatternInstance *instance=nullptr)
Generate a MidiMessageSequence from either the entire clip or one of its pattern instances.
BeatPosition getLoopStartBeats() const override
Returns the beat position of the loop start point.
void setMuted(bool m) override
Mutes or unmutes the clip.
LaunchQuantisation * getLaunchQuantisation() override
Some clip types can be launched, if that's possible, this returns a quantisation that can be used for...
bool isMuted() const override
Returns true if the clip is muted.
BeatDuration getLoopLengthBeats() const override
Returns the length of loop in beats.
void cloneFrom(Clip *) override
Clones the given clip to this clip.
bool isLooping() const override
Returns true if this clip is currently looping.
void disableLooping() override
Disables all looping.
TimePosition getLoopStart() const override
Returns the start time of the loop start point.
void setNumberOfLoops(int) override
Sets the clip looping a number of times.
juce::Colour getDefaultColour() const override
Returns the default colour for this clip.
bool beatBasedLooping() const override
Returns true if this clip's looping is based on beats or false if absolute time.
bool canLoop() const override
StepClips can only loop if they're being used as launcher clips.
void setLoopRangeBeats(BeatRange) override
Sets the loop range the clip should use in beats.
TimeDuration getLoopLength() const override
Returns the length of loop in seconds.
FollowActions * getFollowActions() override
Some clip types can be launched, if that's possible, this can be used to determine the action to perf...
bool usesGlobalLaunchQuatisation() override
Some clip types can be launched, if that's possible, this returns whether the clip's quantisation or ...
ClipPosition getPosition() const override
Returns the ClipPosition on the parent Track.
Holds a list of TempoSetting objects, to form a sequence of tempo changes.
T is_pointer_v
#define JUCE_LEAK_DETECTOR(OwnerClass)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Represents a duration in beats.
Represents a position in beats.
Represents a duration in real-life time.
Represents a position in real-life time.
Represents the position of a clip on a timeline.
ID for objects of type EditElement - e.g.
Provides a thread-safe way to share a clip's levels with an audio engine without worrying about the C...
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
Creates a snapshot of a pattern's notes, velocities and gates to avoid costly property parsing.