Skip to content

Commit

Permalink
Merge pull request #1 from woodybury/get-model-ir-links
Browse files Browse the repository at this point in the history
get models and irs buttons with dymanic clear button
  • Loading branch information
woodybury authored Jan 7, 2025
2 parents 6229d68 + 03f13bc commit 67c40bb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 12 deletions.
14 changes: 9 additions & 5 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)

const auto gearSVG = pGraphics->LoadSVG(GEAR_FN);
const auto fileSVG = pGraphics->LoadSVG(FILE_FN);
const auto globeSVG = pGraphics->LoadSVG(GLOBE_ICON_FN);
const auto crossSVG = pGraphics->LoadSVG(CLOSE_BUTTON_FN);
const auto rightArrowSVG = pGraphics->LoadSVG(RIGHT_ARROW_FN);
const auto leftArrowSVG = pGraphics->LoadSVG(LEFT_ARROW_FN);
Expand Down Expand Up @@ -224,14 +225,17 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
const std::string defaultNamFileString = "Select model...";
const std::string defaultIRString = "Select IR...";
#endif
pGraphics->AttachControl(new NAMFileBrowserControl(modelArea, kMsgTagClearModel, defaultNamFileString.c_str(),
"nam", loadModelCompletionHandler, style, fileSVG, crossSVG,
leftArrowSVG, rightArrowSVG, fileBackgroundBitmap),
kCtrlTagModelFileBrowser);
pGraphics->AttachControl(
new NAMFileBrowserControl(modelArea, kMsgTagClearModel, defaultNamFileString.c_str(), "nam",
loadModelCompletionHandler, style, fileSVG, crossSVG, leftArrowSVG, rightArrowSVG,
fileBackgroundBitmap, globeSVG, "Get NAM Models",
"https://tonehunt.org/popular?tags%5B0%5D=nam"),
kCtrlTagModelFileBrowser);
pGraphics->AttachControl(new ISVGSwitchControl(irSwitchArea, {irIconOffSVG, irIconOnSVG}, kIRToggle));
pGraphics->AttachControl(
new NAMFileBrowserControl(irArea, kMsgTagClearIR, defaultIRString.c_str(), "wav", loadIRCompletionHandler, style,
fileSVG, crossSVG, leftArrowSVG, rightArrowSVG, fileBackgroundBitmap),
fileSVG, crossSVG, leftArrowSVG, rightArrowSVG, fileBackgroundBitmap, globeSVG,
"Get IRs", "https://tonehunt.org/popular?filter=ir"),
kCtrlTagIRFileBrowser);
pGraphics->AttachControl(
new NAMSwitchControl(ngToggleArea, kNoiseGateActive, "Noise Gate", style, switchHandleBitmap));
Expand Down
77 changes: 70 additions & 7 deletions NeuralAmpModeler/NeuralAmpModelerControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
using namespace iplug;
using namespace igraphics;

enum class NAMBrowserState
{
Empty, // when no file loaded, show "Get" button
Loaded // when ile loaded, show "Clear" button
};

// Where the corner button on the plugin (settings, close settings) goes
// :param rect: Rect for the whole plugin's UI
IRECT CornerButtonArea(const IRECT& rect)
Expand Down Expand Up @@ -209,12 +215,30 @@ class NAMFileNameControl : public IVButtonControl
}
};

// URL control for the "Get" models/irs links
class NAMGetButtonControl : public NAMSquareButtonControl
{
public:
NAMGetButtonControl(const IRECT& bounds, const char* label, const char* url, const ISVG& globeSVG)
: NAMSquareButtonControl(
bounds,
[url](IControl* pCaller) {
WDL_String fullURL(url);
pCaller->GetUI()->OpenURL(fullURL.Get());
},
globeSVG)
{
SetTooltip(label);
}
};

