#include "lib/ffmpeg_content.h"
#include "lib/job_manager.h"
#include "lib/maths_util.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
#include <wx/spinctrl.h>
-#include <iostream>
+LIBDCP_ENABLE_WARNINGS
-using std::cout;
using std::dynamic_pointer_cast;
using std::list;
using std::make_shared;
using namespace dcpomatic;
+std::map<boost::filesystem::path, float> AudioPanel::_peak_cache;
+
+
AudioPanel::AudioPanel (ContentPanel* p)
: ContentSubPanel (p, _("Audio"))
{
setup_peak ();
layout ();
} else if (property == AudioContentProperty::GAIN) {
+ /* This is a bit aggressive but probably not so bad */
+ _peak_cache.clear();
setup_peak ();
} else if (property == DCPContentProperty::REFERENCE_AUDIO) {
if (ac.size() == 1) {
auto playlist = make_shared<Playlist>();
playlist->add (_parent->film(), sel.front());
try {
- auto analysis = make_shared<AudioAnalysis>(_parent->film()->audio_analysis_path(playlist));
- peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist);
+ /* Loading the audio analysis file is slow, and this ::peak() is called a few times when
+ * the content selection is changed, so cache it.
+ */
+ auto const path = _parent->film()->audio_analysis_path(playlist);
+ auto cached = _peak_cache.find(path);
+ if (cached != _peak_cache.end()) {
+ peak_dB = cached->second;
+ } else {
+ auto analysis = make_shared<AudioAnalysis>(path);
+ peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist);
+ _peak_cache[path] = *peak_dB;
+ }
} catch (...) {
}