282 lines
8.5 KiB
C++
282 lines
8.5 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include <gtkmm/filechooserdialog.h>
|
|
#include <gtkmm/menu.h>
|
|
#include <gtkmm/menuitem.h>
|
|
#include <gtkmm/stock.h>
|
|
|
|
#include "pbd/compose.h"
|
|
#include "pbd/convert.h"
|
|
|
|
#include "ardour/region.h"
|
|
#include "ardour/triggerbox.h"
|
|
|
|
#include "canvas/constrained_item.h"
|
|
#include "canvas/polygon.h"
|
|
#include "canvas/text.h"
|
|
#include "canvas/widget.h"
|
|
|
|
#include "widgets/ardour_button.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
#include "ardour_ui.h"
|
|
#include "gui_thread.h"
|
|
#include "trigger_ui.h"
|
|
#include "public_editor.h"
|
|
#include "ui_config.h"
|
|
#include "utils.h"
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
using namespace ARDOUR;
|
|
using namespace ArdourCanvas;
|
|
using namespace ArdourWidgets;
|
|
using namespace Gtkmm2ext;
|
|
using namespace PBD;
|
|
using namespace Temporal;
|
|
|
|
static std::vector<std::string> follow_strings;
|
|
static std::string longest_follow;
|
|
static std::vector<std::string> quantize_strings;
|
|
static std::string longest_quantize;
|
|
|
|
TriggerUI::TriggerUI (Item* parent, Trigger& t)
|
|
: Table (parent)
|
|
, trigger (t)
|
|
{
|
|
if (follow_strings.empty()) {
|
|
follow_strings.push_back (follow_action_to_string (Trigger::Stop));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::Again));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::QueuedTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::NextTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::PrevTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::FirstTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::LastTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::AnyTrigger));
|
|
follow_strings.push_back (follow_action_to_string (Trigger::OtherTrigger));
|
|
|
|
for (std::vector<std::string>::const_iterator i = follow_strings.begin(); i != follow_strings.end(); ++i) {
|
|
if (i->length() > longest_follow.length()) {
|
|
longest_follow = *i;
|
|
}
|
|
}
|
|
|
|
quantize_strings.push_back (_("Global"));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (1, 0)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (2, 0)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (4, 0)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (0, Temporal::ticks_per_beat/2)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (0, Temporal::ticks_per_beat/4)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (0, Temporal::ticks_per_beat/8)));
|
|
quantize_strings.push_back (quantize_length_to_string (Beats (0, Temporal::ticks_per_beat/16)));
|
|
|
|
for (std::vector<std::string>::const_iterator i = quantize_strings.begin(); i != quantize_strings.end(); ++i) {
|
|
if (i->length() > longest_quantize.length()) {
|
|
longest_quantize = *i;
|
|
}
|
|
}
|
|
}
|
|
|
|
name = "TriggerUI-CP";
|
|
|
|
_follow_action_button = new ArdourButton ();
|
|
_follow_action_button->set_text (_("Follow Action"));
|
|
|
|
follow_action_button = new ArdourCanvas::Widget (canvas(), *_follow_action_button);
|
|
follow_action_button->name = "FollowAction";
|
|
_follow_action_button->signal_event().connect (sigc::mem_fun (*this, (&TriggerUI::follow_action_button_event)));
|
|
|
|
_follow_left = new ArdourDropdown;
|
|
_follow_left->append_text_item (_("None"));
|
|
_follow_left->append_text_item (_("Repeat"));
|
|
_follow_left->append_text_item (_("Next"));
|
|
_follow_left->append_text_item (_("Previous"));
|
|
_follow_left->set_sizing_text (longest_follow);
|
|
|
|
follow_left = new Widget (canvas(), *_follow_left);
|
|
follow_left->name = "FollowLeft";
|
|
|
|
_follow_right = new ArdourDropdown;
|
|
_follow_right->append_text_item (_("None"));
|
|
_follow_right->append_text_item (_("Repeat"));
|
|
_follow_right->append_text_item (_("Next"));
|
|
_follow_right->append_text_item (_("Previous"));
|
|
_follow_right->set_sizing_text (longest_follow);
|
|
|
|
follow_right = new Widget (canvas(), *_follow_right);
|
|
follow_right->name = "FollowRight";
|
|
|
|
_legato_button = new ArdourButton();
|
|
_legato_button->set_text (_("Legato"));
|
|
legato_button = new ArdourCanvas::Widget (canvas(), *_legato_button);
|
|
|
|
_quantize_button = new ArdourDropdown;
|
|
for (std::vector<std::string>::const_iterator s = quantize_strings.begin(); s != quantize_strings.end(); ++s) {
|
|
_quantize_button->append_text_item (*s);
|
|
}
|
|
quantize_button = new Widget (canvas(), *_quantize_button);
|
|
quantize_button->name = "quantize";
|
|
|
|
const double scale = UIConfiguration::instance().get_ui_scale();
|
|
const Distance spacing = 12. * scale;
|
|
|
|
attach (follow_action_button, 0, 0, 2, 1, PackExpand, PackExpand, { 10 });
|
|
attach (follow_left, 0, 1, 1, 2, PackExpand, PackExpand, { 10 });
|
|
attach (follow_right, 1, 1, 2, 2, PackExpand, PackExpand, { 10 });
|
|
|
|
attach (quantize_button, 0, 2, 1, 3, PackExpand, PackExpand, { 10 });
|
|
attach (legato_button, 1, 2, 2, 3, PackExpand, PackExpand, { 10 });
|
|
|
|
set_fill_color (UIConfiguration::instance().color (X_("theme:bg")));
|
|
name = "triggerUI-table";
|
|
|
|
PropertyChange pc;
|
|
|
|
pc.add (Properties::use_follow);
|
|
pc.add (Properties::legato);
|
|
|
|
trigger_changed (pc);
|
|
|
|
trigger.PropertyChanged.connect (trigger_connections, invalidator (*this), boost::bind (&TriggerUI::trigger_changed, this, _1), gui_context());
|
|
}
|
|
|
|
TriggerUI::~TriggerUI ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
TriggerUI::follow_action_button_event (GdkEvent* ev)
|
|
{
|
|
switch (ev->type) {
|
|
case GDK_BUTTON_PRESS:
|
|
trigger.set_use_follow (!trigger.use_follow());
|
|
return true;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
std::string
|
|
TriggerUI::quantize_length_to_string (Beats const & ql)
|
|
{
|
|
if (ql == Beats (1, 0)) {
|
|
return _("1/4");
|
|
} else if (ql == Beats (2, 0)) {
|
|
return _("1/2");
|
|
} else if (ql == Beats (4, 0)) {
|
|
return _("Whole");
|
|
} else if (ql == Beats (0,Temporal::ticks_per_beat/2)) {
|
|
return _("1/8");
|
|
} else if (ql == Beats (0,Temporal::ticks_per_beat/4)) {
|
|
return _("1/16");
|
|
} else if (ql == Beats (0,Temporal::ticks_per_beat/8)) {
|
|
return _("1/32");
|
|
} else if (ql == Beats (0,Temporal::ticks_per_beat/16)) {
|
|
return _("1/64");
|
|
} else {
|
|
return "???";
|
|
}
|
|
}
|
|
|
|
std::string
|
|
TriggerUI::follow_action_to_string (Trigger::FollowAction fa)
|
|
{
|
|
switch (fa) {
|
|
case Trigger::Stop:
|
|
return _("Stop");
|
|
case Trigger::Again:
|
|
return _("Again");
|
|
case Trigger::QueuedTrigger:
|
|
return _("Queued");
|
|
case Trigger::NextTrigger:
|
|
return _("Next");
|
|
case Trigger::PrevTrigger:
|
|
return _("Prev");
|
|
case Trigger::FirstTrigger:
|
|
return _("First");
|
|
case Trigger::LastTrigger:
|
|
return _("Last");
|
|
case Trigger::AnyTrigger:
|
|
return _("Any");
|
|
case Trigger::OtherTrigger:
|
|
return _("Other");
|
|
}
|
|
/*NOTREACHED*/
|
|
return std::string();
|
|
}
|
|
|
|
void
|
|
TriggerUI::trigger_changed (PropertyChange pc)
|
|
{
|
|
if (pc.contains (Properties::use_follow)) {
|
|
_follow_action_button->set_active_state (trigger.use_follow() ? Gtkmm2ext::ExplicitActive : Gtkmm2ext::Off);
|
|
}
|
|
_follow_right->set_text (follow_action_to_string (trigger.follow_action (0)));
|
|
_follow_left->set_text (follow_action_to_string (trigger.follow_action (1)));
|
|
}
|
|
|
|
/* ------------ */
|
|
|
|
TriggerWidget::TriggerWidget (Trigger& t)
|
|
{
|
|
ui = new TriggerUI (root(), t);
|
|
set_background_color (UIConfiguration::instance().color (X_("theme:bg")));
|
|
}
|
|
|
|
void
|
|
TriggerWidget::size_request (double& w, double& h) const
|
|
{
|
|
ui->size_request (w, h);
|
|
}
|
|
|
|
/* ------------ */
|
|
|
|
TriggerWindow::TriggerWindow (Trigger& t)
|
|
{
|
|
TriggerWidget* tw = manage (new TriggerWidget (t));
|
|
set_title (string_compose (_("Trigger: %1"), t.name()));
|
|
|
|
double w;
|
|
double h;
|
|
|
|
tw->show ();
|
|
tw->size_request (w, h);
|
|
set_default_size (w, h);
|
|
std::cerr << "TW: set default win size to " << w << " x " << h << std::endl;
|
|
add (*tw);
|
|
}
|
|
|
|
bool
|
|
TriggerWindow::on_key_press_event (GdkEventKey* ev)
|
|
{
|
|
Gtk::Window& main_window (ARDOUR_UI::instance()->main_window());
|
|
return ARDOUR_UI_UTILS::relay_key_press (ev, &main_window);
|
|
}
|
|
|
|
bool
|
|
TriggerWindow::on_key_release_event (GdkEventKey* ev)
|
|
{
|
|
Gtk::Window& main_window (ARDOUR_UI::instance()->main_window());
|
|
return ARDOUR_UI_UTILS::relay_key_press (ev, &main_window);
|
|
}
|