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 std::list<CimgArea*> playhead_widgets;
83 l = manage (new Label (_("File:"), ALIGN_END));
84 t->attach (*l, 0, 1, 0, 1);
85 l = manage (new Label ());
86 l->set_ellipsize (Pango::ELLIPSIZE_START);
87 l->set_width_chars (64);
88 l->set_max_width_chars (64);
90 l->set_alignment (ALIGN_START, ALIGN_CENTER);
91 t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
93 Button *b = manage (new Button (_("Open Folder")));
94 t->attach (*b, 3, 4, 0, 1, FILL, SHRINK);
95 b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
97 Button *start_btn = manage (new Button (_("Audition")));
98 t->attach (*start_btn, 3, 4, 1, 2, FILL, SHRINK);
103 framecnt_t file_length = 0;
104 framecnt_t sample_rate = 0;
105 framecnt_t start_off = 0;
106 unsigned int channels = 0;
108 if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
111 file_length = info.length;
112 sample_rate = info.samplerate;
113 start_off = info.timecode;
114 channels = info.channels;
116 /* File Info Table */
118 framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
119 double src_coef = (double) nfr / info.samplerate;
121 l = manage (new Label (_("Format:"), ALIGN_END));
122 t->attach (*l, 0, 1, 1, 2);
123 std::string fmt = info.format_name;
124 std::replace (fmt.begin (), fmt.end (), '\n', ' ');
125 l = manage (new Label ());
126 l->set_ellipsize (Pango::ELLIPSIZE_START);
127 l->set_width_chars (64);
128 l->set_max_width_chars (64);
130 l->set_alignment (ALIGN_START, ALIGN_CENTER);
131 t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
133 l = manage (new Label (_("Channels:"), ALIGN_END));
134 t->attach (*l, 0, 1, 2, 3);
135 l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
136 t->attach (*l, 1, 2, 2, 3);
138 l = manage (new Label (_("Sample rate:"), ALIGN_END));
139 t->attach (*l, 0, 1, 3, 4);
140 l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
141 t->attach (*l, 1, 2, 3, 4);
143 l = manage (new Label (_("Duration:"), ALIGN_END));
144 t->attach (*l, 2, 3, 2, 3);
145 clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
146 clock->set_session (_session);
147 clock->set_mode (AudioClock::MinSec);
148 clock->set (info.length * src_coef + 0.5, true);
149 t->attach (*clock, 3, 4, 2, 3);
151 l = manage (new Label (_("Timecode:"), ALIGN_END));
152 t->attach (*l, 2, 3, 3, 4);
153 clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
154 clock->set_session (_session);
155 clock->set_mode (AudioClock::Timecode);
156 clock->set (info.timecode * src_coef + 0.5, true);
157 t->attach (*clock, 3, 4, 3, 4);
159 l = manage (new Label (_("Error:"), ALIGN_END));
160 t->attach (*l, 0, 1, 1, 2);
161 l = manage (new Label (errmsg, ALIGN_START));
162 t->attach (*l, 1, 4, 1, 2);
165 if (channels > 0 && file_length > 0 && sample_rate > 0 && _session) {
166 start_btn->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::audition), path, channels, page));
168 start_btn->set_sensitive (false);
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 mnw = 0; // max numeric width
194 int lin[4] = { 0, 0, 0, 0 }; // max line height
196 TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
198 TXTSIZE(0, _("Peak:"), get_SmallFont);
199 TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
200 TXTSIZE(2, _("True Peak:"), get_SmallFont);
201 TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
203 TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
204 TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
205 TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
206 TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
209 const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] + 8;
210 const int hh = std::max (100, ht);
211 int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800; // margin left
213 int mml = 0; // min margin left -- ensure left margin is wide enough
214 TXTWIDTH (_("Time"), get_SmallFont);
215 TXTWIDTH (_("100"), get_SmallMonospaceFont);
216 m_l = (std::max (m_l, mml + 8) + 3) & ~3;
218 mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800) / 2;
219 const int nw2 = mnw / 2; // nums, horizontal center
222 y0[0] = (hh - ht) * .5 + lin[0] * .25;
223 y0[1] = y0[0] + lin[0] * 1.25;
224 y0[2] = y0[1] + lin[1] * 1.25;
225 y0[3] = y0[2] + lin[2] * 1.25;
228 { /* peak, loudness and R128 histogram */
229 Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
230 Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
231 Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
233 /* peak and true-peak numerics */
234 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
235 cr->set_source_rgba (0, 0, 0, 1.0);
238 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
239 layout->set_alignment (Pango::ALIGN_LEFT);
240 layout->set_text (_("Peak:"));
241 layout->get_pixel_size (w, h);
242 cr->move_to (rint (nw2 - w * .5), y0[0]);
243 cr->set_source_rgba (.7, .7, .7, 1.0);
244 layout->show_in_cairo_context (cr);
246 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
247 layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
248 layout->get_pixel_size (w, h);
249 cr->move_to (rint (nw2 - w * .5), y0[1]);
250 if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
251 else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
252 layout->show_in_cairo_context (cr);
255 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
256 layout->set_text (_("True Peak:"));
257 layout->get_pixel_size (w, h);
258 cr->move_to (rint (nw2 - w * .5), y0[2]);
259 cr->set_source_rgba (.7, .7, .7, 1.0);
260 layout->show_in_cairo_context (cr);
262 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
263 layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
264 layout->get_pixel_size (w, h);
265 cr->move_to (rint (nw2 - w * .5), y0[3]);
266 if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
267 else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
268 layout->show_in_cairo_context (cr);
273 /* EBU R128 numerics */
274 cr = Cairo::Context::create (ebur);
275 cr->set_source_rgba (0, 0, 0, 1.0);
278 cr->set_source_rgba (.7, .7, .7, 1.0);
280 if (!i->second->have_loudness) {
281 layout->set_alignment (Pango::ALIGN_CENTER);
282 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
283 layout->set_text (_("Not\nAvailable"));
284 layout->get_pixel_size (w, h);
285 cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
286 layout->show_in_cairo_context (cr);
288 else if (p->loudness == -200 && p->loudness_range == 0) {
289 layout->set_alignment (Pango::ALIGN_CENTER);
290 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
291 layout->set_text (_("Not\nAvailable"));
292 layout->get_pixel_size (w, h);
293 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .6));
294 layout->show_in_cairo_context (cr);
297 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
298 layout->set_text (_("(too short integration time)"));
299 layout->get_pixel_size (w, h);
300 cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
301 layout->show_in_cairo_context (cr);
304 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
305 layout->set_alignment (Pango::ALIGN_LEFT);
306 layout->set_text (_("Integrated Loudness:"));
307 layout->get_pixel_size (w, h);
308 cr->move_to (rint (nw2 - w * .5), y0[0]);
309 layout->show_in_cairo_context (cr);
311 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
312 layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
313 layout->get_pixel_size (w, h);
314 cr->move_to (rint (nw2 - w * .5), y0[1]);
315 layout->show_in_cairo_context (cr);
317 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
318 layout->set_text (_("Loudness Range:"));
319 layout->get_pixel_size (w, h);
320 cr->move_to (rint (nw2 - w * .5), y0[2]);
321 layout->show_in_cairo_context (cr);
323 layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
324 layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
325 layout->get_pixel_size (w, h);
326 cr->move_to (rint (nw2 - w * .5), y0[3]);
327 layout->show_in_cairo_context (cr);
331 /* draw loudness histogram */
332 cr = Cairo::Context::create (hist);
333 cr->set_source_rgba (0, 0, 0, 1.0);
336 cr->set_source_rgba (.7, .7, .7, 1.0);
337 cr->set_line_width (1.0);
339 if (p->loudness_hist_max > 0 && i->second->have_loudness) {
340 for (size_t x = 0 ; x < 510; ++x) {
341 cr->move_to (x - .5, hh);
342 cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
347 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
348 layout->set_alignment (Pango::ALIGN_CENTER);
351 layout->set_text (_("LUFS\n(short)"));
352 layout->get_pixel_size (w, h);
353 Gtkmm2ext::rounded_rectangle (cr, 5, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
354 cr->set_source_rgba (.1, .1, .1, 0.7);
357 cr->move_to (6, rint (.5 * (hh + w)));
358 cr->set_source_rgba (.9, .9, .9, 1.0);
359 cr->rotate (M_PI / -2.0);
360 layout->show_in_cairo_context (cr);
364 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
365 layout->set_alignment (Pango::ALIGN_LEFT);
366 for (int g = -53; g <= -8; g += 5) {
367 // grid-lines. [110] -59LUFS .. [650]: -5 LUFS
368 layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
369 layout->get_pixel_size (w, h);
371 cr->set_operator (Cairo::OPERATOR_OVER);
372 Gtkmm2ext::rounded_rectangle (cr,
373 rint ((g + 59.0) * 10.0 - h * .5), 5,
375 const float pk = (g + 59.0) / 54.0;
376 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
377 ArdourCanvas::set_source_rgba (cr, c);
381 cr->set_source_rgba (.9, .9, .9, 1.0);
382 cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
383 cr->rotate (M_PI / -2.0);
384 layout->show_in_cairo_context (cr);
387 cr->set_operator (Cairo::OPERATOR_ADD);
389 cr->set_source_rgba (.3, .3, .3, 1.0);
390 cr->set_dash (dashes, 1.0);
391 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
392 cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
393 cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
400 CimgArea *nu = manage (new CimgArea (nums));
401 CimgArea *eb = manage (new CimgArea (ebur));
402 CimgArea *hi = manage (new CimgArea (hist));
403 HBox *hb = manage (new HBox ());
405 hb->pack_start (*nu, false, false);
406 hb->pack_start (*hi, false, false);
407 hb->pack_start (*eb, false, false);
408 vb->pack_start (*hb, false, false);
411 #define XAXISLABEL(POS, TXT) { \
412 const float yy = rint (POS); \
413 layout->set_text (TXT); \
414 layout->get_pixel_size (w, h); \
415 cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
416 cr->set_source_rgba (.9, .9, .9, 1.0); \
417 cr->set_operator (Cairo::OPERATOR_OVER); \
418 layout->show_in_cairo_context (cr); \
419 cr->move_to (m_l - 4, yy - .5); \
420 cr->line_to (m_l + width, yy - .5); \
421 cr->set_source_rgba (.3, .3, .3, 1.0); \
422 cr->set_operator (Cairo::OPERATOR_ADD); \
426 for (uint32_t c = 0; c < p->n_channels; ++c) {
428 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
429 const float height_2 = std::min (100, 8 * lin[0] / (int) p->n_channels); // TODO refine
431 Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, 2 * height_2);
432 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
433 cr->set_operator (Cairo::OPERATOR_SOURCE);
434 cr->rectangle (0, 0, m_l, 2 * height_2);
435 cr->set_source_rgba (0, 0, 0, 0);
437 cr->rectangle (m_l, 0, width, 2 * height_2);
438 cr->set_source_rgba (0, 0, 0, 1.0);
440 cr->set_operator (Cairo::OPERATOR_OVER);
442 cr->set_source_rgba (.7, .7, .7, 1.0);
443 cr->set_line_width (1.0);
444 for (size_t x = 0 ; x < width; ++x) {
445 cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
446 cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
451 cr->set_source_rgba (1.0, 0, 0, 1.0);
452 for (size_t x = 0 ; x < width; ++x) {
453 if (p->peaks[c][x].max >= 1.0) {
454 cr->move_to (m_l + x - .5, 0);
455 cr->line_to (m_l + x - .5, height_2 * .22);
457 if (p->peaks[c][x].min <= -1.0) {
458 cr->move_to (m_l + x - .5, height_2 * 1.78);
459 cr->line_to (m_l + x - .5, height_2 * 2.);
466 cr->set_source_rgba (1.0, 0.7, 0, 0.7);
467 for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
468 cr->move_to (m_l + (*i) - .5, height_2 * 0.22);
469 cr->line_to (m_l + (*i) - .5, height_2 * 1.78);
474 cr->set_source_rgba (.3, .3, .3, 0.7);
475 cr->move_to (m_l + 0, height_2 - .5);
476 cr->line_to (m_l + width, height_2 - .5);
480 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
481 layout->set_alignment (Pango::ALIGN_LEFT);
482 layout->set_text (_("dBFS"));
483 layout->get_pixel_size (w, h);
484 cr->move_to (rint (.5 * (m_l - h)), rint (height_2 + w * .5));
485 cr->set_source_rgba (.9, .9, .9, 1.0);
487 cr->rotate (M_PI / -2.0);
488 layout->show_in_cairo_context (cr);
492 cr->set_line_width (1.0);
493 cr->set_dash (dashes, 2.0);
494 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
496 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
497 XAXISLABEL (height_2 * 0.6452, _("-9"));
498 XAXISLABEL (height_2 * 1.3548, _("-9"));
499 XAXISLABEL (height_2 * 0.2921, _("-3"));
500 XAXISLABEL (height_2 * 1.7079, _("-3"));
503 CimgArea *wv = manage (new CimgArea (wave));
504 wv->set_audition_axis (m_l, width);
505 playhead_widgets.push_back (wv);
506 wv->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
507 vb->pack_start (*wv);
510 if (channels > 0 && file_length > 0 && sample_rate > 0)
512 /* Time Axis -- re-use waveform width */
513 const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
514 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
515 layout->set_text (_("00:00:00.000"));
516 layout->get_pixel_size (w, h);
517 int height = h * 1.75;
518 Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
519 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
520 cr->set_operator (Cairo::OPERATOR_SOURCE);
521 cr->set_source_rgba (0, 0, 0, 1.0);
523 cr->rectangle (0, 0, m_l, height);
524 cr->set_source_rgba (0, 0, 0, 0);
526 cr->set_operator (Cairo::OPERATOR_OVER);
528 cr->set_line_width (1.0);
529 for (int i = 0; i <= 4; ++i) {
530 const float fract = (float) i / 4.0;
531 // " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
532 const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
535 AudioClock::print_minsec (start_off + file_length * fract,
536 buf, sizeof (buf), sample_rate);
538 layout->set_text (buf);
539 layout->get_pixel_size (w, h);
540 cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
541 cr->set_source_rgba (.9, .9, .9, 1.0);
542 layout->show_in_cairo_context (cr);
544 cr->set_source_rgba (.7, .7, .7, 1.0);
545 cr->move_to (rint (m_l + width * fract) - .5, 0);
546 cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
547 cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
548 cr->line_to (rint (m_l + width * fract) - .5, height);
552 layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
553 layout->set_text (_("Time"));
554 cr->set_source_rgba (.9, .9, .9, 1.0);
555 layout->get_pixel_size (w, h);
556 cr->move_to (rint (.5 * (m_l - w)), rint (.5 * (height - h)));
557 layout->show_in_cairo_context (cr);
560 CimgArea *tm = manage (new CimgArea (ytme));
561 tm->set_audition_axis (m_l, width, true);
562 playhead_widgets.push_back (tm);
563 tm->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
564 vb->pack_start (*tm);
569 const size_t swh = sizeof (p->spectrum) / sizeof (float);
570 const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
571 const size_t width = swh / height;
573 Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
574 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
575 cr->set_operator (Cairo::OPERATOR_SOURCE);
576 cr->rectangle (0, 0, m_l, height);
577 cr->set_source_rgba (0, 0, 0, 0);
579 cr->rectangle (m_l, 0, width, height);
580 cr->set_source_rgba (0, 0, 0, 1.0);
582 cr->set_operator (Cairo::OPERATOR_OVER);
584 for (size_t x = 0 ; x < width; ++x) {
585 for (size_t y = 0 ; y < height; ++y) {
586 const float pk = p->spectrum[x][y];
587 ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
588 ArdourCanvas::set_source_rgba (cr, c);
589 cr->rectangle (m_l + x - .5, y - .5, 1, 1);
595 layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
596 layout->set_text (_("Hz"));
597 layout->get_pixel_size (w, h);
598 cr->move_to (rint (.5 * (m_l - h)), rint ((height + w) * .5));
599 cr->set_source_rgba (.9, .9, .9, 1.0);
601 cr->rotate (M_PI / -2.0);
602 layout->show_in_cairo_context (cr);
606 cr->set_line_width (1.0);
607 cr->set_dash (dashes, 2.0);
608 cr->set_line_cap (Cairo::LINE_CAP_ROUND);
610 layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
611 //XAXISLABEL (p->freq[0], _("50Hz"));
612 XAXISLABEL (p->freq[1], _("100"));
613 XAXISLABEL (p->freq[2], _("500"));
614 XAXISLABEL (p->freq[3], _("1K"));
615 XAXISLABEL (p->freq[4], _("5K"));
616 XAXISLABEL (p->freq[5], _("10K"));
619 CimgArea *sp = manage (new CimgArea (spec));
620 sp->set_audition_axis (m_l, width);
621 playhead_widgets.push_back (sp);
622 sp->seek_playhead.connect (sigc::bind<0> (sigc::mem_fun (*this, &ExportReport::audition_seek), page));
623 vb->pack_start (*sp);
626 timeline[page] = playhead_widgets;
627 pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
628 pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
631 pages.set_show_tabs (true);
633 pages.set_name ("ExportReportNotebook");
634 pages.set_current_page (0);
636 get_vbox ()->set_spacing (4);
637 get_vbox ()->pack_start (pages, false, false);
640 _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
641 _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
644 stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
645 add_button (Stock::CLOSE, RESPONSE_CLOSE);
647 set_default_response (RESPONSE_CLOSE);
648 stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
649 stop_btn->set_sensitive (false);
657 int i = ArdourDialog::run ();
658 if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
664 _session->cancel_audition();
666 return RESPONSE_CLOSE;
670 ExportReport::open_folder (std::string p)
672 PBD::open_uri (Glib::path_get_dirname(p));
676 ExportReport::audition_active (bool active)
678 stop_btn->set_sensitive (active);
679 if (!active && _audition_num == _page_num) {
680 for (std::list<CimgArea*>::const_iterator i = timeline[_audition_num].begin();
681 i != timeline[_audition_num].end();
683 (*i)->set_playhead (-1);
689 ExportReport::audition (std::string path, unsigned n_chn, int page)
692 _session->cancel_audition();
694 /* can't really happen, unless the user replaces the file while the dialog is open.. */
695 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
696 PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
699 if (SMFSource::valid_midi_file (path)) { return; }
701 boost::shared_ptr<Region> r;
703 boost::shared_ptr<AudioFileSource> afs;
704 bool old_sbp = AudioSource::get_build_peakfiles ();
706 /* don't even think of building peakfiles for these files */
707 AudioSource::set_build_peakfiles (false);
709 for (unsigned int n = 0; n < n_chn; ++n) {
711 afs = boost::dynamic_pointer_cast<AudioFileSource> (
712 SourceFactory::createExternal (DataType::AUDIO, *_session,
714 Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
715 if (afs->sample_rate() != _session->nominal_frame_rate()) {
716 boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
717 srclist.push_back(sfs);
719 srclist.push_back(afs);
721 } catch (failed_constructor& err) {
722 PBD::error << _("Could not access soundfile: ") << path << endmsg;
723 AudioSource::set_build_peakfiles (old_sbp);
728 AudioSource::set_build_peakfiles (old_sbp);
730 if (srclist.empty()) {
734 afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
735 std::string rname = region_name_from_path (afs->path(), false);
737 PBD::PropertyList plist;
739 plist.add (ARDOUR::Properties::start, 0);
740 plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
741 plist.add (ARDOUR::Properties::name, rname);
742 plist.add (ARDOUR::Properties::layer, 0);
744 r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
747 _session->audition_region(r);
748 _audition_num = page;
752 ExportReport::stop_audition ()
754 if (_audition_num == _page_num) {
755 for (std::list<CimgArea*>::const_iterator i = timeline[_audition_num].begin();
756 i != timeline[_audition_num].end();
758 (*i)->set_playhead (-1);
762 _session->cancel_audition();
768 ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
770 if (_audition_num == _page_num) {
771 for (std::list<CimgArea*>::const_iterator i = timeline[_audition_num].begin();
772 i != timeline[_audition_num].end();
774 (*i)->set_playhead (-1);
777 _page_num = page_num;
781 ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
783 if (_audition_num == _page_num) {
784 const float p = (float)pos / len;
785 for (std::list<CimgArea*>::const_iterator i = timeline[_audition_num].begin();
786 i != timeline[_audition_num].end();
788 (*i)->set_playhead (p);
794 ExportReport::audition_seek (int page, float pos)
796 if (_audition_num == page && _session) {
797 _session->the_auditioner()->seek_to_percent (100.f * pos);