Make DCIMetadata class and use it.
authorCarl Hetherington <cth@carlh.net>
Fri, 25 Jan 2013 17:16:13 +0000 (17:16 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 25 Jan 2013 17:16:13 +0000 (17:16 +0000)
src/lib/dci_metadata.cc [new file with mode: 0644]
src/lib/dci_metadata.h [new file with mode: 0644]
src/lib/film.cc
src/lib/film.h
src/lib/wscript
src/wx/dci_name_dialog.cc
src/wx/dci_name_dialog.h

diff --git a/src/lib/dci_metadata.cc b/src/lib/dci_metadata.cc
new file mode 100644 (file)
index 0000000..2b4cc3a
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+    Copyright (C) 2012 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 <iostream>
+#include "dci_metadata.h"
+
+using namespace std;
+
+void
+DCIMetadata::write (ostream& f) const
+{
+       f << "audio_language " << audio_language << "\n";
+       f << "subtitle_language " << subtitle_language << "\n";
+       f << "territory " << territory << "\n";
+       f << "rating " << rating << "\n";
+       f << "studio " << studio << "\n";
+       f << "facility " << facility << "\n";
+       f << "package_type " << package_type << "\n";
+}
+
+void
+DCIMetadata::read (string k, string v)
+{
+       if (k == "audio_language") {
+               audio_language = v;
+       } else if (k == "subtitle_language") {
+               subtitle_language = v;
+       } else if (k == "territory") {
+               territory = v;
+       } else if (k == "rating") {
+               rating = v;
+       } else if (k == "studio") {
+               studio = v;
+       } else if (k == "facility") {
+               facility = v;
+       } else if (k == "package_type") {
+               package_type = v;
+       }
+}      
diff --git a/src/lib/dci_metadata.h b/src/lib/dci_metadata.h
new file mode 100644 (file)
index 0000000..eecdc76
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2012 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.
+
+*/
+
+#ifndef DVDOMATIC_DCI_METADATA_H
+#define DVDOMATIC_DCI_METADATA_H
+
+#include <string>
+
+class DCIMetadata
+{
+public:
+       void read (std::string, std::string);
+       void write (std::ostream &) const;
+       
+       std::string audio_language;
+       std::string subtitle_language;
+       std::string territory;
+       std::string rating;
+       std::string studio;
+       std::string facility;
+       std::string package_type;
+};
+
+#endif
index 5a11b0ca969ec5bfb262168158fb3be52e52514f..df89a2552592f1d3865024f00c199413e374c9f5 100644 (file)
@@ -170,13 +170,7 @@ Film::Film (Film const & o)
        , _subtitle_scale    (o._subtitle_scale)
        , _colour_lut        (o._colour_lut)
        , _j2k_bandwidth     (o._j2k_bandwidth)
-       , _audio_language    (o._audio_language)
-       , _subtitle_language (o._subtitle_language)
-       , _territory         (o._territory)
-       , _rating            (o._rating)
-       , _studio            (o._studio)
-       , _facility          (o._facility)
-       , _package_type      (o._package_type)
+       , _dci_metadata      (o._dci_metadata)
        , _size              (o._size)
        , _length            (o._length)
        , _content_digest    (o._content_digest)
@@ -432,14 +426,7 @@ Film::write_metadata () const
        f << "subtitle_scale " << _subtitle_scale << "\n";
        f << "colour_lut " << _colour_lut << "\n";
        f << "j2k_bandwidth " << _j2k_bandwidth << "\n";
-       f << "audio_language " << _audio_language << "\n";
-       f << "subtitle_language " << _subtitle_language << "\n";
-       f << "territory " << _territory << "\n";
-       f << "rating " << _rating << "\n";
-       f << "studio " << _studio << "\n";
-       f << "facility " << _facility << "\n";
-       f << "package_type " << _package_type << "\n";
-
+       _dci_metadata.write (f);
        f << "width " << _size.width << "\n";
        f << "height " << _size.height << "\n";
        f << "length " << _length.get_value_or(0) << "\n";
@@ -561,21 +548,9 @@ Film::read_metadata ()
                        _colour_lut = atoi (v.c_str ());
                } else if (k == "j2k_bandwidth") {
                        _j2k_bandwidth = atoi (v.c_str ());
-               } else if (k == "audio_language") {
-                       _audio_language = v;
-               } else if (k == "subtitle_language") {
-                       _subtitle_language = v;
-               } else if (k == "territory") {
-                       _territory = v;
-               } else if (k == "rating") {
-                       _rating = v;
-               } else if (k == "studio") {
-                       _studio = v;
-               } else if (k == "facility") {
-                       _facility = v;
-               } else if (k == "package_type") {
-                       _package_type = v;
                }
+
+               _dci_metadata.read (k, v);
                
                /* Cached stuff */
                if (k == "width") {
@@ -752,10 +727,12 @@ Film::dci_name () const
                d << format()->dci_name() << "_";
        }
 
