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 "ardour/audiofilesource.h"
33 #include "ardour/audioregion.h"
34 #include "ardour/auditioner.h"
35 #include "ardour/dB.h"
36 #include "ardour/region_factory.h"
37 #include "ardour/session.h"
38 #include "ardour/smf_source.h"
39 #include "ardour/source_factory.h"
40 #include "ardour/srcfilesource.h"
42 #include "audio_clock.h"
43 #include "ui_config.h"
44 #include "export_report.h"
49 using namespace ARDOUR;
51 ExportReport::ExportReport (Session* session, StatusPtr s)
52 : ArdourDialog (_("Export Report/Analysis"))
58 set_resizable (false);
59 pages.set_scrollable ();
61 AnalysisResults & ar = status->result_map;
63 std::vector<double> dashes;
64 dashes.push_back (3.0);
65 dashes.push_back (5.0);
68 for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
70 VBox *vb = manage (new VBox ());
71 Table *t = manage (new Table (4, 4));
72 t->set_border_width (0);
75 vb->set_border_width (4);
76 vb->pack_start (*t, false, false, 2);
78 std::string path = i->first;
79 ExportAnalysisPtr p = i->second;
81 l = manage (new Label (_("File:"), ALIGN_END));
82 t->attach (*l, 0, 1, 0, 1);
83 l = manage (new Label ());
84 l->set_ellipsize (Pango::ELLIPSIZE_START);
85 l->set_width_chars (64);
86 l->set_max_width_chars (64);
88 l->set_alignment (ALIGN_START, ALIGN_CENTER);
89 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
91 Button *b = manage (new Button (_("Open Folder")));
92 t->attach (*b, 3, 4, 0, 1, FILL, SHRINK);
93 b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
95 Button *start_btn = manage (new Button (_("Audition")));
96 t->attach (*start_btn, 3, 4, 1, 2, FILL, SHRINK);
101 framecnt_t file_length = 0;
102 framecnt_t sample_rate = 0;
103 framecnt_t start_off = 0;
104 unsigned int channels = 0;
106 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
109 file_length = info.length;
110 sample_rate = info.samplerate;
111 start_off = info.timecode;
112 channels = info.channels;
114 /* File Info Table */
116 framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
117 double src_coef = (double) nfr / info.samplerate;
119 l = manage (new Label (_("Format:"), ALIGN_END));
120 t->attach (*l, 0, 1, 1, 2);
121 std::string fmt = info.format_name;
122 std::replace (fmt.begin (), fmt.end (), '\n', ' ');
123 l = manage (new Label ());
124 l->set_ellipsize (Pango::ELLIPSIZE_START);
125 l->set_width_chars (64);
126 l->set_max_width_chars (64);
128 l->set_alignment (ALIGN_START, ALIGN_CENTER);
129 t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
131 l = manage (new Label (_("Channels:"), ALIGN_END));
132 t->attach (*l, 0, 1, 2, 3);
133 l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
134 t->attach (*l, 1, 2, 2, 3);
136 l = manage (new Label (_("Sample rate:"), ALIGN_END));
137 t->attach (*l, 0, 1, 3, 4);
138 l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
139 t->attach (*l, 1, 2, 3, 4);
141 l = manage (new Label (_("Duration:"), ALIGN_END));
142 t->attach (*l, 2, 3, 2, 3);
143 clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
144 clock->set_session (_session);
145 clock->set_mode (AudioClock::MinSec);
146 clock->set (info.length * src_coef + 0.5, true);
147 t->attach (*clock, 3, 4, 2, 3);
149 l = manage (new Label (_("Timecode:"), ALIGN_END));
150 t->attach (*l, 2, 3, 3, 4);
151 clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
152 clock->set_session (_session);
153 clock->set_mode (AudioClock::Timecode);
154 clock->set (info.timecode * src_coef + 0.5, true);
155 t->attach (*clock, 3, 4, 3, 4);
157 l = manage (new Label (_("Error:"), ALIGN_END));
158 t->attach (*l, 0, 1, 1, 2);
159 l = manage (new Label (errmsg, ALIGN_START));
160 t->attach (*l, 1, 4, 1, 2);
163 if (channels > 0 && file_length > 0 && sample_rate > 0 && _session) {
164 start_btn->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::audition), path, channels, page));
166 start_btn->set_sensitive (false);
170 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
172 // calc geometry of numerics
173 const float dbfs = accurate_coefficient_to_dB (p->peak);
174 const float dbtp = accurate_coefficient_to_dB (p->truepeak);
176 #define TXTSIZE(LINE, TXT, FONT) { \
177 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
178 layout->set_text (TXT); \
179 layout->get_pixel_size (w, h); \
180 if (w > mnw) { mnw = w; } \
181 if (h > lin[LINE]) { lin[LINE] = h; } \
184 #define TXTWIDTH(TXT, FONT) { \
185 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
186 layout->set_text (TXT); \
187 layout->get_pixel_size (w, h); \
188 if (w > mml) { mml = w; } \
191 int mnw = 0; // max numeric width
192 int lin[4] = { 0, 0, 0, 0 }; // max line height
194 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
196 TXTSIZE(0, _("Peak:"), get_SmallFont);
197 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
198 TXTSIZE(2, _("True Peak:"), get_SmallFont);
199 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
201 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
202 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
203 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
204 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
207 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] + 8;
208 const int hh = std::max (100, ht);
209 int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800; // margin left
211 int mml = 0; // min margin left -- ensure left margin is wide enough
212 TXTWIDTH (_("Time"), get_SmallFont);
213 TXTWIDTH (_("100"), get_SmallMonospaceFont);
214 m_l = (std::max (m_l, mml + 8) + 3) & ~3;
216 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800) / 2;
217 const int nw2 = mnw / 2; // nums, horizontal center
220 y0[0] = (hh - ht) * .5 + lin[0] * .25;
221 y0[1] = y0[0] + lin[0] * 1.25;
222 y0[2] = y0[1] + lin[1] * 1.25;
223 y0[3] = y0[2] + lin[2] * 1.25;
226 { /* peak, loudness and R128 histogram */
227 Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
228 Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
229 Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
231 /* peak and true-peak numerics */
232 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
233 cr->set_source_rgba (0, 0, 0, 1.0);
236 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
237 layout->set_alignment (Pango::ALIGN_LEFT);
238 layout->set_text (_("Peak:"));
239 layout->get_pixel_size (w, h);
240 cr->move_to (rint (nw2 - w * .5), y0[0]);
241 cr->set_source_rgba (.7, .7, .7, 1.0);
242 layout->show_in_cairo_context (cr);
244 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
245 layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
246 layout->get_pixel_size (w, h);
247 cr->move_to (rint (nw2 - w * .5), y0[1]);
248 if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
249 else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
250 layout->show_in_cairo_context (cr);
253 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
254 layout->set_text (_("True Peak:"));
255 layout->get_pixel_size (w, h);
256 cr->move_to (rint (nw2 - w * .5), y0[2]);
257 cr->set_source_rgba (.7, .7, .7, 1.0);
258 layout->show_in_cairo_context (cr);
260 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
261 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
262 layout->get_pixel_size (w, h);
263 cr->move_to (rint (nw2 - w * .5), y0[3]);
264 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
265 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
266 layout->show_in_cairo_context (cr);
271 /* EBU R128 numerics */
272 cr = Cairo::Context::create (ebur);
273 cr->set_source_rgba (0, 0, 0, 1.0);
276 cr->set_source_rgba (.7, .7, .7, 1.0);
278 if (!i->second->have_loudness) {
279 layout->set_alignment (Pango::ALIGN_CENTER);
280 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
281 layout->set_text (_("Not\nAvailable"));
282 layout->get_pixel_size (w, h);
283 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
284 layout->show_in_cairo_context (cr);
286 else if (p->loudness == -200 && p->loudness_range == 0) {
287 layout->set_alignment (Pango::ALIGN_CENTER);
288 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
289 layout->set_text (_("Not\nAvailable"));
290 layout->get_pixel_size (w, h);
291 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .6));
292 layout->show_in_cairo_context (cr);
295 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
296 layout->set_text (_("(too short integration time)"));
297 layout->get_pixel_size (w, h);
298 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
299 layout->show_in_cairo_context (cr);
302 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
303 layout->set_alignment (Pango::ALIGN_LEFT);
304 layout->set_text (_("Integrated Loudness:"));
305 layout->get_pixel_size (w, h);
306 cr->move_to (rint (nw2 - w * .5), y0[0]);
307 layout->show_in_cairo_context (cr);
309 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
310 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
311 layout->get_pixel_size (w, h);
312 cr->move_to (rint (nw2 - w * .5), y0[1]);
313 layout->show_in_cairo_context (cr);
315 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
316 layout->set_text (_("Loudness Range:"));
317 layout->get_pixel_size (w, h);
318 cr->move_to (rint (nw2 - w * .5), y0[2]);
319 layout->show_in_cairo_context (cr);
321 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
322 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
323 layout->get_pixel_size (w, h);
324 cr->move_to (rint (nw2 - w * .5), y0[3]);
325 layout->show_in_cairo_context (cr);
329 /* draw loudness histogram */
330 cr = Cairo::Context::create (hist);
331 cr->set_source_rgba (0, 0, 0, 1.0);
334 cr->set_source_rgba (.7, .7, .7, 1.0);
335 cr->set_line_width (1.0);
337 if (p->loudness_hist_max > 0 && i->second->have_loudness) {
338 for (size_t x = 0 ; x < 510; ++x) {
339 cr->move_to (x - .5, hh);
340 cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
345 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
346 layout->set_alignment (Pango::ALIGN_CENTER);
349 layout->set_text (_("LUFS\n(short)"));
350 layout->get_pixel_size (w, h);
351 Gtkmm2ext::rounded_rectangle (cr, 5, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
352 cr->set_source_rgba (.1, .1, .1, 0.7);
355 cr->move_to (6, rint (.5 * (hh + w)));
356 cr->set_source_rgba (.9, .9, .9, 1.0);
357 cr->rotate (M_PI / -2.0);
358 layout->show_in_cairo_context (cr);
362 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
363 layout->set_alignment (Pango::ALIGN_LEFT);
364 for (int g = -53; g <= -8; g += 5) {
365 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
366 layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
367 layout->get_pixel_size (w, h);
369 cr->set_operator (Cairo::OPERATOR_OVER);
370 Gtkmm2ext::rounded_rectangle (cr,
371 rint ((g + 59.0) * 10.0 - h * .5), 5,
373 const float pk = (g + 59.0) / 54.0;
374 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
375 ArdourCanvas::set_source_rgba (cr, c);
379 cr->set_source_rgba (.9, .9, .9, 1.0);
380 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
381 cr->rotate (M_PI / -2.0);
382 layout->show_in_cairo_context (cr);
385 cr->set_operator (Cairo::OPERATOR_ADD);
387 cr->set_source_rgba (.3, .3, .3, 1.0);
388 cr->set_dash (dashes, 1.0);
389 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
390 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
391 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
398 CimgArea *nu = manage (new CimgArea (nums));
399 CimgArea *eb = manage (new CimgArea (ebur));
400 CimgArea *hi = manage (new CimgArea (hist));
401 HBox *hb = manage (new HBox ());
403 hb->pack_start (*nu, false, false);
404 hb->pack_start (*hi, false, false);
405 hb->pack_start (*eb, false, false);
406 vb->pack_start (*hb, false, false);
409 #define XAXISLABEL(POS, TXT) { \
410 const float yy = rint (POS); \
411 layout->set_text (TXT); \
412 layout->get_pixel_size (w, h); \
413 cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
414 cr->set_source_rgba (.9, .9, .9, 1.0); \
415 cr->set_operator (Cairo::OPERATOR_OVER); \
416 layout->show_in_cairo_context (cr); \
417 cr->move_to (m_l - 4, yy - .5); \
418 cr->line_to (m_l + width, yy - .5); \
419 cr->set_source_rgba (.3, .3, .3, 1.0); \
420 cr->set_operator (Cairo::OPERATOR_ADD); \
424 for (uint32_t c = 0; c < p->n_channels; ++c) {
426 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
427 const float height_2 = std::min (100, 8 * lin[0] / (int) p->n_channels); // TODO refine
429 Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, 2 * height_2);
430 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
431 cr->set_operator (Cairo::OPERATOR_SOURCE);
432 cr->rectangle (0, 0, m_l, 2 * height_2);
433 cr->set_source_rgba (0, 0, 0, 0);
435 cr->rectangle (m_l, 0, width, 2 * height_2);
436 cr->set_source_rgba (0, 0, 0, 1.0);
438 cr->set_operator (Cairo::OPERATOR_OVER);
440 cr->set_source_rgba (.7, .7, .7, 1.0);
441 cr->set_line_width (1.0);
442 for (size_t x = 0 ; x < width; ++x) {
443 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
444 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
449 cr->set_source_rgba (1.0, 0, 0, 1.0);
450 for (size_t x = 0 ; x < width; ++x) {
451 if (p->peaks[c][x].max >= 1.0) {
452 cr->move_to (m_l + x - .5, 0);
453 cr->line_to (m_l + x - .5, height_2 * .22);
455 if (p->peaks[c][x].min <= -1.0) {
456 cr->move_to (m_l + x - .5, height_2 * 1.78);
457 cr->line_to (m_l + x - .5, height_2 * 2.);
464 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
465 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
466 cr->move_to (m_l + (*i) - .5, height_2 * 0.22);
467 cr->line_to (m_l + (*i) - .5, height_2 * 1.78);
472 cr->set_source_rgba (.3, .3, .3, 0.7);
473 cr->move_to (m_l + 0, height_2 - .5);
474 cr->line_to (m_l + width, height_2 - .5);
478 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
479 layout->set_alignment (Pango::ALIGN_LEFT);
480 layout->set_text (_("dBFS"));
481 layout->get_pixel_size (w, h);
482 cr->move_to (rint (.5 * (m_l - h)), rint (height_2 + w * .5));
483 cr->set_source_rgba (.9, .9, .9, 1.0);
485 cr->rotate (M_PI / -2.0);
486 layout->show_in_cairo_context (cr);
490 cr->set_line_width (1.0);
491 cr->set_dash (dashes, 2.0);
492 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
494 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
495 XAXISLABEL (height_2 * 0.6452, _("-9"));
496 XAXISLABEL (height_2 * 1.3548, _("-9"));
497 XAXISLABEL (height_2 * 0.2921, _("-3"));
498 XAXISLABEL (height_2 * 1.7079, _("-3"));
501 CimgArea *wv = manage (new CimgArea (wave));
502 vb->pack_start (*wv);
505 if (channels > 0 && file_length > 0 && sample_rate > 0)
507 /* Time Axis -- re-use waveform width */
508 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
509 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
510 layout->set_text (_("00:00:00.000"));
511 layout->get_pixel_size (w, h);
512 int height = h * 1.75;
513 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
514 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
515 cr->set_operator (Cairo::OPERATOR_SOURCE);
516 cr->set_source_rgba (0, 0, 0, 1.0);
518 cr->rectangle (0, 0, m_l, height);
519 cr->set_source_rgba (0, 0, 0, 0);
521 cr->set_operator (Cairo::OPERATOR_OVER);
523 cr->set_line_width (1.0);
524 for (int i = 0; i <= 4; ++i) {
525 const float fract = (float) i / 4.0;
526 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
527 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
530 AudioClock::print_minsec (start_off + file_length * fract,
531 buf, sizeof (buf), sample_rate);
533 layout->set_text (buf);
534 layout->get_pixel_size (w, h);
535 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
536 cr->set_source_rgba (.9, .9, .9, 1.0);
537 layout->show_in_cairo_context (cr);
539 cr->set_source_rgba (.7, .7, .7, 1.0);
540 cr->move_to (rint (m_l + width * fract) - .5, 0);
541 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
542 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
543 cr->line_to (rint (m_l + width * fract) - .5, height);
547 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
548 layout->set_text (_("Time"));
549 cr->set_source_rgba (.9, .9, .9, 1.0);
550 layout->get_pixel_size (w, h);
551 cr->move_to (rint (.5 * (m_l - w)), rint (.5 * (height - h)));
552 layout->show_in_cairo_context (cr);
555 CimgArea *tm = manage (new CimgArea (ytme));
556 tm->set_audition_axis (m_l, width);
557 timeline.push_back (tm);
558 vb->pack_start (*tm);
560 timeline.push_back (0);
565 const size_t swh = sizeof (p->spectrum) / sizeof (float);
566 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
567 const size_t width = swh / height;
569 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
570 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
571 cr->set_operator (Cairo::OPERATOR_SOURCE);
572 cr->rectangle (0, 0, m_l, height);
573 cr->set_source_rgba (0, 0, 0, 0);
575 cr->rectangle (m_l, 0, width, height);
576 cr->set_source_rgba (0, 0, 0, 1.0);
578 cr->set_operator (Cairo::OPERATOR_OVER);
580 for (size_t x = 0 ; x < width; ++x) {
581 for (size_t y = 0 ; y < height; ++y) {
582 const float pk = p->spectrum[x][y];
583 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
584 ArdourCanvas::set_source_rgba (cr, c);
585 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
591 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
592 layout->set_text (_("Hz"));
593 layout->get_pixel_size (w, h);
594 cr->move_to (rint (.5 * (m_l - h)), rint ((height + w) * .5));
595 cr->set_source_rgba (.9, .9, .9, 1.0);
597 cr->rotate (M_PI / -2.0);
598 layout->show_in_cairo_context (cr);
602 cr->set_line_width (1.0);
603 cr->set_dash (dashes, 2.0);
604 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
606 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
607 //XAXISLABEL (p->freq[0], _("50Hz"));
608 XAXISLABEL (p->freq[1], _("100"));
609 XAXISLABEL (p->freq[2], _("500"));
610 XAXISLABEL (p->freq[3], _("1K"));
611 XAXISLABEL (p->freq[4], _("5K"));
612 XAXISLABEL (p->freq[5], _("10K"));
615 CimgArea *sp = manage (new CimgArea (spec));
616 vb->pack_start (*sp);
619 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
620 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
623 pages.set_show_tabs (true);
625 pages.set_name ("ExportReportNotebook");
626 pages.set_current_page (0);
628 get_vbox ()->set_spacing (4);
629 get_vbox ()->pack_start (pages, false, false);
632 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
633 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
636 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
637 add_button (Stock::CLOSE, RESPONSE_CLOSE);
639 set_default_response (RESPONSE_CLOSE);
640 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
641 stop_btn->set_sensitive (false);
649 int i = ArdourDialog::run ();
650 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
656 _session->cancel_audition();
658 return RESPONSE_CLOSE;
662 ExportReport::open_folder (std::string p)
664 PBD::open_uri (Glib::path_get_dirname(p));
668 ExportReport::audition_active (bool active)
670 stop_btn->set_sensitive (active);
674 ExportReport::audition (std::string path, unsigned n_chn, int page)
677 _session->cancel_audition();
679 /* can't really happen, unless the user replaces the file while the dialog is open.. */
680 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
681 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
684 if (SMFSource::valid_midi_file (path)) { return; }
686 boost::shared_ptr<Region> r;
688 boost::shared_ptr<AudioFileSource> afs;
689 bool old_sbp = AudioSource::get_build_peakfiles ();
691 /* don't even think of building peakfiles for these files */
692 AudioSource::set_build_peakfiles (false);
694 for (unsigned int n = 0; n < n_chn; ++n) {
696 afs = boost::dynamic_pointer_cast<AudioFileSource> (
697 SourceFactory::createExternal (DataType::AUDIO, *_session,
699 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
700 if (afs->sample_rate() != _session->nominal_frame_rate()) {
701 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
702 srclist.push_back(sfs);
704 srclist.push_back(afs);
706 } catch (failed_constructor& err) {
707 PBD::error << _("Could not access soundfile: ") << path << endmsg;
708 AudioSource::set_build_peakfiles (old_sbp);
713 AudioSource::set_build_peakfiles (old_sbp);
715 if (srclist.empty()) {
719 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
720 std::string rname = region_name_from_path (afs->path(), false);
722 PBD::PropertyList plist;
724 plist.add (ARDOUR::Properties::start, 0);
725 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
726 plist.add (ARDOUR::Properties::name, rname);
727 plist.add (ARDOUR::Properties::layer, 0);
729 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
732 _session->audition_region(r);
733 _audition_num = page;
737 ExportReport::stop_audition ()
739 if (_audition_num == _page_num) {
740 assert (timeline[_audition_num]);
741 timeline[_audition_num]->set_playhead (-1);
744 _session->cancel_audition();
750 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
752 if (_audition_num == _page_num) {
753 assert (timeline[_audition_num]);
754 timeline[_audition_num]->set_playhead (-1);
756 _page_num = page_num;
760 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
762 if (_audition_num == _page_num) {
763 assert (timeline[_audition_num]);
764 timeline[_audition_num]->set_playhead ((float)pos / len);