ardour/gtk2_ardour/export_report.cc

767 lines
26 KiB
C++
Raw Normal View History

2016-02-09 21:06:47 -05:00
/*
* Copyright (C) 2016 Robin Gareus <robin@gareus.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2016-02-11 08:07:32 -05:00
#include <algorithm>
#include <pangomm/layout.h>
2016-02-09 21:06:47 -05:00
#include <gtkmm/label.h>
#include <gtkmm/table.h>
2016-02-09 21:06:47 -05:00
#include <gtkmm/stock.h>
#include "pbd/openuri.h"
#include "gtkmm2ext/utils.h"
2016-02-10 15:45:34 -05:00
#include "gtkmm2ext/utils.h"
2016-02-09 21:06:47 -05:00
#include "canvas/utils.h"
#include "canvas/colors.h"
#include "ardour/audiofilesource.h"
#include "ardour/audioregion.h"
#include "ardour/auditioner.h"
#include "ardour/dB.h"
#include "ardour/region_factory.h"
#include "ardour/session.h"
#include "ardour/smf_source.h"
#include "ardour/source_factory.h"
#include "ardour/srcfilesource.h"
#include "audio_clock.h"
#include "ui_config.h"
#include "export_report.h"
2016-02-10 09:09:01 -05:00
2016-02-09 21:06:47 -05:00
#include "i18n.h"
using namespace Gtk;
using namespace ARDOUR;
ExportReport::ExportReport (Session* session, StatusPtr s)
2016-02-09 21:06:47 -05:00
: ArdourDialog (_("Export Report/Analysis"))
, status (s)
, _session (session)
2016-02-12 16:12:40 -05:00
, _audition_num (-1)
, _page_num (0)
2016-02-09 21:06:47 -05:00
{
2016-02-11 08:07:32 -05:00
set_resizable (false);
pages.set_scrollable ();
2016-02-09 21:06:47 -05:00
AnalysisResults & ar = status->result_map;
2016-02-10 15:45:34 -05:00
std::vector<double> dashes;
dashes.push_back (3.0);
dashes.push_back (5.0);
2016-02-12 16:12:40 -05:00
int page = 0;
for (AnalysisResults::iterator i = ar.begin (); i != ar.end (); ++i, ++page) {
2016-02-09 21:06:47 -05:00
Label *l;
VBox *vb = manage (new VBox ());
2016-02-11 08:07:32 -05:00
Table *t = manage (new Table (4, 4));
t->set_border_width (0);
2016-02-11 08:07:32 -05:00
t->set_spacings (4);
vb->set_spacing (4);
vb->set_border_width (4);
2016-02-11 08:07:32 -05:00
vb->pack_start (*t, false, false, 2);
std::string path = i->first;
2016-02-11 08:07:32 -05:00
ExportAnalysisPtr p = i->second;
l = manage (new Label (_("File:"), ALIGN_END));
t->attach (*l, 0, 1, 0, 1);
2016-02-11 08:07:32 -05:00
l = manage (new Label ());
l->set_ellipsize (Pango::ELLIPSIZE_START);
l->set_width_chars (64);
l->set_max_width_chars (64);
l->set_text (path);
l->set_alignment (ALIGN_START, ALIGN_CENTER);
t->attach (*l, 1, 3, 0, 1, FILL, SHRINK);
Button *b = manage (new Button (_("Open Folder")));
t->attach (*b, 3, 4, 0, 1, FILL, SHRINK);
b->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::open_folder), path));
Button *start_btn = manage (new Button (_("Audition")));
t->attach (*start_btn, 3, 4, 1, 2, FILL, SHRINK);
SoundFileInfo info;
std::string errmsg;
2016-02-11 08:07:32 -05:00
framecnt_t file_length = 0;
framecnt_t sample_rate = 0;
framecnt_t start_off = 0;
2016-02-12 16:12:40 -05:00
unsigned int channels = 0;
2016-02-11 08:07:32 -05:00
if (AudioFileSource::get_soundfile_info (path, info, errmsg)) {
AudioClock * clock;
2016-02-11 08:07:32 -05:00
file_length = info.length;
sample_rate = info.samplerate;
start_off = info.timecode;
channels = info.channels;
2016-02-11 08:07:32 -05:00
/* File Info Table */
framecnt_t const nfr = _session ? _session->nominal_frame_rate () : 25;
double src_coef = (double) nfr / info.samplerate;
2016-02-11 08:07:32 -05:00
l = manage (new Label (_("Format:"), ALIGN_END));
t->attach (*l, 0, 1, 1, 2);
2016-02-11 08:07:32 -05:00
std::string fmt = info.format_name;
std::replace (fmt.begin (), fmt.end (), '\n', ' ');
l = manage (new Label ());
l->set_ellipsize (Pango::ELLIPSIZE_START);
l->set_width_chars (64);
l->set_max_width_chars (64);
l->set_text (fmt);
l->set_alignment (ALIGN_START, ALIGN_CENTER);
t->attach (*l, 1, 3, 1, 2, FILL, SHRINK);
2016-02-11 08:07:32 -05:00
l = manage (new Label (_("Channels:"), ALIGN_END));
t->attach (*l, 0, 1, 2, 3);
l = manage (new Label (string_compose ("%1", info.channels), ALIGN_START));
2016-02-11 08:07:32 -05:00
t->attach (*l, 1, 2, 2, 3);
l = manage (new Label (_("Sample rate:"), ALIGN_END));
t->attach (*l, 0, 1, 3, 4);
l = manage (new Label (string_compose (_("%1 Hz"), info.samplerate), ALIGN_START));
t->attach (*l, 1, 2, 3, 4);
l = manage (new Label (_("Duration:"), ALIGN_END));
t->attach (*l, 2, 3, 2, 3);
clock = manage (new AudioClock ("sfboxLengthClock", true, "", false, false, true, false));
clock->set_session (_session);
clock->set_mode (AudioClock::MinSec);
clock->set (info.length * src_coef + 0.5, true);
t->attach (*clock, 3, 4, 2, 3);
l = manage (new Label (_("Timecode:"), ALIGN_END));
t->attach (*l, 2, 3, 3, 4);
clock = manage (new AudioClock ("sfboxTimecodeClock", true, "", false, false, false, false));
clock->set_session (_session);
clock->set_mode (AudioClock::Timecode);
clock->set (info.timecode * src_coef + 0.5, true);
t->attach (*clock, 3, 4, 3, 4);
} else {
l = manage (new Label (_("Error:"), ALIGN_END));
t->attach (*l, 0, 1, 1, 2);
l = manage (new Label (errmsg, ALIGN_START));
t->attach (*l, 1, 4, 1, 2);
}
2016-02-09 21:06:47 -05:00
2016-02-12 16:12:40 -05:00
if (channels > 0 && file_length > 0 && sample_rate > 0 && _session) {
start_btn->signal_clicked ().connect (sigc::bind (sigc::mem_fun (*this, &ExportReport::audition), path, channels, page));
} else {
start_btn->set_sensitive (false);
}
2016-02-11 08:07:32 -05:00
int w, h;
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (get_pango_context ());
2016-02-11 08:07:32 -05:00
// calc geometry of numerics
const float dbfs = accurate_coefficient_to_dB (p->peak);
const float dbtp = accurate_coefficient_to_dB (p->truepeak);
#define TXTSIZE(LINE, TXT, FONT) { \
layout->set_font_description (UIConfiguration::instance ().FONT ()); \
layout->set_text (TXT); \
layout->get_pixel_size (w, h); \
if (w > mnw) { mnw = w; } \
if (h > lin[LINE]) { lin[LINE] = h; } \
}
#define TXTWIDTH(TXT, FONT) { \
layout->set_font_description (UIConfiguration::instance ().FONT ()); \
layout->set_text (TXT); \
layout->get_pixel_size (w, h); \
if (w > mml) { mml = w; } \
}
int mnw = 0; // max numeric width
int lin[4] = { 0, 0, 0, 0 }; // max line height
2016-02-11 16:03:14 -05:00
TXTSIZE(0, _("(too short integration time)"), get_SmallFont);
2016-02-11 08:07:32 -05:00
TXTSIZE(0, _("Peak:"), get_SmallFont);
TXTSIZE(1, string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs), get_LargeFont);
TXTSIZE(2, _("True Peak:"), get_SmallFont);
TXTSIZE(3, string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp), get_LargeFont);
TXTSIZE(0, _("Integrated Loudness:"), get_SmallFont);
TXTSIZE(1, string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness), get_LargeFont);
TXTSIZE(2, _("Loudness Range:"), get_SmallFont);
TXTSIZE(3, string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range), get_LargeFont);
2016-02-10 09:09:01 -05:00
2016-02-11 08:07:32 -05:00
mnw += 8;
const int ht = lin[0] * 1.25 + lin[1] * 1.25 + lin[2] * 1.25 + lin[3] + 8;
const int hh = std::max (100, ht);
int m_l = 2 * mnw + /*hist-width*/ 540 + /*box spacing*/ 8 - /*peak-width*/ 800; // margin left
int mml = 0; // min margin left -- ensure left margin is wide enough
TXTWIDTH (_("Time"), get_SmallFont);
TXTWIDTH (_("100"), get_SmallMonospaceFont);
m_l = (std::max (m_l, mml + 8) + 3) & ~3;
mnw = (m_l - /*hist-width*/ 540 - /*box spacing*/ 8 + /*peak-width*/ 800) / 2;
const int nw2 = mnw / 2; // nums, horizontal center
int y0[4];
y0[0] = (hh - ht) * .5 + lin[0] * .25;
y0[1] = y0[0] + lin[0] * 1.25;
y0[2] = y0[1] + lin[1] * 1.25;
y0[3] = y0[2] + lin[2] * 1.25;
{ /* peak, loudness and R128 histogram */
Cairo::RefPtr<Cairo::ImageSurface> nums = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
Cairo::RefPtr<Cairo::ImageSurface> ebur = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, mnw, hh);
Cairo::RefPtr<Cairo::ImageSurface> hist = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 540, hh);
/* peak and true-peak numerics */
2016-02-10 09:09:01 -05:00
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (nums);
cr->set_source_rgba (0, 0, 0, 1.0);
2016-02-11 08:07:32 -05:00
cr->paint ();
2016-02-10 09:09:01 -05:00
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
layout->set_alignment (Pango::ALIGN_LEFT);
2016-02-11 08:07:32 -05:00
layout->set_text (_("Peak:"));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (nw2 - w * .5), y0[0]);
cr->set_source_rgba (.7, .7, .7, 1.0);
layout->show_in_cairo_context (cr);
2016-02-11 08:07:32 -05:00
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
layout->set_text (string_compose (_("%1 dBFS"), std::setprecision (1), std::fixed, dbfs));
2016-02-11 08:07:32 -05:00
layout->get_pixel_size (w, h);
cr->move_to (rint (nw2 - w * .5), y0[1]);
if (dbfs >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
else if (dbfs > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
layout->show_in_cairo_context (cr);
2016-02-11 08:07:32 -05:00
if (p->have_dbtp) {
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
layout->set_text (_("True Peak:"));
layout->get_pixel_size (w, h);
cr->move_to (rint (nw2 - w * .5), y0[2]);
cr->set_source_rgba (.7, .7, .7, 1.0);
layout->show_in_cairo_context (cr);
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
layout->set_text (string_compose (_("%1 dBTP"), std::setprecision (1), std::fixed, dbtp));
2016-02-11 08:07:32 -05:00
layout->get_pixel_size (w, h);
cr->move_to (rint (nw2 - w * .5), y0[3]);
if (dbtp >= 0.f) { cr->set_source_rgba (1.0, .1, .1, 1.0); }
else if (dbtp > -1.f) { cr->set_source_rgba (1.0, .7, .0, 1.0); }
2016-02-11 08:07:32 -05:00
layout->show_in_cairo_context (cr);
}
nums->flush ();
/* EBU R128 numerics */
cr = Cairo::Context::create (ebur);
cr->set_source_rgba (0, 0, 0, 1.0);
cr->paint ();
2016-02-10 09:09:01 -05:00
cr->set_source_rgba (.7, .7, .7, 1.0);
if (!i->second->have_loudness) {
layout->set_alignment (Pango::ALIGN_CENTER);
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
2016-02-11 16:03:14 -05:00
layout->set_text (_("Not\nAvailable"));
layout->get_pixel_size (w, h);
2016-02-11 16:03:14 -05:00
cr->move_to (rint (nw2 - w * .5), rint ((hh - h) * .5));
layout->show_in_cairo_context (cr);
}
else if (p->loudness == -200 && p->loudness_range == 0) {
layout->set_alignment (Pango::ALIGN_CENTER);
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
2016-02-11 16:03:14 -05:00
layout->set_text (_("Not\nAvailable"));
layout->get_pixel_size (w, h);
2016-02-11 16:03:14 -05:00
cr->move_to (rint (nw2 - w * .5), rint (hh * .5 - h * .6));
layout->show_in_cairo_context (cr);
2016-02-11 08:07:32 -05:00
int yy = h * .5;
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
layout->set_text (_("(too short integration time)"));
layout->get_pixel_size (w, h);
2016-02-11 16:03:14 -05:00
cr->move_to (rint (nw2 - w * .5), rint (hh * .5 + yy));
layout->show_in_cairo_context (cr);
} else {
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
layout->set_alignment (Pango::ALIGN_LEFT);
2016-02-11 08:07:32 -05:00
layout->set_text (_("Integrated Loudness:"));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (nw2 - w * .5), y0[0]);
layout->show_in_cairo_context (cr);
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
2016-02-11 08:07:32 -05:00
layout->set_text (string_compose (_("%1 LUFS"), std::setprecision (1), std::fixed, p->loudness));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (nw2 - w * .5), y0[1]);
layout->show_in_cairo_context (cr);
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
2016-02-11 08:07:32 -05:00
layout->set_text (_("Loudness Range:"));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (nw2 - w * .5), y0[2]);
layout->show_in_cairo_context (cr);
layout->set_font_description (UIConfiguration::instance ().get_LargeFont ());
2016-02-11 08:07:32 -05:00
layout->set_text (string_compose (_("%1 LU"), std::setprecision (1), std::fixed, p->loudness_range));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (nw2 - w * .5), y0[3]);
layout->show_in_cairo_context (cr);
}
2016-02-11 08:07:32 -05:00
ebur->flush ();
2016-02-10 09:09:01 -05:00
/* draw loudness histogram */
cr = Cairo::Context::create (hist);
cr->set_source_rgba (0, 0, 0, 1.0);
2016-02-11 08:07:32 -05:00
cr->paint ();
cr->set_source_rgba (.7, .7, .7, 1.0);
cr->set_line_width (1.0);
if (p->loudness_hist_max > 0 && i->second->have_loudness) {
for (size_t x = 0 ; x < 510; ++x) {
2016-02-11 08:07:32 -05:00
cr->move_to (x - .5, hh);
cr->line_to (x - .5, (float) hh * (1.0 - p->loudness_hist[x] / (float) p->loudness_hist_max));
cr->stroke ();
}
}
2016-02-11 08:07:32 -05:00
layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
layout->set_alignment (Pango::ALIGN_CENTER);
2016-02-11 08:07:32 -05:00
// Label
layout->set_text (_("LUFS\n(short)"));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
Gtkmm2ext::rounded_rectangle (cr, 5, rint (.5 * (hh - w) - 1), h + 2, w + 2, 4);
cr->set_source_rgba (.1, .1, .1, 0.7);
cr->fill ();
2016-02-11 08:07:32 -05:00
cr->save ();
cr->move_to (6, rint (.5 * (hh + w)));
cr->set_source_rgba (.9, .9, .9, 1.0);
2016-02-11 08:07:32 -05:00
cr->rotate (M_PI / -2.0);
layout->show_in_cairo_context (cr);
2016-02-11 08:07:32 -05:00
cr->restore ();
2016-02-11 08:07:32 -05:00
// x-Axis
layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
layout->set_alignment (Pango::ALIGN_LEFT);
for (int g = -53; g <= -8; g += 5) {
// grid-lines. [110] -59LUFS .. [650]: -5 LUFS
layout->set_text (string_compose ("%1", std::setw(3), std::setfill(' '), g));
layout->get_pixel_size (w, h);
cr->set_operator (Cairo::OPERATOR_OVER);
Gtkmm2ext::rounded_rectangle (cr,
rint ((g + 59.0) * 10.0 - h * .5), 5,
h + 2, w + 2, 4);
const float pk = (g + 59.0) / 54.0;
ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4, .6);
ArdourCanvas::set_source_rgba (cr, c);
cr->fill ();
cr->save ();
cr->set_source_rgba (.9, .9, .9, 1.0);
cr->move_to (rint ((g + 59.0) * 10.0 - h * .5), w + 6.0);
cr->rotate (M_PI / -2.0);
layout->show_in_cairo_context (cr);
cr->restore ();
cr->set_operator (Cairo::OPERATOR_ADD);
cr->save ();
cr->set_source_rgba (.3, .3, .3, 1.0);
cr->set_dash (dashes, 1.0);
cr->set_line_cap (Cairo::LINE_CAP_ROUND);
cr->move_to (rint ((g + 59.0) * 10.0) + .5, w + 8.0);
2016-02-11 08:07:32 -05:00
cr->line_to (rint ((g + 59.0) * 10.0) + .5, hh);
cr->stroke ();
cr->restore ();
}
2016-02-10 09:09:01 -05:00
hist->flush ();
2016-02-11 08:07:32 -05:00
2016-02-10 09:09:01 -05:00
CimgArea *nu = manage (new CimgArea (nums));
2016-02-11 08:07:32 -05:00
CimgArea *eb = manage (new CimgArea (ebur));
2016-02-10 09:09:01 -05:00
CimgArea *hi = manage (new CimgArea (hist));
HBox *hb = manage (new HBox ());
2016-02-10 09:09:01 -05:00
hb->set_spacing (4);
2016-02-11 08:07:32 -05:00
hb->pack_start (*nu, false, false);
hb->pack_start (*hi, false, false);
hb->pack_start (*eb, false, false);
vb->pack_start (*hb, false, false);
2016-02-09 21:06:47 -05:00
}
2016-02-11 08:07:32 -05:00
#define XAXISLABEL(POS, TXT) { \
const float yy = rint (POS); \
layout->set_text (TXT); \
layout->get_pixel_size (w, h); \
cr->move_to (m_l - 8 - w, rint ((POS) - h * .5)); \
cr->set_source_rgba (.9, .9, .9, 1.0); \
cr->set_operator (Cairo::OPERATOR_OVER); \
layout->show_in_cairo_context (cr); \
cr->move_to (m_l - 4, yy - .5); \
cr->line_to (m_l + width, yy - .5); \
cr->set_source_rgba (.3, .3, .3, 1.0); \
cr->set_operator (Cairo::OPERATOR_ADD); \
cr->stroke (); \
}
for (uint32_t c = 0; c < p->n_channels; ++c) {
/* draw waveform */
const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
2016-02-11 08:07:32 -05:00
const float height_2 = std::min (100, 8 * lin[0] / (int) p->n_channels); // TODO refine
Cairo::RefPtr<Cairo::ImageSurface> wave = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, 2 * height_2);
2016-02-09 21:06:47 -05:00
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (wave);
2016-02-11 08:07:32 -05:00
cr->set_operator (Cairo::OPERATOR_SOURCE);
cr->rectangle (0, 0, m_l, 2 * height_2);
cr->set_source_rgba (0, 0, 0, 0);
cr->fill ();
cr->rectangle (m_l, 0, width, 2 * height_2);
2016-02-09 21:06:47 -05:00
cr->set_source_rgba (0, 0, 0, 1.0);
cr->fill ();
2016-02-11 08:07:32 -05:00
cr->set_operator (Cairo::OPERATOR_OVER);
2016-02-09 21:06:47 -05:00
cr->set_source_rgba (.7, .7, .7, 1.0);
cr->set_line_width (1.0);
for (size_t x = 0 ; x < width; ++x) {
2016-02-11 08:07:32 -05:00
cr->move_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].max);
cr->line_to (m_l + x - .5, height_2 - height_2 * p->peaks[c][x].min);
2016-02-09 21:06:47 -05:00
}
cr->stroke ();
// > 0dBFS
cr->set_source_rgba (1.0, 0, 0, 1.0);
for (size_t x = 0 ; x < width; ++x) {
if (p->peaks[c][x].max >= 1.0) {
cr->move_to (m_l + x - .5, 0);
cr->line_to (m_l + x - .5, height_2 * .22);
}
if (p->peaks[c][x].min <= -1.0) {
cr->move_to (m_l + x - .5, height_2 * 1.78);
cr->line_to (m_l + x - .5, height_2 * 2.);
}
}
cr->stroke ();
// > -1dBTP
cr->set_source_rgba (1.0, 0.7, 0, 0.7);
for (std::set<framepos_t>::const_iterator i = p->truepeakpos[c].begin (); i != p->truepeakpos[c].end (); ++i) {
cr->move_to (m_l + (*i) - .5, height_2 * 0.22);
cr->line_to (m_l + (*i) - .5, height_2 * 1.78);
cr->stroke ();
}
2016-02-10 15:45:34 -05:00
// zero line
cr->set_source_rgba (.3, .3, .3, 0.7);
2016-02-11 08:07:32 -05:00
cr->move_to (m_l + 0, height_2 - .5);
cr->line_to (m_l + width, height_2 - .5);
cr->stroke ();
2016-02-11 08:07:32 -05:00
// Unit
layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
2016-02-11 08:07:32 -05:00
layout->set_alignment (Pango::ALIGN_LEFT);
2016-02-10 15:45:34 -05:00
layout->set_text (_("dBFS"));
layout->get_pixel_size (w, h);
2016-02-11 08:07:32 -05:00
cr->move_to (rint (.5 * (m_l - h)), rint (height_2 + w * .5));
2016-02-10 15:45:34 -05:00
cr->set_source_rgba (.9, .9, .9, 1.0);
cr->save ();
cr->rotate (M_PI / -2.0);
layout->show_in_cairo_context (cr);
cr->restore ();
2016-02-11 08:07:32 -05:00
// x-Axis
cr->set_line_width (1.0);
cr->set_dash (dashes, 2.0);
cr->set_line_cap (Cairo::LINE_CAP_ROUND);
2016-02-10 15:45:34 -05:00
2016-02-11 08:07:32 -05:00
layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
XAXISLABEL (height_2 * 0.6452, _("-9"));
XAXISLABEL (height_2 * 1.3548, _("-9"));
XAXISLABEL (height_2 * 0.2921, _("-3"));
XAXISLABEL (height_2 * 1.7079, _("-3"));
2016-02-10 15:45:34 -05:00
wave->flush ();
2016-02-09 21:06:47 -05:00
CimgArea *wv = manage (new CimgArea (wave));
vb->pack_start (*wv);
}
2016-02-12 16:12:40 -05:00
if (channels > 0 && file_length > 0 && sample_rate > 0)
2016-02-11 08:07:32 -05:00
{
/* Time Axis -- re-use waveform width */
const size_t width = sizeof (p->peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4;
layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
layout->set_text (_("00:00:00.000"));
layout->get_pixel_size (w, h);
int height = h * 1.75;
Cairo::RefPtr<Cairo::ImageSurface> ytme = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (ytme);
cr->set_operator (Cairo::OPERATOR_SOURCE);
cr->set_source_rgba (0, 0, 0, 1.0);
cr->paint ();
cr->rectangle (0, 0, m_l, height);
cr->set_source_rgba (0, 0, 0, 0);
cr->fill ();
cr->set_operator (Cairo::OPERATOR_OVER);
cr->set_line_width (1.0);
for (int i = 0; i <= 4; ++i) {
const float fract = (float) i / 4.0;
// " XX:XX:XX.XXX" [space/minus] 12 chars = 13.
const float xalign = (i == 4) ? 1.0 : (i == 0) ? 1.0 / 13.0 : 7.0 / 13.0;
char buf[16];
AudioClock::print_minsec (start_off + file_length * fract,
buf, sizeof (buf), sample_rate);
layout->set_text (buf);
layout->get_pixel_size (w, h);
cr->move_to (rint (m_l + width * fract - w * xalign), rint (.5 * (height - h)));
cr->set_source_rgba (.9, .9, .9, 1.0);
layout->show_in_cairo_context (cr);
cr->set_source_rgba (.7, .7, .7, 1.0);
cr->move_to (rint (m_l + width * fract) - .5, 0);
cr->line_to (rint (m_l + width * fract) - .5, ceil (height * .15));
cr->move_to (rint (m_l + width * fract) - .5, floor (height * .85));
cr->line_to (rint (m_l + width * fract) - .5, height);
cr->stroke ();
}
layout->set_font_description (UIConfiguration::instance ().get_SmallFont ());
layout->set_text (_("Time"));
cr->set_source_rgba (.9, .9, .9, 1.0);
layout->get_pixel_size (w, h);
cr->move_to (rint (.5 * (m_l - w)), rint (.5 * (height - h)));
layout->show_in_cairo_context (cr);
ytme->flush ();
CimgArea *tm = manage (new CimgArea (ytme));
2016-02-12 16:12:40 -05:00
tm->set_audition_axis (m_l, width);
timeline.push_back (tm);
2016-02-11 08:07:32 -05:00
vb->pack_start (*tm);
2016-02-12 16:12:40 -05:00
} else {
timeline.push_back (0);
2016-02-11 08:07:32 -05:00
}
2016-02-09 21:06:47 -05:00
{
2016-02-11 08:07:32 -05:00
/* Draw Spectrum */
const size_t swh = sizeof (p->spectrum) / sizeof (float);
const size_t height = sizeof (p->spectrum[0]) / sizeof (float);
const size_t width = swh / height;
2016-02-11 08:07:32 -05:00
Cairo::RefPtr<Cairo::ImageSurface> spec = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, m_l + width, height);
2016-02-09 21:06:47 -05:00
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (spec);
2016-02-11 08:07:32 -05:00
cr->set_operator (Cairo::OPERATOR_SOURCE);
cr->rectangle (0, 0, m_l, height);
cr->set_source_rgba (0, 0, 0, 0);
cr->fill ();
cr->rectangle (m_l, 0, width, height);
2016-02-09 21:06:47 -05:00
cr->set_source_rgba (0, 0, 0, 1.0);
cr->fill ();
2016-02-11 08:07:32 -05:00
cr->set_operator (Cairo::OPERATOR_OVER);
2016-02-09 21:06:47 -05:00
for (size_t x = 0 ; x < width; ++x) {
for (size_t y = 0 ; y < height; ++y) {
2016-02-10 09:09:01 -05:00
const float pk = p->spectrum[x][y];
2016-02-09 21:06:47 -05:00
ArdourCanvas::Color c = ArdourCanvas::hsva_to_color (252 - 260 * pk, .9, .3 + pk * .4);
ArdourCanvas::set_source_rgba (cr, c);
2016-02-11 08:07:32 -05:00
cr->rectangle (m_l + x - .5, y - .5, 1, 1);
2016-02-09 21:06:47 -05:00
cr->fill ();
}
}
2016-02-11 08:07:32 -05:00
// Unit
layout->set_font_description (UIConfiguration::instance ().get_SmallerFont ());
layout->set_text (_("Hz"));
layout->get_pixel_size (w, h);
cr->move_to (rint (.5 * (m_l - h)), rint ((height + w) * .5));
cr->set_source_rgba (.9, .9, .9, 1.0);
cr->save ();
cr->rotate (M_PI / -2.0);
layout->show_in_cairo_context (cr);
cr->restore ();
// x-Axis
cr->set_line_width (1.0);
cr->set_dash (dashes, 2.0);
cr->set_line_cap (Cairo::LINE_CAP_ROUND);
2016-02-11 08:07:32 -05:00
layout->set_font_description (UIConfiguration::instance ().get_SmallMonospaceFont ());
//XAXISLABEL (p->freq[0], _("50Hz"));
XAXISLABEL (p->freq[1], _("100"));
XAXISLABEL (p->freq[2], _("500"));
XAXISLABEL (p->freq[3], _("1K"));
XAXISLABEL (p->freq[4], _("5K"));
XAXISLABEL (p->freq[5], _("10K"));
2016-02-09 21:06:47 -05:00
spec->flush ();
CimgArea *sp = manage (new CimgArea (spec));
vb->pack_start (*sp);
}
pages.pages ().push_back (Notebook_Helpers::TabElem (*vb, Glib::path_get_basename (i->first)));
2016-02-12 16:12:40 -05:00
pages.signal_switch_page().connect (sigc::mem_fun (*this, &ExportReport::on_switch_page));
2016-02-09 21:06:47 -05:00
}
pages.set_show_tabs (true);
pages.show_all ();
pages.set_name ("ExportReportNotebook");
pages.set_current_page (0);
2016-02-11 08:07:32 -05:00
get_vbox ()->set_spacing (4);
get_vbox ()->pack_start (pages, false, false);
2016-02-09 21:06:47 -05:00
if (_session) {
_session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_active, this, _1), gui_context());
2016-02-12 16:12:40 -05:00
_session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&ExportReport::audition_progress, this, _1, _2), gui_context());
}
stop_btn = add_button (Stock::MEDIA_STOP, RESPONSE_ACCEPT);
add_button (Stock::CLOSE, RESPONSE_CLOSE);
set_default_response (RESPONSE_CLOSE);
stop_btn->signal_clicked().connect (sigc::mem_fun (*this, &ExportReport::stop_audition));
stop_btn->set_sensitive (false);
2016-02-09 21:06:47 -05:00
show_all ();
}
int
ExportReport::run ()
{
2016-02-12 16:12:40 -05:00
do {
int i = ArdourDialog::run ();
if (i == Gtk::RESPONSE_DELETE_EVENT || i == RESPONSE_CLOSE) {
break;
}
} while (1);
if (_session) {
_session->cancel_audition();
}
return RESPONSE_CLOSE;
2016-02-09 21:06:47 -05:00
}
void
ExportReport::open_folder (std::string p)
{
PBD::open_uri (Glib::path_get_dirname(p));
}
void
ExportReport::audition_active (bool active)
{
stop_btn->set_sensitive (active);
}
void
2016-02-12 16:12:40 -05:00
ExportReport::audition (std::string path, unsigned n_chn, int page)
{
assert (_session);
_session->cancel_audition();
/* can't really happen, unless the user replaces the file while the dialog is open.. */
if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
PBD::warning << string_compose(_("Could not read file: %1 (%2)."), path, strerror(errno)) << endmsg;
return;
}
if (SMFSource::valid_midi_file (path)) { return; }
boost::shared_ptr<Region> r;
SourceList srclist;
boost::shared_ptr<AudioFileSource> afs;
bool old_sbp = AudioSource::get_build_peakfiles ();
/* don't even think of building peakfiles for these files */
AudioSource::set_build_peakfiles (false);
2016-02-12 16:12:40 -05:00
for (unsigned int n = 0; n < n_chn; ++n) {
try {
afs = boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createExternal (DataType::AUDIO, *_session,
path, n,
Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
if (afs->sample_rate() != _session->nominal_frame_rate()) {
boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(*_session, afs, ARDOUR::SrcGood));
srclist.push_back(sfs);
} else {
srclist.push_back(afs);
}
} catch (failed_constructor& err) {
PBD::error << _("Could not access soundfile: ") << path << endmsg;
AudioSource::set_build_peakfiles (old_sbp);
return;
}
}
AudioSource::set_build_peakfiles (old_sbp);
if (srclist.empty()) {
return;
}
afs = boost::dynamic_pointer_cast<AudioFileSource> (srclist[0]);
std::string rname = region_name_from_path (afs->path(), false);
PBD::PropertyList plist;
plist.add (ARDOUR::Properties::start, 0);
plist.add (ARDOUR::Properties::length, srclist[0]->length(srclist[0]->timeline_position()));
plist.add (ARDOUR::Properties::name, rname);
plist.add (ARDOUR::Properties::layer, 0);
r = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (srclist, plist, false));
r->set_position(0);
_session->audition_region(r);
2016-02-12 16:12:40 -05:00
_audition_num = page;
}
void
ExportReport::stop_audition ()
{
2016-02-12 16:12:40 -05:00
if (_audition_num == _page_num) {
assert (timeline[_audition_num]);
timeline[_audition_num]->set_playhead (-1);
}
if (_session) {
_session->cancel_audition();
}
2016-02-12 16:12:40 -05:00
_audition_num = -1;
}
void
ExportReport::on_switch_page (GtkNotebookPage*, guint page_num)
{
if (_audition_num == _page_num) {
assert (timeline[_audition_num]);
timeline[_audition_num]->set_playhead (-1);
}
_page_num = page_num;
}
void
ExportReport::audition_progress (framecnt_t pos, framecnt_t len)
{
if (_audition_num == _page_num) {
assert (timeline[_audition_num]);
timeline[_audition_num]->set_playhead ((float)pos / len);
}
}