Re-add show audio button and analyse just that content when it is clicked.
authorCarl Hetherington <cth@carlh.net>
Wed, 1 Jul 2015 17:04:14 +0000 (18:04 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 1 Jul 2015 17:04:14 +0000 (18:04 +0100)
src/lib/analyse_audio_job.cc
src/lib/film.cc
src/lib/film.h
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_panel.cc
src/wx/audio_panel.h

index 2146b03..1cec15c 100644 (file)
@@ -89,7 +89,7 @@ AnalyseAudioJob::run ()
        }
 
        _analysis->set_peak (_overall_peak, DCPTime::from_frames (_overall_peak_frame, _film->audio_frame_rate ()));
-       _analysis->write (_film->audio_analysis_path ());
+       _analysis->write (_film->audio_analysis_path (_playlist));
 
        set_progress (1);
        set_state (FINISHED_OK);
index dbb7330..5310ef7 100644 (file)
@@ -228,12 +228,12 @@ Film::internal_video_asset_filename () const
 }
 
 boost::filesystem::path
-Film::audio_analysis_path () const
+Film::audio_analysis_path (shared_ptr<const Playlist> playlist) const
 {
        boost::filesystem::path p = dir ("analysis");
 
        MD5Digester digester;
-       BOOST_FOREACH (shared_ptr<Content> i, content ()) {
+       BOOST_FOREACH (shared_ptr<Content> i, playlist->content ()) {
                shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (i);
                if (!ac) {
                        continue;
index 23478c4..f1df571 100644 (file)
@@ -69,7 +69,7 @@ public:
        boost::filesystem::path internal_video_asset_dir () const;
        boost::filesystem::path internal_video_asset_filename () const;
 
-       boost::filesystem::path audio_analysis_path () const;
+       boost::filesystem::path audio_analysis_path (boost::shared_ptr<const Playlist>) const;
 
        void send_dcp_to_tms ();
        void make_dcp ();
index 70046f5..cd59693 100644 (file)
 using boost::shared_ptr;
 using boost::bind;
 using boost::optional;
+using boost::const_pointer_cast;
 
-AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film)
+/** @param content Content to analyse, or 0 to analyse all of the film's audio */
+AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<AudioContent> content)
        : wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
        , _film (film)
        , _plot (0)
@@ -109,6 +111,13 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film)
 
        _film_connection = film->ContentChanged.connect (boost::bind (&AudioDialog::try_to_load_analysis, this));
        SetTitle (_("DCP-o-matic audio"));
+
+       if (content) {
+               _playlist.reset (new Playlist ());
+               const_pointer_cast<Playlist> (_playlist)->add (content);
+       } else {
+               _playlist = film->playlist ();
+       }
 }
 
 void
@@ -121,12 +130,12 @@ AudioDialog::try_to_load_analysis ()
        shared_ptr<const Film> film = _film.lock ();
        DCPOMATIC_ASSERT (film);
 
-       boost::filesystem::path path = film->audio_analysis_path ();
+       boost::filesystem::path path = film->audio_analysis_path (_playlist);
 
        if (!boost::filesystem::exists (path)) {
                _plot->set_analysis (shared_ptr<AudioAnalysis> ());
                _analysis.reset ();
-               shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, film->playlist ()));
+               shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, _playlist));
                _analysis_finished_connection = job->Finished.connect (bind (&AudioDialog::analysis_finished, this));
                JobManager::instance()->add (job);
                return;
@@ -136,7 +145,7 @@ AudioDialog::try_to_load_analysis ()
                _analysis.reset (new AudioAnalysis (path));
        } catch (xmlpp::exception& e) {
                /* Probably an old-style analysis file: recreate it */
-               shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, film->playlist ()));
+               shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, _playlist));
                _analysis_finished_connection = job->Finished.connect (bind (&AudioDialog::analysis_finished, this));
                JobManager::instance()->add (job);
                return;
@@ -178,7 +187,7 @@ AudioDialog::analysis_finished ()
        shared_ptr<const Film> film = _film.lock ();
        DCPOMATIC_ASSERT (film);
 
