+ 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 ()
+{
+ _audio_dialog.reset();
+
+ auto ac = _parent->selected_audio ();
+ if (ac.size() != 1) {
+ return;
+ }
+
+ _audio_dialog.reset(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 {
+ /* 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 (...) {
+
+ }
+ }