+2018-03-26 Carl Hetherington <cth@carlh.net>
+
+ * Add time axis to audio analysis (part of #1082).
+
+ * Note: from this point in the ChangeLog release versions
+ are marked using git tags and not written to the ChangeLog.
+
2018-03-25 Carl Hetherington <cth@carlh.net>
* Version 2.13.2 released.
_analysis->set_analysis_gain (ac->gain ());
}
+ _analysis->set_samples_per_point (_samples_per_point);
+ _analysis->set_sample_rate (_film->audio_frame_rate ());
_analysis->write (_film->audio_analysis_path (_playlist));
set_progress (1);
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
_loudness_range = f.optional_number_child<float> ("LoudnessRange");
_analysis_gain = f.optional_number_child<double> ("AnalysisGain");
+ _samples_per_point = f.optional_number_child<int64_t> ("SamplesPerPoint");
+ _sample_rate = f.optional_number_child<int64_t> ("SampleRate");
}
void
root->add_child("AnalysisGain")->add_child_text (raw_convert<string> (_analysis_gain.get ()));
}
+ if (_samples_per_point) {
+ root->add_child("SamplesPerPoint")->add_child_text (raw_convert<string> (_samples_per_point.get()));
+ }
+
+ if (_sample_rate) {
+ root->add_child("SampleRate")->add_child_text (raw_convert<string> (_sample_rate.get()));
+ }
+
doc->write_to_file_formatted (filename.string ());
}
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
_analysis_gain = gain;
}
+ boost::optional<int64_t> samples_per_point () const {
+ return _samples_per_point;
+ }
+
+ void set_samples_per_point (int64_t spp) {
+ _samples_per_point = spp;
+ }
+
+ boost::optional<int> sample_rate () const {
+ return _sample_rate;
+ }
+
+ void set_sample_rate (int sr) {
+ _sample_rate = sr;
+ }
+
void write (boost::filesystem::path);
float gain_correction (boost::shared_ptr<const Playlist> playlist);
* happened.
*/
boost::optional<double> _analysis_gain;
+ boost::optional<int64_t> _samples_per_point;
+ boost::optional<int> _sample_rate;
static int const _current_state_version;
};
double db_label_width;
int height;
int y_origin;
- float x_scale;
+ float x_scale; ///< pixels per data point
float y_scale;
};
return;
}
- wxGraphicsPath grid = gc->CreatePath ();
+ wxGraphicsPath h_grid = gc->CreatePath ();
gc->SetFont (gc->CreateFont (*wxSMALL_FONT));
wxDouble db_label_height;
wxDouble db_label_descent;
for (int i = _minimum; i <= 0; i += 10) {
int const y = (metrics.height - (i - _minimum) * metrics.y_scale) - metrics.y_origin;
- grid.MoveToPoint (metrics.db_label_width - 4, y);
- grid.AddLineToPoint (metrics.db_label_width + data_width, y);
+ h_grid.MoveToPoint (metrics.db_label_width - 4, y);
+ h_grid.AddLineToPoint (metrics.db_label_width + data_width, y);
gc->DrawText (std_to_wx (String::compose ("%1dB", i)), 0, y - (db_label_height / 2));
}
gc->SetPen (wxPen (wxColour (200, 200, 200)));
- gc->StrokePath (grid);
+ gc->StrokePath (h_grid);
- gc->DrawText (_("Time"), data_width, metrics.height - metrics.y_origin + db_label_height / 2);
+ if (_analysis->samples_per_point() && _analysis->sample_rate()) {
+
+ /* Draw an x axis with marks */
+
+ wxGraphicsPath v_grid = gc->CreatePath ();
+
+ DCPOMATIC_ASSERT (_analysis->samples_per_point().get() != 0.0);
+ double const pps = _analysis->sample_rate().get() * metrics.x_scale / _analysis->samples_per_point().get();
+
+ gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
+
+ double const mark_interval = calculate_mark_interval (rint (128 / pps));
+
+ DCPTime t = DCPTime::from_seconds (mark_interval);
+ while ((t.seconds() * pps) < data_width) {
+ double tc = t.seconds ();
+ int const h = tc / 3600;
+ tc -= h * 3600;
+ int const m = tc / 60;
+ tc -= m * 60;
+ int const s = tc;
+
+ wxString str = wxString::Format (wxT ("%02d:%02d:%02d"), h, m, s);
+ wxDouble str_width;
+ wxDouble str_height;
+ wxDouble str_descent;
+ wxDouble str_leading;
+ gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
+
+ int const tx = llrintf (metrics.db_label_width + t.seconds() * pps);
+ gc->DrawText (str, tx - str_width / 2, metrics.height - metrics.y_origin + db_label_height);
+
+ v_grid.MoveToPoint (tx, metrics.height - metrics.y_origin + 4);
+ v_grid.AddLineToPoint (tx, metrics.y_origin);
+
+ t += DCPTime::from_seconds (mark_interval);
+ }
+
+ gc->SetPen (wxPen (wxColour (200, 200, 200)));
+ gc->StrokePath (v_grid);
+
+ } else {
+ /* This is an old analysis without samples_per_point information */
+ gc->DrawText (_("Time"), data_width, metrics.height - metrics.y_origin + db_label_height / 2);
+ }
if (_type_visible[AudioPoint::PEAK]) {
for (int c = 0; c < MAX_DCP_AUDIO_CHANNELS; ++c) {
#include "timeline_time_axis_view.h"
#include "timeline.h"
+#include "wx_util.h"
#include <wx/wx.h>
#include <wx/graphics.h>
gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
- double mark_interval = rint (128 / pps);
- if (mark_interval > 5) {
- mark_interval -= lrint (mark_interval) % 5;
- }
- if (mark_interval > 10) {
- mark_interval -= lrint (mark_interval) % 10;
- }
- if (mark_interval > 60) {
- mark_interval -= lrint (mark_interval) % 60;
- }
- if (mark_interval > 3600) {
- mark_interval -= lrint (mark_interval) % 3600;
- }
-
- if (mark_interval < 1) {
- mark_interval = 1;
- }
+ double const mark_interval = calculate_mark_interval (rint (128 / pps));
wxGraphicsPath path = gc->CreatePath ();
path.MoveToPoint (_timeline.tracks_position().x, _y);
{
return boost::filesystem::path(wx_to_std(dialog->GetPath())).replace_extension(extension);
}
+
+double
+calculate_mark_interval (double mark_interval)
+{
+ if (mark_interval > 5) {
+ mark_interval -= lrint (mark_interval) % 5;
+ }
+ if (mark_interval > 10) {
+ mark_interval -= lrint (mark_interval) % 10;
+ }
+ if (mark_interval > 60) {
+ mark_interval -= lrint (mark_interval) % 60;
+ }
+ if (mark_interval > 3600) {
+ mark_interval -= lrint (mark_interval) % 3600;
+ }
+
+ if (mark_interval < 1) {
+ mark_interval = 1;
+ }
+
+ return mark_interval;
+}
extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
extern wxSplashScreen* maybe_show_splash ();
extern boost::filesystem::path path_from_file_dialog (wxFileDialog* dialog, std::string extension);
+extern double calculate_mark_interval (double start);
extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
extern void checked_set (wxSpinCtrl* widget, int value);