From ccf1c4fb5772abbeccecc664e2f5e4b948f72087 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 27 Jul 2021 20:39:55 -0600 Subject: [PATCH] some incredibly hasic functionality for the triggerbox UI --- gtk2_ardour/triggerbox_ui.cc | 64 +++++++++++++++++++++++++++--------- gtk2_ardour/triggerbox_ui.h | 12 ++++++- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/gtk2_ardour/triggerbox_ui.cc b/gtk2_ardour/triggerbox_ui.cc index 9582d953d6..0eb9c97798 100644 --- a/gtk2_ardour/triggerbox_ui.cc +++ b/gtk2_ardour/triggerbox_ui.cc @@ -17,8 +17,13 @@ */ #include "pbd/i18n.h" +#include "pbd/compose.h" + #include "ardour/triggerbox.h" +#include "canvas/polygon.h" +#include "canvas/text.h" + #include "gtkmm2ext/utils.h" #include "triggerbox_ui.h" @@ -36,26 +41,32 @@ TriggerEntry::TriggerEntry (Item* parent, ARDOUR::Trigger& t) set_outline_all (); set_fill_color (Gtkmm2ext::random_color()); set_outline_color (Gtkmm2ext::random_color()); + name = string_compose ("trigger %1", _trigger.index()); + + play_button = new Polygon (this); + + Points p; + p.push_back (Duple (0, 0)); + p.push_back (Duple (0, 10)); + p.push_back (Duple (10, 5)); + + play_button->set (p); + play_button->set_fill_color (Gtkmm2ext::random_color()); + play_button->set_outline (false); + + play_button->set_position (Duple (10, 2)); + + name_text = new Text (this); + name_text->set_font_description (Pango::FontDescription ("Sans 10")); + name_text->set ("Bang Crash"); + name_text->set_color (Gtkmm2ext::random_color()); + name_text->set_position (Duple (50, name_text->height() / 2)); } TriggerEntry::~TriggerEntry () { } -void -TriggerEntry::render (Rect const & area, Cairo::RefPtr context) const -{ - /* convert expose area back to item coordinate space */ - - Rect self (item_to_window (get())); - - setup_outline_context (context); - rounded_rectangle (context, self.x0, self.y0, self.width(), self.height()); - context->stroke_preserve (); - setup_fill_context (context); - context->fill (); -} - /* ---------------------------- */ TriggerBoxUI::TriggerBoxUI (ArdourCanvas::Item* parent, TriggerBox& tb) @@ -82,17 +93,40 @@ TriggerBoxUI::build () // clear_items (true); + _slots.clear (); + while (true) { t = _triggerbox.trigger (n); if (!t) { break; } std::cerr << "NEW TE for trigger " << n << std::endl; - (void) new TriggerEntry (this, *t); + TriggerEntry* te = new TriggerEntry (this, *t); + + _slots.push_back (te); + + te->play_button->Event.connect (sigc::bind (sigc::mem_fun (*this, &TriggerBoxUI::bang), n)); + ++n; } } +bool +TriggerBoxUI::bang (GdkEvent *ev, size_t n) +{ + switch (ev->type) { + case GDK_BUTTON_PRESS: + if (ev->button.button == 1) { + _triggerbox.queue_trigger (&_slots[n]->trigger()); + return true; + } + break; + default: + break; + } + return false; +} + /* ------------ */ TriggerBoxWidget::TriggerBoxWidget (TriggerBox& tb) diff --git a/gtk2_ardour/triggerbox_ui.h b/gtk2_ardour/triggerbox_ui.h index ace3367c00..c3be0a49c9 100644 --- a/gtk2_ardour/triggerbox_ui.h +++ b/gtk2_ardour/triggerbox_ui.h @@ -32,6 +32,11 @@ namespace ARDOUR { class TriggerBox; } +namespace ArdourCanvas { + class Text; + class Polygon; +}; + class TriggerEntry : public ArdourCanvas::Rectangle { public: @@ -39,7 +44,9 @@ class TriggerEntry : public ArdourCanvas::Rectangle ~TriggerEntry (); ARDOUR::Trigger& trigger() const { return _trigger; } - void render (ArdourCanvas::Rect const &, Cairo::RefPtr) const; + + ArdourCanvas::Polygon* play_button; + ArdourCanvas::Text* name_text; private: ARDOUR::Trigger& _trigger; @@ -53,7 +60,10 @@ class TriggerBoxUI : public ArdourCanvas::Box private: ARDOUR::TriggerBox& _triggerbox; + typedef std::vector Slots; + Slots _slots; + bool bang (GdkEvent*, size_t); void build (); };