allow to re-use export-report UI
authorRobin Gareus <robin@gareus.org>
Fri, 11 Mar 2016 16:25:52 +0000 (17:25 +0100)
committerRobin Gareus <robin@gareus.org>
Fri, 11 Mar 2016 16:26:42 +0000 (17:26 +0100)
(we should probably change the name to LoudnessReport)

gtk2_ardour/export_report.cc
gtk2_ardour/export_report.h

index c03a8bb2cde857a0ffa09b3cd4af0bcf3dcb1211..8d3b78c2ef42793e9499a3fe74453079fd922210 100644 (file)
@@ -53,22 +53,38 @@ using namespace ARDOUR;
 
 ExportReport::ExportReport (Session* session, StatusPtr s)
        : ArdourDialog (_("Export Report/Analysis"))
-       , status (s)
        , _session (session)
+       , stop_btn (0)
+       , play_btn (0)
        , _audition_num (-1)
        , _page_num (0)
+{
+       init (s->result_map, true);
+}
+
+ExportReport::ExportReport (const std::string & title, const AnalysisResults & ar)
+       : ArdourDialog (title)
+       , _session (0)
+       , stop_btn (0)
+       , play_btn (0)
+       , _audition_num (-1)
+       , _page_num (0)
+{
+       init (ar, false);
+}
+
+void
+ExportReport::init (const AnalysisResults & ar, bool with_file)
 {
        set_resizable (false);
        pages.set_scrollable ();
 
-       AnalysisResults & ar = status->result_map;
-
        std::vector<double> dashes;
        dashes.push_back (3.0);
        dashes.push_back (5.0);
 
        int page = 0;
-       for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
+       for (AnalysisResults::const_iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
                Label *l;
                VBox *vb = manage (new VBox ());
                Table *t = manage (new Table (4, 4));
@@ -87,19 +103,21 @@ ExportReport::ExportReport (Session* session, StatusPtr s)
 
                std::list<CimgPlayheadArea*> playhead_widgets;
 
-               l = manage (new Label (_("File:"), ALIGN_END));
-               t->attach (*l, 0, 1, 0, 1);
-               l = manage (new Label ());
-               l->set_ellipsize (Pango::ELLIPSIZE_START);
-               l->set_width_chars (48);
-               l->set_max_width_chars (48);
-               l->set_text (path);
-               l->set_alignment (ALIGN_START, ALIGN_CENTER);
-               t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
+               if (with_file) {
+                       l = manage (new Label (_("File:"), ALIGN_END));
+                       t->attach (*l, 0, 1, 0, 1);
+                       l = manage (new Label ());
+                       l->set_ellipsize (Pango::ELLIPSIZE_START);
+                       l->set_width_chars (48);
+                       l->set_max_width_chars (48);
+                       l->set_text (path);
+                       l->set_alignment (ALIGN_START, ALIGN_CENTER);
+                       t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
 
-               Button *b = manage (new Button (_("Open Folder")));
-               t->attach (*b, 3, 4, 0, 2, FILL, SHRINK);
-               b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
+                       Button *b = manage (new Button (_("Open Folder")));
+                       t->attach (*b, 3, 4, 0, 2, FILL, SHRINK);
+                       b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
+               }
 
                SoundFileInfo info;
                std::string errmsg;
@@ -109,7 +127,7 @@ ExportReport::ExportReport (Session* session, StatusPtr s)
                framecnt_t start_off = 0;
                unsigned int channels = 0;
 
-               if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
+               if (with_file && AudioFileSource::get_soundfile_info (path, info, errmsg)) {
                        AudioClock * clock;
 
                        file_length = info.length;
@@ -161,7 +179,7 @@ ExportReport::ExportReport (Session* session, StatusPtr s)
                        clock->set_mode (AudioClock::Timecode);
                        clock->set (info.timecode * src_coef + 0.5, true);
                        t->attach (*clock, 3, 4, 3, 4);
-               } else {
+               } else if (with_file) {
                        l = manage (new Label (_("Error:"), ALIGN_END));
                        t->attach (*l, 0, 1, 1, 2);
                        l = manage (new Label (errmsg, ALIGN_START));
@@ -721,14 +739,18 @@ ExportReport::ExportReport (Session* session, StatusPtr s)
                _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
        }
 
-       play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
-       stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
+       if (_session && with_file) {
+               play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
+               stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
+       }
        add_button (Stock::CLOSE, RESPONSE_CLOSE);
 
        set_default_response (RESPONSE_CLOSE);
-       stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
-       play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
-       stop_btn->set_sensitive (false);
+       if (_session && with_file) {
+               stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
+               play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
+               stop_btn->set_sensitive (false);
+       }
        show_all ();
 }
 
@@ -757,6 +779,9 @@ ExportReport::open_folder (std::string p)
 void
 ExportReport::audition_active (bool active)
 {
+       if (!stop_btn || !play_btn) {
+               return;
+       }
        stop_btn->set_sensitive (active);
        play_btn->set_sensitive (!active);
 
index 019b2f71c392f15e87e455a14b01a1c897fd9ad3..65339be701d32a37c449553f650afedb879a6cea 100644 (file)
@@ -186,9 +186,11 @@ class ExportReport : public ArdourDialog
 public:
        typedef boost::shared_ptr<ARDOUR::ExportStatus> StatusPtr;
        ExportReport (ARDOUR::Session*, StatusPtr);
+       ExportReport (const std::string & title, const ARDOUR::AnalysisResults & ar);
        int run ();
 
 private:
+       void init (const ARDOUR::AnalysisResults &, bool);
        void draw_waveform (Cairo::RefPtr<Cairo::ImageSurface>& wave,
                        ARDOUR::ExportAnalysisPtr, uint32_t, int, size_t, int, int, bool, bool);
 
@@ -203,7 +205,6 @@ private:
        void on_logscale_toggled (Gtk::ToggleButton*);
        void on_rectivied_toggled (Gtk::ToggleButton*);
 
-       StatusPtr        status;
        Gtk::Notebook    pages;
        ARDOUR::Session* _session;
        Gtk::Button*     stop_btn;