From 5e5bf35f3622ef1e25681ec6ceb24ae1b0df772e Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 30 Dec 2008 15:56:38 +0000 Subject: [PATCH] fix for win32 screen saver defeating, and a small tweak to VST hosting --- .../juce_win32_Windowing.cpp | 16 ++++------- juce_amalgamated.cpp | 28 +++++++++---------- .../plugins/formats/juce_VSTPluginFormat.cpp | 13 ++++++--- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/build/win32/platform_specific_code/juce_win32_Windowing.cpp b/build/win32/platform_specific_code/juce_win32_Windowing.cpp index bc2f7f1d18..637fdbf420 100644 --- a/build/win32/platform_specific_code/juce_win32_Windowing.cpp +++ b/build/win32/platform_specific_code/juce_win32_Windowing.cpp @@ -65,7 +65,6 @@ extern bool juce_IsRunningInWine() throw(); static HPALETTE palette = 0; static bool createPaletteIfNeeded = true; static bool shouldDeactivateTitleBar = true; -static bool screenSaverAllowed = true; static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw(); #define WM_TRAYNOTIFY WM_USER + 100 @@ -2183,13 +2182,6 @@ private: } break; - - case SC_MONITORPOWER: - case SC_SCREENSAVE: - if (! screenSaverAllowed) - return 0; - - break; } break; @@ -2317,14 +2309,18 @@ void Desktop::setMousePosition (int x, int y) throw() } //============================================================================== +static bool juce_screenSaverEnabled = true; + void Desktop::setScreenSaverEnabled (const bool isEnabled) throw() { - screenSaverAllowed = isEnabled; + juce_screenSaverEnabled = isEnabled; + SetThreadExecutionState (isEnabled ? (ES_DISPLAY_REQUIRED | ES_CONTINUOUS) + : ES_CONTINUOUS); } bool Desktop::isScreenSaverEnabled() throw() { - return screenSaverAllowed; + return juce_screenSaverEnabled; } //============================================================================== diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index eae06cfa09..8f13710c70 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -31725,6 +31725,10 @@ int VSTPluginInstance::dispatch (const int opcode, const int index, const int va } // handles non plugin-specific callbacks.. + +static const int defaultVSTSampleRateValue = 16384; +static const int defaultVSTBlockSizeValue = 512; + static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt) { (void) index; @@ -31775,10 +31779,10 @@ static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt3 break; case audioMasterGetSampleRate: - return 44100; + return (VstIntPtr) defaultVSTSampleRateValue; case audioMasterGetBlockSize: - return 512; + return (VstIntPtr) defaultVSTBlockSizeValue; case audioMasterSetOutputSampleRate: return 0; @@ -31857,10 +31861,10 @@ VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, Vs return 1; case audioMasterGetSampleRate: - return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : 44100); + return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue); case audioMasterGetBlockSize: - return (VstIntPtr) getBlockSize(); + return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue); case audioMasterWantMidi: wantsMidiMessages = true; @@ -241243,7 +241247,6 @@ extern bool juce_IsRunningInWine() throw(); static HPALETTE palette = 0; static bool createPaletteIfNeeded = true; static bool shouldDeactivateTitleBar = true; -static bool screenSaverAllowed = true; static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw(); #define WM_TRAYNOTIFY WM_USER + 100 @@ -243328,13 +243331,6 @@ private: } break; - - case SC_MONITORPOWER: - case SC_SCREENSAVE: - if (! screenSaverAllowed) - return 0; - - break; } break; @@ -243454,14 +243450,18 @@ void Desktop::setMousePosition (int x, int y) throw() SetCursorPos (x, y); } +static bool juce_screenSaverEnabled = true; + void Desktop::setScreenSaverEnabled (const bool isEnabled) throw() { - screenSaverAllowed = isEnabled; + juce_screenSaverEnabled = isEnabled; + SetThreadExecutionState (isEnabled ? (ES_DISPLAY_REQUIRED | ES_CONTINUOUS) + : ES_CONTINUOUS); } bool Desktop::isScreenSaverEnabled() throw() { - return screenSaverAllowed; + return juce_screenSaverEnabled; } void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable) diff --git a/src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp b/src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp index e5a8ea14fb..f2f9c0d86f 100644 --- a/src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp +++ b/src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp @@ -2305,6 +2305,11 @@ int VSTPluginInstance::dispatch (const int opcode, const int index, const int va //============================================================================== // handles non plugin-specific callbacks.. + +static const int defaultVSTSampleRateValue = 16384; +static const int defaultVSTBlockSizeValue = 512; + + static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt) { (void) index; @@ -2355,10 +2360,10 @@ static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt3 break; case audioMasterGetSampleRate: - return 44100; + return (VstIntPtr) defaultVSTSampleRateValue; case audioMasterGetBlockSize: - return 512; + return (VstIntPtr) defaultVSTBlockSizeValue; case audioMasterSetOutputSampleRate: return 0; @@ -2437,10 +2442,10 @@ VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, Vs return 1; case audioMasterGetSampleRate: - return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : 44100); + return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue); case audioMasterGetBlockSize: - return (VstIntPtr) getBlockSize(); + return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue); case audioMasterWantMidi: wantsMidiMessages = true;