X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffilm_editor.cc;h=feb49ed78a394b392f93e118ae604fe3e2948ce9;hb=d62877ae6c4e316e43f4052e4b9ba673610012cf;hp=d354e6e5ae04cecaf71533430cc5e0c25c27922e;hpb=7ebb57db2013c9e929d44d0e547ab1f27c59cc7f;p=dcpomatic.git diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index d354e6e5a..feb49ed78 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -40,6 +40,7 @@ #include "lib/ffmpeg_decoder.h" #include "lib/imagemagick_content.h" #include "lib/sndfile_content.h" +#include "lib/dcp_content_type.h" #include "filter_dialog.h" #include "wx_util.h" #include "film_editor.h" @@ -48,6 +49,8 @@ #include "dci_metadata_dialog.h" #include "scaler.h" #include "audio_dialog.h" +#include "imagemagick_content_dialog.h" +#include "audio_mapping_view.h" using std::string; using std::cout; @@ -58,12 +61,13 @@ using std::setprecision; using std::list; using std::vector; using boost::shared_ptr; +using boost::weak_ptr; using boost::dynamic_pointer_cast; +using boost::lexical_cast; /** @param f Film to edit */ FilmEditor::FilmEditor (shared_ptr f, wxWindow* parent) : wxPanel (parent) - , _film (f) , _generally_sensitive (true) , _audio_dialog (0) { @@ -82,7 +86,7 @@ FilmEditor::FilmEditor (shared_ptr f, wxWindow* parent) make_subtitle_panel (); _notebook->AddPage (_subtitle_panel, _("Subtitles"), false); - set_film (_film); + set_film (f); connect_to_widgets (); JobManager::instance()->ActiveJobsChanged.connect ( @@ -142,7 +146,7 @@ FilmEditor::make_film_panel () } ++r; - _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize); + _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT (" \n \n "), wxDefaultPosition, wxDefaultSize); grid->Add (_frame_rate_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6); wxFont font = _frame_rate_description->GetFont(); font.SetStyle(wxFONTSTYLE_ITALIC); @@ -150,11 +154,6 @@ FilmEditor::make_film_panel () _frame_rate_description->SetFont(font); ++r; - add_label_to_grid_bag_sizer (grid, _film_panel, _("Original Size"), wxGBPosition (r, 0)); - _original_size = new wxStaticText (_film_panel, wxID_ANY, wxT ("")); - grid->Add (_original_size, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); - ++r; - add_label_to_grid_bag_sizer (grid, _film_panel, _("Length"), wxGBPosition (r, 0)); _length = new wxStaticText (_film_panel, wxID_ANY, wxT ("")); grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); @@ -198,9 +197,12 @@ 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); _content_earlier->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_earlier_clicked), 0, this); _content_later->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_later_clicked), 0, this); _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this); @@ -220,8 +222,8 @@ FilmEditor::connect_to_widgets () _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this); _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this); _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this); -// _ffmpeg_subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_subtitle_stream_changed), 0, this); -// _ffmpeg_audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_audio_stream_changed), 0, this); + _ffmpeg_subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_subtitle_stream_changed), 0, this); + _ffmpeg_audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_audio_stream_changed), 0, this); _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this); _audio_gain_calculate_button->Connect ( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this @@ -246,14 +248,6 @@ FilmEditor::make_video_panel () grid->Add (_format, wxGBPosition (r, 1)); ++r; - _format_description = new wxStaticText (_video_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize); - grid->Add (_format_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6); - wxFont font = _format_description->GetFont(); - font.SetStyle(wxFONTSTYLE_ITALIC); - font.SetPointSize(font.GetPointSize() - 1); - _format_description->SetFont(font); - ++r; - add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0)); _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)); grid->Add (_left_crop, wxGBPosition (r, 1)); @@ -274,6 +268,14 @@ FilmEditor::make_video_panel () grid->Add (_bottom_crop, wxGBPosition (r, 1)); ++r; + _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize); + grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6); + wxFont font = _scaling_description->GetFont(); + font.SetStyle(wxFONTSTYLE_ITALIC); + font.SetPointSize(font.GetPointSize() - 1); + _scaling_description->SetFont(font); + ++r; + /* VIDEO-only stuff */ { add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0)); @@ -337,7 +339,7 @@ FilmEditor::make_content_panel () _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL); s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6); - _content->InsertColumn (0, ""); + _content->InsertColumn (0, wxT("")); _content->SetColumnWidth (0, 512); wxBoxSizer* b = new wxBoxSizer (wxVERTICAL); @@ -345,6 +347,8 @@ FilmEditor::make_content_panel () b->Add (_content_add); _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove")); b->Add (_content_remove); + _content_edit = new wxButton (_content_panel, wxID_ANY, _("Edit...")); + b->Add (_content_edit); _content_earlier = new wxButton (_content_panel, wxID_ANY, _("Earlier")); b->Add (_content_earlier); _content_later = new wxButton (_content_panel, wxID_ANY, _("Later")); @@ -394,6 +398,19 @@ FilmEditor::make_audio_panel () grid->Add (s); } + { + add_label_to_sizer (grid, _audio_panel, _("Audio Stream")); + wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + _ffmpeg_audio_stream = new wxChoice (_audio_panel, wxID_ANY); + s->Add (_ffmpeg_audio_stream, 1); + _audio = new wxStaticText (_audio_panel, wxID_ANY, wxT ("")); + s->Add (_audio, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8); + 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); } @@ -413,9 +430,14 @@ FilmEditor::make_subtitle_panel () _ffmpeg_subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY); grid->Add (_ffmpeg_subtitle_stream); - add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset")); - _subtitle_offset = new wxSpinCtrl (_subtitle_panel); - grid->Add (_subtitle_offset, 1); + { + add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset")); + wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + _subtitle_offset = new wxSpinCtrl (_subtitle_panel); + s->Add (_subtitle_offset); + add_label_to_sizer (s, _subtitle_panel, _("pixels")); + grid->Add (s); + } { add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale")); @@ -586,7 +608,6 @@ FilmEditor::film_changed (Film::Property p) setup_subtitle_control_sensitivity (); setup_streams (); setup_show_audio_sensitivity (); - setup_length (); break; case Film::TRUST_CONTENT_HEADERS: checked_set (_trust_content_headers, _film->trust_content_headers ()); @@ -599,6 +620,7 @@ FilmEditor::film_changed (Film::Property p) checked_set (_right_crop, _film->crop().right); checked_set (_top_crop, _film->crop().top); checked_set (_bottom_crop, _film->crop().bottom); + setup_scaling_description (); break; case Film::FILTERS: { @@ -616,18 +638,6 @@ FilmEditor::film_changed (Film::Property p) checked_set (_name, _film->name()); setup_dcp_name (); break; -// case Film::SOURCE_FRAME_RATE: -// s << fixed << setprecision(2) << _film->source_frame_rate(); -// _source_frame_rate->SetLabel (std_to_wx (s.str ())); -// break; -// case Film::VIDEO_SIZE: -// if (_film->size().width == 0 && _film->size().height == 0) { -// _original_size->SetLabel (wxT ("")); -// } else { -// s << _film->size().width << " x " << _film->size().height; -// _original_size->SetLabel (std_to_wx (s.str ())); -// } -// break; case Film::DCP_CONTENT_TYPE: checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ())); setup_dcp_name (); @@ -674,19 +684,6 @@ FilmEditor::film_changed (Film::Property p) case Film::DCI_METADATA: setup_dcp_name (); break; -// case Film::CONTENT_AUDIO_STREAM: -// if (_film->content_audio_stream()) { -// checked_set (_audio_stream, _film->content_audio_stream()->to_string()); -// } -// setup_dcp_name (); -// setup_audio_details (); -// setup_show_audio_sensitivity (); -// break; -// case Film::SUBTITLE_STREAM: -// if (_film->subtitle_stream()) { -// checked_set (_subtitle_stream, _film->subtitle_stream()->to_string()); -// } -// break; case Film::DCP_FRAME_RATE: for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) { if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast (_film->dcp_frame_rate())) { @@ -698,26 +695,51 @@ FilmEditor::film_changed (Film::Property p) } if (_film->video_frame_rate()) { - _frame_rate_description->SetLabel (std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description)); _best_dcp_frame_rate->Enable (best_dcp_frame_rate (_film->video_frame_rate ()) != _film->dcp_frame_rate ()); } else { - _frame_rate_description->SetLabel (wxT ("")); _best_dcp_frame_rate->Disable (); } + setup_frame_rate_description (); + break; + case Film::AUDIO_MAPPING: + _audio_mapping->set_mapping (_film->audio_mapping ()); + break; } } void -FilmEditor::film_content_changed (int p) +FilmEditor::film_content_changed (weak_ptr content, int property) { - if (p == FFmpegContentProperty::SUBTITLE_STREAMS) { + if (!_film) { + /* We call this method ourselves (as well as using it as a signal handler) + so _film can be 0. + */ + return; + } + + if (property == FFmpegContentProperty::SUBTITLE_STREAMS) { setup_subtitle_control_sensitivity (); setup_streams (); - } else if (p == FFmpegContentProperty::AUDIO_STREAMS) { + } else if (property == FFmpegContentProperty::AUDIO_STREAMS) { setup_streams (); setup_show_audio_sensitivity (); - } else if (p == VideoContentProperty::VIDEO_LENGTH) { + } else if (property == VideoContentProperty::VIDEO_LENGTH) { setup_length (); + boost::shared_ptr c = content.lock (); + if (c && c == selected_content()) { + setup_content_information (); + } + } else if (property == FFmpegContentProperty::AUDIO_STREAM) { + if (_film->ffmpeg_audio_stream()) { + checked_set (_ffmpeg_audio_stream, boost::lexical_cast (_film->ffmpeg_audio_stream()->id)); + } + setup_dcp_name (); + setup_audio_details (); + setup_show_audio_sensitivity (); + } else if (property == FFmpegContentProperty::SUBTITLE_STREAM) { + if (_film->ffmpeg_subtitle_stream()) { + checked_set (_ffmpeg_subtitle_stream, boost::lexical_cast (_film->ffmpeg_subtitle_stream()->id)); + } } } @@ -730,18 +752,15 @@ FilmEditor::setup_format () ++i; ++n; } + if (i == _formats.end()) { checked_set (_format, -1); } else { checked_set (_format, n); } - setup_dcp_name (); - if (_film->format ()) { - _format_description->SetLabel (std_to_wx (_film->format()->description ())); - } else { - _format_description->SetLabel (wxT ("")); - } + setup_dcp_name (); + setup_scaling_description (); } void @@ -762,6 +781,29 @@ FilmEditor::setup_length () } } +void +FilmEditor::setup_frame_rate_description () +{ + wxString d; + if (_film->video_frame_rate()) { + d << std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description); +#ifdef HAVE_SWRESAMPLE + if (_film->audio_frame_rate() != _film->target_audio_sample_rate ()) { + d << wxString::Format ( + _("Audio will be resampled from %dHz to %dHz\n"), + _film->audio_frame_rate(), + _film->target_audio_sample_rate() + ); + } else { + d << "\n"; + } +#else + d << "\n"; +#endif + } + + _frame_rate_description->SetLabel (d); +} /** Called when the format widget has been changed */ void @@ -796,13 +838,17 @@ FilmEditor::dcp_content_type_changed (wxCommandEvent &) void FilmEditor::set_film (shared_ptr f) { - _film = f; - set_things_sensitive (_film != 0); + if (_film == f) { + return; + } + + _film = f; + if (_film) { _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1)); - _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1)); + _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2)); } if (_film) { @@ -836,6 +882,12 @@ FilmEditor::set_film (shared_ptr 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 (), FFmpegContentProperty::SUBTITLE_STREAMS); + film_content_changed (boost::shared_ptr (), FFmpegContentProperty::SUBTITLE_STREAM); + film_content_changed (boost::shared_ptr (), FFmpegContentProperty::AUDIO_STREAMS); + film_content_changed (boost::shared_ptr (), FFmpegContentProperty::AUDIO_STREAM); } /** Updates the sensitivity of lots of widgets to a given value. @@ -859,7 +911,7 @@ FilmEditor::set_things_sensitive (bool s) _bottom_crop->Enable (s); _filters_button->Enable (s); _scaler->Enable (s); -// _ffmpeg_audio_stream->Enable (s); + _ffmpeg_audio_stream->Enable (s); _dcp_content_type->Enable (s); _dcp_frame_rate->Enable (s); _trim_start->Enable (s); @@ -921,6 +973,24 @@ FilmEditor::audio_delay_changed (wxCommandEvent &) _film->set_audio_delay (_audio_delay->GetValue ()); } +void +FilmEditor::setup_notebook_size () +{ + _notebook->InvalidateBestSize (); + + _film_sizer->Layout (); + _film_sizer->SetSizeHints (_film_panel); + _video_sizer->Layout (); + _video_sizer->SetSizeHints (_video_panel); + _audio_sizer->Layout (); + _audio_sizer->SetSizeHints (_audio_panel); + _subtitle_sizer->Layout (); + _subtitle_sizer->SetSizeHints (_subtitle_panel); + + _notebook->Fit (); + Fit (); +} + void FilmEditor::trim_start_changed (wxCommandEvent &) { @@ -996,7 +1066,7 @@ FilmEditor::setup_subtitle_control_sensitivity () { bool h = false; if (_generally_sensitive && _film) { -// h = !_film->subtitle_streams().empty(); + h = !_film->ffmpeg_subtitle_streams().empty(); } _with_subtitles->Enable (h); @@ -1037,26 +1107,31 @@ FilmEditor::edit_dci_button_clicked (wxCommandEvent &) void FilmEditor::setup_streams () { -// _ffmpeg_audio_stream->Clear (); - vector a;// = _film->content_audio_streams (); -// for (vector::iterator i = a.begin(); i != a.end(); ++i) { -// _audio_stream->Append (std_to_wx (ffa->name()), new wxStringClientData (std_to_wx (i->to_string ()))); -// } + if (!_film) { + return; + } + + _ffmpeg_audio_stream->Clear (); + vector a = _film->ffmpeg_audio_streams (); + for (vector::iterator i = a.begin(); i != a.end(); ++i) { + _ffmpeg_audio_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (boost::lexical_cast (i->id)))); + } -// if (_film->use_content_audio() && _film->audio_stream()) { -// checked_set (_audio_stream, _film->audio_stream()->to_string()); -// } + if (_film->ffmpeg_audio_stream()) { + checked_set (_ffmpeg_audio_stream, boost::lexical_cast (_film->ffmpeg_audio_stream()->id)); + } _ffmpeg_subtitle_stream->Clear (); -// vector > s = _film->subtitle_streams (); -// for (vector >::iterator i = s.begin(); i != s.end(); ++i) { -// _subtitle_stream->Append (std_to_wx ((*i)->name()), new wxStringClientData (std_to_wx ((*i)->to_string ()))); -// } -// if (_film->subtitle_stream()) { -// checked_set (_subtitle_stream, _film->subtitle_stream()->to_string()); -// } else { -// _subtitle_stream->SetSelection (wxNOT_FOUND); -// } + vector s = _film->ffmpeg_subtitle_streams (); + for (vector::iterator i = s.begin(); i != s.end(); ++i) { + _ffmpeg_subtitle_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (boost::lexical_cast (i->id)))); + } + + if (_film->ffmpeg_subtitle_stream()) { + checked_set (_ffmpeg_subtitle_stream, boost::lexical_cast (_film->ffmpeg_subtitle_stream()->id)); + } else { + _ffmpeg_subtitle_stream->SetSelection (wxNOT_FOUND); + } } void @@ -1066,14 +1141,16 @@ FilmEditor::ffmpeg_audio_stream_changed (wxCommandEvent &) return; } -#if 0 - _film->set_content_audio_stream ( - audio_stream_factory ( - string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ())), - Film::state_version - ) - ); -#endif + vector a = _film->ffmpeg_audio_streams (); + vector::iterator i = a.begin (); + string const s = string_client_data (_ffmpeg_audio_stream->GetClientObject (_ffmpeg_audio_stream->GetSelection ())); + while (i != a.end() && lexical_cast (i->id) != s) { + ++i; + } + + if (i != a.end ()) { + _film->set_ffmpeg_audio_stream (*i); + } } void @@ -1083,33 +1160,35 @@ FilmEditor::ffmpeg_subtitle_stream_changed (wxCommandEvent &) return; } -#if 0 - _film->set_subtitle_stream ( - subtitle_stream_factory ( - string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ())), - Film::state_version - ) - ); -#endif + vector a = _film->ffmpeg_subtitle_streams (); + vector::iterator i = a.begin (); + string const s = string_client_data (_ffmpeg_subtitle_stream->GetClientObject (_ffmpeg_subtitle_stream->GetSelection ())); + while (i != a.end() && lexical_cast (i->id) != s) { + ++i; + } + + if (i != a.end ()) { + _film->set_ffmpeg_subtitle_stream (*i); + } } void FilmEditor::setup_audio_details () { -#if 0 - if (!_film->content_audio_stream()) { + if (!_film->ffmpeg_audio_stream()) { _audio->SetLabel (wxT ("")); } else { - stringstream s; - if (_film->audio_stream()->channels() == 1) { - s << wx_to_std (_("1 channel")); + wxString s; + if (_film->audio_channels() == 1) { + s << _("1 channel"); } else { - s << _film->audio_stream()->channels () << " " << wx_to_std (_("channels")); + s << _film->audio_channels() << " " << _("channels"); } - s << ", " << _film->audio_stream()->sample_rate() << wx_to_std (_("Hz")); - _audio->SetLabel (std_to_wx (s.str ())); + s << ", " << _film->audio_frame_rate() << _("Hz"); + _audio->SetLabel (s); } -#endif + + setup_notebook_size (); } void @@ -1162,11 +1241,26 @@ FilmEditor::setup_show_audio_sensitivity () void FilmEditor::setup_content () { + string selected_summary; + int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (s != -1) { + selected_summary = wx_to_std (_content->GetItemText (s)); + } + _content->DeleteAllItems (); ContentList content = _film->content (); for (ContentList::iterator i = content.begin(); i != content.end(); ++i) { - _content->InsertItem (_content->GetItemCount(), std_to_wx ((*i)->summary ())); + int const t = _content->GetItemCount (); + _content->InsertItem (t, std_to_wx ((*i)->summary ())); + if ((*i)->summary() == selected_summary) { + _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + } + } + + if (selected_summary.empty () && !content.empty ()) { + /* Select the first item of content if non was selected before */ + _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } } @@ -1196,65 +1290,162 @@ FilmEditor::content_add_clicked (wxCommandEvent &) void FilmEditor::content_remove_clicked (wxCommandEvent &) { - int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (s == -1) { - return; + shared_ptr c = selected_content (); + if (c) { + _film->remove_content (c); } +} +void +FilmEditor::content_activated (wxListEvent& ev) +{ ContentList c = _film->content (); - assert (s >= 0 && size_t (s) < c.size ()); - _film->remove_content (c[s]); + assert (ev.GetIndex() >= 0 && size_t (ev.GetIndex()) < c.size ()); + + edit_content (c[ev.GetIndex()]); } void -FilmEditor::content_earlier_clicked (wxCommandEvent &) +FilmEditor::content_edit_clicked (wxCommandEvent &) { - int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (s == -1) { + shared_ptr c = selected_content (); + if (!c) { return; } - ContentList c = _film->content (); - assert (s >= 0 && size_t (s) < c.size ()); - _film->move_content_earlier (c[s]); + edit_content (c); +} + +void +FilmEditor::edit_content (shared_ptr c) +{ + shared_ptr im = dynamic_pointer_cast (c); + if (im) { + ImageMagickContentDialog* d = new ImageMagickContentDialog (this, im); + d->ShowModal (); + d->Destroy (); + + im->set_video_length (d->video_length() * 24); + } +} + +void +FilmEditor::content_earlier_clicked (wxCommandEvent &) +{ + shared_ptr c = selected_content (); + if (c) { + _film->move_content_earlier (c); + } } void FilmEditor::content_later_clicked (wxCommandEvent &) { - int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (s == -1) { + shared_ptr c = selected_content (); + if (c) { + _film->move_content_later (c); + } +} + +void +FilmEditor::content_selection_changed (wxListEvent &) +{ + setup_content_button_sensitivity (); + setup_content_information (); +} + +void +FilmEditor::setup_content_information () +{ + shared_ptr c = selected_content (); + if (!c) { + _content_information->SetValue (wxT ("")); return; } - ContentList c = _film->content (); - assert (s >= 0 && size_t (s) < c.size ()); - _film->move_content_later (c[s]); + _content_information->SetValue (std_to_wx (c->information ())); } void -FilmEditor::content_item_selected (wxListEvent &) +FilmEditor::setup_content_button_sensitivity () { - setup_content_button_sensitivity (); + _content_add->Enable (_generally_sensitive); + shared_ptr selection = selected_content (); + + _content_edit->Enable (selection && _generally_sensitive && dynamic_pointer_cast (selection)); + _content_remove->Enable (selection && _generally_sensitive); + _content_earlier->Enable (selection && _generally_sensitive); + _content_later->Enable (selection && _generally_sensitive); +} + +shared_ptr +FilmEditor::selected_content () +{ int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (s == -1) { - _content_information->SetValue (""); - return; + return shared_ptr (); } ContentList c = _film->content (); - assert (s >= 0 && size_t (s) < c.size ()); - _content_information->SetValue (std_to_wx (c[s]->information ())); + if (s < 0 || size_t (s) >= c.size ()) { + return shared_ptr (); + } + + return c[s]; } void -FilmEditor::setup_content_button_sensitivity () +FilmEditor::setup_scaling_description () { - _content_add->Enable (_generally_sensitive); + wxString d; + + int lines = 0; + + d << wxString::Format ( + _("Original video is %dx%d (%.2f:1)\n"), + _film->video_size().width, _film->video_size().height, + float (_film->video_size().width) / _film->video_size().height + ); + + ++lines; + + Crop const crop = _film->crop (); + if (crop.left || crop.right || crop.top || crop.bottom) { + libdcp::Size const cropped = _film->cropped_size (_film->video_size ()); + d << wxString::Format ( + _("Cropped to %dx%d (%.2f:1)\n"), + cropped.width, cropped.height, + float (cropped.width) / cropped.height + ); + ++lines; + } + + Format const * format = _film->format (); + if (format) { + int const padding = format->dcp_padding (_film); + libdcp::Size scaled = format->dcp_size (); + scaled.width -= padding * 2; + d << wxString::Format ( + _("Scaled to %dx%d (%.2f:1)\n"), + scaled.width, scaled.height, + float (scaled.width) / scaled.height + ); + ++lines; + + if (padding) { + d << wxString::Format ( + _("Padded with black to %dx%d (%.2f:1)\n"), + format->dcp_size().width, format->dcp_size().height, + float (format->dcp_size().width) / format->dcp_size().height + ); + ++lines; + } + } + + for (int i = lines; i < 4; ++i) { + d << " \n"; + } - bool const have_selection = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1; - _content_remove->Enable (have_selection && _generally_sensitive); - _content_earlier->Enable (have_selection && _generally_sensitive); - _content_later->Enable (have_selection && _generally_sensitive); + _scaling_description->SetLabel (d); }