X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fanalyser.cc;h=58a8f30245351698efec58f9c0c3a9e028f010ad;hb=3aade3801d5ff2c8314eefc4375475f46e913fac;hp=2e14c74b86e267016340b9d7764e5f41c33b3694;hpb=449aab3c465bbbf66d221fac3d7ea559f1720357;p=ardour.git diff --git a/libs/ardour/analyser.cc b/libs/ardour/analyser.cc index 2e14c74b86..58a8f30245 100644 --- a/libs/ardour/analyser.cc +++ b/libs/ardour/analyser.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2008 Paul Davis + Copyright (C) 2008 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,26 +17,28 @@ */ -#include -#include -#include +#include "ardour/analyser.h" +#include "ardour/audiofilesource.h" +#include "ardour/session_event.h" +#include "ardour/transient_detector.h" -#include -#include +#include "pbd/compose.h" +#include "pbd/error.h" +#include "i18n.h" using namespace std; -using namespace sigc; using namespace ARDOUR; using namespace PBD; Analyser* Analyser::the_analyser = 0; -Glib::StaticMutex Analyser::analysis_queue_lock = GLIBMM_STATIC_MUTEX_INIT; -Glib::Cond* Analyser::SourcesToAnalyse = 0; +Glib::Threads::Mutex Analyser::analysis_active_lock; +Glib::Threads::Mutex Analyser::analysis_queue_lock; +Glib::Threads::Cond Analyser::SourcesToAnalyse; list > Analyser::analysis_queue; Analyser::Analyser () { - + } Analyser::~Analyser () @@ -52,8 +54,7 @@ analyser_work () void Analyser::init () { - SourcesToAnalyse = new Glib::Cond(); - Glib::Thread::create (sigc::ptr_fun (analyser_work), false); + Glib::Threads::Thread::create (sigc::ptr_fun (analyser_work)); } void @@ -67,22 +68,22 @@ Analyser::queue_source_for_analysis (boost::shared_ptr src, bool force) return; } - Glib::Mutex::Lock lm (analysis_queue_lock); + Glib::Threads::Mutex::Lock lm (analysis_queue_lock); analysis_queue.push_back (boost::weak_ptr(src)); - SourcesToAnalyse->broadcast (); + SourcesToAnalyse.broadcast (); } void Analyser::work () { - PBD::ThreadCreated (pthread_self(), string ("analyser-") + to_string (pthread_self(), std::dec)); + SessionEvent::create_per_thread_pool ("Analyser", 64); while (true) { analysis_queue_lock.lock (); wait: if (analysis_queue.empty()) { - SourcesToAnalyse->wait (analysis_queue_lock); + SourcesToAnalyse.wait (analysis_queue_lock); } if (analysis_queue.empty()) { @@ -95,7 +96,8 @@ Analyser::work () boost::shared_ptr afs = boost::dynamic_pointer_cast (src); - if (afs && afs->length()) { + if (afs && afs->length(afs->timeline_position())) { + Glib::Threads::Mutex::Lock lm (analysis_active_lock); analyse_audio_file_source (afs); } } @@ -106,14 +108,24 @@ Analyser::analyse_audio_file_source (boost::shared_ptr src) { AnalysisFeatureList results; - TransientDetector td (src->sample_rate()); - - if (td.run (src->get_transients_path(), src.get(), 0, results) == 0) { - src->set_been_analysed (true); - } else { + try { + TransientDetector td (src->sample_rate()); + if (td.run (src->get_transients_path(), src.get(), 0, results) == 0) { + src->set_been_analysed (true); + } else { + src->set_been_analysed (false); + } + } catch (...) { + error << string_compose(_("Transient Analysis failed for %1."), _("Audio File Source")) << endmsg;; src->set_been_analysed (false); + return; } - } - +void +Analyser::flush () +{ + Glib::Threads::Mutex::Lock lq (analysis_queue_lock); + Glib::Threads::Mutex::Lock la (analysis_active_lock); + analysis_queue.clear(); +}