Skip to content

Commit

Permalink
Refactor InstrumentClipView::horizontalEncoderAction (SynthstromAudib…
Browse files Browse the repository at this point in the history
…le#2100)

* Refactor horizontal encoder action

Refactored code for editing note row length and rotating note row horizontally out of horizontalEncoderAction into their own separate functions

Prep for velocity note view

* format
  • Loading branch information
seangoodvibes committed Jun 7, 2024
1 parent 2fc6d00 commit eeb50c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
76 changes: 38 additions & 38 deletions src/deluge/gui/views/instrument_clip_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4513,6 +4513,9 @@ ActionResult InstrumentClipView::verticalEncoderAction(int32_t offset, bool inCa
static const uint32_t noteNudgeUIModes[] = {UI_MODE_NOTES_PRESSED, UI_MODE_HOLDING_HORIZONTAL_ENCODER_BUTTON, 0};

ActionResult InstrumentClipView::horizontalEncoderAction(int32_t offset) {
if (sdRoutineLock) {
return ActionResult::REMIND_ME_OUTSIDE_CARD_ROUTINE; // Just be safe - maybe not necessary
}

// If holding down notes
if (isUIModeActive(UI_MODE_NOTES_PRESSED)) {
Expand All @@ -4529,9 +4532,6 @@ ActionResult InstrumentClipView::horizontalEncoderAction(int32_t offset) {
// Or, if horizontal encoder held down, nudge note
else if (isUIModeActive(UI_MODE_HOLDING_HORIZONTAL_ENCODER_BUTTON)
&& isUIModeWithinRange(noteNudgeUIModes)) {
if (sdRoutineLock) {
return ActionResult::REMIND_ME_OUTSIDE_CARD_ROUTINE; // Just be safe - maybe not necessary
}
nudgeNotes(offset);
}
}
Expand All @@ -4540,57 +4540,57 @@ ActionResult InstrumentClipView::horizontalEncoderAction(int32_t offset) {

// Auditioning but not holding down <> encoder - edit length of just one row
else if (isUIModeActiveExclusively(UI_MODE_AUDITIONING)) {
if (!shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress) {
wantToEditNoteRowLength:
if (sdRoutineLock) {
return ActionResult::REMIND_ME_OUTSIDE_CARD_ROUTINE; // Just be safe - maybe not necessary
}

char modelStackMemory[MODEL_STACK_MAX_SIZE];
ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
ModelStackWithNoteRow* modelStackWithNoteRow =
getOrCreateNoteRowForYDisplay(modelStack, lastAuditionedYDisplay);

editNoteRowLength(modelStackWithNoteRow, offset, lastAuditionedYDisplay);
editedAnyPerNoteRowStuffSinceAuditioningBegan = true;
}

// Unlike for all other cases where we protect against the user accidentally turning the encoder more after
// releasing their press on it, for this edit-NoteRow-length action, because it's a related action, it's quite
// likely that the user actually will want to do it after the yes-pressed-encoder-down action, which is
// "rotate/shift notes in row". So, we have a 250ms timeout for this one.
else if ((uint32_t)(AudioEngine::audioSampleTimer - timeHorizontalKnobLastReleased) >= 250 * 44) {
shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress = false;
goto wantToEditNoteRowLength;
}
editNoteRowLength(offset);
return ActionResult::DEALT_WITH;
}

// Auditioning *and* holding down <> encoder - rotate/shift just one row
else if (isUIModeActiveExclusively(UI_MODE_AUDITIONING | UI_MODE_HOLDING_HORIZONTAL_ENCODER_BUTTON)) {
if (sdRoutineLock) {
return ActionResult::REMIND_ME_OUTSIDE_CARD_ROUTINE; // Just be safe - maybe not necessary
}
rotateNoteRowHorizontally(offset);
return ActionResult::DEALT_WITH;
}

// Or, let parent deal with it
else {
return ClipView::horizontalEncoderAction(offset);
}
}

void InstrumentClipView::editNoteRowLength(int32_t offset) {
if (!shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress) {
wantToEditNoteRowLength:
char modelStackMemory[MODEL_STACK_MAX_SIZE];
ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
ModelStackWithNoteRow* modelStackWithNoteRow =
((InstrumentClip*)modelStack->getTimelineCounter())
->getNoteRowOnScreen(lastAuditionedYDisplay, modelStack); // Don't create
getOrCreateNoteRowForYDisplay(modelStack, lastAuditionedYDisplay);

rotateNoteRowHorizontally(modelStackWithNoteRow, offset, lastAuditionedYDisplay, true);
shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress =
true; // So don't accidentally shorten row after
editNoteRowLength(modelStackWithNoteRow, offset, lastAuditionedYDisplay);
editedAnyPerNoteRowStuffSinceAuditioningBegan = true;
return ActionResult::DEALT_WITH;
}

// Or, let parent deal with it
else {
return ClipView::horizontalEncoderAction(offset);
// Unlike for all other cases where we protect against the user accidentally turning the encoder more after
// releasing their press on it, for this edit-NoteRow-length action, because it's a related action, it's
// quite likely that the user actually will want to do it after the yes-pressed-encoder-down action, which
// is "rotate/shift notes in row". So, we have a 250ms timeout for this one.
else if ((uint32_t)(AudioEngine::audioSampleTimer - timeHorizontalKnobLastReleased) >= 250 * 44) {
shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress = false;
goto wantToEditNoteRowLength;
}
}

void InstrumentClipView::rotateNoteRowHorizontally(int32_t offset) {
char modelStackMemory[MODEL_STACK_MAX_SIZE];
ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
ModelStackWithNoteRow* modelStackWithNoteRow =
((InstrumentClip*)modelStack->getTimelineCounter())
->getNoteRowOnScreen(lastAuditionedYDisplay, modelStack); // Don't create

rotateNoteRowHorizontally(modelStackWithNoteRow, offset, lastAuditionedYDisplay, true);
// So don't accidentally shorten row after
shouldIgnoreHorizontalScrollKnobActionIfNotAlsoPressedForThisNotePress = true;
editedAnyPerNoteRowStuffSinceAuditioningBegan = true;
}

void InstrumentClipView::tempoEncoderAction(int8_t offset, bool encoderButtonPressed, bool shiftButtonPressed) {

if (isUIModeActive(UI_MODE_AUDITIONING)
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/views/instrument_clip_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class InstrumentClipView final : public ClipView, public InstrumentClipMinder {
void cutAuditionedNotesToOne();
ActionResult verticalEncoderAction(int32_t offset, bool inCardRoutine) override;
ActionResult horizontalEncoderAction(int32_t offset) override;
void editNoteRowLength(int32_t offset);
void rotateNoteRowHorizontally(int32_t offset);
void fillOffScreenImageStores();
void graphicsRoutine() override;

Expand Down

0 comments on commit eeb50c7

Please sign in to comment.