Implement TriggerStrip and TriggerPage (WIP)

This commit is contained in:
Robin Gareus 2021-11-11 01:15:00 +01:00
parent 9ce604bc03
commit 59b012ddb0
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 646 additions and 7 deletions

View File

@ -22,21 +22,26 @@
#include <gtkmm/label.h>
#include "pbd/properties.h"
#include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/keyboard.h"
#include "gtkmm2ext/window_title.h"
#include "actions.h"
#include "ardour_ui.h"
#include "gui_thread.h"
#include "public_editor.h"
#include "timers.h"
#include "trigger_page.h"
#include "trigger_strip.h"
#include "ui_config.h"
#include "utils.h"
#include "pbd/i18n.h"
#define PX_SCALE(px) std::max ((float)px, rintf ((float)px* UIConfiguration::instance ().get_ui_scale ()))
using namespace ARDOUR;
using namespace Gtkmm2ext;
using namespace Gtk;
@ -48,19 +53,70 @@ TriggerPage::TriggerPage ()
load_bindings ();
register_actions ();
/* Top-level VBox */
Label* l = manage (new Label ("Hello World!"));
_content.pack_start (*l, true, true);
#if 1 /* Placeholders */
_slot_area_box.pack_start (*Gtk::manage (new Gtk::Label ("Fixed\nWidth\nSlot\nArea")));
_browser_box.pack_start (*Gtk::manage (new Gtk::Label ("File Browser")));
_parameter_box.pack_start (*Gtk::manage (new Gtk::Label ("Parameter HBox")));
_slot_area_box.show_all ();
_browser_box.show_all ();
_parameter_box.show_all ();
#endif
/* Upper pane (slot | strips | file browser) */
_strip_scroller.add (_strip_packer);
_strip_scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
/* last item of strip packer */
_strip_packer.pack_end (_no_strips, true, true);
_no_strips.set_size_request (PX_SCALE (60), -1);
_no_strips.signal_expose_event().connect (sigc::bind (sigc::ptr_fun(&ArdourWidgets::ArdourIcon::expose), &_no_strips, ArdourWidgets::ArdourIcon::CloseCross));
_strip_group_box.pack_start (_slot_area_box, false, false);
_strip_group_box.pack_start (_strip_scroller, true, true);
_pane_upper.add (_strip_group_box);
_pane_upper.add (_browser_box);
/* Top-level Layout */
_pane.add (_pane_upper);
_pane.add (_parameter_box);
_content.pack_start (_pane, true, true);
_content.show ();
/* Show all */
_pane.show ();
_pane_upper.show ();
_strip_group_box.show ();
_strip_scroller.show ();
_strip_packer.show ();
_slot_area_box.show ();
_browser_box.show ();
_parameter_box.show ();
/* setup keybidings */
_content.set_data ("ardour-bindings", bindings);
/* subscribe to signals */
Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&TriggerPage::parameter_changed, this, _1), gui_context ());
PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&TriggerPage::pi_property_changed, this, _1), gui_context ());
/* init */
update_title ();
/* Restore pane state */
float fract;
XMLNode const* settings = ARDOUR_UI::instance ()->trigger_page_settings ();
if (!settings || !settings->get_property ("triggerpage-vpane-pos", fract) || fract > 1.0) {
fract = 0.75f;
}
_pane.set_divider (0, fract);
if (!settings || !settings->get_property ("triggerpage-hpane-pos", fract) || fract > 1.0) {
fract = 0.75f;
}
_pane_upper.set_divider (0, fract);
}
TriggerPage::~TriggerPage ()
@ -96,6 +152,9 @@ TriggerPage::get_state ()
{
XMLNode* node = new XMLNode (X_("TriggerPage"));
node->add_child_nocopy (Tabbable::get_state ());
node->set_property (X_("triggerpage-vpane-pos"), _pane.get_divider ());
node->set_property (X_("triggerpage-hpane-pos"), _pane_upper.get_divider ());
return *node;
}
@ -126,21 +185,38 @@ TriggerPage::set_session (Session* s)
return;
}
XMLNode* node = ARDOUR_UI::instance()->trigger_page_settings ();
XMLNode* node = ARDOUR_UI::instance ()->trigger_page_settings ();
set_state (*node, Stateful::loading_state_version);
_session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&TriggerPage::update_title, this), gui_context ());
_session->StateSaved.connect (_session_connections, invalidator (*this), boost::bind (&TriggerPage::update_title, this), gui_context ());
_session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&TriggerPage::add_routes, this, _1), gui_context ());
TriggerStrip::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TriggerPage::remove_route, this, _1), gui_context ());
_session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&TriggerPage::parameter_changed, this, _1), gui_context ());
initial_track_display ();
update_title ();
start_updating ();
}
void
TriggerPage::session_going_away ()
{
ENSURE_GUI_THREAD (*this, &TriggerPage::session_going_away);
stop_updating ();
#if 0
/* DropReferneces calls RouteUI::self_delete -> CatchDeletion .. */
for (list<TriggerStrip*>::iterator i = _strips.begin(); i != _strips.end(); ++i) {
delete (*i);
}
#endif
_strips.clear ();
SessionHandlePtr::session_going_away ();
update_title ();
}
@ -177,7 +253,149 @@ TriggerPage::update_title ()
}
}
void
TriggerPage::initial_track_display ()
{
boost::shared_ptr<RouteList> r = _session->get_tracks ();
RouteList rl (*r);
_strips.clear ();
add_routes (rl);
}
void
TriggerPage::add_routes (RouteList& rl)
{
rl.sort (Stripable::Sorter ());
for (RouteList::iterator r = rl.begin (); r != rl.end (); ++r) {
/* we're only interested in Tracks */
if (!boost::dynamic_pointer_cast<Track> (*r)) {
continue;
}
#if 0
/* TODO, only subscribe to PropertyChanged, create (and destory) TriggerStrip as needed.
* For now we just hide non trigger strips.
*/
if (!(*r)->presentation_info ().trigger_track ()) {
continue;
}
#endif
if (!(*r)->triggerbox()) {
/* This Route has no TriggerBox -- and can never have one */
continue;
}
TriggerStrip* ts = new TriggerStrip (_session, *r);
_strips.push_back (ts);
(*r)->presentation_info ().PropertyChanged.connect (*this, invalidator (*this), boost::bind (&TriggerPage::stripable_property_changed, this, _1, boost::weak_ptr<Stripable> (*r)), gui_context ());
(*r)->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&TriggerPage::stripable_property_changed, this, _1, boost::weak_ptr<Stripable> (*r)), gui_context ());
}
redisplay_track_list ();
}
void
TriggerPage::remove_route (TriggerStrip* ra)
{
if (!_session || _session->deletion_in_progress ()) {
_strips.clear ();
return;
}
list<TriggerStrip*>::iterator i = find (_strips.begin (), _strips.end (), ra);
if (i != _strips.end ()) {
_strip_packer.remove (**i);
_strips.erase (i);
}
redisplay_track_list ();
}
void
TriggerPage::redisplay_track_list ()
{
bool visible_triggers = false;
for (list<TriggerStrip*>::iterator i = _strips.begin (); i != _strips.end (); ++i) {
TriggerStrip* strip = *i;
boost::shared_ptr<Stripable> s = strip->stripable ();
boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (s);
bool hidden = s->presentation_info ().hidden ();
if (!(s)->presentation_info ().trigger_track ()) {
hidden = true;
}
assert (route && route->triggerbox());
if (!route || !route->triggerbox()) {
hidden = true;
}
if (hidden && strip->get_parent ()) {
/* if packed, remove it */
_strip_packer.remove (*strip);
} else if (!hidden && strip->get_parent ()) {
/* already packed, put it at the end */
_strip_packer.reorder_child (*strip, -1); /* put at end */
visible_triggers = true;
} else if (!hidden) {
_strip_packer.pack_start (*strip, false, false);
visible_triggers = true;
}
}
if (visible_triggers) {
_no_strips.hide ();
} else {
_no_strips.show ();
}
}
void
TriggerPage::parameter_changed (string const& p)
{
}
void
TriggerPage::pi_property_changed (PBD::PropertyChange const& what_changed)
{
/* static signal, not yet used */
}
void
TriggerPage::stripable_property_changed (PBD::PropertyChange const& what_changed, boost::weak_ptr<Stripable> ws)
{
if (what_changed.contains (ARDOUR::Properties::trigger_track)) {
#if 0
boost::shared_ptr<Stripable> s = ws.lock ();
/* TODO: find trigger-strip for given stripable, delete *it; */
#else
/* For now we just hide it */
redisplay_track_list ();
return;
#endif
}
if (what_changed.contains (ARDOUR::Properties::hidden)) {
redisplay_track_list ();
}
}
gint
TriggerPage::start_updating ()
{
_fast_screen_update_connection = Timers::super_rapid_connect (sigc::mem_fun (*this, &TriggerPage::fast_update_strips));
return 0;
}
gint
TriggerPage::stop_updating ()
{
_fast_screen_update_connection.disconnect ();
return 0;
}
void
TriggerPage::fast_update_strips ()
{
if (_content.is_mapped () && _session) {
for (list<TriggerStrip*>::iterator i = _strips.begin (); i != _strips.end (); ++i) {
(*i)->fast_update ();
}
}
}

