Merge master.
[dcpomatic.git] / src / wx / film_editor.cc
index 004bcb922b04f027b7c2f9b45b1b2687477926a5..2d8c752a1229883cfd313031e9eb627805d98bb8 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
 
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/lexical_cast.hpp>
-#include "lib/format.h"
 #include "lib/film.h"
 #include "lib/transcode_job.h"
 #include "lib/exceptions.h"
-#include "lib/ab_transcode_job.h"
 #include "lib/job_manager.h"
 #include "lib/filter.h"
+#include "lib/ratio.h"
 #include "lib/config.h"
-#include "lib/ffmpeg_decoder.h"
 #include "lib/imagemagick_content.h"
 #include "lib/sndfile_content.h"
 #include "lib/dcp_content_type.h"
@@ -54,7 +50,7 @@
 #include "imagemagick_content_dialog.h"
 #include "timeline_dialog.h"
 #include "audio_mapping_view.h"
-#include "container.h"
+#include "timecode.h"
 
 using std::string;
 using std::cout;
@@ -87,7 +83,7 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        make_dcp_panel ();
        _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
        
-       setup_formats ();
+       setup_ratios ();
 
        set_film (f);
        connect_to_widgets ();
@@ -106,39 +102,44 @@ FilmEditor::make_dcp_panel ()
        _dcp_sizer = new wxBoxSizer (wxVERTICAL);
        _dcp_panel->SetSizer (_dcp_sizer);
 
-       wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
+       wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
        _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
 
        int r = 0;
        
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
        _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
-       grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
+       grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
        ++r;
        
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
        _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
        grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        ++r;
 
+       int flags = wxALIGN_CENTER_VERTICAL;
+#ifdef __WXOSX__
+       flags |= wxALIGN_RIGHT;
+#endif 
+
        _use_dci_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use DCI name"));
-       grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
+       grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
        _edit_dci_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
        grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
        _container = new wxChoice (_dcp_panel, wxID_ANY);
-       grid->Add (_container, wxGBPosition (r, 1));
+       grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
        _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
        grid->Add (_dcp_content_type, wxGBPosition (r, 1));
        ++r;
 
        {
-               add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
+               add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Frame Rate"), true, wxGBPosition (r, 0));
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _dcp_frame_rate = new wxChoice (_dcp_panel, wxID_ANY);
                s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
@@ -149,18 +150,18 @@ FilmEditor::make_dcp_panel ()
        ++r;
 
        {
-               add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
+               add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
                wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
                s->Add (_j2k_bandwidth, 1);
-               add_label_to_sizer (s, _dcp_panel, _("MBps"));
+               add_label_to_sizer (s, _dcp_panel, _("MBps"), false);
                grid->Add (s, wxGBPosition (r, 1));
        }
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
        _scaler = new wxChoice (_dcp_panel, wxID_ANY);
-       grid->Add (_scaler, wxGBPosition (r, 1));
+       grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        ++r;
 
        vector<Scaler const *> const sc = Scaler::all ();
@@ -168,9 +169,9 @@ FilmEditor::make_dcp_panel ()
                _scaler->Append (std_to_wx ((*i)->name()));
        }
 
-       vector<Container const *> const co = Container::all ();
-       for (vector<Container const *>::const_iterator i = co.begin(); i != co.end(); ++i) {
-               _container->Append (std_to_wx ((*i)->name ()));
+       vector<Ratio const *> const ratio = Ratio::all ();
+       for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
+               _container->Append (std_to_wx ((*i)->nickname ()));
        }
 
        vector<DCPContentType const *> const ct = DCPContentType::all ();
