X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fmain_clock.cc;h=6b0af8cf9ba67362ead7678f285bdafdb29c0015;hb=30553a267551405712f3b2a3ef1f612630be6477;hp=36b398ee44b406e9c2f56b6726cc78c28647a4f9;hpb=17ad0a0b61a887362ce07b1f8b59de003ddd9233;p=ardour.git diff --git a/gtk2_ardour/main_clock.cc b/gtk2_ardour/main_clock.cc index 36b398ee44..6b0af8cf9b 100644 --- a/gtk2_ardour/main_clock.cc +++ b/gtk2_ardour/main_clock.cc @@ -1,42 +1,55 @@ /* - Copyright (C) 2012 Paul Davis + * Copyright (C) 2012-2017 Robin Gareus + * Copyright (C) 2013-2017 Paul Davis + * Copyright (C) 2015 Colin Fletcher + * Copyright (C) 2015 Tim Mayberry + * Copyright (C) 2016 Nick Mainsbridge + * + * 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. + */ - 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. +#include "pbd/unwind.h" +#include "ardour/tempo.h" - 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "ardour/rc_configuration.h" +#include "actions.h" #include "main_clock.h" -#include "i18n.h" +#include "ui_config.h" +#include "public_editor.h" + +#include "pbd/i18n.h" using namespace Gtk; +using namespace ARDOUR; MainClock::MainClock ( const std::string& clock_name, - bool is_transient, const std::string& widget_name, - bool editable, - bool follows_playhead, - bool primary, - bool duration, - bool with_info + bool primary ) - : AudioClock (clock_name, is_transient, widget_name, editable, follows_playhead, duration, with_info) - , _primary (primary) + : AudioClock (clock_name, false, widget_name, true, true, false, true) + , _primary (primary) + , _suspend_delta_mode_signal (false) { +} +void +MainClock::set_session (ARDOUR::Session *s) +{ + AudioClock::set_session (s); + _left_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-tempo"))); + _right_btn.set_related_action (ActionManager::get_action (X_("Editor"), X_("edit-current-meter"))); } void @@ -48,27 +61,115 @@ MainClock::build_ops_menu () MenuList& ops_items = ops_menu->items(); ops_items.push_back (SeparatorElem ()); - ops_items.push_back (CheckMenuElem (_("Display delta to edit cursor"), sigc::mem_fun (*this, &MainClock::display_delta_to_edit_cursor))); - Gtk::CheckMenuItem* c = dynamic_cast (&ops_items.back()); + RadioMenuItem::Group group; + PBD::Unwinder uw (_suspend_delta_mode_signal, true); + ClockDeltaMode mode; if (_primary) { - if (ARDOUR::Config->get_primary_clock_delta_edit_cursor ()) { - ARDOUR::Config->set_primary_clock_delta_edit_cursor (false); - c->set_active (true); - } + mode = UIConfiguration::instance().get_primary_clock_delta_mode (); } else { - if (ARDOUR::Config->get_secondary_clock_delta_edit_cursor ()) { - ARDOUR::Config->set_secondary_clock_delta_edit_cursor (false); - c->set_active (true); - } + mode = UIConfiguration::instance().get_secondary_clock_delta_mode (); + } + + ops_items.push_back (RadioMenuElem (group, _("Display absolute time"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), NoDelta))); + if (mode == NoDelta) { + RadioMenuItem* i = dynamic_cast (&ops_items.back ()); + i->set_active (true); + } + ops_items.push_back (RadioMenuElem (group, _("Display delta to edit cursor"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), DeltaEditPoint))); + if (mode == DeltaEditPoint) { + RadioMenuItem* i = dynamic_cast (&ops_items.back ()); + i->set_active (true); + } + ops_items.push_back (RadioMenuElem (group, _("Display delta to origin marker"), sigc::bind (sigc::mem_fun (*this, &MainClock::set_display_delta_mode), DeltaOriginMarker))); + if (mode == DeltaOriginMarker) { + RadioMenuItem* i = dynamic_cast (&ops_items.back ()); + i->set_active (true); + } + + ops_items.push_back (SeparatorElem()); + + ops_items.push_back (MenuElem (_("Edit Tempo"), sigc::mem_fun(*this, &MainClock::edit_current_tempo))); + ops_items.push_back (MenuElem (_("Edit Meter"), sigc::mem_fun(*this, &MainClock::edit_current_meter))); + ops_items.push_back (MenuElem (_("Insert Tempo Change"), sigc::mem_fun(*this, &MainClock::insert_new_tempo))); + ops_items.push_back (MenuElem (_("Insert Meter Change"), sigc::mem_fun(*this, &MainClock::insert_new_meter))); +} + +samplepos_t +MainClock::absolute_time () const +{ + if (get_is_duration ()) { + return current_time () + offset (); + } else { + return current_time (); } } void -MainClock::display_delta_to_edit_cursor () +MainClock::set (samplepos_t when, bool force, ARDOUR::samplecnt_t /*offset*/) { + ClockDeltaMode mode; if (_primary) { - ARDOUR::Config->set_primary_clock_delta_edit_cursor (!ARDOUR::Config->get_primary_clock_delta_edit_cursor ()); + mode = UIConfiguration::instance().get_primary_clock_delta_mode (); } else { - ARDOUR::Config->set_secondary_clock_delta_edit_cursor (!ARDOUR::Config->get_secondary_clock_delta_edit_cursor ()); + mode = UIConfiguration::instance().get_secondary_clock_delta_mode (); } + if (!PublicEditor::instance().session()) { + mode = NoDelta; + } + + switch (mode) { + case NoDelta: + AudioClock::set (when, force, 0); + break; + case DeltaEditPoint: + AudioClock::set (when, force, PublicEditor::instance().get_preferred_edit_position (Editing::EDIT_IGNORE_PHEAD)); + break; + case DeltaOriginMarker: + { + Location* loc = PublicEditor::instance().session()->locations()->clock_origin_location (); + AudioClock::set (when, force, loc ? loc->start() : 0); + } + break; + } +} + +void +MainClock::set_display_delta_mode (ClockDeltaMode m) +{ + if (_suspend_delta_mode_signal) { + return; + } + if (_primary) { + UIConfiguration::instance().set_primary_clock_delta_mode (m); + } else { + UIConfiguration::instance().set_secondary_clock_delta_mode (m); + } +} + +void +MainClock::edit_current_tempo () +{ + if (!PublicEditor::instance().session()) return; + ARDOUR::TempoSection* ts = const_cast(&PublicEditor::instance().session()->tempo_map().tempo_section_at_sample (absolute_time())); + PublicEditor::instance().edit_tempo_section (ts); +} + +void +MainClock::edit_current_meter () +{ + if (!PublicEditor::instance().session()) return; + ARDOUR::MeterSection* ms = const_cast(&PublicEditor::instance().session()->tempo_map().meter_section_at_sample (absolute_time())); + PublicEditor::instance().edit_meter_section (ms); +} + +void +MainClock::insert_new_tempo () +{ + PublicEditor::instance().mouse_add_new_tempo_event (absolute_time ()); +} + +void +MainClock::insert_new_meter () +{ + PublicEditor::instance().mouse_add_new_meter_event (absolute_time ()); }