Skip to content

Commit

Permalink
Bugfix/1460 (#3201)
Browse files Browse the repository at this point in the history
Closes #1460
  • Loading branch information
Mikko Saarinki authored Nov 23, 2020
1 parent 196e811 commit 8369a6f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ struct DAWExtraStateStorage
int current_osc[n_scenes] = {0};
modsources modsource = ms_lfo1, modsource_editor[n_scenes] = {ms_lfo1, ms_lfo1};
bool isMSEGOpen = false;
float scaleFactorOnClose = 1;
} editor;


Expand Down
17 changes: 15 additions & 2 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct RememberForgetGuard {
T *t = nullptr;
};

DEF_CLASS_IID(IPlugViewContentScaleSupport);

#endif

#if TARGET_AUDIOUNIT
Expand Down Expand Up @@ -5828,8 +5830,19 @@ VSTGUI::CCommandMenuItem* SurgeGUIEditor::addCallbackMenu(VSTGUI::COptionMenu* t
#if TARGET_VST3
Steinberg::tresult PLUGIN_API SurgeGUIEditor::onSize(Steinberg::ViewRect* newSize)
{
float izfx = newSize->getWidth() * 1.0 / getWindowSizeX() * 100.0;
float izfy = newSize->getHeight() * 1.0 / getWindowSizeY() * 100.0;
Steinberg::ViewRect currentSize = *newSize;

// Cubase sets wrong newSize when reopening editor. See #1460
auto scaleFactorOnClose = synth->storage.getPatch().dawExtraState.editor.scaleFactorOnClose;
if (scaleFactorOnClose > 1)
{
currentSize.bottom *= scaleFactorOnClose;
currentSize.right *= scaleFactorOnClose;
synth->storage.getPatch().dawExtraState.editor.scaleFactorOnClose = 1; // Don't rescale infinitely
}

float izfx = currentSize.getWidth() * 1.0 / getWindowSizeX() * 100.0;
float izfy = currentSize.getHeight() * 1.0 / getWindowSizeY() * 100.0;
float izf = std::min(izfx, izfy);
izf = std::max(izf, 1.0f*minimumZoom);

Expand Down
23 changes: 22 additions & 1 deletion src/common/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
typedef VSTGUI::PluginGUIEditor EditorType;
#elif TARGET_VST3
#include "public.sdk/source/vst/vstguieditor.h"
#include "pluginterfaces/gui/iplugviewcontentscalesupport.h"
typedef Steinberg::Vst::VSTGUIEditor EditorType;
#define PARENT_PLUGIN_TYPE SurgeVst3Processor
#elif TARGET_VST2
Expand Down Expand Up @@ -73,6 +74,9 @@ struct SGEDropAdapter;
class SurgeGUIEditor : public EditorType,
public VSTGUI::IControlListener,
public VSTGUI::IKeyboardHook
#if TARGET_VST3
, public Steinberg::IPlugViewContentScaleSupport
#endif
{
private:
using super = EditorType;
Expand Down Expand Up @@ -126,6 +130,12 @@ class SurgeGUIEditor : public EditorType,

virtual Steinberg::tresult PLUGIN_API onSize(Steinberg::ViewRect* newSize) override;
virtual Steinberg::tresult PLUGIN_API checkSizeConstraint(Steinberg::ViewRect* newSize) override;
virtual Steinberg::tresult PLUGIN_API setContentScaleFactor(ScaleFactor factor) override
{
scaleFactor = factor;
return Steinberg::kResultTrue;
}

#endif


Expand Down Expand Up @@ -201,7 +211,8 @@ class SurgeGUIEditor : public EditorType,
** and double size is "200"
*/

int zoomFactor;
int zoomFactor = 100;
float scaleFactor = 1;
bool zoomEnabled = true;

int patchCountdown = -1;
Expand All @@ -213,6 +224,7 @@ class SurgeGUIEditor : public EditorType,

des->isPopulated = true;
des->editor.instanceZoomFactor = zoomFactor;
des->editor.scaleFactorOnClose = scaleFactor;
des->editor.current_scene = current_scene;
des->editor.current_fx = current_fx;
des->editor.modsource = modsource;
Expand Down Expand Up @@ -492,6 +504,15 @@ class SurgeGUIEditor : public EditorType,
std::string fullyResolvedHelpURL( std::string helpurl );

private:

#if TARGET_VST3
OBJ_METHODS(SurgeGUIEditor, EditorType)
DEFINE_INTERFACES
DEF_INTERFACE(Steinberg::IPlugViewContentScaleSupport)
END_DEFINE_INTERFACES(EditorType)
REFCOUNT_METHODS(EditorType)
#endif

void promptForUserValueEntry(Parameter *p, VSTGUI::CControl *c, int modulationSource = -1);

/*
Expand Down
10 changes: 5 additions & 5 deletions src/vst3/SurgeVst3Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ using namespace Steinberg::Vst;
return 0; \
}

SurgeVst3Processor::SurgeVst3Processor() : blockpos(0), surgeInstance()
SurgeVst3Processor::SurgeVst3Processor() : surgeInstance()
{
checkNamesEvery = 0;
}

SurgeVst3Processor::~SurgeVst3Processor()
Expand Down Expand Up @@ -996,7 +995,7 @@ void SurgeVst3Processor::handleZoom(SurgeGUIEditor *e)
frame->setSize(newW, newH);
/*
** rather than calling setSize on myself as in vst2, I have to
** inform the plugin frame that I have resized wiht a reference
** inform the plugin frame that I have resized with a reference
** to a view (which is the editor). This collaborates with
** the host to resize once the content is scaled
*/
Expand All @@ -1007,12 +1006,13 @@ void SurgeVst3Processor::handleZoom(SurgeGUIEditor *e)
Steinberg::tresult res = ipf->resizeView(e, &vr);
if (res != Steinberg::kResultTrue)
{
std::ostringstream oss;
// Leaving this here for debug purposes. resizeView() can fail in non-fatal way and zoom reset is just too harsh.
/*std::ostringstream oss;
oss << "Your host failed to zoom VST3 to " << e->getZoomFactor() << " scale. "
<< "Surge will now attempt to reset the zoom level to 100%. You may see several "
<< "other error messages in the course of this being resolved.";
Surge::UserInteractions::promptError(oss.str(), "VST3 Host Zoom Error" );
e->setZoomFactor(100);
e->setZoomFactor(100);*/
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vst3/SurgeVst3Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class SurgeVst3Processor : public Steinberg::Vst::SingleComponentEffect,
std::unique_ptr<SurgeSynthesizer> surgeInstance;
std::set<SurgeGUIEditor*> viewsSet;
std::map<int, int> beginEditGuard;
int blockpos;
int blockpos = 0;

bool disableZoom;
bool disableZoom = false;
bool haveZoomed = false;
int lastZoom = -1;
void handleZoom(SurgeGUIEditor *e);
Expand Down

0 comments on commit 8369a6f

Please sign in to comment.