@@ -193,7 +194,7 @@ FilmEditor::connect_to_widgets ()
        _use_dci_name->Connect           (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,     wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
        _edit_dci_button->Connect        (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
        _container->Connect              (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::container_changed), 0, this);
-//     _format->Connect                 (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::format_changed), 0, this);
+       _ratio->Connect                  (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::ratio_changed), 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_add->Connect            (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
@@ -210,6 +211,8 @@ FilmEditor::connect_to_widgets ()
        _dcp_content_type->Connect       (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
        _dcp_frame_rate->Connect         (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
        _best_dcp_frame_rate->Connect    (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
+//     _pad_with_silence->Connect       (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,     wxCommandEventHandler (FilmEditor::pad_with_silence_toggled), 0, this);
+//     _minimum_audio_channels->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,   wxCommandEventHandler (FilmEditor::minimum_audio_channels_changed), 0, this);
        _with_subtitles->Connect         (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,     wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
        _subtitle_offset->Connect        (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
        _subtitle_scale->Connect         (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
@@ -223,43 +226,45 @@ FilmEditor::connect_to_widgets ()
        _audio_delay->Connect            (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
        _audio_stream->Connect           (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::audio_stream_changed), 0, this);
        _subtitle_stream->Connect        (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::subtitle_stream_changed), 0, this);
-       _audio_mapping->Changed.connect  (bind (&FilmEditor::audio_mapping_changed, this, _1));
+       _audio_mapping->Changed.connect  (boost::bind (&FilmEditor::audio_mapping_changed, this, _1));
+       _start->Changed.connect          (boost::bind (&FilmEditor::start_changed, this));
+       _length->Changed.connect         (boost::bind (&FilmEditor::length_changed, this));
 }
 
 void
 FilmEditor::make_video_panel ()
 {
        _video_panel = new wxPanel (_content_notebook);
-       _video_sizer = new wxBoxSizer (wxVERTICAL);
-       _video_panel->SetSizer (_video_sizer);
+       wxBoxSizer* video_sizer = new wxBoxSizer (wxVERTICAL);
+       _video_panel->SetSizer (video_sizer);
        
-       wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
-       _video_sizer->Add (grid, 0, wxALL, 8);
+       wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+       video_sizer->Add (grid, 0, wxALL, 8);
 
        int r = 0;
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), true, wxGBPosition (r, 0));
        _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_left_crop, wxGBPosition (r, 1));
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), true, wxGBPosition (r, 0));
        _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_right_crop, wxGBPosition (r, 1));
        ++r;
        
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), true, wxGBPosition (r, 0));
        _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_top_crop, wxGBPosition (r, 1));
        ++r;
        
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), true, wxGBPosition (r, 0));
        _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_bottom_crop, wxGBPosition (r, 1));
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), wxGBPosition (r, 0));
-       _format = new wxChoice (_video_panel, wxID_ANY);
-       grid->Add (_format, wxGBPosition (r, 1));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), true, wxGBPosition (r, 0));
+       _ratio = new wxChoice (_video_panel, wxID_ANY);
+       grid->Add (_ratio, wxGBPosition (r, 1));
        ++r;
 
        _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
@@ -272,17 +277,17 @@ FilmEditor::make_video_panel ()
 
        /* VIDEO-only stuff */
        {
-               add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
+               add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), true, wxGBPosition (r, 0));
                wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
                s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
                _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
-               s->Add (_filters_button, 0);
+               s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
                grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        }
        ++r;
 
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), true, wxGBPosition (r, 0));
        _colour_lut = new wxChoice (_video_panel, wxID_ANY);
        for (int i = 0; i < 2; ++i) {
                _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
@@ -331,18 +336,20 @@ FilmEditor::make_content_panel ()
        h->Add (_loop_content, 0, wxALL, 6);
        _loop_count = new wxSpinCtrl (_content_panel, wxID_ANY);
        h->Add (_loop_count, 0, wxALL, 6);
-       add_label_to_sizer (h, _content_panel, _("times"));
+       add_label_to_sizer (h, _content_panel, _("times"), false);
        _content_sizer->Add (h, 0, wxALL, 6);
 
        _content_notebook = new wxNotebook (_content_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT);
        _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
-       
+
        make_video_panel ();
        _content_notebook->AddPage (_video_panel, _("Video"), false);
        make_audio_panel ();
        _content_notebook->AddPage (_audio_panel, _("Audio"), false);
        make_subtitle_panel ();
        _content_notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
+       make_timing_panel ();
+       _content_notebook->AddPage (_timing_panel, _("Timing"), false);
 
        _loop_count->SetRange (2, 1024);
 }
