Commit 3a87818f authored by jhammen's avatar jhammen
Browse files

send full state to UI

parent 52672c93
......@@ -20,6 +20,7 @@ add_library(${PROJECT_NAME}_ui SHARED
pluginui.cpp
)
set_target_properties(${PROJECT_NAME}_ui PROPERTIES PREFIX "")
target_link_libraries(${PROJECT_NAME}_ui "jsoncpp")
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTK2 REQUIRED gtk+-2.0)
......
......@@ -554,18 +554,25 @@ void Plugin::run(uint32_t sampleCount) {
lv2_atom_forge_frame_time(&forge, 0);
lv2_atom_forge_object(&forge, &frame, 0, uris.patch_Set);
lv2_atom_forge_key(&forge, uris.patch_property);
lv2_atom_forge_urid(&forge, uris.patchName);
lv2_atom_forge_urid(&forge, uris.patchConfig);
lv2_atom_forge_key(&forge, uris.patch_value);
lv2_atom_forge_string(&forge, config[0]->patchName.c_str(),
config[0]->patchName.length());
lv2_atom_forge_pop(&forge, &frame);
lv2_atom_forge_frame_time(&forge, 0);
lv2_atom_forge_object(&forge, &frame, 0, uris.patch_Set);
lv2_atom_forge_key(&forge, uris.patch_property);
lv2_atom_forge_urid(&forge, uris.hd_config[0]);
lv2_atom_forge_key(&forge, uris.patch_value);
lv2_atom_forge_string(&forge, config[0]->filepath.c_str(),
config[0]->filepath.length());
// create json
StringBuffer json;
json.append("[", 1);
for (int i = 0; i < HD_MAX_PATCHES; i++) {
if (!config[i]) {
break;
}
if (i) {
json.append("\n ,", 3);
}
json.append("{\"name\" : \"");
json.append(config[i]->patchName.c_str());
json.append("\"", 1);
json.append("}", 1);
}
json.append("]", 1);
lv2_atom_forge_string(&forge, json.ptr(), json.size());
lv2_atom_forge_pop(&forge, &frame);
setpatch = false;
}
......
......@@ -96,6 +96,7 @@ class StringBuffer {
return false;
}
}
bool append(const char *str) { return append(str, ::strlen(str)); }
bool append(uint32_t number) {
char numbuf[64];
sprintf(numbuf, "%u", number);
......
......@@ -16,6 +16,7 @@
*/
#include "pluginui.h"
#include <jsoncpp/json/json.h>
#include <stdexcept>
#include <string>
......@@ -56,7 +57,7 @@ PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
handrumr_init_uris(map, &uris);
lv2_atom_forge_init(&forge, map);
// list (aka tree) stuff
// list (aka treeview) stuff
GtkWidget *treeview = gtk_tree_view_new();
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
gtk_tree_selection_set_select_function(selection, on_grid_selection, this, NULL);
......@@ -73,13 +74,15 @@ PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_add_attribute(column, renderer, "text", 1);
gtk_tree_view_column_set_expand(column, TRUE);
column = gtk_tree_view_column_new(); // gain column
gtk_tree_view_column_set_title(column, "Gain");
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_add_attribute(column, renderer, "text", 2);
GtkTreeStore *treestore = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
treestore = gtk_tree_store_new(3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(treestore));
g_object_unref(treestore);
......@@ -137,6 +140,14 @@ PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
*widget = outerBox;
}
void PluginUi::showError(const char *mesg) {
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
GtkWidget *dialog =
gtk_message_dialog_new(nullptr, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", mesg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
}
void PluginUi::portEvent(uint32_t format, const LV2_Atom *atom) {
if (format == uris.atom_eventTransfer && lv2_atom_forge_is_object_type(&forge, atom->type)) {
......@@ -171,8 +182,24 @@ void PluginUi::portEvent(uint32_t format, const LV2_Atom *atom) {
if (type && value && value->type == uris.atom_String) {
const uint32_t prop = ((const LV2_Atom_URID *)type)->body;
const char *str = (const char *)LV2_ATOM_BODY_CONST(value);
if (prop == uris.patchName) {
// gtk_entry_set_text(patchEntry, str);
if (prop == uris.patchConfig) {
Json::Value root;
JSONCPP_STRING errs;
Json::CharReaderBuilder builder;
Json::CharReader *reader = builder.newCharReader();
if (!reader->parse(str, str + strlen(str), &root, &errs)) {
std::string mesg("Handrumr config JSON parse error: ");
mesg.append(errs);
showError(mesg.c_str());
} else {
gtk_tree_store_clear(treestore);
for (uint i = 0; i < root.size(); i++) {
GtkTreeIter treeitem;
gtk_tree_store_append(treestore, &treeitem, NULL);
gtk_tree_store_set(treestore, &treeitem, 0, 0, 1,
root[i]["name"].asCString(), 2, "1.0", -1);
}
}
} else if (prop == uris.hd_config[0]) {
if (strlen(str) > 0) {
GFile *gfile = g_file_new_for_path(str);
......@@ -188,11 +215,7 @@ void PluginUi::portEvent(uint32_t format, const LV2_Atom *atom) {
if (value && value->type == uris.atom_String) {
// show message in dialog
const char *mesg = (const char *)LV2_ATOM_BODY_CONST(value);
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
GtkWidget *dialog = gtk_message_dialog_new(nullptr, flags, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, "%s", mesg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
showError(mesg);
}
}
}
......
......@@ -35,6 +35,7 @@ class PluginUi {
//
GtkWidget *removeButton;
GtkWidget *mopendialog;
GtkTreeStore *treestore;
// last note widgets
GtkEntry *lastEntry;
GtkEntry *velEntry;
......@@ -49,6 +50,9 @@ class PluginUi {
void portEvent(uint32_t format, const LV2_Atom *atom);
void openConfig(const char *filepath);
void enableRemove(bool enable);
private:
void showError(const char *mesg);
};
} // namespace handrumr
......
......@@ -47,7 +47,7 @@ typedef struct {
// state
LV2_URID hd_config[HD_MAX_PATCHES];
// for patch set
LV2_URID patchName;
LV2_URID patchConfig;
// last note
LV2_URID ui_Last;
LV2_URID lastPitch;
......@@ -78,7 +78,7 @@ static inline void handrumr_init_uris(LV2_URID_Map *map, HandrumrLV2URIs *uris)
sprintf(str, "%s%d", HANDRUMR__config, i);
uris->hd_config[i] = map->map(map->handle, str);
}
uris->patchName = map->map(map->handle, HANDRUMR_URI "#patchName");
uris->patchConfig = map->map(map->handle, HANDRUMR_URI "#patchConfig");
uris->ui_Last = map->map(map->handle, HANDRUMR_URI "#UILast");
uris->lastPitch = map->map(map->handle, HANDRUMR_URI "#lastPitch");
......
Supports Markdown
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