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