diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-04-06 23:57:46 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-04-06 23:57:46 +0100 |
| commit | c921cfe23b593d7c367ad76094308c5f08037374 (patch) | |
| tree | d010137615eb3817e57edaf0b0753ef924569965 /src/wx | |
| parent | 8750efb9e072cf3b42e6c3c29521c7031c0b5dfd (diff) | |
Various work on audio channel mapping.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/audio_dialog.cc | 36 | ||||
| -rw-r--r-- | src/wx/audio_dialog.h | 1 | ||||
| -rw-r--r-- | src/wx/audio_mapping_view.cc | 156 | ||||
| -rw-r--r-- | src/wx/audio_mapping_view.h (renamed from src/wx/sndfile_content_dialog.h) | 17 | ||||
| -rw-r--r-- | src/wx/film_editor.cc | 55 | ||||
| -rw-r--r-- | src/wx/film_editor.h | 6 | ||||
| -rw-r--r-- | src/wx/sndfile_content_dialog.cc | 67 | ||||
| -rw-r--r-- | src/wx/wscript | 2 |
8 files changed, 209 insertions, 131 deletions
diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index f53ea7c19..4c50260fa 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -20,7 +20,6 @@ #include <boost/filesystem.hpp> #include "lib/audio_analysis.h" #include "lib/film.h" -#include "lib/audio_mapping.h" #include "audio_dialog.h" #include "audio_plot.h" #include "wx_util.h" @@ -93,7 +92,6 @@ AudioDialog::set_film (shared_ptr<Film> f) _film = f; try_to_load_analysis (); - setup_channels (); _plot->set_gain (_film->audio_gain ()); _film_changed_connection = _film->Changed.connect (bind (&AudioDialog::film_changed, this, _1)); @@ -102,23 +100,6 @@ AudioDialog::set_film (shared_ptr<Film> f) SetTitle (wxString::Format (_("DVD-o-matic audio - %s"), std_to_wx(_film->name()).data())); } -void -AudioDialog::setup_channels () -{ - if (!_film->has_audio()) { - return; - } - - AutomaticAudioMapping m (_film->audio_channels ()); - - for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) { - if (m.dcp_to_source(static_cast<libdcp::Channel>(i))) { - _channel_checkbox[i]->Show (); - } else { - _channel_checkbox[i]->Hide (); - } - } -} void AudioDialog::try_to_load_analysis () @@ -135,12 +116,8 @@ AudioDialog::try_to_load_analysis () _plot->set_analysis (a); - AutomaticAudioMapping m (_film->audio_channels ()); - optional<libdcp::Channel> c = m.source_to_dcp (0); - if (c) { - _channel_checkbox[c.get()]->SetValue (true); - _plot->set_channel_visible (0, true); - } + _channel_checkbox[0]->SetValue (true); + _plot->set_channel_visible (0, true); for (int i = 0; i < AudioPoint::COUNT; ++i) { _type_checkbox[i]->SetValue (true); @@ -158,11 +135,7 @@ AudioDialog::channel_clicked (wxCommandEvent& ev) assert (c < MAX_AUDIO_CHANNELS); - AutomaticAudioMapping m (_film->audio_channels ()); - optional<int> s = m.dcp_to_source (static_cast<libdcp::Channel> (c)); - if (s) { - _plot->set_channel_visible (s.get(), _channel_checkbox[c]->GetValue ()); - } + _plot->set_channel_visible (c, _channel_checkbox[c]->GetValue ()); } void @@ -172,9 +145,6 @@ AudioDialog::film_changed (Film::Property p) case Film::AUDIO_GAIN: _plot->set_gain (_film->audio_gain ()); break; - case Film::CONTENT: - setup_channels (); - break; default: break; } diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index 514faeea0..db1d74f30 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -39,7 +39,6 @@ private: void type_clicked (wxCommandEvent &); void smoothing_changed (wxScrollEvent &); void try_to_load_analysis (); - void setup_channels (); boost::shared_ptr<Film> _film; AudioPlot* _plot; diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc new file mode 100644 index 000000000..d62609d22 --- /dev/null +++ b/src/wx/audio_mapping_view.cc @@ -0,0 +1,156 @@ +/* + Copyright (C) 2013 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 + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <wx/wx.h> +#include <wx/renderer.h> +#include <wx/grid.h> +#include <libdcp/types.h> +#include "lib/audio_mapping.h" +#include "audio_mapping_view.h" +#include "wx_util.h" + +using std::cout; +using std::list; +using boost::shared_ptr; + +/* This could go away with wxWidgets 2.9, which has an API call + to find these values. +*/ + +#ifdef __WXMSW__ +#define CHECKBOX_WIDTH 16 +#define CHECKBOX_HEIGHT 16 +#endif + +#ifdef __WXGTK__ +#define CHECKBOX_WIDTH 20 +#define CHECKBOX_HEIGHT 20 +#endif + + +class NoSelectionStringRenderer : public wxGridCellStringRenderer +{ +public: + void Draw (wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool) + { + wxGridCellStringRenderer::Draw (grid, attr, dc, rect, row, col, false); + } +}; + +class CheckBoxRenderer : public wxGridCellRenderer +{ +public: + + void Draw (wxGrid& grid, wxGridCellAttr &, wxDC& dc, const wxRect& rect, int row, int col, bool) + { + wxRendererNative::Get().DrawCheckBox ( + &grid, + dc, rect, + grid.GetCellValue (row, col) == "1" ? static_cast<int>(wxCONTROL_CHECKED) : 0 + ); + } + + wxSize GetBestSize (wxGrid &, wxGridCellAttr &, wxDC &, int, int) + { + return wxSize (CHECKBOX_WIDTH + 4, CHECKBOX_HEIGHT + 4); + } + + wxGridCellRenderer* Clone () const + { + return new CheckBoxRenderer; + } +}; + + +AudioMappingView::AudioMappingView (wxWindow* parent) + : wxPanel (parent, wxID_ANY) +{ + _grid = new wxGrid (this, wxID_ANY); + + _grid->CreateGrid (0, 7); + _grid->HideRowLabels (); + _grid->DisableDragRowSize (); + _grid->DisableDragColSize (); + _grid->EnableEditing (false); + _grid->SetCellHighlightPenWidth (0); + _grid->SetDefaultRenderer (new NoSelectionStringRenderer); + + _grid->SetColLabelValue (0, _("Content channel")); + _grid->SetColLabelValue (1, _("L")); + _grid->SetColLabelValue (2, _("R")); + _grid->SetColLabelValue (3, _("C")); + _grid->SetColLabelValue (4, _("Lfe")); + _grid->SetColLabelValue (5, _("Ls")); + _grid->SetColLabelValue (6, _("Rs")); + + _grid->AutoSize (); + + wxBoxSizer* s = new wxBoxSizer (wxVERTICAL); + s->Add (_grid, 1, wxEXPAND); + SetSizerAndFit (s); + + Connect (wxID_ANY, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler (AudioMappingView::left_click), 0, this); +} + +void +AudioMappingView::left_click (wxGridEvent& ev) +{ + if (ev.GetCol() == 0) { + return; + } + + if (_grid->GetCellValue (ev.GetRow(), ev.GetCol()) == "1") { + _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "0"); + } else { + _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "1"); + } +} + +void +AudioMappingView::set_mapping (AudioMapping map) +{ + if (_grid->GetNumberRows ()) { + _grid->DeleteRows (0, _grid->GetNumberRows ()); + } + + list<AudioMapping::Channel> content_channels = map.content_channels (); + _grid->InsertRows (0, content_channels.size ()); + + for (size_t r = 0; r < content_channels.size(); ++r) { + for (int c = 1; c < 7; ++c) { + _grid->SetCellRenderer (r, c, new CheckBoxRenderer); + } + } + + int n = 0; + for (list<AudioMapping::Channel>::iterator i = content_channels.begin(); i != content_channels.end(); ++i) { + shared_ptr<const AudioContent> ac = i->content.lock (); + assert (ac); + _grid->SetCellValue (n, 0, wxString::Format ("%s %d", std_to_wx (ac->file().filename().string()), i->index + 1)); + + list<libdcp::Channel> const d = map.content_to_dcp (*i); + for (list<libdcp::Channel>::const_iterator j = d.begin(); j != d.end(); ++j) { + _grid->SetCellValue (n, static_cast<int> (*j) + 1, "1"); + } + ++n; + } + + _grid->AutoSize (); +} + diff --git a/src/wx/sndfile_content_dialog.h b/src/wx/audio_mapping_view.h index 5a328892a..36429412f 100644 --- a/src/wx/sndfile_content_dialog.h +++ b/src/wx/audio_mapping_view.h @@ -17,20 +17,19 @@ */ -#include <vector> -#include <boost/shared_ptr.hpp> +#include <boost/signals2.hpp> #include <wx/wx.h> -#include "lib/audio_mapping.h" +#include <wx/grid.h> -class SndfileContent; - -class SndfileContentDialog : public wxDialog +class AudioMappingView : public wxPanel { public: - SndfileContentDialog (wxWindow *, boost::shared_ptr<SndfileContent>); + AudioMappingView (wxWindow *); - ConfiguredAudioMapping audio_mapping () const; + void set_mapping (AudioMapping); private: - std::vector<std::vector<wxRadioButton *> > _buttons; + void left_click (wxGridEvent &); + + wxGrid* _grid; }; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 6c42359fb..6f08b6567 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -50,7 +50,7 @@ #include "scaler.h" #include "audio_dialog.h" #include "imagemagick_content_dialog.h" -#include "sndfile_content_dialog.h" +#include "audio_mapping_view.h" using std::string; using std::cout; @@ -197,7 +197,9 @@ FilmEditor::connect_to_widgets () _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this); _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this); _trust_content_headers->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_headers_changed), 0, this); - _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_item_selected), 0, this); + _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this); + _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this); + _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler (FilmEditor::content_activated), 0, this); _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this); _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this); _content_edit->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_edit_clicked), 0, this); @@ -406,6 +408,9 @@ FilmEditor::make_audio_panel () grid->Add (s, 1, wxEXPAND); } + _audio_mapping = new AudioMappingView (_audio_panel); + _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6); + _audio_gain->SetRange (-60, 60); _audio_delay->SetRange (-1000, 1000); } @@ -691,6 +696,10 @@ FilmEditor::film_changed (Film::Property p) _frame_rate_description->SetLabel (wxT ("")); _best_dcp_frame_rate->Disable (); } + break; + case Film::AUDIO_MAPPING: + _audio_mapping->set_mapping (_film->audio_mapping ()); + break; } } @@ -849,6 +858,7 @@ FilmEditor::set_film (shared_ptr<Film> f) film_changed (Film::J2K_BANDWIDTH); film_changed (Film::DCI_METADATA); film_changed (Film::DCP_FRAME_RATE); + film_changed (Film::AUDIO_MAPPING); film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS); film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM); @@ -1243,6 +1253,15 @@ FilmEditor::content_remove_clicked (wxCommandEvent &) } void +FilmEditor::content_activated (wxListEvent& ev) +{ + ContentList c = _film->content (); + assert (ev.GetIndex() >= 0 && size_t (ev.GetIndex()) < c.size ()); + + edit_content (c[ev.GetIndex()]); +} + +void FilmEditor::content_edit_clicked (wxCommandEvent &) { shared_ptr<Content> c = selected_content (); @@ -1250,22 +1269,19 @@ FilmEditor::content_edit_clicked (wxCommandEvent &) return; } + edit_content (c); +} + +void +FilmEditor::edit_content (shared_ptr<Content> c) +{ shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (c); if (im) { ImageMagickContentDialog* d = new ImageMagickContentDialog (this, im); - int const r = d->ShowModal (); - d->Destroy (); - - if (r == wxID_OK) { - im->set_video_length (d->video_length() * 24); - } - } - - shared_ptr<SndfileContent> sf = dynamic_pointer_cast<SndfileContent> (c); - if (sf) { - SndfileContentDialog* d = new SndfileContentDialog (this, sf); d->ShowModal (); d->Destroy (); + + im->set_video_length (d->video_length() * 24); } } @@ -1288,7 +1304,7 @@ FilmEditor::content_later_clicked (wxCommandEvent &) } void -FilmEditor::content_item_selected (wxListEvent &) +FilmEditor::content_selection_changed (wxListEvent &) { setup_content_button_sensitivity (); setup_content_information (); @@ -1311,11 +1327,12 @@ FilmEditor::setup_content_button_sensitivity () { _content_add->Enable (_generally_sensitive); - bool const have_selection = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1; - _content_edit->Enable (have_selection && _generally_sensitive); - _content_remove->Enable (have_selection && _generally_sensitive); - _content_earlier->Enable (have_selection && _generally_sensitive); - _content_later->Enable (have_selection && _generally_sensitive); + shared_ptr<Content> selection = selected_content (); + + _content_edit->Enable (selection && _generally_sensitive && dynamic_pointer_cast<ImageMagickContent> (selection)); + _content_remove->Enable (selection && _generally_sensitive); + _content_earlier->Enable (selection && _generally_sensitive); + _content_later->Enable (selection && _generally_sensitive); } shared_ptr<Content> diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index b6f6a24ee..bc6b045c4 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -33,6 +33,7 @@ class wxListCtrl; class wxListEvent; class Film; class AudioDialog; +class AudioMappingView; /** @class FilmEditor * @brief A wx widget to edit a film's metadata, and perform various functions. @@ -63,7 +64,8 @@ private: void top_crop_changed (wxCommandEvent &); void bottom_crop_changed (wxCommandEvent &); void trust_content_headers_changed (wxCommandEvent &); - void content_item_selected (wxListEvent &); + void content_selection_changed (wxListEvent &); + void content_activated (wxListEvent &); void content_add_clicked (wxCommandEvent &); void content_remove_clicked (wxCommandEvent &); void content_edit_clicked (wxCommandEvent &); @@ -110,6 +112,7 @@ private: void active_jobs_changed (bool); boost::shared_ptr<Content> selected_content (); + void edit_content (boost::shared_ptr<Content>); wxNotebook* _notebook; wxPanel* _film_panel; @@ -152,6 +155,7 @@ private: wxButton* _show_audio; wxSpinCtrl* _audio_delay; wxChoice* _ffmpeg_audio_stream; + AudioMappingView* _audio_mapping; wxCheckBox* _with_subtitles; wxChoice* _ffmpeg_subtitle_stream; wxSpinCtrl* _subtitle_offset; diff --git a/src/wx/sndfile_content_dialog.cc b/src/wx/sndfile_content_dialog.cc deleted file mode 100644 index f305b158c..000000000 --- a/src/wx/sndfile_content_dialog.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright (C) 2013 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 - 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "lib/util.h" -#include "lib/sndfile_content.h" -#include "sndfile_content_dialog.h" -#include "wx_util.h" - -using boost::shared_ptr; - -SndfileContentDialog::SndfileContentDialog (wxWindow* parent, shared_ptr<SndfileContent> content) - : wxDialog (parent, wxID_ANY, _("Sound file")) -{ - wxFlexGridSizer* grid = new wxFlexGridSizer (7, 6, 0); - - add_label_to_sizer (grid, this, wxT ("")); - add_label_to_sizer (grid, this, _("L")); - add_label_to_sizer (grid, this, _("R")); - add_label_to_sizer (grid, this, _("C")); - add_label_to_sizer (grid, this, _("Lfe")); - add_label_to_sizer (grid, this, _("Ls")); - add_label_to_sizer (grid, this, _("Rs")); - - _buttons.resize (content->audio_channels ()); - for (int i = 0; i < content->audio_channels(); ++i) { - - if (content->audio_channels() == 1) { - add_label_to_sizer (grid, this, _("Source")); - } else { - add_label_to_sizer (grid, this, wxString::Format (_("Source %d"), i + 1)); - } - - for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { - wxRadioButton* b = new wxRadioButton (this, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, j ? 0 : wxRB_GROUP); - _buttons[i].push_back (b); - grid->Add (b, wxSHRINK); - } - } - - wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); - overall_sizer->Add (grid, 1, wxEXPAND | wxALL, 6); - - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); - if (buttons) { - overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); - } - - SetSizer (overall_sizer); - overall_sizer->Layout (); - overall_sizer->SetSizeHints (this); -} diff --git a/src/wx/wscript b/src/wx/wscript index bd21af6ce..7f9cde9ac 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -5,6 +5,7 @@ import i18n sources = """ audio_dialog.cc + audio_mapping_view.cc audio_plot.cc config_dialog.cc dci_metadata_dialog.cc @@ -20,7 +21,6 @@ sources = """ new_film_dialog.cc properties_dialog.cc server_dialog.cc - sndfile_content_dialog.cc wx_util.cc wx_ui_signaller.cc """ |
