diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 63f0f992160..3e86e6db1f5 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -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; diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index b62ba0b68cc..3ad62d33b81 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -95,6 +95,8 @@ struct RememberForgetGuard { T *t = nullptr; }; +DEF_CLASS_IID(IPlugViewContentScaleSupport); + #endif #if TARGET_AUDIOUNIT @@ -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); diff --git a/src/common/gui/SurgeGUIEditor.h b/src/common/gui/SurgeGUIEditor.h index ae2d77cc575..7eaefc57f62 100644 --- a/src/common/gui/SurgeGUIEditor.h +++ b/src/common/gui/SurgeGUIEditor.h @@ -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 @@ -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; @@ -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 @@ -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; @@ -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; @@ -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); /* diff --git a/src/vst3/SurgeVst3Processor.cpp b/src/vst3/SurgeVst3Processor.cpp index a9a80dbc8f0..8874c1dea08 100644 --- a/src/vst3/SurgeVst3Processor.cpp +++ b/src/vst3/SurgeVst3Processor.cpp @@ -34,9 +34,8 @@ using namespace Steinberg::Vst; return 0; \ } -SurgeVst3Processor::SurgeVst3Processor() : blockpos(0), surgeInstance() +SurgeVst3Processor::SurgeVst3Processor() : surgeInstance() { - checkNamesEvery = 0; } SurgeVst3Processor::~SurgeVst3Processor() @@ -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 */ @@ -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);*/ } } diff --git a/src/vst3/SurgeVst3Processor.h b/src/vst3/SurgeVst3Processor.h index 0a5a90caea5..a5ec8d4a0bd 100644 --- a/src/vst3/SurgeVst3Processor.h +++ b/src/vst3/SurgeVst3Processor.h @@ -127,9 +127,9 @@ class SurgeVst3Processor : public Steinberg::Vst::SingleComponentEffect, std::unique_ptr surgeInstance; std::set viewsSet; std::map beginEditGuard; - int blockpos; + int blockpos = 0; - bool disableZoom; + bool disableZoom = false; bool haveZoomed = false; int lastZoom = -1; void handleZoom(SurgeGUIEditor *e);