@@ -351,42 +358,42 @@ void
 FilmEditor::make_audio_panel ()
 {
        _audio_panel = new wxPanel (_content_notebook);
-       _audio_sizer = new wxBoxSizer (wxVERTICAL);
-       _audio_panel->SetSizer (_audio_sizer);
+       wxBoxSizer* audio_sizer = new wxBoxSizer (wxVERTICAL);
+       _audio_panel->SetSizer (audio_sizer);
        
-       wxFlexGridSizer* grid = new wxFlexGridSizer (3, 4, 4);
-       _audio_sizer->Add (grid, 0, wxALL, 8);
+       wxFlexGridSizer* grid = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+       audio_sizer->Add (grid, 0, wxALL, 8);
 
        _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
        grid->Add (_show_audio, 1);
        grid->AddSpacer (0);
        grid->AddSpacer (0);
 
-       add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
+       add_label_to_sizer (grid, _audio_panel, _("Audio Gain"), true);
        {
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _audio_gain = new wxSpinCtrl (_audio_panel);
                s->Add (_audio_gain, 1);
-               add_label_to_sizer (s, _audio_panel, _("dB"));
+               add_label_to_sizer (s, _audio_panel, _("dB"), false);
                grid->Add (s, 1);
        }
        
        _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
        grid->Add (_audio_gain_calculate_button);
 
-       add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
+       add_label_to_sizer (grid, _audio_panel, _("Audio Delay"), false);
        {
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _audio_delay = new wxSpinCtrl (_audio_panel);
                s->Add (_audio_delay, 1);
                /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
-               add_label_to_sizer (s, _audio_panel, _("ms"));
+               add_label_to_sizer (s, _audio_panel, _("ms"), false);
                grid->Add (s);
        }
 
        grid->AddSpacer (0);
 
-       add_label_to_sizer (grid, _audio_panel, _("Audio Stream"));
+       add_label_to_sizer (grid, _audio_panel, _("Audio Stream"), true);
        _audio_stream = new wxChoice (_audio_panel, wxID_ANY);
        grid->Add (_audio_stream, 1);
        _audio_description = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
@@ -397,44 +404,68 @@ FilmEditor::make_audio_panel ()
        grid->AddSpacer (0);
        
        _audio_mapping = new AudioMappingView (_audio_panel);
-       _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
+       audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
+
+#if 0  
+       {
+               _pad_with_silence = new wxCheckBox (_audio_panel, wxID_ANY, _("Pad with silence to"));
+               grid->Add (_pad_with_silence);
+               wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _minimum_audio_channels = new wxSpinCtrl (_audio_panel);
+               s->Add (_minimum_audio_channels, 1);
+               add_label_to_sizer (s, _audio_panel, _("channels"), false);
+               grid->Add (s);
+       }
+
+       {
+               _use_content_audio = new wxRadioButton (_audio_panel, wxID_ANY, _("Use content's audio"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
+               grid->Add (video_control (_use_content_audio));
+               wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _audio_stream = new wxChoice (_audio_panel, wxID_ANY);
+               s->Add (video_control (_audio_stream), 1);
+               _audio = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
+               s->Add (video_control (_audio), 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
+               grid->Add (s);
+       }
+#endif 
 
        _audio_gain->SetRange (-60, 60);
        _audio_delay->SetRange (-1000, 1000);
+//     _minimum_audio_channels->SetRange (0, MAX_AUDIO_CHANNELS);
 }
 
 void
 FilmEditor::make_subtitle_panel ()
 {
        _subtitle_panel = new wxPanel (_content_notebook);
-       _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
-       _subtitle_panel->SetSizer (_subtitle_sizer);
-       wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
-       _subtitle_sizer->Add (grid, 0, wxALL, 8);
+       wxBoxSizer* subtitle_sizer = new wxBoxSizer (wxVERTICAL);
+       _subtitle_panel->SetSizer (subtitle_sizer);
+       wxFlexGridSizer* grid = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+       subtitle_sizer->Add (grid, 0, wxALL, 8);
 
        _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
        grid->Add (_with_subtitles, 1);
        grid->AddSpacer (0);
        
        {
-               add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
+               add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"), true);
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
                s->Add (_subtitle_offset);
-               add_label_to_sizer (s, _subtitle_panel, _("pixels"));
+               add_label_to_sizer (s, _subtitle_panel, _("pixels"), false);
                grid->Add (s);
        }
 
        {
-               add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
+               add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"), true);
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
                _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
                s->Add (_subtitle_scale);
-               add_label_to_sizer (s, _subtitle_panel, _("%"));
+               add_label_to_sizer (s, _subtitle_panel, _("%"), false);
                grid->Add (s);
        }
 
-       add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Stream"));
+       add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Stream"), true);
        _subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
        grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
        grid->AddSpacer (0);
@@ -443,6 +474,24 @@ FilmEditor::make_subtitle_panel ()
        _subtitle_scale->SetRange (1, 1000);
 }
 
+void
+FilmEditor::make_timing_panel ()
+{
+       _timing_panel = new wxPanel (_content_notebook);
+       wxBoxSizer* timing_sizer = new wxBoxSizer (wxVERTICAL);
+       _timing_panel->SetSizer (timing_sizer);
+       wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
+       timing_sizer->Add (grid, 0, wxALL, 8);
+
+       add_label_to_sizer (grid, _timing_panel, _("Start time"), true);
+       _start = new Timecode (_timing_panel);
+       grid->Add (_start);
+       add_label_to_sizer (grid, _timing_panel, _("Length"), true);
+       _length = new Timecode (_timing_panel);
+       grid->Add (_length);
+}
+
+
 /** Called when the left crop widget has been changed */
 void
 FilmEditor::left_crop_changed (wxCommandEvent &)
@@ -577,10 +626,9 @@ FilmEditor::film_changed (Film::Property p)
                break;
        case Film::CONTENT:
                setup_content ();
-               setup_formats ();
-//             setup_format ();
                setup_subtitle_control_sensitivity ();
                setup_show_audio_sensitivity ();
+               setup_minimum_audio_channels ();
                break;
        case Film::LOOP:
                checked_set (_loop_content, _film->loop() > 1);
@@ -590,18 +638,6 @@ FilmEditor::film_changed (Film::Property p)
        case Film::CONTAINER:
                setup_container ();
                break;
-       case Film::FILTERS:
-       {
-               pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
-               if (p.first.empty () && p.second.empty ()) {
-                       _filters->SetLabel (_("None"));
-               } else {
-                       string const b = p.first + " " + p.second;
-                       _filters->SetLabel (std_to_wx (b));
-               }
-               _dcp_sizer->Layout ();
-               break;
-       }
        case Film::NAME:
                checked_set (_name, _film->name());
                setup_dcp_name ();
@@ -655,6 +691,10 @@ FilmEditor::film_changed (Film::Property p)
                _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
                break;
        }
+       case Film::MINIMUM_AUDIO_CHANNELS:
+//             checked_set (_minimum_audio_channels, _film->minimum_audio_channels ());
+               setup_minimum_audio_channels ();
+               break;
        }
 }
 
