2 Copyright (C) 2008 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "ardour/analyser.h"
21 #include "ardour/audiofilesource.h"
22 #include "ardour/session_event.h"
23 #include "ardour/transient_detector.h"
26 using namespace ARDOUR;
29 Analyser* Analyser::the_analyser = 0;
30 Glib::StaticMutex Analyser::analysis_queue_lock = GLIBMM_STATIC_MUTEX_INIT;
31 Glib::Cond* Analyser::SourcesToAnalyse = 0;
32 list<boost::weak_ptr<Source> > Analyser::analysis_queue;
39 Analyser::~Analyser ()
52 SourcesToAnalyse = new Glib::Cond();
53 Glib::Thread::create (sigc::ptr_fun (analyser_work), false);
57 Analyser::queue_source_for_analysis (boost::shared_ptr<Source> src, bool force)
59 if (!src->can_be_analysed()) {
63 if (!force && src->has_been_analysed()) {
67 Glib::Mutex::Lock lm (analysis_queue_lock);
68 analysis_queue.push_back (boost::weak_ptr<Source>(src));
69 SourcesToAnalyse->broadcast ();
75 SessionEvent::create_per_thread_pool ("Analyser", 64);
78 analysis_queue_lock.lock ();
81 if (analysis_queue.empty()) {
82 SourcesToAnalyse->wait (analysis_queue_lock);
85 if (analysis_queue.empty()) {
89 boost::shared_ptr<Source> src (analysis_queue.front().lock());
90 analysis_queue.pop_front();
91 analysis_queue_lock.unlock ();
93 boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (src);
95 if (afs && afs->length(afs->timeline_position())) {
96 analyse_audio_file_source (afs);
102 Analyser::analyse_audio_file_source (boost::shared_ptr<AudioFileSource> src)
104 AnalysisFeatureList results;
106 TransientDetector td (src->sample_rate());
108 if (td.run (src->get_transients_path(), src.get(), 0, results) == 0) {
109 src->set_been_analysed (true);
111 src->set_been_analysed (false);