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 incrementYNoteInKey(int32_t yNote, int32_t increment,
bool inOctave)
const;
118 static int32_t incrementYNoteInKey(int32_t yNote, int32_t increment,
bool inOctave,
const MusicalKey& key);
119 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode);
120 int32_t getYNoteFromYVisual(int32_t yVisual,
bool inKeyMode,
const MusicalKey& key);
121 bool mayMoveModeNote(int16_t yVisualWithinOctave, int8_t newOffset);
123 void setupPatchingForAllParamManagersForDrum(
SoundDrum* drum);
124 void setupPatchingForAllParamManagersForInstrument(
SoundInstrument* sound);
125 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForInstrument(
MIDICable& cable,
127 void grabVelocityToLevelFromMIDICableAndSetupPatchingForAllParamManagersForDrum(
MIDICable& cable,
SoundDrum* drum,
129 void grabVelocityToLevelFromMIDICableAndSetupPatchingForEverything(
MIDICable& cable);
130 void getCurrentRootNoteAndScaleName(
StringBuf& buffer);
131 void displayCurrentRootNoteAndScaleName();
155 void setTempoFromNumSamples(
double newTempoSamples,
bool shouldLogAction);
157 void setBPM(
float tempoBPM,
bool shouldLogAction);
158 void setTempoFromParams(int32_t magnitude, int8_t whichValue,
bool shouldLogAction);
159 void deleteSoundsWhichWontSound();
160 void writeTemplateSong(
const char* templateSong);
162 deleteClipObject(
Clip* clip,
bool songBeingDestroyedToo =
false,
163 InstrumentRemoval instrumentRemovalInstruction = InstrumentRemoval::DELETE_OR_HIBERNATE_IF_UNUSED);
164 int32_t getMaxMIDIChannelSuffix(int32_t channel);
165 void addOutput(
Output* output,
bool atStart =
true);
166 void deleteOutputThatIsInMainList(
Output* output,
bool stopAnyAuditioningFirst =
true);
167 void markAllInstrumentsAsEdited();
168 Instrument* getInstrumentFromPresetSlot(OutputType outputType, int32_t presetNumber, int32_t presetSubSlotNumber,
169 char const* name,
char const* dirPath,
bool searchHibernatingToo =
true,
170 bool searchNonHibernating =
true);
171 AudioOutput* getAudioOutputFromName(std::string_view name);
172 void setupPatchingForAllParamManagers();
173 void replaceInstrument(
Instrument* oldInstrument,
Instrument* newInstrument,
bool keepNoteRowsWithMIDIInput =
true);
174 void stopAllMIDIAndGateNotesPlaying();
175 void stopAllAuditioning();
176 void deleteOrHibernateOutput(
Output* output);
177 Instrument* getNonAudioInstrumentToSwitchTo(OutputType newOutputType, Availability availabilityRequirement,
178 int16_t newSlot, int8_t newSubSlot,
bool* instrumentWasAlreadyInSong);
179 void removeSessionClipLowLevel(
Clip* clip, int32_t clipIndex);
180 void changeSwingInterval(int32_t newValue);
181 int32_t convertSyncLevelFromFileValueToInternalValue(int32_t fileValue);
182 int32_t convertSyncLevelFromInternalValueToFileValue(int32_t internalValue);
184 void setSongFullPath(
const char* fullPath);
185 int32_t getInputTickMagnitude()
const {
return insideWorldTickMagnitude + insideWorldTickMagnitudeOffsetFromBPM; }
194 firstHibernatingInstrument;
200 int32_t xScrollForReturnToSongView;
201 int32_t xZoomForReturnToSongView;
203 uint32_t tripletsLevel;
205 uint64_t timePerTimerTickBig;
206 int32_t divideByTimePerTimerTick;
213 int32_t insideWorldTickMagnitude;
217 int32_t insideWorldTickMagnitudeOffsetFromBPM;
220 uint8_t swingInterval;
222 Section sections[kMaxNumSections];
225 std::bitset<NUM_PRESET_SCALES> disabledPresetScales;
233 SessionLayoutType sessionLayout = FlashStorage::defaultSessionLayout;
234 int32_t songGridScrollX = 0;
235 int32_t songGridScrollY = 0;
236 int32_t songViewYScroll;
237 int32_t arrangementYScroll;
239 uint8_t sectionToReturnToAfterSongEnd;
241 bool wasLastInArrangementEditor;
242 int32_t lastClipInstanceEnteredStartPos;
245 bool arrangerAutoScrollModeActive;
249 bool outputClipInstanceListIsCurrentlyInvalid;
252 bool paramsInAutomationMode;
254 bool inClipMinderViewOnLoad;
256 int32_t unautomatedParamValues[deluge::modulation::params::kMaxNumUnpatchedParams];
260 std::array<SessionMacro, 8> sessionMacros{};
262 bool getAnyClipsSoloing()
const;
263 Clip* getCurrentClip();
264 void setCurrentClip(Clip* clip) {
265 if (currentClip !=
nullptr) {
266 previousClip = currentClip;
270 uint32_t getInputTickScale();
271 Clip* getSyncScalingClip();
272 void setInputTickScaleClip(Clip* clip);
273 inline bool isFillModeActive() {
return fillModeActive; }
274 void changeFillMode(
bool on);
276 void setClipLength(Clip* clip, uint32_t newLength, Action* action,
bool mayReSyncClip =
true);
277 void doubleClipLength(InstrumentClip* clip, Action* action =
nullptr);
278 Clip* getClipWithOutput(Output* output,
bool mustBeActive =
false, Clip* excludeClip =
nullptr);
279 Error readFromFile(Deserializer& reader);
281 void loadAllSamples(
bool mayActuallyReadFiles =
true);
282 void renderAudio(std::span<StereoSample> outputBuffer, int32_t* reverbBuffer, int32_t sideChainHitPending);
283 bool isYNoteAllowed(int32_t yNote,
bool inKeyMode);
284 Clip* syncScalingClip;
285 void setTimePerTimerTick(uint64_t newTimeBig,
bool shouldLogAction =
false);
288 void ensureInaccessibleParamPresetValuesWithoutKnobsAreZero(Sound* sound);
289 bool areAllClipsInSectionPlaying(int32_t section);
290 void removeYNoteFromMode(int32_t yNoteWithinOctave);
291 void turnSoloingIntoJustPlaying(
bool getRidOfArmingToo =
true);
292 void reassessWhetherAnyClipsSoloing();
293 float getTimePerTimerTickFloat();
294 uint32_t getTimePerTimerTickRounded();
295 int32_t getNumOutputs();
296 Clip* getNextSessionClipWithOutput(int32_t offset, Output* output, Clip* prevClip);
297 bool anyClipsSoloing;
299 ParamManager* getBackedUpParamManagerForExactClip(ModControllableAudio* modControllable, Clip* clip,
300 ParamManager* stealInto =
nullptr);
301 ParamManager* getBackedUpParamManagerPreferablyWithClip(ModControllableAudio* modControllable, Clip* clip,
302 ParamManager* stealInto =
nullptr);
303 void backUpParamManager(ModControllableAudio* modControllable, Clip* clip, ParamManagerForTimeline* paramManager,
304 bool shouldStealExpressionParamsToo =
false);
305 void moveInstrumentToHibernationList(Instrument* instrument);
306 void deleteOrHibernateOutputIfNoClips(Output* output);
307 void removeInstrumentFromHibernationList(Instrument* instrument);
308 bool doesOutputHaveActiveClipInSession(Output* output);
309 bool doesNonAudioSlotHaveActiveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot = -1);
310 bool doesNonAudioSlotHaveClipInSession(OutputType outputType, int32_t slot, int32_t subSlot);
311 bool doesOutputHaveAnyClips(Output* output);
312 void deleteBackedUpParamManagersForClip(Clip* clip);
313 void deleteBackedUpParamManagersForModControllable(ModControllableAudio* modControllable);
314 void deleteHibernatingInstrumentWithSlot(OutputType outputType,
char const* name);
315 void loadCrucialSamplesOnly();
316 Clip* getSessionClipWithOutput(Output* output, int32_t requireSection = -1, Clip* excludeClip =
nullptr,
317 int32_t* clipIndex =
nullptr,
bool excludePendingOverdubs =
false);
318 void restoreClipStatesBeforeArrangementPlay();
319 void deleteOrAddToHibernationListOutput(Output* output);
320 int32_t getLowestSectionWithNoSessionClipForOutput(Output* output);
321 void assertActiveness(ModelStackWithTimelineCounter* modelStack, int32_t endInstanceAtTime = -1);
322 [[nodiscard]]
bool isClipActive(Clip
const* clip)
const;
323 void sendAllMIDIPGMs();
324 void sortOutWhichClipsAreActiveWithoutSendingPGMs(ModelStack* modelStack, int32_t playbackWillStartInArrangerAtPos);
325 void deactivateAnyArrangementOnlyClips();
326 Clip* getLongestClip(
bool includePlayDisabled,
bool includeArrangementOnly);
327 Clip* getLongestActiveClipWithMultipleOrFactorLength(int32_t targetLength,
bool revertToAnyActiveClipIfNone =
true,
328 Clip* excludeClip =
nullptr);
329 int32_t getOutputIndex(Output* output);
330 void setHibernatingMIDIInstrument(MIDIInstrument* newInstrument);
331 void deleteHibernatingMIDIInstrument();
332 MIDIInstrument* grabHibernatingMIDIInstrument(int32_t newSlot, int32_t newSubSlot);
333 NoteRow* findNoteRowForDrum(Kit* kit, Drum* drum, Clip* stopTraversalAtClip =
nullptr);
335 bool anyOutputsSoloingInArrangement;
336 bool getAnyOutputsSoloingInArrangement();
337 void reassessWhetherAnyOutputsSoloingInArrangement();
338 bool isOutputActiveInArrangement(Output* output);
339 Output* getOutputFromIndex(int32_t index);
340 void ensureAllInstrumentsHaveAClipOrBackedUpParamManager(
char const* errorMessageNormal,
341 char const* errorMessageHibernating);
342 Error placeFirstInstancesOfActiveClips(int32_t pos);
343 void endInstancesOfActiveClips(int32_t pos,
bool detachClipsToo =
false);
344 void clearArrangementBeyondPos(int32_t pos, Action* action);
345 void deletingClipInstanceForClip(Output* output, Clip* clip, Action* action,
bool shouldPickNewActiveClip);
346 bool arrangementHasAnyClipInstances();
347 void resumeClipsClonedForArrangementRecording();
348 void setParamsInAutomationMode(
bool newState);
349 bool shouldOldOutputBeReplaced(Clip* clip, Availability* availabilityRequirement =
nullptr);
350 Output* navigateThroughPresetsForInstrument(Output* output, int32_t offset);
351 void instrumentSwapped(Instrument* newInstrument);
352 Instrument* changeOutputType(Instrument* oldInstrument, OutputType newOutputType);
353 AudioOutput* getFirstAudioOutput();
354 AudioOutput* createNewAudioOutput(Output* replaceOutput =
nullptr);
356 void getNoteLengthName(StringBuf& buffer, uint32_t noteLength,
char const* notesString =
"-notes",
357 bool clarifyPerColumn =
false)
const;
358 void replaceOutputLowLevel(Output* newOutput, Output* oldOutput);
359 void removeSessionClip(Clip* clip, int32_t clipIndex,
bool forceClipsAboveToMoveVertically =
false);
360 bool deletePendingOverdubs(Output* onlyWithOutput =
nullptr, int32_t* originalClipIndex =
nullptr,
361 bool createConsequencesForOtherLinearlyRecordingClips =
false);
362 Clip* getPendingOverdubWithOutput(Output* output);
363 Clip* getClipWithOutputAboutToBeginLinearRecording(Output* output);
364 Clip* createPendingNextOverdubBelowClip(Clip* clip, int32_t clipIndex, OverDubType newOverdubNature);
365 bool hasAnyPendingNextOverdubs();
366 Output* getNextAudioOutput(int32_t offset, Output* oldOutput, Availability availabilityRequirement);
367 void deleteOutput(Output* output);
368 void cullAudioClipVoice();
369 int32_t getYScrollSongViewWithoutPendingOverdubs();
370 int32_t removeOutputFromMainList(Output* output,
bool stopAnyAuditioningFirst =
true);
371 void swapClips(Clip* newClip, Clip* oldClip, int32_t clipIndex);
372 Clip* replaceInstrumentClipWithAudioClip(Clip* oldClip, int32_t clipIndex);
373 void setDefaultVelocityForAllInstruments(uint8_t newDefaultVelocity);
374 void midiCableBendRangeUpdatedViaMessage(ModelStack* modelStack, MIDICable& cable, int32_t channelOrZone,
375 int32_t whichBendRange, int32_t bendSemitones);
376 Error addInstrumentsToFileItems(OutputType outputType);
378 uint32_t getQuarterNoteLength();
379 uint32_t getBarLength();
380 uint32_t getSixteenthNoteLength();
381 ModelStackWithThreeMainThings* setupModelStackWithSongAsTimelineCounter(
void* memory);
382 ModelStackWithTimelineCounter* setupModelStackWithCurrentClip(
void* memory);
383 ModelStackWithThreeMainThings* addToModelStack(ModelStack* modelStack);
386 ModelStackWithAutoParam*
getModelStackWithParam(ModelStackWithThreeMainThings* modelStack, int32_t paramID);
390 [[nodiscard]] uint32_t
getLivePos()
const override;
391 [[nodiscard]] int32_t getLoopLength()
const override;
392 [[nodiscard]]
bool isPlayingAutomationNow()
const override;
393 [[nodiscard]]
bool backtrackingCouldLoopBackToEnd()
const override;
394 [[nodiscard]] int32_t getPosAtWhichPlaybackWillCut(ModelStackWithTimelineCounter
const* modelStack)
const override;
395 void getActiveModControllable(ModelStackWithTimelineCounter* modelStack)
override;
396 void expectEvent()
override;
397 TimelineCounter* getTimelineCounterToRecordTo()
override;
400 dsp::Reverb::Model model;
401 float reverbRoomSize;
407 int32_t reverbSidechainVolume;
408 int32_t reverbSidechainShape;
409 int32_t reverbSidechainAttack;
410 int32_t reverbSidechainRelease;
411 SyncLevel reverbSidechainSync;
414 int32_t lastSelectedParamID;
416 lastSelectedParamKind;
417 int32_t lastSelectedParamShortcutX;
418 int32_t lastSelectedParamShortcutY;
419 int32_t lastSelectedParamArrayPosition;
423 void commandTranspose(int32_t interval);
424 int32_t masterTransposeInterval = 0;
425 void transpose(int32_t interval);
426 void adjustMasterTransposeInterval(int32_t interval);
427 void displayMasterTransposeInterval();
430 bool hasBeenTransposed = 0;
431 int16_t transposeOffset = 0;
433 int32_t countAudioClips()
const;
436 uint8_t chordMemNoteCount[kDisplayHeight] = {0};
437 uint8_t chordMem[kDisplayHeight][MAX_NOTES_CHORD_MEM] = {0};
440 void clearTempoAutomation();
441 void updateBPMFromAutomation();
443 float calculateBPM() {
444 float timePerTimerTick = getTimePerTimerTickFloat();
445 return calculateBPM(timePerTimerTick);
447 float calculateBPM(
float timePerTimerTick) {
449 if (insideWorldTickMagnitude > 0) {
450 timePerTimerTick *= ((uint32_t)1 << (insideWorldTickMagnitude));
452 float tempoBPM = (float)110250 / timePerTimerTick;
453 if (insideWorldTickMagnitude < 0) {
454 tempoBPM *= ((uint32_t)1 << (-insideWorldTickMagnitude));
459 int8_t defaultAudioClipOverdubOutputCloning = -1;
462 void changeThresholdRecordingMode(int8_t offset);
463 void displayThresholdRecordingMode();
464 ThresholdRecordingMode thresholdRecordingMode;
467 ScaleMapper scaleMapper;
468 NoteSet userScaleNotes;
470 Clip* currentClip =
nullptr;
471 Clip* previousClip =
nullptr;
472 void inputTickScalePotentiallyJustChanged(uint32_t oldScale);
473 Error readClipsFromFile(Deserializer& reader, ClipArray* clipArray);
474 void addInstrumentToHibernationList(Instrument* instrument);
475 void deleteAllBackedUpParamManagers(
bool shouldAlsoEmptyVector =
true);
476 void deleteAllBackedUpParamManagersWithClips();
477 void deleteAllOutputs(Output** prevPointer);
478 void setupClipIndexesForSaving();
479 void setBPMInner(
float tempoBPM,
bool shouldLogAction);
480 void clearTempoAutomation(
float tempoBPM);