Post-export Analysis GUI
[ardour.git] / gtk2_ardour / export_report.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include "export_report.h"
20
21 #include <gtkmm/label.h>
22 #include <gtkmm/stock.h>
23
24 #include "canvas/utils.h"
25 #include "canvas/colors.h"
26
27 #include "i18n.h"
28
29 using namespace Gtk;
30 using namespace ARDOUR;
31
32 ExportReport::ExportReport (StatusPtr s)
33         : ArdourDialog (_("Export Report/Analysis"))
34         , status (s)
35 {
36
37         AnalysisResults & ar = status->result_map;
38         //size_t n_results = ar.size();
39
40         for (AnalysisResults::iterator i = ar.begin(); i != ar.end(); ++i) {
41                 Label *l;
42                 VBox *vb = manage (new VBox());
43                 vb->set_spacing (6);
44
45                 l = manage (new Label(string_compose (_("File: %1"), i->first)));
46                 vb->pack_start (*l);
47
48                 ExportAnalysisPtr p = i->second;
49                 if (i->second->have_loudness) {
50                         // TODO loudness histogram, HBox
51                         // TODO use cairo-widget and BIG numbers
52                         l = manage (new Label(string_compose (_("Loudness: %1 LUFS"), p->loudness)));
53                         vb->pack_start (*l);
54                         l = manage (new Label(string_compose (_("Loudness Range: %1 LU"), p->loudness_range)));
55                         vb->pack_start (*l);
56                 }
57
58                 {
59                         // TODO re-use Canvas::WaveView::draw_image() somehow.
60                         const size_t peaks = sizeof(p->_peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 2;
61                         const float height_2 = 150.0;
62                         Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, peaks, 2 * height_2);
63                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
64                         cr->rectangle (0, 0, peaks, 2 * height_2);
65                         cr->set_source_rgba (0, 0, 0, 1.0);
66                         cr->fill ();
67                         cr->set_source_rgba (.7, .7, .7, 1.0);
68                         cr->set_line_width (1.0);
69                         for (size_t x = 0 ; x < peaks; ++x) {
70                                 cr->move_to (x - .5, height_2 - height_2 * p->_peaks[x].max);
71                                 cr->line_to (x - .5, height_2 - height_2 * p->_peaks[x].min);
72                         }
73                         cr->stroke ();
74                         wave->flush ();
75
76                         CimgArea *wv = manage (new CimgArea (wave));
77                         vb->pack_start (*wv);
78                 }
79
80                 {
81                         // TODO: get geometry from ExportAnalysis
82                         const size_t width = 800;
83                         const size_t height = 256;
84                         Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, width, height);
85                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
86                         cr->rectangle (0, 0, width, height);
87                         cr->set_source_rgba (0, 0, 0, 1.0);
88                         cr->fill ();
89                         for (size_t x = 0 ; x < width; ++x) {
90                                 for (size_t y = 0 ; y < height; ++y) {
91                                         const float pk = p->_spectrum[x][y];
92                                         ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
93                                         ArdourCanvas::set_source_rgba (cr, c);
94                                         cr->rectangle (x - .5, y - .5, 1, 1);
95                                         cr->fill ();
96                                 }
97                         }
98                         spec->flush ();
99                         CimgArea *sp = manage (new CimgArea (spec));
100                         vb->pack_start (*sp);
101                 }
102
103                 // TODO ellipsize tab-text
104                 pages.pages().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
105         }
106
107         pages.set_show_tabs (true);
108         pages.show_all ();
109         pages.set_name ("ExportReportNotebook");
110         pages.set_current_page (0);
111
112         get_vbox()->set_spacing (12);
113         get_vbox()->pack_start (pages);
114
115         add_button (Stock::CLOSE, RESPONSE_ACCEPT);
116         set_default_response (RESPONSE_ACCEPT);
117         show_all ();
118         //pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::handle_page_change));
119 }
120
121 int
122 ExportReport::run ()
123 {
124         return ArdourDialog::run ();
125 }