diff options
author | Robin Gareus <robin@gareus.org> | 2012-11-13 20:29:28 +0000 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2012-11-13 20:29:28 +0000 |
commit | e1581242ca8554660ea68290688e573a9acfca06 (patch) | |
tree | 49099b7fa12f4c0732dcc635fda59e448c1e5ea3 /libs | |
parent | f761de0d70b896c4a3437f99b238effac520519d (diff) |
implement TC offset for slave&generator.
Many related changes that require atomic update, mostly
because ClockOption slots changed:
* change offset config format to std:string (backwards compat - reads 0)
* make Timecode offset independent from fps
* sample_to_timecode() handle negative sample-num
* audio-clock fix entry and edit of negative numbers
* option editor:
- remove old global internal offset
- add slave & generator TC entry
- still needs UI cleanup, tooltops, maybe sep. tab..
* LTC & MTC slave& generator:
- cache offset
- subscribe to parameter changes
git-svn-id: svn://localhost/ardour2/branches/3.0@13485 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/session.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/session_configuration_vars.h | 6 | ||||
-rw-r--r-- | libs/ardour/ardour/slave.h | 9 | ||||
-rw-r--r-- | libs/ardour/ltc_slave.cc | 27 | ||||
-rw-r--r-- | libs/ardour/mtc_slave.cc | 26 | ||||
-rw-r--r-- | libs/ardour/session_ltc.cc | 18 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 4 | ||||
-rw-r--r-- | libs/ardour/session_time.cc | 3 | ||||
-rw-r--r-- | libs/timecode/src/time.cc | 5 |
9 files changed, 91 insertions, 11 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index d86b919111..9b25f29c8f 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1203,6 +1203,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi framepos_t ltc_enc_off; bool restarting; + framepos_t ltc_timecode_offset; + bool ltc_timecode_negative_offset; + jack_latency_range_t ltc_out_latency; void ltc_tx_initialize(); @@ -1210,6 +1213,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi void ltc_tx_reset(); void ltc_tx_resync_latency(); void ltc_tx_recalculate_position(); + void ltc_tx_parse_offset(); void ltc_tx_send_time_code_for_cycle (framepos_t, framepos_t, double, double, pframes_t nframes); #endif diff --git a/libs/ardour/ardour/session_configuration_vars.h b/libs/ardour/ardour/session_configuration_vars.h index 1bfc254921..1a4a17ce5d 100644 --- a/libs/ardour/ardour/session_configuration_vars.h +++ b/libs/ardour/ardour/session_configuration_vars.h @@ -53,10 +53,8 @@ CONFIG_VARIABLE (bool, external_sync, "external-sync", false) CONFIG_VARIABLE (InsertMergePolicy, insert_merge_policy, "insert-merge-policy", InsertMergeRelax) CONFIG_VARIABLE (framecnt_t, timecode_offset, "timecode-offset", 0) CONFIG_VARIABLE (bool, timecode_offset_negative, "timecode-offset-negative", true) -CONFIG_VARIABLE (framecnt_t, slave_timecode_offset, "slave-timecode-offset", 0) -CONFIG_VARIABLE (bool, slave_timecode_offset_negative, "slave-timecode-offset-negative", true) -CONFIG_VARIABLE (framecnt_t, timecode_generator_offset, "timecode-generator-offset", 0) -CONFIG_VARIABLE (bool, timecode_generator_offset_negative, "timecode-generator-offset-negative", true) +CONFIG_VARIABLE (std::string, slave_timecode_offset, "slave-timecode-offset", " 00:00:00:00") +CONFIG_VARIABLE (std::string, timecode_generator_offset, "timecode-generator-offset", " 00:00:00:00") CONFIG_VARIABLE (bool, glue_new_markers_to_bars_and_beats, "glue-new-markers-to-bars-and-beats", false) CONFIG_VARIABLE (bool, midi_copy_is_fork, "midi-copy-is-fork", false) CONFIG_VARIABLE (bool, glue_new_regions_to_bars_and_beats, "glue-new-regions-to-bars-and-beats", false) diff --git a/libs/ardour/ardour/slave.h b/libs/ardour/ardour/slave.h index 5b424bab6f..d5cb79c522 100644 --- a/libs/ardour/ardour/slave.h +++ b/libs/ardour/ardour/slave.h @@ -247,6 +247,9 @@ class TimecodeSlave : public Slave { of the TC source position. */ virtual std::string approximate_current_position() const = 0; + + framepos_t timecode_offset; + bool timecode_negative_offset; }; class MTC_Slave : public TimecodeSlave { @@ -274,6 +277,7 @@ class MTC_Slave : public TimecodeSlave { Session& session; MIDI::Port* port; PBD::ScopedConnectionList port_connections; + PBD::ScopedConnection config_connection; bool can_notify_on_unknown_rate; static const int frame_tolerance; @@ -327,6 +331,8 @@ class MTC_Slave : public TimecodeSlave { bool outside_window (framepos_t) const; void init_mtc_dll(framepos_t, double); void init_engine_dll (framepos_t, framepos_t); + void parse_timecode_offset(); + void parameter_changed(std::string const & p); }; #ifdef HAVE_LTC @@ -359,6 +365,8 @@ public: void reset(); void resync_xrun(); void resync_latency(); + void parse_timecode_offset(); + void parameter_changed(std::string const & p); Session& session; bool did_reset_tc_format; @@ -384,6 +392,7 @@ public: Timecode::TimecodeFormat a3e_timecode; PBD::ScopedConnectionList port_connections; + PBD::ScopedConnection config_connection; jack_latency_range_t ltc_slave_latency; /* DLL - chase LTC */ diff --git a/libs/ardour/ltc_slave.cc b/libs/ardour/ltc_slave.cc index 166c78ce24..7b182cfa64 100644 --- a/libs/ardour/ltc_slave.cc +++ b/libs/ardour/ltc_slave.cc @@ -60,6 +60,9 @@ LTC_Slave::LTC_Slave (Session& s) memset(&prev_frame, 0, sizeof(LTCFrameExt)); decoder = ltc_decoder_create((int) frames_per_ltc_frame, 128 /*queue size*/); + + session.config.ParameterChanged.connect_same_thread (config_connection, boost::bind (<C_Slave::parameter_changed, this, _1)); + parse_timecode_offset(); reset(); resync_latency(); session.Xrun.connect_same_thread (port_connections, boost::bind (<C_Slave::resync_xrun, this)); @@ -69,6 +72,7 @@ LTC_Slave::LTC_Slave (Session& s) LTC_Slave::~LTC_Slave() { port_connections.drop_connections(); + config_connection.disconnect(); if (did_reset_tc_format) { session.config.set_timecode_format (saved_tc_format); @@ -77,6 +81,27 @@ LTC_Slave::~LTC_Slave() ltc_decoder_free(decoder); } +void +LTC_Slave::parse_timecode_offset() { + Timecode::Time offset_tc; + Timecode::parse_timecode_format(session.config.get_slave_timecode_offset(), offset_tc); + offset_tc.rate = session.timecode_frames_per_second(); + offset_tc.drop = session.timecode_drop_frames(); + session.timecode_to_sample(offset_tc, timecode_offset, false, false); + timecode_negative_offset = offset_tc.negative; +} + +void +LTC_Slave::parameter_changed (std::string const & p) +{ + if (p == "slave-timecode-offset" + || p == "subframes-per-frame" + || p == "timecode-format" + ) { + parse_timecode_offset(); + } +} + ARDOUR::framecnt_t LTC_Slave::resolution () const { @@ -334,7 +359,7 @@ LTC_Slave::process_ltc(framepos_t const now) Timecode::timecode_to_sample (timecode, ltc_frame, true, false, double(session.frame_rate()), session.config.get_subframes_per_frame(), - session.config.get_slave_timecode_offset_negative(), session.config.get_slave_timecode_offset() + timecode_negative_offset, timecode_offset ); framepos_t cur_timestamp = frame.off_end + 1; diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index 1228465f8b..dcc51ee5c8 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -66,6 +66,8 @@ MTC_Slave::MTC_Slave (Session& s, MIDI::Port& p) a3e_timecode = session.config.get_timecode_format(); printed_timecode_warning = false; + session.config.ParameterChanged.connect_same_thread (config_connection, boost::bind (&MTC_Slave::parameter_changed, this, _1)); + parse_timecode_offset(); reset (true); rebind (p); } @@ -73,6 +75,7 @@ MTC_Slave::MTC_Slave (Session& s, MIDI::Port& p) MTC_Slave::~MTC_Slave() { port_connections.drop_connections(); + config_connection.disconnect(); while (busy_guard1 != busy_guard2) { /* make sure MIDI parser is not currently calling any callbacks in here, @@ -101,6 +104,27 @@ MTC_Slave::rebind (MIDI::Port& p) port->parser()->mtc_status.connect_same_thread (port_connections, boost::bind (&MTC_Slave::update_mtc_status, this, _1)); } +void +MTC_Slave::parse_timecode_offset() { + Timecode::Time offset_tc; + Timecode::parse_timecode_format(session.config.get_slave_timecode_offset(), offset_tc); + offset_tc.rate = session.timecode_frames_per_second(); + offset_tc.drop = session.timecode_drop_frames(); + session.timecode_to_sample(offset_tc, timecode_offset, false, false); + timecode_negative_offset = offset_tc.negative; +} + +void +MTC_Slave::parameter_changed (std::string const & p) +{ + if (p == "slave-timecode-offset" + || p == "subframes-per-frame" + || p == "timecode-format" + ) { + parse_timecode_offset(); + } +} + bool MTC_Slave::give_slave_full_control_over_transport_speed() const { @@ -390,7 +414,7 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full, framepos_t now) Timecode::timecode_to_sample (timecode, mtc_frame, true, false, double(session.frame_rate()), session.config.get_subframes_per_frame(), - session.config.get_slave_timecode_offset_negative(), session.config.get_slave_timecode_offset() + timecode_negative_offset, timecode_offset ); DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC at %1 TC %2 = mtc_frame %3 (from full message ? %4) tc-ratio %5\n", diff --git a/libs/ardour/session_ltc.cc b/libs/ardour/session_ltc.cc index 25ba783fc7..733ca6877e 100644 --- a/libs/ardour/session_ltc.cc +++ b/libs/ardour/session_ltc.cc @@ -63,6 +63,7 @@ Session::ltc_tx_initialize() { ltc_enc_tcformat = config.get_timecode_format(); + ltc_tx_parse_offset(); DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX init sr: %1 fps: %2\n", nominal_frame_rate(), timecode_to_frames_per_second(ltc_enc_tcformat))); ltc_encoder = ltc_encoder_create(nominal_frame_rate(), timecode_to_frames_per_second(ltc_enc_tcformat), @@ -119,6 +120,16 @@ Session::ltc_tx_reset() } void +Session::ltc_tx_parse_offset() { + Timecode::Time offset_tc; + Timecode::parse_timecode_format(config.get_timecode_generator_offset(), offset_tc); + offset_tc.rate = timecode_frames_per_second(); + offset_tc.drop = timecode_drop_frames(); + timecode_to_sample(offset_tc, ltc_timecode_offset, false, false); + ltc_timecode_negative_offset = !offset_tc.negative; +} + +void Session::ltc_tx_recalculate_position() { SMPTETimecode enctc; @@ -135,7 +146,7 @@ Session::ltc_tx_recalculate_position() Timecode::timecode_to_sample (a3tc, ltc_enc_pos, true, false, (double)frame_rate(), config.get_subframes_per_frame(), - config.get_timecode_generator_offset_negative(), config.get_timecode_generator_offset() + ltc_timecode_negative_offset, ltc_timecode_offset ); restarting = false; } @@ -204,6 +215,7 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end } ltc_encoder_set_filter(ltc_encoder, LTC_RISE_TIME(ltc_speed)); ltc_enc_tcformat = cur_timecode; + ltc_tx_parse_offset(); ltc_tx_reset(); } @@ -365,14 +377,14 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end timecode_drop_frames(), (double)frame_rate(), config.get_subframes_per_frame(), - config.get_timecode_generator_offset_negative(), config.get_timecode_generator_offset() + ltc_timecode_negative_offset, ltc_timecode_offset ); /* convert timecode back to sample-position */ Timecode::timecode_to_sample (tc_start, tc_sample_start, true, false, (double)frame_rate(), config.get_subframes_per_frame(), - config.get_timecode_generator_offset_negative(), config.get_timecode_generator_offset() + ltc_timecode_negative_offset, ltc_timecode_offset ); /* difference between current frame and TC frame in samples */ diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 46dee236ae..74257ef482 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3565,6 +3565,10 @@ Session::config_changed (std::string p, bool ours) reconnect_ltc_input (); } else if (p == "ltc-sink-port") { reconnect_ltc_output (); +#ifdef HAVE_LTC + } else if (p == "timecode-generator-offset") { + ltc_tx_parse_offset(); +#endif } set_dirty (); diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc index 5e25aaf508..72d8fb1e89 100644 --- a/libs/ardour/session_time.cc +++ b/libs/ardour/session_time.cc @@ -95,6 +95,9 @@ Session::sync_time_vars () } break; }; +#ifdef HAVE_LTC + ltc_tx_parse_offset(); +#endif } void diff --git a/libs/timecode/src/time.cc b/libs/timecode/src/time.cc index b39da34d6d..9a67e177b7 100644 --- a/libs/timecode/src/time.cc +++ b/libs/timecode/src/time.cc @@ -21,6 +21,7 @@ #include <math.h> #include <stdio.h> +#include <stdlib.h> #include "timecode/time.h" @@ -761,8 +762,8 @@ sample_to_timecode ( int64_t offset_sample; if (!use_offset) { - offset_sample = sample; - timecode.negative = false; + timecode.negative = (sample < 0); + offset_sample = llabs(sample); } else { if (offset_is_negative) { offset_sample = sample + offset_samples; |