Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draggable filter panel additions #681

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions hi_core/hi_components/audio_components/EqComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection
ResetOnDoubleClick,
AllowContextMenu,
GainRange,
HandleSize,
numSpecialProperties
};

Expand All @@ -331,6 +332,7 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection
RETURN_DEFAULT_PROPERTY_ID(index, SpecialProperties::ResetOnDoubleClick, "ResetOnDoubleClick");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialProperties::AllowContextMenu, "AllowContextMenu");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialProperties::GainRange, "GainRange");
RETURN_DEFAULT_PROPERTY_ID(index, SpecialProperties::HandleSize, "HandleSize");

jassertfalse;
return {};
Expand All @@ -347,6 +349,7 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection
RETURN_DEFAULT_PROPERTY(index, SpecialProperties::ResetOnDoubleClick, var(false));
RETURN_DEFAULT_PROPERTY(index, SpecialProperties::AllowContextMenu, var(true));
RETURN_DEFAULT_PROPERTY(index, SpecialProperties::GainRange, var(24.0));
RETURN_DEFAULT_PROPERTY(index, SpecialProperties::HandleSize, var(24));

jassertfalse;

Expand All @@ -364,6 +367,8 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection

auto u = (bool)getPropertyWithDefault(object, (int)SpecialProperties::UseUndoManager);
auto rd = (bool)getPropertyWithDefault(object, (int)SpecialProperties::ResetOnDoubleClick);

auto hs = (int)getPropertyWithDefault(object, (int)SpecialProperties::HandleSize);

if (u)
fd->setUndoManager(getMainController()->getControlUndoManager());
Expand All @@ -378,6 +383,7 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection
fd->setResetOnDoubleClick(rd);
fd->setAllowFilterResizing(r);
fd->setSpectrumVisibility((SpectrumVisibility)s);
fd->setHandleSize(hs);
}
}

Expand All @@ -395,6 +401,8 @@ struct FilterDragOverlay::Panel : public PanelWithProcessorConnection

storePropertyInObject(obj, (int)SpecialProperties::GainRange, fd->gainRange);
storePropertyInObject(obj, (int)SpecialProperties::AllowContextMenu, fd->allowContextMenu);

storePropertyInObject(obj, (int)SpecialProperties::HandleSize, fd->handleSize);
}

return obj;
Expand Down Expand Up @@ -564,7 +572,7 @@ void FilterDragOverlay::checkEnabledBands()

void FilterDragOverlay::resized()
{
constrainer->setMinimumOnscreenAmounts(24, 24, 24, 24);
constrainer->setMinimumOnscreenAmounts(handleSize, handleSize, handleSize, handleSize);

fftAnalyser.setBounds(getLocalBounds().reduced(offset));
filterGraph.setBounds(getLocalBounds().reduced(offset));
Expand Down Expand Up @@ -668,7 +676,7 @@ void FilterDragOverlay::updatePositions(bool forceUpdate)

Rectangle<int> b(point, point);

dragComponents[i]->setBounds(b.withSizeKeepingCentre(24, 24));
dragComponents[i]->setBounds(b.withSizeKeepingCentre(handleSize, handleSize));
}
}

Expand Down Expand Up @@ -1015,6 +1023,9 @@ void FilterDragOverlay::FilterDragComponent::mouseDrag(const MouseEvent& e)
{
CHECK_MIDDLE_MOUSE_DRAG(e);

auto* broadcasterValue = new DynamicObject();
broadcasterValue->setProperty("Index", index);

if (e.mods.isShiftDown())
{
auto deltaNormalised = (float)e.getDistanceFromDragStartY() / (float)getParentComponent()->getHeight();
Expand All @@ -1030,12 +1041,16 @@ void FilterDragOverlay::FilterDragComponent::mouseDrag(const MouseEvent& e)

parent.setEqAttribute(CurveEq::BandParameter::Q, index, qRange.convertFrom0to1(newValue));

broadcasterValue->setProperty("Q", qRange.convertFrom0to1(newValue));
parent.eq->sendBroadcasterMessage("QChanged", broadcasterValue);

return;
}
else
{
auto pi = parent.eq->getParameterIndex(index, CurveEq::BandParameter::Q);
dragQStart = parent.eq->getAttribute(pi);
broadcasterValue->setProperty("Q", dragQStart);
}

auto te = e.getEventRelativeTo(this);
Expand Down Expand Up @@ -1073,15 +1088,19 @@ void FilterDragOverlay::FilterDragComponent::mouseDrag(const MouseEvent& e)

parent.setEqAttribute(CurveEq::BandParameter::Freq, index, freq);
parent.setEqAttribute(CurveEq::BandParameter::Gain, index, gain);
}



