2021-07-21 18:44:41 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2021-07-22 12:33:47 -04:00
|
|
|
#include "pbd/i18n.h"
|
2021-07-27 22:39:55 -04:00
|
|
|
#include "pbd/compose.h"
|
2021-07-28 00:40:35 -04:00
|
|
|
#include "pbd/convert.h"
|
2021-07-27 22:39:55 -04:00
|
|
|
|
2021-07-28 00:40:35 -04:00
|
|
|
#include "ardour/region.h"
|
2021-07-21 19:22:09 -04:00
|
|
|
#include "ardour/triggerbox.h"
|
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
#include "canvas/polygon.h"
|
|
|
|
#include "canvas/text.h"
|
|
|
|
|
2021-07-21 19:22:09 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2021-07-21 18:44:41 -04:00
|
|
|
#include "triggerbox_ui.h"
|
2021-07-28 00:40:35 -04:00
|
|
|
#include "ui_config.h"
|
2021-07-21 18:44:41 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace ArdourCanvas;
|
2021-07-21 19:22:09 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2021-07-28 00:40:35 -04:00
|
|
|
using namespace PBD;
|
2021-07-21 18:44:41 -04:00
|
|
|
|
|
|
|
TriggerEntry::TriggerEntry (Item* parent, ARDOUR::Trigger& t)
|
|
|
|
: Rectangle (parent)
|
|
|
|
, _trigger (t)
|
|
|
|
{
|
2021-07-28 00:40:35 -04:00
|
|
|
const double scale = UIConfiguration::instance().get_ui_scale();
|
|
|
|
const double width = 150. * scale;
|
|
|
|
const double height = 20. * scale;
|
|
|
|
|
|
|
|
Rect r (0, 0, width, height);
|
2021-07-21 19:22:09 -04:00
|
|
|
set (r);
|
|
|
|
set_outline_all ();
|
2021-07-27 19:08:31 -04:00
|
|
|
set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
set_outline_color (Gtkmm2ext::random_color());
|
2021-07-27 22:39:55 -04:00
|
|
|
name = string_compose ("trigger %1", _trigger.index());
|
2021-07-21 18:44:41 -04:00
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
play_button = new Polygon (this);
|
2021-07-21 18:44:41 -04:00
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
Points p;
|
2021-07-28 00:40:35 -04:00
|
|
|
const double triangle_size = height - (8. * scale);
|
|
|
|
p.push_back (Duple (0., 0.));
|
|
|
|
p.push_back (Duple (0., triangle_size));
|
|
|
|
p.push_back (Duple (triangle_size, triangle_size / 2.));
|
2021-07-27 22:39:55 -04:00
|
|
|
|
|
|
|
play_button->set (p);
|
|
|
|
play_button->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
play_button->set_outline (false);
|
2021-07-21 19:22:09 -04:00
|
|
|
|
2021-07-28 00:40:35 -04:00
|
|
|
play_button->set_position (Duple (10. * scale, 4. * scale));
|
2021-07-27 22:39:55 -04:00
|
|
|
|
|
|
|
name_text = new Text (this);
|
2021-07-28 00:40:35 -04:00
|
|
|
name_text->set_font_description (UIConfiguration::instance().get_NormalFont());
|
|
|
|
name_text->set (short_version (_trigger.region()->name(), 20));
|
|
|
|
name_text->set_color (Gtkmm2ext::contrasting_text_color (fill_color()));
|
|
|
|
name_text->set_position (Duple (50, 4. * scale));
|
2021-07-27 22:39:55 -04:00
|
|
|
}
|
2021-07-27 19:08:31 -04:00
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
TriggerEntry::~TriggerEntry ()
|
|
|
|
{
|
2021-07-21 19:22:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------- */
|
|
|
|
|
|
|
|
TriggerBoxUI::TriggerBoxUI (ArdourCanvas::Item* parent, TriggerBox& tb)
|
2021-07-21 18:44:41 -04:00
|
|
|
: Box (parent, Box::Vertical)
|
2021-07-21 19:22:09 -04:00
|
|
|
, _triggerbox (tb)
|
2021-07-21 18:44:41 -04:00
|
|
|
{
|
2021-07-21 19:22:09 -04:00
|
|
|
set_homogenous (true);
|
2021-07-27 19:08:31 -04:00
|
|
|
set_spacing (16);
|
|
|
|
set_padding (16);
|
|
|
|
set_fill (false);
|
2021-07-21 19:22:09 -04:00
|
|
|
|
|
|
|
build ();
|
2021-07-21 18:44:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TriggerBoxUI::~TriggerBoxUI ()
|
|
|
|
{
|
|
|
|
}
|
2021-07-21 19:22:09 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
TriggerBoxUI::build ()
|
|
|
|
{
|
|
|
|
Trigger* t;
|
|
|
|
size_t n = 0;
|
|
|
|
|
2021-07-22 12:33:47 -04:00
|
|
|
// clear_items (true);
|
2021-07-21 19:22:09 -04:00
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
_slots.clear ();
|
|
|
|
|
2021-07-21 19:22:09 -04:00
|
|
|
while (true) {
|
|
|
|
t = _triggerbox.trigger (n);
|
|
|
|
if (!t) {
|
|
|
|
break;
|
|
|
|
}
|
2021-07-22 12:33:47 -04:00
|
|
|
std::cerr << "NEW TE for trigger " << n << std::endl;
|
2021-07-27 22:39:55 -04:00
|
|
|
TriggerEntry* te = new TriggerEntry (this, *t);
|
|
|
|
|
|
|
|
_slots.push_back (te);
|
|
|
|
|
|
|
|
te->play_button->Event.connect (sigc::bind (sigc::mem_fun (*this, &TriggerBoxUI::bang), n));
|
|
|
|
|
2021-07-27 19:08:31 -04:00
|
|
|
++n;
|
2021-07-21 19:22:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 22:39:55 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:22:09 -04:00
|
|
|
/* ------------ */
|
|
|
|
|
|
|
|
TriggerBoxWidget::TriggerBoxWidget (TriggerBox& tb)
|
|
|
|
{
|
|
|
|
ui = new TriggerBoxUI (root(), tb);
|
|
|
|
}
|
2021-07-22 12:33:47 -04:00
|
|
|
|
2021-07-28 00:40:35 -04:00
|
|
|
void
|
|
|
|
TriggerBoxWidget::size_request (double& w, double& h) const
|
|
|
|
{
|
|
|
|
ui->size_request (w, h);
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:33:47 -04:00
|
|
|
/* ------------ */
|
|
|
|
|
|
|
|
TriggerBoxWindow::TriggerBoxWindow (TriggerBox& tb)
|
|
|
|
{
|
|
|
|
TriggerBoxWidget* tbw = manage (new TriggerBoxWidget (tb));
|
|
|
|
set_title (_("TriggerBox for XXXX"));
|
2021-07-28 00:40:35 -04:00
|
|
|
|
|
|
|
double w;
|
|
|
|
double h;
|
|
|
|
|
|
|
|
tbw->size_request (w, h);
|
|
|
|
|
|
|
|
set_default_size (w, h);
|
2021-07-22 12:33:47 -04:00
|
|
|
add (*tbw);
|
|
|
|
tbw->show ();
|
|
|
|
}
|