103class Song final :
public TimelineCounter {
107 bool mayDoubleTempo();
108 bool ensureAtLeastOneSessionClip();
109 void transposeAllScaleModeClips(int32_t interval);
110 void transposeAllScaleModeClips(int32_t offset,
bool chromatic);
111 bool anyScaleModeClips();
112 void changeMusicalMode(uint8_t yVisualWithinOctave, int8_t change);
113 void rotateMusicalMode(int8_t change);
114 void replaceMusicalMode(
const ScaleChange& changes,
bool affectMIDITranspose);
115 int32_t getYVisualFromYNote(int32_t yNote,
bool inKeyMode);
116 int32_t getYVisualFromYNote(int32_t yNote,
bool inKeyMode,
const MusicalKey& key);
117 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode);
118 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode,
const MusicalKey& key);
119 bool mayMoveModeNote(int16_t yVisualWithinOctave, int8_t newOffset);
121 void setupPatchingForAllParamManagersForDrum(
SoundDrum* drum);
122 void setupPatchingForAllParamManagersForInstrument(
SoundInstrument* sound);
123 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForInstrument(
MIDICable& cable,
125 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForDrum(
MIDICable& cable,
SoundDrum* drum,
127 void grabVelocityToLevelFromMIDICableAndSetupPatchingForEverything(
MIDICable& cable);
128 void getCurrentRootNoteAndScaleName(
StringBuf& buffer);
129 void displayCurrentRootNoteAndScaleName();
153 void setTempoFromNumSamples(
double newTempoSamples,
bool shouldLogAction);
155 void setBPM(
float tempoBPM,
bool shouldLogAction);
156 void setTempoFromParams(int32_t magnitude, int8_t whichValue,
bool shouldLogAction);
157 void deleteSoundsWhichWontSound();
158 void writeTemplateSong(
const char* templateSong);
160 deleteClipObject(
Clip* clip,
bool songBeingDestroyedToo =
false,
161 InstrumentRemoval instrumentRemovalInstruction = InstrumentRemoval::DELETE_OR_HIBERNATE_IF_UNUSED);
162 int32_t getMaxMIDIChannelSuffix(int32_t channel);
163 void addOutput(
Output* output,
bool atStart =
true);
164 void deleteOutputThatIsInMainList(
Output* output,
bool stopAnyAuditioningFirst =
true);
165 void markAllInstrumentsAsEdited();
166 Instrument* getInstrumentFromPresetSlot(OutputType outputType, int32_t presetNumber, int32_t presetSubSlotNumber,
167 char const* name,
char const* dirPath,
bool searchHibernatingToo =
true,
168 bool searchNonHibernating =
true);
170 void setupPatchingForAllParamManagers();
171 void replaceInstrument(
Instrument* oldInstrument,
Instrument* newInstrument,
bool keepNoteRowsWithMIDIInput =
true);
172 void stopAllMIDIAndGateNotesPlaying();
173 void stopAllAuditioning();
174 void deleteOrHibernateOutput(
Output* output);
175 Instrument* getNonAudioInstrumentToSwitchTo(OutputType newOutputType, Availability availabilityRequirement,
176 int16_t newSlot, int8_t newSubSlot,
bool* instrumentWasAlreadyInSong);
177 void removeSessionClipLowLevel(
Clip* clip, int32_t clipIndex);
178 void changeSwingInterval(int32_t newValue);
179 int32_t convertSyncLevelFromFileValueToInternalValue(int32_t fileValue);
180 int32_t convertSyncLevelFromInternalValueToFileValue(int32_t internalValue);
182 void setSongFullPath(
const char* fullPath);
183 int32_t getInputTickMagnitude()
const {
return insideWorldTickMagnitude + insideWorldTickMagnitudeOffsetFromBPM; }
192 firstHibernatingInstrument;
198 int32_t xScrollForReturnToSongView;
199 int32_t xZoomForReturnToSongView;
201 uint32_t tripletsLevel;
203 uint64_t timePerTimerTickBig;
204 int32_t divideByTimePerTimerTick;
211 int32_t insideWorldTickMagnitude;
215 int32_t insideWorldTickMagnitudeOffsetFromBPM;
218 uint8_t swingInterval;
220 Section sections[kMaxNumSections];
223 std::bitset<NUM_PRESET_SCALES> disabledPresetScales;
231 SessionLayoutType sessionLayout = FlashStorage::defaultSessionLayout;
232 int32_t songGridScrollX = 0;
233 int32_t songGridScrollY = 0;
234 int32_t songViewYScroll;
235 int32_t arrangementYScroll;
237 uint8_t sectionToReturnToAfterSongEnd;
239 bool wasLastInArrangementEditor;
240 int32_t lastClipInstanceEnteredStartPos;
243 bool arrangerAutoScrollModeActive;
247 bool outputClipInstanceListIsCurrentlyInvalid;
250 bool paramsInAutomationMode;
252 bool inClipMinderViewOnLoad;
254 int32_t unautomatedParamValues[deluge::modulation::params::kMaxNumUnpatchedParams];
258 std::array<SessionMacro, 8> sessionMacros{};
260 bool getAnyClipsSoloing()
const;
261 Clip* getCurrentClip();
262 void setCurrentClip(Clip* clip) {
263 if (currentClip !=
nullptr) {
264 previousClip = currentClip;
268 uint32_t getInputTickScale();
269 Clip* getSyncScalingClip();
270 void setInputTickScaleClip(Clip* clip);
271 inline bool isFillModeActive() {
return fillModeActive; }
272 void changeFillMode(
bool on);
274 void setClipLength(Clip* clip, uint32_t newLength, Action* action,
bool mayReSyncClip =
true);
275 void doubleClipLength(InstrumentClip* clip, Action* action =
nullptr);
276 Clip* getClipWithOutput(Output* output,
bool mustBeActive =
false, Clip* excludeClip =
nullptr);
277 Error readFromFile(Deserializer& reader);
279 void loadAllSamples(
bool mayActuallyReadFiles =
true);
280 void renderAudio(std::span<StereoSample> outputBuffer, int32_t* reverbBuffer, int32_t sideChainHitPending);
281 bool isYNoteAllowed(int32_t yNote,
bool inKeyMode);
282 Clip* syncScalingClip;
283 void setTimePerTimerTick(uint64_t newTimeBig,
bool shouldLogAction =
false);
286 void ensureInaccessibleParamPresetValuesWithoutKnobsAreZero(Sound* sound);
287 bool areAllClipsInSectionPlaying(int32_t section);
288 void removeYNoteFromMode(int32_t yNoteWithinOctave);
289 void turnSoloingIntoJustPlaying(
bool getRidOfArmingToo =
true);
290 void reassessWhetherAnyClipsSoloing();
291 float getTimePerTimerTickFloat();
292 uint32_t getTimePerTimerTickRounded();
293 int32_t getNumOutputs();
294 Clip* getNextSessionClipWithOutput(int32_t offset, Output* output, Clip* prevClip);
295 bool anyClipsSoloing;
297 ParamManager* getBackedUpParamManagerForExactClip(ModControllableAudio* modControllable, Clip* clip,
298 ParamManager* stealInto =
nullptr);
299 ParamManager* getBackedUpParamManagerPreferablyWithClip(ModControllableAudio* modControllable, Clip* clip,
300 ParamManager* stealInto =
nullptr);
301 void backUpParamManager(ModControllableAudio* modControllable, Clip* clip, ParamManagerForTimeline* paramManager,
302 bool shouldStealExpressionParamsToo =
false);
303 void moveInstrumentToHibernationList(Instrument* instrument);
304 void deleteOrHibernateOutputIfNoClips(Output* output);
305 void removeInstrumentFromHibernationList(Instrument* instrument);
306 bool doesOutputHaveActiveClipInSession(Output* output);
307 bool doesNonAudioSlotHaveActiveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot = -1);
308 bool doesNonAudioSlotHaveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot);
309 bool doesOutputHaveAnyClips(Output* output);
310 void deleteBackedUpParamManagersForClip(Clip* clip);
311 void deleteBackedUpParamManagersForModControllable(ModControllableAudio* modControllable);
312 void deleteHibernatingInstrumentWithSlot(OutputType outputType,
char const* name);
313 void loadCrucialSamplesOnly();
314 Clip* getSessionClipWithOutput(Output* output, int32_t requireSection = -1, Clip* excludeClip =
nullptr,
315 int32_t* clipIndex =
nullptr,
bool excludePendingOverdubs =
false);
316 void restoreClipStatesBeforeArrangementPlay();
317 void deleteOrAddToHibernationListOutput(Output* output);
318 int32_t getLowestSectionWithNoSessionClipForOutput(Output* output);
319 void assertActiveness(ModelStackWithTimelineCounter* modelStack, int32_t endInstanceAtTime = -1);
320 [[nodiscard]]
bool isClipActive(Clip
const* clip)
const;
321 void sendAllMIDIPGMs();
322 void sortOutWhichClipsAreActiveWithoutSendingPGMs(ModelStack* modelStack, int32_t playbackWillStartInArrangerAtPos);
323 void deactivateAnyArrangementOnlyClips();
324 Clip* getLongestClip(
bool includePlayDisabled,
bool includeArrangementOnly);
325 Clip* getLongestActiveClipWithMultipleOrFactorLength(int32_t targetLength,
bool revertToAnyActiveClipIfNone =
true,
326 Clip* excludeClip =
nullptr);
327 int32_t getOutputIndex(Output* output);
328 void setHibernatingMIDIInstrument(MIDIInstrument* newInstrument);
329 void deleteHibernatingMIDIInstrument();
330 MIDIInstrument* grabHibernatingMIDIInstrument(int32_t newSlot, int32_t newSubSlot);
331 NoteRow* findNoteRowForDrum(Kit* kit, Drum* drum, Clip* stopTraversalAtClip =
nullptr);
333 bool anyOutputsSoloingInArrangement;
334 bool getAnyOutputsSoloingInArrangement();
335 void reassessWhetherAnyOutputsSoloingInArrangement();
336 bool isOutputActiveInArrangement(Output* output);
337 Output* getOutputFromIndex(int32_t index);
338 void ensureAllInstrumentsHaveAClipOrBackedUpParamManager(
char const* errorMessageNormal,
339 char const* errorMessageHibernating);
340 Error placeFirstInstancesOfActiveClips(int32_t pos);
341 void endInstancesOfActiveClips(int32_t pos,
bool detachClipsToo =
false);
342 void clearArrangementBeyondPos(int32_t pos, Action* action);
343 void deletingClipInstanceForClip(Output* output, Clip* clip, Action* action,
bool shouldPickNewActiveClip);
344 bool arrangementHasAnyClipInstances();
345 void resumeClipsClonedForArrangementRecording();
346 void setParamsInAutomationMode(
bool newState);
347 bool shouldOldOutputBeReplaced(Clip* clip, Availability* availabilityRequirement =
nullptr);
348 Output* navigateThroughPresetsForInstrument(Output* output, int32_t offset);
349 void instrumentSwapped(Instrument* newInstrument);
350 Instrument* changeOutputType(Instrument* oldInstrument, OutputType newOutputType);
351 AudioOutput* getFirstAudioOutput();
352 AudioOutput* createNewAudioOutput(Output* replaceOutput =
nullptr);
354 void getNoteLengthName(StringBuf& buffer, uint32_t noteLength,
char const* notesString =
"-notes",
355 bool clarifyPerColumn =
false)
const;
356 void replaceOutputLowLevel(Output* newOutput, Output* oldOutput);
357 void removeSessionClip(Clip* clip, int32_t clipIndex,
bool forceClipsAboveToMoveVertically =
false);
358 bool deletePendingOverdubs(Output* onlyWithOutput =
nullptr, int32_t* originalClipIndex =
nullptr,
359 bool createConsequencesForOtherLinearlyRecordingClips =
false);
360 Clip* getPendingOverdubWithOutput(Output* output);
361 Clip* getClipWithOutputAboutToBeginLinearRecording(Output* output);
362 Clip* createPendingNextOverdubBelowClip(Clip* clip, int32_t clipIndex, OverDubType newOverdubNature);
363 bool hasAnyPendingNextOverdubs();
364 Output* getNextAudioOutput(int32_t offset, Output* oldOutput, Availability availabilityRequirement);
365 void deleteOutput(Output* output);
366 void cullAudioClipVoice();
367 int32_t getYScrollSongViewWithoutPendingOverdubs();
368 int32_t removeOutputFromMainList(Output* output,
bool stopAnyAuditioningFirst =
true);
369 void swapClips(Clip* newClip, Clip* oldClip, int32_t clipIndex);
370 Clip* replaceInstrumentClipWithAudioClip(Clip* oldClip, int32_t clipIndex);
371 void setDefaultVelocityForAllInstruments(uint8_t newDefaultVelocity);
372 void midiCableBendRangeUpdatedViaMessage(ModelStack* modelStack, MIDICable& cable, int32_t channelOrZone,
373 int32_t whichBendRange, int32_t bendSemitones);
374 Error addInstrumentsToFileItems(OutputType outputType);
376 uint32_t getQuarterNoteLength();
377 uint32_t getBarLength();
378 uint32_t getSixteenthNoteLength();
379 ModelStackWithThreeMainThings* setupModelStackWithSongAsTimelineCounter(
void* memory);
380 ModelStackWithTimelineCounter* setupModelStackWithCurrentClip(
void* memory);
381 ModelStackWithThreeMainThings* addToModelStack(ModelStack* modelStack);
384 ModelStackWithAutoParam*
getModelStackWithParam(ModelStackWithThreeMainThings* modelStack, int32_t paramID);
388 [[nodiscard]] uint32_t
getLivePos()
const override;
389 [[nodiscard]] int32_t getLoopLength()
const override;
390 [[nodiscard]]
bool isPlayingAutomationNow()
const override;
391 [[nodiscard]]
bool backtrackingCouldLoopBackToEnd()
const override;
392 [[nodiscard]] int32_t getPosAtWhichPlaybackWillCut(ModelStackWithTimelineCounter
const* modelStack)
const override;
393 void getActiveModControllable(ModelStackWithTimelineCounter* modelStack)
override;
394 void expectEvent()
override;
395 TimelineCounter* getTimelineCounterToRecordTo()
override;
398 dsp::Reverb::Model model;
399 float reverbRoomSize;
405 int32_t reverbSidechainVolume;
406 int32_t reverbSidechainShape;
407 int32_t reverbSidechainAttack;
408 int32_t reverbSidechainRelease;
409 SyncLevel reverbSidechainSync;
412 int32_t lastSelectedParamID;
414 lastSelectedParamKind;
415 int32_t lastSelectedParamShortcutX;
416 int32_t lastSelectedParamShortcutY;
417 int32_t lastSelectedParamArrayPosition;
421 void commandTranspose(int32_t interval);
422 int32_t masterTransposeInterval = 0;
423 void transpose(int32_t interval);
424 void adjustMasterTransposeInterval(int32_t interval);
425 void displayMasterTransposeInterval();
428 bool hasBeenTransposed = 0;
429 int16_t transposeOffset = 0;
431 int32_t countAudioClips()
const;
434 uint8_t chordMemNoteCount[kDisplayHeight] = {0};
435 uint8_t chordMem[kDisplayHeight][MAX_NOTES_CHORD_MEM] = {0};
438 void clearTempoAutomation();
439 void updateBPMFromAutomation();
441 float calculateBPM() {
442 float timePerTimerTick = getTimePerTimerTickFloat();
443 return calculateBPM(timePerTimerTick);
445 float calculateBPM(
float timePerTimerTick) {
447 if (insideWorldTickMagnitude > 0) {
448 timePerTimerTick *= ((uint32_t)1 << (insideWorldTickMagnitude));
450 float tempoBPM = (float)110250 / timePerTimerTick;
451 if (insideWorldTickMagnitude < 0) {
452 tempoBPM *= ((uint32_t)1 << (-insideWorldTickMagnitude));
457 int8_t defaultAudioClipOverdubOutputCloning = -1;
460 void changeThresholdRecordingMode(int8_t offset);
461 void displayThresholdRecordingMode();
462 ThresholdRecordingMode thresholdRecordingMode;
465 ScaleMapper scaleMapper;
466 NoteSet userScaleNotes;
468 Clip* currentClip =
nullptr;
469 Clip* previousClip =
nullptr;
470 void inputTickScalePotentiallyJustChanged(uint32_t oldScale);
471 Error readClipsFromFile(Deserializer& reader, ClipArray* clipArray);
472 void addInstrumentToHibernationList(Instrument* instrument);
473 void deleteAllBackedUpParamManagers(
bool shouldAlsoEmptyVector =
true);
474 void deleteAllBackedUpParamManagersWithClips();
475 void deleteAllOutputs(Output** prevPointer);
476 void setupClipIndexesForSaving();
477 void setBPMInner(
float tempoBPM,
bool shouldLogAction);
478 void clearTempoAutomation(
float tempoBPM);