Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS GetResourcePathFromBundle should get path from extension subfolder #1001

Open
Youlean opened this issue Aug 15, 2023 · 5 comments
Open

Comments

@Youlean
Copy link
Contributor

Youlean commented Aug 15, 2023

pBasePath = [[[[pBundle bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingString:@"/Resources/"];

isAppExtension could be disabled as if you load iOS plugin on macOS it will crash the host as it can't load the resources.
Or this should be changed somehow:

CFLocal<CGDataProviderRef> provider(url.Get() ? CGDataProviderCreateWithURL(url.Get()) : nullptr); // CGDataProviderCreateWithURL will fail in macOS sandbox!

@olilarkin
Copy link
Member

olilarkin commented Aug 15, 2023

PRs welcome.

This stuff is a PITA. Are you trying to compile your iOS app with Catalyst?

@Youlean
Copy link
Contributor Author

Youlean commented Aug 15, 2023

I have fixed some stuff and made it work for my iOS loudness meter lite.

Screenshot 2023-08-15 at 18 32 11

It took me a couple of days to figure what is going on.

This might also help you:

 /*
 ==============================================================================
 
 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers. 
 
 See LICENSE.txt for  more info.
 
 ==============================================================================
*/

#import <CoreAudioKit/AUViewController.h>
#import "IPlugAUAudioUnit.h"
#import "IPlugAUViewController.h"
#include "IPlugPlatform.h"
#include "IPlugLogger.h"

#ifdef OS_IOS
#import "GenericUI.h"
#endif

#if !__has_feature(objc_arc)
#error This file must be compiled with Arc. Use -fobjc-arc flag
#endif

@interface IPlugAUViewController (AUAudioUnitFactory)
@end

#ifdef OS_IOS
#pragma mark - iOS
@implementation IPlugAUViewController

- (AUAudioUnit*) createAudioUnitWithComponentDescription:(AudioComponentDescription) desc error:(NSError **)error
{
  self.audioUnit = [[IPlugAUAudioUnit alloc] initWithComponentDescription:desc error:error];

  dispatch_async(dispatch_get_main_queue(), ^{
    
  // Open window if it is not alredy opened  
  if (![self.audioUnit isWindowOpen])
  {
    [self.audioUnit openWindow:self.view];
  }
    
  });
  
  [self audioUnitInitialized];
  
  return self.audioUnit;
}

#if PLUG_HAS_UI
- (void)viewWillLayoutSubviews
{
  if (self.audioUnit)
  {
    CGRect drawableRect;
    drawableRect = self.view.bounds;
    
    [_audioUnit resize:drawableRect];
  }
  
  [super viewWillLayoutSubviews];
}

-(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
  [super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];
  
  if (self.audioUnit)
  {
    [coordinator animateAlongsideTransition: nil completion: ^void (id<UIViewControllerTransitionCoordinatorContext>)
     {
      [self.audioUnit layoutUI];
    }];
  }
}

- (void) viewDidLoad
{
  [super viewDidLoad];
}

- (void) viewWillAppear:(BOOL) animated
{
  [super viewWillAppear:animated];
  
  if (self.audioUnit)
  {
    [self.audioUnit openWindow:self.view];
  }
}

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
  [super viewWillDisappear:animated];
}

- (void) viewDidDisappear:(BOOL) animated
{
  [super viewDidDisappear:animated];
  
  if (self.audioUnit)
  {
    [self.audioUnit closeWindow];
  }
}

#endif

- (AUAudioUnit*) getAudioUnit
{
  return self.audioUnit;
}

- (void) audioUnitInitialized
{
  dispatch_async(dispatch_get_main_queue(), ^{
    if (self.audioUnit)
    {
      int width = (int) [self.audioUnit width];
      int height = (int) [self.audioUnit height];
      self.preferredContentSize = CGSizeMake(width, height);
      self.view.backgroundColor = UIColor.blackColor;
      
      [self.audioUnit SetIsHostApp: NO];
    }
  });
}

@end

#else // macOS
#pragma mark - macOS
@implementation IPlugAUViewController

- (id) init
{
  self = [super initWithNibName:@"IPlugAUViewController"
                         bundle:[NSBundle bundleForClass:NSClassFromString(@"IPlugAUViewController")]];

  return self;
}

- (AUAudioUnit*) createAudioUnitWithComponentDescription:(AudioComponentDescription) desc error:(NSError **)error
{
  self.audioUnit = [[IPlugAUAudioUnit alloc] initWithComponentDescription:desc error:error];

  return self.audioUnit;
}

- (AUAudioUnit*) getAudioUnit
{
  return self.audioUnit;
}

- (void) audioUnitInitialized
{
  dispatch_async(dispatch_get_main_queue(), ^{
    int viewWidth = (int) [self.audioUnit width];
    int viewHeight = (int) [self.audioUnit height];
    self.preferredContentSize = CGSizeMake (viewWidth, viewHeight);
  });
}

- (void) setAudioUnit:(IPlugAUAudioUnit*) audioUnit
{
  _audioUnit = audioUnit;
  [self audioUnitInitialized];
}

- (void) viewWillAppear
{
  [_audioUnit openWindow:self.view];
}
@end

#endif

@olilarkin
Copy link
Member

Thanks for the code but it's not clear how it relates to the issue?

@Youlean
Copy link
Contributor Author

Youlean commented Aug 15, 2023

sorry, it doesn't, but it is needed if you want to load iOS plugin on macOS

@AlexHarker
Copy link
Collaborator

GetResourcePathFromBundle() works on IOS, so can you clarify how it breaks when running the IOS plugin on macOS. I can see that we'd want to support it, but we'd want to make sure it works correctly on IOS and macOS - a PR that solves that issue would be very welcome.

Likewise - if you could make a separate issue for the loading stuff and at least a clear issue (and ideally a PR) that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants