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[6] = { 0, 0, 0, 0, 0, 0 }; // max line height
200 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
202 TXTSIZE(0, _("-888"), 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);
211 TXTSIZE(4, _("Normalization Gain:"), get_SmallFont);
212 TXTSIZE(5, _("+888.88 dB"), get_SmallMonospaceFont);
214 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
215 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
216 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
217 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
220 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] *1.25 + lin[4] * 1.25 + lin[5];
221 const int hh = std::max (100, ht + 12);
222 const int htn = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3];
223 int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800 - m_r; // margin left
225 int mml = 0; // min margin left -- ensure left margin is wide enough
226 TXTWIDTH (_("Time"), get_SmallFont);
227 TXTWIDTH (_("100"), get_SmallMonospaceFont);
228 m_l = (std::max(anw + mnh + 14, std::max (m_l, mml + 8)) + 3) & ~3;
230 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800 + m_r) / 2;
231 const int nw2 = mnw / 2; // nums, horizontal center
235 y0[0] = (hh - ht) * .5;
237 y0[0] = (hh - htn) * .5;
239 y0[1] = y0[0] + lin[0] * 1.25;
240 y0[2] = y0[1] + lin[1] * 1.25;
241 y0[3] = y0[2] + lin[2] * 1.25;
242 y0[4] = y0[3] + lin[3] * 1.25;
243 y0[5] = y0[4] + lin[4] * 1.25;
246 { /* peak, loudness and R128 histogram */
247 Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
248 Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
249 Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
251 /* peak and true-peak numerics */
252 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
253 cr->set_source_rgba (0, 0, 0, 1.0);
256 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
257 layout->set_alignment (Pango::ALIGN_LEFT);
258 layout->set_text (_("Peak:"));
259 layout->get_pixel_size (w, h);
260 cr->move_to (rint (nw2 - w * .5), y0[0]);
261 cr->set_source_rgba (.7, .7, .7, 1.0);
262 layout->show_in_cairo_context (cr);
264 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
265 layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
266 layout->get_pixel_size (w, h);
267 cr->move_to (rint (nw2 - w * .5), y0[1]);
268 if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
269 else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
270 layout->show_in_cairo_context (cr);
273 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
274 layout->set_text (_("True Peak:"));
275 layout->get_pixel_size (w, h);
276 cr->move_to (rint (nw2 - w * .5), y0[2]);
277 cr->set_source_rgba (.7, .7, .7, 1.0);
278 layout->show_in_cairo_context (cr);
280 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
281 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
282 layout->get_pixel_size (w, h);
283 cr->move_to (rint (nw2 - w * .5), y0[3]);
284 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
285 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
286 layout->show_in_cairo_context (cr);
290 const float ndb = accurate_coefficient_to_dB (p->norm_gain_factor);
291 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
292 layout->set_text (_("Normalization Gain:"));
293 layout->get_pixel_size (w, h);
294 cr->move_to (rint (nw2 - w * .5), y0[4]);
295 cr->set_source_rgba (.7, .7, .7, 1.0);
296 layout->show_in_cairo_context (cr);
298 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
299 layout->set_text (string_compose (_("%1 dB"), std::setprecision (2), std::showpos, std::fixed, ndb));
301 layout->get_pixel_size (w, h);
302 cr->move_to (rint (nw2 - w * .5), y0[5]);
303 // TODO tweak thresholds
304 if (p->norm_gain_factor < 1.0) {
305 cr->set_source_rgba (1.0, .7, .1, 1.0);
306 } else if (p->norm_gain_factor == 1.0) {
307 cr->set_source_rgba (.7, .7, .7, 1.0);
308 } else if (fabsf (ndb) < 12) {
309 cr->set_source_rgba (.1, 1.0, .1, 1.0);
310 } else if (fabsf (ndb) < 18) {
311 cr->set_source_rgba (1.0, .7, .1, 1.0);
313 cr->set_source_rgba (1.0, .1, .1, 1.0);
315 layout->show_in_cairo_context (cr);
320 /* EBU R128 numerics */
321 cr = Cairo::Context::create (ebur);
322 cr->set_source_rgba (0, 0, 0, 1.0);
325 cr->set_source_rgba (.7, .7, .7, 1.0);
327 if (!i->second->have_loudness) {
328 layout->set_alignment (Pango::ALIGN_CENTER);
329 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
330 layout->set_text (_("Not\nAvailable"));
331 layout->get_pixel_size (w, h);
332 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
333 layout->show_in_cairo_context (cr);
335 else if (p->loudness == -200 && p->loudness_range == 0) {
336 layout->set_alignment (Pango::ALIGN_CENTER);
337 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
338 layout->set_text (_("Not\nAvailable"));
339 layout->get_pixel_size (w, h);
340 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .66));
341 layout->show_in_cairo_context (cr);
344 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
345 layout->set_text (_("(too short integration time)"));
346 layout->get_pixel_size (w, h);
347 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
348 layout->show_in_cairo_context (cr);
351 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
352 layout->set_alignment (Pango::ALIGN_LEFT);
353 layout->set_text (_("Integrated Loudness:"));
354 layout->get_pixel_size (w, h);
355 cr->move_to (rint (nw2 - w * .5), y0[0]);
356 layout->show_in_cairo_context (cr);
358 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
359 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
360 layout->get_pixel_size (w, h);
361 cr->move_to (rint (nw2 - w * .5), y0[1]);
362 layout->show_in_cairo_context (cr);
364 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
365 layout->set_text (_("Loudness Range:"));
366 layout->get_pixel_size (w, h);
367 cr->move_to (rint (nw2 - w * .5), y0[2]);
368 layout->show_in_cairo_context (cr);
370 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
371 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
372 layout->get_pixel_size (w, h);
373 cr->move_to (rint (nw2 - w * .5), y0[3]);
374 layout->show_in_cairo_context (cr);
378 /* draw loudness histogram */
379 cr = Cairo::Context::create (hist);
380 cr->set_source_rgba (0, 0, 0, 1.0);
383 cr->set_source_rgba (.7, .7, .7, 1.0);
384 cr->set_line_width (1.0);
386 if (p->loudness_hist_max > 0 && i->second->have_loudness) {
388 for (size_t x = 0 ; x < 510; ++x) {
389 cr->move_to (x - .5, hh);
390 cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
394 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
395 layout->set_alignment (Pango::ALIGN_CENTER);
398 layout->set_text (_("LUFS\n(short)"));
399 layout->get_pixel_size (w, h);
400 Gtkmm2ext::rounded_rectangle (cr, 5, 5, w + 2, h + 2, 4);
401 cr->set_source_rgba (.1, .1, .1, 0.7);
404 cr->set_source_rgba (.9, .9, .9, 1.0);
405 layout->show_in_cairo_context (cr);
408 layout->set_text (_("Multiplicity"));
409 layout->get_pixel_size (w, h);
410 Gtkmm2ext::rounded_rectangle (cr, 5, hh - w - 3, h + 2, w + 2, 4);
411 cr->set_source_rgba (.1, .1, .1, 0.7);
414 cr->move_to (6, hh - 2);
415 cr->set_source_rgba (.9, .9, .9, 1.0);
416 cr->rotate (M_PI / -2.0);
417 layout->show_in_cairo_context (cr);
421 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
422 layout->set_alignment (Pango::ALIGN_LEFT);
423 for (int g = -53; g <= -8; g += 5) {
424 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
425 layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
426 layout->get_pixel_size (w, h);
428 cr->set_operator (Cairo::OPERATOR_OVER);
429 Gtkmm2ext::rounded_rectangle (cr,
430 rint ((g + 59.0) * 10.0 - h * .5), 5,
432 const float pk = (g + 59.0) / 54.0;
433 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
434 ArdourCanvas::set_source_rgba (cr, c);
438 cr->set_source_rgba (.9, .9, .9, 1.0);
439 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
440 cr->rotate (M_PI / -2.0);
441 layout->show_in_cairo_context (cr);
444 cr->set_operator (Cairo::OPERATOR_ADD);
446 cr->set_source_rgba (.3, .3, .3, 1.0);
447 cr->set_dash (dashes, 1.0);
448 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
449 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
450 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
456 layout->set_alignment (Pango::ALIGN_CENTER);
457 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
458 layout->set_text (_("Not\nAvailable"));
459 layout->get_pixel_size (w, h);
460 cr->move_to (rint ((510 - w) * .5), rint ((hh - h) * .5));
461 layout->show_in_cairo_context (cr);
466 CimgArea *nu = manage (new CimgArea (nums));
467 CimgArea *eb = manage (new CimgArea (ebur));
468 CimgArea *hi = manage (new CimgArea (hist));
469 HBox *hb = manage (new HBox ());
471 hb->pack_start (*nu, false, false);
472 hb->pack_start (*hi, false, false);
473 hb->pack_start (*eb, false, false);
475 wtbl->attach (*hb, 0, 2, wrow, wrow + 1, SHRINK, SHRINK);
479 #define XAXISLABEL(POS, TXT) { \
480 const float yy = rint (POS); \
481 layout->set_text (TXT); \
482 layout->get_pixel_size (w, h); \
483 cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
484 cr->set_source_rgba (.9, .9, .9, 1.0); \
485 cr->set_operator (Cairo::OPERATOR_OVER); \
486 layout->show_in_cairo_context (cr); \
487 cr->move_to (m_l - 4, yy - .5); \
488 cr->line_to (m_l + width, yy - .5); \
489 cr->set_source_rgba (.3, .3, .3, 1.0); \
490 cr->set_operator (Cairo::OPERATOR_ADD); \
496 VBox *lrb = manage (new VBox());
497 ToggleButton *log = manage (new ToggleButton (S_("Logscale|Lg")));
498 ToggleButton *rec = manage (new ToggleButton (S_("Rectified|Rf")));
499 lrb->pack_start (*log, false, false, 5);
500 lrb->pack_end (*rec, false, false, 5);
501 log->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_logscale_toggled), log));
502 rec->signal_toggled ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::on_rectivied_toggled), rec));
504 wtbl->attach (*lrb, 1, 2, wrow, wrow + p->n_channels, SHRINK, SHRINK);
507 for (uint32_t c = 0; c < p->n_channels; ++c) {
509 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
511 Cairo::RefPtr<Cairo::ImageSurface> wave;
512 Cairo::RefPtr<Cairo::ImageSurface> wave_log;
513 Cairo::RefPtr<Cairo::ImageSurface> wave_rect;
514 Cairo::RefPtr<Cairo::ImageSurface> wave_lr;
515 draw_waveform(wave, p, c, m_l, width, anw, lin[0], false, false);
516 draw_waveform(wave_log, p, c, m_l, width, anw, lin[0], true, false);
517 draw_waveform(wave_rect, p, c, m_l, width, anw, lin[0], false, true);
518 draw_waveform(wave_lr, p, c, m_l, width, anw, lin[0], true, true);
520 CimgWaveArea *wv = manage (new CimgWaveArea (wave, wave_log, wave_rect, wave_lr, m_l, width));
522 playhead_widgets.push_back (wv);
523 waves.push_back (wv);
524 wv->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
525 wtbl->attach (*wv, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
529 if (channels > 0 && file_length > 0 && sample_rate > 0)
531 /* Time Axis -- re-use waveform width */
532 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
533 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
534 layout->set_text (_("00:00:00.000"));
535 layout->get_pixel_size (w, h);
536 int height = h * 1.75;
537 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
538 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
539 cr->set_operator (Cairo::OPERATOR_SOURCE);
540 cr->set_source_rgba (0, 0, 0, 1.0);
542 cr->rectangle (0, 0, m_l, height);
543 cr->set_source_rgba (0, 0, 0, 0);
545 cr->set_operator (Cairo::OPERATOR_OVER);
547 cr->set_line_width (1.0);
548 for (int i = 0; i <= 4; ++i) {
549 const float fract = (float) i / 4.0;
550 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
551 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
554 AudioClock::print_minsec (start_off + file_length * fract,
555 buf, sizeof (buf), sample_rate);
557 layout->set_text (buf);
558 layout->get_pixel_size (w, h);
559 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
560 cr->set_source_rgba (.9, .9, .9, 1.0);
561 layout->show_in_cairo_context (cr);
563 cr->set_source_rgba (.7, .7, .7, 1.0);
564 cr->move_to (rint (m_l + width * fract) - .5, 0);
565 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
566 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
567 cr->line_to (rint (m_l + width * fract) - .5, height);
571 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
572 layout->set_text (_("Time"));
573 cr->set_source_rgba (.9, .9, .9, 1.0);
574 layout->get_pixel_size (w, h);
575 cr->move_to (rint (m_l - w - 8), rint (.5 * (height - h)));
576 layout->show_in_cairo_context (cr);
579 CimgPlayheadArea *tm = manage (new CimgPlayheadArea (ytme, m_l, width, true));
580 playhead_widgets.push_back (tm);
581 tm->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
582 wtbl->attach (*tm, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
588 const size_t swh = sizeof (p->spectrum) / sizeof (float);
589 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
590 const size_t width = swh / height;
592 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
593 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
594 cr->set_operator (Cairo::OPERATOR_SOURCE);
595 cr->rectangle (0, 0, m_l, height);
596 cr->set_source_rgba (0, 0, 0, 0);
598 cr->rectangle (m_l, 0, width, height);
599 cr->set_source_rgba (0, 0, 0, 1.0);
601 cr->set_operator (Cairo::OPERATOR_OVER);
603 for (size_t x = 0 ; x < width; ++x) {
604 for (size_t y = 0 ; y < height; ++y) {
605 const float pk = p->spectrum[x][y];
606 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
607 ArdourCanvas::set_source_rgba (cr, c);
608 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
614 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
615 layout->set_text (_("Hz"));
616 layout->get_pixel_size (w, h);
617 cr->move_to (rint (m_l - h - anw - 10), rint ((height + w) * .5));
618 cr->set_source_rgba (.9, .9, .9, 1.0);
620 cr->rotate (M_PI / -2.0);
621 layout->show_in_cairo_context (cr);
625 cr->set_line_width (1.0);
626 cr->set_dash (dashes, 2.0);
627 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
629 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
630 //XAXISLABEL (p->freq[0], _("50Hz"));
631 XAXISLABEL (p->freq[1], _("100"));
632 XAXISLABEL (p->freq[2], _("500"));
633 XAXISLABEL (p->freq[3], _("1K"));
634 XAXISLABEL (p->freq[4], _("5K"));
635 XAXISLABEL (p->freq[5], _("10K"));
639 Cairo::RefPtr<Cairo::ImageSurface> scale = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_r, height);
640 cr = Cairo::Context::create (scale);
641 cr->set_operator (Cairo::OPERATOR_SOURCE);
642 cr->rectangle (0, 0, m_r, height);
643 cr->set_source_rgba (0, 0, 0, 0);
646 cr->set_operator (Cairo::OPERATOR_OVER);
647 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
648 layout->set_alignment (Pango::ALIGN_LEFT);
649 layout->set_text (_("dBFS"));
650 layout->get_pixel_size (w, h);
651 cr->move_to (rint (.5 * (m_r - w)), height - h - 2);
652 cr->set_source_rgba (.9, .9, .9, 1.0);
653 layout->show_in_cairo_context (cr);
655 int innertop = ceil (mnh * .5) + 1;
656 size_t innerheight = (height - 2 * innertop - h - 2);
658 cr->rectangle (1, innertop - 1, m_r - 2 - anw, innerheight + 2);
659 cr->set_source_rgba (0, 0, 0, 1.0);
660 cr->fill_preserve ();
661 cr->set_line_width (1.0);
662 cr->set_source_rgba (.7, .7, .6, 1.0);
665 for (size_t y = 0 ; y < innerheight - 2; ++y) {
666 const float pk = 1.0 - (float) y / innerheight;
667 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, sqrt(pk));
668 ArdourCanvas::set_source_rgba (cr, c);
669 cr->rectangle (2, innertop + y + .5, m_r - 4 - anw, 1);
673 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
674 for (int i = 0; i <= 4; ++i) {
675 const float fract = (float) i / 4.0;
676 const float yalign = .5; // (i == 4) ? 0 : (i == 0) ? 1.0 : .5;
678 snprintf (buf, sizeof (buf), "%.0f", AudioGrapher::Analyser::fft_range_db * -fract);
679 layout->set_text (buf);
680 layout->get_pixel_size (w, h);
682 cr->move_to (m_r - anw, rint (innertop + fract * innerheight - h * yalign));
683 cr->set_source_rgba (.9, .9, .9, 1.0);
684 layout->show_in_cairo_context (cr);
688 CimgPlayheadArea *sp = manage (new CimgPlayheadArea (spec, m_l, width));
689 playhead_widgets.push_back (sp);
690 sp->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
691 CimgArea *an = manage (new CimgArea (scale));
692 wtbl->attach (*sp, 0, 1, wrow, wrow + 1, SHRINK, SHRINK);
693 wtbl->attach (*an, 1, 2, wrow, wrow + 1, SHRINK, SHRINK);
697 timeline[page] = playhead_widgets;
699 HBox *tab = manage (new HBox ());
700 l = manage (new Label (Glib::path_get_basename (path)));
701 Gtk::Image *img = manage (new Image (Stock::MEDIA_PLAY, ICON_SIZE_MENU));
702 tab->pack_start (*img);
703 tab->pack_start (*l);
707 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, *tab));
708 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
711 pages.set_show_tabs (true);
713 pages.set_name ("ExportReportNotebook");
714 pages.set_current_page (0);
716 get_vbox ()->set_spacing (4);
717 get_vbox ()->pack_start (pages, false, false);
720 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
721 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
724 play_btn = add_button (Stock::MEDIA_PLAY, RESPONSE_ACCEPT);
725 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
726 add_button (Stock::CLOSE, RESPONSE_CLOSE);
728 set_default_response (RESPONSE_CLOSE);
729 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
730 play_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::play_audition));
731 stop_btn->set_sensitive (false);
739 int i = ArdourDialog::run ();
740 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
746 _session->cancel_audition();
748 return RESPONSE_CLOSE;
752 ExportReport::open_folder (std::string p)
754 PBD::open_uri (Glib::path_get_dirname(p));
758 ExportReport::audition_active (bool active)
760 stop_btn->set_sensitive (active);
761 play_btn->set_sensitive (!active);
763 if (!active && _audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
764 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
765 i != timeline[_audition_num].end();
767 (*i)->set_playhead (-1);
771 if (_audition_num >= 0 ) {
772 Widget *page = pages.get_nth_page (_audition_num);
773 HBox *box = static_cast<Gtk::HBox*> (pages.get_tab_label (*page));
775 (*(box->get_children().begin()))->hide ();
777 (*(box->get_children().begin()))->show ();
787 ExportReport::audition (std::string path, unsigned n_chn, int page)
790 _session->cancel_audition();
792 if (n_chn ==0) { return; }
794 /* can't really happen, unless the user replaces the file while the dialog is open.. */
795 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
796 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
799 if (SMFSource::valid_midi_file (path)) { return; }
801 boost::shared_ptr<Region> r;
803 boost::shared_ptr<AudioFileSource> afs;
804 bool old_sbp = AudioSource::get_build_peakfiles ();
806 /* don't even think of building peakfiles for these files */
807 AudioSource::set_build_peakfiles (false);
809 for (unsigned int n = 0; n < n_chn; ++n) {
811 afs = boost::dynamic_pointer_cast<AudioFileSource> (
812 SourceFactory::createExternal (DataType::AUDIO, *_session,
814 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
815 if (afs->sample_rate() != _session->nominal_frame_rate()) {
816 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
817 srclist.push_back(sfs);
819 srclist.push_back(afs);
821 } catch (failed_constructor& err) {
822 PBD::error << _("Could not access soundfile: ") << path << endmsg;
823 AudioSource::set_build_peakfiles (old_sbp);
828 AudioSource::set_build_peakfiles (old_sbp);
830 if (srclist.empty()) {
834 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
835 std::string rname = region_name_from_path (afs->path(), false);
837 PBD::PropertyList plist;
839 plist.add (ARDOUR::Properties::start, 0);
840 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
841 plist.add (ARDOUR::Properties::name, rname);
842 plist.add (ARDOUR::Properties::layer, 0);
844 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
847 _session->audition_region(r);
848 _audition_num = page;
852 ExportReport::play_audition ()
854 if (_audition_num >= 0 || !_session) { return; }
855 if (files.find (_page_num) == files.end()) { return; }
856 audition (files[_page_num].path, files[_page_num].channels, _page_num);
860 ExportReport::stop_audition ()
862 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
863 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
864 i != timeline[_audition_num].end();
866 (*i)->set_playhead (-1);
870 _session->cancel_audition();
875 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
877 if (_audition_num == _page_num) {
878 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
879 i != timeline[_audition_num].end();
881 (*i)->set_playhead (-1);
884 _page_num = page_num;
888 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
890 if (_audition_num == _page_num && timeline.find (_audition_num) != timeline.end ()) {
891 const float p = (float)pos / len;
892 for (std::list<CimgPlayheadArea*>::const_iterator i = timeline[_audition_num].begin();
893 i != timeline[_audition_num].end();
895 (*i)->set_playhead (p);
901 ExportReport::audition_seek (int page, float pos)
903 if (_audition_num == page && _session) {
904 _session->the_auditioner()->seek_to_percent (100.f * pos);
909 ExportReport::on_logscale_toggled (Gtk::ToggleButton* b)
911 bool en = b->get_active ();
912 for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
913 (*i)->set_logscale (en);
918 ExportReport::on_rectivied_toggled (Gtk::ToggleButton* b)
920 bool en = b->get_active ();
921 for (std::list<CimgWaveArea*>::iterator i = waves.begin (); i != waves.end (); ++i) {
922 (*i)->set_rectified (en);
927 ExportReport::draw_waveform (Cairo::RefPtr<Cairo::ImageSurface>& wave, ExportAnalysisPtr p, uint32_t c, int m_l, size_t width, int anw, int height, bool log, bool rect)
930 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
931 const float height_2 = std::min (100, 8 * height / (int) p->n_channels); // TODO refine
932 const float ht = 2.f * height_2;
934 std::vector<double> dashes;
935 dashes.push_back (3.0);
936 dashes.push_back (5.0);
938 wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, ht);
939 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
940 cr->set_operator (Cairo::OPERATOR_SOURCE);
941 cr->rectangle (0, 0, m_l, ht);
942 cr->set_source_rgba (0, 0, 0, 0);
944 cr->rectangle (m_l, 0, width, ht);
945 cr->set_source_rgba (0, 0, 0, 1.0);
947 cr->set_operator (Cairo::OPERATOR_OVER);
949 cr->set_source_rgba (.7, .7, .7, 1.0);
950 cr->set_line_width (1.0);
960 clip_top = ht * (1.f - alt_log_meter (-1));
961 for (size_t x = 0 ; x < width; ++x) {
962 const float v = alt_log_meter (fast_coefficient_to_dB (std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min))));
963 cr->move_to (m_l + x - .5, ht - ht * v);
964 cr->line_to (m_l + x - .5, ht);
968 clip_top = ht * (1.f - dB_to_coefficient (-1));
969 for (size_t x = 0 ; x < width; ++x) {
970 const float v = std::max (fabsf (p->peaks[c][x].max), fabsf (p->peaks[c][x].min));
971 cr->move_to (m_l + x - .5, ht - ht * v);
972 cr->line_to (m_l + x - .5, ht);
978 clip_top = height_2 - height_2 * alt_log_meter (-1);
979 clip_bot = height_2 + height_2 * alt_log_meter (-1);
980 for (size_t x = 0 ; x < width; ++x) {
982 if (p->peaks[c][x].max > 0) {
983 pmax = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].max));
985 pmax = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].max));
988 if (p->peaks[c][x].min > 0) {
989 pmin = alt_log_meter (fast_coefficient_to_dB (p->peaks[c][x].min));
991 pmin = -alt_log_meter (fast_coefficient_to_dB (-p->peaks[c][x].min));
993 cr->move_to (m_l + x - .5, height_2 - height_2 * pmax);
994 cr->line_to (m_l + x - .5, height_2 - height_2 * pmin);
998 clip_top = height_2 - height_2 * dB_to_coefficient (-1);
999 clip_bot = height_2 + height_2 * dB_to_coefficient (-1);
1000 for (size_t x = 0 ; x < width; ++x) {
1001 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
1002 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
1009 cr->set_source_rgba (1.0, 0, 0, 1.0);
1010 for (size_t x = 0 ; x < width; ++x) {
1011 if (p->peaks[c][x].max >= 1.0) {
1012 cr->move_to (m_l + x - .5, 0);
1013 cr->line_to (m_l + x - .5, clip_top);
1015 if (p->peaks[c][x].min <= -1.0) {
1016 cr->move_to (m_l + x - .5, clip_bot);
1017 cr->line_to (m_l + x - .5, ht);
1023 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
1024 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
1025 cr->move_to (m_l + (*i) - .5, clip_top);
1026 cr->line_to (m_l + (*i) - .5, clip_bot);
1032 cr->set_source_rgba (.3, .3, .3, 0.7);
1033 cr->move_to (m_l + 0, height_2 - .5);
1034 cr->line_to (m_l + width, height_2 - .5);
1039 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
1040 layout->set_alignment (Pango::ALIGN_LEFT);
1041 layout->set_text (_("dBFS"));
1042 layout->get_pixel_size (w, h);
1043 cr->move_to (rint (m_l - h - anw - 10), rint (height_2 + w * .5));
1044 cr->set_source_rgba (.9, .9, .9, 1.0);
1046 cr->rotate (M_PI / -2.0);
1047 layout->show_in_cairo_context (cr);
1051 cr->set_line_width (1.0);
1052 cr->set_dash (dashes, 2.0);
1053 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
1055 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
1059 XAXISLABEL ((ht - ht * alt_log_meter (-36)), _("-36"));
1060 XAXISLABEL ((ht - ht * alt_log_meter (-18)), _("-18"));
1061 XAXISLABEL ((ht - ht * alt_log_meter (-9)), _("-9"));
1062 XAXISLABEL ((ht - ht * alt_log_meter (-3)), _("-3"));
1064 XAXISLABEL ((ht - ht * .1259), _("-18"));
1065 XAXISLABEL ((ht - ht * .3548), _("-9"));
1066 XAXISLABEL ((ht - ht * .7079), _("-3"));
1070 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-18)), _("-18"));
1071 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-9)), _("-9"));
1072 XAXISLABEL ((height_2 - height_2 * alt_log_meter (-3)), _("-3"));
1073 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-18)), _("-18"));
1074 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-9)), _("-9"));
1075 XAXISLABEL ((height_2 + height_2 * alt_log_meter (-3)), _("-3"));
1077 XAXISLABEL (height_2 * 0.6452, _("-9"));
1078 XAXISLABEL (height_2 * 1.3548, _("-9"));
1079 XAXISLABEL (height_2 * 0.2921, _("-3"));
1080 XAXISLABEL (height_2 * 1.7079, _("-3"));