#include "ardour/audioengine.h"
#include "ardour/midi_buffer.h"
#include "ardour/midi_port.h"
+#include "ardour/lmath.h"
#include "ardour/ticker.h"
#include "ardour/session.h"
#include "ardour/tempo.h"
{
public:
- Position() : speed(0.0f), frame(0) { }
+ Position() : speed(0.0f), frame(0), midi_beats(0) { }
~Position() { }
-
+
/** Sync timing information taken from the given Session
- * @return True if timings differed
+ * @return True if timings differed
*/
bool sync (Session* s) {
bool changed = false;
-
+
double sp = s->transport_speed();
framecnt_t fr = s->transport_frame();
-
+
if (speed != sp) {
speed = sp;
changed = true;
s->bbt_time (this->frame, *this);
const TempoMap& tempo = s->tempo_map();
+ const Meter& meter = tempo.meter_at_frame (frame);
- const double divisions = tempo.meter_at(frame).divisions_per_bar();
- const double divisor = tempo.meter_at(frame).note_divisor();
+ const double divisions = meter.divisions_per_bar();
+ const double divisor = meter.note_divisor();
const double qnote_scale = divisor * 0.25f;
double mb;
/** Midi Beats in terms of Song Position Pointer is equivalent to total
- * sixteenth notes at 'time'
+ * sixteenth notes at 'time'
*/
mb = (((bars - 1) * divisions) + beats - 1);
framecnt_t frame;
double midi_beats;
double midi_clocks;
-
+
void print (std::ostream& s) {
s << "frames: " << frame << " midi beats: " << midi_beats << " speed: " << speed;
}
MidiClockTicker::set_session (Session* s)
{
SessionHandlePtr::set_session (s);
-
+
if (_session) {
_session->TransportStateChange.connect_same_thread (_session_connections, boost::bind (&MidiClockTicker::transport_state_changed, this));
_session->TransportLooped.connect_same_thread (_session_connections, boost::bind (&MidiClockTicker::transport_looped, this));
send_position_event (llrint (_pos->midi_beats), 0, nframes);
} else if (_pos->speed == 1.0f) {
send_stop_event (0, nframes);
-
+
if (_pos->frame == 0) {
send_start_event (0, nframes);
} else {
if (_pos->speed == 1.0f) {
if (_session->get_play_loop()) {
assert(_session->locations()->auto_loop_location());
-
+
if (_pos->frame == _session->locations()->auto_loop_location()->start()) {
send_start_event (0, nframes);
} else {
send_continue_event (0, nframes);
}
-
+
} else if (_pos->frame == 0) {
send_start_event (0, nframes);
} else {
send_continue_event (0, nframes);
}
-
+
// send_midi_clock_event (0);
-
+
} else if (_pos->speed == 0.0f) {
send_stop_event (0, nframes);
send_position_event (llrint (_pos->midi_beats), 0, nframes);
double
MidiClockTicker::one_ppqn_in_frames (framepos_t transport_position)
{
- const Tempo& current_tempo = _session->tempo_map().tempo_at (transport_position);
- double frames_per_beat = current_tempo.frames_per_beat (_session->nominal_frame_rate());
-
- double quarter_notes_per_beat = 4.0 / current_tempo.note_type();
- double frames_per_quarter_note = frames_per_beat / quarter_notes_per_beat;
+ const double frames_per_quarter_note = _session->tempo_map().frames_per_quarter_note_at (transport_position, _session->nominal_frame_rate());
return frames_per_quarter_note / double (_ppqn);
}