summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-05-10 00:15:44 +0100
committerCarl Hetherington <cth@carlh.net>2015-05-10 00:15:44 +0100
commitfc96a4b3d6985f28db6bc0e9418e98cc5bec87e3 (patch)
treee6866c8006ccf4fb400bfb8e8481a4f1142fb2e3 /src/wx
parent55002ca15ba288002aeedf3867fb9d07b7b653f0 (diff)
7fd73c0cf1f723896826c77fec3720c5c404d4e8 from master; tidy audio analysis dialogue and add overall peak.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/audio_dialog.cc73
-rw-r--r--src/wx/audio_dialog.h6
-rw-r--r--src/wx/audio_panel.cc2
-rw-r--r--src/wx/film_viewer.cc11
-rw-r--r--src/wx/wx_util.cc14
-rw-r--r--src/wx/wx_util.h2
6 files changed, 81 insertions, 27 deletions
diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc
index 1d41fc185..1ce0f38a8 100644
--- a/src/wx/audio_dialog.cc
+++ b/src/wx/audio_dialog.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
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
@@ -29,31 +29,43 @@ using boost::shared_ptr;
using boost::bind;
using boost::optional;
-AudioDialog::AudioDialog (wxWindow* parent)
+AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film)
: wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
+ , _film (film)
, _plot (0)
{
+ wxFont subheading_font (*wxNORMAL_FONT);
+ subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
+
wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+
+ wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
_plot = new AudioPlot (this);
- sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
+ left->Add (_plot, 1, wxALL | wxEXPAND, 12);
+ _peak_time = new wxStaticText (this, wxID_ANY, wxT (""));
+ left->Add (_peak_time, 0, wxALL, 12);
+
+ sizer->Add (left, 1, wxALL, 12);
- wxBoxSizer* side = new wxBoxSizer (wxVERTICAL);
+ wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Channels"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, 16);
}
for (int i = 0; i < MAX_DCP_AUDIO_CHANNELS; ++i) {
_channel_checkbox[i] = new wxCheckBox (this, wxID_ANY, std_to_wx (audio_channel_name (i)));
- side->Add (_channel_checkbox[i], 1, wxEXPAND | wxALL, 3);
+ right->Add (_channel_checkbox[i], 0, wxEXPAND | wxALL, 3);
_channel_checkbox[i]->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AudioDialog::channel_clicked, this, _1));
}
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Type"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
}
wxString const types[] = {
@@ -63,20 +75,21 @@ AudioDialog::AudioDialog (wxWindow* parent)
for (int i = 0; i < AudioPoint::COUNT; ++i) {
_type_checkbox[i] = new wxCheckBox (this, wxID_ANY, types[i]);
- side->Add (_type_checkbox[i], 1, wxEXPAND | wxALL, 3);
+ right->Add (_type_checkbox[i], 0, wxEXPAND | wxALL, 3);
_type_checkbox[i]->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AudioDialog::type_clicked, this, _1));
}
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Smoothing"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
}
_smoothing = new wxSlider (this, wxID_ANY, AudioPlot::max_smoothing / 2, 1, AudioPlot::max_smoothing);
_smoothing->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind (&AudioDialog::smoothing_changed, this));
- side->Add (_smoothing, 1, wxEXPAND);
+ right->Add (_smoothing, 0, wxEXPAND);
- sizer->Add (side, 0, wxALL, 12);
+ sizer->Add (right, 0, wxALL, 12);
SetSizer (sizer);
sizer->Layout ();
@@ -107,14 +120,14 @@ AudioDialog::try_to_load_analysis ()
if (!boost::filesystem::exists (_content->audio_analysis_path())) {
_plot->set_analysis (shared_ptr<AudioAnalysis> ());
+ _analysis.reset ();
_analysis_finished_connection = _content->analyse_audio (bind (&AudioDialog::analysis_finished, this));
return;
}
- shared_ptr<AudioAnalysis> a;
-
- a.reset (new AudioAnalysis (_content->audio_analysis_path ()));
- _plot->set_analysis (a);
+ _analysis.reset (new AudioAnalysis (_content->audio_analysis_path ()));
+ _plot->set_analysis (_analysis);
+ setup_peak_time ();
/* Set up some defaults if no check boxes are checked */
@@ -173,6 +186,7 @@ AudioDialog::content_changed (int p)
{
if (p == AudioContentProperty::AUDIO_GAIN) {
_plot->set_gain (_content->audio_gain ());
+ setup_peak_time ();
} else if (p == AudioContentProperty::AUDIO_MAPPING) {
try_to_load_analysis ();
}
@@ -196,3 +210,32 @@ AudioDialog::smoothing_changed ()
{
_plot->set_smoothing (_smoothing->GetValue ());
}
+
+void
+AudioDialog::setup_peak_time ()
+{
+ if (!_analysis || !_analysis->peak ()) {
+ return;
+ }
+
+ shared_ptr<Film> film = _film.lock ();
+ if (!film) {
+ return;
+ }
+
+ float peak_dB = 20 * log10 (_analysis->peak().get()) + _content->audio_gain();
+
+ _peak_time->SetLabel (
+ wxString::Format (
+ _("Peak is %.2fdB at %s"),
+ peak_dB,
+ time_to_timecode (_analysis->peak_time().get(), film->video_frame_rate ()).data ()
+ )
+ );
+
+ if (peak_dB > -3) {
+ _peak_time->SetForegroundColour (wxColour (255, 0, 0));
+ } else {
+ _peak_time->SetForegroundColour (wxColour (0, 0, 0));
+ }
+}
diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h
index b27785292..aef8ea944 100644
--- a/src/wx/audio_dialog.h
+++ b/src/wx/audio_dialog.h
@@ -29,7 +29,7 @@ class Film;
class AudioDialog : public wxDialog
{
public:
- AudioDialog (wxWindow *);
+ AudioDialog (wxWindow *, boost::shared_ptr<Film> film);
void set_content (boost::shared_ptr<AudioContent>);
@@ -40,9 +40,13 @@ private:
void smoothing_changed ();
void try_to_load_analysis ();
void analysis_finished ();
+ void setup_peak_time ();
boost::shared_ptr<AudioContent> _content;
+ boost::shared_ptr<AudioAnalysis> _analysis;
+ boost::weak_ptr<Film> _film;
AudioPlot* _plot;
+ wxStaticText* _peak_time;
wxCheckBox* _channel_checkbox[MAX_DCP_AUDIO_CHANNELS];
wxCheckBox* _type_checkbox[AudioPoint::COUNT];
wxSlider* _smoothing;
diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc
index 2a41aeb2d..4d783ca9d 100644
--- a/src/wx/audio_panel.cc
+++ b/src/wx/audio_panel.cc
@@ -217,7 +217,7 @@ AudioPanel::show_clicked ()
return;
}
- _audio_dialog = new AudioDialog (this);
+ _audio_dialog = new AudioDialog (this, _parent->film ());
_audio_dialog->Show ();
_audio_dialog->set_content (ac.front ());
}
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc
index 311ec734c..0938d52a4 100644
--- a/src/wx/film_viewer.cc
+++ b/src/wx/film_viewer.cc
@@ -354,16 +354,7 @@ FilmViewer::set_position_text ()
double const fps = _film->video_frame_rate ();
/* Count frame number from 1 ... not sure if this is the best idea */
_frame_number->SetLabel (wxString::Format (wxT("%d"), int (rint (_position.seconds() * fps)) + 1));
-
- double w = _position.seconds ();
- int const h = (w / 3600);
- w -= h * 3600;
- int const m = (w / 60);
- w -= m * 60;
- int const s = floor (w);
- w -= s;
- int const f = rint (w * fps);
- _timecode->SetLabel (wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f));
+ _timecode->SetLabel (time_to_timecode (_position, fps));
}
void
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index e9c07c91f..9c13cfbcb 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -330,3 +330,17 @@ context_translation (wxString s)
return t;
}
+
+wxString
+time_to_timecode (DCPTime t, float fps)
+{
+ double w = t.seconds ();
+ int const h = (w / 3600);
+ w -= h * 3600;
+ int const m = (w / 60);
+ w -= m * 60;
+ int const s = floor (w);
+ w -= s;
+ int const f = rint (w * fps);
+ return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
+}
diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h
index dfa0fca5e..f2ab2d8c5 100644
--- a/src/wx/wx_util.h
+++ b/src/wx/wx_util.h
@@ -24,6 +24,7 @@
#ifndef DCPOMATIC_WX_UTIL_H
#define DCPOMATIC_WX_UTIL_H
+#include "lib/dcpomatic_time.h"
#include <wx/wx.h>
#include <wx/gbsizer.h>
#include <boost/function.hpp>
@@ -65,6 +66,7 @@ extern wxString std_to_wx (std::string);
extern void dcpomatic_setup_i18n ();
extern wxString context_translation (wxString);
extern std::string string_client_data (wxClientData* o);
+extern wxString time_to_timecode (DCPTime t, float fps);
extern void checked_set (wxFilePickerCtrl* widget, std::string value);
extern void checked_set (wxSpinCtrl* widget, int value);