class NAMFileBrowserControl : public IDirBrowseControlBase
{
public:
NAMFileBrowserControl(const IRECT& bounds, int clearMsgTag, const char* labelStr, const char* fileExtension,
IFileDialogCompletionHandlerFunc ch, const IVStyle& style, const ISVG& loadSVG,
const ISVG& clearSVG, const ISVG& leftSVG, const ISVG& rightSVG, const IBitmap& bitmap)
const ISVG& clearSVG, const ISVG& leftSVG, const ISVG& rightSVG, const IBitmap& bitmap,
const ISVG& globeSVG, const char* getButtonLabel, const char* getButtonURL)
: IDirBrowseControlBase(bounds, fileExtension, false, false)
, mClearMsgTag(clearMsgTag)
, mDefaultLabelStr(labelStr)
Expand All @@ -225,6 +249,10 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
, mClearSVG(clearSVG)
, mLeftSVG(leftSVG)
, mRightSVG(rightSVG)
, mGlobeSVG(globeSVG)
, mGetButtonLabel(getButtonLabel)
, mGetButtonURL(getButtonURL)
, mBrowserState(NAMBrowserState::Empty)
{
mIgnoreMouse = true;
}
Expand Down Expand Up @@ -304,6 +332,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
auto clearFileFunc = [&](IControl* pCaller) {
pCaller->GetDelegate()->SendArbitraryMsgFromUI(mClearMsgTag);
mFileNameControl->SetLabelAndTooltip(mDefaultLabelStr.Get());
SetBrowserState(NAMBrowserState::Empty);
// FIXME disabling output mode...
// pCaller->GetUI()->GetControlWithTag(kCtrlTagOutputMode)->SetDisabled(false);
};
Expand All @@ -328,7 +357,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
IRECT padded = mRECT.GetPadded(-6.f).GetHPadded(-2.f);
const auto buttonWidth = padded.H();
const auto loadFileButtonBounds = padded.ReduceFromLeft(buttonWidth);
const auto clearButtonBounds = padded.ReduceFromRight(buttonWidth);
const auto clearAndGetButtonBounds = padded.ReduceFromRight(buttonWidth);
const auto leftButtonBounds = padded.ReduceFromLeft(buttonWidth);
const auto rightButtonBounds = padded.ReduceFromLeft(buttonWidth);
const auto fileNameButtonBounds = padded;
Expand All @@ -341,10 +370,17 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
->SetAnimationEndActionFunction(nextFileFunc);
AddChildControl(mFileNameControl = new NAMFileNameControl(fileNameButtonBounds, mDefaultLabelStr.Get(), mStyle))
->SetAnimationEndActionFunction(chooseFileFunc);
AddChildControl(new NAMSquareButtonControl(clearButtonBounds, DefaultClickActionFunc, mClearSVG))
->SetAnimationEndActionFunction(clearFileFunc);

mFileNameControl->SetLabelAndTooltip(mDefaultLabelStr.Get());
// creates both right-side controls but only show one based on state
mClearButton = new NAMSquareButtonControl(clearAndGetButtonBounds, DefaultClickActionFunc, mClearSVG);
mClearButton->SetAnimationEndActionFunction(clearFileFunc);
AddChildControl(mClearButton);

mGetButton = new NAMGetButtonControl(clearAndGetButtonBounds, mGetButtonLabel, mGetButtonURL, mGlobeSVG);
AddChildControl(mGetButton);

// initialize control visibility
SetBrowserState(NAMBrowserState::Empty);
}

void LoadFileAtCurrentIndex()
Expand All @@ -367,6 +403,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
{
std::string label(std::string("(FAILED) ") + std::string(mFileNameControl->GetLabelStr()));
mFileNameControl->SetLabelAndTooltip(label.c_str());
SetBrowserState(NAMBrowserState::Empty);
}
break;
case kMsgTagLoadedModel:
Expand All @@ -382,8 +419,9 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
SetupMenu();
SetSelectedFile(fileName.Get());
mFileNameControl->SetLabelAndTooltipEllipsizing(fileName);
break;
SetBrowserState(NAMBrowserState::Loaded);
}
break;
default: break;
}
}
Expand All @@ -398,13 +436,38 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
return;
}

// set the state of the browser and the visibility of the "Get" vs. "Clear" buttons
void SetBrowserState(NAMBrowserState newState)
{
mBrowserState = newState;

switch (mBrowserState)
{
case NAMBrowserState::Empty:
mClearButton->Hide(true);
mGetButton->Hide(false);
break;
case NAMBrowserState::Loaded:
mClearButton->Hide(false);
mGetButton->Hide(true);
break;
}
}

WDL_String mDefaultLabelStr;
IFileDialogCompletionHandlerFunc mCompletionHandlerFunc;
NAMFileNameControl* mFileNameControl = nullptr;
IVStyle mStyle;
IBitmap mBitmap;
ISVG mLoadSVG, mClearSVG, mLeftSVG, mRightSVG;
ISVG mLoadSVG, mClearSVG, mLeftSVG, mRightSVG, mGlobeSVG;
int mClearMsgTag;

// new members for the "Get" button
const char* mGetButtonLabel;
const char* mGetButtonURL;
NAMBrowserState mBrowserState;
NAMSquareButtonControl* mClearButton = nullptr;
NAMGetButtonControl* mGetButton = nullptr;
};

class NAMMeterControl : public IVPeakAvgMeterControl<>, public IBitmapBase
Expand Down
1 change: 1 addition & 0 deletions NeuralAmpModeler/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define MODEL_ICON_FN "ModelIcon.svg"
#define IR_ICON_ON_FN "IRIconOn.svg"
#define IR_ICON_OFF_FN "IRIconOff.svg"
#define GLOBE_ICON_FN "Globe.svg"

#define BACKGROUND_FN "Background.jpg"
#define BACKGROUND2X_FN "[email protected]"
Expand Down
5 changes: 5 additions & 0 deletions NeuralAmpModeler/resources/img/Globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 67c40bb

Please sign in to comment.