summaryrefslogtreecommitdiff
path: root/libs/ardour/ticker.cc
diff options
context:
space:
mode:
authorHans Baier <hansfbaier@googlemail.com>2008-11-26 23:32:55 +0000
committerHans Baier <hansfbaier@googlemail.com>2008-11-26 23:32:55 +0000
commit5ed141cd143abac95ba37c8d944ece847ba86173 (patch)
tree8a67244499b45b4d34685a0c0ad74981991e35e9 /libs/ardour/ticker.cc
parent38382b792113cbf23881c1dca64e16c2d0207d45 (diff)
* added Menu for sending midi clock
* hooked up MidiClockTicker to the session git-svn-id: svn://localhost/ardour2/branches/3.0@4267 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ticker.cc')
-rw-r--r--libs/ardour/ticker.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/libs/ardour/ticker.cc b/libs/ardour/ticker.cc
index bf84bba92b..866fa83e07 100644
--- a/libs/ardour/ticker.cc
+++ b/libs/ardour/ticker.cc
@@ -17,8 +17,10 @@
$Id$
*/
+
#include "ardour/ticker.h"
#include "ardour/session.h"
+#include "ardour/tempo.h"
namespace ARDOUR
{
@@ -34,10 +36,45 @@ void Ticker::set_session(Session& s)
}
}
+void MidiClockTicker::set_session(Session& s)
+{
+ Ticker::set_session(s);
+
+ if(_session) {
+ _session->MIDIClock_PortChanged.connect(mem_fun (*this, &MidiClockTicker::update_midi_clock_port));
+ update_midi_clock_port();
+ }
+}
-void MidiClockTicker::tick(const nframes_t& transport_frames, const BBT_Time& transport_bbt, const SMPTE::Time& transport_smpt)
+void MidiClockTicker::update_midi_clock_port()
{
+ _jack_port = (MIDI::JACK_MidiPort*) _session->midi_clock_port();
+}
+
+void MidiClockTicker::tick(const nframes_t& transport_frames, const BBT_Time& transport_bbt, const SMPTE::Time& transport_smpt)
+{
+ if (!Config->get_send_midi_clock() || _session == 0 || _session->transport_speed() != 1.0f)
+ return;
+
+ const Tempo& current_tempo = _session->tempo_map().tempo_at(transport_frames);
+ const Meter& current_meter = _session->tempo_map().meter_at(transport_frames);
+ double frames_per_beat =
+ current_tempo.frames_per_beat(_session->nominal_frame_rate(),
+ current_meter);
+
+ double quarter_notes_per_beat = 4.0 / current_tempo.note_type();
+ double frames_per_quarter_note = frames_per_beat / quarter_notes_per_beat;
+
+ nframes_t one_ppqn_in_frames = frames_per_quarter_note / double (_ppqn);
+
+ nframes_t next_tick = _last_tick + one_ppqn_in_frames;
+ nframes_t next_tick_offset = next_tick - transport_frames;
+
+ assert(_jack_port->is_process_thread());
+ static uint8_t _midi_clock_tick[1] = { MIDI_CMD_COMMON_TICK };
+ _jack_port->write(_midi_clock_tick, 1, next_tick_offset);
+ _last_tick = next_tick;
}
}