Present fixed formats with video content and variable formats with stills.
authorCarl Hetherington <cth@carlh.net>
Sun, 7 Oct 2012 23:20:10 +0000 (00:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 7 Oct 2012 23:20:10 +0000 (00:20 +0100)
src/lib/format.cc
src/lib/format.h
src/wx/film_editor.cc
src/wx/film_editor.h

index 115e036915d7d35700cee8518339692c6fa86349..aaf5211f953d1aac12b70a78aed486a79ca5ff98 100644 (file)
@@ -123,34 +123,6 @@ Format::from_metadata (string m)
        return from_id (m);
 }
 
-/** @param f A Format.
- *  @return Index of f within our static list, or -1.
- */
-int
-Format::as_index (Format const * f)
-{
-       vector<Format*>::size_type i = 0;
-       while (i < _formats.size() && _formats[i] != f) {
-               ++i;
-       }
-
-       if (i == _formats.size ()) {
-               return -1;
-       }
-
-       return i;
-}
-
-/** @param i An index returned from as_index().
- *  @return Corresponding Format.
- */
-Format const *
-Format::from_index (int i)
-{
-       assert (i >= 0 && i < int(_formats.size ()));
-       return _formats[i];
-}
-
 /** @return All available formats */
 vector<Format const *>
 Format::all ()
@@ -205,16 +177,5 @@ VariableFormat::ratio_as_float (Film const * f) const
 string
 VariableFormat::name () const
 {
-       stringstream s;
-       if (!_nickname.empty ()) {
-               s << _nickname << " (";
-       }
-
-       s << "without stretching";
-
-       if (!_nickname.empty ()) {
-               s << ")";
-       }
-
-       return s.str ();
+       return _nickname;
 }
index 6172dc57d43b3b67881856a14d7d908c29b24b62..fd6cdbece31b1ffb51db910fa77493a98228aa38 100644 (file)
@@ -71,9 +71,7 @@ public:
 
        static Format const * from_nickname (std::string n);
        static Format const * from_metadata (std::string m);
-       static Format const * from_index (int i);
        static Format const * from_id (std::string i);
-       static int as_index (Format const * f);
        static std::vector<Format const *> all ();
        static void setup_formats ();
 
index 9171daa5c2d093acd0111111bd581dd0f64a5744..3b26a5537e3bf3327f80e42bb048bcb20e9e065c 100644 (file)
@@ -182,11 +182,6 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _audio_delay->SetRange (-1000, 1000);
        _still_duration->SetRange (0, 60 * 60);
 
-       vector<Format const *> fmt = Format::all ();
-       for (vector<Format const *>::iterator i = fmt.begin(); i != fmt.end(); ++i) {
-               _format->Append (std_to_wx ((*i)->name ()));
-       }
-
        vector<DCPContentType const *> const ct = DCPContentType::all ();
        for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
                _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
@@ -221,6 +216,7 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _change_dcp_range_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::change_dcp_range_clicked), 0, this);
 
        setup_visibility ();
+       setup_formats ();
 }
 
 /** Called when the left crop widget has been changed */
@@ -295,6 +291,7 @@ FilmEditor::content_changed (wxCommandEvent &)
        _ignore_changes = Film::NONE;
 
        setup_visibility ();
+       setup_formats ();
 }
 
 /** Called when the DCP A/B switch has been toggled */
@@ -342,10 +339,19 @@ FilmEditor::film_changed (Film::Property p)
        case Film::CONTENT:
                _content->SetPath (std_to_wx (_film->content ()));
                setup_visibility ();
+               setup_formats ();
                break;
        case Film::FORMAT:
-               _format->SetSelection (Format::as_index (_film->format ()));
+       {
+               int n = 0;
+               vector<Format const *>::iterator i = _formats.begin ();
+               while (i != _formats.end() && *i != _film->format ()) {
+                       ++i;
+                       ++n;
+               }
+               _format->SetSelection (n);
                break;
+       }
        case Film::CROP:
                _left_crop->SetValue (_film->crop().left);
                _right_crop->SetValue (_film->crop().right);
@@ -445,7 +451,8 @@ FilmEditor::format_changed (wxCommandEvent &)
        _ignore_changes = Film::FORMAT;
        int const n = _format->GetSelection ();
        if (n >= 0) {
-               _film->set_format (Format::from_index (n));
+               assert (n < int (_formats.size()));
+               _film->set_format (_formats[n]);
        }
        _ignore_changes = Film::NONE;
 }
@@ -667,3 +674,31 @@ FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
        
        d->Destroy ();
 }
+
+void
+FilmEditor::setup_formats ()
+{
+       ContentType c = VIDEO;
+
+       if (_film) {
+               c = _film->content_type ();
+       }
+       
+       _formats.clear ();
+
+       vector<Format const *> fmt = Format::all ();
+       for (vector<Format const *>::iterator i = fmt.begin(); i != fmt.end(); ++i) {
+               if (c == VIDEO && dynamic_cast<FixedFormat const *> (*i)) {
+                       _formats.push_back (*i);
+               } else if (c == STILL && dynamic_cast<VariableFormat const *> (*i)) {
+                       _formats.push_back (*i);
+               }
+       }
+
+       _format->Clear ();
+       for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
+               _format->Append (std_to_wx ((*i)->name ()));
+       }
+
+       _sizer->Layout ();
+}
index ac9a5fb3196f78534e1d3e726fdc6811c63ee444..c599cd285c97e0b8ffb4d39b70ac5aba41a5704f 100644 (file)
@@ -68,7 +68,8 @@ private:
        void change_dcp_range_clicked (wxCommandEvent &);
 
        void set_things_sensitive (bool);
-
+       void setup_formats ();
+       
        wxControl* video_control (wxControl *);
        wxControl* still_control (wxControl *);
 
@@ -125,5 +126,7 @@ private:
        std::list<wxControl*> _video_controls;
        std::list<wxControl*> _still_controls;
 
+       std::vector<Format const *> _formats;
+
        wxSizer* _sizer;
 };