Skip to content

Commit

Permalink
Disallow shiftHorizontally in more cases, stop audio while changing v…
Browse files Browse the repository at this point in the history
…alues

I don't actually know if the latter is needed, but the sample_marker_editor
does it when changing these values, so it seems reasonable to do as well.

I also removed the "CANT" message when shiftHorizontally fails, as i felt it
to be a bit redundant - usually it fails for trivial reasons, such as start
or end reached
  • Loading branch information
topisani committed Jul 3, 2023
1 parent 9e2dc51 commit 3378a27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
13 changes: 6 additions & 7 deletions src/deluge/gui/views/clip_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <new>

static Clip* getCurrentClip() {
return currentSong->currentClip;
return currentSong->currentClip;
}

ClipView::ClipView() {
Expand Down Expand Up @@ -94,8 +94,8 @@ Action* ClipView::lengthenClip(int32_t newLength) {

// Only if that didn't get us directly to the correct length, manually set length. This will do a resync if playback active
if (getCurrentClip()->loopLength != newLength) {
int actionType = (newLength < getCurrentClip()->loopLength) ? ACTION_CLIP_LENGTH_DECREASE
: ACTION_CLIP_LENGTH_INCREASE;
int actionType =
(newLength < getCurrentClip()->loopLength) ? ACTION_CLIP_LENGTH_DECREASE : ACTION_CLIP_LENGTH_INCREASE;

action = actionLogger.getNewAction(actionType, true);
if (action && action->currentClip != getCurrentClip()) {
Expand Down Expand Up @@ -227,10 +227,10 @@ int ClipView::horizontalEncoderAction(int offset) {

bool wasShifted = clip->shiftHorizontally(modelStack, shiftAmount);
if (!wasShifted) {
numericDriver.displayPopup(HAVE_OLED ? "Can't shift past start" : "CANT");
// No need to show the user why it didnt succeed, usually these cases are fairly trivial
return ACTION_RESULT_DEALT_WITH;
}

uiNeedsRendering(this, 0xFFFFFFFF, 0);

// If possible, just modify a previous Action to add this new shift amount to it.
Expand All @@ -242,8 +242,7 @@ int ClipView::horizontalEncoderAction(int offset) {
// Or possibly because the Action was created but there wasn't enough RAM to create the Consequence. Anyway, just go add a consequence now.
if (!action->firstConsequence) goto addConsequenceToAction;

ConsequenceClipHorizontalShift* consequence =
(ConsequenceClipHorizontalShift*)action->firstConsequence;
ConsequenceClipHorizontalShift* consequence = (ConsequenceClipHorizontalShift*)action->firstConsequence;
consequence->amount += shiftAmount;

// It might look tempting that if we've completed one whole loop, we could delete the Consequence because everything would be back the same -
Expand Down
30 changes: 22 additions & 8 deletions src/deluge/model/clip/audio_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,26 +1123,40 @@ void AudioClip::setPos(ModelStackWithTimelineCounter* modelStack, int32_t newPos
}

bool AudioClip::shiftHorizontally(ModelStackWithTimelineCounter* modelStack, int amount) {
// No horizontal shift when recording
if (recorder) return false;
// No horizontal shift when no sample is loaded
if (!sampleHolder.audioFile) return false;

int64_t newStartPos = int64_t(sampleHolder.startPos) - getSamplesFromTicks(amount);
uint64_t sampleLength = ((Sample*)sampleHolder.audioFile)->lengthInSamples;

if (newStartPos < 0 || newStartPos > sampleLength) {
return false;
}

if (paramManager.containsAnyParamCollectionsIncludingExpression()) {
paramManager.shiftHorizontally(
modelStack->addOtherTwoThingsButNoNoteRow(output->toModControllable(), &paramManager), amount, loopLength);
}

int64_t newStartPos = int64_t(sampleHolder.startPos) + getSamplesFromTicks(amount);
if (newStartPos < 0) {
return false;
}

uint64_t length = sampleHolder.endPos - sampleHolder.startPos;

// Stop the clip if it is playing
bool active = (playbackHandler.isEitherClockActive() && modelStack->song->isClipActive(this) && voiceSample);
unassignVoiceSample();

sampleHolder.startPos = newStartPos;
sampleHolder.endPos = newStartPos + length;

sampleHolder.claimClusterReasons(sampleControls.reversed, CLUSTER_LOAD_IMMEDIATELY_OR_ENQUEUE);

if (playbackHandler.isEitherClockActive() && modelStack->song->isClipActive(this)) {
sampleHolder.claimClusterReasons(sampleControls.reversed, CLUSTER_LOAD_IMMEDIATELY_OR_ENQUEUE);

if (active) {
expectEvent();
reGetParameterAutomation(modelStack);

// Resume the clip if it was playing before
currentSong->currentClip->resumePlayback(modelStack, true);
}
return true;
}
Expand Down

0 comments on commit 3378a27

Please sign in to comment.