Commit f9efc7cc authored by Cameron Armstrong (Nightfox)'s avatar Cameron Armstrong (Nightfox) Committed by Gargaj
Browse files

Ask the user for microphone access on startup if required

parent 550ad6fa
......@@ -332,7 +332,7 @@ if (APPLE)
${CMAKE_SOURCE_DIR}/src/platform_glfw/Renderer.cpp
${CMAKE_SOURCE_DIR}/src/platform_common/FFT.cpp
${CMAKE_SOURCE_DIR}/src/platform_x11/MIDI.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/Misc.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/Misc.mm
${CMAKE_SOURCE_DIR}/src/platform_x11/Timer.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/SetupDialog.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/Clipboard.cpp
......@@ -423,11 +423,11 @@ if (APPLE)
set(MACOSX_BUNDLE_BUNDLE_NAME ${BZC_EXE_NAME})
set(MACOSX_BUNDLE_GUI_IDENTIFIER "${BZC_EXE_NAME}")
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
set(MACOSX_BUNDLE_INFO_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH},Copyright © 2018 The Bonzomatic Contributors")
set(MACOSX_BUNDLE_INFO_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH},Copyright © 2019 The Bonzomatic Contributors")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2014-2018 The Bonzomatic Contributors. All rights reserved.")
set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2014-2019 The Bonzomatic Contributors. All rights reserved.")
set_source_files_properties(${BZC_RESOURCES_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
......@@ -440,8 +440,9 @@ if (APPLE)
find_library(OPENGL_FRAMEWORK OpenGL)
find_library(CARBON_FRAMEWORK Carbon)
find_library(COREAUDIO_FRAMEWORK CoreAudio)
mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK COREAUDIO_FRAMEWORK)
set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK} ${COREAUDIO_FRAMEWORK})
find_library(AVFOUNDATION_FRAMEWORK AVFoundation)
mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK COREAUDIO_FRAMEWORK AVFOUNDATION_FRAMEWORK)
set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK} ${COREAUDIO_FRAMEWORK} ${AVFOUNDATION_FRAMEWORK})
elseif (UNIX)
set(PLATFORM_LIBS GL)
elseif (WIN32)
......
......@@ -40,5 +40,7 @@
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.4</string>
<key>NSMicrophoneUsageDescription</key>
<string>Bonzomatic requires microphone access for the FFT textures to work.</string>
</dict>
</plist>
\ No newline at end of file
......@@ -7,7 +7,54 @@
#include <unistd.h>
#include <sys/param.h> // For MAXPATHLEN
#include "CoreFoundation/CoreFoundation.h"
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface MiscCocoa : NSObject
@end
@implementation MiscCocoa
+ (void)requestMicrophoneAccess {
switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio])
{
case AVAuthorizationStatusAuthorized:
{
fprintf(stdout, "Microphone access already granted\n");
break;
}
case AVAuthorizationStatusNotDetermined:
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
fprintf(stdout, "Microphone access granted\n");
} else {
fprintf(stderr, "Microphone access denied. No FFT support.\n");
}
}];
return;
}
case AVAuthorizationStatusDenied:
{
fprintf(stderr, "Microphone access previously denied by user. Asking again.\n");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
fprintf(stdout, "Microphone access granted\n");
} else {
fprintf(stderr, "Microphone access denied. No FFT support.\n");
}
}];
return;
}
case AVAuthorizationStatusRestricted:
{
fprintf(stderr, "The user can't grant microphone access due to restrictions.\n");
}
}
}
@end
void Misc::PlatformStartup()
{
......@@ -27,6 +74,11 @@ void Misc::PlatformStartup()
CFRelease(pathURL);
chdir(appPath);
// Check if the user has granted microphone access to Bonzomatic. Else request it.
if (@available(macOS 10.14, *)) {
[MiscCocoa requestMicrophoneAccess];
}
}
void Misc::PlatformShutdown()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment