From: Carl Hetherington Date: Mon, 11 Jan 2021 15:46:13 +0000 (+0100) Subject: More c++ tidying. X-Git-Tag: v2.15.121~16 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=9b946fc5250eff5a5dd4a661896916fcd5d9bd4b More c++ tidying. --- diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc index 0478fcf80..4b4785cc6 100644 --- a/src/lib/dcp_encoder.cc +++ b/src/lib/dcp_encoder.cc @@ -49,6 +49,7 @@ using std::vector; using std::shared_ptr; using std::weak_ptr; using std::dynamic_pointer_cast; +using std::make_shared; using boost::optional; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; @@ -90,26 +91,26 @@ DCPEncoder::~DCPEncoder () void DCPEncoder::go () { - _writer.reset (new Writer (_film, _job)); + _writer = make_shared(_film, _job); _writer->start (); - _j2k_encoder.reset (new J2KEncoder (_film, _writer)); + _j2k_encoder = make_shared(_film, _writer); _j2k_encoder->begin (); { - shared_ptr job = _job.lock (); + auto job = _job.lock (); DCPOMATIC_ASSERT (job); job->sub (_("Encoding")); } if (_non_burnt_subtitles) { - vector fonts = _player->get_subtitle_fonts (); + auto fonts = _player->get_subtitle_fonts (); if (fonts.size() > 1 && _film->interop()) { /* Interop will ignore second and subsequent s so don't even write them as they upset some validators. */ - FontData first = fonts.front (); + auto first = fonts.front(); fonts.clear (); fonts.push_back (first); } @@ -149,7 +150,7 @@ DCPEncoder::audio (shared_ptr data, DCPTime time) { _writer->write (data, time); - shared_ptr job = _job.lock (); + auto job = _job.lock (); DCPOMATIC_ASSERT (job); job->set_progress (float(time.get()) / _film->length().get()); } @@ -174,7 +175,7 @@ optional DCPEncoder::current_rate () const { if (!_j2k_encoder) { - return optional(); + return {}; } return _j2k_encoder->current_encoding_rate (); diff --git a/src/lib/encode_server.cc b/src/lib/encode_server.cc index 6ec3e701c..92589c573 100644 --- a/src/lib/encode_server.cc +++ b/src/lib/encode_server.cc @@ -60,6 +60,7 @@ using std::cout; using std::cerr; using std::fixed; using std::shared_ptr; +using std::make_shared; using boost::thread; using boost::bind; using boost::scoped_array; @@ -123,7 +124,7 @@ EncodeServer::process (shared_ptr socket, struct timeval& after_read, st socket->read (reinterpret_cast (buffer.get()), length); string s (buffer.get()); - shared_ptr xml (new cxml::Document ("EncodingRequest")); + auto xml = make_shared("EncodingRequest"); xml->read_string (s); /* This is a double-check; the server shouldn't even be on the candidate list if it is the wrong version, but it doesn't hurt to make sure here. @@ -134,7 +135,7 @@ EncodeServer::process (shared_ptr socket, struct timeval& after_read, st return -1; } - shared_ptr pvf (new PlayerVideo (xml, socket)); + auto pvf = make_shared(xml, socket); if (!ds.check()) { throw NetworkError ("Checksums do not match"); @@ -144,7 +145,7 @@ EncodeServer::process (shared_ptr socket, struct timeval& after_read, st gettimeofday (&after_read, 0); - ArrayData encoded = dcp_video_frame.encode_locally (); + auto encoded = dcp_video_frame.encode_locally (); gettimeofday (&after_encode, 0); @@ -174,7 +175,7 @@ EncodeServer::worker_thread () return; } - shared_ptr socket = _queue.front (); + auto socket = _queue.front (); _queue.pop_front (); lock.unlock (); @@ -207,13 +208,11 @@ EncodeServer::worker_thread () struct timeval end; gettimeofday (&end, 0); - shared_ptr e ( - new EncodedLogEntry ( - frame, ip, - seconds(after_read) - seconds(start), - seconds(after_encode) - seconds(after_read), - seconds(end) - seconds(after_encode) - ) + auto e = make_shared( + frame, ip, + seconds(after_read) - seconds(start), + seconds(after_encode) - seconds(after_read), + seconds(end) - seconds(after_encode) ); if (_verbose) { @@ -256,7 +255,7 @@ void EncodeServer::broadcast_thread () try { - boost::asio::ip::address address = boost::asio::ip::address_v4::any (); + auto address = boost::asio::ip::address_v4::any (); boost::asio::ip::udp::endpoint listen_endpoint (address, HELLO_PORT); _broadcast.socket = new boost::asio::ip::udp::socket (_broadcast.io_service); @@ -284,17 +283,17 @@ EncodeServer::broadcast_received () if (strcmp (_broadcast.buffer, DCPOMATIC_HELLO) == 0) { /* Reply to the client saying what we can do */ xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node ("ServerAvailable"); + auto root = doc.create_root_node ("ServerAvailable"); root->add_child("Threads")->add_child_text (raw_convert (_worker_threads.size ())); root->add_child("Version")->add_child_text (raw_convert (SERVER_LINK_VERSION)); - string xml = doc.write_to_string ("UTF-8"); + auto xml = doc.write_to_string ("UTF-8"); if (_verbose) { cout << "Offering services to master " << _broadcast.send_endpoint.address().to_string () << "\n"; } try { - shared_ptr socket (new Socket); + auto socket = make_shared(); socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), MAIN_SERVER_PRESENCE_PORT)); socket->write (xml.length() + 1); socket->write ((uint8_t *) xml.c_str(), xml.length() + 1); @@ -303,7 +302,7 @@ EncodeServer::broadcast_received () } try { - shared_ptr socket (new Socket); + auto socket = make_shared(); socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), BATCH_SERVER_PRESENCE_PORT)); socket->write (xml.length() + 1); socket->write ((uint8_t *) xml.c_str(), xml.length() + 1); diff --git a/src/lib/film.cc b/src/lib/film.cc index 8bcbaebe5..a0f25d84b 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -98,6 +98,7 @@ using std::exception; using std::find; using std::shared_ptr; using std::weak_ptr; +using std::make_shared; using std::dynamic_pointer_cast; using boost::optional; using boost::is_any_of; @@ -192,16 +193,16 @@ Film::Film (optional dir) boost::filesystem::path p (boost::filesystem::system_complete (dir.get())); boost::filesystem::path result; - for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) { - if (*i == "..") { + for (auto i: p) { + if (i == "..") { boost::system::error_code ec; if (boost::filesystem::is_symlink(result, ec) || result.filename() == "..") { - result /= *i; + result /= i; } else { result = result.parent_path (); } - } else if (*i != ".") { - result /= *i; + } else if (i != ".") { + result /= i; } } @@ -209,9 +210,9 @@ Film::Film (optional dir) } if (_directory) { - _log.reset (new FileLog (file ("log"))); + _log = make_shared(file("log")); } else { - _log.reset (new NullLog); + _log = make_shared(); } _playlist->set_sequence (_sequence); @@ -284,7 +285,7 @@ Film::internal_video_asset_filename (DCPTimePeriod p) const boost::filesystem::path Film::audio_analysis_path (shared_ptr playlist) const { - boost::filesystem::path p = dir ("analysis"); + auto p = dir ("analysis"); Digester digester; for (auto i: playlist->content ()) { @@ -319,13 +320,13 @@ Film::audio_analysis_path (shared_ptr playlist) const boost::filesystem::path Film::subtitle_analysis_path (shared_ptr content) const { - boost::filesystem::path p = dir ("analysis"); + auto p = dir ("analysis"); Digester digester; digester.add (content->digest()); if (!content->text.empty()) { - shared_ptr tc = content->text.front(); + auto tc = content->text.front(); digester.add (tc->x_scale()); digester.add (tc->y_scale()); for (auto i: tc->fonts()) { @@ -338,7 +339,7 @@ Film::subtitle_analysis_path (shared_ptr content) const digester.add (tc->outline_width()); } - shared_ptr fc = dynamic_pointer_cast(content); + auto fc = dynamic_pointer_cast(content); if (fc) { digester.add (fc->subtitle_stream()->identifier()); } @@ -359,7 +360,7 @@ Film::make_dcp (bool gui, bool check) throw BadSettingError (_("name"), _("Cannot contain slashes")); } - if (container() == 0) { + if (container() == nullptr) { throw MissingSettingError (_("container")); } @@ -371,7 +372,7 @@ Film::make_dcp (bool gui, bool check) throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length.")); } - if (dcp_content_type() == 0) { + if (dcp_content_type() == nullptr) { throw MissingSettingError (_("content type")); } @@ -383,7 +384,7 @@ Film::make_dcp (bool gui, bool check) if (!i->paths_valid()) { throw runtime_error (_("some of your content is missing")); } - shared_ptr dcp = dynamic_pointer_cast (i); + auto dcp = dynamic_pointer_cast(i); if (dcp && dcp->needs_kdm()) { throw runtime_error (_("Some of your content needs a KDM")); } @@ -409,10 +410,10 @@ Film::make_dcp (bool gui, bool check) } LOG_GENERAL ("J2K bandwidth %1", j2k_bandwidth()); - shared_ptr tj (new TranscodeJob (shared_from_this())); - tj->set_encoder (shared_ptr (new DCPEncoder (shared_from_this(), tj))); + auto tj = make_shared(shared_from_this()); + tj->set_encoder (make_shared(shared_from_this(), tj)); if (check) { - shared_ptr cc (new CheckContentChangeJob(shared_from_this(), tj, gui)); + auto cc = make_shared(shared_from_this(), tj, gui); JobManager::instance()->add (cc); } else { JobManager::instance()->add (tj); @@ -423,15 +424,14 @@ Film::make_dcp (bool gui, bool check) void Film::send_dcp_to_tms () { - shared_ptr j (new UploadJob (shared_from_this())); - JobManager::instance()->add (j); + JobManager::instance()->add(make_shared(shared_from_this())); } shared_ptr Film::metadata (bool with_content_paths) const { - shared_ptr doc (new xmlpp::Document); - xmlpp::Element* root = doc->create_root_node ("Metadata"); + auto doc = make_shared(); + auto root = doc->create_root_node ("Metadata"); root->add_child("Version")->add_child_text (raw_convert (current_state_version)); root->add_child("Name")->add_child_text (_name); @@ -465,7 +465,7 @@ Film::metadata (bool with_content_paths) const root->add_child("ReencodeJ2K")->add_child_text (_reencode_j2k ? "1" : "0"); root->add_child("UserExplicitVideoFrameRate")->add_child_text(_user_explicit_video_frame_rate ? "1" : "0"); for (map::const_iterator i = _markers.begin(); i != _markers.end(); ++i) { - xmlpp::Element* m = root->add_child("Marker"); + auto m = root->add_child("Marker"); m->set_attribute("Type", dcp::marker_to_string(i->first)); m->add_child_text(raw_convert(i->second.get())); } @@ -498,8 +498,7 @@ Film::metadata (bool with_content_paths) const void Film::write_metadata (boost::filesystem::path path) const { - shared_ptr doc = metadata (); - doc->write_to_file_formatted (path.string()); + metadata()->write_to_file_formatted(path.string()); } /** Write state to our `metadata' file */ @@ -508,8 +507,7 @@ Film::write_metadata () const { DCPOMATIC_ASSERT (directory()); boost::filesystem::create_directories (directory().get()); - shared_ptr doc = metadata (); - doc->write_to_file_formatted (file(metadata_file).string ()); + metadata()->write_to_file_formatted(file(metadata_file).string()); _dirty = false; } @@ -519,7 +517,7 @@ Film::write_template (boost::filesystem::path path) const { boost::filesystem::create_directories (path.parent_path()); shared_ptr doc = metadata (false); - doc->write_to_file_formatted (path.string ()); + metadata(false)->write_to_file_formatted(path.string()); } /** Read state from our metadata file. @@ -548,7 +546,7 @@ Film::read_metadata (optional path) throw runtime_error (_("This film was created with a newer version of DCP-o-matic, and it cannot be loaded into this version. Sorry!")); } else if (_state_version < current_state_version) { /* This is an older version; save a copy (if we haven't already) */ - boost::filesystem::path const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version); + auto const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version); if (!boost::filesystem::is_regular_file(older)) { try { boost::filesystem::copy_file(*path, older); @@ -571,14 +569,14 @@ Film::read_metadata (optional path) { - optional c = f.optional_string_child ("DCPContentType"); + auto c = f.optional_string_child("DCPContentType"); if (c) { _dcp_content_type = DCPContentType::from_isdcf_name (c.get ()); } } { - optional c = f.optional_string_child ("Container"); + auto c = f.optional_string_child("Container"); if (c) { _container = Ratio::from_id (c.get ()); } @@ -616,7 +614,7 @@ Film::read_metadata (optional path) } if (_audio_processor && !Config::instance()->show_experimental_audio_processors()) { - list ap = AudioProcessor::visible(); + auto ap = AudioProcessor::visible(); if (find(ap.begin(), ap.end(), _audio_processor) == ap.end()) { Config::instance()->set_show_experimental_audio_processors(true); } @@ -639,22 +637,22 @@ Film::read_metadata (optional path) _content_versions.push_back (i->content()); } - optional name_language = f.optional_string_child("NameLanguage"); + auto name_language = f.optional_string_child("NameLanguage"); if (name_language) { _name_language = dcp::LanguageTag (*name_language); } - optional audio_language = f.optional_string_child("AudioLanguage"); + auto audio_language = f.optional_string_child("AudioLanguage"); if (audio_language) { _audio_language = dcp::LanguageTag (*audio_language); } - optional release_territory = f.optional_string_child("ReleaseTerritory"); + auto release_territory = f.optional_string_child("ReleaseTerritory"); if (release_territory) { _release_territory = dcp::LanguageTag::RegionSubtag (*release_territory); } _version_number = f.optional_number_child("VersionNumber").get_value_or(0); - optional status = f.optional_string_child("Status"); + auto status = f.optional_string_child("Status"); if (status) { _status = dcp::string_to_status (*status); } @@ -663,8 +661,8 @@ Film::read_metadata (optional path) _distributor = f.optional_string_child("Distributor").get_value_or(""); _facility = f.optional_string_child("Facility").get_value_or(""); - float value = f.optional_number_child("LuminanceValue").get_value_or(4.5); - optional unit = f.optional_string_child("LuminanceUnit"); + auto value = f.optional_number_child("LuminanceValue").get_value_or(4.5); + auto unit = f.optional_string_child("LuminanceUnit"); if (unit) { _luminance = dcp::Luminance (value, dcp::Luminance::string_to_unit(*unit)); } @@ -693,7 +691,7 @@ Film::read_metadata (optional path) optional found_language; for (auto i: f.node_child("Playlist")->node_children("Content")) { - cxml::ConstNodePtr text = i->optional_node_child("Text"); + auto text = i->optional_node_child("Text"); if (text && text->optional_string_child("Language") && !found_language) { try { found_language = dcp::LanguageTag(text->string_child("Language")); @@ -702,7 +700,7 @@ Film::read_metadata (optional path) } if (_state_version >= 9) { - optional isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage"); + auto isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage"); if (isdcf_language && !found_language) { try { found_language = dcp::LanguageTag(*isdcf_language); @@ -774,7 +772,7 @@ Film::mapped_audio_channels () const } else { for (auto i: content ()) { if (i->audio) { - list c = i->audio->mapping().mapped_output_channels (); + auto c = i->audio->mapping().mapped_output_channels (); copy (c.begin(), c.end(), back_inserter (mapped)); } } @@ -792,7 +790,7 @@ Film::isdcf_name (bool if_created_now) const { string d; - string raw_name = name (); + auto raw_name = name (); /* Split the raw name up into words */ vector words; @@ -801,16 +799,16 @@ Film::isdcf_name (bool if_created_now) const string fixed_name; /* Add each word to fixed_name */ - for (vector::const_iterator i = words.begin(); i != words.end(); ++i) { - string w = *i; + for (auto i: words) { + string w = i; /* First letter is always capitalised */ w[0] = toupper (w[0]); /* Count caps in w */ size_t caps = 0; - for (size_t i = 0; i < w.size(); ++i) { - if (isupper (w[i])) { + for (size_t j = 0; j < w.size(); ++j) { + if (isupper (w[j])) { ++caps; } } @@ -819,13 +817,13 @@ Film::isdcf_name (bool if_created_now) const leave it alone. */ if (caps == w.size ()) { - for (size_t i = 1; i < w.size(); ++i) { - w[i] = tolower (w[i]); + for (size_t j = 1; j < w.size(); ++j) { + w[j] = tolower (w[j]); } } - for (size_t i = 0; i < w.size(); ++i) { - fixed_name += w[i]; + for (size_t j = 0; j < w.size(); ++j) { + fixed_name += w[j]; } } @@ -840,7 +838,7 @@ Film::isdcf_name (bool if_created_now) const d += "-" + raw_convert(isdcf_metadata().content_version); } - ISDCFMetadata const dm = isdcf_metadata (); + auto const dm = isdcf_metadata (); if (dm.temp_version) { d += "-Temp"; @@ -882,7 +880,7 @@ Film::isdcf_name (bool if_created_now) const /* Interior aspect ratio. The standard says we don't do this for trailers, for some strange reason */ if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::TRAILER) { - Ratio const * content_ratio = 0; + Ratio const* content_ratio = nullptr; for (auto i: content ()) { if (i->video) { /* Here's the first piece of video content */ @@ -904,8 +902,8 @@ Film::isdcf_name (bool if_created_now) const for now I'm just appending -CCAP if we have any closed captions. */ - bool burnt_in = true; - bool ccap = false; + auto burnt_in = true; + auto ccap = false; for (auto i: content()) { for (auto j: i->text) { if (j->type() == TEXT_OPEN_SUBTITLE && j->use() && !j->burn()) { @@ -917,7 +915,7 @@ Film::isdcf_name (bool if_created_now) const } if (!_subtitle_languages.empty()) { - string lang = _subtitle_languages.front().language().get_value_or("en").subtag(); + auto lang = _subtitle_languages.front().language().get_value_or("en").subtag(); if (burnt_in) { transform (lang.begin(), lang.end(), lang.begin(), ::tolower); } else { @@ -945,9 +943,9 @@ Film::isdcf_name (bool if_created_now) const /* Count mapped audio channels */ - list mapped = mapped_audio_channels (); + auto mapped = mapped_audio_channels (); - pair ch = audio_channel_types (mapped, audio_channels()); + auto ch = audio_channel_types (mapped, audio_channels()); if (!ch.first && !ch.second) { d += "_MOS"; } else if (ch.first) { @@ -987,9 +985,9 @@ Film::isdcf_name (bool if_created_now) const d += "-3D"; } - bool vf = false; + auto vf = false; for (auto i: content()) { - shared_ptr dc = dynamic_pointer_cast (i); + auto dc = dynamic_pointer_cast(i); if (!dc) { continue; } @@ -1254,15 +1252,15 @@ Film::cpls () const vector out; - boost::filesystem::path const dir = directory().get(); - for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) { + auto const dir = directory().get(); + for (auto i: boost::filesystem::directory_iterator(dir)) { if ( - boost::filesystem::is_directory (*i) && - i->path().leaf() != "j2c" && i->path().leaf() != "video" && i->path().leaf() != "info" && i->path().leaf() != "analysis" + boost::filesystem::is_directory (i) && + i.path().leaf() != "j2c" && i.path().leaf() != "video" && i.path().leaf() != "info" && i.path().leaf() != "analysis" ) { try { - out.push_back (CPLSummary(*i)); + out.push_back (CPLSummary(i)); } catch (...) { } @@ -1297,7 +1295,7 @@ Film::examine_and_add_content (shared_ptr content, bool disable_audio_a run_ffprobe (content->path(0), file("ffprobe.log")); } - shared_ptr j (new ExamineContentJob (shared_from_this(), content)); + auto j = make_shared(shared_from_this(), content); _job_connections.push_back ( j->Finished.connect (bind (&Film::maybe_add_content, this, weak_ptr(j), weak_ptr(content), disable_audio_analysis)) @@ -1309,12 +1307,12 @@ Film::examine_and_add_content (shared_ptr content, bool disable_audio_a void Film::maybe_add_content (weak_ptr j, weak_ptr c, bool disable_audio_analysis) { - shared_ptr job = j.lock (); + auto job = j.lock (); if (!job || !job->finished_ok ()) { return; } - shared_ptr content = c.lock (); + auto content = c.lock (); if (!content) { return; } @@ -1322,7 +1320,7 @@ Film::maybe_add_content (weak_ptr j, weak_ptr c, bool disable_audi add_content (content); if (Config::instance()->automatic_audio_analysis() && content->audio && !disable_audio_analysis) { - shared_ptr playlist (new Playlist); + auto playlist = make_shared(); playlist->add (shared_from_this(), content); boost::signals2::connection c; JobManager::instance()->analyse_audio ( @@ -1429,7 +1427,7 @@ int Film::best_video_frame_rate () const { /* Don't default to anything above 30fps (make the user select that explicitly) */ - int best = _playlist->best_video_frame_rate (); + auto best = _playlist->best_video_frame_rate (); if (best > 30) { best /= 2; } @@ -1505,7 +1503,7 @@ Film::check_settings_consistency () bool change_made = false; for (auto i: content()) { - shared_ptr d = dynamic_pointer_cast(i); + auto d = dynamic_pointer_cast(i); if (!d) { continue; } @@ -1589,7 +1587,7 @@ Film::frame_size () const dcp::Size Film::active_area () const { - dcp::Size const frame = frame_size (); + auto const frame = frame_size (); dcp::Size active; for (auto i: content()) { @@ -1630,8 +1628,8 @@ Film::make_kdm ( throw runtime_error (_("Cannot make a KDM as this project is not encrypted.")); } - shared_ptr cpl (new dcp::CPL (cpl_file)); - shared_ptr signer = Config::instance()->signer_chain (); + auto cpl = make_shared(cpl_file); + auto signer = Config::instance()->signer_chain(); if (!signer->valid ()) { throw InvalidSignerError (); } @@ -1639,10 +1637,10 @@ Film::make_kdm ( /* Find keys that have been added to imported, encrypted DCP content */ list imported_keys; for (auto i: content()) { - shared_ptr d = dynamic_pointer_cast (i); + auto d = dynamic_pointer_cast (i); if (d && d->kdm()) { dcp::DecryptedKDM kdm (d->kdm().get(), Config::instance()->decryption_chain()->key().get()); - list keys = kdm.keys (); + auto keys = kdm.keys (); copy (keys.begin(), keys.end(), back_inserter (imported_keys)); } } @@ -1700,7 +1698,7 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca boost::filesystem::path test = internal_video_asset_dir() / "test"; boost::filesystem::path test2 = internal_video_asset_dir() / "test2"; can_hard_link = true; - FILE* f = fopen_boost (test, "w"); + auto f = fopen_boost (test, "w"); if (f) { fclose (f); boost::system::error_code ec; @@ -1712,7 +1710,7 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca boost::filesystem::remove (test2); } - boost::filesystem::space_info s = boost::filesystem::space (internal_video_asset_dir ()); + auto s = boost::filesystem::space (internal_video_asset_dir ()); required = double (required_disk_space ()) / 1073741824.0f; if (!can_hard_link) { required *= 2; @@ -1766,7 +1764,7 @@ list Film::reels () const { list p; - DCPTime const len = length(); + auto const len = length(); switch (reel_type ()) { case REELTYPE_SINGLE: @@ -1870,7 +1868,7 @@ bool Film::references_dcp_video () const { for (auto i: _playlist->content()) { - shared_ptr d = dynamic_pointer_cast(i); + auto d = dynamic_pointer_cast(i); if (d && d->reference_video()) { return true; } @@ -1883,7 +1881,7 @@ bool Film::references_dcp_audio () const { for (auto i: _playlist->content()) { - shared_ptr d = dynamic_pointer_cast(i); + auto d = dynamic_pointer_cast(i); if (d && d->reference_audio()) { return true; } @@ -1913,7 +1911,7 @@ Film::closed_caption_tracks () const for (auto i: content()) { for (auto j: i->text) { /* XXX: Empty DCPTextTrack ends up being a magic value here - the "unknown" or "not specified" track */ - DCPTextTrack dtt = j->dcp_track().get_value_or(DCPTextTrack()); + auto dtt = j->dcp_track().get_value_or(DCPTextTrack()); if (j->type() == TEXT_CLOSED_CAPTION && find(tt.begin(), tt.end(), dtt) == tt.end()) { tt.push_back (dtt); } @@ -2028,9 +2026,7 @@ Film::set_luminance (dcp::Luminance l) void Film::set_subtitle_language (dcp::LanguageTag language) { - vector lang; - lang.push_back (language); - set_subtitle_languages (lang); + set_subtitle_languages ({language}); } @@ -2061,9 +2057,9 @@ Film::set_facility (string f) optional Film::marker (dcp::Marker type) const { - map::const_iterator i = _markers.find (type); + auto i = _markers.find (type); if (i == _markers.end()) { - return optional(); + return {}; } return i->second; } @@ -2071,7 +2067,7 @@ Film::marker (dcp::Marker type) const shared_ptr Film::info_file_handle (DCPTimePeriod period, bool read) const { - return shared_ptr (new InfoFileHandle(_info_file_mutex, info_file(period), read)); + return std::make_shared(_info_file_mutex, info_file(period), read); } InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read) @@ -2084,7 +2080,7 @@ InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path fil throw OpenFileError (file, errno, OpenFileError::READ); } } else { - bool const exists = boost::filesystem::exists (file); + auto const exists = boost::filesystem::exists (file); if (exists) { _handle = fopen_boost (file, "r+b"); } else { diff --git a/src/lib/film.h b/src/lib/film.h index d79448689..6828df21a 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -67,6 +67,7 @@ struct atmos_encrypted_passthrough_test; class InfoFileHandle { public: + InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read); ~InfoFileHandle (); FILE* get () const { @@ -80,8 +81,6 @@ public: private: friend class Film; - InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read); - boost::mutex::scoped_lock _lock; FILE* _handle; boost::filesystem::path _file; diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc index acd27932e..7c6e23477 100644 --- a/src/lib/j2k_encoder.cc +++ b/src/lib/j2k_encoder.cc @@ -46,6 +46,7 @@ using std::cout; using std::exception; using std::shared_ptr; using std::weak_ptr; +using std::make_shared; using boost::optional; using dcp::Data; using namespace dcpomatic; @@ -83,7 +84,7 @@ J2KEncoder::begin () void J2KEncoder::call_servers_list_changed (weak_ptr encoder) { - shared_ptr e = encoder.lock (); + auto e = encoder.lock (); if (e) { e->servers_list_changed (); } @@ -126,13 +127,13 @@ J2KEncoder::end () So just mop up anything left in the queue here. */ - for (list >::iterator i = _queue.begin(); i != _queue.end(); ++i) { - LOG_GENERAL (N_("Encode left-over frame %1"), (*i)->index ()); + for (auto i: _queue) { + LOG_GENERAL(N_("Encode left-over frame %1"), i->index()); try { _writer->write ( - shared_ptr(new dcp::ArrayData((*i)->encode_locally())), - (*i)->index(), - (*i)->eyes() + make_shared(i->encode_locally()), + i->index(), + i->eyes() ); frame_done (); } catch (std::exception& e) { @@ -205,7 +206,7 @@ J2KEncoder::encode (shared_ptr pv, DCPTime time) */ rethrow (); - Frame const position = time.frames_floor(_film->video_frame_rate()); + auto const position = time.frames_floor(_film->video_frame_rate()); if (_writer->can_fake_write (position)) { /* We can fake-write this frame */ @@ -224,15 +225,13 @@ J2KEncoder::encode (shared_ptr pv, DCPTime time) LOG_DEBUG_ENCODE("Frame @ %1 ENCODE", to_string(time)); /* Queue this new frame for encoding */ LOG_TIMING ("add-frame-to-queue queue=%1", _queue.size ()); - _queue.push_back (shared_ptr ( - new DCPVideo ( - pv, - position, - _film->video_frame_rate(), - _film->j2k_bandwidth(), - _film->resolution() - ) - )); + _queue.push_back (make_shared( + pv, + position, + _film->video_frame_rate(), + _film->j2k_bandwidth(), + _film->resolution() + )); /* The queue might not be empty any more, so notify anything which is waiting on that. @@ -292,7 +291,7 @@ try } LOG_TIMING ("encoder-wake thread=%1 queue=%2", thread_id(), _queue.size()); - shared_ptr vf = _queue.front (); + auto vf = _queue.front (); /* We're about to commit to either encoding this frame or putting it back onto the queue, so we must not be interrupted until one or other of these things have happened. This @@ -311,7 +310,7 @@ try /* We need to encode this input */ if (server) { try { - encoded.reset(new dcp::ArrayData(vf->encode_remotely(server.get()))); + encoded = make_shared(vf->encode_remotely(server.get())); if (remote_backoff > 0) { LOG_GENERAL ("%1 was lost, but now she is found; removing backoff", server->host_name ()); @@ -334,7 +333,7 @@ try } else { try { LOG_TIMING ("start-local-encode thread=%1 frame=%2", thread_id(), vf->index()); - encoded.reset(new dcp::ArrayData(vf->encode_locally())); + encoded = make_shared(vf->encode_locally()); LOG_TIMING ("finish-local-encode thread=%1 frame=%2", thread_id(), vf->index()); } catch (std::exception& e) { /* This is very bad, so don't cope with it, just pass it on */ @@ -380,14 +379,14 @@ J2KEncoder::servers_list_changed () boost::mutex::scoped_lock lm (_threads_mutex); terminate_threads (); - _threads.reset (new boost::thread_group()); + _threads = make_shared(); /* XXX: could re-use threads */ if (!Config::instance()->only_servers_encode ()) { for (int i = 0; i < Config::instance()->master_encoding_threads (); ++i) { #ifdef DCPOMATIC_LINUX - boost::thread* t = _threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional())); + auto t = _threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional())); pthread_setname_np (t->native_handle(), "encode-worker"); #else _threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional())); diff --git a/src/lib/util.cc b/src/lib/util.cc index c7b3281da..0aa7e7a28 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -104,6 +104,7 @@ using std::bad_alloc; using std::set_terminate; using std::make_pair; using std::shared_ptr; +using std::make_shared; using boost::thread; using boost::optional; using boost::lexical_cast; @@ -241,7 +242,7 @@ DCPOMATIC_DISABLE_WARNINGS LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS * info) { - FILE* f = fopen_boost (backtrace_file, "w"); + auto f = fopen_boost (backtrace_file, "w"); fprintf (f, "C-style exception %d\n", info->ExceptionRecord->ExceptionCode); fclose(f); @@ -370,7 +371,7 @@ DCPOMATIC_ENABLE_WARNINGS /* Add our library directory to the libltdl search path so that xmlsec can find xmlsec1-openssl. */ - boost::filesystem::path lib = directory_containing_executable().parent_path(); + auto lib = directory_containing_executable().parent_path(); lib /= "Frameworks"; setenv ("LTDL_LIBRARY_PATH", lib.c_str (), 1); #endif @@ -398,7 +399,7 @@ DCPOMATIC_ENABLE_WARNINGS "Hello dolly", dcp::NONE, dcp::Colour(), dcp::Time(), dcp::Time() ); subs.push_back (StringText(ss, 0)); - render_text (subs, list >(), dcp::Size(640, 480), DCPTime(), 24); + render_text (subs, list>(), dcp::Size(640, 480), DCPTime(), 24); #endif Ratio::setup_ratios (); @@ -479,7 +480,7 @@ digest_head_tail (vector files, boost::uintmax_t size) char* p = buffer.get (); int i = 0; while (i < int64_t (files.size()) && to_do > 0) { - FILE* f = fopen_boost (files[i], "rb"); + auto f = fopen_boost (files[i], "rb"); if (!f) { throw OpenFileError (files[i].string(), errno, OpenFileError::READ); } @@ -499,7 +500,7 @@ digest_head_tail (vector files, boost::uintmax_t size) p = buffer.get (); i = files.size() - 1; while (i >= 0 && to_do > 0) { - FILE* f = fopen_boost (files[i], "rb"); + auto f = fopen_boost (files[i], "rb"); if (!f) { throw OpenFileError (files[i].string(), errno, OpenFileError::READ); } @@ -606,7 +607,7 @@ valid_image_file (boost::filesystem::path f) return false; } - string ext = f.extension().string(); + auto ext = f.extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); return ( ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || @@ -623,7 +624,7 @@ valid_sound_file (boost::filesystem::path f) return false; } - string ext = f.extension().string(); + auto ext = f.extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); return (ext == ".wav" || ext == ".mp3" || ext == ".aif" || ext == ".aiff"); } @@ -631,7 +632,7 @@ valid_sound_file (boost::filesystem::path f) bool valid_j2k_file (boost::filesystem::path f) { - string ext = f.extension().string(); + auto ext = f.extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); return (ext == ".j2k" || ext == ".j2c" || ext == ".jp2"); } @@ -656,7 +657,7 @@ fit_ratio_within (float ratio, dcp::Size full_frame) void * wrapped_av_malloc (size_t s) { - void* p = av_malloc (s); + auto p = av_malloc (s); if (!p) { throw bad_alloc (); } @@ -845,7 +846,7 @@ audio_channel_types (list mapped, int channels) shared_ptr remap (shared_ptr input, int output_channels, AudioMapping map) { - shared_ptr mapped (new AudioBuffers (output_channels, input->frames())); + auto mapped = make_shared(output_channels, input->frames()); mapped->make_silent (); int to_do = min (map.input_channels(), input->channels()); @@ -954,7 +955,7 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size { /* XXX: this is rather inefficient; decoding the image just to get its size */ FFmpegImageProxy proxy (sub.png_image(), VIDEO_RANGE_FULL); - shared_ptr image = proxy.image().image; + auto image = proxy.image().image; /* set up rect with height and width */ dcpomatic::Rect rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height)); @@ -996,7 +997,7 @@ show_jobs_on_console (bool progress) dcpomatic_sleep_seconds (5); - list > jobs = JobManager::instance()->get(); + auto jobs = JobManager::instance()->get(); if (!first && progress) { for (size_t i = 0; i < jobs.size(); ++i) { @@ -1046,11 +1047,11 @@ show_jobs_on_console (bool progress) void copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::function progress) { - FILE* f = fopen_boost (from, "rb"); + auto f = fopen_boost (from, "rb"); if (!f) { throw OpenFileError (from, errno, OpenFileError::READ); } - FILE* t = fopen_boost (to, "wb"); + auto t = fopen_boost (to, "wb"); if (!t) { fclose (f); throw OpenFileError (to, errno, OpenFileError::WRITE); @@ -1059,7 +1060,7 @@ copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::f /* on the order of a second's worth of copying */ boost::uintmax_t const chunk = 20 * 1024 * 1024; - uint8_t* buffer = static_cast (malloc(chunk)); + auto buffer = static_cast (malloc(chunk)); if (!buffer) { throw std::bad_alloc (); } @@ -1132,9 +1133,9 @@ decrypt_kdm_with_helpful_error (dcp::EncryptedKDM kdm) return dcp::DecryptedKDM (kdm, Config::instance()->decryption_chain()->key().get()); } catch (dcp::KDMDecryptionError& e) { /* Try to flesh out the error a bit */ - string const kdm_subject_name = kdm.recipient_x509_subject_name(); + auto const kdm_subject_name = kdm.recipient_x509_subject_name(); bool on_chain = false; - shared_ptr dc = Config::instance()->decryption_chain(); + auto dc = Config::instance()->decryption_chain(); for (auto i: dc->root_to_leaf()) { if (i.subject() == kdm_subject_name) { on_chain = true; diff --git a/src/wx/timecode.cc b/src/wx/timecode.cc index 0602358a9..c4755e574 100644 --- a/src/wx/timecode.cc +++ b/src/wx/timecode.cc @@ -31,7 +31,7 @@ TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button) : wxPanel (parent) , _set_button (0) { - wxSize const s = TimecodeBase::size (parent); + auto const s = TimecodeBase::size (parent); wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); wxArrayString list; @@ -46,7 +46,7 @@ TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button) _sizer = new wxBoxSizer (wxHORIZONTAL); _editable = new wxPanel (this); - wxSizer* editable_sizer = new wxBoxSizer (wxHORIZONTAL); + auto editable_sizer = new wxBoxSizer (wxHORIZONTAL); _hours = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator); _hours->SetMaxLength (2); editable_sizer->Add (_hours); @@ -131,7 +131,7 @@ wxSize TimecodeBase::size (wxWindow* parent) { wxClientDC dc (parent); - wxSize size = dc.GetTextExtent (wxT ("9999")); + auto size = dc.GetTextExtent(wxT("9999")); size.SetHeight (-1); return size; } diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index e5182a0a4..3294676fc 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -51,6 +51,7 @@ using std::abs; using std::shared_ptr; using std::weak_ptr; using std::dynamic_pointer_cast; +using std::make_shared; using boost::bind; using boost::optional; using namespace dcpomatic; @@ -90,7 +91,7 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr film, w _main_canvas->SetDoubleBuffered (true); #endif - wxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); + auto sizer = new wxBoxSizer (wxHORIZONTAL); sizer->Add (_labels_canvas, 0, wxEXPAND); _labels_canvas->SetMinSize (wxSize (_labels_view->bbox().width, -1)); sizer->Add (_main_canvas, 1, wxEXPAND); @@ -142,7 +143,7 @@ Timeline::paint_labels () { wxPaintDC dc (_labels_canvas); - wxGraphicsContext* gc = wxGraphicsContext::Create (dc); + auto gc = wxGraphicsContext::Create (dc); if (!gc) { return; } @@ -162,7 +163,7 @@ Timeline::paint_main () wxPaintDC dc (_main_canvas); _main_canvas->DoPrepareDC (dc); - wxGraphicsContext* gc = wxGraphicsContext::Create (dc); + auto gc = wxGraphicsContext::Create (dc); if (!gc) { return; } @@ -175,18 +176,18 @@ Timeline::paint_main () for (auto i: _views) { - shared_ptr ic = dynamic_pointer_cast (i); + auto ic = dynamic_pointer_cast (i); /* Find areas of overlap with other content views, so that we can plot them */ - list > overlaps; + list> overlaps; for (auto j: _views) { - shared_ptr jc = dynamic_pointer_cast (j); + auto jc = dynamic_pointer_cast (j); /* No overlap with non-content views, views no different tracks, audio views or non-active views */ if (!ic || !jc || i == j || ic->track() != jc->track() || ic->track().get_value_or(2) >= 2 || !ic->active() || !jc->active()) { continue; } - optional > r = j->bbox().intersection (i->bbox()); + auto r = j->bbox().intersection(i->bbox()); if (r) { overlaps.push_back (r.get ()); } @@ -210,11 +211,11 @@ Timeline::paint_main () /* Playhead */ - shared_ptr vp = _viewer.lock (); + auto vp = _viewer.lock (); DCPOMATIC_ASSERT (vp); gc->SetPen (*wxRED_PEN); - wxGraphicsPath path = gc->CreatePath (); + auto path = gc->CreatePath (); double const ph = vp->position().seconds() * pixels_per_second().get_value_or(0); path.MoveToPoint (ph, 0); path.AddLineToPoint (ph, pixels_per_track() * _tracks + 32); @@ -241,7 +242,7 @@ Timeline::film_change (ChangeType type, Film::Property p) void Timeline::recreate_views () { - shared_ptr film = _film.lock (); + auto film = _film.lock (); if (!film) { return; } @@ -252,19 +253,19 @@ Timeline::recreate_views () for (auto i: film->content ()) { if (i->video) { - _views.push_back (shared_ptr (new TimelineVideoContentView (*this, i))); + _views.push_back (make_shared(*this, i)); } if (i->audio && !i->audio->mapping().mapped_output_channels().empty ()) { - _views.push_back (shared_ptr (new TimelineAudioContentView (*this, i))); + _views.push_back (make_shared(*this, i)); } for (auto j: i->text) { - _views.push_back (shared_ptr (new TimelineTextContentView (*this, i, j))); + _views.push_back (make_shared(*this, i, j)); } if (i->atmos) { - _views.push_back (shared_ptr(new TimelineAtmosContentView(*this, i))); + _views.push_back (make_shared(*this, i)); } } @@ -303,23 +304,23 @@ place (shared_ptr film, TimelineViewList& views, int& tracks) continue; } - shared_ptr cv = dynamic_pointer_cast (i); + auto cv = dynamic_pointer_cast (i); int t = base; - shared_ptr content = cv->content(); + auto content = cv->content(); DCPTimePeriod const content_period (content->position(), content->end(film)); while (true) { - TimelineViewList::iterator j = views.begin(); + auto j = views.begin(); while (j != views.end()) { - shared_ptr test = dynamic_pointer_cast (*j); + auto test = dynamic_pointer_cast (*j); if (!test) { ++j; continue; } - shared_ptr test_content = test->content(); + auto test_content = test->content(); if ( test->track() && test->track().get() == t && content_period.overlap(DCPTimePeriod(test_content->position(), test_content->end(film)))) { @@ -350,15 +351,15 @@ place (shared_ptr film, TimelineViewList& views, int& tracks) struct AudioMappingComparator { bool operator()(shared_ptr a, shared_ptr b) { int la = -1; - shared_ptr cva = dynamic_pointer_cast(a); + auto cva = dynamic_pointer_cast(a); if (cva) { - list oc = cva->content()->audio->mapping().mapped_output_channels(); + auto oc = cva->content()->audio->mapping().mapped_output_channels(); la = *min_element(boost::begin(oc), boost::end(oc)); } int lb = -1; - shared_ptr cvb = dynamic_pointer_cast(b); + auto cvb = dynamic_pointer_cast(b); if (cvb) { - list oc = cvb->content()->audio->mapping().mapped_output_channels(); + auto oc = cvb->content()->audio->mapping().mapped_output_channels(); lb = *min_element(boost::begin(oc), boost::end(oc)); } return la < lb; @@ -380,13 +381,13 @@ Timeline::assign_tracks () Audio N */ - shared_ptr film = _film.lock (); + auto film = _film.lock (); DCPOMATIC_ASSERT (film); _tracks = 0; - for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr c = dynamic_pointer_cast (*i); + for (auto i: _views) { + auto c = dynamic_pointer_cast(i); if (c) { c->unset_track (); } @@ -396,7 +397,7 @@ Timeline::assign_tracks () bool have_3d = false; for (auto i: _views) { - shared_ptr cv = dynamic_pointer_cast (i); + auto cv = dynamic_pointer_cast(i); if (!cv) { continue; } @@ -421,7 +422,7 @@ Timeline::assign_tracks () bool have_atmos = false; for (auto i: _views) { - shared_ptr cv = dynamic_pointer_cast(i); + auto cv = dynamic_pointer_cast(i); if (cv) { cv->set_track (_tracks); have_atmos = true; @@ -436,7 +437,7 @@ Timeline::assign_tracks () DCP channel index. */ - TimelineViewList views = _views; + auto views = _views; sort(views.begin(), views.end(), AudioMappingComparator()); int const audio_tracks = place (film, views, _tracks); @@ -458,7 +459,7 @@ Timeline::tracks () const void Timeline::setup_scrollbars () { - shared_ptr film = _film.lock (); + auto film = _film.lock (); if (!film || !_pixels_per_second) { return; } @@ -475,19 +476,19 @@ shared_ptr Timeline::event_to_view (wxMouseEvent& ev) { /* Search backwards through views so that we find the uppermost one first */ - TimelineViewList::reverse_iterator i = _views.rbegin(); + auto i = _views.rbegin(); int vsx, vsy; _main_canvas->GetViewStart (&vsx, &vsy); Position const p (ev.GetX() + vsx * _x_scroll_rate, ev.GetY() + vsy * _y_scroll_rate); while (i != _views.rend() && !(*i)->bbox().contains (p)) { - shared_ptr cv = dynamic_pointer_cast (*i); + auto cv = dynamic_pointer_cast(*i); ++i; } if (i == _views.rend ()) { - return shared_ptr (); + return {}; } return *i; @@ -515,8 +516,8 @@ Timeline::left_down (wxMouseEvent& ev) void Timeline::left_down_select (wxMouseEvent& ev) { - shared_ptr view = event_to_view (ev); - shared_ptr content_view = dynamic_pointer_cast (view); + auto view = event_to_view (ev); + auto content_view = dynamic_pointer_cast(view); _down_view.reset (); @@ -525,14 +526,14 @@ Timeline::left_down_select (wxMouseEvent& ev) _down_view_position = content_view->content()->position (); } - for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); + for (auto i: _views) { + auto cv = dynamic_pointer_cast(i); if (!cv) { continue; } if (!ev.ShiftDown ()) { - cv->set_selected (view == *i); + cv->set_selected (view == i); } } @@ -544,13 +545,13 @@ Timeline::left_down_select (wxMouseEvent& ev) if (_down_view) { /* Pre-compute the points that we might snap to */ - for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); + for (auto i: _views) { + auto cv = dynamic_pointer_cast(i); if (!cv || cv == _down_view || cv->content() == _down_view->content()) { continue; } - shared_ptr film = _film.lock (); + auto film = _film.lock (); DCPOMATIC_ASSERT (film); _start_snaps.push_back (cv->content()->position()); @@ -627,8 +628,8 @@ Timeline::left_up_zoom (wxMouseEvent& ev) return; } - DCPTime const time_left = DCPTime::from_seconds((top_left.x + vsx) / *_pixels_per_second); - DCPTime const time_right = DCPTime::from_seconds((bottom_right.x + vsx) / *_pixels_per_second); + auto const time_left = DCPTime::from_seconds((top_left.x + vsx) / *_pixels_per_second); + auto const time_right = DCPTime::from_seconds((bottom_right.x + vsx) / *_pixels_per_second); set_pixels_per_second (double(GetSize().GetWidth()) / (time_right.seconds() - time_left.seconds())); double const tracks_top = double(top_left.y - tracks_y_offset()) / _pixels_per_track; @@ -712,8 +713,8 @@ Timeline::right_down (wxMouseEvent& ev) void Timeline::right_down_select (wxMouseEvent& ev) { - shared_ptr view = event_to_view (ev); - shared_ptr cv = dynamic_pointer_cast (view); + auto view = event_to_view (ev); + auto cv = dynamic_pointer_cast (view); if (!cv) { return; } @@ -729,7 +730,7 @@ Timeline::right_down_select (wxMouseEvent& ev) void Timeline::maybe_snap (DCPTime a, DCPTime b, optional& nearest_distance) const { - DCPTime const d = a - b; + auto const d = a - b; if (!nearest_distance || d.abs() < nearest_distance.get().abs()) { nearest_distance = d; } @@ -744,7 +745,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev, bool force_emit) double const pps = _pixels_per_second.get (); - wxPoint const p = ev.GetPosition(); + auto const p = ev.GetPosition(); if (!_first_move) { /* We haven't moved yet; in that case, we must move the mouse some reasonable distance @@ -761,13 +762,13 @@ Timeline::set_position_from_event (wxMouseEvent& ev, bool force_emit) return; } - DCPTime new_position = _down_view_position + DCPTime::from_seconds ((p.x - _down_point.x) / pps); + auto new_position = _down_view_position + DCPTime::from_seconds ((p.x - _down_point.x) / pps); - shared_ptr film = _film.lock (); + auto film = _film.lock (); DCPOMATIC_ASSERT (film); if (_snap) { - DCPTime const new_end = new_position + _down_view->content()->length_after_trim(film); + auto const new_end = new_position + _down_view->content()->length_after_trim(film); /* Signed `distance' to nearest thing (i.e. negative is left on the timeline, positive is right). */ @@ -825,8 +826,8 @@ Timeline::resized () void Timeline::clear_selection () { - for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); + for (auto i: _views) { + shared_ptr cv = dynamic_pointer_cast(i); if (cv) { cv->set_selected (false); } @@ -838,8 +839,8 @@ Timeline::selected_views () const { TimelineContentViewList sel; - for (TimelineViewList::const_iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); + for (auto i: _views) { + auto cv = dynamic_pointer_cast(i); if (cv && cv->selected()) { sel.push_back (cv); } @@ -852,10 +853,9 @@ ContentList Timeline::selected_content () const { ContentList sel; - TimelineContentViewList views = selected_views (); - for (TimelineContentViewList::const_iterator i = views.begin(); i != views.end(); ++i) { - sel.push_back ((*i)->content ()); + for (auto i: selected_views()) { + sel.push_back(i->content()); } return sel; @@ -864,8 +864,8 @@ Timeline::selected_content () const void Timeline::set_selection (ContentList selection) { - for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) { - shared_ptr cv = dynamic_pointer_cast (*i); + for (auto i: _views) { + auto cv = dynamic_pointer_cast (i); if (cv) { cv->set_selected (find (selection.begin(), selection.end(), cv->content ()) != selection.end ()); } @@ -915,7 +915,7 @@ Timeline::tool_clicked (Tool t) void Timeline::zoom_all () { - shared_ptr film = _film.lock (); + auto film = _film.lock (); DCPOMATIC_ASSERT (film); set_pixels_per_second ((_main_canvas->GetSize().GetWidth() - 32) / film->length().seconds()); set_pixels_per_track ((_main_canvas->GetSize().GetHeight() - tracks_y_offset() - _time_axis_view->bbox().height - 32) / _tracks);