+
+void
+AudioPanel::setup_peak ()
+{
+ ContentList sel = _parent->selected_audio ();
+ bool alert = false;
+
+ if (sel.size() != 1) {
+ _peak->SetLabel (wxT (""));
+ } else {
+ shared_ptr<Playlist> playlist (new Playlist);
+ playlist->add (sel.front ());
+ try {
+ shared_ptr<AudioAnalysis> analysis (new AudioAnalysis (_parent->film()->audio_analysis_path (playlist)));
+ if (analysis->sample_peak ()) {
+ float const peak_dB = 20 * log10 (analysis->sample_peak().get()) + analysis->gain_correction (playlist);
+ if (peak_dB > -3) {
+ alert = true;
+ }
+ _peak->SetLabel (wxString::Format (_("Peak: %.2fdB"), peak_dB));
+ } else {
+ _peak->SetLabel (_("Peak: unknown"));
+ }
+ } catch (...) {
+ _peak->SetLabel (_("Peak: unknown"));
+ }
+ }
+
+ static wxColour normal = _peak->GetForegroundColour ();
+
+ if (alert) {
+ _peak->SetForegroundColour (wxColour (255, 0, 0));
+ } else {
+ _peak->SetForegroundColour (normal);
+ }
+}
+
+void
+AudioPanel::active_jobs_changed (optional<string> j)
+{
+ if (j && *j == "analyse_audio") {
+ setup_peak ();
+ }
+}
+
+void
+AudioPanel::reference_clicked ()
+{
+ ContentList c = _parent->selected ();
+ if (c.size() != 1) {
+ return;
+ }
+
+ shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
+ if (!d) {
+ return;
+ }
+
+ d->set_reference_audio (_reference->GetValue ());
+}