e4aac1e0fbd610af6d4ef76eb9957fbb1f0af36b
[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 <algorithm>
20
21 #include <pangomm/layout.h>
22 #include <gtkmm/label.h>
23 #include <gtkmm/table.h>
24 #include <gtkmm/stock.h>
25
26 #include "gtkmm2ext/utils.h"
27 #include "canvas/utils.h"
28 #include "canvas/colors.h"
29
30 #include "ardour/audiofilesource.h"
31 #include "ardour/session.h"
32 #include "ardour/ardour/dB.h"
33
34 #include "audio_clock.h"
35 #include "ui_config.h"
36 #include "export_report.h"
37
38 #include "i18n.h"
39
40 using namespace Gtk;
41 using namespace ARDOUR;
42
43 ExportReport::ExportReport (Session* _session, StatusPtr s)
44         : ArdourDialog (_("Export Report/Analysis"))
45         , status (s)
46 {
47         set_resizable (false);
48         pages.set_scrollable ();
49
50         AnalysisResults & ar = status->result_map;
51
52         std::vector<double> dashes;
53         dashes.push_back (3.0);
54         dashes.push_back (5.0);
55
56         for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i) {
57                 Label *l;
58                 VBox *vb = manage (new VBox ());
59                 Table *t = manage (new Table (4, 4));
60                 t->set_spacings (4);
61                 vb->set_spacing (4);
62                 vb->pack_start (*t, false, false, 2);
63
64                 std::string path = i->first;
65                 ExportAnalysisPtr p = i->second;
66
67                 l = manage (new Label (_("File:"), ALIGN_END));
68                 t->attach (*l, 0, 1, 0, 1);
69                 l = manage (new Label ());
70                 l->set_ellipsize (Pango::ELLIPSIZE_START);
71                 l->set_width_chars (64);
72                 l->set_max_width_chars (64);
73                 l->set_text (path);
74                 l->set_alignment (ALIGN_START, ALIGN_CENTER);
75                 t->attach (*l, 1, 4, 0, 1, FILL, SHRINK);
76
77                 SoundFileInfo info;
78                 std::string errmsg;
79
80                 framecnt_t file_length = 0;
81                 framecnt_t sample_rate = 0;
82                 framecnt_t start_off = 0;
83
84                 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
85                         AudioClock * clock;
86
87                         file_length = info.length;
88                         sample_rate = info.samplerate;
89                         start_off = info.timecode;
90
91                         /* File Info Table */
92
93                         framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
94                         double src_coef = (double) nfr / info.samplerate;
95
96                         l = manage (new Label (_("Format:"), ALIGN_END));
97                         t->attach (*l, 0, 1, 1, 2);
98                         std::string fmt = info.format_name;
99                         std::replace (fmt.begin (), fmt.end (), '\n', ' ');
100                         l = manage (new Label ());
101                         l->set_ellipsize (Pango::ELLIPSIZE_START);
102                         l->set_width_chars (64);
103                         l->set_max_width_chars (64);
104                         l->set_text (fmt);
105                         l->set_alignment (ALIGN_START, ALIGN_CENTER);
106                         t->attach (*l, 1, 4, 1, 2, FILL, SHRINK);
107
108                         l = manage (new Label (_("Channels:"), ALIGN_END));
109                         t->attach (*l, 0, 1, 2, 3);
110                         l = manage (new Label (string_compose ("%1", info.channels)));
111                         t->attach (*l, 1, 2, 2, 3);
112
113                         l = manage (new Label (_("Sample rate:"), ALIGN_END));
114                         t->attach (*l, 2, 3, 2, 3);
115                         l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate)));
116                         t->attach (*l, 3, 4, 2, 3);
117
118                         l = manage (new Label (_("Duration:"), ALIGN_END));
119                         t->attach (*l, 0, 1, 3, 4);
120                         clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
121                         clock->set_session (_session);
122                         clock->set_mode (AudioClock::MinSec);
123                         clock->set (info.length * src_coef + 0.5, true);
124                         t->attach (*clock, 1, 2, 3, 4);
125
126                         l = manage (new Label (_("Timecode:"), ALIGN_END));
127                         t->attach (*l, 2, 3, 3, 4);
128                         clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
129                         clock->set_session (_session);
130                         clock->set_mode (AudioClock::Timecode);
131                         clock->set (info.timecode * src_coef + 0.5, true);
132                         t->attach (*clock, 3, 4, 3, 4);
133                 } else {
134                         l = manage (new Label (_("Error:"), ALIGN_END));
135                         t->attach (*l, 0, 1, 1, 2);
136                         l = manage (new Label (errmsg, ALIGN_START));
137                         t->attach (*l, 1, 4, 1, 2);
138                 }
139
140                 int w, h;
141                 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
142
143                 // calc geometry of numerics
144                 const float dbfs = accurate_coefficient_to_dB (p->peak);
145                 const float dbtp = accurate_coefficient_to_dB (p->truepeak);
146
147 #define TXTSIZE(LINE, TXT, FONT) {                                     \
148   layout->set_font_description (UIConfiguration::instance ().FONT ()); \
149   layout->set_text (TXT);                                              \
150   layout->get_pixel_size (w, h);                                       \
151   if (w > mnw) { mnw = w; }                                            \
152   if (h > lin[LINE]) { lin[LINE] = h; }                                \
153 }
154
155 #define TXTWIDTH(TXT, FONT) {                                          \
156   layout->set_font_description (UIConfiguration::instance ().FONT ()); \
157   layout->set_text (TXT);                                              \
158   layout->get_pixel_size (w, h);                                       \
159   if (w > mml) { mml = w; }                                            \
160 }
161
162                 int mnw = 0; // max numeric width
163                 int lin[4] = { 0, 0, 0, 0 }; // max line height
164
165                 TXTSIZE(0, _("Peak:"), get_SmallFont);
166                 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
167                 TXTSIZE(2, _("True Peak:"), get_SmallFont);
168                 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
169
170                 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
171                 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
172                 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
173                 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
174
175                 mnw += 8;
176                 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] + 8;
177                 const int hh = std::max (100, ht);
178                 int m_l =  2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800; // margin left
179
180                 int mml = 0; // min margin left -- ensure left margin is wide enough
181                 TXTWIDTH (_("Time"), get_SmallFont);
182                 TXTWIDTH (_("100"), get_SmallMonospaceFont);
183                 m_l = (std::max (m_l, mml + 8) + 3) & ~3;
184
185                 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800) / 2;
186                 const int nw2 = mnw / 2; // nums, horizontal center
187
188                 int y0[4];
189                 y0[0] = (hh - ht) * .5 + lin[0] * .25;
190                 y0[1] = y0[0] + lin[0] * 1.25;
191                 y0[2] = y0[1] + lin[1] * 1.25;
192                 y0[3] = y0[2] + lin[2] * 1.25;
193
194
195                 { /* peak, loudness and R128 histogram */
196                         Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
197                         Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
198                         Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
199
200                         /* peak and true-peak numerics */
201                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
202                         cr->set_source_rgba (0, 0, 0, 1.0);
203                         cr->paint ();
204
205                         layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
206                         layout->set_alignment (Pango::ALIGN_LEFT);
207                         layout->set_text (_("Peak:"));
208                         layout->get_pixel_size (w, h);
209                         cr->move_to (rint (nw2 - w * .5), y0[0]);
210                         cr->set_source_rgba (.7, .7, .7, 1.0);
211                         layout->show_in_cairo_context (cr);
212
213                         layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
214                         layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed,
215                                                 accurate_coefficient_to_dB (p->peak)));
216                         layout->get_pixel_size (w, h);
217                         cr->move_to (rint (nw2 - w * .5), y0[1]);
218                         if (p->peak > .944) { cr->set_source_rgba (1.0, .5, .5, 1.0); }
219                         layout->show_in_cairo_context (cr);
220
221                         if (p->have_dbtp) {
222                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
223                                 layout->set_text (_("True Peak:"));
224                                 layout->get_pixel_size (w, h);
225                                 cr->move_to (rint (nw2 - w * .5), y0[2]);
226                                 cr->set_source_rgba (.7, .7, .7, 1.0);
227                                 layout->show_in_cairo_context (cr);
228
229                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
230                                 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed,
231                                                 accurate_coefficient_to_dB (p->truepeak)));
232                                 layout->get_pixel_size (w, h);
233                                 cr->move_to (rint (nw2 - w * .5), y0[3]);
234                                 if (p->truepeak > .944) { cr->set_source_rgba (1.0, .5, .5, 1.0); }
235                                 layout->show_in_cairo_context (cr);
236                         }
237
238                         nums->flush ();
239
240                         /* EBU R128 numerics */
241                         cr = Cairo::Context::create (ebur);
242                         cr->set_source_rgba (0, 0, 0, 1.0);
243                         cr->paint ();
244
245                         cr->set_source_rgba (.7, .7, .7, 1.0);
246
247                         if (!i->second->have_loudness) {
248                                 layout->set_alignment (Pango::ALIGN_CENTER);
249                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
250                                 layout->set_text (_("not\navailable"));
251                                 layout->get_pixel_size (w, h);
252                                 cr->move_to (rint (nw2 - w * .5), rint (hh - h * .5));
253                                 layout->show_in_cairo_context (cr);
254                         }
255                         else if (p->loudness == -200 && p->loudness_range == 0) {
256                                 layout->set_alignment (Pango::ALIGN_CENTER);
257                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
258                                 layout->set_text (_("not\navailable"));
259                                 layout->get_pixel_size (w, h);
260                                 cr->move_to (rint (nw2 - w * .5), rint (hh - h * .6));
261                                 layout->show_in_cairo_context (cr);
262                                 int yy = h * .5;
263
264                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
265                                 layout->set_text (_("(too short integration time)"));
266                                 layout->get_pixel_size (w, h);
267                                 cr->move_to (rint (nw2 - w * .5), rint (hh + yy));
268                                 layout->show_in_cairo_context (cr);
269
270                         } else {
271                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
272                                 layout->set_alignment (Pango::ALIGN_LEFT);
273                                 layout->set_text (_("Integrated Loudness:"));
274                                 layout->get_pixel_size (w, h);
275                                 cr->move_to (rint (nw2 - w * .5), y0[0]);
276                                 layout->show_in_cairo_context (cr);
277
278                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
279                                 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed,  p->loudness));
280                                 layout->get_pixel_size (w, h);
281                                 cr->move_to (rint (nw2 - w * .5), y0[1]);
282                                 layout->show_in_cairo_context (cr);
283
284                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
285                                 layout->set_text (_("Loudness Range:"));
286                                 layout->get_pixel_size (w, h);
287                                 cr->move_to (rint (nw2 - w * .5), y0[2]);
288                                 layout->show_in_cairo_context (cr);
289
290                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
291                                 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
292                                 layout->get_pixel_size (w, h);
293                                 cr->move_to (rint (nw2 - w * .5), y0[3]);
294                                 layout->show_in_cairo_context (cr);
295                         }
296                         ebur->flush ();
297
298                         /* draw loudness histogram */
299                         cr = Cairo::Context::create (hist);
300                         cr->set_source_rgba (0, 0, 0, 1.0);
301                         cr->paint ();
302
303                         cr->set_source_rgba (.7, .7, .7, 1.0);
304                         cr->set_line_width (1.0);
305
306                         if (p->loudness_hist_max > 0 && i->second->have_loudness) {
307                                 for (size_t x = 0 ; x < 510; ++x) {
308                                         cr->move_to (x - .5, hh);
309                                         cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
310                                         cr->stroke ();
311                                 }
312                         }
313
314                         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
315                         layout->set_alignment (Pango::ALIGN_CENTER);
316
317                         // Label
318                         layout->set_text (_("LUFS\n(short)"));
319                         layout->get_pixel_size (w, h);
320                         Gtkmm2ext::rounded_rectangle (cr, 5, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
321                         cr->set_source_rgba (.1, .1, .1, 0.7);
322                         cr->fill ();
323                         cr->save ();
324                         cr->move_to (6, rint (.5 * (hh + w)));
325                         cr->set_source_rgba (.9, .9, .9, 1.0);
326                         cr->rotate (M_PI / -2.0);
327                         layout->show_in_cairo_context (cr);
328                         cr->restore ();
329
330                         // x-Axis
331                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
332                         layout->set_alignment (Pango::ALIGN_LEFT);
333                         for (int g = -53; g <= -8; g += 5) {
334                                 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
335                                 layout->set_text (string_compose ("%1", g));
336                                 layout->get_pixel_size (w, h);
337
338                                 cr->set_operator (Cairo::OPERATOR_OVER);
339                                 Gtkmm2ext::rounded_rectangle (cr,
340                                                 rint ((g + 59.0) * 10.0 - h * .5), 5,
341                                                 h + 2, w + 2, 4);
342                                 const float pk = (g + 59.0) / 54.0;
343                                 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
344                                 ArdourCanvas::set_source_rgba (cr, c);
345                                 cr->fill ();
346
347                                 cr->save ();
348                                 cr->set_source_rgba (.9, .9, .9, 1.0);
349                                 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
350                                 cr->rotate (M_PI / -2.0);
351                                 layout->show_in_cairo_context (cr);
352                                 cr->restore ();
353
354                                 cr->set_operator (Cairo::OPERATOR_ADD);
355                                 cr->save ();
356                                 cr->set_source_rgba (.3, .3, .3, 1.0);
357                                 cr->set_dash (dashes, 1.0);
358                                 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
359                                 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
360                                 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
361                                 cr->stroke ();
362                                 cr->restore ();
363                         }
364
365                         hist->flush ();
366
367                         CimgArea *nu = manage (new CimgArea (nums));
368                         CimgArea *eb = manage (new CimgArea (ebur));
369                         CimgArea *hi = manage (new CimgArea (hist));
370                         HBox *hb = manage (new HBox ());
371                         hb->set_spacing (4);
372                         hb->pack_start (*nu, false, false);
373                         hb->pack_start (*hi, false, false);
374                         hb->pack_start (*eb, false, false);
375                         vb->pack_start (*hb, false, false);
376                 }
377
378 #define XAXISLABEL(POS, TXT) {                            \
379   const float yy = rint (POS);                            \
380   layout->set_text (TXT);                                 \
381   layout->get_pixel_size (w, h);                          \
382   cr->move_to (m_l - 8 - w, rint ((POS) - h * .5));       \
383   cr->set_source_rgba (.9, .9, .9, 1.0);                  \
384   cr->set_operator (Cairo::OPERATOR_OVER);                \
385   layout->show_in_cairo_context (cr);                     \
386   cr->move_to (m_l - 4, yy - .5);                         \
387   cr->line_to (m_l + width, yy - .5);                     \
388   cr->set_source_rgba (.3, .3, .3, 1.0);                  \
389   cr->set_operator (Cairo::OPERATOR_ADD);                 \
390   cr->stroke ();                                          \
391 }
392
393                 for (uint32_t c = 0; c < p->n_channels; ++c) {
394                         /* draw waveform */
395                         const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
396                         const float height_2 = std::min (100, 8 * lin[0] / (int) p->n_channels); // TODO refine
397
398                         Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, 2 * height_2);
399                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
400                         cr->set_operator (Cairo::OPERATOR_SOURCE);
401                         cr->rectangle (0, 0, m_l, 2 * height_2);
402                         cr->set_source_rgba (0, 0, 0, 0);
403                         cr->fill ();
404                         cr->rectangle (m_l, 0, width, 2 * height_2);
405                         cr->set_source_rgba (0, 0, 0, 1.0);
406                         cr->fill ();
407                         cr->set_operator (Cairo::OPERATOR_OVER);
408
409                         cr->set_source_rgba (.7, .7, .7, 1.0);
410                         cr->set_line_width (1.0);
411                         for (size_t x = 0 ; x < width; ++x) {
412                                 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
413                                 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
414                         }
415                         cr->stroke ();
416
417                         // zero line
418                         cr->set_source_rgba (.3, .3, .3, 0.7);
419                         cr->move_to (m_l + 0, height_2 - .5);
420                         cr->line_to (m_l + width, height_2 - .5);
421                         cr->stroke ();
422
423                         // Unit
424                         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
425                         layout->set_alignment (Pango::ALIGN_LEFT);
426                         layout->set_text (_("dBFS"));
427                         layout->get_pixel_size (w, h);
428                         cr->move_to (rint (.5 * (m_l - h)), rint (height_2 + w * .5));
429                         cr->set_source_rgba (.9, .9, .9, 1.0);
430                         cr->save ();
431                         cr->rotate (M_PI / -2.0);
432                         layout->show_in_cairo_context (cr);
433                         cr->restore ();
434
435                         // x-Axis
436                         cr->set_line_width (1.0);
437                         cr->set_dash (dashes, 2.0);
438                         cr->set_line_cap (Cairo::LINE_CAP_ROUND);
439
440                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
441                         XAXISLABEL (height_2 * 0.6452, _("-9"));
442                         XAXISLABEL (height_2 * 1.3548, _("-9"));
443                         XAXISLABEL (height_2 * 0.2921, _("-3"));
444                         XAXISLABEL (height_2 * 1.7079, _("-3"));
445
446                         wave->flush ();
447                         CimgArea *wv = manage (new CimgArea (wave));
448                         vb->pack_start (*wv);
449                 }
450
451                 if (file_length > 0 && sample_rate > 0)
452                 {
453                         /* Time Axis  -- re-use waveform width */
454                         const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
455                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
456                         layout->set_text (_("00:00:00.000"));
457                         layout->get_pixel_size (w, h);
458                         int height = h * 1.75;
459                         Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
460                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
461                         cr->set_operator (Cairo::OPERATOR_SOURCE);
462                         cr->set_source_rgba (0, 0, 0, 1.0);
463                         cr->paint ();
464                         cr->rectangle (0, 0, m_l, height);
465                         cr->set_source_rgba (0, 0, 0, 0);
466                         cr->fill ();
467                         cr->set_operator (Cairo::OPERATOR_OVER);
468
469                         cr->set_line_width (1.0);
470                         for (int i = 0; i <= 4; ++i) {
471                                 const float fract = (float) i / 4.0;
472                                 // " XX:XX:XX.XXX"  [space/minus] 12 chars = 13.
473                                 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
474
475                                 char buf[16];
476                                 AudioClock::print_minsec (start_off + file_length * fract,
477                                                 buf, sizeof (buf), sample_rate);
478
479                                 layout->set_text (buf);
480                                 layout->get_pixel_size (w, h);
481                                 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
482                                 cr->set_source_rgba (.9, .9, .9, 1.0);
483                                 layout->show_in_cairo_context (cr);
484
485                                 cr->set_source_rgba (.7, .7, .7, 1.0);
486                                 cr->move_to (rint (m_l + width * fract) - .5, 0);
487                                 cr->line_to (rint (m_l + width * fract) - .5, ceil  (height * .15));
488                                 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
489                                 cr->line_to (rint (m_l + width * fract) - .5, height);
490                                 cr->stroke ();
491                         }
492
493                         layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
494                         layout->set_text (_("Time"));
495                         cr->set_source_rgba (.9, .9, .9, 1.0);
496                         layout->get_pixel_size (w, h);
497                         cr->move_to (rint (.5 * (m_l - w)), rint (.5 * (height - h)));
498                         layout->show_in_cairo_context (cr);
499
500                         ytme->flush ();
501                         CimgArea *tm = manage (new CimgArea (ytme));
502                         vb->pack_start (*tm);
503                 }
504
505                 {
506                         /* Draw Spectrum */
507                         const size_t swh = sizeof (p->spectrum) / sizeof (float);
508                         const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
509                         const size_t width = swh / height;
510
511                         Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
512                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
513                         cr->set_operator (Cairo::OPERATOR_SOURCE);
514                         cr->rectangle (0, 0, m_l, height);
515                         cr->set_source_rgba (0, 0, 0, 0);
516                         cr->fill ();
517                         cr->rectangle (m_l, 0, width, height);
518                         cr->set_source_rgba (0, 0, 0, 1.0);
519                         cr->fill ();
520                         cr->set_operator (Cairo::OPERATOR_OVER);
521
522                         for (size_t x = 0 ; x < width; ++x) {
523                                 for (size_t y = 0 ; y < height; ++y) {
524                                         const float pk = p->spectrum[x][y];
525                                         ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
526                                         ArdourCanvas::set_source_rgba (cr, c);
527                                         cr->rectangle (m_l + x - .5, y - .5, 1, 1);
528                                         cr->fill ();
529                                 }
530                         }
531
532                         // Unit
533                         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
534                         layout->set_text (_("Hz"));
535                         layout->get_pixel_size (w, h);
536                         cr->move_to (rint (.5 * (m_l - h)), rint ((height + w) * .5));
537                         cr->set_source_rgba (.9, .9, .9, 1.0);
538                         cr->save ();
539                         cr->rotate (M_PI / -2.0);
540                         layout->show_in_cairo_context (cr);
541                         cr->restore ();
542
543                         // x-Axis
544                         cr->set_line_width (1.0);
545                         cr->set_dash (dashes, 2.0);
546                         cr->set_line_cap (Cairo::LINE_CAP_ROUND);
547
548                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
549                         //XAXISLABEL (p->freq[0], _("50Hz"));
550                         XAXISLABEL (p->freq[1], _("100"));
551                         XAXISLABEL (p->freq[2], _("500"));
552                         XAXISLABEL (p->freq[3], _("1K"));
553                         XAXISLABEL (p->freq[4], _("5K"));
554                         XAXISLABEL (p->freq[5], _("10K"));
555
556                         spec->flush ();
557                         CimgArea *sp = manage (new CimgArea (spec));
558                         vb->pack_start (*sp);
559                 }
560
561                 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
562         }
563
564         pages.set_show_tabs (true);
565         pages.show_all ();
566         pages.set_name ("ExportReportNotebook");
567         pages.set_current_page (0);
568
569         get_vbox ()->set_spacing (4);
570         get_vbox ()->pack_start (pages, false, false);
571
572         add_button (Stock::CLOSE, RESPONSE_ACCEPT);
573         set_default_response (RESPONSE_ACCEPT);
574         show_all ();
575 }
576
577 int
578 ExportReport::run ()
579 {
580         return ArdourDialog::run ();
581 }