+ static_cast<AudioEngine*>(arg)->freewheel_callback (onoff);
+}
+
+void
+AudioEngine::freewheel_callback (int onoff)
+{
+ _freewheeling = onoff;
+
+ if (onoff) {
+ _pre_freewheel_mmc_enabled = MIDI::Manager::instance()->mmc()->send_enabled ();
+ MIDI::Manager::instance()->mmc()->enable_send (false);
+ } else {
+ MIDI::Manager::instance()->mmc()->enable_send (_pre_freewheel_mmc_enabled);
+ }
+}
+
+void
+AudioEngine::_registration_callback (jack_port_id_t /*id*/, int /*reg*/, void* arg)
+{
+ AudioEngine* ae = static_cast<AudioEngine*> (arg);
+
+ if (!ae->port_remove_in_progress) {
+ ae->PortRegisteredOrUnregistered (); /* EMIT SIGNAL */
+ }
+}
+
+void
+AudioEngine::_latency_callback (jack_latency_callback_mode_t mode, void* arg)
+{
+ return static_cast<AudioEngine *> (arg)->jack_latency_callback (mode);
+}
+
+void
+AudioEngine::_connect_callback (jack_port_id_t id_a, jack_port_id_t id_b, int conn, void* arg)
+{
+ AudioEngine* ae = static_cast<AudioEngine*> (arg);
+
+ if (ae->port_remove_in_progress) {
+ return;
+ }
+
+ GET_PRIVATE_JACK_POINTER (ae->_jack);
+
+ jack_port_t* jack_port_a = jack_port_by_id (_priv_jack, id_a);
+ jack_port_t* jack_port_b = jack_port_by_id (_priv_jack, id_b);
+
+ boost::shared_ptr<Port> port_a;
+ boost::shared_ptr<Port> port_b;
+
+ boost::shared_ptr<Ports> pr = ae->ports.reader ();
+ Ports::iterator i = pr->begin ();
+ while (i != pr->end() && (port_a == 0 || port_b == 0)) {
+ if (jack_port_a == i->second->jack_port()) {
+ port_a = i->second;
+ } else if (jack_port_b == i->second->jack_port()) {
+ port_b = i->second;
+ }
+ ++i;
+ }
+
+ ae->PortConnectedOrDisconnected (
+ port_a, jack_port_name (jack_port_a),
+ port_b, jack_port_name (jack_port_b),
+ conn == 0 ? false : true
+ ); /* EMIT SIGNAL */
+}
+
+void
+AudioEngine::split_cycle (pframes_t offset)
+{
+ /* caller must hold process lock */
+
+ Port::increment_global_port_buffer_offset (offset);
+
+ /* tell all Ports that we're going to start a new (split) cycle */
+
+ boost::shared_ptr<Ports> p = ports.reader();
+
+ for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+ i->second->cycle_split ();
+ }
+}
+
+void*
+AudioEngine::process_thread ()
+{
+ /* JACK doesn't do this for us when we use the wait API
+ */
+
+ _thread_init_callback (0);
+
+ _main_thread = new ProcessThread;
+
+ while (1) {
+ GET_PRIVATE_JACK_POINTER_RET(_jack,0);
+
+ pframes_t nframes = jack_cycle_wait (_priv_jack);
+
+ if (process_callback (nframes)) {
+ return 0;
+ }
+
+ jack_cycle_signal (_priv_jack, 0);
+ }
+
+ return 0;