diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-03 13:52:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-14 10:21:11 +0100 |
| commit | b0834f33e972a6e7b0d234d09e420007943a136d (patch) | |
| tree | aac5cde453a18983a7c87462e1042ecd520218a4 /src | |
| parent | d2bd0c628fd0616fe3b7dd02bd955b2c07ab48d5 (diff) | |
Peak value of audio into the audio tab.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/audio_analysis.cc | 19 | ||||
| -rw-r--r-- | src/lib/audio_analysis.h | 4 | ||||
| -rw-r--r-- | src/lib/job_manager.cc | 2 | ||||
| -rw-r--r-- | src/lib/job_manager.h | 2 | ||||
| -rw-r--r-- | src/wx/audio_dialog.cc | 25 | ||||
| -rw-r--r-- | src/wx/audio_dialog.h | 1 | ||||
| -rw-r--r-- | src/wx/audio_panel.cc | 70 | ||||
| -rw-r--r-- | src/wx/audio_panel.h | 3 | ||||
| -rw-r--r-- | src/wx/film_editor.cc | 2 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 2 |
10 files changed, 97 insertions, 33 deletions
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc index 6fcd97c94..10e022322 100644 --- a/src/lib/audio_analysis.cc +++ b/src/lib/audio_analysis.cc @@ -21,6 +21,8 @@ #include "cross.h" #include "util.h" #include "raw_convert.h" +#include "playlist.h" +#include "audio_content.h" #include <libxml++/libxml++.h> #include <boost/filesystem.hpp> #include <boost/foreach.hpp> @@ -38,6 +40,7 @@ using std::cout; using std::max; using std::list; using boost::shared_ptr; +using boost::dynamic_pointer_cast; AudioAnalysis::AudioAnalysis (int channels) { @@ -115,3 +118,19 @@ AudioAnalysis::write (boost::filesystem::path filename) doc->write_to_file_formatted (filename.string ()); } + +float +AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist) +{ + if (playlist->content().size() == 1 && analysis_gain ()) { + /* In this case we know that the analysis was of a single piece of content and + we know that content's gain when the analysis was run. Hence we can work out + what correction is now needed to make it look `right'. + */ + shared_ptr<const AudioContent> ac = dynamic_pointer_cast<const AudioContent> (playlist->content().front ()); + DCPOMATIC_ASSERT (ac); + return ac->audio_gain() - analysis_gain().get (); + } + + return 0.0f; +} diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h index 5e71705bf..0d06e5973 100644 --- a/src/lib/audio_analysis.h +++ b/src/lib/audio_analysis.h @@ -31,6 +31,8 @@ namespace xmlpp { class Element; } +class Playlist; + class AudioAnalysis : public boost::noncopyable { public: @@ -65,6 +67,8 @@ public: void write (boost::filesystem::path); + float gain_correction (boost::shared_ptr<const Playlist> playlist); + private: std::vector<std::vector<AudioPoint> > _data; boost::optional<float> _peak; diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index 3748fa353..0597983db 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -146,8 +146,8 @@ JobManager::scheduler () } if (active_job != _last_active_job) { + emit (boost::bind (boost::ref (ActiveJobsChanged), _last_active_job, active_job)); _last_active_job = active_job; - emit (boost::bind (boost::ref (ActiveJobsChanged), active_job)); } dcpomatic_sleep (1); diff --git a/src/lib/job_manager.h b/src/lib/job_manager.h index 7de7862a1..560b5ca66 100644 --- a/src/lib/job_manager.h +++ b/src/lib/job_manager.h @@ -53,7 +53,7 @@ public: ); boost::signals2::signal<void (boost::weak_ptr<Job>)> JobAdded; - boost::signals2::signal<void (boost::optional<std::string>)> ActiveJobsChanged; + boost::signals2::signal<void (boost::optional<std::string>, boost::optional<std::string>)> ActiveJobsChanged; static JobManager* instance (); static void drop (); diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index d4108f89c..27b345406 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -150,7 +150,7 @@ AudioDialog::try_to_load_analysis () } _plot->set_analysis (_analysis); - _plot->set_gain_correction (gain_correction ()); + _plot->set_gain_correction (_analysis->gain_correction (_playlist)); setup_peak_time (); /* Set up some defaults if no check boxes are checked */ @@ -220,7 +220,7 @@ AudioDialog::content_changed (int p) /* We can use a short-cut to render the effect of this change, rather than recalculating everything. */ - _plot->set_gain_correction (gain_correction ()); + _plot->set_gain_correction (_analysis->gain_correction (_playlist)); setup_peak_time (); } else { try_to_load_analysis (); @@ -259,7 +259,7 @@ AudioDialog::setup_peak_time () return; } - float const peak_dB = 20 * log10 (_analysis->peak().get()) + gain_correction (); + float const peak_dB = 20 * log10 (_analysis->peak().get()) + _analysis->gain_correction (_playlist); _peak_time->SetLabel ( wxString::Format ( @@ -283,22 +283,3 @@ AudioDialog::Show (bool show) try_to_load_analysis (); return r; } - -/** @return gain correction in dB required to be added to raw gain values to render - * the dialog correctly. - */ -float -AudioDialog::gain_correction () -{ - if (_playlist->content().size() == 1 && _analysis->analysis_gain ()) { - /* In this case we know that the analysis was of a single piece of content and - we know that content's gain when the analysis was run. Hence we can work out - what correction is now needed to make it look `right'. - */ - shared_ptr<const AudioContent> ac = dynamic_pointer_cast<const AudioContent> (_playlist->content().front ()); - DCPOMATIC_ASSERT (ac); - return ac->audio_gain() - _analysis->analysis_gain().get (); - } - - return 0.0f; -} diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index 945ff013b..c99261150 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -42,7 +42,6 @@ private: void try_to_load_analysis (); void analysis_finished (); void setup_peak_time (); - float gain_correction (); boost::shared_ptr<AudioAnalysis> _analysis; boost::weak_ptr<Film> _film; diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index 4b6167bf7..adaf826f4 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -17,15 +17,16 @@ */ -#include "lib/config.h" -#include "lib/ffmpeg_content.h" -#include "lib/cinema_sound_processor.h" #include "audio_panel.h" #include "audio_mapping_view.h" #include "wx_util.h" #include "gain_calculator_dialog.h" #include "content_panel.h" #include "audio_dialog.h" +#include "lib/config.h" +#include "lib/ffmpeg_content.h" +#include "lib/cinema_sound_processor.h" +#include "lib/job_manager.h" #include <wx/spinctrl.h> #include <boost/lexical_cast.hpp> #include <boost/foreach.hpp> @@ -38,6 +39,7 @@ using std::pair; using boost::dynamic_pointer_cast; using boost::lexical_cast; using boost::shared_ptr; +using boost::optional; AudioPanel::AudioPanel (ContentPanel* p) : ContentSubPanel (p, _("Audio")) @@ -48,9 +50,15 @@ AudioPanel::AudioPanel (ContentPanel* p) int r = 0; - _show = new wxButton (this, wxID_ANY, _("Show graph of audio levels...")); - grid->Add (_show, wxGBPosition (r, 0), wxGBSpan (1, 2)); - ++r; + { + wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + _show = new wxButton (this, wxID_ANY, _("Show graph of audio levels...")); + s->Add (_show); + _peak = new wxStaticText (this, wxID_ANY, wxT ("")); + s->Add (_peak, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP); + grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2)); + ++r; + } add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0)); _gain = new ContentSpinCtrlDouble<AudioContent> ( @@ -102,6 +110,8 @@ AudioPanel::AudioPanel (ContentPanel* p) _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this)); _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1)); + + JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&AudioPanel::active_jobs_changed, this, _1)); } AudioPanel::~AudioPanel () @@ -119,6 +129,7 @@ AudioPanel::film_changed (Film::Property property) case Film::AUDIO_CHANNELS: case Film::AUDIO_PROCESSOR: _mapping->set_output_channels (_parent->film()->audio_output_names ()); + setup_peak (); break; case Film::VIDEO_FRAME_RATE: setup_description (); @@ -140,7 +151,10 @@ AudioPanel::film_content_changed (int property) _mapping->set (AudioMapping ()); } setup_description (); + setup_peak (); _sizer->Layout (); + } else if (property == AudioContentProperty::AUDIO_GAIN) { + setup_peak (); } } @@ -221,3 +235,47 @@ AudioPanel::show_clicked () _audio_dialog = new AudioDialog (this, _parent->film (), ac.front ()); _audio_dialog->Show (); } + +void +AudioPanel::setup_peak () +{ + AudioContentList 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->peak ()) { + float const peak_dB = 20 * log10 (analysis->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 (); + } +} diff --git a/src/wx/audio_panel.h b/src/wx/audio_panel.h index e4ccfaf3d..00b06442e 100644 --- a/src/wx/audio_panel.h +++ b/src/wx/audio_panel.h @@ -43,10 +43,13 @@ private: void gain_calculate_button_clicked (); void mapping_changed (AudioMapping); void setup_description (); + void setup_peak (); + void active_jobs_changed (boost::optional<std::string>); wxButton* _show; ContentSpinCtrlDouble<AudioContent>* _gain; wxButton* _gain_calculate_button; + wxStaticText* _peak; ContentSpinCtrl<AudioContent>* _delay; AudioMappingView* _mapping; wxStaticText* _description; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index b67c9612d..6d60772be 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -53,7 +53,7 @@ FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer) _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false); JobManager::instance()->ActiveJobsChanged.connect ( - bind (&FilmEditor::active_jobs_changed, this, _1) + bind (&FilmEditor::active_jobs_changed, this, _2) ); set_film (shared_ptr<Film> ()); diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index f00cdfe28..924172970 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -114,7 +114,7 @@ FilmViewer::FilmViewer (wxWindow* p) set_film (shared_ptr<Film> ()); JobManager::instance()->ActiveJobsChanged.connect ( - bind (&FilmViewer::active_jobs_changed, this, _1) + bind (&FilmViewer::active_jobs_changed, this, _2) ); setup_sensitivity (); |
