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