Skip to content

Commit

Permalink
UI edits clamp start < end for sample and loop (#1322)
Browse files Browse the repository at this point in the history
Closes #1313
  • Loading branch information
baconpaul authored Sep 13, 2024
1 parent 831984f commit 8ffc51f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src-ui/app/edit-screen/components/mapping-pane/SampleWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,23 @@ void SampleWaveform::mouseDrag(const juce::MouseEvent &e)
{
case MouseState::HZ_DRAG_SAMPSTART:
display->variantView.variants[display->selectedVariation].startSample =
sampleForXPixel(xpos);
std::min(sampleForXPixel(xpos),
display->variantView.variants[display->selectedVariation].endSample);
break;
case MouseState::HZ_DRAG_SAMPEND:
display->variantView.variants[display->selectedVariation].endSample = sampleForXPixel(xpos);
display->variantView.variants[display->selectedVariation].endSample =
std::max(sampleForXPixel(xpos),
display->variantView.variants[display->selectedVariation].startSample);
break;
case MouseState::HZ_DRAG_LOOPSTART:
display->variantView.variants[display->selectedVariation].startLoop = sampleForXPixel(xpos);
display->variantView.variants[display->selectedVariation].startLoop =
std::min(sampleForXPixel(xpos),
display->variantView.variants[display->selectedVariation].endLoop);
break;
case MouseState::HZ_DRAG_LOOPEND:
display->variantView.variants[display->selectedVariation].endLoop = sampleForXPixel(xpos);
display->variantView.variants[display->selectedVariation].endLoop =
std::max(sampleForXPixel(xpos),
display->variantView.variants[display->selectedVariation].startLoop);
break;
default:
break;
Expand Down
13 changes: 13 additions & 0 deletions src-ui/app/edit-screen/components/mapping-pane/VariantDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,26 @@ void VariantDisplay::rebuildForSelectedVariation(size_t sel, bool rebuildTabs)
};

attachSamplePoint(startP, "StartS", variantView.variants[selectedVariation].startSample);
sampleAttachments[startP]->precheckGuiAdjust = [this](auto f) {
return std::min(f, this->variantView.variants[this->selectedVariation].endSample);
};
addLabel(startP, "Start");
attachSamplePoint(endP, "EndS", variantView.variants[selectedVariation].endSample);
sampleAttachments[endP]->precheckGuiAdjust = [this](auto f) {
return std::max(f, this->variantView.variants[this->selectedVariation].startSample);
};
addLabel(endP, "End");
attachSamplePoint(startL, "StartL", variantView.variants[selectedVariation].startLoop);
sampleAttachments[startL]->precheckGuiAdjust = [this](auto f) {
return std::min(f, this->variantView.variants[this->selectedVariation].endLoop);
};

editor->themeApplier.applyVariantLoopTheme(sampleEditors[startL].get());
addLabel(startL, "Start");
attachSamplePoint(endL, "EndL", variantView.variants[selectedVariation].endLoop);
sampleAttachments[endL]->precheckGuiAdjust = [this](auto f) {
return std::max(f, this->variantView.variants[this->selectedVariation].startLoop);
};
editor->themeApplier.applyVariantLoopTheme(sampleEditors[endL].get());
addLabel(endL, "End");
attachSamplePoint(fadeL, "fadeL", variantView.variants[selectedVariation].loopFade);
Expand Down
8 changes: 7 additions & 1 deletion src-ui/connectors/PayloadDataAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ struct SamplePointDataAttachment : sst::jucegui::data::Continuous
std::string label;
int64_t sampleCount{0};
std::function<void(const SamplePointDataAttachment &)> onGuiChanged{nullptr};
std::function<int64_t(int64_t)> precheckGuiAdjust{nullptr};

SamplePointDataAttachment(int64_t &v,
std::function<void(const SamplePointDataAttachment &)> ogc)
Expand All @@ -431,8 +432,13 @@ struct SamplePointDataAttachment : sst::jucegui::data::Continuous
return "";
return fmt::format("{}", (int64_t)f);
}
void setValueFromGUI(const float &f) override
void setValueFromGUI(const float &ff) override
{
auto f = ff;
if (precheckGuiAdjust)
{
f = precheckGuiAdjust(ff);
}
value = (int64_t)f;
if (onGuiChanged)
onGuiChanged(*this);
Expand Down

0 comments on commit 8ffc51f

Please sign in to comment.