Browse files

UI kinda works again

  • Loading branch information...
1 parent 7f12305 commit 09153d50d6c4d1dd18aacde24393adcdbbc50634 @spencersalazar committed Apr 3, 2016
Showing with 80 additions and 93 deletions.
  1. +7 −6 AudioUnit/AudioUnit-test.ck
  2. +73 −87 AudioUnit/AudioUnit.mm
View
13 AudioUnit/AudioUnit-test.ck
@@ -1,9 +1,6 @@
//MAUI_Slider slider;
//slider.display();
-// synchronize to period
-1.15::second => dur T;
-T - (now % T) => now;
// list available AUs
AudioUnit.list() @=> string aus[];
@@ -18,12 +15,16 @@ for(int i; i < aus.cap(); i++)
// setup patch
AudioUnit au => NRev reverb => dac;
// open General MIDI synth
-au.open("DLSMusicDevice");
-//au.open("Massive");
+//au.open("DLSMusicDevice");
+au.open("FM8");
// set reverb
0.1 => reverb.mix;
// display UI
-//au.display();
+au.display();
+
+// synchronize to period
+1.075::second => dur T;
+T - (now % T) => now;
// set program (voice)
if(me.args())
View
160 AudioUnit/AudioUnit.mm
@@ -11,7 +11,7 @@
#include "chuck_type.h"
#include <AudioUnit/AudioUnit.h>
-#include <AudioUnit/AudioUnitCarbonView.h>
+#include <AudioUnit/AUCocoaUIView.h>
#include <CoreAudio/CoreAudio.h>
#include <CoreAudioKit/CoreAudioKit.h>
#include <Foundation/Foundation.h>
@@ -30,6 +30,9 @@
using namespace std;
+void (*g_Chuck_UI_Manager_init)();
+void (*g_Chuck_UI_Manager_start)();
+
// declaration of chugin constructor
CK_DLL_CTOR(audiounit_ctor);
// declaration of chugin desctructor
@@ -48,6 +51,15 @@
t_CKINT audiounit_data_offset = 0;
+void dispatch_sync_noblock(dispatch_queue_t queue, dispatch_block_t block)
+{
+ if(dispatch_get_current_queue() == queue)
+ block();
+ else
+ dispatch_sync(queue, block);
+}
+
+
class CKAudioUnitManager
{
public:
@@ -166,88 +178,41 @@ - (void)display
{
if(m_window == nil)
{
-// NSRect r = NSMakeRect(0, 0, 500, 500);
-// m_window = [[NSWindow alloc] initWithContentRect:r
-// styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
-// backing:NSBackingStoreBuffered
-// defer:YES];
-// [m_window setReleasedWhenClosed:NO];
-//// [m_window setContentView:[[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 500)] autorelease]];
-// [m_window center];
+ NSRect r = NSMakeRect(0, 0, 500, 500);
+ m_window = [[NSWindow alloc] initWithContentRect:r
+ styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES];
+ [m_window setReleasedWhenClosed:NO];
+ // [m_window setContentView:[[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 500)] autorelease]];
+ [m_window center];
}
-
-#if !__LP64__
-// WindowRef carbonWindow = (WindowRef) [m_window windowRef];
- OSStatus result;
-
- HIWindowRef carbonWindow;
-
- Rect windowRect = { 0, 0, 500, 500 };
- result = CreateNewWindow(kDocumentWindowClass,
- kWindowStandardHandlerAttribute |
- kWindowCloseBoxAttribute |
- kWindowCollapseBoxAttribute |
- kWindowCompositingAttribute,
- &windowRect, &carbonWindow);
-
- CreateRootControl(carbonWindow, NULL);
- ControlRef rootControl = NULL;
- GetRootControl(carbonWindow, &rootControl);
-
- UInt32 dataSize;
- Boolean isWritable;
- AudioComponentDescription * carbonViewDescs = NULL;
- UInt32 numComponents;
-
- result = AudioUnitGetPropertyInfo(m_au,
- kAudioUnitProperty_GetUIComponentList,
- kAudioUnitScope_Global,
- 0,
- &dataSize,
- &isWritable );
-
- numComponents = dataSize/sizeof(AudioComponentDescription);
- carbonViewDescs = new AudioComponentDescription[numComponents];
-
- result = AudioUnitGetProperty(m_au,
- kAudioUnitProperty_GetUIComponentList,
- kAudioUnitScope_Global,
- 0,
- carbonViewDescs,
- &dataSize);
-
- AudioComponent uiComponent = AudioComponentFindNext(NULL, &carbonViewDescs[0]);
- AudioComponentInstance uiComponentInstance;
- AudioComponentInstanceNew(uiComponent, &uiComponentInstance);
-
- ControlRef auControl;
- Float32Point auLoc = { 0, 0 };
- Float32Point auSize = { 500, 500 };
- result = AudioUnitCarbonViewCreate(uiComponentInstance, m_au, carbonWindow, rootControl,
- &auLoc, &auSize, &auControl);
-
- Rect controlRect;
- GetControlBounds(auControl, &controlRect);
- SizeWindow(carbonWindow, controlRect.right - controlRect.left,
- controlRect.bottom - controlRect.top, true);
-
-// ActivateControl(auControl);
-// EnableControl(auControl);
+ AudioUnitCocoaViewInfo auViewInfo;
+ auViewInfo.mCocoaAUViewBundleLocation = nil;
+ auViewInfo.mCocoaAUViewClass[0] = nil;
+ UInt32 dataSize = 1*sizeof(AudioUnitCocoaViewInfo);
-// ActivateWindow(carbonWindow, true);
-// BringToFront(carbonWindow);
-
- m_window = [[NSWindow alloc] initWithWindowRef:carbonWindow];
+ OSStatus result = AudioUnitGetProperty(m_au, kAudioUnitProperty_CocoaUI,
+ kAudioUnitScope_Global, 0, &auViewInfo, &dataSize);
+ if(result != noErr)
+ {
+ assert(0);
+ }
+
+ // the host gets the path to the view bundle
+ NSURL *auBundleURL = (NSURL *) auViewInfo.mCocoaAUViewBundleLocation;
+ // the host gets the view's class name
+ NSString *auViewFactoryName = (NSString *) auViewInfo.mCocoaAUViewClass[0];
+
+ NSBundle *auBundle = [NSBundle bundleWithURL:auBundleURL];
+ Class auViewFactoryClass = [auBundle classNamed:auViewFactoryName];
+ id<AUCocoaUIBase> auViewFactory = [auViewFactoryClass new];
+ NSView *auView = [auViewFactory uiViewForAudioUnit:m_au
+ withSize:NSMakeSize(500, 500)];
-// Rect controlRect;
-// GetControlBounds(auControl, &controlRect);
-// [m_window setFrame:[m_window frameRectForContentRect:NSMakeRect(0, 0,
-// controlRect.right - controlRect.left,
-// controlRect.bottom - controlRect.top)]
-// display:YES];
-
-#endif
+ [m_window setContentSize:auView.frame.size];
+ m_window.contentView = auView;
[m_window center];
[m_window makeKeyAndOrderFront:nil];
@@ -265,15 +230,26 @@ - (void)display
{
public:
// constructor
- CKAudioUnit(t_CKFLOAT fs)
+ CKAudioUnit(t_CKFLOAT fs) : m_au(NULL), m_helper(nil), m_buffer(NULL), m_fs(fs)
{
+ // first check if we are in miniAudicle
+ const char **MA_VERSION = (const char **) dlsym(RTLD_DEFAULT, "MA_VERSION");
+ if(MA_VERSION == NULL)
+ {
+ // find standalone UI hooks for MAUI.chug
+ g_Chuck_UI_Manager_init = (void (*)()) dlsym(RTLD_DEFAULT, "Chuck_UI_Manager_init");
+ g_Chuck_UI_Manager_start = (void (*)()) dlsym(RTLD_DEFAULT, "Chuck_UI_Manager_start");
+
+ if(g_Chuck_UI_Manager_init == NULL || g_Chuck_UI_Manager_start == NULL)
+ {
+ EM_error3("AudioUnit.chug: error: unable to find MAUI");
+ }
+ }
+
m_fs = fs;
m_timestamp.mSampleTime = 0;
m_timestamp.mFlags = kAudioTimeStampSampleTimeValid;
- m_au = NULL;
-
- m_buffer = NULL;
m_renderBufferSize = 64;
m_bufferPos = 0;
}
@@ -433,10 +409,19 @@ t_CKBOOL send_midi(t_CKUINT data1, t_CKUINT data2, t_CKUINT data3)
t_CKBOOL display()
{
- CKAudioUnitHelper * helper = [[CKAudioUnitHelper alloc] initWithAudioUnit:m_au];
- [helper performSelectorOnMainThread:@selector(display)
- withObject:nil
- waitUntilDone:NO];
+// if(g_Chuck_UI_Manager_init != NULL)
+// g_Chuck_UI_Manager_init();
+ if(g_Chuck_UI_Manager_start != NULL)
+ g_Chuck_UI_Manager_start();
+
+ if(m_helper == nil)
+ m_helper = [[CKAudioUnitHelper alloc] initWithAudioUnit:m_au];
+ dispatch_sync_noblock(dispatch_get_main_queue(), ^{
+ [m_helper display];
+ });
+// [helper performSelectorOnMainThread:@selector(display)
+// withObject:nil
+// waitUntilDone:NO];
return TRUE;
}
@@ -452,6 +437,7 @@ t_CKBOOL display()
t_CKUINT m_renderBufferSize;
t_CKUINT m_bufferPos;
CABufferList * m_buffer;
+ CKAudioUnitHelper * m_helper;
};

0 comments on commit 09153d5

Please sign in to comment.