Skip to content

Commit

Permalink
(XT 1.1) Make certain osc controls semitransparent for Audio In (#5766)
Browse files Browse the repository at this point in the history
* Make certain osc controls semitransparent for Audio In

Closes #5638

* Cleanup
  • Loading branch information
mkruselj authored Jan 22, 2022
1 parent 51fc0cb commit 3805547
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 17 deletions.
30 changes: 30 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,31 @@ SurgePatch::SurgePatch(SurgeStorage *storage)
}
} lfoPhaseName;

// Assign the dynamic deactivation handlers
static struct OscAudioInDeact : public ParameterDynamicDeactivationFunction
{
const bool getValue(const Parameter *p) const override
{
auto cge = p->ctrlgroup_entry;
auto osc = &(p->storage->getPatch().scene[p->scene - 1].osc[cge]);

return osc->type.val.i == ot_audioinput;
}
} oscAudioInDeact;

static struct LfoRatePhaseDeact : public ParameterDynamicDeactivationFunction
{
const bool getValue(const Parameter *p) const override
{
auto cge = p->ctrlgroup_entry - ms_lfo1;
auto lf = &(p->storage->getPatch().scene[p->scene - 1].lfo[cge]);
auto res = lf->shape.val.i == lt_envelope;

if (!res && p->can_deactivate())
{
return p->deactivated;
}

return res;
}
} lfoRatePhaseDeact;
Expand All @@ -551,27 +567,41 @@ SurgePatch::SurgePatch(SurgeStorage *storage)
auto cge = p->ctrlgroup_entry - ms_lfo1;
auto lf = &(p->storage->getPatch().scene[p->scene - 1].lfo[cge]);
auto res = lf->delay.deactivated;

return res;
}

Parameter *getPrimaryDeactivationDriver(const Parameter *p) const override
{
auto cge = p->ctrlgroup_entry - ms_lfo1;
auto lf = &(p->storage->getPatch().scene[p->scene - 1].lfo[cge]);

return &(lf->delay);
}
} lfoEnvelopeDeact;