-       if (!audio_language().empty ()) {
-               d << audio_language();
-               if (!subtitle_language().empty() && with_subtitles()) {
-                       d << "-" << subtitle_language();
+       DCIMetadata const dm = dci_metadata ();
+
+       if (!dm.audio_language.empty ()) {
+               d << dm.audio_language;
+               if (!dm.subtitle_language.empty() && with_subtitles()) {
+                       d << "-" << dm.subtitle_language;
                } else {
                        d << "-XX";
                }
@@ -763,10 +740,10 @@ Film::dci_name () const
                d << "_";
        }
 
-       if (!territory().empty ()) {
-               d << territory();
-               if (!rating().empty ()) {
-                       d << "-" << rating();
+       if (!dm.territory.empty ()) {
+               d << dm.territory;
+               if (!dm.rating.empty ()) {
+                       d << "-" << dm.rating;
                }
                d << "_";
        }
@@ -788,18 +765,18 @@ Film::dci_name () const
 
        d << "2K_";
 
-       if (!studio().empty ()) {
-               d << studio() << "_";
+       if (!dm.studio.empty ()) {
+               d << dm.studio << "_";
        }
 
        d << boost::gregorian::to_iso_string (_dci_date) << "_";
 
-       if (!facility().empty ()) {
-               d << facility() << "_";
+       if (!dm.facility.empty ()) {
+               d << dm.facility << "_";
        }
 
-       if (!package_type().empty ()) {
-               d << package_type();
+       if (!dm.package_type.empty ()) {
+               d << dm.package_type;
        }
 
        return d.str ();
@@ -1227,71 +1204,11 @@ Film::set_j2k_bandwidth (int b)
 }
 
 void
-Film::set_audio_language (string l)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _audio_language = l;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_subtitle_language (string l)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _subtitle_language = l;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_territory (string t)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _territory = t;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_rating (string r)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _rating = r;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_studio (string s)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _studio = s;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_facility (string f)
-{
-       {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               _facility = f;
-       }
-       signal_changed (DCI_METADATA);
-}
-
-void
-Film::set_package_type (string p)
+Film::set_dci_metadata (DCIMetadata m)
 {
        {
                boost::mutex::scoped_lock lm (_state_mutex);
-               _package_type = p;
+               _dci_metadata = m;
        }
        signal_changed (DCI_METADATA);
 }
index d3530b81772ac43f117d2d4f2734778c9d0d28c9..af7ec670134bd9bdda2f32298ce9f5aa3a5c6cc0 100644 (file)
@@ -38,6 +38,7 @@ extern "C" {
 #include "dcp_content_type.h"
 #include "util.h"
 #include "stream.h"
+#include "dci_metadata.h"
 
 class Format;
 class Job;
@@ -265,41 +266,11 @@ public:
                return _j2k_bandwidth;
        }
 
-       std::string audio_language () const {
+       DCIMetadata dci_metadata () const {
                boost::mutex::scoped_lock lm (_state_mutex);
-               return _audio_language;
+               return _dci_metadata;
        }
        
-       std::string subtitle_language () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _subtitle_language;
-       }
-       
-       std::string territory () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _territory;
-       }
-       
-       std::string rating () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _rating;
-       }
-       
-       std::string studio () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _studio;
-       }
-       
-       std::string facility () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _facility;
-       }
-       
-       std::string package_type () const {
-               boost::mutex::scoped_lock lm (_state_mutex);
-               return _package_type;
-       }
-
        libdcp::Size size () const {
                boost::mutex::scoped_lock lm (_state_mutex);
                return _size;
@@ -368,13 +339,7 @@ public:
        void set_subtitle_scale (float);
        void set_colour_lut (int);
        void set_j2k_bandwidth (int);
-       void set_audio_language (std::string);
-       void set_subtitle_language (std::string);
-       void set_territory (std::string);
-       void set_rating (std::string);
-       void set_studio (std::string);
-       void set_facility (std::string);
-       void set_package_type (std::string);
+       void set_dci_metadata (DCIMetadata);
        void set_size (libdcp::Size);
        void set_length (SourceFrame);
        void unset_length ();
@@ -472,15 +437,9 @@ private:
        int _colour_lut;
        /** bandwidth for J2K files in bits per second */
        int _j2k_bandwidth;
-       
-       /* DCI naming stuff */
-       std::string _audio_language;
-       std::string _subtitle_language;
-       std::string _territory;
-       std::string _rating;
-       std::string _studio;
-       std::string _facility;
-       std::string _package_type;
+
+       /** DCI naming stuff */
+       DCIMetadata _dci_metadata;
 
        /* Data which are cached to speed things up */
 
index 4d93a31aa00b0b57d0a545547e75164cdcd60fcc..cada2b0c30b683f1979af043ebf3dad96aea9a31 100644 (file)
@@ -18,6 +18,7 @@ def build(bld):
                 config.cc
                  combiner.cc
                  cross.cc
+                dci_metadata.cc
                 dcp_content_type.cc
                 dcp_video_frame.cc
                  decoder.cc
index 6927d6c9eba713dc52e2c135878c2ce81542f937..41d93576f6be5e59b4eb5609e06fe811d3c8032b 100644 (file)
@@ -59,21 +59,23 @@ DCINameDialog::DCINameDialog (wxWindow* parent, shared_ptr<Film> film)
        _package_type = new wxTextCtrl (this, wxID_ANY);
        table->Add (_package_type, 1, wxEXPAND);
 
-       _audio_language->SetValue (std_to_wx (_film->audio_language ()));
-       _subtitle_language->SetValue (std_to_wx (_film->subtitle_language ()));
-       _territory->SetValue (std_to_wx (_film->territory ()));
-       _rating->SetValue (std_to_wx (_film->rating ()));
-       _studio->SetValue (std_to_wx (_film->studio ()));
-       _facility->SetValue (std_to_wx (_film->facility ()));
-       _package_type->SetValue (std_to_wx (_film->package_type ()));
+       DCIMetadata dm = _film->dci_metadata ();
+
+       _audio_language->SetValue (std_to_wx (dm.audio_language));
+       _subtitle_language->SetValue (std_to_wx (dm.subtitle_language));
+       _territory->SetValue (std_to_wx (dm.territory));
+       _rating->SetValue (std_to_wx (dm.rating));
+       _studio->SetValue (std_to_wx (dm.studio));
+       _facility->SetValue (std_to_wx (dm.facility));
+       _package_type->SetValue (std_to_wx (dm.package_type));
        
-       _audio_language->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::audio_language_changed), 0, this);
-       _subtitle_language->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::subtitle_language_changed), 0, this);
-       _territory->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::territory_changed), 0, this);
-       _rating->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::rating_changed), 0, this);
-       _studio->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::studio_changed), 0, this);
-       _facility->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::facility_changed), 0, this);
-       _package_type->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::package_type_changed), 0, this);
+       _audio_language->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _subtitle_language->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _territory->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _rating->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _studio->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _facility->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
+       _package_type->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (DCINameDialog::changed), 0, this);
 
        wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
        overall_sizer->Add (table, 1, wxEXPAND | wxALL, 6);