@@ -671,28 +711,102 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
        shared_ptr<Content> content = weak_content.lock ();
        shared_ptr<VideoContent> video_content;
        shared_ptr<AudioContent> audio_content;
+       shared_ptr<FFmpegContent> ffmpeg_content;
        if (content) {
                video_content = dynamic_pointer_cast<VideoContent> (content);
                audio_content = dynamic_pointer_cast<AudioContent> (content);
+               ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
        }
 
-       if (property == VideoContentProperty::VIDEO_CROP) {
+       /* We can't use case {} here */
+       
+       if (property == ContentProperty::START) {
+               if (content) {
+                       _start->set (content->start (), _film->dcp_video_frame_rate ());
+               } else {
+                       _start->set (0, 24);
+               }
+       } else if (property == ContentProperty::LENGTH) {
+               if (content) {
+                       _length->set (content->length (), _film->dcp_video_frame_rate ());
+               } else {
+                       _length->set (0, 24);
+               }
+       } else if (property == VideoContentProperty::VIDEO_CROP) {
                checked_set (_left_crop,   video_content ? video_content->crop().left :   0);
                checked_set (_right_crop,  video_content ? video_content->crop().right :  0);
                checked_set (_top_crop,    video_content ? video_content->crop().top :    0);
                checked_set (_bottom_crop, video_content ? video_content->crop().bottom : 0);
                setup_scaling_description ();
+       } else if (property == VideoContentProperty::VIDEO_RATIO) {
+               if (video_content) {
+                       int n = 0;
+                       vector<Ratio const *> ratios = Ratio::all ();
+                       vector<Ratio const *>::iterator i = ratios.begin ();
+                       while (i != ratios.end() && *i != video_content->ratio()) {
+                               ++i;
+                               ++n;
+                       }
+
+                       if (i == ratios.end()) {
+                               checked_set (_ratio, -1);
+                       } else {
+                               checked_set (_ratio, n);
+                       }
+               } else {
+                       checked_set (_ratio, -1);
+               }
        } else if (property == AudioContentProperty::AUDIO_GAIN) {
                checked_set (_audio_gain, audio_content ? audio_content->audio_gain() : 0);
        } else if (property == AudioContentProperty::AUDIO_DELAY) {
                checked_set (_audio_delay, audio_content ? audio_content->audio_delay() : 0);
+       } else if (property == AudioContentProperty::AUDIO_MAPPING) {
+               _audio_mapping->set (audio_content ? audio_content->audio_mapping () : AudioMapping ());
        } else if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
+               _subtitle_stream->Clear ();
+               if (ffmpeg_content) {
+                       vector<shared_ptr<FFmpegSubtitleStream> > s = ffmpeg_content->subtitle_streams ();
+                       if (s.empty ()) {
+                               _subtitle_stream->Enable (false);
+                       }
+                       for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
+                               _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                       }
+                       
+                       if (ffmpeg_content->subtitle_stream()) {
+                               checked_set (_subtitle_stream, lexical_cast<string> (ffmpeg_content->subtitle_stream()->id));
+                       } else {
+                               _subtitle_stream->SetSelection (wxNOT_FOUND);
+                       }
+               }
                setup_subtitle_control_sensitivity ();
        } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
