112class Song final :
public TimelineCounter {
120 bool mayDoubleTempo();
121 bool ensureAtLeastOneSessionClip();
122 void transposeAllScaleModeClips(int32_t interval);
123 void transposeAllScaleModeClips(int32_t offset,
bool chromatic);
124 bool anyScaleModeClips();
135 int32_t getYVisualFromYNote(int32_t yNote,
bool inKeyMode);
136 int32_t getYVisualFromYNote(int32_t yNote,
bool inKeyMode,
const MusicalKey& key);
137 int32_t incrementYNoteInKey(int32_t yNote, int32_t increment,
bool inOctave,
bool inKey)
const;
138 static int32_t incrementYNoteInKey(int32_t yNote, int32_t increment,
bool inOctave,
const MusicalKey& key);
139 static int32_t incrementYNoteNoKey(int32_t yNote, int32_t increment,
bool inOctave,
const MusicalKey& key);
140 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode);
141 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode,
const MusicalKey& key);
142 bool mayMoveModeNote(int16_t yVisualWithinOctave, int8_t newOffset);
144 void setupPatchingForAllParamManagersForDrum(
SoundDrum* drum);
145 void setupPatchingForAllParamManagersForInstrument(
SoundInstrument* sound);
146 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForInstrument(
MIDICable& cable,
148 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForDrum(
MIDICable& cable,
SoundDrum* drum,
150 void grabVelocityToLevelFromMIDICableAndSetupPatchingForEverything(
MIDICable& cable);
151 void getCurrentRootNoteAndScaleName(
StringBuf& buffer);
152 void displayCurrentRootNoteAndScaleName();
185 void setTempoFromNumSamples(
double newTempoSamples,
bool shouldLogAction);
187 void setBPM(
float tempoBPM,
bool shouldLogAction);
188 void setTempoFromParams(int32_t magnitude, int8_t whichValue,
bool shouldLogAction);
189 void deleteSoundsWhichWontSound();
190 void writeTemplateSong(
const char* templateSong);
192 deleteClipObject(
Clip* clip,
bool songBeingDestroyedToo =
false,
193 InstrumentRemoval instrumentRemovalInstruction = InstrumentRemoval::DELETE_OR_HIBERNATE_IF_UNUSED);
194 int32_t getMaxMIDIChannelSuffix(int32_t channel);
195 void addOutput(
Output* output,
bool atStart =
true);
196 void deleteOutputThatIsInMainList(
Output* output,
bool stopAnyAuditioningFirst =
true);
197 void markAllInstrumentsAsEdited();
198 Instrument* getInstrumentFromPresetSlot(OutputType outputType, int32_t presetNumber, int32_t presetSubSlotNumber,
199 char const* name,
char const* dirPath,
bool searchHibernatingToo =
true,
200 bool searchNonHibernating =
true);
201 AudioOutput* getAudioOutputFromName(std::string_view name);
202 void setupPatchingForAllParamManagers();
203 void replaceInstrument(
Instrument* oldInstrument,
Instrument* newInstrument,
bool keepNoteRowsWithMIDIInput =
true);
204 void stopAllMIDIAndGateNotesPlaying();
205 void stopAllAuditioning();
206 void deleteOrHibernateOutput(
Output* output);
207 Instrument* getNonAudioInstrumentToSwitchTo(OutputType newOutputType, Availability availabilityRequirement,
208 int16_t newSlot, int8_t newSubSlot,
bool* instrumentWasAlreadyInSong);
209 void removeSessionClipLowLevel(
Clip* clip, int32_t clipIndex);
210 void changeSwingInterval(int32_t newValue);
211 int32_t convertSyncLevelFromFileValueToInternalValue(int32_t fileValue);
212 int32_t convertSyncLevelFromInternalValueToFileValue(int32_t internalValue);
214 void setSongFullPath(
const char* fullPath);
215 int32_t getInputTickMagnitude()
const {
return insideWorldTickMagnitude + insideWorldTickMagnitudeOffsetFromBPM; }
224 firstHibernatingInstrument;
230 int32_t xScrollForReturnToSongView;
231 int32_t xZoomForReturnToSongView;
233 uint32_t tripletsLevel;
235 uint64_t timePerTimerTickBig;
236 int32_t divideByTimePerTimerTick;
243 int32_t insideWorldTickMagnitude;
247 int32_t insideWorldTickMagnitudeOffsetFromBPM;
250 uint8_t swingInterval;
252 Section sections[kMaxNumSections];
255 std::bitset<NUM_PRESET_SCALES> disabledPresetScales;
261 SessionLayoutType sessionLayout = FlashStorage::defaultSessionLayout;
262 int32_t songGridScrollX = 0;
263 int32_t songGridScrollY = 0;
264 int32_t songViewYScroll;
265 int32_t arrangementYScroll;
267 uint8_t sectionToReturnToAfterSongEnd;
269 bool wasLastInArrangementEditor;
270 int32_t lastClipInstanceEnteredStartPos;
273 bool arrangerAutoScrollModeActive;
277 bool outputClipInstanceListIsCurrentlyInvalid;
280 bool paramsInAutomationMode;
282 bool inClipMinderViewOnLoad;
284 int32_t unautomatedParamValues[deluge::modulation::params::kMaxNumUnpatchedParams];
288 std::array<SessionMacro, 8> sessionMacros{};
290 bool getAnyClipsSoloing()
const;
291 Clip* getCurrentClip();
292 void setCurrentClip(Clip* clip) {
293 if (currentClip !=
nullptr) {
294 previousClip = currentClip;
298 uint32_t getInputTickScale();
299 Clip* getSyncScalingClip();
300 void setInputTickScaleClip(Clip* clip);
301 inline bool isFillModeActive() {
return fillModeActive; }
302 void changeFillMode(
bool on);
304 void setClipLength(Clip* clip, uint32_t newLength, Action* action,
bool mayReSyncClip =
true);
305 void doubleClipLength(InstrumentClip* clip, Action* action =
nullptr);
306 Clip* getClipWithOutput(Output* output,
bool mustBeActive =
false, Clip* excludeClip =
nullptr);
307 Error readFromFile(Deserializer& reader);
309 void loadAllSamples(
bool mayActuallyReadFiles =
true);
310 void renderAudio(std::span<StereoSample> outputBuffer, int32_t* reverbBuffer, int32_t sideChainHitPending);
311 Clip* syncScalingClip;
312 void setTimePerTimerTick(uint64_t newTimeBig,
bool shouldLogAction =
false);
314 void resyncLFOs(
bool reset_state =
false);
315 void ensureInaccessibleParamPresetValuesWithoutKnobsAreZero(Sound* sound);
316 bool areAllClipsInSectionPlaying(int32_t section);
317 void turnSoloingIntoJustPlaying(
bool getRidOfArmingToo =
true);
318 void reassessWhetherAnyClipsSoloing();
319 float getTimePerTimerTickFloat();
320 uint32_t getTimePerTimerTickRounded();
321 int32_t getNumOutputs();
322 Clip* getNextSessionClipWithOutput(int32_t offset, Output* output, Clip* prevClip);
323 bool anyClipsSoloing;
325 ParamManager* getBackedUpParamManagerForExactClip(ModControllableAudio* modControllable, Clip* clip,
326 ParamManager* stealInto =
nullptr);
327 ParamManager* getBackedUpParamManagerPreferablyWithClip(ModControllableAudio* modControllable, Clip* clip,
328 ParamManager* stealInto =
nullptr);
329 void backUpParamManager(ModControllableAudio* modControllable, Clip* clip, ParamManagerForTimeline* paramManager,
330 bool shouldStealExpressionParamsToo =
false);
331 void moveInstrumentToHibernationList(Instrument* instrument);
332 void deleteOrHibernateOutputIfNoClips(Output* output);
333 void removeInstrumentFromHibernationList(Instrument* instrument);
334 bool doesOutputHaveActiveClipInSession(Output* output);
335 bool doesNonAudioSlotHaveActiveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot = -1);
336 bool doesNonAudioSlotHaveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot);
337 bool doesOutputHaveAnyClips(Output* output);
338 void deleteBackedUpParamManagersForClip(Clip* clip);
339 void deleteBackedUpParamManagersForModControllable(ModControllableAudio* modControllable);
340 void deleteHibernatingInstrumentWithSlot(OutputType outputType,
char const* name);
341 void loadCrucialSamplesOnly();
342 Clip* getSessionClipWithOutput(Output* output, int32_t requireSection = -1, Clip* excludeClip =
nullptr,
343 int32_t* clipIndex =
nullptr,
bool excludePendingOverdubs =
false);
344 void restoreClipStatesBeforeArrangementPlay();
345 void deleteOrAddToHibernationListOutput(Output* output);
346 int32_t getLowestSectionWithNoSessionClipForOutput(Output* output);
347 void assertActiveness(ModelStackWithTimelineCounter* modelStack, int32_t endInstanceAtTime = -1);
348 [[nodiscard]]
bool isClipActive(Clip
const* clip)
const;
349 void sendAllMIDIPGMs();
350 void sortOutWhichClipsAreActiveWithoutSendingPGMs(ModelStack* modelStack, int32_t playbackWillStartInArrangerAtPos);
351 void deactivateAnyArrangementOnlyClips();
352 Clip* getLongestClip(
bool includePlayDisabled,
bool includeArrangementOnly);
353 Clip* getLongestActiveClipWithMultipleOrFactorLength(int32_t targetLength,
bool revertToAnyActiveClipIfNone =
true,
354 Clip* excludeClip =
nullptr);
355 int32_t getOutputIndex(Output* output);
356 void setHibernatingMIDIInstrument(MIDIInstrument* newInstrument);
357 void deleteHibernatingMIDIInstrument();
358 MIDIInstrument* grabHibernatingMIDIInstrument(int32_t newSlot, int32_t newSubSlot);
359 NoteRow* findNoteRowForDrum(Kit* kit, Drum* drum, Clip* stopTraversalAtClip =
nullptr);
361 bool anyOutputsSoloingInArrangement;
362 bool getAnyOutputsSoloingInArrangement();
363 void reassessWhetherAnyOutputsSoloingInArrangement();
364 bool isOutputActiveInArrangement(Output* output);
365 Output* getOutputFromIndex(int32_t index);
366 void ensureAllInstrumentsHaveAClipOrBackedUpParamManager(
char const* errorMessageNormal,
367 char const* errorMessageHibernating);
368 Error placeFirstInstancesOfActiveClips(int32_t pos);
369 void endInstancesOfActiveClips(int32_t pos,
bool detachClipsToo =
false);
370 void clearArrangementBeyondPos(int32_t pos, Action* action);
371 void deletingClipInstanceForClip(Output* output, Clip* clip, Action* action,
bool shouldPickNewActiveClip);
372 bool arrangementHasAnyClipInstances();
373 void resumeClipsClonedForArrangementRecording();
374 void setParamsInAutomationMode(
bool newState);
375 bool shouldOldOutputBeReplaced(Clip* clip, Availability* availabilityRequirement =
nullptr);
376 Output* navigateThroughPresetsForInstrument(Output* output, int32_t offset, Clip* displayClip =
nullptr);
377 void instrumentSwapped(Instrument* newInstrument);
378 Instrument* changeOutputType(Instrument* oldInstrument, OutputType newOutputType);
379 AudioOutput* getFirstAudioOutput();
380 AudioOutput* createNewAudioOutput(Output* replaceOutput =
nullptr);
382 void getNoteLengthName(StringBuf& buffer, uint32_t noteLength,
char const* notesString =
"-notes",
383 bool clarifyPerColumn =
false)
const;
384 void replaceOutputLowLevel(Output* newOutput, Output* oldOutput);
385 void removeSessionClip(Clip* clip, int32_t clipIndex,
bool forceClipsAboveToMoveVertically =
false);
386 bool deletePendingOverdubs(Output* onlyWithOutput =
nullptr, int32_t* originalClipIndex =
nullptr,
387 bool createConsequencesForOtherLinearlyRecordingClips =
false);
388 Clip* getPendingOverdubWithOutput(Output* output);
389 Clip* getClipWithOutputAboutToBeginLinearRecording(Output* output);
390 Clip* createPendingNextOverdubBelowClip(Clip* clip, int32_t clipIndex, OverDubType newOverdubNature);
391 bool hasAnyPendingNextOverdubs();
392 Output* getNextAudioOutput(int32_t offset, Output* oldOutput, Availability availabilityRequirement);
393 void deleteOutput(Output* output);
394 void clearRecordingFromReferencesTo(Output* output);
395 void retargetRecordingFromReferences(Output* oldOutput, Output* newOutput);
396 void cullAudioClipVoice();
397 int32_t getYScrollSongViewWithoutPendingOverdubs();
398 int32_t removeOutputFromMainList(Output* output,
bool stopAnyAuditioningFirst =
true);
399 void swapClips(Clip* newClip, Clip* oldClip, int32_t clipIndex);
400 Clip* replaceInstrumentClipWithAudioClip(Clip* oldClip, int32_t clipIndex);
401 void setDefaultVelocityForAllInstruments(uint8_t newDefaultVelocity);
402 void midiCableBendRangeUpdatedViaMessage(ModelStack* modelStack, MIDICable& cable, int32_t channelOrZone,
403 int32_t whichBendRange, int32_t bendSemitones);
404 Error addInstrumentsToFileItems(OutputType outputType);
406 uint32_t getQuarterNoteLength();
407 uint32_t getBarLength();
408 uint32_t getSixteenthNoteLength();
409 ModelStackWithThreeMainThings* setupModelStackWithSongAsTimelineCounter(
void* memory);
410 ModelStackWithTimelineCounter* setupModelStackWithCurrentClip(
void* memory);
411 ModelStackWithThreeMainThings* addToModelStack(ModelStack* modelStack);
414 ModelStackWithAutoParam*
getModelStackWithParam(ModelStackWithThreeMainThings* modelStack, int32_t paramID);
418 [[nodiscard]] uint32_t
getLivePos()
const override;
419 [[nodiscard]] int32_t getLoopLength()
const override;
420 [[nodiscard]]
bool isPlayingAutomationNow()
const override;
421 [[nodiscard]]
bool backtrackingCouldLoopBackToEnd()
const override;
422 [[nodiscard]] int32_t getPosAtWhichPlaybackWillCut(ModelStackWithTimelineCounter
const* modelStack)
const override;
423 void getActiveModControllable(ModelStackWithTimelineCounter* modelStack)
override;
424 void expectEvent()
override;
425 TimelineCounter* getTimelineCounterToRecordTo()
override;
428 dsp::Reverb::Model model;
429 float reverbRoomSize;
435 int32_t reverbSidechainVolume;
436 int32_t reverbSidechainShape;
437 int32_t reverbSidechainAttack;
438 int32_t reverbSidechainRelease;
439 SyncLevel reverbSidechainSync;
442 int32_t lastSelectedParamID;
444 lastSelectedParamKind;
445 int32_t lastSelectedParamShortcutX;
446 int32_t lastSelectedParamShortcutY;
447 int32_t lastSelectedParamArrayPosition;
451 void commandTranspose(int32_t interval);
452 int32_t masterTransposeInterval = 0;
453 void transpose(int32_t interval);
454 void adjustMasterTransposeInterval(int32_t interval);
455 void displayMasterTransposeInterval();
458 bool hasBeenTransposed = 0;
459 int16_t transposeOffset = 0;
461 int32_t countAudioVoices()
const;
464 uint8_t chordMemNoteCount[kDisplayHeight] = {0};
465 uint8_t chordMem[kDisplayHeight][MAX_NOTES_CHORD_MEM] = {0};
468 void clearTempoAutomation();
469 void updateBPMFromAutomation();
471 float calculateBPM() {
472 float timePerTimerTick = getTimePerTimerTickFloat();
473 return calculateBPM(timePerTimerTick);
475 float calculateBPM(
float timePerTimerTick) {
477 if (insideWorldTickMagnitude > 0) {
478 timePerTimerTick *= ((uint32_t)1 << (insideWorldTickMagnitude));
480 float tempoBPM = (float)110250 / timePerTimerTick;
481 if (insideWorldTickMagnitude < 0) {
482 tempoBPM *= ((uint32_t)1 << (-insideWorldTickMagnitude));
487 int8_t defaultAudioClipOverdubOutputCloning = -1;
490 void changeThresholdRecordingMode(int8_t offset);
491 void displayThresholdRecordingMode();
492 ThresholdRecordingMode thresholdRecordingMode;
495 void changeRootNote(int32_t newRootNote, InstrumentClip* clipToAvoidAdjustingScrollFor,
496 InstrumentClip* clipEnteringScaleMode);
497 ScaleMapper scaleMapper;
498 NoteSet userScaleNotes;
500 Clip* currentClip =
nullptr;
501 Clip* previousClip =
nullptr;
502 void inputTickScalePotentiallyJustChanged(uint32_t oldScale);
503 Error readClipsFromFile(Deserializer& reader, ClipArray* clipArray);
504 void addInstrumentToHibernationList(Instrument* instrument);
505 void deleteAllBackedUpParamManagers(
bool shouldAlsoEmptyVector =
true);
506 void deleteAllBackedUpParamManagersWithClips();
507 void deleteAllOutputs(Output** prevPointer);
508 void setupClipIndexesForSaving();
509 void setBPMInner(
float tempoBPM,
bool shouldLogAction);
510 void clearTempoAutomation(
float tempoBPM);