From a70488e38ea6159496d7e6f15386247779d695f7 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 9 Jun 2021 16:05:03 +0100 Subject: [PATCH] MacOS: Fix API deprecations in macOS 12.0 and iOS 15.0 --- .../native/juce_mac_CoreAudio.cpp | 58 ++++++++++++------- .../juce_core/native/juce_mac_SystemStats.mm | 15 +++-- .../native/juce_win32_SystemStats.cpp | 1 + modules/juce_core/system/juce_SystemStats.h | 1 + .../messages/juce_ApplicationBase.cpp | 2 +- .../native/juce_ios_FileChooser.mm | 2 +- .../native/juce_ios_UIViewComponentPeer.mm | 6 +- .../native/juce_mac_FileChooser.mm | 2 + .../native/juce_mac_NSViewComponentPeer.mm | 9 ++- .../native/juce_mac_AppleRemote.mm | 9 ++- 10 files changed, 73 insertions(+), 32 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp index 8c3c4bc8d1..402400b0b0 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp @@ -31,6 +31,13 @@ namespace juce JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wnonnull") +constexpr auto juceAudioObjectPropertyElementMain = + #if defined (MAC_OS_VERSION_12_0) + kAudioObjectPropertyElementMain; + #else + kAudioObjectPropertyElementMaster; + #endif + //============================================================================== struct SystemVol { @@ -38,7 +45,7 @@ struct SystemVol : outputDeviceID (kAudioObjectUnknown) { addr.mScope = kAudioObjectPropertyScopeGlobal; - addr.mElement = kAudioObjectPropertyElementMaster; + addr.mElement = juceAudioObjectPropertyElementMain; addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice; if (AudioObjectHasProperty (kAudioObjectSystemObject, &addr)) @@ -48,7 +55,7 @@ struct SystemVol if (status == noErr) { - addr.mElement = kAudioObjectPropertyElementMaster; + addr.mElement = juceAudioObjectPropertyElementMain; addr.mSelector = selector; addr.mScope = kAudioDevicePropertyScopeOutput; @@ -123,9 +130,16 @@ private: JUCE_END_IGNORE_WARNINGS_GCC_LIKE +constexpr auto juceAudioHardwareServiceDeviceProperty_VirtualMainVolume = + #if defined (MAC_OS_VERSION_12_0) + kAudioHardwareServiceDeviceProperty_VirtualMainVolume; + #else + kAudioHardwareServiceDeviceProperty_VirtualMasterVolume; + #endif + #define JUCE_SYSTEMAUDIOVOL_IMPLEMENTED 1 -float JUCE_CALLTYPE SystemAudioVolume::getGain() { return SystemVol (kAudioHardwareServiceDeviceProperty_VirtualMasterVolume).getGain(); } -bool JUCE_CALLTYPE SystemAudioVolume::setGain (float gain) { return SystemVol (kAudioHardwareServiceDeviceProperty_VirtualMasterVolume).setGain (gain); } +float JUCE_CALLTYPE SystemAudioVolume::getGain() { return SystemVol (juceAudioHardwareServiceDeviceProperty_VirtualMainVolume).getGain(); } +bool JUCE_CALLTYPE SystemAudioVolume::setGain (float gain) { return SystemVol (juceAudioHardwareServiceDeviceProperty_VirtualMainVolume).setGain (gain); } bool JUCE_CALLTYPE SystemAudioVolume::isMuted() { return SystemVol (kAudioDevicePropertyMute).isMuted(); } bool JUCE_CALLTYPE SystemAudioVolume::setMuted (bool mute) { return SystemVol (kAudioDevicePropertyMute).setMuted (mute); } @@ -204,7 +218,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyStreamConfiguration; pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, nullptr, &size))) { @@ -259,7 +273,7 @@ public: AudioObjectPropertyAddress pa; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates; UInt32 size = 0; @@ -300,7 +314,7 @@ public: AudioObjectPropertyAddress pa; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange; UInt32 size = 0; @@ -341,7 +355,7 @@ public: UInt32 latency = 0; UInt32 size = sizeof (latency); AudioObjectPropertyAddress pa; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioDevicePropertyLatency; pa.mScope = scope; AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &latency); @@ -357,7 +371,7 @@ public: int getBitDepthFromDevice (AudioObjectPropertyScope scope) const { AudioObjectPropertyAddress pa; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioStreamPropertyPhysicalFormat; pa.mScope = scope; @@ -374,7 +388,7 @@ public: { AudioObjectPropertyAddress pa; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioDevicePropertyBufferFrameSize; UInt32 framesPerBuf = (UInt32) bufferSize; @@ -387,7 +401,7 @@ public: { AudioObjectPropertyAddress pa; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; pa.mSelector = kAudioDevicePropertyDeviceIsAlive; UInt32 isAlive = 0; @@ -503,7 +517,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyDataSourceNameForID; pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &transSize, &avt))) s.add (buffer); @@ -521,7 +535,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyDataSource; pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (deviceID != 0) { @@ -556,7 +570,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyDataSource; pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; OSType typeId = types[index]; @@ -570,7 +584,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyNominalSampleRate; pa.mScope = kAudioObjectPropertyScopeGlobal; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; Float64 sr = 0; UInt32 size = (UInt32) sizeof (sr); return OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &sr)) ? (double) sr : 0.0; @@ -584,7 +598,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyNominalSampleRate; pa.mScope = kAudioObjectPropertyScopeGlobal; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; Float64 sr = newSampleRate; return OK (AudioObjectSetPropertyData (deviceID, &pa, 0, nullptr, sizeof (sr), &sr)); } @@ -626,7 +640,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyBufferFrameSize; pa.mScope = kAudioObjectPropertyScopeGlobal; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; UInt32 framesPerBuf = (UInt32) bufferSizeSamples; if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, nullptr, sizeof (framesPerBuf), &framesPerBuf))) @@ -715,7 +729,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyDeviceIsRunning; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &running)); @@ -893,7 +907,7 @@ private: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyDataSources; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; UInt32 size = 0; if (deviceID != 0 @@ -2040,7 +2054,7 @@ public: AudioObjectPropertyAddress pa; pa.mSelector = kAudioHardwarePropertyDevices; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, nullptr, &size) == noErr) { @@ -2105,7 +2119,7 @@ public: pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice; pa.mScope = kAudioObjectPropertyScopeWildcard; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, nullptr, &size, &deviceID) == noErr) { @@ -2213,7 +2227,7 @@ private: AudioObjectPropertyAddress pa; pa.mSelector = kAudioDevicePropertyStreamConfiguration; pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; - pa.mElement = kAudioObjectPropertyElementMaster; + pa.mElement = juceAudioObjectPropertyElementMain; if (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, nullptr, &size) == noErr) { diff --git a/modules/juce_core/native/juce_mac_SystemStats.mm b/modules/juce_core/native/juce_mac_SystemStats.mm index 96341c3a59..1420e7a480 100644 --- a/modules/juce_core/native/juce_mac_SystemStats.mm +++ b/modules/juce_core/native/juce_mac_SystemStats.mm @@ -119,14 +119,19 @@ SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() const auto major = parts[0].getIntValue(); const auto minor = parts[1].getIntValue(); - if (major == 10) + switch (major) { - jassert (minor > 2); - return (OperatingSystemType) (minor + MacOSX_10_7 - 7); + case 10: + { + jassert (minor > 2); + return (OperatingSystemType) (minor + MacOSX_10_7 - 7); + } + + case 11: return MacOS_11; + case 12: return MacOS_12; } - jassert (major == 11); - return MacOS_11; + return UnknownOS; #endif } diff --git a/modules/juce_core/native/juce_win32_SystemStats.cpp b/modules/juce_core/native/juce_win32_SystemStats.cpp index 3a8c969928..2546db2429 100644 --- a/modules/juce_core/native/juce_win32_SystemStats.cpp +++ b/modules/juce_core/native/juce_win32_SystemStats.cpp @@ -292,6 +292,7 @@ String SystemStats::getOperatingSystemName() case MacOSX_10_14: JUCE_FALLTHROUGH case MacOSX_10_15: JUCE_FALLTHROUGH case MacOS_11: JUCE_FALLTHROUGH + case MacOS_12: JUCE_FALLTHROUGH case UnknownOS: JUCE_FALLTHROUGH case WASM: JUCE_FALLTHROUGH diff --git a/modules/juce_core/system/juce_SystemStats.h b/modules/juce_core/system/juce_SystemStats.h index d42a185c3e..788802f028 100644 --- a/modules/juce_core/system/juce_SystemStats.h +++ b/modules/juce_core/system/juce_SystemStats.h @@ -63,6 +63,7 @@ public: MacOSX_10_14 = MacOSX | 14, MacOSX_10_15 = MacOSX | 15, MacOS_11 = MacOSX | 16, + MacOS_12 = MacOSX | 17, Win2000 = Windows | 1, WinXP = Windows | 2, diff --git a/modules/juce_events/messages/juce_ApplicationBase.cpp b/modules/juce_events/messages/juce_ApplicationBase.cpp index d1936b0f83..6e6bc09ca4 100644 --- a/modules/juce_events/messages/juce_ApplicationBase.cpp +++ b/modules/juce_events/messages/juce_ApplicationBase.cpp @@ -201,7 +201,7 @@ String JUCEApplicationBase::getCommandLineParameters() for (int i = 1; i < juce_argc; ++i) { - String arg (juce_argv[i]); + String arg { CharPointer_UTF8 (juce_argv[i]) }; if (arg.containsChar (' ') && ! arg.isQuotedString()) arg = arg.quoted ('"'); diff --git a/modules/juce_gui_basics/native/juce_ios_FileChooser.mm b/modules/juce_gui_basics/native/juce_ios_FileChooser.mm index 3d8d00c3f6..c89117abf8 100644 --- a/modules/juce_gui_basics/native/juce_ios_FileChooser.mm +++ b/modules/juce_gui_basics/native/juce_ios_FileChooser.mm @@ -26,7 +26,7 @@ namespace juce { -#if ! (defined (__IPHONE_15_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_15_0) +#if ! (defined (__IPHONE_16_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_16_0) JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") #define JUCE_DEPRECATION_IGNORED 1 #endif diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index 4d2c0d1b54..adc0479fc9 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -39,7 +39,11 @@ static UIInterfaceOrientation getWindowOrientation() UIApplication* sharedApplication = [UIApplication sharedApplication]; #if (defined (__IPHONE_13_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_13_0) - return [[[[sharedApplication windows] firstObject] windowScene] interfaceOrientation]; + for (UIScene* scene in [sharedApplication connectedScenes]) + if ([scene isKindOfClass: [UIWindowScene class]]) + return [(UIWindowScene*) scene interfaceOrientation]; + + return UIInterfaceOrientationPortrait; #else return [sharedApplication statusBarOrientation]; #endif diff --git a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm index 61febe1b1d..fde66668d8 100644 --- a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm +++ b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm @@ -83,7 +83,9 @@ public: filters.removeEmptyStrings(); [panel setTitle: juceStringToNS (owner.title)]; + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations") [panel setAllowedFileTypes: createAllowedTypesArray (filters)]; + JUCE_END_IGNORE_WARNINGS_GCC_LIKE if (! isSave) { diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 87fc0bb7d5..2b5018be46 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -1309,7 +1309,14 @@ public: static NSArray* getSupportedDragTypes() { - return [NSArray arrayWithObjects: (NSString*) kUTTypeFileURL, (NSString*) kPasteboardTypeFileURLPromise, NSPasteboardTypeString, nil]; + const auto type = + #if defined (MAC_OS_X_VERSION_10_13) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_13 + NSPasteboardTypeFileURL; + #else + kUTTypeFileURL; + #endif + + return [NSArray arrayWithObjects: (NSString*) type, (NSString*) kPasteboardTypeFileURLPromise, NSPasteboardTypeString, nil]; } BOOL sendDragCallback (const int type, id sender) diff --git a/modules/juce_gui_extra/native/juce_mac_AppleRemote.mm b/modules/juce_gui_extra/native/juce_mac_AppleRemote.mm index 812c2902be..ec8d5d8e37 100644 --- a/modules/juce_gui_extra/native/juce_mac_AppleRemote.mm +++ b/modules/juce_gui_extra/native/juce_mac_AppleRemote.mm @@ -47,7 +47,14 @@ namespace io_iterator_t iter = 0; io_object_t iod = 0; - if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess + const auto defaultPort = + #if defined (MAC_OS_VERSION_12_0) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_12_0 + kIOMainPortDefault; + #else + kIOMasterPortDefault; + #endif + + if (IOServiceGetMatchingServices (defaultPort, dict, &iter) == kIOReturnSuccess && iter != 0) { iod = IOIteratorNext (iter);