2012-05-31 19:14:03 -04:00
/*
Copyright ( C ) 2012 Paul Davis
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 . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2017-11-22 16:10:37 -05:00
# include "pbd/unwind.h"
2016-12-11 11:24:30 -05:00
# include "ardour/tempo.h"
2014-12-22 13:39:41 -05:00
2016-12-11 11:24:30 -05:00
# include "actions.h"
# include "main_clock.h"
2015-01-02 09:44:54 -05:00
# include "ui_config.h"
2016-12-11 11:24:30 -05:00
# include "public_editor.h"
2015-01-02 09:44:54 -05:00
2016-07-14 14:44:52 -04:00
# include "pbd/i18n.h"
2012-05-31 19:14:03 -04:00
using namespace Gtk ;
2017-11-22 16:10:37 -05:00
using namespace ARDOUR ;
2012-05-31 19:14:03 -04:00
MainClock : : MainClock (
const std : : string & clock_name ,
const std : : string & widget_name ,
2015-02-15 07:56:25 -05:00
bool primary
2012-05-31 19:14:03 -04:00
)
2015-02-15 07:56:25 -05:00
: AudioClock ( clock_name , false , widget_name , true , true , false , true )
2017-11-22 16:10:37 -05:00
, _primary ( primary )
, _suspend_delta_mode_signal ( false )
2012-05-31 19:14:03 -04:00
{
2016-12-11 11:24:30 -05:00
}
2012-05-31 19:14:03 -04:00
2016-12-11 11:24:30 -05:00
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 " ) ) ) ;
2012-05-31 19:14:03 -04:00
}
void
MainClock : : build_ops_menu ( )
{
using namespace Menu_Helpers ;
AudioClock : : build_ops_menu ( ) ;
MenuList & ops_items = ops_menu - > items ( ) ;
ops_items . push_back ( SeparatorElem ( ) ) ;
2017-11-22 16:10:37 -05:00
RadioMenuItem : : Group group ;
PBD : : Unwinder < bool > uw ( _suspend_delta_mode_signal , true ) ;
ClockDeltaMode mode ;
2012-05-31 19:14:03 -04:00
if ( _primary ) {
2017-11-22 16:10:37 -05:00
mode = UIConfiguration : : instance ( ) . get_primary_clock_delta_mode ( ) ;
2012-05-31 19:14:03 -04:00
} else {
2017-11-22 16:10:37 -05:00
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 < RadioMenuItem * > ( & 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 < RadioMenuItem * > ( & 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 < RadioMenuItem * > ( & ops_items . back ( ) ) ;
i - > set_active ( true ) ;
2012-05-31 19:14:03 -04:00
}
2015-02-03 14:25:10 -05:00
ops_items . push_back ( SeparatorElem ( ) ) ;
2017-11-22 16:10:37 -05:00
2015-02-03 14:25:10 -05:00
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 ) ) ) ;
2012-05-31 19:14:03 -04:00
}
2017-09-18 12:39:17 -04:00
samplepos_t
2015-02-07 18:22:59 -05:00
MainClock : : absolute_time ( ) const
{
if ( get_is_duration ( ) ) {
2017-11-22 16:10:37 -05:00
return current_time ( ) + offset ( ) ;
2015-02-07 18:22:59 -05:00
} else {
return current_time ( ) ;
}
}
2012-05-31 19:14:03 -04:00
void
2017-11-22 16:10:37 -05:00
MainClock : : set ( samplepos_t when , bool force , ARDOUR : : samplecnt_t /*offset*/ )
{
ClockDeltaMode mode ;
if ( _primary ) {
mode = UIConfiguration : : instance ( ) . get_primary_clock_delta_mode ( ) ;
} else {
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 )
2012-05-31 19:14:03 -04:00
{
2017-11-22 16:10:37 -05:00
if ( _suspend_delta_mode_signal ) {
return ;
}
2012-05-31 19:14:03 -04:00
if ( _primary ) {
2017-11-22 16:10:37 -05:00
UIConfiguration : : instance ( ) . set_primary_clock_delta_mode ( m ) ;
2012-05-31 19:14:03 -04:00
} else {
2017-11-22 16:10:37 -05:00
UIConfiguration : : instance ( ) . set_secondary_clock_delta_mode ( m ) ;
2012-05-31 19:14:03 -04:00
}
}
2015-02-03 14:25:10 -05:00
void
MainClock : : edit_current_tempo ( )
{
2015-08-17 21:02:34 -04:00
if ( ! PublicEditor : : instance ( ) . session ( ) ) return ;
2017-09-18 12:39:17 -04:00
ARDOUR : : TempoSection * ts = const_cast < ARDOUR : : TempoSection * > ( & PublicEditor : : instance ( ) . session ( ) - > tempo_map ( ) . tempo_section_at_sample ( absolute_time ( ) ) ) ;
2016-06-08 15:54:53 -04:00
PublicEditor : : instance ( ) . edit_tempo_section ( ts ) ;
2015-02-03 14:25:10 -05:00
}
void
MainClock : : edit_current_meter ( )
{
2015-08-17 21:02:34 -04:00
if ( ! PublicEditor : : instance ( ) . session ( ) ) return ;
2017-09-18 12:39:17 -04:00
ARDOUR : : MeterSection * ms = const_cast < ARDOUR : : MeterSection * > ( & PublicEditor : : instance ( ) . session ( ) - > tempo_map ( ) . meter_section_at_sample ( absolute_time ( ) ) ) ;
2016-06-08 16:44:39 -04:00
PublicEditor : : instance ( ) . edit_meter_section ( ms ) ;
2015-02-03 14:25:10 -05:00
}
void
MainClock : : insert_new_tempo ( )
{
2015-02-07 18:22:59 -05:00
PublicEditor : : instance ( ) . mouse_add_new_tempo_event ( absolute_time ( ) ) ;
2015-02-03 14:25:10 -05:00
}
void
MainClock : : insert_new_meter ( )
{
2015-02-07 18:22:59 -05:00
PublicEditor : : instance ( ) . mouse_add_new_meter_event ( absolute_time ( ) ) ;
2015-02-03 14:25:10 -05:00
}