broadcasterValue->setProperty("Frequency", freq);
broadcasterValue->setProperty("Gain", gain);
parent.eq->sendBroadcasterMessage("BandMoved", broadcasterValue);
}

void FilterDragOverlay::FilterDragComponent::mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &d)
{
if (parent.eq == nullptr)
return;

auto* broadcasterValue = new DynamicObject();
broadcasterValue->setProperty("Index", index);

if (e.mods.isCtrlDown() || parent.isInFloatingTile)
{
Expand All @@ -1099,15 +1118,15 @@ void FilterDragOverlay::FilterDragComponent::mouseWheelMove(const MouseEvent &e,
q = jlimit(0.1, 8.0, q * amp);

parent.setEqAttribute(CurveEq::BandParameter::Q, index, q);
broadcasterValue->setProperty("Q", q);
parent.eq->sendBroadcasterMessage("QChanged", broadcasterValue);
}
else
{
getParentComponent()->mouseWheelMove(e, d);
}
}



void FilterDragOverlay::FilterDragComponent::mouseDoubleClick(const MouseEvent& e)
{
if (parent.eq == nullptr)
Expand Down Expand Up @@ -1148,12 +1167,24 @@ void FilterDragOverlay::FilterDragComponent::setConstrainer(ComponentBoundsConst
void FilterDragOverlay::FilterDragComponent::mouseEnter(const MouseEvent& e)
{
over = true;

auto* broadcasterValue = new DynamicObject();
broadcasterValue->setProperty("Index", index);
broadcasterValue->setProperty("Over", true);
parent.eq->sendBroadcasterMessage("MouseOver", broadcasterValue);

parent.repaint();
}

void FilterDragOverlay::FilterDragComponent::mouseExit(const MouseEvent& e)
{
over = false;

auto* broadcasterValue = new DynamicObject();
broadcasterValue->setProperty("Index", index);
broadcasterValue->setProperty("Over", false);
parent.eq->sendBroadcasterMessage("MouseOver", broadcasterValue);

parent.repaint();
}

Expand Down
3 changes: 3 additions & 0 deletions hi_core/hi_components/audio_components/EqComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class FilterDragOverlay : public Component,

void setResetOnDoubleClick(bool shouldReset) { resetOnDoubleClick = shouldReset; }

void setHandleSize(int newSize) { handleSize = newSize; }

void setAllowContextMenu(bool shouldAllow)
{
allowContextMenu = shouldAllow;
Expand Down Expand Up @@ -250,6 +252,7 @@ class FilterDragOverlay : public Component,

bool allowContextMenu = true;
double gainRange = 24.0;
int handleSize = 24;

bool resetOnDoubleClick = false;
bool allowFilterResizing = true;
Expand Down
2 changes: 1 addition & 1 deletion hi_scripting/scripting/api/ScriptBroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4375,7 +4375,7 @@ void ScriptBroadcaster::attachToEqEvents(var moduleIds, var events, var optional
}

StringArray eventTypes;
StringArray legitEventTypes = { "BandAdded", "BandRemoved", "BandSelected", "FFTEnabled" };
StringArray legitEventTypes = { "BandAdded", "BandRemoved", "BandSelected", "BandMoved", "QChanged", "MouseOver", "FFTEnabled" };

if (events.isString() && events.toString().isNotEmpty())
{
Expand Down
4 changes: 2 additions & 2 deletions tools/json_dialog/broadcaster/broadcaster.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@
"ID": "eqEventTypes",
"EmptyText": "Enter event types (BandAdded, BandRemoved, etc)...",
"Required": true,
"Items": "BandAdded\nBandRemoved\nBandSelected\nFFTEnabled",
"Help": "Set the event type that the broadcaster should react too. This can be multiple items from this list:\n\n- `BandAdded`\n- `BandRemoved`\n- `BandSelected`\n- `FFTEnabled`",
"Items": "BandAdded\nBandRemoved\nBandSelected\nBandMoved\nQChanged\nMouseOver\nFFTEnabled",
"Help": "Set the event type that the broadcaster should react too. This can be multiple items from this list:\n\n- `BandAdded`\n- `BandRemoved`\n- `BandSelected`\n- `BandMoved`\n- `QChanged`\n- `MouseOver`\n- `FFTEnabled`",
"UseInitValue": "",
"Height": 80,
"ParseArray": true
Expand Down