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"))
56 set_resizable (false);
57 pages.set_scrollable ();
59 AnalysisResults & ar = status->result_map;
61 std::vector<double> dashes;
62 dashes.push_back (3.0);
63 dashes.push_back (5.0);
65 for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i) {
67 VBox *vb = manage (new VBox ());
68 Table *t = manage (new Table (4, 4));
69 t->set_border_width (0);
72 vb->set_border_width (4);
73 vb->pack_start (*t, false, false, 2);
75 std::string path = i->first;
76 ExportAnalysisPtr p = i->second;
78 l = manage (new Label (_("File:"), ALIGN_END));
79 t->attach (*l, 0, 1, 0, 1);
80 l = manage (new Label ());
81 l->set_ellipsize (Pango::ELLIPSIZE_START);
82 l->set_width_chars (64);
83 l->set_max_width_chars (64);
85 l->set_alignment (ALIGN_START, ALIGN_CENTER);
86 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
88 Button *b = manage (new Button (_("Open Folder")));
89 t->attach (*b, 3, 4, 0, 1, FILL, SHRINK);
90 b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
92 Button *start_btn = manage (new Button (_("Audition")));
93 t->attach (*start_btn, 3, 4, 1, 2, FILL, SHRINK);
98 framecnt_t file_length = 0;
99 framecnt_t sample_rate = 0;
100 framecnt_t start_off = 0;
101 framecnt_t channels = 0;
103 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
106 file_length = info.length;
107 sample_rate = info.samplerate;
108 start_off = info.timecode;
109 channels = info.channels;
111 /* File Info Table */
113 framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
114 double src_coef = (double) nfr / info.samplerate;
116 l = manage (new Label (_("Format:"), ALIGN_END));
117 t->attach (*l, 0, 1, 1, 2);
118 std::string fmt = info.format_name;
119 std::replace (fmt.begin (), fmt.end (), '\n', ' ');
120 l = manage (new Label ());
121 l->set_ellipsize (Pango::ELLIPSIZE_START);
122 l->set_width_chars (64);
123 l->set_max_width_chars (64);
125 l->set_alignment (ALIGN_START, ALIGN_CENTER);
126 t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
128 l = manage (new Label (_("Channels:"), ALIGN_END));
129 t->attach (*l, 0, 1, 2, 3);
130 l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
131 t->attach (*l, 1, 2, 2, 3);
133 l = manage (new Label (_("Sample rate:"), ALIGN_END));
134 t->attach (*l, 0, 1, 3, 4);
135 l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
136 t->attach (*l, 1, 2, 3, 4);
138 l = manage (new Label (_("Duration:"), ALIGN_END));
139 t->attach (*l, 2, 3, 2, 3);
140 clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
141 clock->set_session (_session);
142 clock->set_mode (AudioClock::MinSec);
143 clock->set (info.length * src_coef + 0.5, true);
144 t->attach (*clock, 3, 4, 2, 3);
146 l = manage (new Label (_("Timecode:"), ALIGN_END));
147 t->attach (*l, 2, 3, 3, 4);
148 clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
149 clock->set_session (_session);
150 clock->set_mode (AudioClock::Timecode);
151 clock->set (info.timecode * src_coef + 0.5, true);
152 t->attach (*clock, 3, 4, 3, 4);
154 l = manage (new Label (_("Error:"), ALIGN_END));
155 t->attach (*l, 0, 1, 1, 2);
156 l = manage (new Label (errmsg, ALIGN_START));
157 t->attach (*l, 1, 4, 1, 2);
160 if (channels > 0 && _session) {
161 start_btn->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::audition), path, channels));
163 start_btn->set_sensitive (false);
167 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
169 // calc geometry of numerics
170 const float dbfs = accurate_coefficient_to_dB (p->peak);
171 const float dbtp = accurate_coefficient_to_dB (p->truepeak);
173 #define TXTSIZE(LINE, TXT, FONT) { \
174 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
175 layout->set_text (TXT); \
176 layout->get_pixel_size (w, h); \
177 if (w > mnw) { mnw = w; } \
178 if (h > lin[LINE]) { lin[LINE] = h; } \
181 #define TXTWIDTH(TXT, FONT) { \
182 layout->set_font_description (UIConfiguration::instance ().FONT ()); \
183 layout->set_text (TXT); \
184 layout->get_pixel_size (w, h); \
185 if (w > mml) { mml = w; } \
188 int mnw = 0; // max numeric width
189 int lin[4] = { 0, 0, 0, 0 }; // max line height
191 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
193 TXTSIZE(0, _("Peak:"), get_SmallFont);
194 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
195 TXTSIZE(2, _("True Peak:"), get_SmallFont);
196 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
198 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
199 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
200 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
201 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
204 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] + 8;
205 const int hh = std::max (100, ht);
206 int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800; // margin left
208 int mml = 0; // min margin left -- ensure left margin is wide enough
209 TXTWIDTH (_("Time"), get_SmallFont);
210 TXTWIDTH (_("100"), get_SmallMonospaceFont);
211 m_l = (std::max (m_l, mml + 8) + 3) & ~3;
213 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800) / 2;
214 const int nw2 = mnw / 2; // nums, horizontal center
217 y0[0] = (hh - ht) * .5 + lin[0] * .25;
218 y0[1] = y0[0] + lin[0] * 1.25;
219 y0[2] = y0[1] + lin[1] * 1.25;
220 y0[3] = y0[2] + lin[2] * 1.25;
223 { /* peak, loudness and R128 histogram */
224 Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
225 Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
226 Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
228 /* peak and true-peak numerics */
229 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
230 cr->set_source_rgba (0, 0, 0, 1.0);
233 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
234 layout->set_alignment (Pango::ALIGN_LEFT);
235 layout->set_text (_("Peak:"));
236 layout->get_pixel_size (w, h);
237 cr->move_to (rint (nw2 - w * .5), y0[0]);
238 cr->set_source_rgba (.7, .7, .7, 1.0);
239 layout->show_in_cairo_context (cr);
241 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
242 layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
243 layout->get_pixel_size (w, h);
244 cr->move_to (rint (nw2 - w * .5), y0[1]);
245 if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
246 else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
247 layout->show_in_cairo_context (cr);
250 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
251 layout->set_text (_("True Peak:"));
252 layout->get_pixel_size (w, h);
253 cr->move_to (rint (nw2 - w * .5), y0[2]);
254 cr->set_source_rgba (.7, .7, .7, 1.0);
255 layout->show_in_cairo_context (cr);
257 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
258 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
259 layout->get_pixel_size (w, h);
260 cr->move_to (rint (nw2 - w * .5), y0[3]);
261 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
262 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
263 layout->show_in_cairo_context (cr);
268 /* EBU R128 numerics */
269 cr = Cairo::Context::create (ebur);
270 cr->set_source_rgba (0, 0, 0, 1.0);
273 cr->set_source_rgba (.7, .7, .7, 1.0);
275 if (!i->second->have_loudness) {
276 layout->set_alignment (Pango::ALIGN_CENTER);
277 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
278 layout->set_text (_("Not\nAvailable"));
279 layout->get_pixel_size (w, h);
280 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
281 layout->show_in_cairo_context (cr);
283 else if (p->loudness == -200 && p->loudness_range == 0) {
284 layout->set_alignment (Pango::ALIGN_CENTER);
285 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
286 layout->set_text (_("Not\nAvailable"));
287 layout->get_pixel_size (w, h);
288 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .6));
289 layout->show_in_cairo_context (cr);
292 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
293 layout->set_text (_("(too short integration time)"));
294 layout->get_pixel_size (w, h);
295 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
296 layout->show_in_cairo_context (cr);
299 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
300 layout->set_alignment (Pango::ALIGN_LEFT);
301 layout->set_text (_("Integrated Loudness:"));
302 layout->get_pixel_size (w, h);
303 cr->move_to (rint (nw2 - w * .5), y0[0]);
304 layout->show_in_cairo_context (cr);
306 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
307 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
308 layout->get_pixel_size (w, h);
309 cr->move_to (rint (nw2 - w * .5), y0[1]);
310 layout->show_in_cairo_context (cr);
312 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
313 layout->set_text (_("Loudness Range:"));
314 layout->get_pixel_size (w, h);
315 cr->move_to (rint (nw2 - w * .5), y0[2]);
316 layout->show_in_cairo_context (cr);
318 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
319 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
320 layout->get_pixel_size (w, h);
321 cr->move_to (rint (nw2 - w * .5), y0[3]);
322 layout->show_in_cairo_context (cr);
326 /* draw loudness histogram */
327 cr = Cairo::Context::create (hist);
328 cr->set_source_rgba (0, 0, 0, 1.0);
331 cr->set_source_rgba (.7, .7, .7, 1.0);
332 cr->set_line_width (1.0);
334 if (p->loudness_hist_max > 0 && i->second->have_loudness) {
335 for (size_t x = 0 ; x < 510; ++x) {
336 cr->move_to (x - .5, hh);
337 cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
342 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
343 layout->set_alignment (Pango::ALIGN_CENTER);
346 layout->set_text (_("LUFS\n(short)"));
347 layout->get_pixel_size (w, h);
348 Gtkmm2ext::rounded_rectangle (cr, 5, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
349 cr->set_source_rgba (.1, .1, .1, 0.7);
352 cr->move_to (6, rint (.5 * (hh + w)));
353 cr->set_source_rgba (.9, .9, .9, 1.0);
354 cr->rotate (M_PI / -2.0);
355 layout->show_in_cairo_context (cr);
359 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
360 layout->set_alignment (Pango::ALIGN_LEFT);
361 for (int g = -53; g <= -8; g += 5) {
362 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
363 layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
364 layout->get_pixel_size (w, h);
366 cr->set_operator (Cairo::OPERATOR_OVER);
367 Gtkmm2ext::rounded_rectangle (cr,
368 rint ((g + 59.0) * 10.0 - h * .5), 5,
370 const float pk = (g + 59.0) / 54.0;
371 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
372 ArdourCanvas::set_source_rgba (cr, c);
376 cr->set_source_rgba (.9, .9, .9, 1.0);
377 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
378 cr->rotate (M_PI / -2.0);
379 layout->show_in_cairo_context (cr);
382 cr->set_operator (Cairo::OPERATOR_ADD);
384 cr->set_source_rgba (.3, .3, .3, 1.0);
385 cr->set_dash (dashes, 1.0);
386 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
387 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
388 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
395 CimgArea *nu = manage (new CimgArea (nums));
396 CimgArea *eb = manage (new CimgArea (ebur));
397 CimgArea *hi = manage (new CimgArea (hist));
398 HBox *hb = manage (new HBox ());
400 hb->pack_start (*nu, false, false);
401 hb->pack_start (*hi, false, false);
402 hb->pack_start (*eb, false, false);
403 vb->pack_start (*hb, false, false);
406 #define XAXISLABEL(POS, TXT) { \
407 const float yy = rint (POS); \
408 layout->set_text (TXT); \
409 layout->get_pixel_size (w, h); \
410 cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
411 cr->set_source_rgba (.9, .9, .9, 1.0); \
412 cr->set_operator (Cairo::OPERATOR_OVER); \
413 layout->show_in_cairo_context (cr); \
414 cr->move_to (m_l - 4, yy - .5); \
415 cr->line_to (m_l + width, yy - .5); \
416 cr->set_source_rgba (.3, .3, .3, 1.0); \
417 cr->set_operator (Cairo::OPERATOR_ADD); \
421 for (uint32_t c = 0; c < p->n_channels; ++c) {
423 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
424 const float height_2 = std::min (100, 8 * lin[0] / (int) p->n_channels); // TODO refine
426 Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, 2 * height_2);
427 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
428 cr->set_operator (Cairo::OPERATOR_SOURCE);
429 cr->rectangle (0, 0, m_l, 2 * height_2);
430 cr->set_source_rgba (0, 0, 0, 0);
432 cr->rectangle (m_l, 0, width, 2 * height_2);
433 cr->set_source_rgba (0, 0, 0, 1.0);
435 cr->set_operator (Cairo::OPERATOR_OVER);
437 cr->set_source_rgba (.7, .7, .7, 1.0);
438 cr->set_line_width (1.0);
439 for (size_t x = 0 ; x < width; ++x) {
440 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
441 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
446 cr->set_source_rgba (1.0, 0, 0, 1.0);
447 for (size_t x = 0 ; x < width; ++x) {
448 if (p->peaks[c][x].max >= 1.0) {
449 cr->move_to (m_l + x - .5, 0);
450 cr->line_to (m_l + x - .5, height_2 * .22);
452 if (p->peaks[c][x].min <= -1.0) {
453 cr->move_to (m_l + x - .5, height_2 * 1.78);
454 cr->line_to (m_l + x - .5, height_2 * 2.);
461 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
462 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
463 cr->move_to (m_l + (*i) - .5, height_2 * 0.22);
464 cr->line_to (m_l + (*i) - .5, height_2 * 1.78);
469 cr->set_source_rgba (.3, .3, .3, 0.7);
470 cr->move_to (m_l + 0, height_2 - .5);
471 cr->line_to (m_l + width, height_2 - .5);
475 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
476 layout->set_alignment (Pango::ALIGN_LEFT);
477 layout->set_text (_("dBFS"));
478 layout->get_pixel_size (w, h);
479 cr->move_to (rint (.5 * (m_l - h)), rint (height_2 + w * .5));
480 cr->set_source_rgba (.9, .9, .9, 1.0);
482 cr->rotate (M_PI / -2.0);
483 layout->show_in_cairo_context (cr);
487 cr->set_line_width (1.0);
488 cr->set_dash (dashes, 2.0);
489 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
491 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
492 XAXISLABEL (height_2 * 0.6452, _("-9"));
493 XAXISLABEL (height_2 * 1.3548, _("-9"));
494 XAXISLABEL (height_2 * 0.2921, _("-3"));
495 XAXISLABEL (height_2 * 1.7079, _("-3"));
498 CimgArea *wv = manage (new CimgArea (wave));
499 vb->pack_start (*wv);
502 if (file_length > 0 && sample_rate > 0)
504 /* Time Axis -- re-use waveform width */
505 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
506 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
507 layout->set_text (_("00:00:00.000"));
508 layout->get_pixel_size (w, h);
509 int height = h * 1.75;
510 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
511 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
512 cr->set_operator (Cairo::OPERATOR_SOURCE);
513 cr->set_source_rgba (0, 0, 0, 1.0);
515 cr->rectangle (0, 0, m_l, height);
516 cr->set_source_rgba (0, 0, 0, 0);
518 cr->set_operator (Cairo::OPERATOR_OVER);
520 cr->set_line_width (1.0);
521 for (int i = 0; i <= 4; ++i) {
522 const float fract = (float) i / 4.0;
523 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
524 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
527 AudioClock::print_minsec (start_off + file_length * fract,
528 buf, sizeof (buf), sample_rate);
530 layout->set_text (buf);
531 layout->get_pixel_size (w, h);
532 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
533 cr->set_source_rgba (.9, .9, .9, 1.0);
534 layout->show_in_cairo_context (cr);
536 cr->set_source_rgba (.7, .7, .7, 1.0);
537 cr->move_to (rint (m_l + width * fract) - .5, 0);
538 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
539 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
540 cr->line_to (rint (m_l + width * fract) - .5, height);
544 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
545 layout->set_text (_("Time"));
546 cr->set_source_rgba (.9, .9, .9, 1.0);
547 layout->get_pixel_size (w, h);
548 cr->move_to (rint (.5 * (m_l - w)), rint (.5 * (height - h)));
549 layout->show_in_cairo_context (cr);
552 CimgArea *tm = manage (new CimgArea (ytme));
553 vb->pack_start (*tm);
558 const size_t swh = sizeof (p->spectrum) / sizeof (float);
559 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
560 const size_t width = swh / height;
562 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
563 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
564 cr->set_operator (Cairo::OPERATOR_SOURCE);
565 cr->rectangle (0, 0, m_l, height);
566 cr->set_source_rgba (0, 0, 0, 0);
568 cr->rectangle (m_l, 0, width, height);
569 cr->set_source_rgba (0, 0, 0, 1.0);
571 cr->set_operator (Cairo::OPERATOR_OVER);
573 for (size_t x = 0 ; x < width; ++x) {
574 for (size_t y = 0 ; y < height; ++y) {
575 const float pk = p->spectrum[x][y];
576 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
577 ArdourCanvas::set_source_rgba (cr, c);
578 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
584 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
585 layout->set_text (_("Hz"));
586 layout->get_pixel_size (w, h);
587 cr->move_to (rint (.5 * (m_l - h)), rint ((height + w) * .5));
588 cr->set_source_rgba (.9, .9, .9, 1.0);
590 cr->rotate (M_PI / -2.0);
591 layout->show_in_cairo_context (cr);
595 cr->set_line_width (1.0);
596 cr->set_dash (dashes, 2.0);
597 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
599 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
600 //XAXISLABEL (p->freq[0], _("50Hz"));
601 XAXISLABEL (p->freq[1], _("100"));
602 XAXISLABEL (p->freq[2], _("500"));
603 XAXISLABEL (p->freq[3], _("1K"));
604 XAXISLABEL (p->freq[4], _("5K"));
605 XAXISLABEL (p->freq[5], _("10K"));
608 CimgArea *sp = manage (new CimgArea (spec));
609 vb->pack_start (*sp);
612 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
615 pages.set_show_tabs (true);
617 pages.set_name ("ExportReportNotebook");
618 pages.set_current_page (0);
620 get_vbox ()->set_spacing (4);
621 get_vbox ()->pack_start (pages, false, false);
624 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
625 // TODO need a reference to the current page.. and Time-axis image-surface...
626 //_session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
629 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
630 add_button (Stock::CLOSE, RESPONSE_CLOSE);
632 set_default_response (RESPONSE_CLOSE);
633 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
634 stop_btn->set_sensitive (false);
641 while (ArdourDialog::run () != RESPONSE_CLOSE) { }
643 _session->cancel_audition();
645 return RESPONSE_CLOSE;
649 ExportReport::open_folder (std::string p)
651 PBD::open_uri (Glib::path_get_dirname(p));
655 ExportReport::audition_active (bool active)
657 stop_btn->set_sensitive (active);
661 ExportReport::audition (std::string path, unsigned n_chn)
664 _session->cancel_audition();
666 /* can't really happen, unless the user replaces the file while the dialog is open.. */
667 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
668 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
671 if (SMFSource::valid_midi_file (path)) { return; }
673 boost::shared_ptr<Region> r;
675 boost::shared_ptr<AudioFileSource> afs;
676 bool old_sbp = AudioSource::get_build_peakfiles ();
678 /* don't even think of building peakfiles for these files */
679 AudioSource::set_build_peakfiles (false);
681 for (int n = 0; n < n_chn; ++n) {
683 afs = boost::dynamic_pointer_cast<AudioFileSource> (
684 SourceFactory::createExternal (DataType::AUDIO, *_session,
686 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
687 if (afs->sample_rate() != _session->nominal_frame_rate()) {
688 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcBest));
689 srclist.push_back(sfs);
691 srclist.push_back(afs);
693 } catch (failed_constructor& err) {
694 PBD::error << _("Could not access soundfile: ") << path << endmsg;
695 AudioSource::set_build_peakfiles (old_sbp);
700 AudioSource::set_build_peakfiles (old_sbp);
702 if (srclist.empty()) {
706 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
707 std::string rname = region_name_from_path (afs->path(), false);
709 PBD::PropertyList plist;
711 plist.add (ARDOUR::Properties::start, 0);
712 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
713 plist.add (ARDOUR::Properties::name, rname);
714 plist.add (ARDOUR::Properties::layer, 0);
716 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
719 _session->audition_region(r);
723 ExportReport::stop_audition ()
726 _session->cancel_audition();