+ film_content_changed (AudioContentProperty::STREAMS);
+ film_content_changed (AudioContentProperty::GAIN);
+ film_content_changed (AudioContentProperty::FADE_IN);
+ film_content_changed (AudioContentProperty::FADE_OUT);
+ film_content_changed (AudioContentProperty::USE_SAME_FADES_AS_VIDEO);
+ film_content_changed (DCPContentProperty::REFERENCE_AUDIO);
+
+ setup_sensitivity ();
+}
+
+
+void
+AudioPanel::setup_sensitivity ()
+{
+ auto sel = _parent->selected_audio ();
+
+ shared_ptr<DCPContent> dcp;
+ if (sel.size() == 1) {
+ dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
+ }
+
+ string why_not;
+ bool const can_reference = dcp && dcp->can_reference_audio (_parent->film(), why_not);
+ wxString cannot;
+ if (why_not.empty()) {
+ cannot = _("Cannot reference this DCP's audio.");
+ } else {
+ cannot = _("Cannot reference this DCP's audio: ") + std_to_wx(why_not);
+ }
+ setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
+
+ auto const ref = _reference->GetValue();
+ auto const single = sel.size() == 1;
+
+ auto const all_have_video = std::all_of(sel.begin(), sel.end(), [](shared_ptr<const Content> c) { return static_cast<bool>(c->video); });
+
+ _gain->wrapped()->Enable (!ref);
+ _gain_calculate_button->Enable (!ref && single);
+ _show->Enable (single);
+ _peak->Enable (!ref && single);
+ _delay->wrapped()->Enable (!ref);
+ _mapping->Enable (!ref && single);
+ _description->Enable (!ref && single);
+ _fade_in->Enable (!_use_same_fades_as_video->GetValue());
+ _fade_out->Enable (!_use_same_fades_as_video->GetValue());
+ _use_same_fades_as_video->Enable (!ref && all_have_video);
+}
+
+
+void
+AudioPanel::show_clicked ()
+{
+ if (_audio_dialog) {
+ _audio_dialog->Destroy ();
+ _audio_dialog = nullptr;
+ }
+
+ auto ac = _parent->selected_audio ();
+ if (ac.size() != 1) {
+ return;
+ }
+
+ _audio_dialog = new AudioDialog (this, _parent->film(), _parent->film_viewer(), ac.front());
+ _audio_dialog->Show ();
+}
+
+
+/** @return If there is one selected piece of audio content, return its peak value in dB (if known) */
+optional<float>
+AudioPanel::peak () const
+{
+ optional<float> peak_dB;
+
+ auto sel = _parent->selected_audio ();
+ if (sel.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);
+ } catch (...) {
+
+ }
+ }
+
+ return peak_dB;
+}
+
+
+void
+AudioPanel::setup_peak ()
+{
+ auto sel = _parent->selected_audio ();
+
+ auto peak_dB = peak ();
+ if (sel.size() != 1) {
+ _peak->SetLabel (wxT(""));
+ } else {
+ peak_dB = peak ();
+ if (peak_dB) {
+ _peak->SetLabel (wxString::Format(_("Peak: %.2fdB"), *peak_dB));
+ } else {
+ _peak->SetLabel (_("Peak: unknown"));
+ }
+ }
+
+ static auto normal = _peak->GetForegroundColour ();
+
+ if (peak_dB && *peak_dB > -0.5) {
+ _peak->SetForegroundColour (wxColour (255, 0, 0));
+ } else if (peak_dB && *peak_dB > -3) {
+ _peak->SetForegroundColour (wxColour (186, 120, 0));
+ } else {
+ _peak->SetForegroundColour (normal);
+ }
+}
+