aboutsummaryrefslogtreecommitdiffstats
path: root/src/jalv_osx.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/jalv_osx.m')
-rw-r--r--src/jalv_osx.m159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/jalv_osx.m b/src/jalv_osx.m
new file mode 100644
index 0000000..be970df
--- /dev/null
+++ b/src/jalv_osx.m
@@ -0,0 +1,159 @@
+#import <Cocoa/Cocoa.h>
+#import <Foundation/Foundation.h>
+#include "jalv_internal.h"
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+@end
+
+@interface AppDelegate ()
+@property IBOutlet NSWindow* window;
+@property IBOutlet NSWindow* selectWindow;
+@property NSTimer* timer;
+@end
+
+static Jalv* g_jalv = NULL;
+NSWindowController* swc = NULL;
+NSWindowController* mwc = NULL;
+
+static const LilvPlugin*
+get_ith_plugin(unsigned i)
+{
+ const LilvPlugins* plugins = lilv_world_get_all_plugins(g_jalv->world);
+ LilvIter* p = lilv_plugins_begin(plugins);
+ for (unsigned j = 0; j < i; ++j) {
+ p = lilv_plugins_next(plugins, p);
+ }
+ return lilv_plugins_get(plugins, p);
+}
+
+@interface TableController : NSObject <NSTableViewDataSource, NSTableViewDelegate>
+@end
+
+@implementation TableController
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView
+{
+ return lilv_plugins_size(lilv_world_get_all_plugins(g_jalv->world));
+}
+
+- (id)tableView:(NSTableView*)tableView
+objectValueForTableColumn:(NSTableColumn*)tableColumn
+ row:(NSInteger)row
+{
+ const LilvPlugin* plugin = get_ith_plugin(row);
+ if ([tableColumn.identifier isEqualToString:@"URI"]) {
+ return [NSString stringWithUTF8String:lilv_node_as_string(lilv_plugin_get_uri(plugin))];
+ } else if ([tableColumn.identifier isEqualToString:@"Name"]) {
+ return [NSString stringWithUTF8String:lilv_node_as_string(lilv_plugin_get_name(plugin))];
+ } else {
+ return @"?";
+ }
+}
+
+- (void)tableViewSelectionDidChange:(NSNotification*)notification
+{
+ // Get selected plugin
+ Jalv* jalv = g_jalv;
+ NSTableView* tableView = notification.object;
+ const LilvPlugin* plugin = get_ith_plugin(tableView.selectedRow);
+
+ // Load plugin and set up Jalv internals
+ jalv_load_plugin(g_jalv, lilv_plugin_get_uri(plugin), NULL);
+
+ // Load and show main window
+ mwc = [[NSWindowController alloc] initWithWindowNibName:@"MainWindow"];
+ [mwc showWindow:self];
+
+ if (jalv->ui && !jalv->opts.generic_ui) {
+ // Instantiate custom UI
+ jalv_ui_instantiate(jalv, jalv_native_ui_type(jalv), mwc.window.contentView);
+ }
+
+ if (g_jalv->ui_instance) {
+ NSView* ui = suil_instance_get_widget(g_jalv->ui_instance);
+ [mwc.window setContentSize:[ui frame].size];
+ } else {
+ NSRect frame = NSMakeRect(10, 10, 800, 100);
+ NSSlider* widget = [[NSSlider alloc] initWithFrame:frame];
+ [widget retain];
+ [mwc.window.contentView addSubview:widget];
+ }
+}
+
+@end
+
+@implementation AppDelegate
+
+- (void)openDocument:(NSNotification*)aNotification
+{
+}
+
+- (void)onTimer:(NSTimer*)timer
+{
+ jalv_update(g_jalv);
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
+{
+ Jalv* jalv = g_jalv;
+
+ self.timer = [
+ [NSTimer scheduledTimerWithTimeInterval: 1/(float)jalv->ui_update_hz
+ target: self
+ selector: @selector(onTimer:)
+ userInfo: NULL
+ repeats: YES] retain];
+
+ swc = [[NSWindowController alloc] initWithWindowNibName:@"SelectPlugin"];
+ [swc showWindow:self];
+}
+
+- (void)applicationWillTerminate:(NSNotification*)aNotification
+{
+}
+
+@end
+
+const char*
+jalv_native_ui_type(Jalv* jalv)
+{
+ return "http://lv2plug.in/ns/extensions/ui#CocoaUI";
+}
+
+int
+jalv_init(int* argc, char*** argv, JalvOptions* opts)
+{
+ return 0;
+}
+
+bool
+jalv_discover_ui(Jalv* jalv)
+{
+ return TRUE;
+}
+
+int
+jalv_open_ui(Jalv* jalv)
+{
+ g_jalv = jalv;
+ return NSApplicationMain(0, NULL);
+}
+
+void
+jalv_ui_port_event(Jalv* jalv,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ uint32_t protocol,
+ const void* buffer)
+{
+ if (jalv->ui_instance) {
+ suil_instance_port_event(jalv->ui_instance, port_index,
+ buffer_size, protocol, buffer);
+ }
+}
+
+int
+jalv_close_ui(Jalv* jalv)
+{
+ return 0;
+}