From 3703ac71435369d77be8ded1be595d758aee6ea3 Mon Sep 17 00:00:00 2001 From: Stephan Steinbach <61017+ssteinbach@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:49:27 -0700 Subject: [PATCH] Release v0.15.0 changes (#1403) * freeze versions ahead of release * remove path * remove .dev1 suffix * bump version number in CMakeLists.txt to 0.15 * Update README.md * Update CONTRIBUTORS.md * update supported VFX platform list * add link to Presentations wiki page * tweak some settings in clang format * Run make format over the c++ code * match autoformatted C++ in the version map Signed-off-by: Stephan Steinbach Co-authored-by: Nick Porcino --- .clang-format | 8 +- .github/workflows/python-package.yml | 26 +- CMakeLists.txt | 2 +- CONTRIBUTORS.md | 15 +- README.md | 89 ++-- setup.py | 2 +- src/opentime/rationalTime.cpp | 149 ++++--- src/opentime/rationalTime.h | 40 +- src/opentime/timeRange.cpp | 1 - src/opentime/timeRange.h | 80 ++-- src/opentime/timeTransform.cpp | 1 - src/opentime/timeTransform.h | 13 +- src/opentimelineio/CORE_VERSION_MAP.cpp | 130 +++--- src/opentimelineio/CORE_VERSION_MAP.last.cpp | 65 ++- src/opentimelineio/anyDictionary.h | 54 +-- src/opentimelineio/anyVector.h | 2 +- src/opentimelineio/clip.cpp | 20 +- src/opentimelineio/composition.cpp | 57 ++- src/opentimelineio/composition.h | 37 +- src/opentimelineio/deserialization.cpp | 69 ++- src/opentimelineio/effect.cpp | 4 +- src/opentimelineio/gap.cpp | 10 +- src/opentimelineio/generatorReference.cpp | 5 +- src/opentimelineio/imageSequenceReference.cpp | 40 +- src/opentimelineio/imageSequenceReference.h | 9 +- src/opentimelineio/item.cpp | 21 +- src/opentimelineio/linearTimeWarp.cpp | 4 +- src/opentimelineio/marker.cpp | 6 +- src/opentimelineio/mediaReference.cpp | 9 +- src/opentimelineio/serializableCollection.cpp | 4 +- src/opentimelineio/serializableObject.cpp | 30 +- src/opentimelineio/serializableObject.h | 76 ++-- .../serializableObjectWithMetadata.cpp | 9 +- src/opentimelineio/serialization.cpp | 396 ++++++++---------- src/opentimelineio/serialization.h | 25 +- src/opentimelineio/stack.cpp | 7 +- src/opentimelineio/stack.h | 6 +- src/opentimelineio/stackAlgorithm.cpp | 17 +- src/opentimelineio/stackAlgorithm.h | 3 +- src/opentimelineio/stringUtils.cpp | 3 +- src/opentimelineio/timeline.cpp | 6 +- src/opentimelineio/timeline.h | 7 +- src/opentimelineio/track.cpp | 11 +- src/opentimelineio/track.h | 9 +- src/opentimelineio/trackAlgorithm.cpp | 7 +- src/opentimelineio/trackAlgorithm.h | 4 +- src/opentimelineio/transition.cpp | 8 +- src/opentimelineio/typeRegistry.cpp | 81 ++-- src/opentimelineio/typeRegistry.h | 15 +- src/opentimelineio/unknownSchema.cpp | 3 +- src/opentimelineio/unknownSchema.h | 3 +- .../console/autogen_version_map.py | 7 +- 52 files changed, 914 insertions(+), 791 deletions(-) diff --git a/.clang-format b/.clang-format index 369a912de..3f6b84b74 100644 --- a/.clang-format +++ b/.clang-format @@ -8,9 +8,9 @@ AlignConsecutiveDeclarations: true AlignEscapedNewlines: Right AlignOperands: true AlignTrailingComments: true -# AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -# AllowAllConstructorInitializersOnNextLine: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: InlineOnly @@ -39,7 +39,7 @@ BraceWrapping: SplitEmptyFunction: false SplitEmptyRecord: false SplitEmptyNamespace: false -BreakBeforeBinaryOperators: None +BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 48a54d1bf..455d05f6d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -6,7 +6,7 @@ name: OpenTimelineIO # for configuring which build will be a C++ coverage build / coverage report env: GH_COV_PY: 3.7 - GH_COV_OS: ubuntu-latest + GH_COV_OS: ubuntu-20.04 GH_DEPENDABOT: dependabot on: @@ -24,15 +24,15 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-20.04, windows-2022, macos-11] # Unfortunately the CMake test target is OS dependent so we set it as # a variable here. include: - - os: ubuntu-latest + - os: ubuntu-20.04 OTIO_TEST_TARGET: test - - os: windows-latest + - os: windows-2022 OTIO_TEST_TARGET: RUN_TESTS - - os: macos-latest + - os: macos-11 OTIO_TEST_TARGET: test env: @@ -86,13 +86,13 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-20.04, windows-2022, macos-11] python-version: ['2.7', '3.7', '3.8', '3.9', '3.10'] include: - - { os: ubuntu-latest, shell: bash } - - { os: macos-latest, shell: bash } - - { os: windows-latest, shell: pwsh } - - { os: windows-latest, shell: msys2, python-version: 'mingw64' } + - { os: ubuntu-20.04, shell: bash } + - { os: macos-11, shell: bash } + - { os: windows-2022, shell: pwsh } + - { os: windows-2022, shell: msys2, python-version: 'mingw64' } defaults: run: @@ -129,7 +129,7 @@ jobs: sudo apt-get install lcov - name: Install python build dependencies run: | - python -m pip install --upgrade pip setuptools wheel flake8>=3.5 check-manifest + python -m pip install --upgrade pip setuptools wheel "flake8>=3.5" check-manifest - name: install mock for python 2.7 tests only if: matrix.python-version == 2.7 run: python -m pip install --upgrade mock @@ -158,7 +158,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-20.04, windows-2022, macos-11] python-build: ['cp27*', 'cp37*', 'cp38*', 'cp39*', 'cp310*'] steps: - uses: actions/checkout@v3 @@ -206,7 +206,7 @@ jobs: package_sdist: needs: py_build_test - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c6b58796..19df9d17f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.18.2) # TODO: read this information from a configuration file, here, and in setup.py set(OTIO_VERSION_MAJOR "0") -set(OTIO_VERSION_MINOR "14") +set(OTIO_VERSION_MINOR "15") set(OTIO_VERSION_PATCH "0") set(OTIO_VERSION ${OTIO_VERSION_MAJOR}.${OTIO_VERSION_MINOR}.${OTIO_VERSION_PATCH}) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ccfdb68f4..0842825f9 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,9 +5,11 @@ If you know of anyone missing from this list, please contact us: https://lists.a * Aditya Rana ([Viraj-Rana008](https://github.com/Viraj-Rana008)) * Alex Schworer ([schworer](https://github.com/schworer)) * Alex Widener ([boredstiff](https://github.com/boredstiff)) +* Andrew Moore ([andrewmoore-nz](https://github.com/andrewmoore-nz)) * Ashley Whetter ([AWhetter](https://github.com/AWhetter)) * Bas Hesen ([bashesenaxis](https://github.com/bashesenaxis)) * Bonnie Tai ([bonpix](https://github.com/bonpix)) +* Cameron Kerr ([camkerr](https://github.com/camkerr)) * Daniel Flehner Heen ([apetrynet](https://github.com/apetrynet)) * Darby Johnston ([darbyjohnston](https://github.com/darbyjohnston)) * Darwyn Peachey ([peachey](https://github.com/peachey)) @@ -15,15 +17,17 @@ If you know of anyone missing from this list, please contact us: https://lists.a * Ed Caspersen ([repsac](https://github.com/repsac)) * Emile Labrosse ([elabrosseRodeofx](https://github.com/elabrosseRodeofx)) * Eric ([eric-with-a-c](https://github.com/eric-with-a-c)) +* Eric Desruisseaux ([desruie](https://github.com/desruie)) * Eric Reinecke ([reinecke](https://github.com/reinecke)) -* Félix Bourbonnais ([BadSingleton](https://github.com/BadSingleton)) -* Félix David ([Tilix4](https://github.com/Tilix4)) * Flavian Liger ([flavienliger](https://github.com/flavienliger)) * Fredrik Brännbacka ([smaragden](https://github.com/smaragden)) * Freeson Wang ([freesonluxo](https://github.com/freesonluxo)) +* Félix Bourbonnais ([BadSingleton](https://github.com/BadSingleton)) +* Félix David ([Tilix4](https://github.com/Tilix4)) * Henry Wilkes ([hwilkes-igalia](https://github.com/hwilkes-igalia)) * Jean-Christophe Morin ([JeanChristopheMorinPerso](https://github.com/JeanChristopheMorinPerso)) * Jeffrey Barendse ([IOjeffrey](https://github.com/IOjeffrey)) +* jlskuz ([jlskuz](https://github.com/jlskuz)) * John Mertic ([jmertic](https://github.com/jmertic)) * Jon Morley ([rogergodspeed](https://github.com/rogergodspeed)) * Jonathan Hearn ([splidje](https://github.com/splidje)) @@ -32,11 +36,14 @@ If you know of anyone missing from this list, please contact us: https://lists.a * Julian Yu-Chung Chen ([jchen9](https://github.com/jchen9)) * Karthik Ramesh Iyer ([KarthikRIyer](https://github.com/KarthikRIyer)) * Laura Savidge ([lsavidge](https://github.com/lsavidge)) +* Mark Reid ([markreidvfx](https://github.com/markreidvfx)) * Matt Johnson ([mattyjams](https://github.com/mattyjams)) +* Michael Dolan ([michdolan](https://github.com/michdolan)) * Michael Jefferies ([michaeljefferies](https://github.com/michaeljefferies)) * Mike Koetter ([mikekoetter](https://github.com/mikekoetter)) * Mike Mahony ([mikemahony](https://github.com/mikemahony)) * Nick Porcino ([meshula](https://github.com/meshula)) +* Pedro Labonia ([pedrolabonia](https://github.com/pedrolabonia)) * Robyn Rindge ([avrata](https://github.com/avrata)) * Roger Nelson ([rogernelson](https://github.com/rogernelson)) * Sasha Aleshchenko ([TheBigSasha](https://github.com/TheBigSasha)) @@ -46,10 +53,14 @@ If you know of anyone missing from this list, please contact us: https://lists.a * Simran Spiller ([Simran-B](https://github.com/Simran-B)) * Stefan Schulze ([stefanschulze](https://github.com/stefanschulze)) * Stephan Steinbach ([ssteinbach](https://github.com/ssteinbach)) +* Stéphane Deverly ([gplsteph](https://github.com/gplsteph)) * Thibault Saunier ([thiblahute](https://github.com/thiblahute)) * Thierry Dervieux-Lecocq ([tdervieux](https://github.com/tdervieux)) +* ThomasWilshaw ([ThomasWilshaw](https://github.com/ThomasWilshaw)) * Tim Lehr ([timlehr](https://github.com/timlehr)) * Troy James Sobotka ([sobotka](https://github.com/sobotka)) * Tuan Truong ([tuan-huy-truong](https://github.com/tuan-huy-truong)) +* Utsab Saha ([utsab](https://github.com/utsab)) * Valerio Viperino ([vvzen](https://github.com/vvzen)) * Vincent Pinon ([vpinon](https://github.com/vpinon)) +* Visaj Nirav Shah ([visajshah](https://github.com/visajshah)) \ No newline at end of file diff --git a/README.md b/README.md index 13b254210..f83abee2d 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,23 @@ OpenTimelineIO [![OpenTimelineIO](docs/_static/OpenTimelineIO@3xDark.png)](http://opentimeline.io) ============== -[![Supported VFX Platform Versions](https://img.shields.io/badge/vfx%20platform-2018--2021-lightgrey.svg)](http://www.vfxplatform.com/) +[![Supported VFX Platform Versions](https://img.shields.io/badge/vfx%20platform-2019--2022-lightgrey.svg)](http://www.vfxplatform.com/) ![Supported Versions](https://img.shields.io/badge/python-2.7%2C%203.7%2C%203.8%2C%203.9%2C%203.10-blue) [![Build Status](https://github.com/AcademySoftwareFoundation/OpenTimelineIO/actions/workflows/python-package.yml/badge.svg)](https://github.com/AcademySoftwareFoundation/OpenTimelineIO/actions/workflows/python-package.yml) [![codecov](https://codecov.io/gh/AcademySoftwareFoundation/OpenTimelineIO/branch/main/graph/badge.svg)](https://codecov.io/gh/AcademySoftwareFoundation/OpenTimelineIO) [![docs](https://readthedocs.org/projects/opentimelineio/badge/?version=latest)](https://opentimelineio.readthedocs.io/en/latest/index.html) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2288/badge)](https://bestpractices.coreinfrastructure.org/projects/2288) -Main web site: http://opentimeline.io/ +Links +----- -Documentation: https://opentimelineio.readthedocs.io/ - -GitHub: https://github.com/AcademySoftwareFoundation/OpenTimelineIO - -Discussion group: https://lists.aswf.io/g/otio-discussion - -Slack channel: https://academysoftwarefdn.slack.com/messages/CMQ9J4BQC -To join, create an account here first: https://slack.aswf.io/ +* Main web site: http://opentimeline.io/ +* Documentation: https://opentimelineio.readthedocs.io/ +* GitHub: https://github.com/AcademySoftwareFoundation/OpenTimelineIO +* [Discussion group](https://lists.aswf.io/g/otio-discussion) +* [Slack channel](https://academysoftwarefdn.slack.com/messages/CMQ9J4BQC) + * To join, create an account here first: https://slack.aswf.io/ +* [Presentations](https://github.com/AcademySoftwareFoundation/OpenTimelineIO/wiki/Presentations) PUBLIC BETA NOTICE ------------------ @@ -33,17 +33,19 @@ Overview -------- OpenTimelineIO is an interchange format and API for editorial cut information. -OTIO is not a container format for media, rather it contains information about -the order and length of cuts and references to external media. +OTIO contains information about the order and length of cuts and + references to external media. It is not however, a container format for media. -OTIO includes both a file format and an API for manipulating that format. It -also includes a plugin architecture for writing adapters to convert -from/to existing editorial timeline formats. It also implements a dependency- -less library for dealing strictly with time, `opentime`. +For integration with applications, the core OTIO library is implemented in C++ +and provides an in-memory data model, as well as library functions for +interpreting, manipulating, and serializing that data model. Within the core is +a dependency-less library for dealing strictly with time, `opentime`. -You can provide adapters for your video editing tool or pipeline as needed. -Each adapter allows for import/export between that proprietary tool and the -OpenTimelineIO format. +The project also supports an official python binding, which is intended to be +an idiomatic and ergonomic binding for python developers. The python binding +includes a plugin system which supports a number of different types of plugins, +most notably adapters, which can be used to read and write legacy formats into +the OTIO data model. Documentation -------------- @@ -52,24 +54,25 @@ Documentation, including quick start, architecture, use cases, API docs, and muc Supported VFX Platforms ----------------- The current release supports: -- VFX platform 2021, 2020, 2019, 2018 +- VFX platform 2022, 2021, 2020, 2019 - Python 2.7 - 3.10 For more information on our vfxplatform support policy: [Contribution Guidelines Documentation Page](https://opentimelineio.readthedocs.io/en/latest/tutorials/contributing.html) For more information on the vfxplatform: [VFX Platform Homepage](https://vfxplatform.com) -Adapters --------- +Adapter Plugins +--------------- -OpenTimelineIO supports, or plans to support, conversion adapters for many -existing file formats, such as Final Cut Pro XML, AAF, CMX 3600 EDL, etc. +To provide interoperability with other file formats or applications lacking a +native integration, the opentimelineio community has built a number of python +adapter plugins. This includes Final Cut Pro XML, AAF, CMX 3600 EDL, and more. -See: https://opentimelineio.readthedocs.io/en/latest/tutorials/adapters.html +For more information about this, including supported formats, see: https://opentimelineio.readthedocs.io/en/latest/tutorials/adapters.html Other Plugins ------------- -OTIO also supports several other kinds of plugins, for more information see: +The OTIO python bindings also support several other kinds of plugins, for more information see: * [Media Linkers](https://opentimelineio.readthedocs.io/en/latest/tutorials/write-a-media-linker.html) - Generate media references to local media according to your local conventions. * [HookScripts](https://opentimelineio.readthedocs.io/en/latest/tutorials/write-a-hookscript.html) - Scripts that can run at various points during OTIO execution (_ie_ before the media linker) @@ -88,11 +91,43 @@ For detailed installation instructions and notes on how to run the included view Example Usage ------------- +C++: + +```c++ +#include + +#include "opentimelineio/timeline.h" + +namespace otio = opentimelineio::OPENTIMELINEIO_VERSION; + +void +main() +{ + otio::ErrorStatus err; + otio::SerializableObject::Retainer tl( + dynamic_cast( + otio::Timeline::from_json_file("taco.otio", &err) + ) + ); + const std::vector> clips = ( + tl->clip_if() + ); + for (const auto& cl : clips) + { + otio::RationalTime dur = cl->duration(); + std::cout << "Name: " << cl->name() << " ["; + std::cout << dur.value() << "/" << dur.rate() << "]" << std::endl; + } +} ``` + +Python: + +```python import opentimelineio as otio timeline = otio.adapters.read_from_file("foo.aaf") -for clip in timeline.each_clip(): +for clip in timeline.clip_if(): print(clip.name, clip.duration()) ``` diff --git a/setup.py b/setup.py index c581dd23d..f1b3a4abd 100644 --- a/setup.py +++ b/setup.py @@ -201,7 +201,7 @@ def cmake_install(self): # Metadata that gets stamped into the __init__ files during the build phase. PROJECT_METADATA = { - "version": "0.15.0.dev1", + "version": "0.15.0", "author": 'Contributors to the OpenTimelineIO project', "author_email": 'otio-discussion@lists.aswf.io', "license": 'Modified Apache 2.0 License', diff --git a/src/opentime/rationalTime.cpp b/src/opentime/rationalTime.cpp index 25a6ce658..de7ead556 100644 --- a/src/opentime/rationalTime.cpp +++ b/src/opentime/rationalTime.cpp @@ -68,8 +68,8 @@ double RationalTime::nearest_valid_timecode_rate(double rate) { double nearest_rate = 0; - double min_diff = std::numeric_limits::max(); - for (auto valid_rate : smpte_timecode_rates) + double min_diff = std::numeric_limits::max(); + for (auto valid_rate: smpte_timecode_rates) { if (valid_rate == rate) { @@ -80,7 +80,7 @@ RationalTime::nearest_valid_timecode_rate(double rate) { continue; } - min_diff = diff; + min_diff = diff; nearest_rate = valid_rate; } return nearest_rate; @@ -95,7 +95,11 @@ is_dropframe_rate(double rate) } static bool -parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* result) +parseFloat( + char const* pCurr, + char const* pEnd, + bool allow_negative, + double* result) { if (pCurr >= pEnd || !pCurr) { @@ -103,16 +107,16 @@ parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* res return false; } - double ret = 0.0; + double ret = 0.0; double sign = 1.0; if (*pCurr == '+') { ++pCurr; } - else if (*pCurr == '-') + else if (*pCurr == '-') { - if (!allow_negative) + if (!allow_negative) { *result = 0.0; return false; @@ -130,7 +134,7 @@ parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* res // partially compliant. // uint64_t uintPart = 0; - while (pCurr < pEnd) + while (pCurr < pEnd) { char c = *pCurr; if (c < '0' || c > '9') @@ -158,14 +162,14 @@ parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* res } // check for end of string or delimiter - if (pCurr == pEnd || *pCurr == '\0') + if (pCurr == pEnd || *pCurr == '\0') { *result = sign * ret; return true; } // if the next character is not a decimal point, the string is malformed. - if (*pCurr != '.') + if (*pCurr != '.') { *result = 0.0; // zero consistent with earlier error condition return false; @@ -174,7 +178,7 @@ parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* res ++pCurr; // skip decimal double position_scale = 0.1; - while (pCurr < pEnd) + while (pCurr < pEnd) { char c = *pCurr; if (c < '0' || c > '9') @@ -190,10 +194,11 @@ parseFloat(char const* pCurr, char const* pEnd, bool allow_negative, double* res return true; } - RationalTime RationalTime::from_timecode( - std::string const& timecode, double rate, ErrorStatus* error_status) + std::string const& timecode, + double rate, + ErrorStatus* error_status) { if (!RationalTime::is_valid_timecode_rate(rate)) { @@ -295,19 +300,22 @@ RationalTime::from_timecode( // convert to frames const int value = - (((total_minutes * 60) + seconds) * nominal_fps + frames - - (dropframes * - (total_minutes - static_cast(std::floor(total_minutes / 10))))); + (((total_minutes * 60) + seconds) * nominal_fps + frames + - (dropframes + * (total_minutes + - static_cast(std::floor(total_minutes / 10))))); return RationalTime{ double(value), rate }; } static void -set_error(std::string const& time_string, - ErrorStatus::Outcome code, - ErrorStatus* err) +set_error( + std::string const& time_string, + ErrorStatus::Outcome code, + ErrorStatus* err) { - if (err) { + if (err) + { *err = ErrorStatus( code, string_printf( @@ -319,19 +327,24 @@ set_error(std::string const& time_string, RationalTime RationalTime::from_time_string( - std::string const& time_string, double rate, ErrorStatus* error_status) + std::string const& time_string, + double rate, + ErrorStatus* error_status) { - if (!RationalTime::is_valid_timecode_rate(rate)) + if (!RationalTime::is_valid_timecode_rate(rate)) { - set_error(time_string, ErrorStatus::INVALID_TIMECODE_RATE, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIMECODE_RATE, + error_status); return RationalTime::_invalid_time; } - const char* start = time_string.data(); - const char* end = start + time_string.length(); - char* current = const_cast(end); - char* parse_end = current; - char* prev_parse_end = current; + const char* start = time_string.data(); + const char* end = start + time_string.length(); + char* current = const_cast(end); + char* parse_end = current; + char* prev_parse_end = current; double power[3] = { 1.0, // seconds @@ -340,65 +353,83 @@ RationalTime::from_time_string( }; double accumulator = 0.0; - int radix = 0; - while (start <= current) + int radix = 0; + while (start <= current) { - if (*current == ':') + if (*current == ':') { parse_end = current + 1; - char c = *parse_end; - if (c != '\0' && c != ':') + char c = *parse_end; + if (c != '\0' && c != ':') { - if (c< '0' || c > '9') + if (c < '0' || c > '9') { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; } double val = 0.0; if (!parseFloat(parse_end, prev_parse_end + 1, false, &val)) { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; } prev_parse_end = nullptr; - if (radix < 2 && val >= 60.0) + if (radix < 2 && val >= 60.0) { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; } accumulator += val * power[radix]; } ++radix; - if (radix == sizeof(power) / sizeof(power[0])) + if (radix == sizeof(power) / sizeof(power[0])) { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; } } - else if (current < prev_parse_end && - (*current < '0' || *current > '9') && - *current != '.') + else if ( + current < prev_parse_end && (*current < '0' || *current > '9') + && *current != '.') { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; } - if (start == current) + if (start == current) { - if (prev_parse_end) + if (prev_parse_end) { double val = 0.0; if (!parseFloat(start, prev_parse_end + 1, true, &val)) { - set_error(time_string, ErrorStatus::INVALID_TIME_STRING, error_status); + set_error( + time_string, + ErrorStatus::INVALID_TIME_STRING, + error_status); return RationalTime::_invalid_time; - } + } accumulator += val * power[radix]; } break; } --current; - if (!prev_parse_end) + if (!prev_parse_end) { prev_parse_end = current; } @@ -409,7 +440,9 @@ RationalTime::from_time_string( std::string RationalTime::to_timecode( - double rate, IsDropFrameRate drop_frame, ErrorStatus* error_status) const + double rate, + IsDropFrameRate drop_frame, + ErrorStatus* error_status) const { if (error_status) { @@ -505,10 +538,11 @@ RationalTime::to_timecode( if (frames_over_ten_minutes > dropframes) { - value += (dropframes * 9 * ten_minute_chunks) + - dropframes * std::floor( - (frames_over_ten_minutes - dropframes) / - frames_per_minute); + value += (dropframes * 9 * ten_minute_chunks) + + dropframes + * std::floor( + (frames_over_ten_minutes - dropframes) + / frames_per_minute); } else { @@ -528,7 +562,12 @@ RationalTime::to_timecode( static_cast(std::floor(std::floor(seconds_total / 60) / 60)); return string_printf( - "%02d:%02d:%02d%c%02d", hours, minutes, seconds, div, frames); + "%02d:%02d:%02d%c%02d", + hours, + minutes, + seconds, + div, + frames); } std::string diff --git a/src/opentime/rationalTime.h b/src/opentime/rationalTime.h index 39abd512b..ec791bc25 100644 --- a/src/opentime/rationalTime.h +++ b/src/opentime/rationalTime.h @@ -38,7 +38,7 @@ class RationalTime , _rate{ rate } {} - constexpr RationalTime(RationalTime const&) noexcept = default; + constexpr RationalTime(RationalTime const&) noexcept = default; RationalTime& operator=(RationalTime const&) noexcept = default; bool is_invalid_time() const noexcept @@ -77,28 +77,30 @@ class RationalTime } static RationalTime constexpr duration_from_start_end_time( - RationalTime start_time, RationalTime end_time_exclusive) noexcept + RationalTime start_time, + RationalTime end_time_exclusive) noexcept { return start_time._rate == end_time_exclusive._rate - ? RationalTime{ end_time_exclusive._value - - start_time._value, + ? RationalTime{ end_time_exclusive._value + - start_time._value, start_time._rate } : RationalTime{ end_time_exclusive.value_rescaled_to( - start_time) - - start_time._value, + start_time) + - start_time._value, start_time._rate }; } static RationalTime constexpr duration_from_start_end_time_inclusive( - RationalTime start_time, RationalTime end_time_inclusive) noexcept + RationalTime start_time, + RationalTime end_time_inclusive) noexcept { return start_time._rate == end_time_inclusive._rate - ? RationalTime{ end_time_inclusive._value - - start_time._value + 1, + ? RationalTime{ end_time_inclusive._value - start_time._value + + 1, start_time._rate } : RationalTime{ end_time_inclusive.value_rescaled_to( - start_time) - - start_time._value + 1, + start_time) + - start_time._value + 1, start_time._rate }; } @@ -197,11 +199,11 @@ class RationalTime operator+(RationalTime lhs, RationalTime rhs) noexcept { return (lhs._rate < rhs._rate) - ? RationalTime{ lhs.value_rescaled_to(rhs._rate) + - rhs._value, + ? RationalTime{ lhs.value_rescaled_to(rhs._rate) + + rhs._value, rhs._rate } - : RationalTime{ rhs.value_rescaled_to(lhs._rate) + - lhs._value, + : RationalTime{ rhs.value_rescaled_to(lhs._rate) + + lhs._value, lhs._rate }; } @@ -209,11 +211,11 @@ class RationalTime operator-(RationalTime lhs, RationalTime rhs) noexcept { return (lhs._rate < rhs._rate) - ? RationalTime{ lhs.value_rescaled_to(rhs._rate) - - rhs._value, + ? RationalTime{ lhs.value_rescaled_to(rhs._rate) + - rhs._value, rhs._rate } - : RationalTime{ lhs._value - - rhs.value_rescaled_to(lhs._rate), + : RationalTime{ lhs._value + - rhs.value_rescaled_to(lhs._rate), lhs._rate }; } diff --git a/src/opentime/timeRange.cpp b/src/opentime/timeRange.cpp index fe8ba8cbd..c57dd643e 100644 --- a/src/opentime/timeRange.cpp +++ b/src/opentime/timeRange.cpp @@ -2,4 +2,3 @@ // Copyright Contributors to the OpenTimelineIO project #include "opentime/timeRange.h" - diff --git a/src/opentime/timeRange.h b/src/opentime/timeRange.h index 832361954..3c039c6da 100644 --- a/src/opentime/timeRange.h +++ b/src/opentime/timeRange.h @@ -41,7 +41,8 @@ class TimeRange {} explicit constexpr TimeRange( - RationalTime start_time, RationalTime duration) noexcept + RationalTime start_time, + RationalTime duration) noexcept : _start_time{ start_time } , _duration{ duration } {} @@ -82,14 +83,17 @@ class TimeRange constexpr TimeRange extended_by(TimeRange other) const noexcept { - const RationalTime new_start_time{ std::min( - _start_time, other._start_time) }, - new_end_time{ std::max( - end_time_exclusive(), other.end_time_exclusive()) }; + const RationalTime new_start_time{ + std::min(_start_time, other._start_time) + }, + new_end_time{ + std::max(end_time_exclusive(), other.end_time_exclusive()) + }; return TimeRange{ new_start_time, RationalTime::duration_from_start_end_time( - new_start_time, new_end_time) }; + new_start_time, + new_end_time) }; } RationalTime clamped(RationalTime other) const noexcept @@ -101,8 +105,9 @@ class TimeRange { const TimeRange r{ std::max(other._start_time, _start_time), other._duration }; - const RationalTime end{ std::min( - r.end_time_exclusive(), end_time_exclusive()) }; + const RationalTime end{ + std::min(r.end_time_exclusive(), end_time_exclusive()) + }; return TimeRange{ r._start_time, end - r._start_time }; } @@ -142,14 +147,15 @@ class TimeRange * @param other */ constexpr bool contains( - TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + TimeRange other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisStart = _start_time.to_seconds(); const double thisEnd = end_time_exclusive().to_seconds(); const double otherStart = other._start_time.to_seconds(); const double otherEnd = other.end_time_exclusive().to_seconds(); - return greater_than(otherStart, thisStart, epsilon_s) && - lesser_than(otherEnd, thisEnd, epsilon_s); + return greater_than(otherStart, thisStart, epsilon_s) + && lesser_than(otherEnd, thisEnd, epsilon_s); } /** @@ -175,15 +181,16 @@ class TimeRange * @param epsilon_s */ constexpr bool overlaps( - TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + TimeRange other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisStart = _start_time.to_seconds(); const double thisEnd = end_time_exclusive().to_seconds(); const double otherStart = other._start_time.to_seconds(); const double otherEnd = other.end_time_exclusive().to_seconds(); - return lesser_than(thisStart, otherStart, epsilon_s) && - greater_than(thisEnd, otherStart, epsilon_s) && - greater_than(otherEnd, thisEnd, epsilon_s); + return lesser_than(thisStart, otherStart, epsilon_s) + && greater_than(thisEnd, otherStart, epsilon_s) + && greater_than(otherEnd, thisEnd, epsilon_s); } /** @@ -210,7 +217,8 @@ class TimeRange * @param epsilon_s */ constexpr bool before( - RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + RationalTime other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisEnd = end_time_exclusive().to_seconds(); const double otherTime = other.to_seconds(); @@ -249,8 +257,8 @@ class TimeRange const double thisEnd = end_time_exclusive().to_seconds(); const double otherStart = other._start_time.to_seconds(); const double otherEnd = other.end_time_exclusive().to_seconds(); - return fabs(otherStart - thisStart) <= epsilon_s && - lesser_than(thisEnd, otherEnd, epsilon_s); + return fabs(otherStart - thisStart) <= epsilon_s + && lesser_than(thisEnd, otherEnd, epsilon_s); } /** @@ -262,7 +270,8 @@ class TimeRange * @param other */ constexpr bool begins( - RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + RationalTime other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisStart = _start_time.to_seconds(); const double otherStart = other.to_seconds(); @@ -279,14 +288,15 @@ class TimeRange * @param epsilon_s */ constexpr bool finishes( - TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + TimeRange other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisStart = _start_time.to_seconds(); const double thisEnd = end_time_exclusive().to_seconds(); const double otherStart = other._start_time.to_seconds(); const double otherEnd = other.end_time_exclusive().to_seconds(); - return fabs(thisEnd - otherEnd) <= epsilon_s && - greater_than(thisStart, otherStart, epsilon_s); + return fabs(thisEnd - otherEnd) <= epsilon_s + && greater_than(thisStart, otherStart, epsilon_s); } /** @@ -299,7 +309,8 @@ class TimeRange * @param epsilon_s */ constexpr bool finishes( - RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + RationalTime other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisEnd = end_time_exclusive().to_seconds(); const double otherEnd = other.to_seconds(); @@ -316,14 +327,15 @@ class TimeRange * @param epsilon_s */ constexpr bool intersects( - TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const noexcept + TimeRange other, + double epsilon_s = DEFAULT_EPSILON_s) const noexcept { const double thisStart = _start_time.to_seconds(); const double thisEnd = end_time_exclusive().to_seconds(); const double otherStart = other._start_time.to_seconds(); const double otherEnd = other.end_time_exclusive().to_seconds(); - return lesser_than(thisStart, otherEnd, epsilon_s) && - greater_than(thisEnd, otherStart, epsilon_s); + return lesser_than(thisStart, otherEnd, epsilon_s) + && greater_than(thisEnd, otherStart, epsilon_s); } /** @@ -338,8 +350,8 @@ class TimeRange { const RationalTime start = lhs._start_time - rhs._start_time; const RationalTime duration = lhs._duration - rhs._duration; - return fabs(start.to_seconds()) < DEFAULT_EPSILON_s && - fabs(duration.to_seconds()) < DEFAULT_EPSILON_s; + return fabs(start.to_seconds()) < DEFAULT_EPSILON_s + && fabs(duration.to_seconds()) < DEFAULT_EPSILON_s; } /** @@ -353,19 +365,23 @@ class TimeRange } static constexpr TimeRange range_from_start_end_time( - RationalTime start_time, RationalTime end_time_exclusive) noexcept + RationalTime start_time, + RationalTime end_time_exclusive) noexcept { return TimeRange{ start_time, RationalTime::duration_from_start_end_time( - start_time, end_time_exclusive) }; + start_time, + end_time_exclusive) }; } static constexpr TimeRange range_from_start_end_time_inclusive( - RationalTime start_time, RationalTime end_time_inclusive) noexcept + RationalTime start_time, + RationalTime end_time_inclusive) noexcept { return TimeRange{ start_time, RationalTime::duration_from_start_end_time_inclusive( - start_time, end_time_inclusive) }; + start_time, + end_time_inclusive) }; } private: diff --git a/src/opentime/timeTransform.cpp b/src/opentime/timeTransform.cpp index 125bc4e6d..97201bfcc 100644 --- a/src/opentime/timeTransform.cpp +++ b/src/opentime/timeTransform.cpp @@ -2,4 +2,3 @@ // Copyright Contributors to the OpenTimelineIO project #include "opentime/timeTransform.h" - diff --git a/src/opentime/timeTransform.h b/src/opentime/timeTransform.h index 45e586c83..435899114 100644 --- a/src/opentime/timeTransform.h +++ b/src/opentime/timeTransform.h @@ -28,7 +28,7 @@ class TimeTransform constexpr double rate() const noexcept { return _rate; } - constexpr TimeTransform(TimeTransform const&) noexcept = default; + constexpr TimeTransform(TimeTransform const&) noexcept = default; TimeTransform& operator=(TimeTransform const&) noexcept = default; TimeRange applied_to(TimeRange other) const noexcept @@ -47,18 +47,17 @@ class TimeTransform RationalTime applied_to(RationalTime other) const noexcept { - RationalTime result{ - RationalTime{ other._value * _scale, other._rate } + _offset - }; - double target_rate = _rate > 0 ? _rate : other._rate; + RationalTime result{ RationalTime{ other._value * _scale, other._rate } + + _offset }; + double target_rate = _rate > 0 ? _rate : other._rate; return target_rate > 0 ? result.rescaled_to(target_rate) : result; } friend constexpr bool operator==(TimeTransform lhs, TimeTransform rhs) noexcept { - return lhs._offset == rhs._offset && lhs._scale == rhs._scale && - lhs._rate == rhs._rate; + return lhs._offset == rhs._offset && lhs._scale == rhs._scale + && lhs._rate == rhs._rate; } friend constexpr bool diff --git a/src/opentimelineio/CORE_VERSION_MAP.cpp b/src/opentimelineio/CORE_VERSION_MAP.cpp index 7c5ffd90d..1eee987c6 100644 --- a/src/opentimelineio/CORE_VERSION_MAP.cpp +++ b/src/opentimelineio/CORE_VERSION_MAP.cpp @@ -14,73 +14,71 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { -const label_to_schema_version_map CORE_VERSION_MAP { +const label_to_schema_version_map CORE_VERSION_MAP{ { "0.14.0", - { - { "Adapter", 1 }, - { "Clip", 1 }, - { "Composable", 1 }, - { "Composition", 1 }, - { "Effect", 1 }, - { "ExternalReference", 1 }, - { "FreezeFrame", 1 }, - { "Gap", 1 }, - { "GeneratorReference", 1 }, - { "HookScript", 1 }, - { "ImageSequenceReference", 1 }, - { "Item", 1 }, - { "LinearTimeWarp", 1 }, - { "Marker", 2 }, - { "MediaLinker", 1 }, - { "MediaReference", 1 }, - { "MissingReference", 1 }, - { "PluginManifest", 1 }, - { "SchemaDef", 1 }, - { "SerializableCollection", 1 }, - { "SerializableObject", 1 }, - { "SerializableObjectWithMetadata", 1 }, - { "Stack", 1 }, - { "TimeEffect", 1 }, - { "Timeline", 1 }, - { "Track", 1 }, - { "Transition", 1 }, - { "UnknownSchema", 1 }, - } - }, - { "0.15.0.dev1", - { - { "Adapter", 1 }, - { "Clip", 2 }, - { "Composable", 1 }, - { "Composition", 1 }, - { "Effect", 1 }, - { "ExternalReference", 1 }, - { "FreezeFrame", 1 }, - { "Gap", 1 }, - { "GeneratorReference", 1 }, - { "HookScript", 1 }, - { "ImageSequenceReference", 1 }, - { "Item", 1 }, - { "LinearTimeWarp", 1 }, - { "Marker", 2 }, - { "MediaLinker", 1 }, - { "MediaReference", 1 }, - { "MissingReference", 1 }, - { "PluginManifest", 1 }, - { "SchemaDef", 1 }, - { "SerializableCollection", 1 }, - { "SerializableObject", 1 }, - { "SerializableObjectWithMetadata", 1 }, - { "Stack", 1 }, - { "Test", 1 }, - { "TimeEffect", 1 }, - { "Timeline", 1 }, - { "Track", 1 }, - { "Transition", 1 }, - { "UnknownSchema", 1 }, - } - }, + { + { "Adapter", 1 }, + { "Clip", 1 }, + { "Composable", 1 }, + { "Composition", 1 }, + { "Effect", 1 }, + { "ExternalReference", 1 }, + { "FreezeFrame", 1 }, + { "Gap", 1 }, + { "GeneratorReference", 1 }, + { "HookScript", 1 }, + { "ImageSequenceReference", 1 }, + { "Item", 1 }, + { "LinearTimeWarp", 1 }, + { "Marker", 2 }, + { "MediaLinker", 1 }, + { "MediaReference", 1 }, + { "MissingReference", 1 }, + { "PluginManifest", 1 }, + { "SchemaDef", 1 }, + { "SerializableCollection", 1 }, + { "SerializableObject", 1 }, + { "SerializableObjectWithMetadata", 1 }, + { "Stack", 1 }, + { "TimeEffect", 1 }, + { "Timeline", 1 }, + { "Track", 1 }, + { "Transition", 1 }, + { "UnknownSchema", 1 }, + } }, + { "0.15.0", + { + { "Adapter", 1 }, + { "Clip", 2 }, + { "Composable", 1 }, + { "Composition", 1 }, + { "Effect", 1 }, + { "ExternalReference", 1 }, + { "FreezeFrame", 1 }, + { "Gap", 1 }, + { "GeneratorReference", 1 }, + { "HookScript", 1 }, + { "ImageSequenceReference", 1 }, + { "Item", 1 }, + { "LinearTimeWarp", 1 }, + { "Marker", 2 }, + { "MediaLinker", 1 }, + { "MediaReference", 1 }, + { "MissingReference", 1 }, + { "PluginManifest", 1 }, + { "SchemaDef", 1 }, + { "SerializableCollection", 1 }, + { "SerializableObject", 1 }, + { "SerializableObjectWithMetadata", 1 }, + { "Stack", 1 }, + { "Test", 1 }, + { "TimeEffect", 1 }, + { "Timeline", 1 }, + { "Track", 1 }, + { "Transition", 1 }, + { "UnknownSchema", 1 }, + } }, // {next} }; -} } // namespace opentimelineio::OPENTIMELINEIO_VERSION +}} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/CORE_VERSION_MAP.last.cpp b/src/opentimelineio/CORE_VERSION_MAP.last.cpp index efadb67ec..713d9761a 100644 --- a/src/opentimelineio/CORE_VERSION_MAP.last.cpp +++ b/src/opentimelineio/CORE_VERSION_MAP.last.cpp @@ -14,40 +14,39 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { -const label_to_schema_version_map CORE_VERSION_MAP { +const label_to_schema_version_map CORE_VERSION_MAP{ { "0.14.0", - { - { "Adapter", 1 }, - { "Clip", 1 }, - { "Composable", 1 }, - { "Composition", 1 }, - { "Effect", 1 }, - { "ExternalReference", 1 }, - { "FreezeFrame", 1 }, - { "Gap", 1 }, - { "GeneratorReference", 1 }, - { "HookScript", 1 }, - { "ImageSequenceReference", 1 }, - { "Item", 1 }, - { "LinearTimeWarp", 1 }, - { "Marker", 2 }, - { "MediaLinker", 1 }, - { "MediaReference", 1 }, - { "MissingReference", 1 }, - { "PluginManifest", 1 }, - { "SchemaDef", 1 }, - { "SerializableCollection", 1 }, - { "SerializableObject", 1 }, - { "SerializableObjectWithMetadata", 1 }, - { "Stack", 1 }, - { "TimeEffect", 1 }, - { "Timeline", 1 }, - { "Track", 1 }, - { "Transition", 1 }, - { "UnknownSchema", 1 }, - } - }, + { + { "Adapter", 1 }, + { "Clip", 1 }, + { "Composable", 1 }, + { "Composition", 1 }, + { "Effect", 1 }, + { "ExternalReference", 1 }, + { "FreezeFrame", 1 }, + { "Gap", 1 }, + { "GeneratorReference", 1 }, + { "HookScript", 1 }, + { "ImageSequenceReference", 1 }, + { "Item", 1 }, + { "LinearTimeWarp", 1 }, + { "Marker", 2 }, + { "MediaLinker", 1 }, + { "MediaReference", 1 }, + { "MissingReference", 1 }, + { "PluginManifest", 1 }, + { "SchemaDef", 1 }, + { "SerializableCollection", 1 }, + { "SerializableObject", 1 }, + { "SerializableObjectWithMetadata", 1 }, + { "Stack", 1 }, + { "TimeEffect", 1 }, + { "Timeline", 1 }, + { "Track", 1 }, + { "Transition", 1 }, + { "UnknownSchema", 1 }, + } }, // {next} }; -} } // namespace opentimelineio::OPENTIMELINEIO_VERSION +}} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/anyDictionary.h b/src/opentimelineio/anyDictionary.h index 3512897e7..af5f5a29f 100644 --- a/src/opentimelineio/anyDictionary.h +++ b/src/opentimelineio/anyDictionary.h @@ -127,12 +127,8 @@ class AnyDictionary : private std::map // if key is in this, and the type of key matches the type of result, then // set result to the value of any_cast(this[key]) and return true, // otherwise return false - template - bool - get_if_set( - const std::string& key, - containedType* result - ) const + template + bool get_if_set(const std::string& key, containedType* result) const { if (result == nullptr) { @@ -141,66 +137,50 @@ class AnyDictionary : private std::map const auto it = this->find(key); - if ( - (it != this->end()) - && ( - it->second.type().hash_code() - == typeid(containedType).hash_code() - ) - ) + if ((it != this->end()) + && (it->second.type().hash_code() + == typeid(containedType).hash_code())) { *result = any_cast(it->second); return true; - } + } else { return false; } } - inline bool - has_key( - const std::string& key - ) const + inline bool has_key(const std::string& key) const { return (this->find(key) != this->end()); } // if key is in this, place the value in result and return true, otherwise // store the value in result at key and return false - template - bool - set_default( - const std::string& key, - containedType* result - ) + template + bool set_default(const std::string& key, containedType* result) { if (result == nullptr) { return false; } - const auto d_it = this->find(key); + const auto d_it = this->find(key); - if ( - (d_it != this->end()) - && ( - d_it->second.type().hash_code() - == typeid(containedType).hash_code() - ) - ) + if ((d_it != this->end()) + && (d_it->second.type().hash_code() + == typeid(containedType).hash_code())) { *result = any_cast(d_it->second); return true; - } - else + } + else { - this->insert({key, *result}); + this->insert({ key, *result }); return false; } } - using map::empty; using map::max_size; using map::size; @@ -240,7 +220,7 @@ class AnyDictionary : private std::map assert(d); } - MutationStamp(MutationStamp const&) = delete; + MutationStamp(MutationStamp const&) = delete; MutationStamp& operator=(MutationStamp const&) = delete; ~MutationStamp() diff --git a/src/opentimelineio/anyVector.h b/src/opentimelineio/anyVector.h index 230bd6ead..38561fead 100644 --- a/src/opentimelineio/anyVector.h +++ b/src/opentimelineio/anyVector.h @@ -123,7 +123,7 @@ class AnyVector : private std::vector assert(v != nullptr); } - MutationStamp(MutationStamp const&) = delete; + MutationStamp(MutationStamp const&) = delete; MutationStamp& operator=(MutationStamp const&) = delete; ~MutationStamp() diff --git a/src/opentimelineio/clip.cpp b/src/opentimelineio/clip.cpp index f817d2f4c..b48624fb6 100644 --- a/src/opentimelineio/clip.cpp +++ b/src/opentimelineio/clip.cpp @@ -59,8 +59,8 @@ Clip::check_for_valid_media_reference_key( { *error_status = ErrorStatus( ErrorStatus::MEDIA_REFERENCES_CONTAIN_EMPTY_KEY, - caller + - " failed because the media references contain an empty string key", + caller + + " failed because the media references contain an empty string key", this); } return false; @@ -73,8 +73,8 @@ Clip::check_for_valid_media_reference_key( { *error_status = ErrorStatus( ErrorStatus::MEDIA_REFERENCES_DO_NOT_CONTAIN_ACTIVE_KEY, - caller + - " failed because the media references do not contain the active key", + caller + + " failed because the media references do not contain the active key", this); } return false; @@ -114,7 +114,8 @@ Clip::active_media_reference_key() const noexcept void Clip::set_active_media_reference_key( - std::string const& new_active_key, ErrorStatus* error_status) noexcept + std::string const& new_active_key, + ErrorStatus* error_status) noexcept { if (!check_for_valid_media_reference_key( "set_active_media_reference_key", @@ -137,10 +138,11 @@ Clip::set_media_reference(MediaReference* media_reference) bool Clip::read_from(Reader& reader) { - return reader.read("media_references", &_media_references) && - reader.read( - "active_media_reference_key", &_active_media_reference_key) && - Parent::read_from(reader); + return reader.read("media_references", &_media_references) + && reader.read( + "active_media_reference_key", + &_active_media_reference_key) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/composition.cpp b/src/opentimelineio/composition.cpp index 09065eacd..a9920f5c3 100644 --- a/src/opentimelineio/composition.cpp +++ b/src/opentimelineio/composition.cpp @@ -45,7 +45,8 @@ Composition::clear_children() bool Composition::set_children( - std::vector const& children, ErrorStatus* error_status) + std::vector const& children, + ErrorStatus* error_status) { for (auto child: children) { @@ -71,7 +72,9 @@ Composition::set_children( bool Composition::insert_child( - int index, Composable* child, ErrorStatus* error_status) + int index, + Composable* child, + ErrorStatus* error_status) { if (child->parent()) { @@ -207,14 +210,15 @@ Composition::is_parent_of(Composable const* other) const std::pair, optional> Composition::handles_of_child( - Composable const* /* child */, ErrorStatus* /* error_status */) const + Composable const* /* child */, + ErrorStatus* /* error_status */) const { return std::make_pair(optional(), optional()); } int -Composition::_index_of_child( - Composable const* child, ErrorStatus* error_status) const +Composition::_index_of_child(Composable const* child, ErrorStatus* error_status) + const { for (size_t i = 0; i < _children.size(); i++) { @@ -234,7 +238,8 @@ Composition::_index_of_child( std::vector Composition::_path_from_child( - Composable const* child, ErrorStatus* error_status) const + Composable const* child, + ErrorStatus* error_status) const { auto current = child->parent(); std::vector parents{ current }; @@ -258,8 +263,8 @@ Composition::_path_from_child( } TimeRange -Composition::range_of_child_at_index( - int /* index */, ErrorStatus* error_status) const +Composition::range_of_child_at_index(int /* index */, ErrorStatus* error_status) + const { if (error_status) { @@ -270,7 +275,8 @@ Composition::range_of_child_at_index( TimeRange Composition::trimmed_range_of_child_at_index( - int /* index */, ErrorStatus* error_status) const + int /* index */, + ErrorStatus* error_status) const { if (error_status) { @@ -291,8 +297,8 @@ Composition::range_of_all_children(ErrorStatus* error_status) const // XXX should have reference_space argument or something TimeRange -Composition::range_of_child( - Composable const* child, ErrorStatus* error_status) const +Composition::range_of_child(Composable const* child, ErrorStatus* error_status) + const { auto parents = _path_from_child(child, error_status); if (is_error(error_status)) @@ -333,16 +339,18 @@ Composition::range_of_child( current = parent; } - return (reference_space != this) - ? transformed_time_range( - *result_range, reference_space, error_status) - : *result_range; + return (reference_space != this) ? transformed_time_range( + *result_range, + reference_space, + error_status) + : *result_range; } // XXX should have reference_space argument or something optional Composition::trimmed_range_of_child( - Composable const* child, ErrorStatus* error_status) const + Composable const* child, + ErrorStatus* error_status) const { auto parents = _path_from_child(child, error_status); if (is_error(error_status)) @@ -395,8 +403,8 @@ Composition::trimmed_range_of_child( auto new_duration = std::min( result_range->end_time_exclusive(), - source_range()->end_time_exclusive()) - - new_start_time; + source_range()->end_time_exclusive()) + - new_start_time; if (new_duration.value() < 0) { return nullopt; @@ -443,13 +451,15 @@ Composition::trim_child_range(TimeRange child_range) const if (child_range.start_time() < sr.start_time()) { child_range = TimeRange::range_from_start_end_time( - sr.start_time(), child_range.end_time_exclusive()); + sr.start_time(), + child_range.end_time_exclusive()); } if (child_range.end_time_exclusive() > sr.end_time_exclusive()) { child_range = TimeRange::range_from_start_end_time( - child_range.start_time(), sr.end_time_exclusive()); + child_range.start_time(), + sr.end_time_exclusive()); } return child_range; @@ -535,7 +545,9 @@ Composition::child_at_time( } result = composition.value->child_at_time( - child_search_time, error_status, shallow_search); + child_search_time, + error_status, + shallow_search); if (is_error(error_status)) { return result; @@ -545,7 +557,8 @@ Composition::child_at_time( std::vector> Composition::children_in_range( - TimeRange const& search_range, ErrorStatus* error_status) const + TimeRange const& search_range, + ErrorStatus* error_status) const { std::vector> children; diff --git a/src/opentimelineio/composition.h b/src/opentimelineio/composition.h index 4bb6f6702..a6c865df6 100644 --- a/src/opentimelineio/composition.h +++ b/src/opentimelineio/composition.h @@ -41,10 +41,14 @@ class Composition : public Item ErrorStatus* error_status = nullptr); bool insert_child( - int index, Composable* child, ErrorStatus* error_status = nullptr); + int index, + Composable* child, + ErrorStatus* error_status = nullptr); bool set_child( - int index, Composable* child, ErrorStatus* error_status = nullptr); + int index, + Composable* child, + ErrorStatus* error_status = nullptr); bool remove_child(int index, ErrorStatus* error_status = nullptr); @@ -57,18 +61,23 @@ class Composition : public Item virtual std::pair, optional> handles_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; virtual TimeRange range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; virtual TimeRange trimmed_range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; // leaving out reference_space argument for now: TimeRange range_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; optional trimmed_range_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; optional trim_child_range(TimeRange child_range) const; @@ -110,9 +119,11 @@ class Composition : public Item virtual void write_to(Writer&) const; int _index_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; std::vector _path_from_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; private: // XXX: python implementation is O(n^2) in number of children @@ -197,7 +208,9 @@ Composition::children_if( if (search_range) { search_range = transformed_time_range( - *search_range, composition, error_status); + *search_range, + composition, + error_status); if (is_error(error_status)) { return out; @@ -205,7 +218,9 @@ Composition::children_if( } const auto valid_children = composition->children_if( - error_status, search_range, shallow_search); + error_status, + search_range, + shallow_search); if (is_error(error_status)) { return out; diff --git a/src/opentimelineio/deserialization.cpp b/src/opentimelineio/deserialization.cpp index 2b50544e7..05a3e2b30 100644 --- a/src/opentimelineio/deserialization.cpp +++ b/src/opentimelineio/deserialization.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Contributors to the OpenTimelineIO project -#include "opentimelineio/serializableObject.h" -#include "opentimelineio/serializableObjectWithMetadata.h" #include "opentime/rationalTime.h" #include "opentime/timeRange.h" #include "opentime/timeTransform.h" @@ -233,7 +231,9 @@ class JSONDecoder : public OTIO_rapidjson:: _error_status = ErrorStatus( ErrorStatus::INTERNAL_ERROR, string_printf( - "%s (near line %d)", err_msg.c_str(), _line_number_function())); + "%s (near line %d)", + err_msg.c_str(), + _line_number_function())); } void _error(ErrorStatus const& error_status) @@ -339,7 +339,10 @@ SerializableObject::Reader::_fix_reference_ids( if (a.type() == typeid(AnyDictionary)) { _fix_reference_ids( - any_cast(a), error_function, resolver, line_number); + any_cast(a), + error_function, + resolver, + line_number); } else if (a.type() == typeid(AnyVector)) { @@ -347,7 +350,10 @@ SerializableObject::Reader::_fix_reference_ids( for (size_t i = 0; i < child_array.size(); i++) { _fix_reference_ids( - child_array[i], error_function, resolver, line_number); + child_array[i], + error_function, + resolver, + line_number); } } else if (a.type() == typeid(SerializableObject::ReferenceId)) @@ -370,7 +376,9 @@ SerializableObject::Reader::_fix_reference_ids( template bool SerializableObject::Reader::_fetch( - std::string const& key, T* dest, bool* had_null) + std::string const& key, + T* dest, + bool* had_null) { auto e = _dict.find(key); if (e == _dict.end()) @@ -480,7 +488,8 @@ SerializableObject::Reader::_fetch(std::string const& key, int64_t* dest) bool SerializableObject::Reader::_fetch( - std::string const& key, SerializableObject** dest) + std::string const& key, + SerializableObject** dest) { auto e = _dict.find(key); if (e == _dict.end()) @@ -513,7 +522,8 @@ SerializableObject::Reader::_fetch( bool SerializableObject::Reader::_type_check( - std::type_info const& wanted, std::type_info const& found) + std::type_info const& wanted, + std::type_info const& found) { if (wanted != found) { @@ -572,8 +582,8 @@ SerializableObject::Reader::_decode(_Resolver& resolver) else if (schema_name_and_version == "TimeRange.1") { RationalTime start_time, duration; - return _fetch("start_time", &start_time) && - _fetch("duration", &duration) + return _fetch("start_time", &start_time) + && _fetch("duration", &duration) ? any(TimeRange(start_time, duration)) : any(); } @@ -581,8 +591,8 @@ SerializableObject::Reader::_decode(_Resolver& resolver) { RationalTime offset; double rate, scale; - return _fetch("offset", &offset) && _fetch("rate", &rate) && - _fetch("scale", &scale) + return _fetch("offset", &offset) && _fetch("rate", &rate) + && _fetch("scale", &scale) ? any(TimeTransform(offset, scale, rate)) : any(); } @@ -623,7 +633,8 @@ SerializableObject::Reader::_decode(_Resolver& resolver) if (e != resolver.object_for_id.end()) { _error(ErrorStatus( - ErrorStatus::DUPLICATE_OBJECT_REFERENCE, ref_id)); + ErrorStatus::DUPLICATE_OBJECT_REFERENCE, + ref_id)); return any(); } } @@ -633,7 +644,9 @@ SerializableObject::Reader::_decode(_Resolver& resolver) int schema_version; if (!split_schema_string( - schema_name_and_version, &schema_name, &schema_version)) + schema_name_and_version, + &schema_name, + &schema_version)) { _error(ErrorStatus( ErrorStatus::MALFORMED_SCHEMA, @@ -744,7 +757,8 @@ SerializableObject::Reader::read(std::string const& key, Imath::Box2d* value) template bool SerializableObject::Reader::_read_optional( - std::string const& key, optional* value) + std::string const& key, + optional* value) { bool had_null; T result; @@ -770,35 +784,40 @@ SerializableObject::Reader::read(std::string const& key, optional* value) bool SerializableObject::Reader::read( - std::string const& key, optional* value) + std::string const& key, + optional* value) { return _read_optional(key, value); } bool SerializableObject::Reader::read( - std::string const& key, optional* value) + std::string const& key, + optional* value) { return _read_optional(key, value); } bool SerializableObject::Reader::read( - std::string const& key, optional* value) + std::string const& key, + optional* value) { return _read_optional(key, value); } bool SerializableObject::Reader::read( - std::string const& key, optional* value) + std::string const& key, + optional* value) { return _read_optional(key, value); } bool SerializableObject::Reader::read( - std::string const& key, optional* value) + std::string const& key, + optional* value) { return _read_optional(key, value); } @@ -822,7 +841,9 @@ SerializableObject::Reader::read(std::string const& key, any* value) bool deserialize_json_from_string( - std::string const& input, any* destination, ErrorStatus* error_status) + std::string const& input, + any* destination, + ErrorStatus* error_status) { OTIO_rapidjson::Reader reader; OTIO_rapidjson::StringStream ss(input.c_str()); @@ -861,7 +882,9 @@ deserialize_json_from_string( bool deserialize_json_from_file( - std::string const& file_name, any* destination, ErrorStatus* error_status) + std::string const& file_name, + any* destination, + ErrorStatus* error_status) { FILE* fp = nullptr; @@ -874,7 +897,7 @@ deserialize_json_from_file( { fp = nullptr; } -#else // _WINDOWS +#else // _WINDOWS fp = fopen(file_name.c_str(), "r"); #endif // _WINDOWS if (!fp) diff --git a/src/opentimelineio/effect.cpp b/src/opentimelineio/effect.cpp index f7306d1eb..e1e4f75f7 100644 --- a/src/opentimelineio/effect.cpp +++ b/src/opentimelineio/effect.cpp @@ -20,8 +20,8 @@ Effect::~Effect() bool Effect::read_from(Reader& reader) { - return reader.read("effect_name", &_effect_name) && - Parent::read_from(reader); + return reader.read("effect_name", &_effect_name) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/gap.cpp b/src/opentimelineio/gap.cpp index b310d4df8..c7bb28b0a 100644 --- a/src/opentimelineio/gap.cpp +++ b/src/opentimelineio/gap.cpp @@ -21,11 +21,11 @@ Gap::Gap( std::vector const& markers, AnyDictionary const& metadata) : Parent( - name, - TimeRange(RationalTime(0, duration.rate()), duration), - metadata, - effects, - markers) + name, + TimeRange(RationalTime(0, duration.rate()), duration), + metadata, + effects, + markers) {} Gap::~Gap() diff --git a/src/opentimelineio/generatorReference.cpp b/src/opentimelineio/generatorReference.cpp index 4830df762..bc4ebf217 100644 --- a/src/opentimelineio/generatorReference.cpp +++ b/src/opentimelineio/generatorReference.cpp @@ -23,8 +23,9 @@ GeneratorReference::~GeneratorReference() bool GeneratorReference::read_from(Reader& reader) { - return reader.read("generator_kind", &_generator_kind) && - reader.read("parameters", &_parameters) && Parent::read_from(reader); + return reader.read("generator_kind", &_generator_kind) + && reader.read("parameters", &_parameters) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/imageSequenceReference.cpp b/src/opentimelineio/imageSequenceReference.cpp index 3ff8c772f..c8cef6baa 100644 --- a/src/opentimelineio/imageSequenceReference.cpp +++ b/src/opentimelineio/imageSequenceReference.cpp @@ -68,10 +68,11 @@ ImageSequenceReference::number_of_images_in_sequence() const int ImageSequenceReference::frame_for_time( - RationalTime const& time, ErrorStatus* error_status) const + RationalTime const& time, + ErrorStatus* error_status) const { - if (!this->available_range().has_value() || - !this->available_range().value().contains(time)) + if (!this->available_range().has_value() + || !this->available_range().value().contains(time)) { if (error_status) { @@ -94,7 +95,8 @@ ImageSequenceReference::frame_for_time( std::string ImageSequenceReference::target_url_for_image_number( - int image_number, ErrorStatus* error_status) const + int image_number, + ErrorStatus* error_status) const { if (_rate == 0) { @@ -107,8 +109,8 @@ ImageSequenceReference::target_url_for_image_number( return std::string(); } else if ( - !this->available_range().has_value() || - this->available_range().value().duration().value() == 0) + !this->available_range().has_value() + || this->available_range().value().duration().value() == 0) { if (error_status) { @@ -147,14 +149,14 @@ ImageSequenceReference::target_url_for_image_number( // If the base does not include a trailing slash, add it std::string path_sep = std::string(); const auto target_url_base_len = _target_url_base.length(); - if (target_url_base_len > 0 && - _target_url_base.compare(target_url_base_len - 1, 1, "/") != 0) + if (target_url_base_len > 0 + && _target_url_base.compare(target_url_base_len - 1, 1, "/") != 0) { path_sep = "/"; } - std::string out_string = _target_url_base + path_sep + _name_prefix + sign + - zero_pad + image_num_string + _name_suffix; + std::string out_string = _target_url_base + path_sep + _name_prefix + sign + + zero_pad + image_num_string + _name_suffix; if (error_status) { *error_status = ErrorStatus(ErrorStatus::OK); @@ -164,7 +166,8 @@ ImageSequenceReference::target_url_for_image_number( RationalTime ImageSequenceReference::presentation_time_for_image_number( - int image_number, ErrorStatus* error_status) const + int image_number, + ErrorStatus* error_status) const { if (image_number >= this->number_of_images_in_sequence()) { @@ -188,13 +191,14 @@ ImageSequenceReference::read_from(Reader& reader) int64_t frame_step_value = 0; int64_t frame_zero_padding_value = 0; - auto result = reader.read("target_url_base", &_target_url_base) && - reader.read("name_prefix", &_name_prefix) && - reader.read("name_suffix", &_name_suffix) && - reader.read("start_frame", &start_frame_value) && - reader.read("frame_step", &frame_step_value) && - reader.read("rate", &_rate) && - reader.read("frame_zero_padding", &frame_zero_padding_value); + auto result = + reader.read("target_url_base", &_target_url_base) + && reader.read("name_prefix", &_name_prefix) + && reader.read("name_suffix", &_name_suffix) + && reader.read("start_frame", &start_frame_value) + && reader.read("frame_step", &frame_step_value) + && reader.read("rate", &_rate) + && reader.read("frame_zero_padding", &frame_zero_padding_value); _start_frame = static_cast(start_frame_value); _frame_step = static_cast(frame_step_value); diff --git a/src/opentimelineio/imageSequenceReference.h b/src/opentimelineio/imageSequenceReference.h index 4642a96a8..3be0ad0ab 100644 --- a/src/opentimelineio/imageSequenceReference.h +++ b/src/opentimelineio/imageSequenceReference.h @@ -97,13 +97,16 @@ class ImageSequenceReference final : public MediaReference int end_frame() const; int number_of_images_in_sequence() const; int frame_for_time( - RationalTime const& time, ErrorStatus* error_status = nullptr) const; + RationalTime const& time, + ErrorStatus* error_status = nullptr) const; std::string target_url_for_image_number( - int image_number, ErrorStatus* error_status = nullptr) const; + int image_number, + ErrorStatus* error_status = nullptr) const; RationalTime presentation_time_for_image_number( - int image_number, ErrorStatus* error_status = nullptr) const; + int image_number, + ErrorStatus* error_status = nullptr) const; protected: virtual ~ImageSequenceReference(); diff --git a/src/opentimelineio/item.cpp b/src/opentimelineio/item.cpp index 76a220b3d..9ac6dfe43 100644 --- a/src/opentimelineio/item.cpp +++ b/src/opentimelineio/item.cpp @@ -75,7 +75,8 @@ Item::visible_range(ErrorStatus* error_status) const if (head_tail.second) { result = TimeRange( - result.start_time(), result.duration() + *head_tail.second); + result.start_time(), + result.duration() + *head_tail.second); } } return result; @@ -107,7 +108,9 @@ Item::range_in_parent(ErrorStatus* error_status) const RationalTime Item::transformed_time( - RationalTime time, Item const* to_item, ErrorStatus* error_status) const + RationalTime time, + Item const* to_item, + ErrorStatus* error_status) const { if (!to_item) { @@ -157,7 +160,9 @@ Item::transformed_time( TimeRange Item::transformed_time_range( - TimeRange time_range, Item const* to_item, ErrorStatus* error_status) const + TimeRange time_range, + Item const* to_item, + ErrorStatus* error_status) const { return TimeRange( transformed_time(time_range.start_time(), to_item, error_status), @@ -167,11 +172,11 @@ Item::transformed_time_range( bool Item::read_from(Reader& reader) { - return reader.read_if_present("source_range", &_source_range) && - reader.read_if_present("effects", &_effects) && - reader.read_if_present("markers", &_markers) && - reader.read_if_present("enabled", &_enabled) && - Parent::read_from(reader); + return reader.read_if_present("source_range", &_source_range) + && reader.read_if_present("effects", &_effects) + && reader.read_if_present("markers", &_markers) + && reader.read_if_present("enabled", &_enabled) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/linearTimeWarp.cpp b/src/opentimelineio/linearTimeWarp.cpp index d2a734eea..8700e3a99 100644 --- a/src/opentimelineio/linearTimeWarp.cpp +++ b/src/opentimelineio/linearTimeWarp.cpp @@ -20,8 +20,8 @@ LinearTimeWarp::~LinearTimeWarp() bool LinearTimeWarp::read_from(Reader& reader) { - return reader.read("time_scalar", &_time_scalar) && - Parent::read_from(reader); + return reader.read("time_scalar", &_time_scalar) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/marker.cpp b/src/opentimelineio/marker.cpp index 8dd924826..0c6b748b1 100644 --- a/src/opentimelineio/marker.cpp +++ b/src/opentimelineio/marker.cpp @@ -22,9 +22,9 @@ Marker::~Marker() bool Marker::read_from(Reader& reader) { - return reader.read_if_present("color", &_color) && - reader.read("marked_range", &_marked_range) && - Parent::read_from(reader); + return reader.read_if_present("color", &_color) + && reader.read("marked_range", &_marked_range) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/mediaReference.cpp b/src/opentimelineio/mediaReference.cpp index b680d1cc5..df75c0f3a 100644 --- a/src/opentimelineio/mediaReference.cpp +++ b/src/opentimelineio/mediaReference.cpp @@ -27,10 +27,11 @@ MediaReference::is_missing_reference() const bool MediaReference::read_from(Reader& reader) { - return reader.read_if_present("available_range", &_available_range) && - reader.read_if_present( - "available_image_bounds", &_available_image_bounds) && - Parent::read_from(reader); + return reader.read_if_present("available_range", &_available_range) + && reader.read_if_present( + "available_image_bounds", + &_available_image_bounds) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/serializableCollection.cpp b/src/opentimelineio/serializableCollection.cpp index 12dc8d07e..d1d9f662b 100644 --- a/src/opentimelineio/serializableCollection.cpp +++ b/src/opentimelineio/serializableCollection.cpp @@ -47,7 +47,9 @@ SerializableCollection::insert_child(int index, SerializableObject* child) bool SerializableCollection::set_child( - int index, SerializableObject* child, ErrorStatus* error_status) + int index, + SerializableObject* child, + ErrorStatus* error_status) { index = adjusted_vector_index(index, _children); if (index < 0 || index >= int(_children.size())) diff --git a/src/opentimelineio/serializableObject.cpp b/src/opentimelineio/serializableObject.cpp index bce6a89de..dfad434a8 100644 --- a/src/opentimelineio/serializableObject.cpp +++ b/src/opentimelineio/serializableObject.cpp @@ -114,38 +114,36 @@ SerializableObject::is_unknown_schema() const std::string SerializableObject::to_json_string( - ErrorStatus* error_status, - const schema_version_map* schema_version_targets, - int indent -) const + ErrorStatus* error_status, + const schema_version_map* schema_version_targets, + int indent) const { return serialize_json_to_string( - any(Retainer<>(this)), + any(Retainer<>(this)), schema_version_targets, error_status, - indent - ); + indent); } bool SerializableObject::to_json_file( - std::string const& file_name, - ErrorStatus* error_status, + std::string const& file_name, + ErrorStatus* error_status, const schema_version_map* schema_version_targets, - int indent) const + int indent) const { return serialize_json_to_file( any(Retainer<>(this)), file_name, schema_version_targets, error_status, - indent - ); + indent); } SerializableObject* SerializableObject::from_json_string( - std::string const& input, ErrorStatus* error_status) + std::string const& input, + ErrorStatus* error_status) { any dest; @@ -172,7 +170,8 @@ SerializableObject::from_json_string( SerializableObject* SerializableObject::from_json_file( - std::string const& file_name, ErrorStatus* error_status) + std::string const& file_name, + ErrorStatus* error_status) { any dest; @@ -244,7 +243,8 @@ SerializableObject::_managed_release() void SerializableObject::install_external_keepalive_monitor( - std::function monitor, bool apply_now) + std::function monitor, + bool apply_now) { { std::lock_guard lock(_mutex); diff --git a/src/opentimelineio/serializableObject.h b/src/opentimelineio/serializableObject.h index 811e7e55d..ee72d8d94 100644 --- a/src/opentimelineio/serializableObject.h +++ b/src/opentimelineio/serializableObject.h @@ -45,23 +45,23 @@ class SerializableObject */ bool possibly_delete(); - bool - to_json_file( - std::string const& file_name, - ErrorStatus* error_status = nullptr, + bool to_json_file( + std::string const& file_name, + ErrorStatus* error_status = nullptr, const schema_version_map* target_family_label_spec = nullptr, - int indent = 4) const; + int indent = 4) const; - std::string - to_json_string( - ErrorStatus* error_status = nullptr, - const schema_version_map* target_family_label_spec = nullptr, - int indent = 4) const; + std::string to_json_string( + ErrorStatus* error_status = nullptr, + const schema_version_map* target_family_label_spec = nullptr, + int indent = 4) const; static SerializableObject* from_json_file( - std::string const& file_name, ErrorStatus* error_status = nullptr); + std::string const& file_name, + ErrorStatus* error_status = nullptr); static SerializableObject* from_json_string( - std::string const& input, ErrorStatus* error_status = nullptr); + std::string const& input, + ErrorStatus* error_status = nullptr); bool is_equivalent_to(SerializableObject const& other) const; @@ -149,10 +149,10 @@ class SerializableObject _error(ErrorStatus( ErrorStatus::TYPE_MISMATCH, std::string( - "Expected object of type " + - fwd_type_name_for_error_message(typeid(T)) + - "; read type " + fwd_type_name_for_error_message(so) + - " instead"))); + "Expected object of type " + + fwd_type_name_for_error_message(typeid(T)) + + "; read type " + fwd_type_name_for_error_message(so) + + " instead"))); return false; } @@ -191,7 +191,10 @@ class SerializableObject { int line_number = line_number_for_object[e.first]; Reader::_fix_reference_ids( - e.second, error_function, *this, line_number); + e.second, + error_function, + *this, + line_number); Reader r(e.second, error_function, e.first, line_number); e.first->read_from(r); } @@ -382,7 +385,7 @@ class SerializableObject _Resolver&, int line_number); - Reader(Reader const&) = delete; + Reader(Reader const&) = delete; Reader operator=(Reader const&) = delete; AnyDictionary _dict; @@ -401,10 +404,10 @@ class SerializableObject { public: static bool write_root( - any const& value, - class Encoder& encoder, - const schema_version_map* downgrade_version_manifest=nullptr, - ErrorStatus* error_status = nullptr); + any const& value, + class Encoder& encoder, + const schema_version_map* downgrade_version_manifest = nullptr, + ErrorStatus* error_status = nullptr); void write(std::string const& key, bool value); void write(std::string const& key, int64_t value); @@ -513,11 +516,10 @@ class SerializableObject ///@} Writer( - class Encoder& encoder, - const schema_version_map* downgrade_version_manifest - ) - : _encoder(encoder), - _downgrade_version_manifest(downgrade_version_manifest) + class Encoder& encoder, + const schema_version_map* downgrade_version_manifest) + : _encoder(encoder) + , _downgrade_version_manifest(downgrade_version_manifest) { _build_dispatch_tables(); @@ -525,7 +527,7 @@ class SerializableObject ~Writer(); - Writer(Writer const&) = delete; + Writer(Writer const&) = delete; Writer operator=(Writer const&) = delete; void _build_dispatch_tables(); @@ -537,7 +539,9 @@ class SerializableObject bool _any_equals(any const& lhs, any const& rhs); std::string _no_key; - std::unordered_map> + std::unordered_map< + std::type_info const*, + std::function> _write_dispatch_table; std::unordered_map< std::type_info const*, @@ -546,13 +550,14 @@ class SerializableObject std::unordered_map> _write_dispatch_table_by_name; - std::unordered_map _id_for_object; - std::unordered_map _next_id_for_type; + std::unordered_map + _id_for_object; + std::unordered_map _next_id_for_type; - Writer* _child_writer = nullptr; + Writer* _child_writer = nullptr; CloningEncoder* _child_cloning_encoder = nullptr; - class Encoder& _encoder; + class Encoder& _encoder; const schema_version_map* _downgrade_version_manifest; friend class SerializableObject; }; @@ -624,7 +629,7 @@ class SerializableObject virtual bool _is_deletable(); private: - SerializableObject(SerializableObject const&) = delete; + SerializableObject(SerializableObject const&) = delete; SerializableObject& operator=(SerializableObject const&) = delete; template friend struct Retainer; @@ -645,7 +650,8 @@ class SerializableObject }; void install_external_keepalive_monitor( - std::function monitor, bool apply_now); + std::function monitor, + bool apply_now); int current_ref_count() const; diff --git a/src/opentimelineio/serializableObjectWithMetadata.cpp b/src/opentimelineio/serializableObjectWithMetadata.cpp index dc2a9b97a..d08d3b081 100644 --- a/src/opentimelineio/serializableObjectWithMetadata.cpp +++ b/src/opentimelineio/serializableObjectWithMetadata.cpp @@ -6,7 +6,8 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { SerializableObjectWithMetadata::SerializableObjectWithMetadata( - std::string const& name, AnyDictionary const& metadata) + std::string const& name, + AnyDictionary const& metadata) : _name(name) , _metadata(metadata) {} @@ -17,9 +18,9 @@ SerializableObjectWithMetadata::~SerializableObjectWithMetadata() bool SerializableObjectWithMetadata::read_from(Reader& reader) { - return reader.read_if_present("metadata", &_metadata) && - reader.read_if_present("name", &_name) && - SerializableObject::read_from(reader); + return reader.read_if_present("metadata", &_metadata) + && reader.read_if_present("name", &_name) + && SerializableObject::read_from(reader); } void diff --git a/src/opentimelineio/serialization.cpp b/src/opentimelineio/serialization.cpp index fc9f29dcd..32f107deb 100644 --- a/src/opentimelineio/serialization.cpp +++ b/src/opentimelineio/serialization.cpp @@ -1,11 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Contributors to the OpenTimelineIO project +#include "opentimelineio/serialization.h" #include "errorStatus.h" #include "nonstd/optional.hpp" -#include "opentimelineio/serializableObject.h" -#include "opentimelineio/serialization.h" #include "opentimelineio/anyDictionary.h" +#include "opentimelineio/serializableObject.h" #include "opentimelineio/unknownSchema.h" #include "stringUtils.h" #include @@ -98,18 +98,18 @@ class Encoder class CloningEncoder : public Encoder { public: - enum class ResultObjectPolicy { + enum class ResultObjectPolicy + { CloneBackToSerializableObject = 0, - MathTypesConcreteAnyDictionaryResult, + MathTypesConcreteAnyDictionaryResult, OnlyAnyDictionary, }; CloningEncoder( - CloningEncoder::ResultObjectPolicy result_object_policy, - const schema_version_map* schema_version_targets = nullptr - ) : - _result_object_policy(result_object_policy), - _downgrade_version_manifest(schema_version_targets) + CloningEncoder::ResultObjectPolicy result_object_policy, + const schema_version_map* schema_version_targets = nullptr) + : _result_object_policy(result_object_policy) + , _downgrade_version_manifest(schema_version_targets) { using namespace std::placeholders; _error_function = std::bind(&CloningEncoder::_error, this, _1); @@ -117,8 +117,7 @@ class CloningEncoder : public Encoder virtual ~CloningEncoder() {} - virtual bool - encoding_to_anydict() override + virtual bool encoding_to_anydict() override { return (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary); } @@ -166,7 +165,6 @@ class CloningEncoder : public Encoder top.array.emplace_back(newstack); } } - } void _store(any&& a) @@ -202,111 +200,105 @@ class CloningEncoder : public Encoder void write_value(std::string const& value) override { _store(any(value)); } void write_value(double value) override { _store(any(value)); } - void - write_value(RationalTime const& value) override - { - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + void write_value(RationalTime const& value) override + { + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { AnyDictionary result = { - {"OTIO_SCHEMA", "RationalTime.1"}, - {"value", value.value()}, - {"rate", value.rate()}, + { "OTIO_SCHEMA", "RationalTime.1" }, + { "value", value.value() }, + { "rate", value.rate() }, }; _store(any(std::move(result))); - } - else + } + else { - _store(any(value)); + _store(any(value)); } } - void - write_value(TimeRange const& value) override + void write_value(TimeRange const& value) override { - - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { AnyDictionary result = { - {"OTIO_SCHEMA", "TimeRange.1"}, - {"duration", value.duration()}, - {"start_time", value.start_time()}, + { "OTIO_SCHEMA", "TimeRange.1" }, + { "duration", value.duration() }, + { "start_time", value.start_time() }, }; _store(any(std::move(result))); - } - else - { - _store(any(value)); } - + else + { + _store(any(value)); + } } - void - write_value(TimeTransform const& value) override + void write_value(TimeTransform const& value) override { - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { - AnyDictionary result { - {"OTIO_SCHEMA", "TimeTransform.1"}, - {"offset", value.offset()}, - {"rate", value.rate()}, - {"scale", value.scale()}, + AnyDictionary result{ + { "OTIO_SCHEMA", "TimeTransform.1" }, + { "offset", value.offset() }, + { "rate", value.rate() }, + { "scale", value.scale() }, }; _store(any(std::move(result))); - } - else + } + else { - _store(any(value)); + _store(any(value)); } } - void - write_value(SerializableObject::ReferenceId value) override + void write_value(SerializableObject::ReferenceId value) override { - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { - AnyDictionary result { - {"OTIO_SCHEMA", "SerializableObjectRef.1"}, - {"id", value.id.c_str()}, + AnyDictionary result{ + { "OTIO_SCHEMA", "SerializableObjectRef.1" }, + { "id", value.id.c_str() }, }; _store(any(std::move(result))); - } - else + } + else { - _store(any(value)); + _store(any(value)); } - _store(any(value)); + _store(any(value)); } - - void - write_value(Imath::V2d const& value) + + void write_value(Imath::V2d const& value) { - - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { - AnyDictionary result { - {"OTIO_SCHEMA", "V2d.1"}, - {"x", value.x}, - {"y", value.y}, + AnyDictionary result{ + { "OTIO_SCHEMA", "V2d.1" }, + { "x", value.x }, + { "y", value.y }, }; _store(any(std::move(result))); } - else + else { - _store(any(value)); + _store(any(value)); } - } - void - write_value(Imath::Box2d const& value) override + void write_value(Imath::Box2d const& value) override { - if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) + if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary) { - AnyDictionary result { - {"OTIO_SCHEMA", "Box2d.1"}, - {"min", value.min}, - {"max", value.max}, + AnyDictionary result{ + { "OTIO_SCHEMA", "Box2d.1" }, + { "min", value.min }, + { "max", value.max }, }; _store(any(std::move(result))); - } else { - _store(any(value)); + } + else + { + _store(any(value)); } } // @} @@ -372,8 +364,7 @@ class CloningEncoder : public Encoder if (_stack.empty()) { _internal_error( - "Encoder::end_object() called without matching start_object()" - ); + "Encoder::end_object() called without matching start_object()"); return; } @@ -390,16 +381,13 @@ class CloningEncoder : public Encoder /* * Convert back to SerializableObject* right here. */ - if ( - _result_object_policy - == ResultObjectPolicy::CloneBackToSerializableObject - ) + if (_result_object_policy + == ResultObjectPolicy::CloneBackToSerializableObject) { SerializableObject::Reader reader( - top.dict, + top.dict, _error_function, - nullptr - ); + nullptr); _stack.pop_back(); _store(reader._decode(_resolver)); @@ -409,10 +397,8 @@ class CloningEncoder : public Encoder AnyDictionary m; m.swap(top.dict); - if ( - (_downgrade_version_manifest != nullptr) - && (!_downgrade_version_manifest->empty()) - ) + if ((_downgrade_version_manifest != nullptr) + && (!_downgrade_version_manifest->empty())) { _downgrade_dictionary(m); } @@ -435,7 +421,6 @@ class CloningEncoder : public Encoder std::string cur_key; }; - void _internal_error(std::string const& err_msg) { _error(ErrorStatus(ErrorStatus::INTERNAL_ERROR, err_msg)); @@ -446,10 +431,7 @@ class CloningEncoder : public Encoder ResultObjectPolicy _result_object_policy; const schema_version_map* _downgrade_version_manifest = nullptr; - void - _downgrade_dictionary( - AnyDictionary& m - ) + void _downgrade_dictionary(AnyDictionary& m) { std::string schema_string = ""; @@ -458,22 +440,21 @@ class CloningEncoder : public Encoder return; } - const auto sep = schema_string.rfind('.'); + const auto sep = schema_string.rfind('.'); const std::string& schema_name = schema_string.substr(0, sep); - const auto dg_version_it = _downgrade_version_manifest->find( - schema_name - ); + const auto dg_version_it = + _downgrade_version_manifest->find(schema_name); if (dg_version_it == _downgrade_version_manifest->end()) { return; } - const std::string& schema_vers = schema_string.substr(sep+1); - int current_version = -1; + const std::string& schema_vers = schema_string.substr(sep + 1); + int current_version = -1; - if (!schema_vers.empty()) + if (!schema_vers.empty()) { current_version = std::stoi(schema_vers); } @@ -481,45 +462,37 @@ class CloningEncoder : public Encoder // @TODO: is 0 a legitimate schema version? if (current_version < 0) { - _internal_error( - string_printf( - "Could not parse version number from Schema" - " string: %s", - schema_string.c_str() - ) - ); + _internal_error(string_printf( + "Could not parse version number from Schema" + " string: %s", + schema_string.c_str())); return; } const int target_version = static_cast(dg_version_it->second); - const auto& type_rec = ( - TypeRegistry::instance()._find_type_record(schema_name) - ); + const auto& type_rec = + (TypeRegistry::instance()._find_type_record(schema_name)); - while (current_version > target_version) + while (current_version > target_version) { - const auto& next_dg_fn = ( - type_rec->downgrade_functions.find(current_version) - ); + const auto& next_dg_fn = + (type_rec->downgrade_functions.find(current_version)); - if (next_dg_fn == type_rec->downgrade_functions.end()) + if (next_dg_fn == type_rec->downgrade_functions.end()) { - _internal_error( - string_printf( - "No downgrader function available for " - "going from version %d to version %d.", - current_version, - target_version - ) - ); + _internal_error(string_printf( + "No downgrader function available for " + "going from version %d to version %d.", + current_version, + target_version)); return; } // apply it next_dg_fn->second(&m); - current_version --; + current_version--; } m["OTIO_SCHEMA"] = schema_name + "." + std::to_string(current_version); @@ -664,8 +637,8 @@ template bool _simple_any_comparison(any const& lhs, any const& rhs) { - return lhs.type() == typeid(T) && rhs.type() == typeid(T) && - any_cast(lhs) == any_cast(rhs); + return lhs.type() == typeid(T) && rhs.type() == typeid(T) + && any_cast(lhs) == any_cast(rhs); } template <> @@ -679,9 +652,9 @@ template <> bool _simple_any_comparison(any const& lhs, any const& rhs) { - return lhs.type() == typeid(char const*) && - rhs.type() == typeid(char const*) && - !strcmp(any_cast(lhs), any_cast(rhs)); + return lhs.type() == typeid(char const*) + && rhs.type() == typeid(char const*) + && !strcmp(any_cast(lhs), any_cast(rhs)); } void @@ -777,8 +750,8 @@ SerializableObject::Writer::_build_dispatch_tables() bool SerializableObject::Writer::_any_dict_equals(any const& lhs, any const& rhs) { - if (lhs.type() != typeid(AnyDictionary) || - rhs.type() != typeid(AnyDictionary)) + if (lhs.type() != typeid(AnyDictionary) + || rhs.type() != typeid(AnyDictionary)) { return false; } @@ -795,8 +768,8 @@ SerializableObject::Writer::_any_dict_equals(any const& lhs, any const& rhs) return false; } - if (l_it.first != r_it->first || - !_any_equals(l_it.second, r_it->second)) + if (l_it.first != r_it->first + || !_any_equals(l_it.second, r_it->second)) { return false; } @@ -841,11 +814,10 @@ SerializableObject::Writer::_any_equals(any const& lhs, any const& rhs) bool SerializableObject::Writer::write_root( - any const& value, - Encoder& encoder, + any const& value, + Encoder& encoder, const schema_version_map* schema_version_targets, - ErrorStatus* error_status -) + ErrorStatus* error_status) { Writer w(encoder, schema_version_targets); w.write(w._no_key, value); @@ -884,7 +856,8 @@ SerializableObject::Writer::write(std::string const& key, double value) void SerializableObject::Writer::write( - std::string const& key, std::string const& value) + std::string const& key, + std::string const& value) { _encoder_write_key(key); _encoder.write_value(value); @@ -906,7 +879,8 @@ SerializableObject::Writer::write(std::string const& key, TimeRange value) void SerializableObject::Writer::write( - std::string const& key, optional value) + std::string const& key, + optional value) { _encoder_write_key(key); value ? _encoder.write_value(*value) : _encoder.write_null_value(); @@ -914,7 +888,8 @@ SerializableObject::Writer::write( void SerializableObject::Writer::write( - std::string const& key, optional value) + std::string const& key, + optional value) { _encoder_write_key(key); value ? _encoder.write_value(*value) : _encoder.write_null_value(); @@ -922,17 +897,15 @@ SerializableObject::Writer::write( void SerializableObject::Writer::write( - std::string const& key, optional value) + std::string const& key, + optional value) { _encoder_write_key(key); value ? _encoder.write_value(*value) : _encoder.write_null_value(); } void -SerializableObject::Writer::write( - std::string const& key, - TimeTransform value -) +SerializableObject::Writer::write(std::string const& key, TimeTransform value) { _encoder_write_key(key); _encoder.write_value(value); @@ -940,10 +913,9 @@ SerializableObject::Writer::write( void SerializableObject::Writer::write( - std::string const& key, - SerializableObject const* value -) -{ + std::string const& key, + SerializableObject const* value) +{ _encoder_write_key(key); if (!value) { @@ -980,51 +952,51 @@ SerializableObject::Writer::write( _next_id_for_type[schema_type_name] = 0; } - std::string next_id = schema_type_name + "-" + - std::to_string(++_next_id_for_type[schema_type_name]); + std::string next_id = + schema_type_name + "-" + + std::to_string(++_next_id_for_type[schema_type_name]); _id_for_object[value] = next_id; // detect if downgrading needs to happen - const std::string& schema_name = value->schema_name(); - int schema_version = value->schema_version(); + const std::string& schema_name = value->schema_name(); + int schema_version = value->schema_version(); any downgraded = {}; // if there is a manifest & the encoder is not converting to AnyDictionary - if ( - (_downgrade_version_manifest != nullptr) - && (!_downgrade_version_manifest->empty()) - && (!_encoder.encoding_to_anydict()) - ) + if ((_downgrade_version_manifest != nullptr) + && (!_downgrade_version_manifest->empty()) + && (!_encoder.encoding_to_anydict())) { - const auto& target_version_it = _downgrade_version_manifest->find( - schema_name - ); + const auto& target_version_it = + _downgrade_version_manifest->find(schema_name); // ...and if that downgrade manifest specifies a target version for // this schema if (target_version_it != _downgrade_version_manifest->end()) { - const int target_version = static_cast(target_version_it->second); + const int target_version = + static_cast(target_version_it->second); // and the current_version is greater than the target version - if (schema_version > target_version) + if (schema_version > target_version) { if (_child_writer == nullptr) { _child_cloning_encoder = new CloningEncoder( - CloningEncoder::ResultObjectPolicy::OnlyAnyDictionary, - _downgrade_version_manifest - ); + CloningEncoder::ResultObjectPolicy::OnlyAnyDictionary, + _downgrade_version_manifest); _child_writer = new Writer(*_child_cloning_encoder, {}); } - else { + else + { _child_cloning_encoder->_stack.clear(); } _child_writer->write(_child_writer->_no_key, value); - if (_child_cloning_encoder->has_errored(&_encoder._error_status)) + if (_child_cloning_encoder->has_errored( + &_encoder._error_status)) { return; } @@ -1041,11 +1013,9 @@ SerializableObject::Writer::write( // _original_schema_name and _original_schema_version attributes if (UnknownSchema const* us = dynamic_cast(value)) { - schema_str = ( - us->_original_schema_name - + "." - + std::to_string(us->_original_schema_version) - ); + schema_str = + (us->_original_schema_name + "." + + std::to_string(us->_original_schema_version)); } else { @@ -1064,7 +1034,7 @@ SerializableObject::Writer::write( // anydictionary or the SerializableObject if (!(downgraded.empty())) { - for (const auto& kv : any_cast(downgraded)) + for (const auto& kv: any_cast(downgraded)) { this->write(kv.first, kv.second); } @@ -1103,7 +1073,8 @@ SerializableObject::Writer::write(std::string const& key, Imath::Box2d value) void SerializableObject::Writer::write( - std::string const& key, AnyDictionary const& value) + std::string const& key, + AnyDictionary const& value) { _encoder_write_key(key); @@ -1119,7 +1090,8 @@ SerializableObject::Writer::write( void SerializableObject::Writer::write( - std::string const& key, AnyVector const& value) + std::string const& key, + AnyVector const& value) { _encoder_write_key(key); @@ -1134,9 +1106,7 @@ SerializableObject::Writer::write( } void -SerializableObject::Writer::write( - std::string const& key, - any const& value) +SerializableObject::Writer::write(std::string const& key, any const& value) { std::type_info const& type = value.type(); @@ -1158,12 +1128,7 @@ SerializableObject::Writer::write( const auto& backup_e = _write_dispatch_table_by_name.find(type.name()); if (backup_e != _write_dispatch_table_by_name.end()) { - e = _write_dispatch_table.insert( - { - &type, - backup_e->second - } - ).first; + e = _write_dispatch_table.insert({ &type, backup_e->second }).first; } } @@ -1175,10 +1140,9 @@ SerializableObject::Writer::write( { std::string s; std::string bad_type_name = - (type == typeid(UnknownType)) - ? type_name_for_error_message( - any_cast(value).type_name) - : type_name_for_error_message(type); + (type == typeid(UnknownType)) ? type_name_for_error_message( + any_cast(value).type_name) + : type_name_for_error_message(type); if (&key != &_no_key) { @@ -1207,9 +1171,8 @@ SerializableObject::is_equivalent_to(SerializableObject const& other) const return false; } - const auto policy = ( - CloningEncoder::ResultObjectPolicy::MathTypesConcreteAnyDictionaryResult - ); + const auto policy = (CloningEncoder::ResultObjectPolicy:: + MathTypesConcreteAnyDictionaryResult); CloningEncoder e1(policy), e2(policy); SerializableObject::Writer w1(e1, {}); @@ -1219,16 +1182,15 @@ SerializableObject::is_equivalent_to(SerializableObject const& other) const w2.write(w2._no_key, any(Retainer<>(&other))); return ( - !e1.has_errored() && !e2.has_errored() && - w1._any_equals(e1._root, e2._root)); + !e1.has_errored() && !e2.has_errored() + && w1._any_equals(e1._root, e2._root)); } SerializableObject* SerializableObject::clone(ErrorStatus* error_status) const { CloningEncoder e( - CloningEncoder::ResultObjectPolicy::CloneBackToSerializableObject - ); + CloningEncoder::ResultObjectPolicy::CloneBackToSerializableObject); SerializableObject::Writer w(e, {}); w.write(w._no_key, any(Retainer<>(this))); @@ -1252,15 +1214,13 @@ SerializableObject::clone(ErrorStatus* error_status) const : nullptr; } - // to json_string std::string serialize_json_to_string( - const any& value, + const any& value, const schema_version_map* schema_version_targets, - ErrorStatus* error_status, - int indent -) + ErrorStatus* error_status, + int indent) { OTIO_rapidjson::StringBuffer output_string_buffer; @@ -1279,29 +1239,25 @@ serialize_json_to_string( JSONEncoder json_encoder(json_writer); - if ( - !SerializableObject::Writer::write_root( - value, - json_encoder, - schema_version_targets, - error_status - ) - ) + if (!SerializableObject::Writer::write_root( + value, + json_encoder, + schema_version_targets, + error_status)) { return std::string(); } return std::string(output_string_buffer.GetString()); - } bool serialize_json_to_file( - any const& value, - std::string const& file_name, + any const& value, + std::string const& file_name, const schema_version_map* schema_version_targets, - ErrorStatus* error_status, - int indent) + ErrorStatus* error_status, + int indent) { #if defined(_WINDOWS) @@ -1310,7 +1266,7 @@ serialize_json_to_file( std::vector wchars(wlen); MultiByteToWideChar(CP_UTF8, 0, file_name.c_str(), -1, wchars.data(), wlen); std::ofstream os(wchars.data()); -#else // _WINDOWS +#else // _WINDOWS std::ofstream os(file_name); #endif // _WINDOWS @@ -1342,19 +1298,17 @@ serialize_json_to_file( } status = SerializableObject::Writer::write_root( - value, + value, json_encoder, schema_version_targets, - error_status - ); + error_status); return status; } - SerializableObject::Writer::~Writer() { - if (_child_writer) + if (_child_writer) { delete _child_writer; } diff --git a/src/opentimelineio/serialization.h b/src/opentimelineio/serialization.h index aa4772435..2fce4dbf6 100644 --- a/src/opentimelineio/serialization.h +++ b/src/opentimelineio/serialization.h @@ -5,8 +5,8 @@ #include "opentimelineio/any.h" #include "opentimelineio/errorStatus.h" -#include "opentimelineio/version.h" #include "opentimelineio/typeRegistry.h" +#include "opentimelineio/version.h" #include #include @@ -14,22 +14,17 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { - -std::string -serialize_json_to_string( - const any& value, +std::string serialize_json_to_string( + const any& value, const schema_version_map* schema_version_targets = nullptr, - ErrorStatus* error_status = nullptr, - int indent = 4 -); + ErrorStatus* error_status = nullptr, + int indent = 4); -bool -serialize_json_to_file( - const any& value, - std::string const& file_name, +bool serialize_json_to_file( + const any& value, + std::string const& file_name, const schema_version_map* schema_version_targets = nullptr, - ErrorStatus* error_status = nullptr, - int indent = 4 -); + ErrorStatus* error_status = nullptr, + int indent = 4); }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/stack.cpp b/src/opentimelineio/stack.cpp index e86c1953f..767e88826 100644 --- a/src/opentimelineio/stack.cpp +++ b/src/opentimelineio/stack.cpp @@ -80,8 +80,8 @@ Stack::range_of_all_children(ErrorStatus* error_status) const } TimeRange -Stack::trimmed_range_of_child_at_index( - int index, ErrorStatus* error_status) const +Stack::trimmed_range_of_child_at_index(int index, ErrorStatus* error_status) + const { auto range = range_of_child_at_index(index, error_status); if (is_error(error_status) || !source_range()) @@ -91,7 +91,8 @@ Stack::trimmed_range_of_child_at_index( const TimeRange sr = *source_range(); return TimeRange( - sr.start_time(), std::min(range.duration(), sr.duration())); + sr.start_time(), + std::min(range.duration(), sr.duration())); } TimeRange diff --git a/src/opentimelineio/stack.h b/src/opentimelineio/stack.h index 6c88561f3..87410adb1 100644 --- a/src/opentimelineio/stack.h +++ b/src/opentimelineio/stack.h @@ -29,9 +29,11 @@ class Stack : public Composition std::vector const& markers = std::vector()); virtual TimeRange range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; virtual TimeRange trimmed_range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; virtual TimeRange available_range(ErrorStatus* error_status = nullptr) const; diff --git a/src/opentimelineio/stackAlgorithm.cpp b/src/opentimelineio/stackAlgorithm.cpp index 01f908e1c..6800cbc2d 100644 --- a/src/opentimelineio/stackAlgorithm.cpp +++ b/src/opentimelineio/stackAlgorithm.cpp @@ -51,7 +51,8 @@ _flatten_next_item( else { auto result = range_track_map.emplace( - track, track->range_of_all_children(error_status)); + track, + track->range_of_all_children(error_status)); if (is_error(error_status)) { return; @@ -155,7 +156,12 @@ flatten_stack(Stack* in_stack, ErrorStatus* error_status) RangeTrackMap range_track_map; _flatten_next_item( - range_track_map, flat_track, tracks, -1, nullopt, error_status); + range_track_map, + flat_track, + tracks, + -1, + nullopt, + error_status); return flat_track; } @@ -167,7 +173,12 @@ flatten_stack(std::vector const& tracks, ErrorStatus* error_status) RangeTrackMap range_track_map; _flatten_next_item( - range_track_map, flat_track, tracks, -1, nullopt, error_status); + range_track_map, + flat_track, + tracks, + -1, + nullopt, + error_status); return flat_track; } }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/stackAlgorithm.h b/src/opentimelineio/stackAlgorithm.h index cd89627fe..7fb22af8a 100644 --- a/src/opentimelineio/stackAlgorithm.h +++ b/src/opentimelineio/stackAlgorithm.h @@ -11,6 +11,7 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { Track* flatten_stack(Stack* in_stack, ErrorStatus* error_status = nullptr); Track* flatten_stack( - std::vector const& tracks, ErrorStatus* error_status = nullptr); + std::vector const& tracks, + ErrorStatus* error_status = nullptr); }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/stringUtils.cpp b/src/opentimelineio/stringUtils.cpp index 46dae43e5..f84d97765 100644 --- a/src/opentimelineio/stringUtils.cpp +++ b/src/opentimelineio/stringUtils.cpp @@ -18,7 +18,8 @@ cxxabi_type_name_for_error_mesage(const char* name) int status = -4; // some arbitrary value to eliminate the compiler warning std::unique_ptr res{ - abi::__cxa_demangle(name, NULL, NULL, &status), std::free + abi::__cxa_demangle(name, NULL, NULL, &status), + std::free }; return (status == 0) ? res.get() : name; diff --git a/src/opentimelineio/timeline.cpp b/src/opentimelineio/timeline.cpp index 2afdcff3f..6c9e9b2fc 100644 --- a/src/opentimelineio/timeline.cpp +++ b/src/opentimelineio/timeline.cpp @@ -27,9 +27,9 @@ Timeline::set_tracks(Stack* stack) bool Timeline::read_from(Reader& reader) { - return reader.read("tracks", &_tracks) && - reader.read_if_present("global_start_time", &_global_start_time) && - Parent::read_from(reader); + return reader.read("tracks", &_tracks) + && reader.read_if_present("global_start_time", &_global_start_time) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/timeline.h b/src/opentimelineio/timeline.h index 6f80c697b..7c90120fb 100644 --- a/src/opentimelineio/timeline.h +++ b/src/opentimelineio/timeline.h @@ -53,7 +53,8 @@ class Timeline : public SerializableObjectWithMetadata } TimeRange range_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const + Composable const* child, + ErrorStatus* error_status = nullptr) const { return _tracks.value->range_of_child(child, error_status); } @@ -105,7 +106,9 @@ Timeline::children_if( bool shallow_search) const { return _tracks.value->children_if( - error_status, search_range, shallow_search); + error_status, + search_range, + shallow_search); } }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/track.cpp b/src/opentimelineio/track.cpp index 44e027666..ef90f2ab6 100644 --- a/src/opentimelineio/track.cpp +++ b/src/opentimelineio/track.cpp @@ -109,8 +109,8 @@ Track::range_of_child_at_index(int index, ErrorStatus* error_status) const } TimeRange -Track::trimmed_range_of_child_at_index( - int index, ErrorStatus* error_status) const +Track::trimmed_range_of_child_at_index(int index, ErrorStatus* error_status) + const { auto child_range = range_of_child_at_index(index, error_status); if (is_error(error_status)) @@ -165,8 +165,8 @@ Track::available_range(ErrorStatus* error_status) const } std::pair, optional> -Track::handles_of_child( - Composable const* child, ErrorStatus* error_status) const +Track::handles_of_child(Composable const* child, ErrorStatus* error_status) + const { optional head, tail; auto neighbors = neighbors_of(child, error_status); @@ -272,7 +272,8 @@ Track::range_of_all_children(ErrorStatus* error_status) const else if (auto item = dynamic_retainer_cast(child)) { auto last_range = TimeRange( - last_end_time, item->trimmed_range(error_status).duration()); + last_end_time, + item->trimmed_range(error_status).duration()); result[child] = last_range; last_end_time = last_range.end_time_exclusive(); } diff --git a/src/opentimelineio/track.h b/src/opentimelineio/track.h index ec19cae3b..443c75806 100644 --- a/src/opentimelineio/track.h +++ b/src/opentimelineio/track.h @@ -44,15 +44,18 @@ class Track : public Composition void set_kind(std::string const& kind) { _kind = kind; } virtual TimeRange range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; virtual TimeRange trimmed_range_of_child_at_index( - int index, ErrorStatus* error_status = nullptr) const; + int index, + ErrorStatus* error_status = nullptr) const; virtual TimeRange available_range(ErrorStatus* error_status = nullptr) const; virtual std::pair, optional> handles_of_child( - Composable const* child, ErrorStatus* error_status = nullptr) const; + Composable const* child, + ErrorStatus* error_status = nullptr) const; std::pair, Retainer> neighbors_of( Composable const* item, diff --git a/src/opentimelineio/trackAlgorithm.cpp b/src/opentimelineio/trackAlgorithm.cpp index ff3a71ffa..4b6e6e5be 100644 --- a/src/opentimelineio/trackAlgorithm.cpp +++ b/src/opentimelineio/trackAlgorithm.cpp @@ -8,7 +8,9 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { Track* track_trimmed_to_range( - Track* in_track, TimeRange trim_range, ErrorStatus* error_status) + Track* in_track, + TimeRange trim_range, + ErrorStatus* error_status) { Track* new_track = dynamic_cast(in_track->clone(error_status)); if (is_error(error_status) || !new_track) @@ -23,7 +25,8 @@ track_trimmed_to_range( } std::vector children_copy( - new_track->children().begin(), new_track->children().end()); + new_track->children().begin(), + new_track->children().end()); for (size_t i = children_copy.size(); i--;) { diff --git a/src/opentimelineio/trackAlgorithm.h b/src/opentimelineio/trackAlgorithm.h index 5e2fe369c..54ce6d35e 100644 --- a/src/opentimelineio/trackAlgorithm.h +++ b/src/opentimelineio/trackAlgorithm.h @@ -9,6 +9,8 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { Track* track_trimmed_to_range( - Track* in_track, TimeRange trim_range, ErrorStatus* error_status = nullptr); + Track* in_track, + TimeRange trim_range, + ErrorStatus* error_status = nullptr); }} // namespace opentimelineio::OPENTIMELINEIO_VERSION diff --git a/src/opentimelineio/transition.cpp b/src/opentimelineio/transition.cpp index ee19c2360..63be6f76e 100644 --- a/src/opentimelineio/transition.cpp +++ b/src/opentimelineio/transition.cpp @@ -30,10 +30,10 @@ Transition::overlapping() const bool Transition::read_from(Reader& reader) { - return reader.read("in_offset", &_in_offset) && - reader.read("out_offset", &_out_offset) && - reader.read("transition_type", &_transition_type) && - Parent::read_from(reader); + return reader.read("in_offset", &_in_offset) + && reader.read("out_offset", &_out_offset) + && reader.read("transition_type", &_transition_type) + && Parent::read_from(reader); } void diff --git a/src/opentimelineio/typeRegistry.cpp b/src/opentimelineio/typeRegistry.cpp index f75229c3e..725407949 100644 --- a/src/opentimelineio/typeRegistry.cpp +++ b/src/opentimelineio/typeRegistry.cpp @@ -76,7 +76,10 @@ TypeRegistry::TypeRegistry() register_type(); register_type(); register_type_from_existing_type( - "SerializeableCollection", 1, "SerializableCollection", nullptr); + "SerializeableCollection", + 1, + "SerializableCollection", + nullptr); register_type(); register_type(); @@ -114,35 +117,25 @@ TypeRegistry::TypeRegistry() }); // 2->1 - register_downgrade_function( - Clip::Schema::name, - 2, - [](AnyDictionary* d) - { - AnyDictionary mrefs; - std::string active_rkey = ""; + register_downgrade_function(Clip::Schema::name, 2, [](AnyDictionary* d) { + AnyDictionary mrefs; + std::string active_rkey = ""; - if (d->get_if_set("media_references", &mrefs)) + if (d->get_if_set("media_references", &mrefs)) + { + if (d->get_if_set("active_media_reference_key", &active_rkey)) + { + AnyDictionary active_ref; + if (mrefs.get_if_set(active_rkey, &active_ref)) { - if ( - d->get_if_set( - "active_media_reference_key", - &active_rkey - ) - ) - { - AnyDictionary active_ref; - if (mrefs.get_if_set(active_rkey, &active_ref)) - { - (*d)["media_reference"] = active_ref; - } - } + (*d)["media_reference"] = active_ref; } - - d->erase("media_references"); - d->erase("active_media_reference_key"); } - ); + } + + d->erase("media_references"); + d->erase("active_media_reference_key"); + }); } bool @@ -166,7 +159,7 @@ TypeRegistry::register_type( // && existing_tr->schema_version == schema_version // && existing_tr->class_name == class_name // && ( - // existing_tr->create.target() + // existing_tr->create.target() // == create.target() // ) // ) { @@ -200,16 +193,18 @@ TypeRegistry::register_type_from_existing_type( { if (!_find_type_record(schema_name)) { - _type_records[schema_name] = new _TypeRecord{ - r->schema_name, r->schema_version, r->class_name, r->create - }; + _type_records[schema_name] = new _TypeRecord{ r->schema_name, + r->schema_version, + r->class_name, + r->create }; return true; } if (error_status) { *error_status = ErrorStatus( - ErrorStatus::SCHEMA_ALREADY_REGISTERED, schema_name); + ErrorStatus::SCHEMA_ALREADY_REGISTERED, + schema_name); } return false; } @@ -237,11 +232,7 @@ TypeRegistry::register_upgrade_function( if (auto r = _find_type_record(schema_name)) { auto result = r->upgrade_functions.insert( - { - version_to_upgrade_to, - upgrade_function - } - ); + { version_to_upgrade_to, upgrade_function }); return result.second; } @@ -258,11 +249,7 @@ TypeRegistry::register_downgrade_function( if (auto r = _find_type_record(schema_name)) { auto result = r->downgrade_functions.insert( - { - version_to_downgrade_from, - downgrade_function - } - ); + { version_to_downgrade_from, downgrade_function }); return result.second; } @@ -323,8 +310,8 @@ TypeRegistry::_instance_from_schema( { for (const auto& e: type_record->upgrade_functions) { - if (schema_version <= e.first && - e.first <= type_record->schema_version) + if (schema_version <= e.first + && e.first <= type_record->schema_version) { e.second(&dict); } @@ -399,13 +386,13 @@ TypeRegistry::set_type_record( } void -TypeRegistry::type_version_map( - schema_version_map& result) +TypeRegistry::type_version_map(schema_version_map& result) { std::lock_guard lock(_registry_mutex); - for (const auto& pair: _type_records) { - const auto record_ptr = pair.second; + for (const auto& pair: _type_records) + { + const auto record_ptr = pair.second; result[record_ptr->schema_name] = record_ptr->schema_version; } } diff --git a/src/opentimelineio/typeRegistry.h b/src/opentimelineio/typeRegistry.h index 47ec0e14e..2f2e61854 100644 --- a/src/opentimelineio/typeRegistry.h +++ b/src/opentimelineio/typeRegistry.h @@ -9,9 +9,9 @@ #include #include +#include #include #include -#include #include namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { @@ -24,7 +24,8 @@ class AnyDictionary; // @TODO: should we make version an int64_t? That would match what we can // serialize natively, since we only serialize 64 bit signed ints. using schema_version_map = std::unordered_map; -using label_to_schema_version_map = std::unordered_map; +using label_to_schema_version_map = + std::unordered_map; extern const label_to_schema_version_map CORE_VERSION_MAP; @@ -101,7 +102,9 @@ class TypeRegistry std::function upgrade_function) { return register_upgrade_function( - CLASS::schema_name, version_to_upgrade_to, upgrade_function); + CLASS::schema_name, + version_to_upgrade_to, + upgrade_function); } /// Downgrade function from version_to_downgrade_from to @@ -119,7 +122,9 @@ class TypeRegistry std::function upgrade_function) { return register_downgrade_function( - CLASS::schema_name, version_to_upgrade_to, upgrade_function); + CLASS::schema_name, + version_to_upgrade_to, + upgrade_function); } SerializableObject* instance_from_schema( @@ -148,7 +153,7 @@ class TypeRegistry private: TypeRegistry(); - TypeRegistry(TypeRegistry const&) = delete; + TypeRegistry(TypeRegistry const&) = delete; TypeRegistry& operator=(TypeRegistry const&) = delete; class _TypeRecord diff --git a/src/opentimelineio/unknownSchema.cpp b/src/opentimelineio/unknownSchema.cpp index 545d823b6..5ee35bda2 100644 --- a/src/opentimelineio/unknownSchema.cpp +++ b/src/opentimelineio/unknownSchema.cpp @@ -6,7 +6,8 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { UnknownSchema::UnknownSchema( - std::string const& original_schema_name, int original_schema_version) + std::string const& original_schema_name, + int original_schema_version) : _original_schema_name(original_schema_name) , _original_schema_version(original_schema_version) {} diff --git a/src/opentimelineio/unknownSchema.h b/src/opentimelineio/unknownSchema.h index b7736350c..518c8c8be 100644 --- a/src/opentimelineio/unknownSchema.h +++ b/src/opentimelineio/unknownSchema.h @@ -18,7 +18,8 @@ class UnknownSchema : public SerializableObject }; UnknownSchema( - std::string const& original_schema_name, int original_schema_version); + std::string const& original_schema_name, + int original_schema_version); std::string original_schema_name() const noexcept { diff --git a/src/py-opentimelineio/opentimelineio/console/autogen_version_map.py b/src/py-opentimelineio/opentimelineio/console/autogen_version_map.py index a77d3616e..7ab517c70 100644 --- a/src/py-opentimelineio/opentimelineio/console/autogen_version_map.py +++ b/src/py-opentimelineio/opentimelineio/console/autogen_version_map.py @@ -12,13 +12,12 @@ LABEL_MAP_TEMPLATE = """{{ "{label}", - {{ + {{ {sv_map} - }} - }}, + }} }}, // {{next}}""" MAP_ITEM_TEMPLATE = '{indent}{{ "{key}", {value} }},' -INDENT = 12 +INDENT = 10 def _parsed_args():