+               _audio_stream->Clear ();
+               if (ffmpeg_content) {
+                       vector<shared_ptr<FFmpegAudioStream> > a = ffmpeg_content->audio_streams ();
+                       for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
+                               _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                       }
+                       
+                       if (ffmpeg_content->audio_stream()) {
+                               checked_set (_audio_stream, lexical_cast<string> (ffmpeg_content->audio_stream()->id));
+                       }
+               }
                setup_show_audio_sensitivity ();
        } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
                setup_dcp_name ();
                setup_show_audio_sensitivity ();
+       } else if (property == FFmpegContentProperty::FILTERS) {
+               if (ffmpeg_content) {
+                       pair<string, string> p = Filter::ffmpeg_strings (ffmpeg_content->filters ());
+                       if (p.first.empty () && p.second.empty ()) {
+                               _filters->SetLabel (_("None"));
+                       } else {
+                               string const b = p.first + " " + p.second;
+                               _filters->SetLabel (std_to_wx (b));
+                       }
+                       _dcp_sizer->Layout ();
+               }
        }
 }
 
@@ -700,14 +814,14 @@ void
 FilmEditor::setup_container ()
 {
        int n = 0;
-       vector<Container const *> containers = Container::all ();
-       vector<Container const *>::iterator i = containers.begin ();
-       while (i != containers.end() && *i != _film->container ()) {
+       vector<Ratio const *> ratios = Ratio::all ();
+       vector<Ratio const *>::iterator i = ratios.begin ();
+       while (i != ratios.end() && *i != _film->container ()) {
                ++i;
                ++n;
        }
        
-       if (i == containers.end()) {
+       if (i == ratios.end()) {
                checked_set (_container, -1);
        } else {
                checked_set (_container, n);
@@ -727,9 +841,9 @@ FilmEditor::container_changed (wxCommandEvent &)
 
        int const n = _container->GetSelection ();
        if (n >= 0) {
-               vector<Container const *> containers = Container::all ();
-               assert (n < int (containers.size()));
-               _film->set_container (containers[n]);
+               vector<Ratio const *> ratios = Ratio::all ();
+               assert (n < int (ratios.size()));
+               _film->set_container (ratios[n]);
        }
 }
 
@@ -770,17 +884,12 @@ FilmEditor::set_film (shared_ptr<Film> f)
                FileChanged ("");
        }
 
-       if (_audio_dialog) {
-               _audio_dialog->set_film (_film);
-       }
-       
        film_changed (Film::NAME);
        film_changed (Film::USE_DCI_NAME);
        film_changed (Film::CONTENT);
        film_changed (Film::LOOP);
        film_changed (Film::DCP_CONTENT_TYPE);
        film_changed (Film::CONTAINER);
-       film_changed (Film::FILTERS);
        film_changed (Film::SCALER);
        film_changed (Film::WITH_SUBTITLES);
        film_changed (Film::SUBTITLE_OFFSET);
@@ -790,13 +899,8 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::DCI_METADATA);
        film_changed (Film::DCP_VIDEO_FRAME_RATE);
 
-       film_content_changed (boost::shared_ptr<Content> (), VideoContentProperty::VIDEO_CROP);
-       film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_GAIN);
-       film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_DELAY);
-       film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
-       film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
-       film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
-       film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
+       wxListEvent ev;
+       content_selection_changed (ev);
 }
 
 /** Updates the sensitivity of lots of widgets to a given value.
@@ -810,8 +914,7 @@ FilmEditor::set_things_sensitive (bool s)
        _name->Enable (s);
        _use_dci_name->Enable (s);
        _edit_dci_button->Enable (s);
-       _format->Enable (s);
-       _content->Enable (s);
+       _ratio->Enable (s);
        _content->Enable (s);
        _left_crop->Enable (s);
        _right_crop->Enable (s);
@@ -828,6 +931,9 @@ FilmEditor::set_things_sensitive (bool s)
        _audio_gain_calculate_button->Enable (s);
        _show_audio->Enable (s);
        _audio_delay->Enable (s);
+       _container->Enable (s);
+       _loop_content->Enable (s);
+       _loop_count->Enable (s);
 
        setup_subtitle_control_sensitivity ();
        setup_show_audio_sensitivity ();
@@ -838,8 +944,18 @@ FilmEditor::set_things_sensitive (bool s)
 void
 FilmEditor::edit_filters_clicked (wxCommandEvent &)
 {
-       FilterDialog* d = new FilterDialog (this, _film->filters());
-       d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
+       if (!fc) {
+               return;
+       }
+       
+       FilterDialog* d = new FilterDialog (this, fc->filters());
+       d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
        d->ShowModal ();
        d->Destroy ();
 }
@@ -922,13 +1038,13 @@ FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
 }
 
 void
-FilmEditor::setup_formats ()
+FilmEditor::setup_ratios ()
 {
-       _formats = Format::all ();
+       _ratios = Ratio::all ();
 
-       _format->Clear ();
-       for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
-               _format->Append (std_to_wx ((*i)->name ()));
+       _ratio->Clear ();
+       for (vector<Ratio const *>::iterator i = _ratios.begin(); i != _ratios.end(); ++i) {
+               _ratio->Append (std_to_wx ((*i)->nickname ()));
        }
 
        _dcp_sizer->Layout ();
@@ -1011,10 +1127,20 @@ FilmEditor::show_audio_clicked (wxCommandEvent &)
                _audio_dialog->Destroy ();
                _audio_dialog = 0;
        }
+
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
+       if (!ac) {
+               return;
+       }
        
        _audio_dialog = new AudioDialog (this);
        _audio_dialog->Show ();
-       _audio_dialog->set_film (_film);
+       _audio_dialog->set_content (ac);
 }
 
 void
@@ -1054,7 +1180,7 @@ FilmEditor::setup_content ()
        }
 
        if (selected_summary.empty () && !content.empty ()) {
-               /* Select the item of content if non was selected before */
+               /* Select the item of content if none was selected before */
                _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
        }
 }