-       if (!boost::filesystem::exists (film->audio_analysis_path ())) {
+       if (!boost::filesystem::exists (film->audio_analysis_path (_playlist))) {
                /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
                   Give up.
                */
index d35cca1..c992611 100644 (file)
 
 */
 
-#include <boost/shared_ptr.hpp>
-#include <boost/signals2.hpp>
-#include <wx/wx.h>
 #include "lib/film.h"
 #include "lib/audio_analysis.h"
+#include "lib/playlist.h"
+#include <wx/wx.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/signals2.hpp>
 
 class AudioPlot;
 class Film;
@@ -29,7 +30,7 @@ class Film;
 class AudioDialog : public wxDialog
 {
 public:
-       AudioDialog (wxWindow *, boost::shared_ptr<Film> film);
+       AudioDialog (wxWindow *, boost::shared_ptr<Film> film, boost::shared_ptr<AudioContent> content = boost::shared_ptr<AudioContent> ());
 
        bool Show (bool show = true);
 
@@ -44,6 +45,7 @@ private:
 
        boost::shared_ptr<AudioAnalysis> _analysis;
        boost::weak_ptr<Film> _film;
+       boost::shared_ptr<const Playlist> _playlist;
        AudioPlot* _plot;
        wxStaticText* _peak_time;
        wxCheckBox* _channel_checkbox[MAX_DCP_AUDIO_CHANNELS];
index c31d5b5..46d7a22 100644 (file)
@@ -25,6 +25,7 @@
 #include "wx_util.h"
 #include "gain_calculator_dialog.h"
 #include "content_panel.h"
+#include "audio_dialog.h"
 #include <wx/spinctrl.h>
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
@@ -40,12 +41,17 @@ using boost::shared_ptr;
 
 AudioPanel::AudioPanel (ContentPanel* p)
        : ContentSubPanel (p, _("Audio"))
+       , _audio_dialog (0)
 {
        wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
        _sizer->Add (grid, 0, wxALL, 8);
 
        int r = 0;
 
+       _show = new wxButton (this, wxID_ANY, _("Show Audio..."));
+       grid->Add (_show, wxGBPosition (r, 0));
+       ++r;
+
        add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
        _gain = new ContentSpinCtrlDouble<AudioContent> (
                this,
@@ -92,11 +98,19 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _gain->wrapped()->SetIncrement (0.5);
        _delay->wrapped()->SetRange (-1000, 1000);
 
-       _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,  boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
+       _show->Bind                  (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::show_clicked, this));
+       _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));
 }
 
+AudioPanel::~AudioPanel ()
+{
+       if (_audio_dialog) {
+               _audio_dialog->Destroy ();
+               _audio_dialog = 0;
+       }
+}
 
 void
 AudioPanel::film_changed (Film::Property property)
@@ -190,3 +204,20 @@ AudioPanel::content_selection_changed ()
 
        film_content_changed (AudioContentProperty::AUDIO_STREAMS);
 }
+
+void
+AudioPanel::show_clicked ()
+{
+       if (_audio_dialog) {
+               _audio_dialog->Destroy ();
+               _audio_dialog = 0;
+       }
+
+       AudioContentList ac = _parent->selected_audio ();
+       if (ac.size() != 1) {
+               return;
+       }
+
+       _audio_dialog = new AudioDialog (this, _parent->film (), ac.front ());
+       _audio_dialog->Show ();
+}
index 2856cec..e4ccfaf 100644 (file)
@@ -26,26 +26,31 @@ class wxButton;
 class wxChoice;
 class wxStaticText;
 class AudioMappingView;
+class AudioDialog;
 
 class AudioPanel : public ContentSubPanel
 {
 public:
        AudioPanel (ContentPanel *);
+       ~AudioPanel ();
 
        void film_changed (Film::Property);
        void film_content_changed (int);
        void content_selection_changed ();
 
 private:
+       void show_clicked ();
        void gain_calculate_button_clicked ();
        void mapping_changed (AudioMapping);
        void setup_description ();
 
+       wxButton* _show;
        ContentSpinCtrlDouble<AudioContent>* _gain;
        wxButton* _gain_calculate_button;
        ContentSpinCtrl<AudioContent>* _delay;
        AudioMappingView* _mapping;
        wxStaticText* _description;
+       AudioDialog* _audio_dialog;
 
        boost::signals2::scoped_connection _mapping_connection;
 };