Commit c3c5490b authored by jhammen's avatar jhammen
Browse files

store key to instrument mapping in lv2 config

parent 85cb2b6c
......@@ -23,7 +23,6 @@ namespace handrumr {
class Instrument {
string mName;
uint8_t mKey;
Layer *mLayers;
uint16_t mLayerCount;
......@@ -31,8 +30,6 @@ class Instrument {
~Instrument() { delete[] mLayers; }
string &name() { return mName; }
void name(const string &n) { mName = n; }
uint8_t key() { return mKey; }
void key(uint8_t key) { mKey = key; }
void layers(Layer *layers, uint16_t count) {
mLayers = layers;
mLayerCount = count;
......@@ -53,4 +50,4 @@ class Instrument {
} // namespace handrumr
#endif // INSTRUMENT_H
\ No newline at end of file
#endif // INSTRUMENT_H
This diff is collapsed.
......@@ -17,6 +17,8 @@
#ifndef PLUGIN_H
#define PLUGIN_H
#include <atomic>
#include <jsoncpp/json/json.h>
#include <map>
#include <sndfile.h>
#include <stdarg.h>
......@@ -37,13 +39,13 @@ namespace handrumr {
struct PluginConfig {
string filepath;
float gain;
Instrument *instruments;
uint16_t instrumentCount;
Instrument *instrument;
string patchName;
bool exclusive;
PluginConfig *next;
PluginConfig() : gain(0.0), instruments(nullptr), instrumentCount(0), next(nullptr) {}
~PluginConfig() { delete[] instruments; }
uint8_t key;
PluginConfig() : gain(0.0), instrument(nullptr), next(nullptr) {}
~PluginConfig() { delete instrument; }
};
class SamplePlay {
......@@ -114,7 +116,7 @@ class StringBuffer {
}
size_t size() { return mend + 1; }
size_t strlen() { return mend; }
const char *ptr() { return buffer; }
char *ptr() { return buffer; }
void clear() { mend = 0; }
};
......@@ -124,26 +126,31 @@ enum { WKR_LOAD_REQUEST, WKR_STRING_MESG, WKR_DELETE_REQUEST, WKR_CONFIG_RESPONS
class LoadMesg {
const int64_t mtype = WKR_LOAD_REQUEST;
uint32_t mindex;
uint32_t mkey;
float mgain;
StringBuffer mname;
StringBuffer mpath;
public:
LoadMesg() {}
LoadMesg(const char *str, uint32_t index) : mindex(index) { name(str, ::strlen(str)); }
int32_t type() { return mtype; }
uint32_t index() { return mindex; }
void index(uint32_t index) { mindex = index; }
uint32_t key() { return mkey; }
void key(uint32_t key) { mkey = key; }
float gain() { return mgain; }
void gain(float gain) { mgain = gain; }
const char *name() { return mname.ptr(); }
bool name(const char *str, uint32_t size) { return mname.append(str, size); }
void index(uint32_t index) { mindex = index; }
uint32_t index() { return mindex; }
size_t size() { return sizeof(mtype) + sizeof(mindex) + sizeof(mgain) + mname.size(); }
size_t strlen() { return mname.strlen(); }
char *path() { return mpath.ptr(); }
bool path(const char *str, uint32_t size) { return mpath.append(str, size); }
size_t size() {
return sizeof(mtype) + sizeof(mindex) + sizeof(mkey) + sizeof(mgain) + mpath.size();
}
size_t strlen() { return mpath.strlen(); }
bool deserialize(const char *buffer, uint32_t size) {
mindex = *((uint32_t *)(buffer + sizeof(mtype)));
mgain = *((float *)(buffer + sizeof(mtype) + sizeof(mindex)));
uint32_t header = sizeof(mtype) + sizeof(mindex) + sizeof(mgain);
return mname.append(buffer + header, size - header);
mkey = *((uint32_t *)(buffer + sizeof(mtype) + sizeof(mindex)));
mgain = *((float *)(buffer + sizeof(mtype) + sizeof(mindex) + sizeof(mkey)));
uint32_t header = sizeof(mtype) + sizeof(mindex) + sizeof(mkey) + sizeof(mgain);
return mpath.append(buffer + header, size - header);
}
};
......@@ -204,6 +211,7 @@ class Plugin {
HandrumrLV2URIs uris;
uint16_t channelCount;
PluginConfig *config[HD_MAX_PATCHES];
std::atomic<uint32_t> configCount;
PluginConfig *inactiveList;
LV2_Worker_Schedule *worker;
std::map<string, SampleFile *> filecache;
......@@ -234,12 +242,9 @@ class Plugin {
private:
string fullpath(string sampleBase, string filename);
LV2_Worker_Status channelMismatch(LV2_Worker_Respond_Function respond,
LV2_Worker_Respond_Handle handle, uint16_t channels,
string path, uint16_t index);
LV2_Worker_Status channelOutOfRange(LV2_Worker_Respond_Function respond,
LV2_Worker_Respond_Handle handle, uint16_t channel,
uint16_t index);
string channelMismatch(uint16_t channels, string path);
string channelOutOfRange(uint16_t channel);
Instrument *loadInstrument(Json::Value &jsonInstr, float odbgain, string &sampleBase, zip *zip);
};
} // namespace handrumr
......
......@@ -77,14 +77,28 @@ PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
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(); // instrument column
gtk_tree_view_column_set_title(column, "Instrument");
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);
// gtk_tree_view_column_set_expand(column, TRUE);
column = gtk_tree_view_column_new(); // key column
gtk_tree_view_column_set_title(column, "Key");
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", 3);
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);
gtk_tree_view_column_add_attribute(column, renderer, "text", 4);
treestore = gtk_tree_store_new(3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
treestore = gtk_tree_store_new(5, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(treestore));
g_object_unref(treestore);
......@@ -209,12 +223,18 @@ void PluginUi::notify(uint32_t format, const LV2_Atom *atom) {
} else {
gtk_tree_store_clear(treestore);
for (uint i = 0; i < root.size(); i++) {
int channel = 0;
const char *name = root[i]["name"].asCString();
const char *instrument = root[i].isMember("instrument")
? root[i]["instrument"].asCString()
: "";
int key = root[i]["key"].asInt();
char gainstr[128];
sprintf(gainstr, "%+.2f dB", root[i]["gain"].asFloat());
sprintf(gainstr, "%+.1f dB", root[i]["gain"].asFloat());
GtkTreeIter treeitem;
gtk_tree_store_append(treestore, &treeitem, NULL);
gtk_tree_store_set(treestore, &treeitem, 0, 0, 1, name, 2, gainstr, -1);
gtk_tree_store_set(treestore, &treeitem, 0, channel, 1, name, 2,
instrument, 3, key, 4, gainstr, -1);
}
}
}
......
......@@ -29,7 +29,7 @@
#define HANDRUMR16_URI HANDRUMR_URI "16"
#define HANDRUMR__config HANDRUMR_URI "#config"
#define HD_MAX_PATCHES 24
#define HD_MAX_PATCHES 32
typedef struct {
LV2_URID atom_Float;
......
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