2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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.
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.
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.
21 #include <pangomm/layout.h>
22 #include <gtkmm/label.h>
23 #include <gtkmm/table.h>
24 #include <gtkmm/stock.h>
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"
32 #include "audiographer/general/analyser.h"
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"
44 #include "audio_clock.h"
45 #include "export_report.h"
47 #include "ui_config.h"
52 using namespace ARDOUR;
54 ExportReport::ExportReport (Session* session, StatusPtr s)
55 : ArdourDialog (_("Export Report/Analysis"))
61 set_resizable (false);
62 pages.set_scrollable ();
64 AnalysisResults & ar = status->result_map;
66 std::vector<double> dashes;
67 dashes.push_back (3.0);
68 dashes.push_back (5.0);
71 for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
73 VBox *vb = manage (new VBox ());
74 Table *t = manage (new Table (4, 4));
75 Table *wtbl = manage (new Table (3, 2));
77 t->set_border_width (0);
79 wtbl->set_spacings (4);
81 vb->set_border_width (4);
82 vb->pack_start (*t, false, false, 2);
83 vb->pack_start (*wtbl, false, false, 2);
85 std::string path = i->first;
86 ExportAnalysisPtr p = i->second;
88 std::list<CimgPlayheadArea*> playhead_widgets;
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);
97 l->set_alignment (ALIGN_START, ALIGN_CENTER);
98 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
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));
107 framecnt_t file_length = 0;
108 framecnt_t sample_rate = 0;
109 framecnt_t start_off = 0;
110 unsigned int channels = 0;
112 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
115 file_length = info.length;
116 sample_rate = info.samplerate;
117 start_off = info.timecode;
118 channels = info.channels;
120 files.insert (std::make_pair (page, AuditionInfo (path, channels)));
122 /* File Info Table */
124 framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
125 double src_coef = (double) nfr / info.samplerate;
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);
136 l->set_alignment (ALIGN_START, ALIGN_CENTER);
137 t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
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);
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);
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);
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);
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);
172 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
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);
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; } \
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; } \
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
198 int lin[4] = { 0, 0, 0, 0 }; // max line height
200 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
202 TXTSIZE(0, _("-88"), get_SmallMonospaceFont);
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);
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);
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
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;
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
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;
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);
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);
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);
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);
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);
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);
282 /* EBU R128 numerics */
283 cr = Cairo::Context::create (ebur);
284 cr->set_source_rgba (0, 0, 0, 1.0);
287 cr->set_source_rgba (.7, .7, .7, 1.0);
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);
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);
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);
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);
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);
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);
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);
340 /* draw loudness histogram */
341 cr = Cairo::Context::create (hist);
342 cr->set_source_rgba (0, 0, 0, 1.0);
345 cr->set_source_rgba (.7, .7, .7, 1.0);
346 cr->set_line_width (1.0);
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));
355 // TODO print "Not Avail"
358 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
359 layout->set_alignment (Pango::ALIGN_CENTER);
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);
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);
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);
382 cr->set_operator (Cairo::OPERATOR_OVER);
383 Gtkmm2ext::rounded_rectangle (cr,
384 rint ((g + 59.0) * 10.0 - h * .5), 5,
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);
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);
398 cr->set_operator (Cairo::OPERATOR_ADD);
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);
409 // add normalization gain factor here (for want of a better place)
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, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
419 cr->set_source_rgba (.1, .1, .1, 0.7);
421 cr->set_source_rgba (.3, .7, .3, 1.0);
422 cr->move_to (6, hh - h - 2);
423 layout->show_in_cairo_context (cr);
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 ());
433 hb->pack_start (*nu, false, false);
434 hb->pack_start (*hi, false, false);
435 hb->pack_start (*eb, false, false);
437 wtbl->attach (*hb, 0, 2, wrow, wrow + 1, SHRINK, SHRINK);
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); \
456 for (uint32_t c = 0; c < p->n_channels; ++c) {
458 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
460 Cairo::RefPtr<Cairo::ImageSurface> wave;
461 Cairo::RefPtr<Cairo::ImageSurface> wave_log;
462 Cairo::RefPtr<Cairo::ImageSurface> wave_rect;
463 Cairo::RefPtr<Cairo::ImageSurface> wave_lr;
464 draw_waveform(wave, p, c, m_l, width, anw, lin[0], false, false);
465 draw_waveform(wave_log, p, c, m_l, width, anw, lin[0], true, false);
466 draw_waveform(wave_rect, p, c, m_l, width, anw, lin[0], false, true);
467 draw_waveform(wave_lr, p, c, m_l, width, anw, lin[0], true, true);
469 CimgWaveArea *wv = manage (new CimgWaveArea (wave, wave_log, wave_rect, wave_lr, m_l, width));
471 playhead_widgets.push_back (wv);
472 wv->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
474 VBox *lrb = manage (new VBox());
475 ToggleButton *log = manage (new ToggleButton (S_("Logscale|L")));
476 ToggleButton *rec = manage (new ToggleButton (S_("Rectified|R")));
477 lrb->pack_start (*log, false, false, 5);
478 lrb->pack_end (*rec, false, false, 5);
479 log->signal_toggled ().connect (sigc::bind (sigc::mem_fun (wv, &CimgWaveArea::set_logscale), log));
480 rec->signal_toggled ().connect (sigc::bind (sigc::mem_fun (wv, &CimgWaveArea::set_rectified), rec));
483 wtbl->attach (*wv, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
484 wtbl->attach (*lrb, 1, 2, wrow, wrow + 1, SHRINK, SHRINK);
488 if (channels > 0 && file_length > 0 && sample_rate > 0)
490 /* Time Axis -- re-use waveform width */
491 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
492 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
493 layout->set_text (_("00:00:00.000"));
494 layout->get_pixel_size (w, h);
495 int height = h * 1.75;
496 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
497 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
498 cr->set_operator (Cairo::OPERATOR_SOURCE);
499 cr->set_source_rgba (0, 0, 0, 1.0);
501 cr->rectangle (0, 0, m_l, height);
502 cr->set_source_rgba (0, 0, 0, 0);
504 cr->set_operator (Cairo::OPERATOR_OVER);
506 cr->set_line_width (1.0);
507 for (int i = 0; i <= 4; ++i) {
508 const float fract = (float) i / 4.0;
509 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
510 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
513 AudioClock::print_minsec (start_off + file_length * fract,
514 buf, sizeof (buf), sample_rate);
516 layout->set_text (buf);
517 layout->get_pixel_size (w, h);
518 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
519 cr->set_source_rgba (.9, .9, .9, 1.0);
520 layout->show_in_cairo_context (cr);
522 cr->set_source_rgba (.7, .7, .7, 1.0);
523 cr->move_to (rint (m_l + width * fract) - .5, 0);
524 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
525 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
526 cr->line_to (rint (m_l + width * fract) - .5, height);
530 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
531 layout->set_text (_("Time"));
532 cr->set_source_rgba (.9, .9, .9, 1.0);
533 layout->get_pixel_size (w, h);
534 cr->move_to (rint (m_l - w - anw - 2), rint (.5 * (height - h)));
535 layout->show_in_cairo_context (cr);
538 CimgPlayheadArea *tm = manage (new CimgPlayheadArea (ytme, m_l, width, true));
539 playhead_widgets.push_back (tm);
540 tm->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
541 wtbl->attach (*tm, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
547 const size_t swh = sizeof (p->spectrum) / sizeof (float);
548 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
549 const size_t width = swh / height;
551 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
552 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
553 cr->set_operator (Cairo::OPERATOR_SOURCE);
554 cr->rectangle (0, 0, m_l, height);
555 cr->set_source_rgba (0, 0, 0, 0);
557 cr->rectangle (m_l, 0, width, height);
558 cr->set_source_rgba (0, 0, 0, 1.0);
560 cr->set_operator (Cairo::OPERATOR_OVER);
562 for (size_t x = 0 ; x < width; ++x) {
563 for (size_t y = 0 ; y < height; ++y) {
564 const float pk = p->spectrum[x][y];
565 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
566 ArdourCanvas::set_source_rgba (cr, c);
567 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
573 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
574 layout->set_text (_("Hz"));
575 layout->get_pixel_size (w, h);
576 cr->move_to (rint (m_l - h - anw - 2), rint ((height + w) * .5));
577 cr->set_source_rgba (.9, .9, .9, 1.0);
579 cr->rotate (M_PI / -2.0);
580 layout->show_in_cairo_context (cr);
584 cr->set_line_width (1.0);
585 cr->set_dash (dashes, 2.0);
586 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
588 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
589 //XAXISLABEL (p->freq[0], _("50Hz"));
590 XAXISLABEL (p->freq[1], _("100"));
591 XAXISLABEL (p->freq[2], _("500"));
592 XAXISLABEL (p->freq[3], _("1K"));
593 XAXISLABEL (p->freq[4], _("5K"));
594 XAXISLABEL (p->freq[5], _("10K"));
598 Cairo::RefPtr<Cairo::ImageSurface> scale = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_r, height);
599 cr = Cairo::Context::create (scale);
600 cr->set_operator (Cairo::OPERATOR_SOURCE);
601 cr->rectangle (0, 0, m_r, height);
602 cr->set_source_rgba (0, 0, 0, 0);
605 cr->set_operator (Cairo::OPERATOR_OVER);
606 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
607 layout->set_alignment (Pango::ALIGN_LEFT);
608 layout->set_text (_("dBFS"));
609 layout->get_pixel_size (w, h);
610 cr->move_to (rint (.5 * (m_r - w)), height - h - 2);
611 cr->set_source_rgba (.9, .9, .9, 1.0);
612 layout->show_in_cairo_context (cr);
614 int innertop = ceil (mnh * .5) + 1;
615 size_t innerheight = (height - 2 * innertop - h - 2);
617 cr->rectangle (1, innertop - 1, m_r - 2 - anw, innerheight + 2);
618 cr->set_source_rgba (0, 0, 0, 1.0);
619 cr->fill_preserve ();
620 cr->set_line_width (1.0);
621 cr->set_source_rgba (.7, .7, .6, 1.0);
624 for (size_t y = 0 ; y < innerheight - 2; ++y) {
625 const float pk = 1.0 - (float) y / innerheight;
626 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
627 ArdourCanvas::set_source_rgba (cr, c);
628 cr->rectangle (2, innertop + y + .5, m_r - 4 - anw, 1);
632 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
633 for (int i = 0; i <= 4; ++i) {
634 const float fract = (float) i / 4.0;
635 const float yalign = .5; // (i == 4) ? 0 : (i == 0) ? 1.0 : .5;
637 snprintf (buf, sizeof (buf), "%.0f", AudioGrapher::Analyser::fft_range_db * -fract);
638 layout->set_text (buf);
639 layout->get_pixel_size (w, h);
641 cr->move_to (m_r - anw, rint (innertop + fract * innerheight - h * yalign));
642 cr->set_source_rgba (.9, .9, .9, 1.0);
643 layout->show_in_cairo_context (cr);
647 CimgPlayheadArea *sp = manage (new CimgPlayheadArea (spec, m_l, width));
648 playhead_widgets.push_back (sp);
649 sp->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
650 CimgArea *an = manage (new CimgArea (scale));
651 wtbl->attach (*sp, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
652 wtbl->attach (*an, 1, 2, wrow, wrow + 1, SHRINK, SHRINK);
656 timeline[page] = playhead_widgets;
658 HBox *tab = manage (new HBox ());
659 l = manage (new Label (Glib::path_get_basename (path)));
660 Gtk::Image *img = manage (new Image (Stock::MEDIA_PLAY, ICON_SIZE_MENU));
661 tab->pack_start (*img);
662 tab->pack_start (*l);
666 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, *tab));
667 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
670 pages.set_show_tabs (true);
672 pages.set_name ("ExportReportNotebook");
673 pages.set_current_page (0);
675 get_vbox ()->set_spacing (4);
676 get_vbox ()->pack_start (pages, false, false);
679 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
680 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
683 play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
684 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
685 add_button (Stock::CLOSE, RESPONSE_CLOSE);
687 set_default_response (RESPONSE_CLOSE);
688 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
689 play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
690 stop_btn->set_sensitive (false);
698 int i = ArdourDialog::run ();
699 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
705 _session->cancel_audition();
707 return RESPONSE_CLOSE;
711 ExportReport::open_folder (std::string p)
713 PBD::open_uri (Glib::path_get_dirname(p));
717 ExportReport::audition_active (bool active)
719 stop_btn->set_sensitive (active);
720 play_btn->set_sensitive (!active);
722 if (!active && _audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
723 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
724 i != timeline[_audition_num].end();
726 (*i)->set_playhead (-1);
730 if (_audition_num >= 0 ) {
731 Widget *page = pages.get_nth_page (_audition_num);
732 HBox *box = static_cast<Gtk::HBox*> (pages.get_tab_label (*page));
734 (*(box->get_children().begin()))->hide ();
736 (*(box->get_children().begin()))->show ();
746 ExportReport::audition (std::string path, unsigned n_chn, int page)
749 _session->cancel_audition();
751 if (n_chn ==0) { return; }
753 /* can't really happen, unless the user replaces the file while the dialog is open.. */
754 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
755 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
758 if (SMFSource::valid_midi_file (path)) { return; }
760 boost::shared_ptr<Region> r;
762 boost::shared_ptr<AudioFileSource> afs;
763 bool old_sbp = AudioSource::get_build_peakfiles ();
765 /* don't even think of building peakfiles for these files */
766 AudioSource::set_build_peakfiles (false);
768 for (unsigned int n = 0; n < n_chn; ++n) {
770 afs = boost::dynamic_pointer_cast<AudioFileSource> (
771 SourceFactory::createExternal (DataType::AUDIO, *_session,
773 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
774 if (afs->sample_rate() != _session->nominal_frame_rate()) {
775 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
776 srclist.push_back(sfs);
778 srclist.push_back(afs);
780 } catch (failed_constructor& err) {
781 PBD::error << _("Could not access soundfile: ") << path << endmsg;
782 AudioSource::set_build_peakfiles (old_sbp);
787 AudioSource::set_build_peakfiles (old_sbp);
789 if (srclist.empty()) {
793 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
794 std::string rname = region_name_from_path (afs->path(), false);
796 PBD::PropertyList plist;
798 plist.add (ARDOUR::Properties::start, 0);
799 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
800 plist.add (ARDOUR::Properties::name, rname);
801 plist.add (ARDOUR::Properties::layer, 0);
803 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
806 _session->audition_region(r);
807 _audition_num = page;
811 ExportReport::play_audition ()
813 if (_audition_num >= 0 || !_session) { return; }
814 if (files.find (_page_num) == files.end()) { return; }
815 audition (files[_page_num].path, files[_page_num].channels, _page_num);
819 ExportReport::stop_audition ()
821 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
822 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
823 i != timeline[_audition_num].end();
825 (*i)->set_playhead (-1);
829 _session->cancel_audition();
834 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
836 if (_audition_num == _page_num) {
837 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
838 i != timeline[_audition_num].end();
840 (*i)->set_playhead (-1);
843 _page_num = page_num;
847 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
849 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
850 const float p = (float)pos / len;
851 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
852 i != timeline[_audition_num].end();
854 (*i)->set_playhead (p);
860 ExportReport::audition_seek (int page, float pos)
862 if (_audition_num == page && _session) {
863 _session->the_auditioner()->seek_to_percent (100.f * pos);
868 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)
871 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
872 const float height_2 = std::min (100, 8 * height / (int) p->n_channels); // TODO refine
873 const float ht = 2.f * height_2;
875 std::vector<double> dashes;
876 dashes.push_back (3.0);
877 dashes.push_back (5.0);
879 wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, ht);
880 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
881 cr->set_operator (Cairo::OPERATOR_SOURCE);
882 cr->rectangle (0, 0, m_l, ht);
883 cr->set_source_rgba (0, 0, 0, 0);
885 cr->rectangle (m_l, 0, width, ht);
886 cr->set_source_rgba (0, 0, 0, 1.0);
888 cr->set_operator (Cairo::OPERATOR_OVER);
890 cr->set_source_rgba (.7, .7, .7, 1.0);
891 cr->set_line_width (1.0);
901 clip_top = ht * (1.f - alt_log_meter (-1));
902 for (size_t x = 0 ; x < width; ++x) {
903 const float v = alt_log_meter (fast_coefficient_to_dB (std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min))));
904 cr->move_to (m_l + x - .5, ht - ht * v);
905 cr->line_to (m_l + x - .5, ht);
909 clip_top = ht * (1.f - dB_to_coefficient (-1));
910 for (size_t x = 0 ; x < width; ++x) {
911 const float v = std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min));
912 cr->move_to (m_l + x - .5, ht - ht * v);
913 cr->line_to (m_l + x - .5, ht);
919 clip_top = height_2 - height_2 * alt_log_meter (-1);
920 clip_bot = height_2 + height_2 * alt_log_meter (-1);
921 for (size_t x = 0 ; x < width; ++x) {
923 if (p->peaks[c][x].max > 0) {
924 pmax = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].max));
926 pmax = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].max));
929 if (p->peaks[c][x].min > 0) {
930 pmin = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].min));
932 pmin = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].min));
934 cr->move_to (m_l + x - .5, height_2 - height_2 * pmax);
935 cr->line_to (m_l + x - .5, height_2 - height_2 * pmin);
939 clip_top = height_2 - height_2 * dB_to_coefficient (-1);
940 clip_bot = height_2 + height_2 * dB_to_coefficient (-1);
941 for (size_t x = 0 ; x < width; ++x) {
942 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
943 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
950 cr->set_source_rgba (1.0, 0, 0, 1.0);
951 for (size_t x = 0 ; x < width; ++x) {
952 if (p->peaks[c][x].max >= 1.0) {
953 cr->move_to (m_l + x - .5, 0);
954 cr->line_to (m_l + x - .5, clip_top);
956 if (p->peaks[c][x].min <= -1.0) {
957 cr->move_to (m_l + x - .5, clip_bot);
958 cr->line_to (m_l + x - .5, ht);
964 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
965 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
966 cr->move_to (m_l + (*i) - .5, clip_top);
967 cr->line_to (m_l + (*i) - .5, clip_bot);
973 cr->set_source_rgba (.3, .3, .3, 0.7);
974 cr->move_to (m_l + 0, height_2 - .5);
975 cr->line_to (m_l + width, height_2 - .5);
980 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
981 layout->set_alignment (Pango::ALIGN_LEFT);
982 layout->set_text (_("dBFS"));
983 layout->get_pixel_size (w, h);
984 cr->move_to (rint (m_l - h - anw - 10), rint (height_2 + w * .5));
985 cr->set_source_rgba (.9, .9, .9, 1.0);
987 cr->rotate (M_PI / -2.0);
988 layout->show_in_cairo_context (cr);
992 cr->set_line_width (1.0);
993 cr->set_dash (dashes, 2.0);
994 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
996 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
1000 XAXISLABEL ((ht - ht * alt_log_meter (-36)), _("-36"));
1001 XAXISLABEL ((ht - ht * alt_log_meter (-18)), _("-18"));
1002 XAXISLABEL ((ht - ht * alt_log_meter (-9)), _("-9"));
1003 XAXISLABEL ((ht - ht * alt_log_meter (-3)), _("-3"));
1005 XAXISLABEL ((ht - ht * .1259), _("-18"));
1006 XAXISLABEL ((ht - ht * .3548), _("-9"));
1007 XAXISLABEL ((ht - ht * .7079), _("-3"));
1011 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-18)), _("-18"));
1012 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-9)), _("-9"));
1013 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-3)), _("-3"));
1014 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-18)), _("-18"));
1015 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-9)), _("-9"));
1016 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-3)), _("-3"));
1018 XAXISLABEL (height_2 * 0.6452, _("-9"));
1019 XAXISLABEL (height_2 * 1.3548, _("-9"));
1020 XAXISLABEL (height_2 * 0.2921, _("-3"));
1021 XAXISLABEL (height_2 * 1.7079, _("-3"));