Tidy up handling of content-modified checks when using the dcpomatic_cli.
[dcpomatic.git] / src / tools / dcpomatic_cli.cc
index 7fc5ed55dd9603d702eb4496adf6b37649b73629..13efb6b1958dd537060b7dafcee37d9a49955525 100644 (file)
@@ -33,6 +33,7 @@
 #include "lib/ratio.h"
 #include "lib/video_content.h"
 #include "lib/audio_content.h"
+#include "lib/dcpomatic_log.h"
 #include <dcp/version.h>
 #include <boost/foreach.hpp>
 #include <getopt.h>
@@ -84,13 +85,13 @@ print_dump (shared_ptr<Film> film)
                cout << "\n"
                     << c->path(0) << "\n"
                     << "\tat " << c->position().seconds ()
-                    << " length " << c->full_length().seconds ()
+                    << " length " << c->full_length(film).seconds ()
                     << " start trim " << c->trim_start().seconds ()
                     << " end trim " << c->trim_end().seconds () << "\n";
 
                if (c->video) {
                        cout << "\t" << c->video->size().width << "x" << c->video->size().height << "\n"
-                            << "\t" << c->active_video_frame_rate() << "fps\n"
+                            << "\t" << c->active_video_frame_rate(film) << "fps\n"
                             << "\tcrop left " << c->video->left_crop()
                             << " right " << c->video->right_crop()
                             << " top " << c->video->top_crop()
@@ -269,7 +270,7 @@ main (int argc, char* argv[])
        }
 
        if (config) {
-               Config::override_path = *config;
+               State::override_path = *config;
        }
 
        if (servers) {
@@ -331,6 +332,8 @@ main (int argc, char* argv[])
                exit (EXIT_SUCCESS);
        }
 
+       dcpomatic_log = film->log ();
+
        ContentList content = film->content ();
        for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
                vector<boost::filesystem::path> paths = (*i)->paths ();
@@ -346,65 +349,8 @@ main (int argc, char* argv[])
                cout << "\nMaking DCP for " << film->name() << "\n";
        }
 
-       film->make_dcp ();
-
-       bool should_stop = false;
-       bool first = true;
-       bool error = false;
-       while (!should_stop) {
-
-               dcpomatic_sleep (5);
-
-               list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
-
-               if (!first && progress) {
-                       for (size_t i = 0; i < jobs.size(); ++i) {
-                               cout << "\033[1A\033[2K";
-                       }
-                       cout.flush ();
-               }
-
-               first = false;
-
-               int unfinished = 0;
-               int finished_in_error = 0;
-
-               BOOST_FOREACH (shared_ptr<Job> i, jobs) {
-                       if (progress) {
-                               cout << i->name();
-                               if (!i->sub_name().empty()) {
-                                       cout << "; " << i->sub_name();
-                               }
-                               cout << ": ";
-
-                               if (i->progress ()) {
-                                       cout << i->status() << "                            \n";
-                               } else {
-                                       cout << ": Running           \n";
-                               }
-                       }
-
-                       if (!i->finished ()) {
-                               ++unfinished;
-                       }
-
-                       if (i->finished_in_error ()) {
-                               ++finished_in_error;
-                               error = true;
-                       }
-
-                       if (!progress && i->finished_in_error ()) {
-                               /* We won't see this error if we haven't been showing progress,
-                                  so show it now.
-                               */
-                               cout << i->status() << "\n";
-                       }
-               }
-
-               if (unfinished == 0 || finished_in_error != 0) {
-                       should_stop = true;
-               }
-       }
+       film->make_dcp (false);
+       bool const error = show_jobs_on_console (progress);
 
        if (keep_going) {
                while (true) {