@@ -89,43 +91,17 @@ DCINameDialog::DCINameDialog (wxWindow* parent, shared_ptr<Film> film)
 }
 
 void
-DCINameDialog::audio_language_changed (wxCommandEvent &)
+DCINameDialog::changed (wxCommandEvent &)
 {
-       _film->set_audio_language (wx_to_std (_audio_language->GetValue ()));
-}
-
-void
-DCINameDialog::subtitle_language_changed (wxCommandEvent &)
-{
-       _film->set_subtitle_language (wx_to_std (_subtitle_language->GetValue ()));
-}
-
-void
-DCINameDialog::territory_changed (wxCommandEvent &)
-{
-       _film->set_territory (wx_to_std (_territory->GetValue ()));
-}
-
-void
-DCINameDialog::rating_changed (wxCommandEvent &)
-{
-       _film->set_rating (wx_to_std (_rating->GetValue ()));
-}
+       DCIMetadata dm;
 
-void
-DCINameDialog::studio_changed (wxCommandEvent &)
-{
-       _film->set_studio (wx_to_std (_studio->GetValue ()));
-}
+       dm.audio_language = wx_to_std (_audio_language->GetValue ());
+       dm.subtitle_language = wx_to_std (_subtitle_language->GetValue ());
+       dm.territory = wx_to_std (_territory->GetValue ());
+       dm.rating = wx_to_std (_rating->GetValue ());
+       dm.studio = wx_to_std (_studio->GetValue ());
+       dm.facility = wx_to_std (_facility->GetValue ());
+       dm.package_type = wx_to_std (_package_type->GetValue ());
 
-void
-DCINameDialog::facility_changed (wxCommandEvent &)
-{
-       _film->set_facility (wx_to_std (_facility->GetValue ()));
-}
-
-void
-DCINameDialog::package_type_changed (wxCommandEvent &)
-{
-       _film->set_package_type (wx_to_std (_package_type->GetValue ()));
+       _film->set_dci_metadata (dm);
 }
index 1fd5436b8c94438880b5c4339de370a198b427dc..dc96deed6e26c9f99ea672e2f65a5ed9b490026d 100644 (file)
@@ -29,13 +29,7 @@ public:
        DCINameDialog (wxWindow *, boost::shared_ptr<Film>);
 
 private:
-       void audio_language_changed (wxCommandEvent &);
-       void subtitle_language_changed (wxCommandEvent &);
-       void territory_changed (wxCommandEvent &);
-       void rating_changed (wxCommandEvent &);
-       void studio_changed (wxCommandEvent &);
-       void facility_changed (wxCommandEvent &);
-       void package_type_changed (wxCommandEvent &);
+       void changed (wxCommandEvent &);
        
        wxTextCtrl* _audio_language;
        wxTextCtrl* _subtitle_language;