Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
clip.h
1/*
2 * Copyright © 2014-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "definitions_cxx.hpp"
21#include "gui/colour/colour.h"
22#include "gui/views/audio_clip_view.h"
23#include "gui/waveform/waveform_render_data.h"
24#include "io/midi/learned_midi.h"
25#include "model/clip/clip.h"
26#include "model/sample/sample_controls.h"
27#include "model/sample/sample_holder_for_clip.h"
28#include "model/sample/sample_playback_guide.h"
29#include "model/timeline_counter.h"
30#include "modulation/params/param.h"
31#include "util/d_string.h"
32#include <cstdint>
33
34class Song;
36class Output;
37class AudioClip;
38class InstrumentClip;
39class Action;
40class TimelineView;
43class Serializer;
44class Deserializer;
45
46class Clip : public TimelineCounter {
47
48public:
49 Clip(ClipType newType);
50 ~Clip() override;
51 bool cancelAnyArming();
52 int32_t getMaxZoom();
53 virtual int32_t getMaxLength();
54 virtual Error clone(ModelStackWithTimelineCounter* modelStack, bool shouldFlattenReversing = false) const = 0;
55 void cloneFrom(Clip const* other);
56 void beginInstance(Song* song, int32_t arrangementRecordPos);
57 void endInstance(int32_t arrangementRecordPos, bool evenIfOtherClip = false);
58 virtual void setPos(ModelStackWithTimelineCounter* modelStack, int32_t newPos,
59 bool useActualPosForParamManagers = true);
60 virtual void setPosForParamManagers(ModelStackWithTimelineCounter* modelStack, bool useActualPos = true);
61 virtual void expectNoFurtherTicks(Song* song, bool actuallySoundChange = true) = 0;
62 virtual void resumePlayback(ModelStackWithTimelineCounter* modelStack, bool mayMakeSound = true) = 0;
63 virtual void reGetParameterAutomation(ModelStackWithTimelineCounter* modelStack);
64 virtual void processCurrentPos(ModelStackWithTimelineCounter* modelStack, uint32_t ticksSinceLast);
65 void prepareForDestruction(ModelStackWithTimelineCounter* modelStack,
66 InstrumentRemoval instrumentRemovalInstruction);
67 uint32_t getActualCurrentPosAsIfPlayingInForwardDirection();
68 int32_t getCurrentPosAsIfPlayingInForwardDirection();
69 Clip* getClipBeingRecordedFrom();
70 Clip* getClipToRecordTo();
71 [[nodiscard]] bool isArrangementOnlyClip() const;
72 bool isActiveOnOutput();
73 virtual bool deleteSoundsWhichWontSound(Song* song);
74 virtual Error appendClip(ModelStackWithTimelineCounter* thisModelStack,
75 ModelStackWithTimelineCounter* otherModelStack);
76 Error resumeOriginalClipFromThisClone(ModelStackWithTimelineCounter* modelStackOriginal,
77 ModelStackWithTimelineCounter* modelStackClone);
78 virtual Error transferVoicesToOriginalClipFromThisClone(ModelStackWithTimelineCounter* modelStackOriginal,
79 ModelStackWithTimelineCounter* modelStackClone) {
80 return Error::NONE;
81 }
82 virtual void increaseLengthWithRepeats(ModelStackWithTimelineCounter* modelStack, int32_t newLength,
83 IndependentNoteRowLengthIncrease independentNoteRowInstruction,
84 bool completelyRenderOutIterationDependence = false,
85 Action* action = nullptr) {
86 } // This is not implemented for AudioClips - because in the cases where we call this, we don't want it to happen
87 // for AudioClips
88 virtual void lengthChanged(ModelStackWithTimelineCounter* modelStack, int32_t oldLength, Action* action = nullptr);
89 virtual void getSuggestedParamManager(Clip* newClip, ParamManagerForTimeline** suggestedParamManager, Sound* sound);
90 virtual ParamManagerForTimeline* getCurrentParamManager() { return nullptr; }
91
92 // You're likely to want to call pickAnActiveClipIfPossible() after this
93 virtual void detachFromOutput(ModelStackWithTimelineCounter* modelStack, bool shouldRememberDrumName,
94 bool shouldDeleteEmptyNoteRowsAtEndOfList = false,
95 bool shouldRetainLinksToSounds = false, bool keepNoteRowsWithMIDIInput = true,
96 bool shouldGrabMidiCommands = false, bool shouldBackUpExpressionParamsToo = true) = 0;
97
98 virtual Error undoDetachmentFromOutput(ModelStackWithTimelineCounter* modelStack);
99 virtual bool renderAsSingleRow(ModelStackWithTimelineCounter* modelStack, TimelineView* editorScreen,
100 int32_t xScroll, uint32_t xZoom, RGB* image, uint8_t occupancyMask[],
101 bool addUndefinedArea = true, int32_t noteRowIndexStart = 0,
102 int32_t noteRowIndexEnd = 2147483647, int32_t xStart = 0,
103 int32_t xEnd = kDisplayWidth, bool allowBlur = true, bool drawRepeats = false);
104
105 // To be called after Song loaded, to link to the relevant Output object
106 virtual Error claimOutput(ModelStackWithTimelineCounter* modelStack) = 0;
107 virtual void finishLinearRecording(ModelStackWithTimelineCounter* modelStack, Clip* nextPendingLoop = nullptr,
108 int32_t buttonLatencyForTempolessRecord = 0) = 0;
109 virtual Error beginLinearRecording(ModelStackWithTimelineCounter* modelStack, int32_t buttonPressLatency) = 0;
110 void drawUndefinedArea(int32_t localScroll, uint32_t, int32_t lengthToDisplay, RGB* image, uint8_t[],
111 int32_t imageWidth, TimelineView* editorScreen, bool tripletsOnHere);
112 bool opportunityToBeginSessionLinearRecording(ModelStackWithTimelineCounter* modelStack, bool* newOutputCreated,
113 int32_t buttonPressLatency);
114 virtual Clip* cloneAsNewOverdub(ModelStackWithTimelineCounter* modelStack, OverDubType newOverdubNature) = 0;
115
118 virtual bool shouldCloneForOverdubs() {
119 return true; // instrument version of in place overdub doesn't quite work so never do it for now
120 };
121 void setupOverdubInPlace(OverDubType type);
122 virtual bool getCurrentlyRecordingLinearly() = 0;
123 virtual bool currentlyScrollableAndZoomable() = 0;
124 virtual void clear(Action* action, ModelStackWithTimelineCounter* modelStack, bool clearAutomation,
125 bool clearSequenceAndMPE);
126
127 void writeToFile(Serializer& writer, Song* song);
128 virtual void writeDataToFile(Serializer& writer, Song* song);
129 void writeMidiCommandsToFile(Serializer& writer, Song* song);
130 virtual char const* getXMLTag() = 0;
131 virtual Error readFromFile(Deserializer& reader, Song* song) = 0;
132 void readTagFromFile(Deserializer& reader, char const* tagName, Song* song, int32_t* readAutomationUpToPos);
133
134 virtual void copyBasicsFrom(Clip const* otherClip);
135 void setupForRecordingAsAutoOverdub(Clip* existingClip, Song* song, OverDubType newOverdubNature);
136 void outputChanged(ModelStackWithTimelineCounter* modelStack, Output* newOutput);
137 virtual bool isAbandonedOverdub() = 0;
138 virtual bool wantsToBeginLinearRecording(Song* song);
139 virtual void quantizeLengthForArrangementRecording(ModelStackWithTimelineCounter* modelStack, int32_t lengthSoFar,
140 uint32_t timeRemainder, int32_t suggestedLength,
141 int32_t alternativeLongerLength) = 0;
142 virtual void abortRecording() = 0;
143 virtual void stopAllNotesPlaying(Song* song, bool actuallySoundChange = true) {}
144 virtual bool willCloneOutputForOverdub() { return false; }
145 void setSequenceDirectionMode(ModelStackWithTimelineCounter* modelStack, SequenceDirection newSequenceDirection);
146 virtual void incrementPos(ModelStackWithTimelineCounter* modelStack, int32_t numTicks);
148 virtual bool shiftHorizontally(ModelStackWithTimelineCounter* modelStack, int32_t amount, bool shiftAutomation,
149 bool shiftSequenceAndMPE) = 0;
150
151 // ----- TimelineCounter implementation -------
152 [[nodiscard]] uint32_t getLivePos() const override;
153 [[nodiscard]] int32_t getLoopLength() const override;
154 [[nodiscard]] bool isPlayingAutomationNow() const override;
155 [[nodiscard]] bool backtrackingCouldLoopBackToEnd() const override;
156 [[nodiscard]] int32_t getPosAtWhichPlaybackWillCut(ModelStackWithTimelineCounter const* modelStack) const override;
157 [[nodiscard]] int32_t getLastProcessedPos() const override;
158 bool possiblyCloneForArrangementRecording(ModelStackWithTimelineCounter* modelStack) override;
159 TimelineCounter* getTimelineCounterToRecordTo() override;
160 void getActiveModControllable(ModelStackWithTimelineCounter* modelStack) override;
161 void expectEvent() override;
162
163 Output* output;
164
165 int16_t colourOffset;
166
167 const ClipType type;
168 uint8_t section;
169 bool soloingInSessionMode;
170 ArmState armState;
171 bool activeIfNoSolo;
172 bool activeIfNoSoloBeforeStemExport; // Used by stem export to restore previous state
173 bool exportStem; // Used by stem export to flag if this note row should be exported
174 bool wasActiveBefore; // A temporary thing used by Song::doLaunch()
175 bool gotInstanceYet; // For use only while loading song
176
177 bool isPendingOverdub;
178 bool isUnfinishedAutoOverdub;
179 bool wasWantingToDoLinearRecordingBeforeCountIn; // Only valid during a count-in
180 OverDubType overdubNature;
181
182 LearnedMIDI muteMIDICommand;
183
184#if HAVE_SEQUENCE_STEP_CONTROL
185 bool currentlyPlayingReversed;
186 SequenceDirection sequenceDirectionMode;
187#endif
188
189 int32_t loopLength;
190
191 // Before linear recording of this Clip began, and this Clip started getting extended to multiples of this
192 int32_t originalLength;
193
194 int32_t lastProcessedPos;
195
196 Clip* beingRecordedFromClip;
197
198 int32_t repeatCount;
199
200 uint32_t indexForSaving; // For use only while saving song
201
202 LaunchStyle launchStyle;
203 int64_t fillEventAtTickCount;
204 bool overdubsShouldCloneOutput;
205
206 // START ~ new Automation Clip View Variables
207 bool onAutomationClipView; // new to save the view that you are currently in
208 //(e.g. if you leave clip and want to come back where you left off)
209
212 deluge::modulation::params::Kind lastSelectedParamKind;
213 int32_t lastSelectedParamShortcutX;
214 int32_t lastSelectedParamShortcutY;
215 int32_t lastSelectedParamArrayPosition;
216 OutputType lastSelectedOutputType;
217 PatchSource lastSelectedPatchSource;
218 // END ~ new Automation Clip View Variables
219
220 virtual bool isEmpty(bool displayPopup = true) = 0;
221
222 virtual bool renderSidebar(uint32_t whichRows = 0, RGB image[][kDisplayWidth + kSideBarWidth] = nullptr,
223 uint8_t occupancyMask[][kDisplayWidth + kSideBarWidth] = nullptr) = 0;
224 // Setup the name per clip on session/song/grid view and to be selectable on the arranger
225 String name;
226
227protected:
228 virtual void posReachedEnd(ModelStackWithTimelineCounter* modelStack); // May change the TimelineCounter in the
229 // modelStack if new Clip got created
230 virtual bool
231 cloneOutput(ModelStackWithTimelineCounter* modelStack) = 0; // Returns whether a new Output was in fact created
232 Error solicitParamManager(Song* song, ParamManager* newParamManager = nullptr,
233 Clip* favourClipForCloningParamManager = nullptr);
234 virtual void pingpongOccurred(ModelStackWithTimelineCounter* modelStack) {}
235};
Definition action.h:75
Definition audio_clip.h:35
Definition clip.h:46
uint32_t getLivePos() const override
Get the current tick of this timeline counter relative to the playback handler.
Definition clip.cpp:149
int32_t getLastProcessedPos() const override
Get the tick at which this timeline counter last did anything.
Definition clip.cpp:192
virtual bool shiftHorizontally(ModelStackWithTimelineCounter *modelStack, int32_t amount, bool shiftAutomation, bool shiftSequenceAndMPE)=0
Return true if successfully shifted.
int32_t lastSelectedParamID
last selected Parameter to be edited in Automation Instrument Clip View
Definition clip.h:211
virtual bool shouldCloneForOverdubs()
Definition clip.h:118
Definition storage_manager.h:185
Definition instrument_clip.h:48
Definition learned_midi.h:30
Definition model_stack.h:129
Definition output.h:81
Definition param_manager.h:174
Definition param_manager.h:45
This class represents the colour format most used by the Deluge globally.
Definition rgb.h:14
Definition storage_manager.h:119
Definition song.h:104
Definition sound.h:71
Definition d_string.h:46
Definition timeline_view.h:27
Kind
Definition param.h:42