#include <gtkmm.h>
#include <lvtk/ui.hpp>
#include "silence.h"
using namespace Gtk;
using namespace sigc;
using Glib::ustring;
struct midi_t {
LV2_Atom atom;
uint8_t midi[3];
};
class SilenceGtk :
public UI<SilenceGtk, URID<true> >
{
public:
SilenceGtk (const char* plugin_uri)
{
Gtk::Main::init_gtkmm_internals();
p_hbox = new Gtk::HBox();
if (p_hbox) {
Button *btn = manage (new Button(ustring("Silence")));
btn->signal_pressed().connect(
mem_fun(*this, &SilenceGtk::send_note_on));
btn->signal_released().connect(
mem_fun(*this, &SilenceGtk::send_note_off));
p_hbox->pack_start (*btn);
} else {
p_hbox = 0;
}
}
LV2UI_Widget*
widget()
{
if (p_hbox) {
return widget_cast (p_hbox->gobj());
}
return NULL;
}
protected:
void
send_note_on()
{
LV2_URID xfer = map(LV2_ATOM__eventTransfer);
LV2_URID midiEvent = map(LV2_MIDI__MidiEvent);
midi_t midi = {{3, midiEvent}, { 0x90, 0x40, 0x40 }};
write (p_midi, sizeof(midi), xfer, (void*)&midi);
}
void
send_note_off()
{
LV2_URID xfer = map(LV2_ATOM__eventTransfer);
LV2_URID midiEvent = map(LV2_MIDI__MidiEvent);
midi_t midi = {{3, midiEvent},{ 0x80, 0x40, 0x40 }};
write (p_midi, sizeof(midi), xfer, (void*)&midi);
}
private:
Gtk::HBox *p_hbox;
};
int _ = SilenceGtk::register_class ("http://lvtoolkit.org/plugins/silence#ui");