View File

@ -29,6 +29,8 @@
#include "widgets/pane.h"
#include "widgets/tabbable.h"
class TriggerStrip;
class TriggerPage : public ArdourWidgets::Tabbable, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList
{
public:
@ -38,7 +40,7 @@ public:
void set_session (ARDOUR::Session*);
XMLNode& get_state ();
int set_state (const XMLNode&, int /* version */);
int set_state (const XMLNode&, int /* version */);
Gtk::Window* use_own_window (bool and_fill_it);
@ -49,8 +51,33 @@ private:
void session_going_away ();
void parameter_changed (std::string const&);
Gtkmm2ext::Bindings* bindings;
void initial_track_display ();
void add_routes (ARDOUR::RouteList&);
void remove_route (TriggerStrip*);
void redisplay_track_list ();
void pi_property_changed (PBD::PropertyChange const&);
void stripable_property_changed (PBD::PropertyChange const&, boost::weak_ptr<ARDOUR::Stripable>);
gint start_updating ();
gint stop_updating ();
void fast_update_strips ();
Gtkmm2ext::Bindings* bindings;
Gtk::VBox _content;
ArdourWidgets::VPane _pane;
ArdourWidgets::HPane _pane_upper;
Gtk::HBox _strip_group_box;
Gtk::ScrolledWindow _strip_scroller;
Gtk::HBox _strip_packer;
Gtk::EventBox _no_strips;
Gtk::VBox _slot_area_box;
Gtk::VBox _browser_box;
Gtk::HBox _parameter_box;
std::list<TriggerStrip*> _strips;
sigc::connection _fast_screen_update_connection;
};
#endif /* __gtk_ardour_trigger_page_h__ */

