add region & range loudnless report
authorRobin Gareus <robin@gareus.org>
Fri, 11 Mar 2016 16:26:27 +0000 (17:26 +0100)
committerRobin Gareus <robin@gareus.org>
Fri, 11 Mar 2016 16:26:42 +0000 (17:26 +0100)
gtk2_ardour/ardour.menus.in
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_selection.cc
gtk2_ardour/simple_progress_dialog.h [new file with mode: 0644]

index 5ada15a157b1f3e713947caee0f560db198822f4..e8fc335dde98b573161b7418ccf1809c60ad2d61 100644 (file)
       <menuitem action='loop-region'/>
       <menuitem action='rename-region'/>
       <menuitem action='show-region-properties'/>
-      <menuitem action='analyze-region'/>
+      <menuitem action='loudness-analyze-region'/>
+      <menuitem action='spectal-analyze-region'/>
       <menu action='RegionMenuEdit'>
          <menuitem action='combine-regions'/>
          <menuitem action='uncombine-regions'/>
     <menuitem action='export-region'/>
     <menuitem action='bounce-regions-processed'/>
     <menuitem action='bounce-regions-unprocessed'/>
-    <menuitem action='analyze-region'/>
+    <menuitem action='loudness-analyze-region'/>
+    <menuitem action='spectral-analyze-region'/>
     <separator/>
     <menuitem action='remove-region'/>
     
index 0afc797dc1e7df317a313359e516bb0d0959ad2b..a118d1d6420b334f89e3525865c875040b219b2b 100644 (file)
@@ -65,6 +65,7 @@
 #include "gtkmm2ext/choice.h"
 #include "gtkmm2ext/cell_renderer_pixbuf_toggle.h"
 
+#include "ardour/analysis_graph.h"
 #include "ardour/audio_track.h"
 #include "ardour/audioengine.h"
 #include "ardour/audioregion.h"
 #include "editor_routes.h"
 #include "editor_snapshots.h"
 #include "editor_summary.h"
+#include "export_report.h"
 #include "global_port_matrix.h"
 #include "gui_object.h"
 #include "gui_thread.h"
 #include "rgb_macros.h"
 #include "rhythm_ferret.h"
 #include "selection.h"
+#include "simple_progress_dialog.h"
 #include "sfdb_ui.h"
 #include "tempo_lines.h"
 #include "time_axis_view.h"
@@ -1714,7 +1717,103 @@ Editor::build_track_region_context_menu ()
 }
 
 void
-Editor::analyze_region_selection ()
+Editor::loudness_analyze_region_selection ()
+{
+       if (!_session) {
+               return;
+       }
+       Selection& s (PublicEditor::instance ().get_selection ());
+       RegionSelection ars = s.regions;
+       ARDOUR::AnalysisGraph ag (_session);
+       framecnt_t total_work = 0;
+
+       for (RegionSelection::iterator j = ars.begin (); j != ars.end (); ++j) {
+               AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*j);
+               if (!arv) {
+                       continue;
+               }
+               if (!boost::dynamic_pointer_cast<AudioRegion> (arv->region ())) {
+                       continue;
+               }
+               assert (dynamic_cast<RouteTimeAxisView *> (&arv->get_time_axis_view ()));
+               total_work += arv->region ()->length ();
+       }
+
+       SimpleProgressDialog spd (_("Region Loudness Analysis"), sigc::mem_fun (ag, &AnalysisGraph::cancel));
+       ScopedConnection c;
+       ag.set_total_frames (total_work);
+       ag.Progress.connect_same_thread (c, boost::bind (&SimpleProgressDialog::update_progress, &spd, _1, _2));
+       spd.show();
+
+       for (RegionSelection::iterator j = ars.begin (); j != ars.end (); ++j) {
+               AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*j);
+               if (!arv) {
+                       continue;
+               }
+               boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (arv->region ());
+               if (!ar) {
+                       continue;
+               }
+               ag.analyze_region (ar);
+       }
+       spd.hide();
+       if (!ag.canceled ()) {
+               ExportReport er (_("Audio Report/Analysis"), ag.results ());
+               er.run();
+       }
+}
+
+void
+Editor::loudness_analyze_range_selection ()
+{
+       if (!_session) {
+               return;
+       }
+       Selection& s (PublicEditor::instance ().get_selection ());
+       TimeSelection ts = s.time;
+       ARDOUR::AnalysisGraph ag (_session);
+       framecnt_t total_work = 0;
+
+       for (TrackSelection::iterator i = s.tracks.begin (); i != s.tracks.end (); ++i) {
+               boost::shared_ptr<AudioPlaylist> pl = boost::dynamic_pointer_cast<AudioPlaylist> ((*i)->playlist ());
+               if (!pl) {
+                       continue;
+               }
+               RouteUI *rui = dynamic_cast<RouteUI *> (*i);
+               if (!pl || !rui) {
+                       continue;
+               }
+               for (std::list<AudioRange>::iterator j = ts.begin (); j != ts.end (); ++j) {
+                       total_work += j->length ();
+               }
+       }
+
+       SimpleProgressDialog spd (_("Range Loudness Analysis"), sigc::mem_fun (ag, &AnalysisGraph::cancel));
+       ScopedConnection c;
+       ag.set_total_frames (total_work);
+       ag.Progress.connect_same_thread (c, boost::bind (&SimpleProgressDialog::update_progress, &spd, _1, _2));
+       spd.show();
+
+       for (TrackSelection::iterator i = s.tracks.begin (); i != s.tracks.end (); ++i) {
+               boost::shared_ptr<AudioPlaylist> pl = boost::dynamic_pointer_cast<AudioPlaylist> ((*i)->playlist ());
+               if (!pl) {
+                       continue;
+               }
+               RouteUI *rui = dynamic_cast<RouteUI *> (*i);
+               if (!pl || !rui) {
+                       continue;
+               }
+               ag.analyze_range (rui->route (), pl, ts);
+       }
+       spd.hide();
+       if (!ag.canceled ()) {
+               ExportReport er (_("Audio Report/Analysis"), ag.results ());
+               er.run();
+       }
+}
+
+void
+Editor::spectral_analyze_region_selection ()
 {
        if (analysis_window == 0) {
                analysis_window = new AnalysisWindow();
@@ -1732,7 +1831,7 @@ Editor::analyze_region_selection ()
 }
 
 void
-Editor::analyze_range_selection()
+Editor::spectral_analyze_range_selection()
 {
        if (analysis_window == 0) {
                analysis_window = new AnalysisWindow();
@@ -1826,7 +1925,8 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Zoom to Range"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), false)));
 
        edit_items.push_back (SeparatorElem());
-       edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
+       edit_items.push_back (MenuElem (_("Loudness Analysis"), sigc::mem_fun(*this, &Editor::loudness_analyze_range_selection)));
+       edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::spectral_analyze_range_selection)));
 
        edit_items.push_back (SeparatorElem());
 