@@ -1076,13 +1202,17 @@ FilmEditor::content_add_clicked (wxCommandEvent &)
        for (unsigned int i = 0; i < paths.GetCount(); ++i) {
                boost::filesystem::path p (wx_to_std (paths[i]));
 
+               shared_ptr<Content> c;
+
                if (ImageMagickContent::valid_file (p)) {
-                       _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (_film, p)));
+                       c.reset (new ImageMagickContent (_film, p));
                } else if (SndfileContent::valid_file (p)) {
-                       _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (_film, p)));
+                       c.reset (new SndfileContent (_film, p));
                } else {
-                       _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (_film, p)));
+                       c.reset (new FFmpegContent (_film, p));
                }
+
+               _film->examine_and_add_content (c);
        }
 }
 
@@ -1099,6 +1229,22 @@ void
 FilmEditor::content_selection_changed (wxListEvent &)
 {
         setup_content_sensitivity ();
+       shared_ptr<Content> s = selected_content ();
+       
+       if (_audio_dialog && s && dynamic_pointer_cast<AudioContent> (s)) {
+               _audio_dialog->set_content (dynamic_pointer_cast<AudioContent> (s));
+       }
+       
+       film_content_changed (s, ContentProperty::START);
+       film_content_changed (s, ContentProperty::LENGTH);
+       film_content_changed (s, VideoContentProperty::VIDEO_CROP);
+       film_content_changed (s, VideoContentProperty::VIDEO_RATIO);
+       film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
+       film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
+       film_content_changed (s, AudioContentProperty::AUDIO_MAPPING);
+       film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
+       film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
+       film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
 }
 
 void
