X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fanalyser.cc;h=457291f72f51071f3cbc567fbe0bfe167d89e5eb;hb=1389fa9e2246a1b7faf193932a7c3ca4ba559c64;hp=2e14c74b86e267016340b9d7764e5f41c33b3694;hpb=006a181cd028fb53c8cb8902b904a06c0214a637;p=ardour.git diff --git a/libs/ardour/analyser.cc b/libs/ardour/analyser.cc index 2e14c74b86..457291f72f 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,29 @@ */ -#include -#include -#include +#include "ardour/analyser.h" +#include "ardour/audiofilesource.h" +#include "ardour/rc_configuration.h" +#include "ardour/session_event.h" +#include "ardour/transient_detector.h" -#include -#include +#include "pbd/compose.h" +#include "pbd/error.h" +#include "pbd/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 +55,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 +69,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 +97,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 +109,25 @@ 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()); + td.set_sensitivity (3, Config->get_transient_sensitivity()); // "General purpose" + 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(); +}