index d0d84b1a6e1381fdff8eca12e3ba3e2b37d382b8..1d11dd282dff0f5c8d75e52b987e2327b025f601 100644 (file)
@@ -274,8 +274,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* analysis window */
 
-       void analyze_region_selection();
-       void analyze_range_selection();
+       void loudness_analyze_region_selection();
+       void loudness_analyze_range_selection();
+
+       void spectral_analyze_region_selection();
+       void spectral_analyze_range_selection();
 
        /* export */
 
index 046d9b94e111e1a825f9ac1d1dea024946039075..008a4d75dcd17d85113c9896fe2f2f05b92bde1b 100644 (file)
@@ -1924,7 +1924,8 @@ Editor::register_region_actions ()
        reg_sens (_region_actions, "combine-regions", _("Combine"), sigc::mem_fun (*this, &Editor::combine_regions));
        reg_sens (_region_actions, "uncombine-regions", _("Uncombine"), sigc::mem_fun (*this, &Editor::uncombine_regions));
 
-       reg_sens (_region_actions, "analyze-region", _("Spectral Analysis..."), sigc::mem_fun (*this, &Editor::analyze_region_selection));
+       reg_sens (_region_actions, "loudness-analyze-region", _("Loudness Analysis..."), sigc::mem_fun (*this, &Editor::loudness_analyze_region_selection));
+       reg_sens (_region_actions, "spectral-analyze-region", _("Spectral Analysis..."), sigc::mem_fun (*this, &Editor::spectral_analyze_region_selection));
 
        reg_sens (_region_actions, "reset-region-gain-envelopes", _("Reset Envelope"), sigc::mem_fun (*this, &Editor::reset_region_gain_envelopes));
 
index 41198ec93882df3e95effda31a2557ef4415898b..4386b228776808919a8e83a975efea1d48aeb3df 100644 (file)
@@ -1258,7 +1258,8 @@ Editor::sensitize_the_right_region_actions ()
 
        } else {
 
-               _region_actions->get_action("analyze-region")->set_sensitive (false);
+               _region_actions->get_action("loudness-analyze-region")->set_sensitive (false);
+               _region_actions->get_action("spectral-analyze-region")->set_sensitive (false);
                _region_actions->get_action("reset-region-gain-envelopes")->set_sensitive (false);
                _region_actions->get_action("toggle-region-gain-envelope-active")->set_sensitive (false);
                _region_actions->get_action("pitch-shift-region")->set_sensitive (false);
diff --git a/gtk2_ardour/simple_progress_dialog.h b/gtk2_ardour/simple_progress_dialog.h
new file mode 100644 (file)
index 0000000..1e76f6b
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef _ardour_gtk_simpple_progress_dialog_h_
+#define _ardour_gtk_simpple_progress_dialog_h_
+
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/button.h>
+#include <gtkmm/progressbar.h>
+
+#include "ardour/types.h"
+
+class SimpleProgressDialog : public Gtk::MessageDialog
+{
+public:
+       SimpleProgressDialog (std::string title, const Glib::SignalProxy0< void >::SlotType & cancel)
+               : MessageDialog (title, false, MESSAGE_OTHER, BUTTONS_NONE, true)
+       {
+               get_vbox()->set_size_request(400,-1);
+               set_title (title);
+               pbar = manage (new Gtk::ProgressBar());
+               pbar->show();
+               get_vbox()->pack_start (*pbar, PACK_SHRINK, 4);
+
+               Gtk::Button *cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+               cancel_button->signal_clicked().connect (cancel);
+               cancel_button->show();
+               get_vbox()->pack_start (*cancel_button, PACK_SHRINK);
+       }
+
+       void update_progress (framecnt_t c, framecnt_t t) {
+               pbar->set_fraction ((float) c / (float) t);
+               // see also ARDOUR_UI::gui_idle_handler();
+               int timeout = 30;
+               while (gtk_events_pending() && --timeout) {
+                       gtk_main_iteration ();
+               }
+       }
+private:
+       Gtk::ProgressBar *pbar;
+};
+#endif