@@ -1111,9 +1257,10 @@ FilmEditor::setup_content_sensitivity ()
         _content_remove->Enable (selection && _generally_sensitive);
        _content_timeline->Enable (_generally_sensitive);
 
-       _video_panel->Enable (selection && _generally_sensitive);
-       _audio_panel->Enable (selection && _generally_sensitive);
-       _subtitle_panel->Enable (selection && _generally_sensitive);
+       _video_panel->Enable    (selection && dynamic_pointer_cast<VideoContent>  (selection) && _generally_sensitive);
+       _audio_panel->Enable    (selection && dynamic_pointer_cast<AudioContent>  (selection) && _generally_sensitive);
+       _subtitle_panel->Enable (selection && dynamic_pointer_cast<FFmpegContent> (selection) && _generally_sensitive);
+       _timing_panel->Enable   (selection && _generally_sensitive);
 }
 
 shared_ptr<Content>
@@ -1173,8 +1320,8 @@ XXX
        }
 
        Crop const crop = _film->crop ();
-       if (crop.left || crop.right || crop.top || crop.bottom) {
-               libdcp::Size const cropped = _film->cropped_size (_film->video_size ());
+       if ((crop.left || crop.right || crop.top || crop.bottom) && _film->size() != libdcp::Size (0, 0)) {
+               libdcp::Size const cropped = _film->cropped_size (_film->size ());
                d << wxString::Format (
                        _("Cropped to %dx%d (%.2f:1)\n"),
                        cropped.width, cropped.height,
@@ -1249,48 +1396,6 @@ FilmEditor::content_timeline_clicked (wxCommandEvent &)
        _timeline_dialog->Show ();
 }
 
-void
-FilmEditor::setup_content_properties ()
-{
-       _audio_stream->Clear ();
-       _subtitle_stream->Clear ();
-
-       shared_ptr<Content> c = selected_content ();
-       if (!c) {
-               return;
-       }
-
-       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
-       if (fc) {
-               
-               vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
-               for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
-                       _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
-               }
-               
-               if (fc->audio_stream()) {
-                       checked_set (_audio_stream, lexical_cast<string> (fc->audio_stream()->id));
-               }
-               
-               vector<shared_ptr<FFmpegSubtitleStream> > s = fc->subtitle_streams ();
-               if (s.empty ()) {
-                       _subtitle_stream->Enable (false);
-               }
-               for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
-                       _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
-               }
-               
-               if (fc->subtitle_stream()) {
-                       checked_set (_subtitle_stream, lexical_cast<string> (fc->subtitle_stream()->id));
-               } else {
-                       _subtitle_stream->SetSelection (wxNOT_FOUND);
-               }
-
-               /* XXX: should be general audiocontent */
-               _audio_mapping->set_mapping (fc->audio_mapping ());
-       }
-}
-
 void
 FilmEditor::audio_stream_changed (wxCommandEvent &)
 {
@@ -1364,11 +1469,105 @@ FilmEditor::audio_mapping_changed (AudioMapping m)
                return;
        }
        
