Commit 9e6c9019 authored by jhammen's avatar jhammen
Browse files

add gain control port

parent 3a87818f
......@@ -35,10 +35,19 @@
lv2:index 1 ;
lv2:symbol "notify" ;
lv2:name "Notify" ;
] , [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 2 ;
lv2:symbol "gain" ;
lv2:name "Gain" ;
lv2:default 1.0 ;
lv2:minimum 0.0 ;
lv2:maximum 2.0 ;
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 2 ;
lv2:index 3 ;
lv2:symbol "out" ;
lv2:name "Out"
] ;
......
......@@ -35,100 +35,109 @@
lv2:index 1 ;
lv2:symbol "notify" ;
lv2:name "Notify" ;
] , [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 2 ;
lv2:symbol "gain" ;
lv2:name "Gain" ;
lv2:default 1.0 ;
lv2:minimum 0.0 ;
lv2:maximum 2.0 ;
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 2 ;
lv2:index 3 ;
lv2:symbol "out_1" ;
lv2:name "Out 1"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 3 ;
lv2:index 4 ;
lv2:symbol "out_2" ;
lv2:name "Out 2"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 4 ;
lv2:index 5 ;
lv2:symbol "out_3" ;
lv2:name "Out 3"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 5 ;
lv2:index 6 ;
lv2:symbol "out_4" ;
lv2:name "Out 4"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 6 ;
lv2:index 7 ;
lv2:symbol "out_5" ;
lv2:name "Out 5"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 7 ;
lv2:index 8 ;
lv2:symbol "out_6" ;
lv2:name "Out 6"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 8 ;
lv2:index 9 ;
lv2:symbol "out_7" ;
lv2:name "Out 7"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 9 ;
lv2:index 10 ;
lv2:symbol "out_8" ;
lv2:name "Out 8"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 10 ;
lv2:index 11 ;
lv2:symbol "out_9" ;
lv2:name "Out 9"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 11 ;
lv2:index 12 ;
lv2:symbol "out_10" ;
lv2:name "Out 10"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 12 ;
lv2:index 13 ;
lv2:symbol "out_11" ;
lv2:name "Out 11"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 13 ;
lv2:index 14 ;
lv2:symbol "out_12" ;
lv2:name "Out 12"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 14 ;
lv2:index 15 ;
lv2:symbol "out_13" ;
lv2:name "Out 13"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 15 ;
lv2:index 16 ;
lv2:symbol "out_14" ;
lv2:name "Out 14"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 16 ;
lv2:index 17 ;
lv2:symbol "out_15" ;
lv2:name "Out 15"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 17 ;
lv2:index 18 ;
lv2:symbol "out_16" ;
lv2:name "Out 16"
] ;
......
......@@ -35,16 +35,25 @@
lv2:index 1 ;
lv2:symbol "notify" ;
lv2:name "Notify" ;
] , [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 2 ;
lv2:symbol "gain" ;
lv2:name "Gain" ;
lv2:default 1.0 ;
lv2:minimum 0.0 ;
lv2:maximum 2.0 ;
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 2 ;
lv2:index 3 ;
lv2:symbol "out_l" ;
lv2:name "Out Left"
] , [
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 3 ;
lv2:index 4 ;
lv2:symbol "out_r" ;
lv2:name "Out Right"
] ;
......
......@@ -36,7 +36,7 @@ static LV2UI_Handle instantiate(const LV2UI_Descriptor *descriptor, const char *
static void port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size,
uint32_t format, const void *buffer) {
((PluginUi *)handle)->portEvent(format, (const LV2_Atom *)buffer);
((PluginUi *)handle)->portEvent(port_index, format, buffer);
}
static void cleanup(LV2UI_Handle handle) {}
......
......@@ -86,8 +86,10 @@ void Plugin::connectPort(uint32_t port, void *data) {
midiinput = (const LV2_Atom_Sequence *)data;
} else if (port == 1) {
uioutput = (LV2_Atom_Sequence *)data;
} else if (port == 2) {
controlin = (float*)data;
} else {
outputPort[port - 2] = (float *)data;
outputPort[port - 3] = (float *)data;
}
}
......@@ -508,6 +510,7 @@ void Plugin::run(uint32_t sampleCount) {
for (uint16_t i = 0; i < channelCount; i++) {
memset(outputPort[i], 0, sampleCount * sizeof(float));
}
float gain = controlin[0];
// loop over active samples
bool inactive = inactiveList != nullptr;
......@@ -520,7 +523,7 @@ void Plugin::run(uint32_t sampleCount) {
uint64_t end = std::min(play.remaining() + start, (uint64_t)sampleCount);
// add overlap
for (uint64_t i = start; i < end; i++) {
outputPort[channel][i] += play.next();
outputPort[channel][i] += play.next() * gain;
}
if (play.finished()) {
// shrink maxActive if possible
......
......@@ -163,6 +163,7 @@ class Plugin {
bool mactivated;
const LV2_Atom_Sequence *midiinput;
float **outputPort;
float *controlin;
LV2_URID_Map *map;
HandrumrLV2URIs uris;
uint16_t channelCount;
......
......@@ -40,6 +40,10 @@ static void on_open_response(GtkDialog *dialog, int response, void *handle) {
static void on_openbutton_click(GtkButton *, void *handle) { gtk_widget_show((GtkWidget *)handle); }
static void on_gain_change(GtkRange *, void *handle) {
((PluginUi *)handle)->mainGainChange();
}
PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
LV2UI_Controller controller, LV2UI_Write_Function writefunc)
: mcontroller(controller), write(writefunc) {
......@@ -132,9 +136,15 @@ PluginUi::PluginUi(const LV2_Feature *const *features, LV2UI_Widget *widget,
gtk_box_pack_start(GTK_BOX(lastBox), instLabel, FALSE, FALSE, 4);
gtk_box_pack_start(GTK_BOX(lastBox), instEntryWidget, FALSE, FALSE, 4);
// volume
GtkObject *adjustment = gtk_adjustment_new(1.0, 0.0, 2.0, 0.05, 0, 0);
mainGain = gtk_hscale_new(GTK_ADJUSTMENT(adjustment));
g_signal_connect(mainGain, "value-changed", G_CALLBACK(on_gain_change), this);
GtkWidget *outerBox = gtk_vbox_new(0, 0);
gtk_box_pack_start(GTK_BOX(outerBox), treeview, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(outerBox), buttonRow, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(outerBox), mainGain, FALSE, FALSE, 3);
gtk_box_pack_start(GTK_BOX(outerBox), gtk_hseparator_new(), FALSE, FALSE, 3);
gtk_box_pack_start(GTK_BOX(outerBox), lastBox, FALSE, FALSE, 3);
*widget = outerBox;
......@@ -148,8 +158,15 @@ void PluginUi::showError(const char *mesg) {
gtk_widget_destroy(GTK_WIDGET(dialog));
}
void PluginUi::portEvent(uint32_t format, const LV2_Atom *atom) {
void PluginUi::portEvent(uint32_t port, uint32_t format, const void *buffer) {
if(port == 1) {
notify(format, (const LV2_Atom *)buffer);
} else if(port == 2) {
gtk_range_set_value(GTK_RANGE(mainGain), *static_cast<const float*>(buffer));
}
}
void PluginUi::notify(uint32_t format, const LV2_Atom *atom) {
if (format == uris.atom_eventTransfer && lv2_atom_forge_is_object_type(&forge, atom->type)) {
const LV2_Atom_Object *obj = (const LV2_Atom_Object *)atom;
if (obj->body.otype == uris.ui_Last) {
......@@ -238,4 +255,10 @@ void PluginUi::openConfig(const char *filepath) {
void PluginUi::enableRemove(bool enable) { gtk_widget_set_sensitive(removeButton, enable); }
void PluginUi::mainGainChange()
{
float value = static_cast<float>(gtk_range_get_value(GTK_RANGE(mainGain)));
write(mcontroller, 2, sizeof(float), 0, &value);
}
} // namespace handrumr
......@@ -36,6 +36,7 @@ class PluginUi {
GtkWidget *removeButton;
GtkWidget *mopendialog;
GtkTreeStore *treestore;
GtkWidget *mainGain;
// last note widgets
GtkEntry *lastEntry;
GtkEntry *velEntry;
......@@ -47,12 +48,14 @@ class PluginUi {
public:
PluginUi(const LV2_Feature *const *, LV2UI_Widget *widget, LV2UI_Controller controller,
LV2UI_Write_Function writefunc);
void portEvent(uint32_t format, const LV2_Atom *atom);
void portEvent(uint32_t port, uint32_t format, const void *buffer);
void openConfig(const char *filepath);
void enableRemove(bool enable);
void mainGainChange();
private:
void showError(const char *mesg);
void notify(uint32_t format, const LV2_Atom *atom);
};
} // namespace handrumr
......
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