for (int sc = 0; sc < n_scenes; ++sc)
{
// TODO: Don't forget to add osc phase here once we add it in XT 2.0!
for (int o = 0; o < n_oscs; ++o)
{
scene[sc].osc[o].pitch.dynamicDeactivation = &oscAudioInDeact;
scene[sc].osc[o].octave.dynamicDeactivation = &oscAudioInDeact;
scene[sc].osc[o].keytrack.dynamicDeactivation = &oscAudioInDeact;
scene[sc].osc[o].retrigger.dynamicDeactivation = &oscAudioInDeact;
}

for (int lf = 0; lf < n_lfos; ++lf)
{
scene[sc].lfo[lf].start_phase.dynamicName = &lfoPhaseName;
scene[sc].lfo[lf].start_phase.dynamicDeactivation = &lfoRatePhaseDeact;
scene[sc].lfo[lf].rate.dynamicDeactivation = &lfoRatePhaseDeact;

auto *curr = &(scene[sc].lfo[lf].delay), *end = &(scene[sc].lfo[lf].release);

curr->deactivated = false;
curr++; // we don't want to apply it to delay

while (curr <= end)
{
curr->dynamicDeactivation = &lfoEnvelopeDeact;
Expand Down
27 changes: 16 additions & 11 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4809,6 +4809,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
return dynamic_cast<Surge::GUI::IComponentTagValue *>(
juceSkinComponents[skinCtrl->sessionid].get());
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::MultiSwitch)
{
auto rect = juce::Rectangle<int>(skinCtrl->x, skinCtrl->y, skinCtrl->w, skinCtrl->h);
Expand Down Expand Up @@ -4872,6 +4873,8 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control

if (p)
{
hsw->setDeactivated(p->appears_deactivated());

auto fval = p->get_value_f01();

if (p->ctrltype == ct_scenemode)
Expand Down Expand Up @@ -4910,22 +4913,14 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
case tag_mp_jogwaveshape:
cg = cg_FILTER;
break;

/* keep these up top
case tag_mp_category:
case tag_mp_patch:
case tag_store:
cg = endCG;
addToGlobalControls = true;
break; */
case tag_mp_jogfx:
cg = cg_FX;
break;

default:
cg = endCG;
break;
}

if (cg != endCG)
{
addAndMakeVisibleWithTracking(frame->getControlGroupLayer(cg), *hsw);
Expand Down Expand Up @@ -4953,9 +4948,10 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
}
else
{
std::cout << "Can't get a CHSwitch2 BG" << std::endl;
std::cout << "Can't get a MultiSwitch background" << std::endl;
}
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::Switch)
{
auto rect = juce::Rectangle<int>(skinCtrl->x, skinCtrl->y, skinCtrl->w, skinCtrl->h);
Expand All @@ -4965,6 +4961,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
{
auto hsw = componentForSkinSession<Surge::Widgets::Switch>(skinCtrl->sessionid);
hsw->setStorage(&(synth->storage));

if (p)
{
addAndMakeVisibleWithTrackingInCG(p->ctrlgroup, *hsw);
Expand Down Expand Up @@ -5006,9 +5003,11 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control

if (paramIndex >= 0)
nonmod_param[paramIndex] = hsw.get();

if (p)
{
hsw->setValue(p->get_value_f01());
hsw->setDeactivated(p->appears_deactivated());

// Carry over this filter type special case from the default control path
if (p->ctrltype == ct_filtersubtype)
Expand Down Expand Up @@ -5044,6 +5043,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
juceSkinComponents[skinCtrl->sessionid].get());
}
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::LFODisplay)
{
if (!p)
Expand Down Expand Up @@ -5120,6 +5120,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
addAndMakeVisibleWithTrackingInCG(cg_OSC, *oscMenu);
return oscMenu.get();
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::FxMenu)
{
if (!fxMenu)
Expand Down Expand Up @@ -5240,6 +5241,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
}
return nullptr;
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::FilterSelector)
{
// Obviously exposing this widget as a controllable widget would be better
Expand Down Expand Up @@ -5337,6 +5339,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
return dynamic_cast<Surge::GUI::IComponentTagValue *>(
juceSkinComponents[skinCtrl->sessionid].get());
}

if (skinCtrl->defaultComponent == Surge::Skin::Components::WaveShaperSelector)
{
// Obviously exposing this widget as a controllable widget would be better
Expand Down Expand Up @@ -5370,9 +5373,11 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control

return dynamic_cast<Surge::GUI::IComponentTagValue *>(waveshaperSelector.get());
}

if (skinCtrl->ultimateparentclassname != Surge::GUI::NoneClassName)
std::cout << "Unable to make control with upc " << skinCtrl->ultimateparentclassname
std::cout << "Unable to make control with UPC " << skinCtrl->ultimateparentclassname
<< std::endl;

return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/widgets/ModulatableControlInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct ModulatableControlInterface
virtual float getModValue() const { return modValue; }
float modValue{0.f};

/* Deativation can occur by a function or by a value */
/* Deactivation can occur by a function or by a value */
virtual void setDeactivatedFn(std::function<bool()> f)
{
hasDeactivatedFn = true;
Expand Down
13 changes: 10 additions & 3 deletions src/surge-xt/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,30 @@ void MultiSwitch::paint(juce::Graphics &g)
auto y = -valueToOff(value) * heightOfOneImage;
auto t = juce::AffineTransform().translated(0, y);

float activationOpacity = 1.0;

if (isDeactivated)
{
activationOpacity = 0.5;
}

g.reduceClipRegion(getLocalBounds());
switchD->draw(g, 1.0, t);
switchD->draw(g, activationOpacity, t);

if (isHovered)
{
int iv = getIntegerValue();

if (iv == hoverSelection && hoverOnSwitchD)
{
hoverOnSwitchD->draw(g, 1.0, t);
hoverOnSwitchD->draw(g, activationOpacity, t);
}
else if (hoverSwitchD)
{
auto y2 = hoverSelection + frameOffset;
auto t2 = juce::AffineTransform().translated(0, -y2 * heightOfOneImage);

hoverSwitchD->draw(g, 1.0, t2);
hoverSwitchD->draw(g, activationOpacity, t2);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/surge-xt/gui/widgets/MultiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ struct MultiSwitch : public juce::Component,
void updateAccessibleStateOnUserValueChange() override;
std::unique_ptr<juce::AccessibilityHandler> createAccessibilityHandler() override;

bool isDeactivated{false};
void setDeactivated(bool b) { isDeactivated = b; }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MultiSwitch);
};

Expand Down
11 changes: 9 additions & 2 deletions src/surge-xt/gui/widgets/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ void Switch::paint(juce::Graphics &g)
y = -getIntegerValue() * getLocalBounds().getHeight();
}

float activationOpacity = 1.0;

if (isDeactivated)
{
activationOpacity = 0.35;
}

auto t = juce::AffineTransform().translated(0, y);
g.reduceClipRegion(getLocalBounds());

switchD->draw(g, 1.0, t);
switchD->draw(g, activationOpacity, t);

if (isHovered && hoverSwitchD)
{
hoverSwitchD->draw(g, 1.0, t);
hoverSwitchD->draw(g, activationOpacity, t);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/surge-xt/gui/widgets/Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ struct Switch : public juce::Component, public WidgetBaseMixin<Switch>

std::unique_ptr<juce::AccessibilityHandler> createAccessibilityHandler() override;

bool isDeactivated{false};
void setDeactivated(bool b) { isDeactivated = b; }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Switch);
};
} // namespace Widgets
Expand Down

0 comments on commit 3805547

Please sign in to comment.