Export Analysis GUI: clarify signal-distribution axis labels
[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 "audiographer/general/analyser.h"
33
34 #include "ardour/audiofilesource.h"
35 #include "ardour/audioregion.h"
36 #include "ardour/auditioner.h"
37 #include "ardour/dB.h"
38 #include "ardour/region_factory.h"
39 #include "ardour/session.h"
40 #include "ardour/smf_source.h"
41 #include "ardour/source_factory.h"
42 #include "ardour/srcfilesource.h"
43
44 #include "audio_clock.h"
45 #include "export_report.h"
46 #include "logmeter.h"
47 #include "ui_config.h"
48
49 #include "i18n.h"
50
51 using namespace Gtk;
52 using namespace ARDOUR;
53
54 ExportReport::ExportReport (Session* session, StatusPtr s)
55         : ArdourDialog (_("Export Report/Analysis"))
56         , status (s)
57         , _session (session)
58         , _audition_num (-1)
59         , _page_num (0)
60 {
61         set_resizable (false);
62         pages.set_scrollable ();
63
64         AnalysisResults & ar = status->result_map;
65
66         std::vector<double> dashes;
67         dashes.push_back (3.0);
68         dashes.push_back (5.0);
69
70         int page = 0;
71         for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
72                 Label *l;
73                 VBox *vb = manage (new VBox ());
74                 Table *t = manage (new Table (4, 4));
75                 Table *wtbl = manage (new Table (3, 2));
76                 int wrow = 0;
77                 t->set_border_width (0);
78                 t->set_spacings (4);
79                 wtbl->set_spacings (4);
80                 vb->set_spacing (4);
81                 vb->set_border_width (4);
82                 vb->pack_start (*t, false, false, 2);
83                 vb->pack_start (*wtbl, false, false, 2);
84
85                 std::string path = i->first;
86                 ExportAnalysisPtr p = i->second;
87
88                 std::list<CimgPlayheadArea*> playhead_widgets;
89
90                 l = manage (new Label (_("File:"), ALIGN_END));
91                 t->attach (*l, 0, 1, 0, 1);
92                 l = manage (new Label ());
93                 l->set_ellipsize (Pango::ELLIPSIZE_START);
94                 l->set_width_chars (48);
95                 l->set_max_width_chars (48);
96                 l->set_text (path);
97                 l->set_alignment (ALIGN_START, ALIGN_CENTER);
98                 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
99
100                 Button *b = manage (new Button (_("Open Folder")));
101                 t->attach (*b, 3, 4, 0, 2, FILL, SHRINK);
102                 b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
103
104                 SoundFileInfo info;
105                 std::string errmsg;
106
107                 framecnt_t file_length = 0;
108                 framecnt_t sample_rate = 0;
109                 framecnt_t start_off = 0;
110                 unsigned int channels = 0;
111
112                 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
113                         AudioClock * clock;
114
115                         file_length = info.length;
116                         sample_rate = info.samplerate;
117                         start_off = info.timecode;
118                         channels = info.channels;
119
120                         files.insert (std::make_pair (page, AuditionInfo (path, channels)));
121
122                         /* File Info Table */
123
124                         framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
125                         double src_coef = (double) nfr / info.samplerate;
126
127                         l = manage (new Label (_("Format:"), ALIGN_END));
128                         t->attach (*l, 0, 1, 1, 2);
129                         std::string fmt = info.format_name;
130                         std::replace (fmt.begin (), fmt.end (), '\n', ' ');
131                         l = manage (new Label ());
132                         l->set_ellipsize (Pango::ELLIPSIZE_START);
133                         l->set_width_chars (48);
134                         l->set_max_width_chars (48);
135                         l->set_text (fmt);
136                         l->set_alignment (ALIGN_START, ALIGN_CENTER);
137                         t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
138
139                         l = manage (new Label (_("Channels:"), ALIGN_END));
140                         t->attach (*l, 0, 1, 2, 3);
141                         l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
142                         t->attach (*l, 1, 2, 2, 3);
143
144                         l = manage (new Label (_("Sample rate:"), ALIGN_END));
145                         t->attach (*l, 0, 1, 3, 4);
146                         l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
147                         t->attach (*l, 1, 2, 3, 4);
148
149                         l = manage (new Label (_("Duration:"), ALIGN_END));
150                         t->attach (*l, 2, 3, 2, 3);
151                         clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
152                         clock->set_session (_session);
153                         clock->set_mode (AudioClock::MinSec);
154                         clock->set (info.length * src_coef + 0.5, true);
155                         t->attach (*clock, 3, 4, 2, 3);
156
157                         l = manage (new Label (_("Timecode:"), ALIGN_END));
158                         t->attach (*l, 2, 3, 3, 4);
159                         clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
160                         clock->set_session (_session);
161                         clock->set_mode (AudioClock::Timecode);
162                         clock->set (info.timecode * src_coef + 0.5, true);
163                         t->attach (*clock, 3, 4, 3, 4);
164                 } else {
165                         l = manage (new Label (_("Error:"), ALIGN_END));
166                         t->attach (*l, 0, 1, 1, 2);
167                         l = manage (new Label (errmsg, ALIGN_START));
168                         t->attach (*l, 1, 4, 1, 2);
169                 }
170
171                 int w, h;
172                 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
173
174                 // calc geometry of numerics
175                 const float dbfs = accurate_coefficient_to_dB (p->peak);
176                 const float dbtp = accurate_coefficient_to_dB (p->truepeak);
177
178 #define TXTSIZE(LINE, TXT, FONT) {                                     \
179   layout->set_font_description (UIConfiguration::instance ().FONT ()); \
180   layout->set_text (TXT);                                              \
181   layout->get_pixel_size (w, h);                                       \
182   if (w > mnw) { mnw = w; }                                            \
183   if (h > lin[LINE]) { lin[LINE] = h; }                                \
184 }
185
186 #define TXTWIDTH(TXT, FONT) {                                          \
187   layout->set_font_description (UIConfiguration::instance ().FONT ()); \
188   layout->set_text (TXT);                                              \
189   layout->get_pixel_size (w, h);                                       \
190   if (w > mml) { mml = w; }                                            \
191 }
192
193                 int m_r = 0; // right side
194                 int mnh = 0; // mono height
195                 int mnw = 0; // max numeric width
196                 int anw = 0; // spectrum annotation text width
197
198                 int lin[6] = { 0, 0, 0, 0, 0, 0 }; // max line height
199
200                 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
201
202                 TXTSIZE(0, _("-888"), get_SmallMonospaceFont);
203                 anw = w;
204                 m_r = anw + 10;
205                 mnh = h + 1;
206
207                 TXTSIZE(0, _("Peak:"), get_SmallFont);
208                 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
209                 TXTSIZE(2, _("True Peak:"), get_SmallFont);
210                 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
211                 TXTSIZE(4, _("Normalization Gain:"), get_SmallFont);
212                 TXTSIZE(5, _("+888.88 dB"), get_SmallMonospaceFont);
213
214                 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
215                 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
216                 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
217                 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
218
219                 mnw += 8;
220                 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] *1.25 + lin[4] * 1.25 + lin[5];
221                 const int hh = std::max (100, ht + 12);
222                 const int htn = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3];
223                 int m_l =  2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800 - m_r; // margin left
224
225                 int mml = 0; // min margin left -- ensure left margin is wide enough
226                 TXTWIDTH (_("Time"), get_SmallFont);
227                 TXTWIDTH (_("100"), get_SmallMonospaceFont);
228                 m_l = (std::max(anw + mnh + 14, std::max (m_l, mml + 8)) + 3) & ~3;
229
230                 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800 + m_r) / 2;
231                 const int nw2 = mnw / 2; // nums, horizontal center
232
233                 int y0[4];
234                 if (p->normalized) {
235                         y0[0] = (hh - ht) * .5;
236                 } else {
237                         y0[0] = (hh - htn) * .5;
238                 }
239                 y0[1] = y0[0] + lin[0] * 1.25;
240                 y0[2] = y0[1] + lin[1] * 1.25;
241                 y0[3] = y0[2] + lin[2] * 1.25;
242                 y0[4] = y0[3] + lin[3] * 1.25;
243                 y0[5] = y0[4] + lin[4] * 1.25;
244
245
246                 { /* peak, loudness and R128 histogram */
247                         Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
248                         Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
249                         Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
250
251                         /* peak and true-peak numerics */
252                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
253                         cr->set_source_rgba (0, 0, 0, 1.0);
254                         cr->paint ();
255
256                         layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
257                         layout->set_alignment (Pango::ALIGN_LEFT);
258                         layout->set_text (_("Peak:"));
259                         layout->get_pixel_size (w, h);
260                         cr->move_to (rint (nw2 - w * .5), y0[0]);
261                         cr->set_source_rgba (.7, .7, .7, 1.0);
262                         layout->show_in_cairo_context (cr);
263
264                         layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
265                         layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
266                         layout->get_pixel_size (w, h);
267                         cr->move_to (rint (nw2 - w * .5), y0[1]);
268                         if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
269                         else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
270                         layout->show_in_cairo_context (cr);
271
272                         if (p->have_dbtp) {
273                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
274                                 layout->set_text (_("True Peak:"));
275                                 layout->get_pixel_size (w, h);
276                                 cr->move_to (rint (nw2 - w * .5), y0[2]);
277                                 cr->set_source_rgba (.7, .7, .7, 1.0);
278                                 layout->show_in_cairo_context (cr);
279
280                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
281                                 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
282                                 layout->get_pixel_size (w, h);
283                                 cr->move_to (rint (nw2 - w * .5), y0[3]);
284                                 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
285                                 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
286                                 layout->show_in_cairo_context (cr);
287                         }
288
289                         if (p->normalized) {
290                                 const float ndb = accurate_coefficient_to_dB (p->norm_gain_factor);
291                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
292                                 layout->set_text (_("Normalization Gain:"));
293                                 layout->get_pixel_size (w, h);
294                                 cr->move_to (rint (nw2 - w * .5), y0[4]);
295                                 cr->set_source_rgba (.7, .7, .7, 1.0);
296                                 layout->show_in_cairo_context (cr);
297
298                                 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
299                                 layout->set_text (string_compose (_("%1 dB"), std::setprecision (2), std::showpos, std::fixed, ndb));
300
301                                 layout->get_pixel_size (w, h);
302                                 cr->move_to (rint (nw2 - w * .5), y0[5]);
303                                 // TODO tweak thresholds
304                                 if (p->norm_gain_factor < 1.0) {
305                                         cr->set_source_rgba (1.0, .7, .1, 1.0);
306                                 } else if (p->norm_gain_factor == 1.0) {
307                                         cr->set_source_rgba (.7, .7, .7, 1.0);
308                                 } else if (fabsf (ndb) < 12) {
309                                         cr->set_source_rgba (.1, 1.0, .1, 1.0);
310                                 } else if (fabsf (ndb) < 18) {
311                                         cr->set_source_rgba (1.0, .7, .1, 1.0);
312                                 } else {
313                                         cr->set_source_rgba (1.0, .1, .1, 1.0);
314                                 }
315                                 layout->show_in_cairo_context (cr);
316                         }
317
318                         nums->flush ();
319
320                         /* EBU R128 numerics */
321                         cr = Cairo::Context::create (ebur);
322                         cr->set_source_rgba (0, 0, 0, 1.0);
323                         cr->paint ();
324
325                         cr->set_source_rgba (.7, .7, .7, 1.0);
326
327                         if (!i->second->have_loudness) {
328                                 layout->set_alignment (Pango::ALIGN_CENTER);
329                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
330                                 layout->set_text (_("Not\nAvailable"));
331                                 layout->get_pixel_size (w, h);
332                                 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
333                                 layout->show_in_cairo_context (cr);
334                         }
335                         else if (p->loudness == -200 && p->loudness_range == 0) {
336                                 layout->set_alignment (Pango::ALIGN_CENTER);
337                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
338                                 layout->set_text (_("Not\nAvailable"));
339                                 layout->get_pixel_size (w, h);
340                                 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .66));
341                                 layout->show_in_cairo_context (cr);
342                                 int yy = h * .5;
343
344                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
345                                 layout->set_text (_("(too short integration time)"));
346                                 layout->get_pixel_size (w, h);
347                                 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
348                                 layout->show_in_cairo_context (cr);
349
350                         } else {
351                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
352                                 layout->set_alignment (Pango::ALIGN_LEFT);
353                                 layout->set_text (_("Integrated Loudness:"));
354                                 layout->get_pixel_size (w, h);
355                                 cr->move_to (rint (nw2 - w * .5), y0[0]);
356                                 layout->show_in_cairo_context (cr);
357
358                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
359                                 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed,  p->loudness));
360                                 layout->get_pixel_size (w, h);
361                                 cr->move_to (rint (nw2 - w * .5), y0[1]);
362                                 layout->show_in_cairo_context (cr);
363
364                                 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
365                                 layout->set_text (_("Loudness Range:"));
366                                 layout->get_pixel_size (w, h);
367                                 cr->move_to (rint (nw2 - w * .5), y0[2]);
368                                 layout->show_in_cairo_context (cr);
369
370                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
371                                 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
372                                 layout->get_pixel_size (w, h);
373                                 cr->move_to (rint (nw2 - w * .5), y0[3]);
374                                 layout->show_in_cairo_context (cr);
375                         }
376                         ebur->flush ();
377
378                         /* draw loudness histogram */
379                         cr = Cairo::Context::create (hist);
380                         cr->set_source_rgba (0, 0, 0, 1.0);
381                         cr->paint ();
382
383                         cr->set_source_rgba (.7, .7, .7, 1.0);
384                         cr->set_line_width (1.0);
385
386                         if (p->loudness_hist_max > 0 && i->second->have_loudness) {
387                                 // draw data
388                                 for (size_t x = 0 ; x < 510; ++x) {
389                                         cr->move_to (x - .5, hh);
390                                         cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
391                                         cr->stroke ();
392                                 }
393
394                                 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
395                                 layout->set_alignment (Pango::ALIGN_CENTER);
396
397                                 // x-axis label
398                                 layout->set_text (_("LUFS\n(short)"));
399                                 layout->get_pixel_size (w, h);
400                                 Gtkmm2ext::rounded_rectangle (cr, 5, 5, w + 2, h + 2, 4);
401                                 cr->set_source_rgba (.1, .1, .1, 0.7);
402                                 cr->fill ();
403                                 cr->move_to (6, 6);
404                                 cr->set_source_rgba (.9, .9, .9, 1.0);
405                                 layout->show_in_cairo_context (cr);
406
407                                 // y-axis label
408                                 layout->set_text (_("Multiplicity"));
409                                 layout->get_pixel_size (w, h);
410                                 Gtkmm2ext::rounded_rectangle (cr, 5, hh - w - 3, h + 2, w + 2, 4);
411                                 cr->set_source_rgba (.1, .1, .1, 0.7);
412                                 cr->fill ();
413                                 cr->save ();
414                                 cr->move_to (6, hh - 2);
415                                 cr->set_source_rgba (.9, .9, .9, 1.0);
416                                 cr->rotate (M_PI / -2.0);
417                                 layout->show_in_cairo_context (cr);
418                                 cr->restore ();
419
420                                 // x-Axis labels
421                                 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
422                                 layout->set_alignment (Pango::ALIGN_LEFT);
423                                 for (int g = -53; g <= -8; g += 5) {
424                                         // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
425                                         layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
426                                         layout->get_pixel_size (w, h);
427
428                                         cr->set_operator (Cairo::OPERATOR_OVER);
429                                         Gtkmm2ext::rounded_rectangle (cr,
430                                                         rint ((g + 59.0) * 10.0 - h * .5), 5,
431                                                         h + 2, w + 2, 4);
432                                         const float pk = (g + 59.0) / 54.0;
433                                         ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
434                                         ArdourCanvas::set_source_rgba (cr, c);
435                                         cr->fill ();
436
437                                         cr->save ();
438                                         cr->set_source_rgba (.9, .9, .9, 1.0);
439                                         cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
440                                         cr->rotate (M_PI / -2.0);
441                                         layout->show_in_cairo_context (cr);
442                                         cr->restore ();
443
444                                         cr->set_operator (Cairo::OPERATOR_ADD);
445                                         cr->save ();
446                                         cr->set_source_rgba (.3, .3, .3, 1.0);
447                                         cr->set_dash (dashes, 1.0);
448                                         cr->set_line_cap (Cairo::LINE_CAP_ROUND);
449                                         cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
450                                         cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
451                                         cr->stroke ();
452                                         cr->restore ();
453                                 }
454
455                         } else {
456                                 layout->set_alignment (Pango::ALIGN_CENTER);
457                                 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
458                                 layout->set_text (_("Not\nAvailable"));
459                                 layout->get_pixel_size (w, h);
460                                 cr->move_to (rint ((510 - w) * .5), rint ((hh - h) * .5));
461                                 layout->show_in_cairo_context (cr);
462                         }
463
464                         hist->flush ();
465
466                         CimgArea *nu = manage (new CimgArea (nums));
467                         CimgArea *eb = manage (new CimgArea (ebur));
468                         CimgArea *hi = manage (new CimgArea (hist));
469                         HBox *hb = manage (new HBox ());
470                         hb->set_spacing (4);
471                         hb->pack_start (*nu, false, false);
472                         hb->pack_start (*hi, false, false);
473                         hb->pack_start (*eb, false, false);
474
475                         wtbl->attach (*hb, 0, 2, wrow, wrow + 1, SHRINK, SHRINK);
476                         ++wrow;
477                 }
478
479 #define XAXISLABEL(POS, TXT) {                            \
480   const float yy = rint (POS);                            \
481   layout->set_text (TXT);                                 \
482   layout->get_pixel_size (w, h);                          \
483   cr->move_to (m_l - 8 - w, rint ((POS) - h * .5));       \
484   cr->set_source_rgba (.9, .9, .9, 1.0);                  \
485   cr->set_operator (Cairo::OPERATOR_OVER);                \
486   layout->show_in_cairo_context (cr);                     \
487   cr->move_to (m_l - 4, yy - .5);                         \
488   cr->line_to (m_l + width, yy - .5);                     \
489   cr->set_source_rgba (.3, .3, .3, 1.0);                  \
490   cr->set_operator (Cairo::OPERATOR_ADD);                 \
491   cr->stroke ();                                          \
492 }
493
494
495                 {
496                         VBox *lrb = manage (new VBox());
497                         ToggleButton *log = manage (new ToggleButton (S_("Logscale|Lg")));
498                         ToggleButton *rec = manage (new ToggleButton (S_("Rectified|Rf")));
499                         lrb->pack_start (*log, false, false, 5);
500                         lrb->pack_end (*rec, false, false, 5);
501                         log->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_logscale_toggled), log));
502                         rec->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_rectivied_toggled), rec));
503                         lrb->show_all ();
504                         wtbl->attach (*lrb, 1, 2, wrow, wrow + p->n_channels, SHRINK, SHRINK);
505                 }
506
507                 for (uint32_t c = 0; c < p->n_channels; ++c) {
508                         /* draw waveform */
509                         const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
510
511                         Cairo::RefPtr<Cairo::ImageSurface> wave;
512                         Cairo::RefPtr<Cairo::ImageSurface> wave_log;
513                         Cairo::RefPtr<Cairo::ImageSurface> wave_rect;
514                         Cairo::RefPtr<Cairo::ImageSurface> wave_lr;
515                         draw_waveform(wave, p, c, m_l, width, anw, lin[0], false, false);
516                         draw_waveform(wave_log, p, c, m_l, width, anw, lin[0], true, false);
517                         draw_waveform(wave_rect, p, c, m_l, width, anw, lin[0], false, true);
518                         draw_waveform(wave_lr, p, c, m_l, width, anw, lin[0], true, true);
519
520                         CimgWaveArea *wv = manage (new CimgWaveArea (wave, wave_log, wave_rect, wave_lr, m_l, width));
521
522                         playhead_widgets.push_back (wv);
523                         waves.push_back (wv);
524                         wv->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
525                         wtbl->attach (*wv, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
526                         ++wrow;
527                 }
528
529                 if (channels > 0 && file_length > 0 && sample_rate > 0)
530                 {
531                         /* Time Axis  -- re-use waveform width */
532                         const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
533                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
534                         layout->set_text (_("00:00:00.000"));
535                         layout->get_pixel_size (w, h);
536                         int height = h * 1.75;
537                         Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
538                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
539                         cr->set_operator (Cairo::OPERATOR_SOURCE);
540                         cr->set_source_rgba (0, 0, 0, 1.0);
541                         cr->paint ();
542                         cr->rectangle (0, 0, m_l, height);
543                         cr->set_source_rgba (0, 0, 0, 0);
544                         cr->fill ();
545                         cr->set_operator (Cairo::OPERATOR_OVER);
546
547                         cr->set_line_width (1.0);
548                         for (int i = 0; i <= 4; ++i) {
549                                 const float fract = (float) i / 4.0;
550                                 // " XX:XX:XX.XXX"  [space/minus] 12 chars = 13.
551                                 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
552
553                                 char buf[16];
554                                 AudioClock::print_minsec (start_off + file_length * fract,
555                                                 buf, sizeof (buf), sample_rate);
556
557                                 layout->set_text (buf);
558                                 layout->get_pixel_size (w, h);
559                                 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
560                                 cr->set_source_rgba (.9, .9, .9, 1.0);
561                                 layout->show_in_cairo_context (cr);
562
563                                 cr->set_source_rgba (.7, .7, .7, 1.0);
564                                 cr->move_to (rint (m_l + width * fract) - .5, 0);
565                                 cr->line_to (rint (m_l + width * fract) - .5, ceil  (height * .15));
566                                 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
567                                 cr->line_to (rint (m_l + width * fract) - .5, height);
568                                 cr->stroke ();
569                         }
570
571                         layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
572                         layout->set_text (_("Time"));
573                         cr->set_source_rgba (.9, .9, .9, 1.0);
574                         layout->get_pixel_size (w, h);
575                         cr->move_to (rint (m_l - w - 8), rint (.5 * (height - h)));
576                         layout->show_in_cairo_context (cr);
577
578                         ytme->flush ();
579                         CimgPlayheadArea *tm = manage (new CimgPlayheadArea (ytme, m_l, width, true));
580                         playhead_widgets.push_back (tm);
581                         tm->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
582                         wtbl->attach (*tm, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
583                         ++wrow;
584                 }
585
586                 {
587                         /* Draw Spectrum */
588                         const size_t swh = sizeof (p->spectrum) / sizeof (float);
589                         const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
590                         const size_t width = swh / height;
591
592                         Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
593                         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
594                         cr->set_operator (Cairo::OPERATOR_SOURCE);
595                         cr->rectangle (0, 0, m_l, height);
596                         cr->set_source_rgba (0, 0, 0, 0);
597                         cr->fill ();
598                         cr->rectangle (m_l, 0, width, height);
599                         cr->set_source_rgba (0, 0, 0, 1.0);
600                         cr->fill ();
601                         cr->set_operator (Cairo::OPERATOR_OVER);
602
603                         for (size_t x = 0 ; x < width; ++x) {
604                                 for (size_t y = 0 ; y < height; ++y) {
605                                         const float pk = p->spectrum[x][y];
606                                         ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
607                                         ArdourCanvas::set_source_rgba (cr, c);
608                                         cr->rectangle (m_l + x - .5, y - .5, 1, 1);
609                                         cr->fill ();
610                                 }
611                         }
612
613                         // Unit
614                         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
615                         layout->set_text (_("Hz"));
616                         layout->get_pixel_size (w, h);
617                         cr->move_to (rint (m_l - h - anw - 10), rint ((height + w) * .5));
618                         cr->set_source_rgba (.9, .9, .9, 1.0);
619                         cr->save ();
620                         cr->rotate (M_PI / -2.0);
621                         layout->show_in_cairo_context (cr);
622                         cr->restore ();
623
624                         // x-Axis
625                         cr->set_line_width (1.0);
626                         cr->set_dash (dashes, 2.0);
627                         cr->set_line_cap (Cairo::LINE_CAP_ROUND);
628
629                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
630                         //XAXISLABEL (p->freq[0], _("50Hz"));
631                         XAXISLABEL (p->freq[1], _("100"));
632                         XAXISLABEL (p->freq[2], _("500"));
633                         XAXISLABEL (p->freq[3], _("1K"));
634                         XAXISLABEL (p->freq[4], _("5K"));
635                         XAXISLABEL (p->freq[5], _("10K"));
636                         spec->flush ();
637
638                         // annotations
639                         Cairo::RefPtr<Cairo::ImageSurface> scale = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_r, height);
640                         cr = Cairo::Context::create (scale);
641                         cr->set_operator (Cairo::OPERATOR_SOURCE);
642                         cr->rectangle (0, 0, m_r, height);
643                         cr->set_source_rgba (0, 0, 0, 0);
644                         cr->fill ();
645
646                         cr->set_operator (Cairo::OPERATOR_OVER);
647                         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
648                         layout->set_alignment (Pango::ALIGN_LEFT);
649                         layout->set_text (_("dBFS"));
650                         layout->get_pixel_size (w, h);
651                         cr->move_to (rint (.5 * (m_r - w)), height - h - 2);
652                         cr->set_source_rgba (.9, .9, .9, 1.0);
653                         layout->show_in_cairo_context (cr);
654
655                         int innertop = ceil (mnh * .5) + 1;
656                         size_t innerheight = (height - 2 * innertop - h - 2);
657
658                         cr->rectangle (1, innertop - 1,  m_r - 2 - anw, innerheight + 2);
659                         cr->set_source_rgba (0, 0, 0, 1.0);
660                         cr->fill_preserve ();
661                         cr->set_line_width (1.0);
662                         cr->set_source_rgba (.7, .7, .6, 1.0);
663                         cr->stroke ();
664
665                         for (size_t y = 0 ; y < innerheight - 2; ++y) {
666                                         const float pk = 1.0 - (float) y / innerheight;
667                                         ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
668                                         ArdourCanvas::set_source_rgba (cr, c);
669                                         cr->rectangle (2, innertop + y + .5, m_r - 4 - anw, 1);
670                                         cr->fill ();
671                         }
672
673                         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
674                         for (int i = 0; i <= 4; ++i) {
675                                 const float fract = (float) i / 4.0;
676                                 const float yalign = .5; // (i == 4) ? 0 : (i == 0) ? 1.0 : .5;
677                                 char buf[16];
678                                 snprintf (buf, sizeof (buf), "%.0f", AudioGrapher::Analyser::fft_range_db * -fract);
679                                 layout->set_text (buf);
680                                 layout->get_pixel_size (w, h);
681
682                                 cr->move_to (m_r - anw, rint (innertop + fract * innerheight - h * yalign));
683                                 cr->set_source_rgba (.9, .9, .9, 1.0);
684                                 layout->show_in_cairo_context (cr);
685                         }
686                         scale->flush ();
687
688                         CimgPlayheadArea *sp = manage (new CimgPlayheadArea (spec, m_l, width));
689                         playhead_widgets.push_back (sp);
690                         sp->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
691                         CimgArea *an = manage (new CimgArea (scale));
692                         wtbl->attach (*sp, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
693                         wtbl->attach (*an, 1, 2, wrow, wrow + 1, SHRINK, SHRINK);
694                         ++wrow;
695                 }
696
697                 timeline[page] = playhead_widgets;
698
699                 HBox *tab = manage (new HBox ());
700                 l = manage (new Label (Glib::path_get_basename (path)));
701                 Gtk::Image *img =  manage (new Image (Stock::MEDIA_PLAY, ICON_SIZE_MENU));
702                 tab->pack_start (*img);
703                 tab->pack_start (*l);
704                 l->show();
705                 tab->show();
706                 img->hide();
707                 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, *tab));
708                 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
709         }
710
711         pages.set_show_tabs (true);
712         pages.show_all ();
713         pages.set_name ("ExportReportNotebook");
714         pages.set_current_page (0);
715
716         get_vbox ()->set_spacing (4);
717         get_vbox ()->pack_start (pages, false, false);
718
719         if (_session) {
720                 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
721                 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
722         }
723
724         play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
725         stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
726         add_button (Stock::CLOSE, RESPONSE_CLOSE);
727
728         set_default_response (RESPONSE_CLOSE);
729         stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
730         play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
731         stop_btn->set_sensitive (false);
732         show_all ();
733 }
734
735 int
736 ExportReport::run ()
737 {
738         do {
739                 int i = ArdourDialog::run ();
740                 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
741                         break;
742                 }
743         } while (1);
744
745         if (_session) {
746                 _session->cancel_audition();
747         }
748         return RESPONSE_CLOSE;
749 }
750
751 void
752 ExportReport::open_folder (std::string p)
753 {
754         PBD::open_uri (Glib::path_get_dirname(p));
755 }
756
757 void
758 ExportReport::audition_active (bool active)
759 {
760         stop_btn->set_sensitive (active);
761         play_btn->set_sensitive (!active);
762
763         if (!active && _audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
764                 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
765                                 i != timeline[_audition_num].end();
766                                 ++i) {
767                         (*i)->set_playhead (-1);
768                 }
769         }
770
771         if (_audition_num >= 0 ) {
772                 Widget *page = pages.get_nth_page (_audition_num);
773                 HBox *box = static_cast<Gtk::HBox*> (pages.get_tab_label (*page));
774                 if (!active) {
775                         (*(box->get_children().begin()))->hide ();
776                 } else {
777                         (*(box->get_children().begin()))->show ();
778                 }
779         }
780
781         if (!active) {
782                 _audition_num = -1;
783         }
784 }
785
786 void
787 ExportReport::audition (std::string path, unsigned n_chn, int page)
788 {
789         assert (_session);
790         _session->cancel_audition();
791
792         if (n_chn ==0) { return; }
793
794         /* can't really happen, unless the user replaces the file while the dialog is open.. */
795         if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
796                 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
797                 return;
798         }
799         if (SMFSource::valid_midi_file (path)) { return; }
800
801         boost::shared_ptr<Region> r;
802         SourceList srclist;
803         boost::shared_ptr<AudioFileSource> afs;
804         bool old_sbp = AudioSource::get_build_peakfiles ();
805
806         /* don't even think of building peakfiles for these files */
807         AudioSource::set_build_peakfiles (false);
808
809         for (unsigned int n = 0; n < n_chn; ++n) {
810                 try {
811                         afs = boost::dynamic_pointer_cast<AudioFileSource> (
812                                 SourceFactory::createExternal (DataType::AUDIO, *_session,
813                                                                                  path, n,
814                                                                                  Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
815                         if (afs->sample_rate() != _session->nominal_frame_rate()) {
816                                 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
817                                 srclist.push_back(sfs);
818                         } else {
819                                 srclist.push_back(afs);
820                         }
821                 } catch (failed_constructor& err) {
822                         PBD::error << _("Could not access soundfile: ") << path << endmsg;
823                         AudioSource::set_build_peakfiles (old_sbp);
824                         return;
825                 }
826         }
827
828         AudioSource::set_build_peakfiles (old_sbp);
829
830         if (srclist.empty()) {
831                 return;
832         }
833
834         afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
835         std::string rname = region_name_from_path (afs->path(), false);
836
837         PBD::PropertyList plist;
838
839         plist.add (ARDOUR::Properties::start, 0);
840         plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
841         plist.add (ARDOUR::Properties::name, rname);
842         plist.add (ARDOUR::Properties::layer, 0);
843
844         r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
845
846         r->set_position(0);
847         _session->audition_region(r);
848         _audition_num = page;
849 }
850
851 void
852 ExportReport::play_audition ()
853 {
854         if (_audition_num >= 0 || !_session) { return; }
855         if (files.find (_page_num) == files.end()) { return; }
856         audition (files[_page_num].path, files[_page_num].channels, _page_num);
857 }
858
859 void
860 ExportReport::stop_audition ()
861 {
862         if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
863                 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
864                                 i != timeline[_audition_num].end();
865                                 ++i) {
866                         (*i)->set_playhead (-1);
867                 }
868         }
869         if (_session) {
870                 _session->cancel_audition();
871         }
872 }
873
874 void
875 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
876 {
877         if (_audition_num == _page_num) {
878                 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
879                                 i != timeline[_audition_num].end();
880                                 ++i) {
881                         (*i)->set_playhead (-1);
882                 }
883         }
884         _page_num = page_num;
885 }
886
887 void
888 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
889 {
890         if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
891                 const float p = (float)pos / len;
892                 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
893                                 i != timeline[_audition_num].end();
894                                 ++i) {
895                         (*i)->set_playhead (p);
896                 }
897         }
898 }
899
900 void
901 ExportReport::audition_seek (int page, float pos)
902 {
903         if (_audition_num == page && _session) {
904                 _session->the_auditioner()->seek_to_percent (100.f * pos);
905         }
906 }
907
908 void
909 ExportReport::on_logscale_toggled (Gtk::ToggleButton* b)
910 {
911         bool en = b->get_active ();
912         for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
913                 (*i)->set_logscale (en);
914         }
915 }
916
917 void
918 ExportReport::on_rectivied_toggled (Gtk::ToggleButton* b)
919 {
920         bool en = b->get_active ();
921         for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
922                 (*i)->set_rectified (en);
923         }
924 }
925
926 void
927 ExportReport::draw_waveform (Cairo::RefPtr<Cairo::ImageSurface>& wave, ExportAnalysisPtr p, uint32_t c, int m_l, size_t width, int anw, int height, bool log, bool rect)
928 {
929         int w, h;
930         Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
931         const float height_2 = std::min (100, 8 * height / (int) p->n_channels); // TODO refine
932         const float ht = 2.f * height_2;
933
934         std::vector<double> dashes;
935         dashes.push_back (3.0);
936         dashes.push_back (5.0);
937
938         wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, ht);
939         Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
940         cr->set_operator (Cairo::OPERATOR_SOURCE);
941         cr->rectangle (0, 0, m_l, ht);
942         cr->set_source_rgba (0, 0, 0, 0);
943         cr->fill ();
944         cr->rectangle (m_l, 0, width, ht);
945         cr->set_source_rgba (0, 0, 0, 1.0);
946         cr->fill ();
947         cr->set_operator (Cairo::OPERATOR_OVER);
948
949         cr->set_source_rgba (.7, .7, .7, 1.0);
950         cr->set_line_width (1.0);
951
952         // -1dB range
953         float clip_top;
954         float clip_bot;
955
956         if (rect) {
957                 clip_bot = ht;
958
959                 if (log) {
960                         clip_top = ht * (1.f - alt_log_meter (-1));
961                         for (size_t x = 0 ; x < width; ++x) {
962                                 const float v = alt_log_meter (fast_coefficient_to_dB (std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min))));
963                                 cr->move_to (m_l + x - .5, ht - ht * v);
964                                 cr->line_to (m_l + x - .5, ht);
965                         }
966                         cr->stroke ();
967                 } else {
968                         clip_top = ht * (1.f - dB_to_coefficient (-1));
969                         for (size_t x = 0 ; x < width; ++x) {
970                                 const float v = std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min));
971                                 cr->move_to (m_l + x - .5, ht - ht * v);
972                                 cr->line_to (m_l + x - .5, ht);
973                         }
974                         cr->stroke ();
975                 }
976         } else {
977                 if (log) {
978                         clip_top = height_2 - height_2 * alt_log_meter (-1);
979                         clip_bot = height_2 + height_2 * alt_log_meter (-1);
980                         for (size_t x = 0 ; x < width; ++x) {
981                                 float pmax, pmin;
982                                 if (p->peaks[c][x].max > 0) {
983                                         pmax =  alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].max));
984                                 } else {
985                                         pmax = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].max));
986                                 }
987
988                                 if (p->peaks[c][x].min > 0) {
989                                         pmin =  alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].min));
990                                 } else {
991                                         pmin = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].min));
992                                 }
993                                 cr->move_to (m_l + x - .5, height_2 - height_2 * pmax);
994                                 cr->line_to (m_l + x - .5, height_2 - height_2 * pmin);
995                         }
996                         cr->stroke ();
997                 } else {
998                         clip_top = height_2 - height_2 * dB_to_coefficient (-1);
999                         clip_bot = height_2 + height_2 * dB_to_coefficient (-1);
1000                         for (size_t x = 0 ; x < width; ++x) {
1001                                 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
1002                                 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
1003                         }
1004                         cr->stroke ();
1005                 }
1006         }
1007
1008         // > 0dBFS
1009         cr->set_source_rgba (1.0, 0, 0, 1.0);
1010         for (size_t x = 0 ; x < width; ++x) {
1011                 if (p->peaks[c][x].max >= 1.0) {
1012                         cr->move_to (m_l + x - .5, 0);
1013                         cr->line_to (m_l + x - .5, clip_top);
1014                 }
1015                 if (p->peaks[c][x].min <= -1.0) {
1016                         cr->move_to (m_l + x - .5, clip_bot);
1017                         cr->line_to (m_l + x - .5, ht);
1018                 }
1019         }
1020         cr->stroke ();
1021
1022         // > -1dBTP
1023         cr->set_source_rgba (1.0, 0.7, 0, 0.7);
1024         for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
1025                 cr->move_to (m_l + (*i) - .5, clip_top);
1026                 cr->line_to (m_l + (*i) - .5, clip_bot);
1027                 cr->stroke ();
1028         }
1029
1030         if (!rect) {
1031                 // zero line
1032                 cr->set_source_rgba (.3, .3, .3, 0.7);
1033                 cr->move_to (m_l + 0, height_2 - .5);
1034                 cr->line_to (m_l + width, height_2 - .5);
1035                 cr->stroke ();
1036         }
1037
1038         // Unit
1039         layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
1040         layout->set_alignment (Pango::ALIGN_LEFT);
1041         layout->set_text (_("dBFS"));
1042         layout->get_pixel_size (w, h);
1043         cr->move_to (rint (m_l - h - anw - 10), rint (height_2 + w * .5));
1044         cr->set_source_rgba (.9, .9, .9, 1.0);
1045         cr->save ();
1046         cr->rotate (M_PI / -2.0);
1047         layout->show_in_cairo_context (cr);
1048         cr->restore ();
1049
1050         // x-Axis
1051         cr->set_line_width (1.0);
1052         cr->set_dash (dashes, 2.0);
1053         cr->set_line_cap (Cairo::LINE_CAP_ROUND);
1054
1055         layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
1056
1057         if (rect) {
1058                 if (log) {
1059                         XAXISLABEL ((ht - ht * alt_log_meter (-36)), _("-36"));
1060                         XAXISLABEL ((ht - ht * alt_log_meter (-18)), _("-18"));
1061                         XAXISLABEL ((ht - ht * alt_log_meter (-9)), _("-9"));
1062                         XAXISLABEL ((ht - ht * alt_log_meter (-3)), _("-3"));
1063                 } else {
1064                         XAXISLABEL ((ht - ht * .1259), _("-18"));
1065                         XAXISLABEL ((ht - ht * .3548), _("-9"));
1066                         XAXISLABEL ((ht - ht * .7079), _("-3"));
1067                 }
1068         } else {
1069                 if (log) {
1070                         XAXISLABEL ((height_2 - height_2 * alt_log_meter (-18)), _("-18"));
1071                         XAXISLABEL ((height_2 - height_2 * alt_log_meter (-9)), _("-9"));
1072                         XAXISLABEL ((height_2 - height_2 * alt_log_meter (-3)), _("-3"));
1073                         XAXISLABEL ((height_2 + height_2 * alt_log_meter (-18)), _("-18"));
1074                         XAXISLABEL ((height_2 + height_2 * alt_log_meter (-9)), _("-9"));
1075                         XAXISLABEL ((height_2 + height_2 * alt_log_meter (-3)), _("-3"));
1076                 } else {
1077                         XAXISLABEL (height_2 * 0.6452, _("-9"));
1078                         XAXISLABEL (height_2 * 1.3548, _("-9"));
1079                         XAXISLABEL (height_2 * 0.2921, _("-3"));
1080                         XAXISLABEL (height_2 * 1.7079, _("-3"));
1081                 }
1082         }
1083         wave->flush ();
1084 }