Commit d76db774 authored by Hanspeter Portner's avatar Hanspeter Portner

prototype nk ui.

parent 43e6c7b1
......@@ -16,6 +16,7 @@ include_directories(${PROJECT_SOURCE_DIR}/api)
include_directories(${PROJECT_SOURCE_DIR}/ui)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/plugin)
include_directories(${PROJECT_SOURCE_DIR}/pugl)
include_directories(${PROJECT_BINARY_DIR})
# check for visibility support in compiler on Unices
......@@ -71,6 +72,7 @@ set(LIBS ${LIBS} ${LV2_LDFLAGS})
include(CMakeDependentOption)
option(BUILD_SIMPLE_UI "Build simple external UI" OFF)
option(BUILD_WEB_UI "Build web-based external UI" ON)
option(BUILD_NK_UI "Build nuklear UI" ON)
option(BUILD_INLINE_DISPLAY "Build inline display" ON)
option(USE_MANUAL_GC "Use manual garbage collection" OFF)
option(USE_VERBOSE_LOG "Use verbose log for websocket" OFF)
......@@ -160,6 +162,84 @@ else()
set(WEB_WRAP "#")
endif()
if(BUILD_NK_UI)
set(LIBS_NK ${LIBS_NK} m)
if(WIN32)
set(MOONY_UI_TYPE "WindowsUI")
elseif(APPLE)
set(MOONY_UI_TYPE "CocoaUI")
else()
set(MOONY_UI_TYPE "X11UI")
endif()
find_package(OpenGL)
if(${OPENGL_FOUND})
set(LIBS_NK ${LIBS_NK} ${OPENGL_LIBRARIES})
else() # try pkg-config
pkg_search_module(GL REQUIRED gl)
if(${GL_FOUND})
set(LIBS_NK ${LIBS_NK} ${GL_LDFLAGS})
else()
message(FATAL_ERROR "OpenGL not found")
endif()
endif()
add_definitions("-DPUGL_HAVE_GL")
if(WIN32)
find_library(GDI32_LIBRARY NAMES gdi32)
if(GDI32_LIBRARY)
set(LIBS_NK ${LIBS_NK} ${GDI32_LIBRARY})
else()
message(FATAL_ERROR "gdi32 library not found")
endif()
find_library(USER32_LIBRARY NAMES user32)
if(USER32_LIBRARY)
set(LIBS_NK ${LIBS_NK} ${USER32_LIBRARY})
else()
message(FATAL_ERROR "user32 library not found")
endif()
set(TAR_UI ${TAR_UI} pugl/pugl/pugl_win.cpp)
elseif(APPLE)
find_library(COCOA_LIBRARY NAMES Cocoa)
if(COCOA_LIBRARY)
set(LIBS_NK ${LIBS_NK} ${COCOA_LIBRARY})
else()
message(FATAL_ERROR "Cocoa framework not found")
endif()
set(TAR_UI ${TAR_UI} pugl/pugl/pugl_osx.m)
else() # GNU/Linux
pkg_search_module(X11 REQUIRED x11>=1.6)
include_directories(${X11_INCLUDE_DIRS})
set(LIBS_NK ${LIBS_NK} ${X11_LDFLAGS})
pkg_search_module(XEXT REQUIRED xext>=1.3)
include_directories(${XEXT_INCLUDE_DIRS})
set(LIBS_NK ${LIBS_NK} ${XEXT_LDFLAGS})
set(TAR_UI ${TAR_UI} pugl/pugl/pugl_x11.c)
endif()
add_library(moony_nk MODULE
ui/moony_nk.c
ui/nk_ui.c
${TAR_UI})
target_link_libraries(moony_nk ${LIBS_NK})
set_target_properties(moony_nk PROPERTIES PREFIX "")
if(NOT WIN32)
set_target_properties(moony_nk PROPERTIES LINK_FLAGS "-Wl,-e,lv2ui_descriptor")
endif()
install(TARGETS moony_nk DESTINATION ${PLUGIN_DEST})
install(FILES ${PROJECT_SOURCE_DIR}/nuklear/extra_font/Cousine-Regular.ttf DESTINATION ${PLUGIN_DEST})
else()
set(NK_WRAP "#")
endif()
add_library(lua OBJECT
lua-5.3.3/lapi.c
lua-5.3.3/lcode.c
......
......@@ -85,16 +85,14 @@
#define MOONY_DSP_URI MOONY_URI"#dsp"
#define MOONY_DESTINATION_URI MOONY_URI"#destination"
#define MOONY_COMMON_UI_URI MOONY_URI"#ui_3_common_1_ui"
#define MOONY_COMMON_KX_URI MOONY_URI"#ui_3_common_2_kx"
#define MOONY_COMMON_EO_URI MOONY_URI"#ui_3_common_3_eo"
#define MOONY_SIMPLE_UI_URI MOONY_URI"#ui_2_simple_1_ui"
#define MOONY_SIMPLE_KX_URI MOONY_URI"#ui_2_simple_2_kx"
#define MOONY_WEB_UI_URI MOONY_URI"#ui_1_web_1_ui"
#define MOONY_WEB_KX_URI MOONY_URI"#ui_1_web_2_kx"
#define MOONY_NK_URI MOONY_URI"#ui_3_nk"
#define MOONY_C1XC1_URI MOONY_URI"#c1xc1"
#define MOONY_C2XC2_URI MOONY_URI"#c2xc2"
#define MOONY_C4XC4_URI MOONY_URI"#c4xc4"
......@@ -119,16 +117,14 @@ extern const LV2_Descriptor c1a1xc1a1;
extern const LV2_Descriptor c2a1xc2a1;
extern const LV2_Descriptor c4a1xc4a1;
extern const LV2UI_Descriptor common_eo;
extern const LV2UI_Descriptor common_ui;
extern const LV2UI_Descriptor common_kx;
extern const LV2UI_Descriptor simple_ui;
extern const LV2UI_Descriptor simple_kx;
extern const LV2UI_Descriptor web_ui;
extern const LV2UI_Descriptor web_kx;
extern const LV2UI_Descriptor nk_ui;
typedef enum _moony_udata_t {
MOONY_UDATA_ATOM,
MOONY_UDATA_FORGE,
......
......@@ -39,6 +39,7 @@ moony:c1xc1
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:c2xc2
......@@ -50,6 +51,7 @@ moony:c2xc2
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:c4xc4
......@@ -61,6 +63,7 @@ moony:c4xc4
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
# atom in, atom out
......@@ -73,6 +76,7 @@ moony:a1xa1
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:a2xa2
......@@ -84,6 +88,7 @@ moony:a2xa2
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:a4xa4
......@@ -95,6 +100,7 @@ moony:a4xa4
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
# control/atom in, control/atom out
......@@ -107,6 +113,7 @@ moony:c1a1xc1a1
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:c2a1xc2a1
......@@ -118,6 +125,7 @@ moony:c2a1xc2a1
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
moony:c4a1xc4a1
......@@ -129,6 +137,7 @@ moony:c4a1xc4a1
@WEB_WRAP@ui:ui moony:ui_1_web_2_kx ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_1_ui ;
@SIMPLE_WRAP@ui:ui moony:ui_2_simple_2_kx ;
@NK_WRAP@ui:ui moony:ui_3_nk ;
rdfs:seeAlso <moony.ttl> .
# Web UI
......@@ -151,6 +160,12 @@ moony:ui_2_simple_2_kx
ui:binary <moony_simple@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony_ui.ttl> .
# NK UI
moony:ui_3_nk
a ui:@MOONY_UI_TYPE@ ;
ui:binary <moony_nk@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <moony_ui.ttl> .
# Banks
moony:bank-through
a pset:Bank ;
......
......@@ -189,3 +189,44 @@ moony:ui_2_simple_2_kx
ui:protocol atom:eventTransfer ;
] ;
lv2:requiredFeature kx:Host, ui:portMap, urid:map .
moony:ui_3_nk
ui:portNotification [
ui:plugin moony:c1xc1 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:c2xc2 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:c4xc4 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:a1xa1 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:a2xa2 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:a4xa4 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:c1a1xc1a1 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:c2a1xc2a1 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] , [
ui:plugin moony:c4a1xc4a1 ;
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer ;
] ;
lv2:requiredFeature ui:portMap, urid:map ;
lv2:extensionData ui:idleInterface .
/*
* Copyright (c) 2015-2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
* Copyright (c) 2015 Hanspeter Portner (dev@open-music-kontrollers.ch)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Artistic License 2.0 as published by
......@@ -16,23 +16,6 @@
*/
#include <moony.h>
#include <sandbox_ui.h>
const LV2UI_Descriptor common_ui= {
.URI = MOONY_COMMON_UI_URI,
.instantiate = sandbox_ui_instantiate,
.cleanup = sandbox_ui_cleanup,
.port_event = sandbox_ui_port_event,
.extension_data = sandbox_ui_extension_data
};
const LV2UI_Descriptor common_kx= {
.URI = MOONY_COMMON_KX_URI,
.instantiate = sandbox_ui_instantiate,
.cleanup = sandbox_ui_cleanup,
.port_event = sandbox_ui_port_event,
.extension_data = NULL
};
#ifdef _WIN32
__declspec(dllexport)
......@@ -45,10 +28,7 @@ lv2ui_descriptor(uint32_t index)
switch(index)
{
case 0:
return &common_ui;
case 1:
return &common_kx;
return &nk_ui;
default:
return NULL;
}
......
/*
* Copyright (c) 2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Artistic License 2.0 as published by
* The Perl Foundation.
*
* This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Artistic License 2.0 for more details.
*
* You should have received a copy of the Artistic License 2.0
* along the source as a COPYING file. If not, obtain it from
* http://www.perlfoundation.org/artistic_license_2_0.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <inttypes.h>
#include <moony.h>
#define NK_PUGL_IMPLEMENTATION
#include "nk_pugl/nk_pugl.h"
typedef struct _plughandle_t plughandle_t;
struct _plughandle_t {
LV2_URID_Map *map;
LV2_Atom_Forge forge;
LV2_Log_Log *log;
LV2_Log_Logger logger;
nk_pugl_window_t win;
LV2UI_Controller *controller;
LV2UI_Write_Function writer;
float dy;
struct nk_text_edit text_edit;
bool code_hidden;
bool prop_hidden;
};
static void
_expose(struct nk_context *ctx, struct nk_rect wbounds, void *data)
{
plughandle_t *handle = data;
const float dy = handle->dy;
const struct nk_vec2 window_padding = ctx->style.window.padding;
const struct nk_vec2 group_padding = ctx->style.window.group_padding;
const float header_h = 1*dy + 2*window_padding.y;
const float footer_h = 1*dy + 2*window_padding.y;
const float body_h = wbounds.h - header_h - footer_h;
if(nk_begin(ctx, "Moony", wbounds, NK_WINDOW_NO_SCROLLBAR))
{
nk_window_set_bounds(ctx, wbounds);
nk_layout_row_begin(ctx, NK_DYNAMIC, dy, 2);
{
nk_layout_row_push(ctx, 0.6);
handle->code_hidden = !nk_select_label(ctx, "Code", NK_TEXT_LEFT, !handle->code_hidden);
nk_layout_row_push(ctx, 0.4);
handle->prop_hidden = !nk_select_label(ctx, "Properties", NK_TEXT_LEFT, !handle->prop_hidden);
}
nk_layout_row_begin(ctx, NK_DYNAMIC, body_h, !handle->code_hidden + !handle->prop_hidden);
{
if(!handle->code_hidden)
{
nk_layout_row_push(ctx, handle->prop_hidden ? 1.0 : 0.6);
const nk_flags state = nk_edit_buffer(ctx, NK_EDIT_BOX, &handle->text_edit, nk_filter_default);
}
if(!handle->prop_hidden)
{
nk_layout_row_push(ctx, handle->code_hidden ? 1.0 : 0.4);
if(nk_group_begin(ctx, "Properties", NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER))
{
//FIXME
nk_group_end(ctx);
}
}
}
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, dy, 3);
{
nk_button_label(ctx, "left");
nk_button_label(ctx, "right");
nk_label(ctx, "Moony.lv2: "MOONY_VERSION, NK_TEXT_RIGHT);
}
}
nk_end(ctx);
}
static LV2UI_Handle
instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
const char *bundle_path, LV2UI_Write_Function write_function,
LV2UI_Controller controller, LV2UI_Widget *widget,
const LV2_Feature *const *features)
{
plughandle_t *handle = calloc(1, sizeof(plughandle_t));
if(!handle)
return NULL;
void *parent = NULL;
LV2UI_Resize *host_resize = NULL;
for(int i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_UI__parent))
parent = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_UI__resize))
host_resize = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_URID__map))
handle->map = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_LOG__log))
handle->log = features[i]->data;
}
if(!parent)
{
fprintf(stderr,
"%s: Host does not support ui:parent\n", descriptor->URI);
free(handle);
return NULL;
}
if(!handle->map)
{
fprintf(stderr,
"%s: Host does not support urid:map\n", descriptor->URI);
free(handle);
return NULL;
}
if(handle->log)
lv2_log_logger_init(&handle->logger, handle->map, handle->log);
lv2_atom_forge_init(&handle->forge, handle->map);
handle->controller = controller;
handle->writer = write_function;
const char *NK_SCALE = getenv("NK_SCALE");
const float scale = NK_SCALE ? atof(NK_SCALE) : 1.f;
handle->dy = 20.f * scale;
nk_pugl_config_t *cfg = &handle->win.cfg;
cfg->width = 1280 * scale;
cfg->height = 720 * scale;
cfg->resizable = true;
cfg->ignore = false;
cfg->class = "tracker";
cfg->title = "Tracker";
cfg->parent = (intptr_t)parent;
cfg->data = handle;
cfg->expose = _expose;
char *path;
if(asprintf(&path, "%sCousine-Regular.ttf", bundle_path) == -1)
path = NULL;
cfg->font.face = path;
cfg->font.size = 13 * scale;
*(intptr_t *)widget = nk_pugl_init(&handle->win);
nk_pugl_show(&handle->win);
if(path)
free(path);
if(host_resize)
host_resize->ui_resize(host_resize->handle, cfg->width, cfg->height);
nk_textedit_init_default(&handle->text_edit);
return handle;
}
static void
cleanup(LV2UI_Handle instance)
{
plughandle_t *handle = instance;
nk_textedit_free(&handle->text_edit);
nk_pugl_hide(&handle->win);
nk_pugl_shutdown(&handle->win);
free(handle);
}
static void
port_event(LV2UI_Handle instance, uint32_t index, uint32_t size,
uint32_t protocol, const void *buf)
{
plughandle_t *handle = instance;
//FIXME
}
static int
_idle(LV2UI_Handle instance)
{
plughandle_t *handle = instance;
return nk_pugl_process_events(&handle->win);
}
static const LV2UI_Idle_Interface idle_ext = {
.idle = _idle
};
static const void *
ext_data(const char *uri)
{
if(!strcmp(uri, LV2_UI__idleInterface))
return &idle_ext;
return NULL;
}
const LV2UI_Descriptor nk_ui= {
.URI = MOONY_NK_URI,
.instantiate = instantiate,
.cleanup = cleanup,
.port_event = port_event,
.extension_data = ext_data
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment