diff options
author | Michael Fisher <mfisher31@gmail.com> | 2013-07-29 12:19:55 -0500 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2013-07-29 20:05:11 +0200 |
commit | d3919894449e2f61a1cfa64330b0810c53042f97 (patch) | |
tree | 8f18a0150bb0164ee22c2ed6751daeeaf2957b96 /libs/ardour/ticker.cc | |
parent | 3538fa84425069be35e3b1cd1e0c898bbfa43fed (diff) |
Moving Mclk locating code to ticker.cc. Housekeeping
Diffstat (limited to 'libs/ardour/ticker.cc')
-rw-r--r-- | libs/ardour/ticker.cc | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/libs/ardour/ticker.cc b/libs/ardour/ticker.cc index 5d078952a1..75da935239 100644 --- a/libs/ardour/ticker.cc +++ b/libs/ardour/ticker.cc @@ -80,8 +80,8 @@ void MidiClockTicker::transport_state_changed() framepos_t position = _session->transport_frame(); DEBUG_TRACE (PBD::DEBUG::MidiClock, - string_compose ("Transport state change @ %4, speed: %1 position: %2 play loop: %3\n", speed, position, _session->get_play_loop(), position) - ); + string_compose ("Transport state change @ %4, speed: %1 position: %2 play loop: %3\n", speed, position, _session->get_play_loop(), position) + ); if (speed == 1.0f) { _last_tick = position; @@ -109,6 +109,7 @@ void MidiClockTicker::transport_state_changed() return; send_stop_event(0); + send_position_event (position, 0); } tick (position); @@ -116,7 +117,12 @@ void MidiClockTicker::transport_state_changed() void MidiClockTicker::position_changed (framepos_t position) { - DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Position change: %1\n", position)); + const double speed = _session->transport_speed(); + DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Transport Position Change: %1, speed: %2\n", position, speed)); + + if (speed == 0.0f && Config->get_send_midi_clock()) { + send_position_event (position, 0); + } _last_tick = position; } @@ -155,9 +161,11 @@ void MidiClockTicker::tick (const framepos_t& transport_frame) MIDI::JackMIDIPort* mp = dynamic_cast<MIDI::JackMIDIPort*> (_midi_port); + /* DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Transport: %1, last tick time: %2, next tick time: %3, offset: %4, cycle length: %5\n", transport_frame, _last_tick, next_tick, next_tick_offset, mp ? mp->nframes_this_cycle() : 0)); + */ if (!mp || (next_tick_offset >= mp->nframes_this_cycle())) { break; @@ -188,7 +196,7 @@ void MidiClockTicker::send_midi_clock_event (pframes_t offset) return; } - DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Tick with offset %1\n", offset)); + // DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Tick with offset %1\n", offset)); static uint8_t _midi_clock_tick[1] = { MIDI_CMD_COMMON_CLOCK }; _midi_port->write (_midi_clock_tick, 1, offset); @@ -200,6 +208,8 @@ void MidiClockTicker::send_start_event (pframes_t offset) return; } + DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Start %1\n", _last_tick)); + static uint8_t _midi_clock_tick[1] = { MIDI_CMD_COMMON_START }; _midi_port->write (_midi_clock_tick, 1, offset); } @@ -210,6 +220,8 @@ void MidiClockTicker::send_continue_event (pframes_t offset) return; } + DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Continue %1\n", _last_tick)); + static uint8_t _midi_clock_tick[1] = { MIDI_CMD_COMMON_CONTINUE }; _midi_port->write (_midi_clock_tick, 1, offset); } @@ -220,9 +232,42 @@ void MidiClockTicker::send_stop_event (pframes_t offset) return; } + DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Stop %1\n", _last_tick)); + static uint8_t _midi_clock_tick[1] = { MIDI_CMD_COMMON_STOP }; _midi_port->write (_midi_clock_tick, 1, offset); } +void +MidiClockTicker::send_position_event (framepos_t transport_position, pframes_t offset) +{ + if (_midi_port == 0 || _session == 0 || _session->engine().freewheeling()) { + return; + } + + const TempoMap& tempo = _session->tempo_map(); + + Timecode::BBT_Time time; + _session->bbt_time (transport_position, time); + const double beats_per_bar = tempo.meter_at(transport_position).divisions_per_bar(); + /* Midi Beats in terms of Song Position Pointer is equivalent to total + sixteenth notes at 'time' */ + const uint32_t midi_beats = 4 * (((time.bars - 1) * beats_per_bar) + time.beats - 1); + /* can only use 14bits worth */ + if (midi_beats > 0x3fff) { + return; + } + + /* split midi beats into a 14bit value */ + MIDI::byte msg[3] = { + MIDI_CMD_COMMON_SONG_POS, + midi_beats & 0x007f, + midi_beats & 0x3f80 + }; + + DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Song Position: %1\n", midi_beats)); + + _midi_port->midimsg (msg, sizeof (msg), offset); +} |