-       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
-       if (!fc) {
+       shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
+       if (!ac) {
+               return;
+       }
+
+       ac->set_audio_mapping (m);
+}
+
+void
+FilmEditor::start_changed ()
+{
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       c->set_start (_start->get (_film->dcp_video_frame_rate ()));
+}
+
+void
+FilmEditor::length_changed ()
+{
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (c);
+       if (ic) {
+               ic->set_video_length (_length->get(_film->dcp_video_frame_rate()) * ic->video_frame_rate() / TIME_HZ);
+       }
+}
+
+void
+FilmEditor::set_selection (weak_ptr<Content> wc)
+{
+       Playlist::ContentList content = _film->content ();
+       for (size_t i = 0; i < content.size(); ++i) {
+               if (content[i] == wc.lock ()) {
+                       _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+               } else {
+                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
+               }
+       }
+}
+
+void
+FilmEditor::ratio_changed (wxCommandEvent &)
+{
+       if (!_film) {
+               return;
+       }
+
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
+       if (!vc) {
+               return;
+       }
+       
+       int const n = _ratio->GetSelection ();
+       if (n >= 0) {
+               vector<Ratio const *> ratios = Ratio::all ();
+               assert (n < int (ratios.size()));
+               vc->set_ratio (ratios[n]);
+       }
+}
+
+void
+FilmEditor::setup_minimum_audio_channels ()
+{
+#if 0  
+       if (!_film || !_film->audio_stream ()) {
+               _pad_with_silence->SetValue (false);
+               return;
+       }
+
+       _pad_with_silence->SetValue (_film->audio_stream()->channels() < _film->minimum_audio_channels());
+
+       AudioMapping m (_film);
+       _minimum_audio_channels->SetRange (m.minimum_dcp_channels() + 1, MAX_AUDIO_CHANNELS);
+#endif 
+}
+
+void
+FilmEditor::pad_with_silence_toggled (wxCommandEvent &)
+{
+
+}
+
+void
+FilmEditor::minimum_audio_channels_changed (wxCommandEvent &)
+{
+       if (!_film) {
                return;
        }
 
-       /* XXX: should be general to audiocontent */
-       fc->audio_stream()->mapping = m;
+//     _film->set_minimum_audio_channels (_minimum_audio_channels->GetValue ());
 }