From 9dd35cac8c6ca8198eb858891dfb0a0d9cdede4c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 1 Jun 2016 12:28:00 +0100 Subject: [PATCH] Basics of better audio stream labelling in the audio mapping view (#849). --- ChangeLog | 5 ++ src/lib/ffmpeg_examiner.cc | 18 +---- src/lib/ffmpeg_examiner.h | 1 - src/wx/audio_mapping_view.cc | 125 ++++++++++++++++++++++++++++++++++- src/wx/audio_mapping_view.h | 27 +++++++- src/wx/audio_panel.cc | 11 +++ 6 files changed, 164 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 943aac2c0..81a22db73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-01 c.hetherington + + * Basics of better audio stream labelling in the audio + mapping view (#849). + 2016-06-01 Carl Hetherington * Updated cs_CZ translation from Tomáš Begeni. diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index f98c478e7..06154cc8c 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -67,7 +67,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptr ( new FFmpegAudioStream ( - audio_stream_name (s), + stream_name (s), s->id, s->codec->sample_rate, (double (_format_context->duration) / AV_TIME_BASE) * s->codec->sample_rate, @@ -345,22 +345,6 @@ FFmpegExaminer::sample_aspect_ratio () const return double (sar.num) / sar.den; } -string -FFmpegExaminer::audio_stream_name (AVStream* s) const -{ - SafeStringStream n; - - n << stream_name (s); - - if (!n.str().empty()) { - n << "; "; - } - - n << s->codec->channels << " channels"; - - return n.str (); -} - string FFmpegExaminer::subtitle_stream_name (AVStream* s) const { diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h index f338723b7..c3dde84fe 100644 --- a/src/lib/ffmpeg_examiner.h +++ b/src/lib/ffmpeg_examiner.h @@ -77,7 +77,6 @@ private: void subtitle_packet (AVCodecContext *, boost::shared_ptr); std::string stream_name (AVStream* s) const; - std::string audio_stream_name (AVStream* s) const; std::string subtitle_stream_name (AVStream* s) const; boost::optional frame_time (AVStream* s) const; diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc index 8d39a40ff..46560e094 100644 --- a/src/wx/audio_mapping_view.cc +++ b/src/wx/audio_mapping_view.cc @@ -32,16 +32,20 @@ #include #include #include +#include +#include #include using std::cout; using std::list; using std::string; +using std::min; using std::max; using std::vector; using boost::shared_ptr; #define INDICATOR_SIZE 16 +#define LEFT_WIDTH 48 enum { ID_off = 1, @@ -117,6 +121,11 @@ AudioMappingView::AudioMappingView (wxWindow* parent) , _last_tooltip_row (0) , _last_tooltip_column (0) { + _left_labels = new wxPanel (this, wxID_ANY); + _left_labels->Bind (wxEVT_PAINT, boost::bind (&AudioMappingView::paint_left_labels, this)); + _top_labels = new wxPanel (this, wxID_ANY); + _top_labels->Bind (wxEVT_PAINT, boost::bind (&AudioMappingView::paint_top_labels, this)); + _grid = new wxGrid (this, wxID_ANY); _grid->CreateGrid (0, MAX_DCP_AUDIO_CHANNELS + 1); @@ -128,9 +137,13 @@ AudioMappingView::AudioMappingView (wxWindow* parent) _grid->SetDefaultRenderer (new NoSelectionStringRenderer); _grid->AutoSize (); - _sizer = new wxBoxSizer (wxVERTICAL); - _sizer->Add (_grid, 1, wxEXPAND | wxALL); - SetSizerAndFit (_sizer); + wxSizer* vertical_sizer = new wxBoxSizer (wxVERTICAL); + vertical_sizer->Add (_top_labels); + wxSizer* horizontal_sizer = new wxBoxSizer (wxHORIZONTAL); + horizontal_sizer->Add (_left_labels); + horizontal_sizer->Add (_grid, 1, wxEXPAND | wxALL); + vertical_sizer->Add (horizontal_sizer); + SetSizerAndFit (vertical_sizer); Bind (wxEVT_GRID_CELL_LEFT_CLICK, boost::bind (&AudioMappingView::left_click, this, _1)); Bind (wxEVT_GRID_CELL_RIGHT_CLICK, boost::bind (&AudioMappingView::right_click, this, _1)); @@ -329,6 +342,112 @@ AudioMappingView::mouse_moved (wxMouseEvent& ev) void AudioMappingView::sized (wxSizeEvent& ev) { + int const top_height = 24; + _grid->AutoSize (); + _left_labels->SetMinSize (wxSize (LEFT_WIDTH, _grid->GetSize().GetHeight())); + _top_labels->SetMinSize (wxSize (_grid->GetSize().GetWidth() + LEFT_WIDTH, top_height)); ev.Skip (); } + +void +AudioMappingView::paint_left_labels () +{ + wxPaintDC dc (_left_labels); + + wxGraphicsContext* gc = wxGraphicsContext::Create (dc); + if (!gc) { + return; + } + + wxSize const size = dc.GetSize(); + int const half = size.GetWidth() / 2; + + gc->SetPen (wxPen (wxColour (0, 0, 0))); + gc->SetAntialiasMode (wxANTIALIAS_DEFAULT); + + if (_grid->GetNumberRows() > 0) { + + /* Draw a line at the top of the first group */ + int ypos = _grid->GetColLabelSize() - 1; + wxGraphicsPath lines = gc->CreatePath(); + lines.MoveToPoint (half, ypos); + lines.AddLineToPoint (size.GetWidth(), ypos); + + /* And the names of the groups and a line under each */ + BOOST_FOREACH (Group const & i, _input_groups) { + int const old_ypos = ypos; + ypos += (i.to - i.from + 1) * _grid->GetRowSize(0); + + dc.SetClippingRegion (0, old_ypos + 2, size.GetWidth(), ypos - 4); + + dc.SetFont (*wxSWISS_FONT); + wxCoord label_width; + wxCoord label_height; + dc.GetTextExtent (std_to_wx (i.name), &label_width, &label_height); + + dc.DrawRotatedText (i.name, half + (half - label_height) / 2, (ypos + old_ypos + label_width) / 2, 90); + dc.DestroyClippingRegion (); + + lines.MoveToPoint (half, ypos); + lines.AddLineToPoint (size.GetWidth(), ypos); + } + + gc->StrokePath (lines); + } + + /* Overall label */ + dc.SetFont (wxSWISS_FONT->Bold()); + wxCoord overall_label_width; + wxCoord overall_label_height; + dc.GetTextExtent (_("Content"), &overall_label_width, &overall_label_height); + dc.DrawRotatedText ( + _("Content"), + (half - overall_label_height) / 2, + min (size.GetHeight(), (size.GetHeight() + _grid->GetColLabelSize() + overall_label_width) / 2), + 90 + ); + + delete gc; +} + +void +AudioMappingView::paint_top_labels () +{ + wxPaintDC dc (_top_labels); + if (_grid->GetNumberCols() == 0) { + return; + } + + wxGraphicsContext* gc = wxGraphicsContext::Create (dc); + if (!gc) { + return; + } + + wxSize const size = dc.GetSize(); + + gc->SetAntialiasMode (wxANTIALIAS_DEFAULT); + + dc.SetFont (wxSWISS_FONT->Bold()); + wxCoord label_width; + wxCoord label_height; + dc.GetTextExtent (_("DCP"), &label_width, &label_height); + + dc.DrawText (_("DCP"), (size.GetWidth() + _grid->GetColSize(0) + LEFT_WIDTH - label_width) / 2, (size.GetHeight() - label_height) / 2); + + gc->SetPen (wxPen (wxColour (0, 0, 0))); + wxGraphicsPath lines = gc->CreatePath(); + lines.MoveToPoint (LEFT_WIDTH + _grid->GetColSize(0) - 1, 0); + lines.AddLineToPoint (LEFT_WIDTH + _grid->GetColSize(0) - 1, size.GetHeight()); + lines.MoveToPoint (size.GetWidth() - 1, 0); + lines.AddLineToPoint (size.GetWidth() - 1, size.GetHeight()); + gc->StrokePath (lines); + + delete gc; +} + +void +AudioMappingView::set_input_groups (vector const & groups) +{ + _input_groups = groups; +} diff --git a/src/wx/audio_mapping_view.h b/src/wx/audio_mapping_view.h index 2a2bacb00..2c4432535 100644 --- a/src/wx/audio_mapping_view.h +++ b/src/wx/audio_mapping_view.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2015 Carl Hetherington + Copyright (C) 2013-2016 Carl Hetherington This file is part of DCP-o-matic. @@ -52,6 +52,24 @@ public: void set_input_channels (std::vector const & names); void set_output_channels (std::vector const & names); + struct Group + { + Group (int f, int t, std::string n) + : from (f) + , to (t) + , name (n) + {} + + /** First channel index (from 0) */ + int from; + /** Last channel index (from 0) */ + int to; + /** Name of this group */ + std::string name; + }; + + void set_input_groups (std::vector const & groups); + boost::signals2::signal Changed; private: @@ -61,6 +79,8 @@ private: void update_cells (); void map_values_changed (); void sized (wxSizeEvent &); + void paint_left_labels (); + void paint_top_labels (); void off (); void full (); @@ -68,13 +88,16 @@ private: void edit (); wxGrid* _grid; - wxSizer* _sizer; + wxPanel* _left_labels; + wxPanel* _top_labels; AudioMapping _map; wxMenu* _menu; int _menu_row; int _menu_column; + std::vector _input_groups; + int _last_tooltip_row; int _last_tooltip_column; }; diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index df8c7871e..fa086b8e3 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -25,6 +25,7 @@ #include "content_panel.h" #include "audio_dialog.h" #include "lib/config.h" +#include "lib/ffmpeg_audio_stream.h" #include "lib/ffmpeg_content.h" #include "lib/cinema_sound_processor.h" #include "lib/job_manager.h" @@ -154,6 +155,16 @@ AudioPanel::film_content_changed (int property) if (ac.size() == 1) { _mapping->set (ac.front()->audio->mapping()); _mapping->set_input_channels (ac.front()->audio->channel_names ()); + + vector groups; + int c = 0; + BOOST_FOREACH (shared_ptr i, ac.front()->audio->streams()) { + shared_ptr f = dynamic_pointer_cast (i); + groups.push_back (AudioMappingView::Group (c, c + i->channels() - 1, f ? f->name : "")); + c += i->channels (); + } + _mapping->set_input_groups (groups); + } else { _mapping->set (AudioMapping ()); } -- 2.30.2