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"))
62 init (s->result_map, true);
65 ExportReport::ExportReport (const std::string & title, const AnalysisResults & ar)
66 : ArdourDialog (title)
77 ExportReport::init (const AnalysisResults & ar, bool with_file)
79 set_resizable (false);
80 pages.set_scrollable ();
82 std::vector<double> dashes;
83 dashes.push_back (3.0);
84 dashes.push_back (5.0);
87 for (AnalysisResults::const_iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
89 VBox *vb = manage (new VBox ());
90 Table *t = manage (new Table (4, 4));
91 Table *wtbl = manage (new Table (3, 2));
93 t->set_border_width (0);
95 wtbl->set_spacings (4);
97 vb->set_border_width (4);
98 vb->pack_start (*t, false, false, 2);
99 vb->pack_start (*wtbl, false, false, 2);
101 std::string path = i->first;
102 ExportAnalysisPtr p = i->second;
104 std::list<CimgPlayheadArea*> playhead_widgets;
107 l = manage (new Label (_("File:"), ALIGN_END));
108 t->attach (*l, 0, 1, 0, 1);
109 l = manage (new Label ());
110 l->set_ellipsize (Pango::ELLIPSIZE_START);
111 l->set_width_chars (48);
112 l->set_max_width_chars (48);
114 l->set_alignment (ALIGN_START, ALIGN_CENTER);
115 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
117 Button *b = manage (new Button (_("Open Folder")));
118 t->attach (*b, 3, 4, 0, 2, FILL, SHRINK);
119 b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
125 framecnt_t file_length = 0;
126 framecnt_t sample_rate = 0;
127 framecnt_t start_off = 0;
128 unsigned int channels = 0;
130 if (with_file && AudioFileSource::get_soundfile_info (path, info, errmsg)) {
133 file_length = info.length;
134 sample_rate = info.samplerate;
135 start_off = info.timecode;
136 channels = info.channels;
138 files.insert (std::make_pair (page, AuditionInfo (path, channels)));
140 /* File Info Table */
142 framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
143 double src_coef = (double) nfr / info.samplerate;
145 l = manage (new Label (_("Format:"), ALIGN_END));
146 t->attach (*l, 0, 1, 1, 2);
147 std::string fmt = info.format_name;
148 std::replace (fmt.begin (), fmt.end (), '\n', ' ');
149 l = manage (new Label ());
150 l->set_ellipsize (Pango::ELLIPSIZE_START);
151 l->set_width_chars (48);
152 l->set_max_width_chars (48);
154 l->set_alignment (ALIGN_START, ALIGN_CENTER);
155 t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
157 l = manage (new Label (_("Channels:"), ALIGN_END));
158 t->attach (*l, 0, 1, 2, 3);
159 l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
160 t->attach (*l, 1, 2, 2, 3);
162 l = manage (new Label (_("Sample rate:"), ALIGN_END));
163 t->attach (*l, 0, 1, 3, 4);
164 l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
165 t->attach (*l, 1, 2, 3, 4);
167 l = manage (new Label (_("Duration:"), ALIGN_END));
168 t->attach (*l, 2, 3, 2, 3);
169 clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
170 clock->set_session (_session);
171 clock->set_mode (AudioClock::MinSec);
172 clock->set (info.length * src_coef + 0.5, true);
173 t->attach (*clock, 3, 4, 2, 3);
175 l = manage (new Label (_("Timecode:"), ALIGN_END));
176 t->attach (*l, 2, 3, 3, 4);
177 clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
178 clock->set_session (_session);
179 clock->set_mode (AudioClock::Timecode);
180 clock->set (info.timecode * src_coef + 0.5, true);
181 t->attach (*clock, 3, 4, 3, 4);
182 } else if (with_file) {
183 l = manage (new Label (_("Error:"), ALIGN_END));
184 t->attach (*l, 0, 1, 1, 2);
185 l = manage (new Label (errmsg, ALIGN_START));
186 t->attach (*l, 1, 4, 1, 2);
190 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
192 // calc geometry of numerics
193 const float dbfs = accurate_coefficient_to_dB (p->peak);
194 const float dbtp = accurate_coefficient_to_dB (p->truepeak);
196 #define TXTSIZE(LINE, TXT, FONT) { \
197 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
198 layout->set_text (TXT); \
199 layout->get_pixel_size (w, h); \
200 if (w > mnw) { mnw = w; } \
201 if (h > lin[LINE]) { lin[LINE] = h; } \
204 #define TXTWIDTH(TXT, FONT) { \
205 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
206 layout->set_text (TXT); \
207 layout->get_pixel_size (w, h); \
208 if (w > mml) { mml = w; } \
211 int m_r = 0; // right side
212 int mnh = 0; // mono height
213 int mnw = 0; // max numeric width
214 int anw = 0; // spectrum annotation text width
216 int lin[6] = { 0, 0, 0, 0, 0, 0 }; // max line height
218 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
220 TXTSIZE(0, _("-888"), get_SmallMonospaceFont);
225 TXTSIZE(0, _("Peak:"), get_SmallFont);
226 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
227 TXTSIZE(2, _("True Peak:"), get_SmallFont);
228 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
229 TXTSIZE(4, _("Normalization Gain:"), get_SmallFont);
230 TXTSIZE(5, _("+888.88 dB"), get_SmallMonospaceFont);
232 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
233 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
234 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
235 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
238 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];
239 const int hh = std::max (100, ht + 12);
240 const int htn = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3];
241 int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800 - m_r; // margin left
243 int mml = 0; // min margin left -- ensure left margin is wide enough
244 TXTWIDTH (_("Time"), get_SmallFont);
245 TXTWIDTH (_("100"), get_SmallMonospaceFont);
246 m_l = (std::max(anw + mnh + 14, std::max (m_l, mml + 8)) + 3) & ~3;
248 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800 + m_r) / 2;
249 const int nw2 = mnw / 2; // nums, horizontal center
253 y0[0] = (hh - ht) * .5;
255 y0[0] = (hh - htn) * .5;
257 y0[1] = y0[0] + lin[0] * 1.25;
258 y0[2] = y0[1] + lin[1] * 1.25;
259 y0[3] = y0[2] + lin[2] * 1.25;
260 y0[4] = y0[3] + lin[3] * 1.25;
261 y0[5] = y0[4] + lin[4] * 1.25;
264 { /* peak, loudness and R128 histogram */
265 Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
266 Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
267 Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
269 /* peak and true-peak numerics */
270 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
271 cr->set_source_rgba (0, 0, 0, 1.0);
274 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
275 layout->set_alignment (Pango::ALIGN_LEFT);
276 layout->set_text (_("Peak:"));
277 layout->get_pixel_size (w, h);
278 cr->move_to (rint (nw2 - w * .5), y0[0]);
279 cr->set_source_rgba (.7, .7, .7, 1.0);
280 layout->show_in_cairo_context (cr);
282 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
283 layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
284 layout->get_pixel_size (w, h);
285 cr->move_to (rint (nw2 - w * .5), y0[1]);
286 if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
287 else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
288 layout->show_in_cairo_context (cr);
291 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
292 layout->set_text (_("True Peak:"));
293 layout->get_pixel_size (w, h);
294 cr->move_to (rint (nw2 - w * .5), y0[2]);
295 cr->set_source_rgba (.7, .7, .7, 1.0);
296 layout->show_in_cairo_context (cr);
298 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
299 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
300 layout->get_pixel_size (w, h);
301 cr->move_to (rint (nw2 - w * .5), y0[3]);
302 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
303 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
304 layout->show_in_cairo_context (cr);
308 const float ndb = accurate_coefficient_to_dB (p->norm_gain_factor);
309 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
310 layout->set_text (_("Normalization Gain:"));
311 layout->get_pixel_size (w, h);
312 cr->move_to (rint (nw2 - w * .5), y0[4]);
313 cr->set_source_rgba (.7, .7, .7, 1.0);
314 layout->show_in_cairo_context (cr);
316 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
317 layout->set_text (string_compose (_("%1 dB"), std::setprecision (2), std::showpos, std::fixed, ndb));
319 layout->get_pixel_size (w, h);
320 cr->move_to (rint (nw2 - w * .5), y0[5]);
321 // TODO tweak thresholds
322 if (p->norm_gain_factor < 1.0) {
323 cr->set_source_rgba (1.0, .7, .1, 1.0);
324 } else if (p->norm_gain_factor == 1.0) {
325 cr->set_source_rgba (.7, .7, .7, 1.0);
326 } else if (fabsf (ndb) < 12) {
327 cr->set_source_rgba (.1, 1.0, .1, 1.0);
328 } else if (fabsf (ndb) < 18) {
329 cr->set_source_rgba (1.0, .7, .1, 1.0);
331 cr->set_source_rgba (1.0, .1, .1, 1.0);
333 layout->show_in_cairo_context (cr);
338 /* EBU R128 numerics */
339 cr = Cairo::Context::create (ebur);
340 cr->set_source_rgba (0, 0, 0, 1.0);
343 cr->set_source_rgba (.7, .7, .7, 1.0);
345 if (!i->second->have_loudness) {
346 layout->set_alignment (Pango::ALIGN_CENTER);
347 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
348 layout->set_text (_("Not\nAvailable"));
349 layout->get_pixel_size (w, h);
350 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
351 layout->show_in_cairo_context (cr);
353 else if (p->loudness == -200 && p->loudness_range == 0) {
354 layout->set_alignment (Pango::ALIGN_CENTER);
355 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
356 layout->set_text (_("Not\nAvailable"));
357 layout->get_pixel_size (w, h);
358 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .66));
359 layout->show_in_cairo_context (cr);
362 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
363 layout->set_text (_("(too short integration time)"));
364 layout->get_pixel_size (w, h);
365 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
366 layout->show_in_cairo_context (cr);
369 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
370 layout->set_alignment (Pango::ALIGN_LEFT);
371 layout->set_text (_("Integrated Loudness:"));
372 layout->get_pixel_size (w, h);
373 cr->move_to (rint (nw2 - w * .5), y0[0]);
374 layout->show_in_cairo_context (cr);
376 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
377 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
378 layout->get_pixel_size (w, h);
379 cr->move_to (rint (nw2 - w * .5), y0[1]);
380 layout->show_in_cairo_context (cr);
382 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
383 layout->set_text (_("Loudness Range:"));
384 layout->get_pixel_size (w, h);
385 cr->move_to (rint (nw2 - w * .5), y0[2]);
386 layout->show_in_cairo_context (cr);
388 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
389 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
390 layout->get_pixel_size (w, h);
391 cr->move_to (rint (nw2 - w * .5), y0[3]);
392 layout->show_in_cairo_context (cr);
396 /* draw loudness histogram */
397 cr = Cairo::Context::create (hist);
398 cr->set_source_rgba (0, 0, 0, 1.0);
401 cr->set_source_rgba (.7, .7, .7, 1.0);
402 cr->set_line_width (1.0);
404 if (p->loudness_hist_max > 0 && i->second->have_loudness) {
406 for (size_t x = 0 ; x < 510; ++x) {
407 cr->move_to (x - .5, hh);
408 cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
412 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
413 layout->set_alignment (Pango::ALIGN_CENTER);
416 layout->set_text (_("LUFS\n(short)"));
417 layout->get_pixel_size (w, h);
418 Gtkmm2ext::rounded_rectangle (cr, 5, 5, w + 2, h + 2, 4);
419 cr->set_source_rgba (.1, .1, .1, 0.7);
422 cr->set_source_rgba (.9, .9, .9, 1.0);
423 layout->show_in_cairo_context (cr);
426 layout->set_text (_("Multiplicity"));
427 layout->get_pixel_size (w, h);
428 Gtkmm2ext::rounded_rectangle (cr, 5, hh - w - 3, h + 2, w + 2, 4);
429 cr->set_source_rgba (.1, .1, .1, 0.7);
432 cr->move_to (6, hh - 2);
433 cr->set_source_rgba (.9, .9, .9, 1.0);
434 cr->rotate (M_PI / -2.0);
435 layout->show_in_cairo_context (cr);
439 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
440 layout->set_alignment (Pango::ALIGN_LEFT);
441 for (int g = -53; g <= -8; g += 5) {
442 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
443 layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
444 layout->get_pixel_size (w, h);
446 cr->set_operator (Cairo::OPERATOR_OVER);
447 Gtkmm2ext::rounded_rectangle (cr,
448 rint ((g + 59.0) * 10.0 - h * .5), 5,
450 const float pk = (g + 59.0) / 54.0;
451 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
452 ArdourCanvas::set_source_rgba (cr, c);
456 cr->set_source_rgba (.9, .9, .9, 1.0);
457 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
458 cr->rotate (M_PI / -2.0);
459 layout->show_in_cairo_context (cr);
462 cr->set_operator (Cairo::OPERATOR_ADD);
464 cr->set_source_rgba (.3, .3, .3, 1.0);
465 cr->set_dash (dashes, 1.0);
466 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
467 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
468 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
474 layout->set_alignment (Pango::ALIGN_CENTER);
475 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
476 layout->set_text (_("Not\nAvailable"));
477 layout->get_pixel_size (w, h);
478 cr->move_to (rint ((510 - w) * .5), rint ((hh - h) * .5));
479 layout->show_in_cairo_context (cr);
484 CimgArea *nu = manage (new CimgArea (nums));
485 CimgArea *eb = manage (new CimgArea (ebur));
486 CimgArea *hi = manage (new CimgArea (hist));
487 HBox *hb = manage (new HBox ());
489 hb->pack_start (*nu, false, false);
490 hb->pack_start (*hi, false, false);
491 hb->pack_start (*eb, false, false);
493 wtbl->attach (*hb, 0, 2, wrow, wrow + 1, SHRINK, SHRINK);
497 #define XAXISLABEL(POS, TXT) { \
498 const float yy = rint (POS); \
499 layout->set_text (TXT); \
500 layout->get_pixel_size (w, h); \
501 cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
502 cr->set_source_rgba (.9, .9, .9, 1.0); \
503 cr->set_operator (Cairo::OPERATOR_OVER); \
504 layout->show_in_cairo_context (cr); \
505 cr->move_to (m_l - 4, yy - .5); \
506 cr->line_to (m_l + width, yy - .5); \
507 cr->set_source_rgba (.3, .3, .3, 1.0); \
508 cr->set_operator (Cairo::OPERATOR_ADD); \
514 VBox *lrb = manage (new VBox());
515 ToggleButton *log = manage (new ToggleButton (S_("Logscale|Lg")));
516 ToggleButton *rec = manage (new ToggleButton (S_("Rectified|Rf")));
517 lrb->pack_start (*log, false, false, 5);
518 lrb->pack_end (*rec, false, false, 5);
519 log->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_logscale_toggled), log));
520 rec->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_rectivied_toggled), rec));
522 wtbl->attach (*lrb, 1, 2, wrow, wrow + p->n_channels, SHRINK, SHRINK);
525 for (uint32_t c = 0; c < p->n_channels; ++c) {
527 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
529 Cairo::RefPtr<Cairo::ImageSurface> wave;
530 Cairo::RefPtr<Cairo::ImageSurface> wave_log;
531 Cairo::RefPtr<Cairo::ImageSurface> wave_rect;
532 Cairo::RefPtr<Cairo::ImageSurface> wave_lr;
533 draw_waveform(wave, p, c, m_l, width, anw, lin[0], false, false);
534 draw_waveform(wave_log, p, c, m_l, width, anw, lin[0], true, false);
535 draw_waveform(wave_rect, p, c, m_l, width, anw, lin[0], false, true);
536 draw_waveform(wave_lr, p, c, m_l, width, anw, lin[0], true, true);
538 CimgWaveArea *wv = manage (new CimgWaveArea (wave, wave_log, wave_rect, wave_lr, m_l, width));
540 playhead_widgets.push_back (wv);
541 waves.push_back (wv);
542 wv->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
543 wtbl->attach (*wv, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
547 if (channels > 0 && file_length > 0 && sample_rate > 0)
549 /* Time Axis -- re-use waveform width */
550 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
551 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
552 layout->set_text (_("00:00:00.000"));
553 layout->get_pixel_size (w, h);
554 int height = h * 1.75;
555 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
556 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
557 cr->set_operator (Cairo::OPERATOR_SOURCE);
558 cr->set_source_rgba (0, 0, 0, 1.0);
560 cr->rectangle (0, 0, m_l, height);
561 cr->set_source_rgba (0, 0, 0, 0);
563 cr->set_operator (Cairo::OPERATOR_OVER);
565 cr->set_line_width (1.0);
566 for (int i = 0; i <= 4; ++i) {
567 const float fract = (float) i / 4.0;
568 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
569 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
572 AudioClock::print_minsec (start_off + file_length * fract,
573 buf, sizeof (buf), sample_rate);
575 layout->set_text (buf);
576 layout->get_pixel_size (w, h);
577 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
578 cr->set_source_rgba (.9, .9, .9, 1.0);
579 layout->show_in_cairo_context (cr);
581 cr->set_source_rgba (.7, .7, .7, 1.0);
582 cr->move_to (rint (m_l + width * fract) - .5, 0);
583 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
584 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
585 cr->line_to (rint (m_l + width * fract) - .5, height);
589 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
590 layout->set_text (_("Time"));
591 cr->set_source_rgba (.9, .9, .9, 1.0);
592 layout->get_pixel_size (w, h);
593 cr->move_to (rint (m_l - w - 8), rint (.5 * (height - h)));
594 layout->show_in_cairo_context (cr);
597 CimgPlayheadArea *tm = manage (new CimgPlayheadArea (ytme, m_l, width, true));
598 playhead_widgets.push_back (tm);
599 tm->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
600 wtbl->attach (*tm, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
606 const size_t swh = sizeof (p->spectrum) / sizeof (float);
607 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
608 const size_t width = swh / height;
610 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
611 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
612 cr->set_operator (Cairo::OPERATOR_SOURCE);
613 cr->rectangle (0, 0, m_l, height);
614 cr->set_source_rgba (0, 0, 0, 0);
616 cr->rectangle (m_l, 0, width, height);
617 cr->set_source_rgba (0, 0, 0, 1.0);
619 cr->set_operator (Cairo::OPERATOR_OVER);
621 for (size_t x = 0 ; x < width; ++x) {
622 for (size_t y = 0 ; y < height; ++y) {
623 const float pk = p->spectrum[x][y];
624 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
625 ArdourCanvas::set_source_rgba (cr, c);
626 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
632 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
633 layout->set_text (_("Hz"));
634 layout->get_pixel_size (w, h);
635 cr->move_to (rint (m_l - h - anw - 10), rint ((height + w) * .5));
636 cr->set_source_rgba (.9, .9, .9, 1.0);
638 cr->rotate (M_PI / -2.0);
639 layout->show_in_cairo_context (cr);
643 cr->set_line_width (1.0);
644 cr->set_dash (dashes, 2.0);
645 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
647 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
648 //XAXISLABEL (p->freq[0], _("50Hz"));
649 XAXISLABEL (p->freq[1], _("100"));
650 XAXISLABEL (p->freq[2], _("500"));
651 XAXISLABEL (p->freq[3], _("1K"));
652 XAXISLABEL (p->freq[4], _("5K"));
653 XAXISLABEL (p->freq[5], _("10K"));
657 Cairo::RefPtr<Cairo::ImageSurface> scale = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_r, height);
658 cr = Cairo::Context::create (scale);
659 cr->set_operator (Cairo::OPERATOR_SOURCE);
660 cr->rectangle (0, 0, m_r, height);
661 cr->set_source_rgba (0, 0, 0, 0);
664 cr->set_operator (Cairo::OPERATOR_OVER);
665 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
666 layout->set_alignment (Pango::ALIGN_LEFT);
667 layout->set_text (_("dBFS"));
668 layout->get_pixel_size (w, h);
669 cr->move_to (rint (.5 * (m_r - w)), height - h - 2);
670 cr->set_source_rgba (.9, .9, .9, 1.0);
671 layout->show_in_cairo_context (cr);
673 int innertop = ceil (mnh * .5) + 1;
674 size_t innerheight = (height - 2 * innertop - h - 2);
676 cr->rectangle (1, innertop - 1, m_r - 2 - anw, innerheight + 2);
677 cr->set_source_rgba (0, 0, 0, 1.0);
678 cr->fill_preserve ();
679 cr->set_line_width (1.0);
680 cr->set_source_rgba (.7, .7, .6, 1.0);
683 for (size_t y = 0 ; y < innerheight - 2; ++y) {
684 const float pk = 1.0 - (float) y / innerheight;
685 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
686 ArdourCanvas::set_source_rgba (cr, c);
687 cr->rectangle (2, innertop + y + .5, m_r - 4 - anw, 1);
691 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
692 for (int i = 0; i <= 4; ++i) {
693 const float fract = (float) i / 4.0;
694 const float yalign = .5; // (i == 4) ? 0 : (i == 0) ? 1.0 : .5;
696 snprintf (buf, sizeof (buf), "%.0f", AudioGrapher::Analyser::fft_range_db * -fract);
697 layout->set_text (buf);
698 layout->get_pixel_size (w, h);
700 cr->move_to (m_r - anw, rint (innertop + fract * innerheight - h * yalign));
701 cr->set_source_rgba (.9, .9, .9, 1.0);
702 layout->show_in_cairo_context (cr);
706 CimgPlayheadArea *sp = manage (new CimgPlayheadArea (spec, m_l, width));
707 playhead_widgets.push_back (sp);
708 sp->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
709 CimgArea *an = manage (new CimgArea (scale));
710 wtbl->attach (*sp, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
711 wtbl->attach (*an, 1, 2, wrow, wrow + 1, SHRINK, SHRINK);
715 timeline[page] = playhead_widgets;
717 HBox *tab = manage (new HBox ());
718 l = manage (new Label (Glib::path_get_basename (path)));
719 Gtk::Image *img = manage (new Image (Stock::MEDIA_PLAY, ICON_SIZE_MENU));
720 tab->pack_start (*img);
721 tab->pack_start (*l);
725 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, *tab));
726 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
729 pages.set_show_tabs (true);
731 pages.set_name ("ExportReportNotebook");
732 pages.set_current_page (0);
734 get_vbox ()->set_spacing (4);
735 get_vbox ()->pack_start (pages, false, false);
738 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
739 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
742 if (_session && with_file) {
743 play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
744 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
746 add_button (Stock::CLOSE, RESPONSE_CLOSE);
748 set_default_response (RESPONSE_CLOSE);
749 if (_session && with_file) {
750 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
751 play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
752 stop_btn->set_sensitive (false);
761 int i = ArdourDialog::run ();
762 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
768 _session->cancel_audition();
770 return RESPONSE_CLOSE;
774 ExportReport::open_folder (std::string p)
776 PBD::open_folder (Glib::path_get_dirname(p));
780 ExportReport::audition_active (bool active)
782 if (!stop_btn || !play_btn) {
785 stop_btn->set_sensitive (active);
786 play_btn->set_sensitive (!active);
788 if (!active && _audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
789 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
790 i != timeline[_audition_num].end();
792 (*i)->set_playhead (-1);
796 if (_audition_num >= 0 ) {
797 Widget *page = pages.get_nth_page (_audition_num);
798 HBox *box = static_cast<Gtk::HBox*> (pages.get_tab_label (*page));
800 (*(box->get_children().begin()))->hide ();
802 (*(box->get_children().begin()))->show ();
812 ExportReport::audition (std::string path, unsigned n_chn, int page)
815 _session->cancel_audition();
817 if (n_chn ==0) { return; }
819 /* can't really happen, unless the user replaces the file while the dialog is open.. */
820 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
821 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
824 if (SMFSource::valid_midi_file (path)) { return; }
826 boost::shared_ptr<Region> r;
828 boost::shared_ptr<AudioFileSource> afs;
829 bool old_sbp = AudioSource::get_build_peakfiles ();
831 /* don't even think of building peakfiles for these files */
832 AudioSource::set_build_peakfiles (false);
834 for (unsigned int n = 0; n < n_chn; ++n) {
836 afs = boost::dynamic_pointer_cast<AudioFileSource> (
837 SourceFactory::createExternal (DataType::AUDIO, *_session,
839 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
840 if (afs->sample_rate() != _session->nominal_frame_rate()) {
841 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
842 srclist.push_back(sfs);
844 srclist.push_back(afs);
846 } catch (failed_constructor& err) {
847 PBD::error << _("Could not access soundfile: ") << path << endmsg;
848 AudioSource::set_build_peakfiles (old_sbp);
853 AudioSource::set_build_peakfiles (old_sbp);
855 if (srclist.empty()) {
859 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
860 std::string rname = region_name_from_path (afs->path(), false);
862 PBD::PropertyList plist;
864 plist.add (ARDOUR::Properties::start, 0);
865 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
866 plist.add (ARDOUR::Properties::name, rname);
867 plist.add (ARDOUR::Properties::layer, 0);
869 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
872 _session->audition_region(r);
873 _audition_num = page;
877 ExportReport::play_audition ()
879 if (_audition_num >= 0 || !_session) { return; }
880 if (files.find (_page_num) == files.end()) { return; }
881 audition (files[_page_num].path, files[_page_num].channels, _page_num);
885 ExportReport::stop_audition ()
887 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
888 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
889 i != timeline[_audition_num].end();
891 (*i)->set_playhead (-1);
895 _session->cancel_audition();
900 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
902 if (_audition_num == _page_num) {
903 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
904 i != timeline[_audition_num].end();
906 (*i)->set_playhead (-1);
909 _page_num = page_num;
913 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
915 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
916 const float p = (float)pos / len;
917 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
918 i != timeline[_audition_num].end();
920 (*i)->set_playhead (p);
926 ExportReport::audition_seek (int page, float pos)
928 if (_audition_num == page && _session) {
929 _session->the_auditioner()->seek_to_percent (100.f * pos);
934 ExportReport::on_logscale_toggled (Gtk::ToggleButton* b)
936 bool en = b->get_active ();
937 for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
938 (*i)->set_logscale (en);
943 ExportReport::on_rectivied_toggled (Gtk::ToggleButton* b)
945 bool en = b->get_active ();
946 for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
947 (*i)->set_rectified (en);
952 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)
955 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
956 const float height_2 = std::min (100, 8 * height / (int) p->n_channels); // TODO refine
957 const float ht = 2.f * height_2;
959 std::vector<double> dashes;
960 dashes.push_back (3.0);
961 dashes.push_back (5.0);
963 wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, ht);
964 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
965 cr->set_operator (Cairo::OPERATOR_SOURCE);
966 cr->rectangle (0, 0, m_l, ht);
967 cr->set_source_rgba (0, 0, 0, 0);
969 cr->rectangle (m_l, 0, width, ht);
970 cr->set_source_rgba (0, 0, 0, 1.0);
972 cr->set_operator (Cairo::OPERATOR_OVER);
974 cr->set_source_rgba (.7, .7, .7, 1.0);
975 cr->set_line_width (1.0);
985 clip_top = ht * (1.f - alt_log_meter (-1));
986 for (size_t x = 0 ; x < width; ++x) {
987 const float v = alt_log_meter (fast_coefficient_to_dB (std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min))));
988 cr->move_to (m_l + x - .5, ht - ht * v);
989 cr->line_to (m_l + x - .5, ht);
993 clip_top = ht * (1.f - dB_to_coefficient (-1));
994 for (size_t x = 0 ; x < width; ++x) {
995 const float v = std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min));
996 cr->move_to (m_l + x - .5, ht - ht * v);
997 cr->line_to (m_l + x - .5, ht);
1003 clip_top = height_2 - height_2 * alt_log_meter (-1);
1004 clip_bot = height_2 + height_2 * alt_log_meter (-1);
1005 for (size_t x = 0 ; x < width; ++x) {
1007 if (p->peaks[c][x].max > 0) {
1008 pmax = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].max));
1010 pmax = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].max));
1013 if (p->peaks[c][x].min > 0) {
1014 pmin = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].min));
1016 pmin = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].min));
1018 cr->move_to (m_l + x - .5, height_2 - height_2 * pmax);
1019 cr->line_to (m_l + x - .5, height_2 - height_2 * pmin);
1023 clip_top = height_2 - height_2 * dB_to_coefficient (-1);
1024 clip_bot = height_2 + height_2 * dB_to_coefficient (-1);
1025 for (size_t x = 0 ; x < width; ++x) {
1026 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
1027 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
1034 cr->set_source_rgba (1.0, 0, 0, 1.0);
1035 for (size_t x = 0 ; x < width; ++x) {
1036 if (p->peaks[c][x].max >= 1.0) {
1037 cr->move_to (m_l + x - .5, 0);
1038 cr->line_to (m_l + x - .5, clip_top);
1040 if (p->peaks[c][x].min <= -1.0) {
1041 cr->move_to (m_l + x - .5, clip_bot);
1042 cr->line_to (m_l + x - .5, ht);
1048 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
1049 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
1050 cr->move_to (m_l + (*i) - .5, clip_top);
1051 cr->line_to (m_l + (*i) - .5, clip_bot);
1057 cr->set_source_rgba (.3, .3, .3, 0.7);
1058 cr->move_to (m_l + 0, height_2 - .5);
1059 cr->line_to (m_l + width, height_2 - .5);
1064 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
1065 layout->set_alignment (Pango::ALIGN_LEFT);
1066 layout->set_text (_("dBFS"));
1067 layout->get_pixel_size (w, h);
1068 cr->move_to (rint (m_l - h - anw - 10), rint (height_2 + w * .5));
1069 cr->set_source_rgba (.9, .9, .9, 1.0);
1071 cr->rotate (M_PI / -2.0);
1072 layout->show_in_cairo_context (cr);
1076 cr->set_line_width (1.0);
1077 cr->set_dash (dashes, 2.0);
1078 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
1080 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
1084 XAXISLABEL ((ht - ht * alt_log_meter (-36)), _("-36"));
1085 XAXISLABEL ((ht - ht * alt_log_meter (-18)), _("-18"));
1086 XAXISLABEL ((ht - ht * alt_log_meter (-9)), _("-9"));
1087 XAXISLABEL ((ht - ht * alt_log_meter (-3)), _("-3"));
1089 XAXISLABEL ((ht - ht * .1259), _("-18"));
1090 XAXISLABEL ((ht - ht * .3548), _("-9"));
1091 XAXISLABEL ((ht - ht * .7079), _("-3"));
1095 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-18)), _("-18"));
1096 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-9)), _("-9"));
1097 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-3)), _("-3"));
1098 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-18)), _("-18"));
1099 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-9)), _("-9"));
1100 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-3)), _("-3"));
1102 XAXISLABEL (height_2 * 0.6452, _("-9"));
1103 XAXISLABEL (height_2 * 1.3548, _("-9"));
1104 XAXISLABEL (height_2 * 0.2921, _("-3"));
1105 XAXISLABEL (height_2 * 1.7079, _("-3"));