diff --git a/src/detail/standalone/macos/AppDelegate.h b/src/detail/standalone/macos/AppDelegate.h index c27c4127..29efc515 100644 --- a/src/detail/standalone/macos/AppDelegate.h +++ b/src/detail/standalone/macos/AppDelegate.h @@ -6,7 +6,9 @@ { // AudioSettingsWindowDelegate *audioSettingsWindowDelegate; } -@property(assign) IBOutlet NSWindow *window; + +@property(assign) NSTimer* requestCallbackTimer; +@property(assign) IBOutlet NSWindow* window; - (IBAction)openAudioSettingsWindow:(id)sender; diff --git a/src/detail/standalone/macos/AppDelegate.mm b/src/detail/standalone/macos/AppDelegate.mm index d1040c69..d44313cf 100644 --- a/src/detail/standalone/macos/AppDelegate.mm +++ b/src/detail/standalone/macos/AppDelegate.mm @@ -27,6 +27,16 @@ - (void)resetSampleRateSelection; @implementation AppDelegate +- (void)timerCallback:(NSTimer *)instance +{ + auto *standaloneHost = freeaudio::clap_wrapper::standalone::getStandaloneHost(); + if (standaloneHost->callbackRequested.exchange(false)) + { + auto *plugin = freeaudio::clap_wrapper::standalone::getMainPlugin()->_plugin; + plugin->on_main_thread(plugin); + } +} + - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application @@ -61,7 +71,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { return; } - + self.requestCallbackTimer = [NSTimer timerWithTimeInterval:0.08 + target:self + selector:@selector(timerCallback:) + userInfo:nil + repeats:YES]; + auto *runLoop = [NSRunLoop currentRunLoop]; + [runLoop addTimer:self.requestCallbackTimer forMode:NSDefaultRunLoopMode]; std::string pid{PLUGIN_ID}; int pindex{PLUGIN_INDEX}; @@ -142,6 +158,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification [alert runModal]; } }; + freeaudio::clap_wrapper::standalone::mainStartAudio(); } @@ -164,8 +181,8 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification plugin->_ext._gui->destroy(plugin->_plugin); } - [[self window] setDelegate:nil]; - [[self window] release]; + [self.requestCallbackTimer invalidate]; + self.requestCallbackTimer = nil; freeaudio::clap_wrapper::standalone::mainFinish(); }