diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-12-20 16:18:24 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-12-20 16:18:24 +0000 |
| commit | 3476f2f8251d5800abdd968963cac57b0df8a657 (patch) | |
| tree | dea2e82b66f7da44387023fe0c662253dfcec777 /src | |
| parent | f8e6fdee828647bc5a6a1cc7627052a072a37dc6 (diff) | |
Allow content factory to return multiple content.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/content_factory.cc | 34 | ||||
| -rw-r--r-- | src/lib/content_factory.h | 2 | ||||
| -rw-r--r-- | src/tools/dcpomatic.cc | 5 | ||||
| -rw-r--r-- | src/tools/dcpomatic_create.cc | 10 | ||||
| -rw-r--r-- | src/wx/content_menu.cc | 30 | ||||
| -rw-r--r-- | src/wx/content_panel.cc | 36 |
6 files changed, 66 insertions, 51 deletions
diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index d3905e4e7..9dd042037 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -100,22 +100,22 @@ content_factory (shared_ptr<const Film> film, cxml::NodePtr node, int version, l return content; } -/** Create a Content object from a file or directory. +/** Create some Content objects from a file or directory. * @param film Film that the content will be in. * @param path File or directory. - * @return Content object. + * @return Content objects. */ -shared_ptr<Content> +list<shared_ptr<Content> > content_factory (shared_ptr<const Film> film, boost::filesystem::path path) { - shared_ptr<Content> content; + list<shared_ptr<Content> > content; if (boost::filesystem::is_directory (path)) { LOG_GENERAL ("Look in directory %1", path); if (boost::filesystem::is_empty (path)) { - return shared_ptr<Content> (); + return content; } /* Guess if this is a DCP or a set of images: read the first ten filenames and if they @@ -152,33 +152,37 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path) } if (is_dcp) { - content.reset (new DCPContent (film, path)); + content.push_back (shared_ptr<Content> (new DCPContent (film, path))); } else { - content.reset (new ImageContent (film, path)); + content.push_back (shared_ptr<Content> (new ImageContent (film, path))); } } else { + shared_ptr<Content> single; + string ext = path.extension().string (); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); if (valid_image_file (path)) { - content.reset (new ImageContent (film, path)); + single.reset (new ImageContent (film, path)); } else if (ext == ".srt" || ext == ".ssa" || ext == ".ass") { - content.reset (new TextSubtitleContent (film, path)); + single.reset (new TextSubtitleContent (film, path)); } else if (ext == ".xml") { - content.reset (new DCPSubtitleContent (film, path)); + single.reset (new DCPSubtitleContent (film, path)); } else if (ext == ".mxf" && dcp::SMPTESubtitleAsset::valid_mxf (path)) { - content.reset (new DCPSubtitleContent (film, path)); + single.reset (new DCPSubtitleContent (film, path)); } else if (ext == ".mxf" && VideoMXFContent::valid_mxf (path)) { - content.reset (new VideoMXFContent (film, path)); + single.reset (new VideoMXFContent (film, path)); } else if (ext == ".mxf" && AtmosMXFContent::valid_mxf (path)) { - content.reset (new AtmosMXFContent (film, path)); + single.reset (new AtmosMXFContent (film, path)); } - if (!content) { - content.reset (new FFmpegContent (film, path)); + if (!single) { + single.reset (new FFmpegContent (film, path)); } + + content.push_back (single); } return content; diff --git a/src/lib/content_factory.h b/src/lib/content_factory.h index b319febfc..9c090c690 100644 --- a/src/lib/content_factory.h +++ b/src/lib/content_factory.h @@ -29,4 +29,4 @@ class Film; class Content; extern boost::shared_ptr<Content> content_factory (boost::shared_ptr<const Film>, cxml::NodePtr, int, std::list<std::string> &); -extern boost::shared_ptr<Content> content_factory (boost::shared_ptr<const Film>, boost::filesystem::path); +extern std::list<boost::shared_ptr<Content> > content_factory (boost::shared_ptr<const Film>, boost::filesystem::path); diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index aa37f2fb7..097b7905a 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -76,6 +76,7 @@ #endif #include <boost/filesystem.hpp> #include <boost/noncopyable.hpp> +#include <boost/foreach.hpp> #include <iostream> #include <fstream> /* This is OK as it's only used with DCPOMATIC_WINDOWS */ @@ -1094,7 +1095,9 @@ private: if (!_film_to_create.empty ()) { _frame->new_film (_film_to_create, optional<string> ()); if (!_content_to_add.empty ()) { - _frame->film()->examine_and_add_content (content_factory (_frame->film(), _content_to_add)); + BOOST_FOREACH (shared_ptr<Content> i, content_factory (_frame->film(), _content_to_add)) { + _frame->film()->examine_and_add_content (i); + } } } diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index c14522a02..0582f5cac 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -32,6 +32,7 @@ #include "lib/cross.h" #include <libxml++/libxml++.h> #include <boost/filesystem.hpp> +#include <boost/foreach.hpp> #include <getopt.h> #include <string> #include <iostream> @@ -227,11 +228,12 @@ main (int argc, char* argv[]) film->set_signed (sign); for (int i = optind; i < argc; ++i) { - shared_ptr<Content> c = content_factory (film, boost::filesystem::canonical (argv[i])); - if (c->video) { - c->video->set_scale (VideoContentScale (content_ratio)); + BOOST_FOREACH (shared_ptr<Content> j, content_factory (film, boost::filesystem::canonical (argv[i]))) { + if (j->video) { + j->video->set_scale (VideoContentScale (content_ratio)); + } + film->examine_and_add_content (j); } - film->examine_and_add_content (c); } JobManager* jm = JobManager::instance (); diff --git a/src/wx/content_menu.cc b/src/wx/content_menu.cc index 0240a8c33..429699956 100644 --- a/src/wx/content_menu.cc +++ b/src/wx/content_menu.cc @@ -278,8 +278,6 @@ ContentMenu::find_missing () return; } - shared_ptr<Content> content; - /* XXX: a bit nasty */ shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (_content.front ()); shared_ptr<DCPContent> dc = dynamic_pointer_cast<DCPContent> (_content.front ()); @@ -299,27 +297,31 @@ ContentMenu::find_missing () d->Destroy (); } + list<shared_ptr<Content> > content; + if (r == wxID_OK) { content = content_factory (film, path); } - if (!content) { + if (content.empty ()) { return; } - shared_ptr<Job> j (new ExamineContentJob (film, content)); + BOOST_FOREACH (shared_ptr<Content> i, content) { + shared_ptr<Job> j (new ExamineContentJob (film, i)); - j->Finished.connect ( - bind ( - &ContentMenu::maybe_found_missing, - this, - boost::weak_ptr<Job> (j), - boost::weak_ptr<Content> (_content.front ()), - boost::weak_ptr<Content> (content) - ) - ); + j->Finished.connect ( + bind ( + &ContentMenu::maybe_found_missing, + this, + boost::weak_ptr<Job> (j), + boost::weak_ptr<Content> (_content.front ()), + boost::weak_ptr<Content> (i) + ) + ); - JobManager::instance()->add (j); + JobManager::instance()->add (j); + } } void diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index b67bdb4eb..816512fb6 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -310,7 +310,7 @@ ContentPanel::add_folder_clicked () return; } - shared_ptr<Content> content; + list<shared_ptr<Content> > content; try { content = content_factory (_film, path); @@ -319,26 +319,28 @@ ContentPanel::add_folder_clicked () return; } - if (!content) { + if (content.empty ()) { error_dialog (_parent, _("No content found in this folder.")); return; } - shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (content); - if (ic) { - ImageSequenceDialog* e = new ImageSequenceDialog (_panel); - r = e->ShowModal (); - float const frame_rate = e->frame_rate (); - e->Destroy (); - - if (r != wxID_OK) { - return; + BOOST_FOREACH (shared_ptr<Content> i, content) { + shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i); + if (ic) { + ImageSequenceDialog* e = new ImageSequenceDialog (_panel); + r = e->ShowModal (); + float const frame_rate = e->frame_rate (); + e->Destroy (); + + if (r != wxID_OK) { + return; + } + + ic->set_video_frame_rate (frame_rate); } - ic->set_video_frame_rate (frame_rate); + _film->examine_and_add_content (i); } - - _film->examine_and_add_content (content); } /** @return true if this remove "click" should be ignored */ @@ -583,7 +585,9 @@ ContentPanel::add_files (list<boost::filesystem::path> paths) /* XXX: check for lots of files here and do something */ - for (list<boost::filesystem::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) { - _film->examine_and_add_content (content_factory (_film, *i)); + BOOST_FOREACH (boost::filesystem::path i, paths) { + BOOST_FOREACH (shared_ptr<Content> j, content_factory (_film, i)) { + _film->examine_and_add_content (j); + } } } |
