Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[ardour.git] / libs / ardour / audioengine.cc
index 71481e695f0900272e11d2bb096af3cf43e5b408..8b5d4ba42cfd76ce39fb6ad69c42b9a7d5bb4c69 100644 (file)
@@ -86,20 +86,22 @@ AudioEngine::AudioEngine (string client_name)
 
        Port::set_engine (this);
        
-       Parameter::init_metadata(NullAutomation);
-       Parameter::init_metadata(GainAutomation);
-       Parameter::init_metadata(PanAutomation);
-       Parameter::init_metadata(PluginAutomation);
-       Parameter::init_metadata(SoloAutomation);
-       Parameter::init_metadata(MuteAutomation);
-       Parameter::init_metadata(MidiCCAutomation);
-       Parameter::init_metadata(MidiPgmChangeAutomation);
-       Parameter::init_metadata(MidiPitchBenderAutomation);
-       Parameter::init_metadata(MidiChannelAftertouchAutomation);
-       Parameter::init_metadata(FadeInAutomation);
-       Parameter::init_metadata(FadeOutAutomation);
-       Parameter::init_metadata(EnvelopeAutomation);
-       Parameter::init_metadata(MidiCCAutomation);
+       // Initialize parameter metadata (e.g. ranges)
+       Evoral::Parameter p(NullAutomation);
+       p = EventTypeMap::instance().new_parameter(NullAutomation);
+       p = EventTypeMap::instance().new_parameter(GainAutomation);
+       p = EventTypeMap::instance().new_parameter(PanAutomation);
+       p = EventTypeMap::instance().new_parameter(PluginAutomation);
+       p = EventTypeMap::instance().new_parameter(SoloAutomation);
+       p = EventTypeMap::instance().new_parameter(MuteAutomation);
+       p = EventTypeMap::instance().new_parameter(MidiCCAutomation);
+       p = EventTypeMap::instance().new_parameter(MidiPgmChangeAutomation);
+       p = EventTypeMap::instance().new_parameter(MidiPitchBenderAutomation);
+       p = EventTypeMap::instance().new_parameter(MidiChannelPressureAutomation);
+       p = EventTypeMap::instance().new_parameter(FadeInAutomation);
+       p = EventTypeMap::instance().new_parameter(FadeOutAutomation);
+       p = EventTypeMap::instance().new_parameter(EnvelopeAutomation);
+       p = EventTypeMap::instance().new_parameter(MidiCCAutomation);
 }
 
 AudioEngine::~AudioEngine ()
@@ -130,7 +132,7 @@ _thread_init_callback (void *arg)
           knows about it.
        */
 
-       PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096);
+       PBD::notify_gui_about_thread_creation (pthread_self(), X_("Audioengine"), 4096);
        MIDI::JACK_MidiPort::set_process_thread (pthread_self());
 }
 
@@ -342,8 +344,13 @@ AudioEngine::process_callback (nframes_t nframes)
 
        boost::shared_ptr<Ports> p = ports.reader();
 
-       // Prepare ports (ie read data if necessary)
        for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+
+               /* Only run cycle_start() on output ports, because 
+                  inputs must be done in the correct processing order,
+                  which requires interleaving with route processing.
+               */
+
                (*i)->cycle_start (nframes, 0);
        }
 
@@ -359,12 +366,6 @@ AudioEngine::process_callback (nframes_t nframes)
                }
        }
        
-       // Finalize ports (ie write data if necessary)
-
-       for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
-               (*i)->cycle_end (nframes, 0);
-       }
-
        if (_freewheeling) {
                return 0;
        }
@@ -403,11 +404,18 @@ AudioEngine::process_callback (nframes_t nframes)
                        Port *port = (*i);
                        
                        if (port->sends_output()) {
-                               port->get_buffer().silence(nframes);
+                               port->get_buffer(nframes, 0 ).silence(nframes);
                        }
                }
        }
 
+       // Finalize ports (ie write data if necessary)
+
+       for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+
+               (*i)->cycle_end (nframes, 0);
+       }
+
        _processed_frames = next_processed_frames;
        return 0;
 }
@@ -914,8 +922,6 @@ AudioEngine::halted (void *arg)
        ae->_buffer_size = 0;
        ae->_frame_rate = 0;
 
-       cerr << "!!! HALTED !!!\n";
-
        if (was_running) {
                ae->Halted(); /* EMIT SIGNAL */
        }
@@ -1095,7 +1101,6 @@ AudioEngine::transport_stop ()
 void
 AudioEngine::transport_start ()
 {
-       // cerr << "tell JACK to start\n";
        if (_jack) {
                jack_transport_start (_jack);
        }
@@ -1201,19 +1206,10 @@ AudioEngine::connect_to_jack (string client_name)
        _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name);
 
        if (_jack == NULL) {
-
-               if (status & JackServerFailed) {
-                       error << _("Unable to connect to JACK server") << endmsg;
-               }
-               
                // error message is not useful here
                return -1;
        }
 
-       if (status & JackServerStarted) {
-               info << _("JACK server started") << endmsg;
-       }
-
        if (status & JackNameNotUnique) {
                jack_client_name = jack_get_client_name (_jack);
        }
@@ -1320,7 +1316,7 @@ AudioEngine::reconnect_to_jack ()
        
        if (Config->get_jack_time_master()) {
                jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
-       }
+       } 
        
        if (jack_activate (_jack) == 0) {
                _running = true;