View File

@ -0,0 +1,282 @@
/*
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* 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 <list>
#include <sigc++/bind.h>
#include "pbd/unwind.h"
#include "ardour/audio_track.h"
#include "ardour/profile.h"
#include "gtkmm2ext/utils.h"
#include "widgets/tooltips.h"
#include "gui_thread.h"
#include "mixer_ui.h"
#include "plugin_selector.h"
#include "plugin_ui.h"
#include "trigger_strip.h"
#include "ui_config.h"
#include "pbd/i18n.h"
using namespace ARDOUR;
using namespace ArdourWidgets;
using namespace ARDOUR_UI_UTILS;
using namespace PBD;
using namespace Gtk;
using namespace Gtkmm2ext;
using namespace std;
PBD::Signal1<void, TriggerStrip*> TriggerStrip::CatchDeletion;
#define PX_SCALE(pxmin, dflt) rint (std::max ((double)pxmin, (double)dflt* UIConfiguration::instance ().get_ui_scale ()))
TriggerStrip::TriggerStrip (Session* s, boost::shared_ptr<ARDOUR::Route> rt)
: SessionHandlePtr (s)
, RouteUI (s)
, _pb_selection ()
, _processor_box (s, boost::bind (&TriggerStrip::plugin_selector, this), _pb_selection, 0)
, _trigger_display (*rt->triggerbox ())
{
init ();
RouteUI::set_route (rt);
/* set route */
_processor_box.set_route (rt);
name_changed ();
map_frozen ();
update_sensitivity ();
show ();
}
TriggerStrip::~TriggerStrip ()
{
CatchDeletion (this);
}
void
TriggerStrip::self_delete ()
{
delete this;
}
string
TriggerStrip::state_id () const
{
return string_compose ("trigger %1", _route->id ().to_s ());
}
void
TriggerStrip::set_session (Session* s)
{
RouteUI::set_session (s);
if (!s) {
return;
}
s->config.ParameterChanged.connect (*this, invalidator (*this), ui_bind (&TriggerStrip::parameter_changed, this, _1), gui_context ());
}
string
TriggerStrip::name () const
{
return _route->name ();
}
Gdk::Color
TriggerStrip::color () const
{
return RouteUI::route_color ();
}
void
TriggerStrip::init ()
{
_name_button.set_name ("mixer strip button");
_name_button.set_text_ellipsize (Pango::ELLIPSIZE_END);
_name_button.signal_size_allocate ().connect (sigc::mem_fun (*this, &TriggerStrip::name_button_resized));
/* main layout */
global_vpacker.set_spacing (2);
global_vpacker.pack_start (_name_button, Gtk::PACK_SHRINK);
global_vpacker.pack_start (_trigger_display, true, true); // XXX
global_vpacker.pack_start (_processor_box, true, true);
/* top-level layout */
global_frame.add (global_vpacker);
global_frame.set_shadow_type (Gtk::SHADOW_IN);
global_frame.set_name ("BaseFrame");
add (global_frame);
/* Signals */
_name_button.signal_button_press_event ().connect (sigc::mem_fun (*this, &TriggerStrip::name_button_press), false);
/* Visibility */
_name_button.show ();
_trigger_display.show ();
_processor_box.show ();
global_frame.show ();
global_vpacker.show ();
show ();
/* Width -- wide channel strip
* Note that panners require an ven number of horiz. pixels
*/
const float scale = std::max (1.f, UIConfiguration::instance ().get_ui_scale ());
int width = rintf (110.f * scale) + 1;
width &= ~1;
set_size_request (width, -1);
}
void
TriggerStrip::set_button_names ()
{
mute_button->set_text (S_("Mute|M"));
monitor_input_button->set_text (_("In"));
monitor_disk_button->set_text (_("Disk"));
if (!Config->get_solo_control_is_listen_control ()) {
solo_button->set_text (_("Solo"));
} else {
switch (Config->get_listen_position ()) {
case AfterFaderListen:
solo_button->set_text (_("AFL"));
break;
case PreFaderListen:
solo_button->set_text (_("PFL"));
break;
}
}
}
void
TriggerStrip::route_property_changed (const PropertyChange& what_changed)
{
if (what_changed.contains (ARDOUR::Properties::name)) {
name_changed ();
}
}
void
TriggerStrip::route_color_changed ()
{
_name_button.modify_bg (STATE_NORMAL, color ());
}
void
TriggerStrip::update_sensitivity ()
{
bool en = _route->active ();
monitor_input_button->set_sensitive (en);
monitor_disk_button->set_sensitive (en);
#if 0
if (!en) {
end_rename (true);
}
if (!is_track() || track()->mode() != ARDOUR::Normal) {
_playlist_button.set_sensitive (false);
}
#endif
}
PluginSelector*
TriggerStrip::plugin_selector ()
{
return Mixer_UI::instance ()->plugin_selector ();
}
void
TriggerStrip::hide_processor_editor (boost::weak_ptr<Processor> p)
{
/* TODO consolidate w/ MixerStrip::hide_processor_editor
* -> RouteUI ?
*/
boost::shared_ptr<Processor> processor (p.lock ());
if (!processor) {
return;
}
Gtk::Window* w = _processor_box.get_processor_ui (processor);
if (w) {
w->hide ();
}
}
void
TriggerStrip::map_frozen ()
{
ENSURE_GUI_THREAD (*this, &TriggerStrip::map_frozen)
boost::shared_ptr<AudioTrack> at = audio_track ();
bool en = _route->active () || ARDOUR::Profile->get_mixbus ();
if (at) {
switch (at->freeze_state ()) {
case AudioTrack::Frozen:
_processor_box.set_sensitive (false);
_route->foreach_processor (sigc::mem_fun (*this, &TriggerStrip::hide_processor_editor));
break;
default:
_processor_box.set_sensitive (en);
break;
}
} else {
_processor_box.set_sensitive (en);
}
RouteUI::map_frozen ();
}
void
TriggerStrip::fast_update ()
{
}
void
TriggerStrip::parameter_changed (string p)
{
}
void
TriggerStrip::name_changed ()
{
_name_button.set_text (_route->name ());
set_tooltip (_name_button, Gtkmm2ext::markup_escape_text (_route->name ()));
}
void
TriggerStrip::name_button_resized (Gtk::Allocation& alloc)
{
_name_button.set_layout_ellipsize_width (alloc.get_width () * PANGO_SCALE);
}
bool
TriggerStrip::name_button_press (GdkEventButton*)
{
// TODO
return false;
}

