mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-07 14:15:46 +01:00
* removed unnecessary method calls (preparse/postparse) in JACK_MidiPort
* Changed calculation of current speed and transport position to double to avoid accumulating rounding errors git-svn-id: svn://localhost/ardour2/branches/3.0@4106 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
72f286e10e
commit
6abd152d17
3 changed files with 27 additions and 28 deletions
|
|
@ -231,6 +231,9 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
|
|||
|
||||
/// the time stamp and transport position of the last inbound MIDI clock message
|
||||
SafeTime current;
|
||||
/// since current.position is integral, we need to keep track of decimal places
|
||||
/// to be precise
|
||||
double current_position;
|
||||
|
||||
/// The duration of the current MIDI clock frame in frames
|
||||
nframes_t current_midi_clock_frame_duration;
|
||||
|
|
@ -239,11 +242,11 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
|
|||
|
||||
/// how many MIDI clock frames to average over
|
||||
static const int32_t accumulator_size = 4;
|
||||
float accumulator[accumulator_size];
|
||||
double accumulator[accumulator_size];
|
||||
int32_t accumulator_index;
|
||||
|
||||
/// the running average of current_midi_clock_frame_duration
|
||||
float average_midi_clock_frame_duration;
|
||||
double average_midi_clock_frame_duration;
|
||||
|
||||
void reset ();
|
||||
void start (MIDI::Parser& parser, nframes_t timestamp);
|
||||
|
|
|
|||
|
|
@ -85,13 +85,13 @@ MIDIClock_Slave::update_midi_clock (Parser& parser, nframes_t timestamp)
|
|||
const Tempo& current_tempo = session.tempo_map().tempo_at(now);
|
||||
const Meter& current_meter = session.tempo_map().meter_at(now);
|
||||
double frames_per_beat =
|
||||
current_tempo.frames_per_beat(session.frame_rate(),
|
||||
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;
|
||||
|
||||
one_ppqn_in_frames = frames_per_quarter_note / ppqn;
|
||||
one_ppqn_in_frames = frames_per_quarter_note / double (ppqn);
|
||||
|
||||
// for the first MIDI clock event we dont have any past
|
||||
// data, so we assume a sane tempo
|
||||
|
|
@ -100,20 +100,18 @@ MIDIClock_Slave::update_midi_clock (Parser& parser, nframes_t timestamp)
|
|||
} else {
|
||||
current_midi_clock_frame_duration = now - last.timestamp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// moving average over incoming intervals
|
||||
accumulator[accumulator_index++] = (float) current_midi_clock_frame_duration;
|
||||
accumulator[accumulator_index++] = current_midi_clock_frame_duration;
|
||||
if(accumulator_index == accumulator_size)
|
||||
accumulator_index = 0;
|
||||
|
||||
average_midi_clock_frame_duration = 0.0;
|
||||
for(int i = 0; i < accumulator_size; i++)
|
||||
average_midi_clock_frame_duration += accumulator[i];
|
||||
average_midi_clock_frame_duration /= accumulator_size;
|
||||
average_midi_clock_frame_duration /= double(accumulator_size);
|
||||
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
JACK_MidiPort *jack_port = dynamic_cast<JACK_MidiPort *>(port);
|
||||
pthread_t process_thread_id = 0;
|
||||
if(jack_port) {
|
||||
|
|
@ -132,6 +130,7 @@ MIDIClock_Slave::update_midi_clock (Parser& parser, nframes_t timestamp)
|
|||
|
||||
current.guard1++;
|
||||
current.position += one_ppqn_in_frames;
|
||||
current_position += one_ppqn_in_frames;
|
||||
current.timestamp = now;
|
||||
current.guard2++;
|
||||
|
||||
|
|
@ -153,9 +152,10 @@ MIDIClock_Slave::start (Parser& parser, nframes_t timestamp)
|
|||
|
||||
current_midi_clock_frame_duration = 0;
|
||||
|
||||
session.request_transport_speed(one_ppqn_in_frames / average_midi_clock_frame_duration);
|
||||
session.request_transport_speed(one_ppqn_in_frames / double(average_midi_clock_frame_duration));
|
||||
current.guard1++;
|
||||
current.position = 0;
|
||||
current_position = 0;
|
||||
current.timestamp = now;
|
||||
current.guard2++;
|
||||
|
||||
|
|
@ -172,6 +172,7 @@ MIDIClock_Slave::stop (Parser& parser, nframes_t timestamp)
|
|||
|
||||
current.guard1++;
|
||||
current.position = 0;
|
||||
current_position = 0;
|
||||
current.timestamp = 0;
|
||||
current.guard2++;
|
||||
|
||||
|
|
@ -211,23 +212,17 @@ MIDIClock_Slave::ok() const
|
|||
bool
|
||||
MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
|
||||
{
|
||||
float previous_speed;
|
||||
|
||||
nframes_t now = session.engine().frame_time();
|
||||
|
||||
if(!_started) {
|
||||
if (!_started) {
|
||||
speed = 0.0;
|
||||
pos = 0;
|
||||
previous_speed = one_ppqn_in_frames / average_midi_clock_frame_duration;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
nframes_t now = session.engine().frame_time();
|
||||
SafeTime last;
|
||||
read_current (&last);
|
||||
|
||||
/* no timecode for 1/4 second ? conclude that its stopped */
|
||||
|
||||
if (last_inbound_frame &&
|
||||
now > last_inbound_frame &&
|
||||
now - last_inbound_frame > session.frame_rate() / 4) {
|
||||
|
|
@ -242,20 +237,20 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
|
|||
|
||||
//cerr << " now: " << now << " last: " << last.timestamp;
|
||||
|
||||
speed = one_ppqn_in_frames / average_midi_clock_frame_duration;
|
||||
// calculate speed
|
||||
double speed_double = one_ppqn_in_frames / average_midi_clock_frame_duration;
|
||||
speed = float(speed_double);
|
||||
//cerr << " final speed: " << speed;
|
||||
|
||||
// calculate position
|
||||
if (now > last.timestamp) {
|
||||
// we are in between MIDI clock messages
|
||||
// so we interpolate position according to speed
|
||||
nframes_t elapsed = now - last.timestamp;
|
||||
nframes_t delta = elapsed * speed;
|
||||
//cerr << " elapsed: " << elapsed << " elapsed (scaled) " << delta;
|
||||
pos = last.position + delta;
|
||||
pos = nframes_t (current_position + double(elapsed) * speed_double);
|
||||
} else {
|
||||
// A new MIDI clock message has arrived this cycle
|
||||
pos = (last.position + session.transport_frame()) / 2.0;
|
||||
previous_speed = speed;
|
||||
pos = current_position;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -265,7 +260,7 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
|
|||
*/
|
||||
|
||||
// we want start on frame 0 on the first call after a MIDI start
|
||||
if(_starting) {
|
||||
if (_starting) {
|
||||
pos = 0;
|
||||
_starting = false;
|
||||
}
|
||||
|
|
@ -286,6 +281,7 @@ MIDIClock_Slave::reset ()
|
|||
last_inbound_frame = 0;
|
||||
current.guard1++;
|
||||
current.position = 0;
|
||||
current_position = 0;
|
||||
current.timestamp = 0;
|
||||
current.guard2++;
|
||||
|
||||
|
|
|
|||
|
|
@ -76,13 +76,11 @@ JACK_MidiPort::cycle_start (nframes_t nframes)
|
|||
jack_midi_event_get (&ev, jack_buffer, i);
|
||||
|
||||
if (input_parser) {
|
||||
input_parser->raw_preparse (*input_parser, ev.buffer, ev.size);
|
||||
for (size_t i = 0; i < ev.size; i++) {
|
||||
// the midi events here are used for MIDI clock only
|
||||
input_parser->set_midi_clock_timestamp(ev.time + jack_last_frame_time(_jack_client));
|
||||
input_parser->scanner (ev.buffer[i]);
|
||||
}
|
||||
input_parser->raw_postparse (*input_parser, ev.buffer, ev.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -199,6 +197,8 @@ JACK_MidiPort::read(byte * buf, size_t bufsize)
|
|||
|
||||
jack_midi_event_t ev;
|
||||
|
||||
cerr << "JACK_MidiPort::read called" << endl;
|
||||
|
||||
int err = jack_midi_event_get (&ev,
|
||||
jack_port_get_buffer(_jack_input_port, _nframes_this_cycle),
|
||||
_last_read_index++);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue