COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 08-13-2011, 11:15 AM   #1
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: UK
Posts: 1,163
Default ditching carbon

I have been experimenting with removing IGraphicsCarbon from IPlug and using a cocoa child window in carbon hosts (e.g. all 32bit vst hosts except reaper + some audiounit hosts).

The benefits are:

- more consistent text entry text rendering across hosts on osx
- better looking & much more flexible text entry via NSTextField
- less code to maintain in iPlug
- possibly easier window resizing
- nicer gui behaviour in non-composited carbon hosts (hopefully)

The downside is that it doesn't work correctly in all hosts (at the moment) - the gui window does not seem to be positioned correctly in some - I've seen similar problems with juce plugins which do this. I have tried using 32bit vst within Live, MaxMSP4 (non-composited carbon) MaxMSP5 (composited carbon) and it works well. I use the same method for RTAS and it works well. It doesn't work for vst in sample manager, and audiomulch. Also I have problems with AUs that use carbon windows.

Not sure if it is worth the effort, but it annoys me a bit that my text-entries look crap in carbon and i want to start filtering the text input with NSFormatter etc. You can call it in IGraphicsMac::OpenWindow(void* pWindow, void* pControl) which gets triggered in carbon hosts.

here is the code for attaching / removing the window if anyone is interested - it goes in IGraphicsMac.mm.

Code:
@interface CUSTOM_COCOA_WINDOW : NSWindow {}
@end

@implementation CUSTOM_COCOA_WINDOW
- (BOOL)canBecomeKeyWindow {return YES;}
@end

void* attachSubWindow (void* hostWindowRef, IGraphics* pGraphics)
{
  CocoaAutoReleasePool pool;
  
  NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: hostWindowRef];
  [hostWindow retain];
  [hostWindow setCanHide: YES];
  [hostWindow setReleasedWhenClosed: YES];
  
  NSRect w = [hostWindow frame];
  NSRect windowRect = NSMakeRect(w.origin.x, w.origin.y, pGraphics->Width(), pGraphics->Height());
  CUSTOM_COCOA_WINDOW *childWindow = [[CUSTOM_COCOA_WINDOW alloc] initWithContentRect:windowRect 
                                                      styleMask:( NSBorderlessWindowMask ) 
                                                        backing:NSBackingStoreBuffered defer:NO];
  [childWindow retain];
  [childWindow setOpaque:YES];
  [childWindow setCanHide: YES];
  [childWindow setHasShadow: NO];
  [childWindow setReleasedWhenClosed: YES];
  
  NSView* childContent = [childWindow contentView];
  pGraphics->OpenWindow(childContent);
  
  [hostWindow addChildWindow: childWindow ordered: NSWindowAbove];
  [hostWindow orderFront: nil];
  [childWindow orderFront: nil];
  
  return (void*) hostWindow;
}

void removeSubWindow (void* cocoaHostWindow, IGraphics* pGraphics)
{
  CocoaAutoReleasePool pool;
  
  NSWindow* hostWindow = (NSWindow*) cocoaHostWindow;
  NSArray* childWindows = [hostWindow childWindows];
  NSWindow* childWindow = [childWindows objectAtIndex:0]; // todo: check it is allways the only child
  
  [childWindow orderOut:nil];
  [hostWindow orderOut:nil];
  [childWindow close];
  [hostWindow removeChildWindow: childWindow];
  [hostWindow close];
}
__________________
VirtualCZ | pMix | Endless Series | iPlug2 | Linkedin | Facebook
Available for Audio Dev tuition via Skype (IPlug/JUCE/C++)
olilarkin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.