111
gtk2_ardour/trigger_strip.h Normal file
View File

@ -0,0 +1,111 @@
/*
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* 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.
*/
#ifndef __ardour_trigger_strip__
#define __ardour_trigger_strip__
#include <gtkmm/box.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/frame.h>
#include "pbd/stateful.h"
#include "ardour/ardour.h"
#include "ardour/types.h"
#include "widgets/ardour_button.h"
#include "axis_view.h"
#include "processor_box.h"
#include "processor_selection.h"
#include "route_ui.h"
#include "triggerbox_ui.h"
class PluginSelector;
class TriggerStrip : public AxisView, public RouteUI, public Gtk::EventBox
{
public:
TriggerStrip (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Route>);
~TriggerStrip ();
/* AxisView */
std::string name () const;
Gdk::Color color () const;
boost::shared_ptr<ARDOUR::Stripable> stripable () const
{
return RouteUI::stripable ();
}
void set_session (ARDOUR::Session* s);
void fast_update ();
static PBD::Signal1<void, TriggerStrip*> CatchDeletion;
protected:
void self_delete ();
//void on_size_allocate (Gtk::Allocation&);
//void on_size_request (Gtk::Requisition*);
/* AxisView */
std::string state_id () const;
/* route UI */
void set_button_names ();
#if 0
void route_rec_enable_changed ();
void blink_rec_display (bool onoff);
void route_active_changed ();
void map_frozen ();
#endif
private:
void init ();
/* RouteUI */
void route_property_changed (const PBD::PropertyChange&);
void route_color_changed ();
void update_sensitivity ();
void parameter_changed (std::string);
void map_frozen ();
/* Callbacks */
void name_changed ();
void name_button_resized (Gtk::Allocation&);
bool name_button_press (GdkEventButton*);
/* Plugin related */
PluginSelector* plugin_selector ();
void hide_processor_editor (boost::weak_ptr<ARDOUR::Processor>);
ProcessorSelection _pb_selection;
/* Layout */
Gtk::Frame global_frame;
Gtk::VBox global_vpacker;
/* Widgets */
ArdourWidgets::ArdourButton _name_button;
ProcessorBox _processor_box;
TriggerBoxWidget _trigger_display;
};
#endif /* __ardour_trigger_strip__ */

View File

@ -298,6 +298,7 @@ gtk2_ardour_sources = [
'transport_masters_dialog.cc',
'transpose_dialog.cc',
'trigger_page.cc',
'trigger_strip.cc',
'trigger_ui.cc',
'triggerbox_ui.cc',
'ui_config.cc',