X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftime_info_box.cc;h=d5d77acee8af1d729edc4fe49278d6d1790cd689;hb=79731a716deae9a90be646695480f06f92c268f5;hp=a58aa071c0f2e184c8423b56509eb672ecbf1939;hpb=0a53bb1d42361eeb6552af03a1d3578535d948d0;p=ardour.git diff --git a/gtk2_ardour/time_info_box.cc b/gtk2_ardour/time_info_box.cc index a58aa071c0..d5d77acee8 100644 --- a/gtk2_ardour/time_info_box.cc +++ b/gtk2_ardour/time_info_box.cc @@ -17,113 +17,189 @@ */ +#include #include "pbd/compose.h" -#include "gtkmm2ext/cairocell.h" #include "gtkmm2ext/gui_thread.h" #include "gtkmm2ext/utils.h" +#include "gtkmm2ext/actions.h" #include "ardour/location.h" +#include "ardour/profile.h" #include "ardour/session.h" -#include "time_info_box.h" #include "audio_clock.h" +#include "automation_line.h" +#include "control_point.h" #include "editor.h" +#include "region_view.h" +#include "time_info_box.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace Gtk; using namespace ARDOUR; - -TimeInfoBox::TimeInfoBox () - : Table (4, 4) +using std::min; +using std::max; + +TimeInfoBox::TimeInfoBox (std::string state_node_name, bool with_punch) + : table (3, 3) + , punch_start (0) + , punch_end (0) + , syncing_selection (false) + , syncing_punch (false) + , with_punch_clock (with_punch) { - selection_start = new AudioClock ("selection-start", false, "SelectionClockDisplay", false, false, false, false); - selection_end = new AudioClock ("selection-end", false, "SelectionClockDisplay", false, false, false, false); - selection_length = new AudioClock ("selection-length", false, "SelectionClockDisplay", false, false, true, false); - - punch_start = new AudioClock ("punch-start", false, "PunchClockDisplay", false, false, false, false); - punch_end = new AudioClock ("punch-end", false, "PunchClockDisplay", false, false, false, false); - - bool bg = true; - - CairoEditableText& ss (selection_start->main_display()); - ss.set_ypad (1); - ss.set_xpad (1); - ss.set_corner_radius (0); - ss.set_draw_background (bg); - - CairoEditableText& se (selection_end->main_display()); - se.set_ypad (1); - se.set_xpad (1); - se.set_corner_radius (0); - se.set_draw_background (bg); - - CairoEditableText& sl (selection_length->main_display()); - sl.set_ypad (1); - sl.set_xpad (2); - sl.set_corner_radius (0); - sl.set_draw_background (bg); - - CairoEditableText& ps (punch_start->main_display()); - ps.set_ypad (1); - ps.set_xpad (2); - ps.set_corner_radius (0); - ps.set_draw_background (bg); - - CairoEditableText& pe (punch_end->main_display()); - pe.set_ypad (1); - pe.set_xpad (2); - pe.set_corner_radius (0); - pe.set_draw_background (bg); - - selection_title.set_markup (string_compose ("%1", _("Selection"))); - punch_title.set_markup (string_compose ("%1", _("Punch"))); + set_name (X_("TimeInfoBox")); + + selection_start = new AudioClock ( + string_compose ("%1-selection-start", state_node_name), + false, "selection", false, false, false, false); + selection_end = new AudioClock ( + string_compose ("%1-selection-end", state_node_name), + false, "selection", false, false, false, false); + selection_length = new AudioClock ( + string_compose ("%1-selection-length", state_node_name), + false, "selection", false, false, true, false); + + selection_title.set_text (_("Selection")); set_homogeneous (false); - set_spacings (0); + set_spacing (0); + set_border_width (2); + + pack_start (table, false, false); + + table.set_homogeneous (false); + table.set_spacings (0); + table.set_border_width (2); + table.set_col_spacings (2); Gtk::Label* l; - attach (selection_title, 0, 2, 0, 1); - l = manage (new Label); - l->set_markup (string_compose ("%1", _("Start"))); - attach (*l, 0, 1, 1, 2); - attach (*selection_start, 1, 2, 1, 2); - l = manage (new Label); - l->set_markup (string_compose ("%1", _("End"))); - attach (*l, 0, 1, 2, 3); - attach (*selection_end, 1, 2, 2, 3); + selection_title.set_name ("TimeInfoSelectionTitle"); + if (with_punch_clock) { + table.attach (selection_title, 1, 2, 0, 1); + } l = manage (new Label); - l->set_markup (string_compose ("%1", _("Length"))); - attach (*l, 0, 1, 3, 4); - attach (*selection_length, 1, 2, 3, 4); + l->set_text (_("Start")); + l->set_alignment (1.0, 0.5); + l->set_name (X_("TimeInfoSelectionLabel")); + table.attach (*l, 0, 1, 1, 2, FILL); + table.attach (*selection_start, 1, 2, 1, 2); - attach (punch_title, 2, 4, 0, 1); l = manage (new Label); - l->set_markup (string_compose ("%1", _("Start"))); - attach (*l, 2, 3, 1, 2); - attach (*punch_start, 3, 4, 1, 2); + l->set_text (_("End")); + l->set_alignment (1.0, 0.5); + l->set_name (X_("TimeInfoSelectionLabel")); + table.attach (*l, 0, 1, 2, 3, FILL); + table.attach (*selection_end, 1, 2, 2, 3); + l = manage (new Label); - l->set_markup (string_compose ("%1", _("End"))); - attach (*l, 2, 3, 2, 3); - attach (*punch_end, 3, 4, 2, 3); + l->set_text (_("Length")); + l->set_alignment (1.0, 0.5); + l->set_name (X_("TimeInfoSelectionLabel")); + table.attach (*l, 0, 1, 3, 4, FILL); + table.attach (*selection_length, 1, 2, 3, 4); + + if (with_punch_clock) { + punch_start = new AudioClock ( + string_compose ("%1-punch-start", state_node_name), + false, "punch", false, false, false, false); + punch_end = new AudioClock ( + string_compose ("%1-punch-end", state_node_name), + false, "punch", false, false, false, false); + punch_title.set_text (_("Punch")); + + punch_title.set_name ("TimeInfoSelectionTitle"); + table.attach (punch_title, 2, 3, 0, 1); + table.attach (*punch_start, 2, 3, 1, 2); + table.attach (*punch_end, 2, 3, 2, 3); + } + + show_all (); + + selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start)); + selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end)); + selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length)); - show_all (); + selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true); + selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true); + + if (with_punch_clock) { + punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start)); + punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end)); + + punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true); + punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true); + } Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed)); + Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed)); + + Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context()); } TimeInfoBox::~TimeInfoBox () { - delete selection_length; - delete selection_end; - delete selection_start; - - delete punch_start; - delete punch_end; + delete selection_length; + delete selection_end; + delete selection_start; + + delete punch_start; + delete punch_end; +} + +void +TimeInfoBox::track_mouse_mode () +{ + selection_changed (); +} + +bool +TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src) +{ + if (!_session) { + return false; + } + + if (ev->button == 1) { + if (!src->off()) { + _session->request_locate (src->current_time ()); + } + return true; + } + + return false; +} + +void +TimeInfoBox::sync_selection_mode (AudioClock* src) +{ + if (!syncing_selection) { + syncing_selection = true; + selection_start->set_mode (src->mode()); + selection_end->set_mode (src->mode()); + selection_length->set_mode (src->mode()); + syncing_selection = false; + } +} + +void +TimeInfoBox::sync_punch_mode (AudioClock* src) +{ + if (!with_punch_clock) { + return; + } + if (!syncing_punch) { + syncing_punch = true; + punch_start->set_mode (src->mode()); + punch_end->set_mode (src->mode()); + syncing_punch = false; + } } + void TimeInfoBox::set_session (Session* s) { @@ -133,40 +209,160 @@ TimeInfoBox::set_session (Session* s) selection_end->set_session (s); selection_length->set_session (s); + if (!with_punch_clock) { + return; + } + punch_start->set_session (s); punch_end->set_session (s); if (s) { Location* punch = s->locations()->auto_punch_location (); - + if (punch) { watch_punch (punch); } - - _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR, - boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context()); + + punch_changed (punch); + + _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR, + boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context()); } } +void +TimeInfoBox::region_selection_changed () +{ + samplepos_t s, e; + Selection& selection (Editor::instance().get_selection()); + s = selection.regions.start(); + e = selection.regions.end_sample(); + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (s); + selection_end->set (e); + selection_length->set (e, false, s); +} + void TimeInfoBox::selection_changed () { - selection_start->set (Editor::instance().get_selection().time.start()); - selection_end->set (Editor::instance().get_selection().time.end_frame()); - selection_length->set (Editor::instance().get_selection().time.length()); + samplepos_t s, e; + Selection& selection (Editor::instance().get_selection()); + + region_property_connections.drop_connections(); + + switch (Editor::instance().current_mouse_mode()) { + + case Editing::MouseContent: + /* displaying MIDI note selection is tricky */ + selection_start->set_off (true); + selection_end->set_off (true); + selection_length->set_off (true); + break; + + case Editing::MouseObject: + if (selection.regions.empty()) { + if (selection.points.empty()) { + Glib::RefPtr act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range"); + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); + + if (tact && tact->get_active() && !selection.time.empty()) { + /* show selected range */ + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (selection.time.start()); + selection_end->set (selection.time.end_sample()); + selection_length->set (selection.time.end_sample(), false, selection.time.start()); + } else { + selection_start->set_off (true); + selection_end->set_off (true); + selection_length->set_off (true); + } + } else { + s = max_samplepos; + e = 0; + for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) { + samplepos_t const p = (*i)->line().session_position ((*i)->model ()); + s = min (s, p); + e = max (e, p); + } + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (s); + selection_end->set (e); + selection_length->set (e, false, s); + } + } else { + /* this is more efficient than tracking changes per region in large selections */ + std::set > playlists; + for (RegionSelection::iterator s = selection.regions.begin(); s != selection.regions.end(); ++s) { + boost::shared_ptr pl = (*s)->region()->playlist(); + if (pl) { + playlists.insert (pl); + } + } + for (std::set >::iterator ps = playlists.begin(); ps != playlists.end(); ++ps) { + (*ps)->ContentsChanged.connect (region_property_connections, invalidator (*this), + boost::bind (&TimeInfoBox::region_selection_changed, this), gui_context()); + } + region_selection_changed (); + } + break; + + case Editing::MouseRange: + if (selection.time.empty()) { + Glib::RefPtr act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range"); + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); + + if (tact && tact->get_active() && !selection.regions.empty()) { + /* show selected regions */ + s = selection.regions.start(); + e = selection.regions.end_sample(); + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (s); + selection_end->set (e); + selection_length->set (e, false, s); + } else { + selection_start->set_off (true); + selection_end->set_off (true); + selection_length->set_off (true); + } + } else { + selection_start->set_off (false); + selection_end->set_off (false); + selection_length->set_off (false); + selection_start->set (selection.time.start()); + selection_end->set (selection.time.end_sample()); + selection_length->set (selection.time.end_sample(), false, selection.time.start()); + } + break; + + default: + selection_start->set_off (true); + selection_end->set_off (true); + selection_length->set_off (true); + break; + } } void TimeInfoBox::punch_location_changed (Location* loc) { - if (loc) { + if (loc && with_punch_clock) { watch_punch (loc); - } + } } void TimeInfoBox::watch_punch (Location* punch) { + assert (with_punch_clock); punch_connections.drop_connections (); punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context()); @@ -178,40 +374,16 @@ TimeInfoBox::watch_punch (Location* punch) void TimeInfoBox::punch_changed (Location* loc) { + assert (with_punch_clock); if (!loc) { - punch_start->set (99999999); - punch_end->set (999999999); + punch_start->set_off (true); + punch_end->set_off (true); return; } + punch_start->set_off (false); + punch_end->set_off (false); + punch_start->set (loc->start()); punch_end->set (loc->end()); -} - -bool -TimeInfoBox::on_expose_event (GdkEventExpose* ev) -{ - { - int x, y; - Gtk::Widget* window_parent; - Glib::RefPtr win = Gtkmm2ext::window_to_draw_on (*this, &window_parent); - - if (win) { - - Cairo::RefPtr context = win->create_cairo_context(); - - translate_coordinates (*window_parent, 0, 0, x, y); - - context->rectangle (x, y, ev->area.width, ev->area.height); - context->clip (); - - context->set_source_rgba (0.149, 0.149, 0.149, 1.0); - Gtkmm2ext::rounded_rectangle (context, x, y, get_allocation().get_width(), get_allocation().get_height(), 5); - context->fill (); - } - } - - Table::on_expose_event (ev); - - return false; }