bool locked() const;
bool ok() const;
- bool starting() const { return _starting; }
nframes_t resolution() const;
bool requires_seekahead () const { return true; }
void stop (MIDI::Parser& parser);
void update_midi_clock (MIDI::Parser& parser);
void read_current (SafeTime *) const;
- bool _starting;
+ bool _started;
};
class ADAT_Slave : public Slave
port = &p;
std::cerr << "MIDIClock_Slave: connecting to port " << port->name() << std::endl;
- port->input()->trace(true, &std::cout, string(port->name()));
connections.push_back (port->input()->timing.connect (mem_fun (*this, &MIDIClock_Slave::update_midi_clock)));
connections.push_back (port->input()->start.connect (mem_fun (*this, &MIDIClock_Slave::start)));
void
MIDIClock_Slave::update_midi_clock (Parser& parser)
{
+ // ignore clock events if no start event received
+ if(!_started)
+ return;
nframes_t now = session.engine().frame_time();
- _starting = false;
-
- std::cerr << "got MIDI Clock message at time " << now << std::endl;
SafeTime last;
read_current (&last);
midi_clock_frame += (long) (one_ppqn_in_frames)
+ session.worst_output_latency();
+ /*
+ std::cerr << "got MIDI Clock message at time " << now
+ << " result: " << midi_clock_frame
+ << " open_ppqn_in_frames: " << one_ppqn_in_frames << std::endl;
+ */
+
if (first_midi_clock_frame == 0) {
first_midi_clock_frame = midi_clock_frame;
first_midi_clock_time = now;
std::cerr << "MIDIClock_Slave got start message" << endl;
midi_clock_speed = 1.0f;
- _starting = true;
+ _started = true;
}
void
std::cerr << "MIDIClock_Slave got stop message" << endl;
midi_clock_speed = 0.0f;
- midi_clock_frame = 0;
- _starting = false;
-
- current.guard1++;
- current.position = midi_clock_frame;
- current.timestamp = 0;
- current.guard2++;
+ _started = false;
}
void
speed_now = (float) ((last.position - first_midi_clock_frame) / (double) (now - first_midi_clock_time));
+ cerr << "speed_and_position: speed_now: " << speed_now ;
+
accumulator[accumulator_index++] = speed_now;
if (accumulator_index >= accumulator_size) {
pos = elapsed + last.position;
speed = midi_clock_speed;
+
+ cerr << " final speed: " << speed << " position: " << pos << endl;
return true;
}
{
MIDI::Parser* input_parser;
+ cerr << "enabling tracing: " << yn << " for input port " << port->name() << endl;
+
if (port) {
if ((input_parser = port->input()) != 0) {
input_parser->trace (yn, &cout, "input: ");
input_parser->trace (yn, &cout, "input: ");
}
}
+
+ if (_midi_clock_port
+ && _midi_clock_port != _mmc_port
+ && _midi_clock_port != _mtc_port
+ && _midi_clock_port != _midi_port) {
+ if ((input_parser = _midi_clock_port->input()) != 0) {
+ input_parser->trace (yn, &cout, "input: ");
+ }
+ }
}
Config->set_trace_midi_input (yn);
nfds++;
}
- cerr << "before handling midi clock port" << endl;
if (_midi_clock_port && (_midi_clock_port != _mmc_port || !Config->get_mmc_control()) && _midi_clock_port->selectable() >= 0) {
- cerr << "inside handling midi clock port" << endl;
pfd[nfds].fd = _midi_clock_port->selectable();
pfd[nfds].events = POLLIN|POLLHUP|POLLERR;
ports[nfds] = _midi_clock_port;
_last_read_index = 0;
_last_write_timestamp = 0;
+ // output
void *buffer = jack_port_get_buffer (_jack_output_port, nframes);
jack_midi_clear_buffer (buffer);
flush (buffer);
+
+ // input
+ void* jack_buffer = jack_port_get_buffer(_jack_input_port, nframes);
+ const nframes_t event_count = jack_midi_get_event_count(jack_buffer);
+
+ jack_midi_event_t ev;
+
+ for (nframes_t i=0; i < event_count; ++i) {
+
+ 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++) {
+ input_parser->scanner (ev.buffer[i]);
+ }
+ input_parser->raw_postparse (*input_parser, ev.buffer, ev.size);
+ }
+ }
}
int
{
assert(_currently_in_cycle);
assert(_jack_input_port);
-
+
jack_midi_event_t ev;
int err = jack_midi_event_get (&ev,
trace_connection.disconnect ();
if (onoff) {
+ cerr << "enabling tracing for port " << _port.name() << endl;
trace_stream = o;
trace_prefix = prefix;
trace_connection = any.connect (mem_fun (*this, &Parser::trace_event));