-
Notifications
You must be signed in to change notification settings - Fork 309
Cxx examples #918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cxx examples #918
Conversation
I've updated the code to use Retainers and added the missing code for Windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very helpful, I've dropped a few notes inline.
Might be an idea to mark this PR as "WIP" until it's ready to land? That's the convention we're using in this repo, in general, when things are being iterated and thought through. |
Rather than the |
Any thoughts about the Python functions each_clip() and deepcopy() for C++? |
each_clip() and deepcopy() both seem handy for c++ use. Maybe a quick sketch and discussion if they should be a topic for a PR for OTIO? (Since deepcopy() is a Pythonism, I'd suggest deep_copy for C++.) |
I've broken out the C++ code for using Python adapters into two separate examples, "python_adapters_child_process.cpp" and "python_adapters_embed.cpp", for using the adapters via child processes and an embedded Python interpreter respectively. I think I prefer the embedding approach, that way there is less environment setup to worry about (making sure otioconvert is in the search path), and there is less platform specific code (child process creation and pipes seem more complicated on Windows). I still need to take a look and see if I can get rid of the temporary files, and the flatten_video_tracks.cpp example is missing a C++ version of deepcopy(). @meshula Have you used CreateProcess() on Windows before? The MSDN documentation says to pass "cmd.exe" in to execute bat files, but I got the error "The system cannot find the file specified.". If I use "C:\windows\system32\cmd.exe" it works OK, but it seems like a bad idea to hard code the path... |
The embedding approach is valid, but it's a whole other can of worms. Not everyone will want to bind Python into their application, because there's so much other environment to set up to make that fully functional. Embedded IS interesting, but so is calling out. CreateProcess with a full path to system32\cmd.exe is actually fine; cmd has been there forever, and is unlikely to move in the foreseeable future. It's like the assumption that we make in expecting to be able to find sh at /bin/sh until the end of time. |
OK, I've changed the example "python_adapters_embed.cpp" to use Python directly without needing temporary files. I did this by converting the timeline into JSON and passing that to/from Python where the adapters are used for file IO. It's a bit more code than before, but it's not too bad and doesn't require any platform specific code. I also looked into deepcopy() and apparently it's just a wrapper around SerializableObject::clone(), so maybe it's not needed for C++. I updated the example "flatten_video_tracks.cpp" to use clone() and it should be complete now. I think that addresses all of the feedback, should I "un-draft" this PR? Or should this also include C++ versions of the rest of the Python examples? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together, @darbyjohnston. Both deepcopy
and each_clip
are based on pythonisms, and yeah -- deep copy() is just exposing the clone
functionality. I wonder if each_clip
would become a C++11 style iterator? Or are those just not good?
The interface for a C++ style iterator is not hard to satisfy; here's a nice overview. https://internalpointers.com/post/writing-custom-iterators-modern-cpp That gives you compatibility with lots of STL features like std::copy, so iterators would be a definite nice-to-have. |
Codecov Report
@@ Coverage Diff @@
## master #918 +/- ##
==========================================
- Coverage 85.96% 85.74% -0.23%
==========================================
Files 184 191 +7
Lines 17892 18085 +193
Branches 1993 2044 +51
==========================================
+ Hits 15381 15507 +126
- Misses 2002 2055 +53
- Partials 509 523 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Un-drafting this since it seems like most of the feedback has been resolved and the other work for Retainers and each_clip() should probably be separate PRs... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks @darbyjohnston!
Fixes #917
This is WIP code to convert the Python examples to C++. I've successfully converted "summarize_timing.py" and started converting "flatten_video_tracks.py". With these changes, and the CMake variable OTIO_CXX_EXAMPLE set to "ON", you can run:
Converting the examples brought up a couple of questions:
Note this code currently only works for Linux/macOS, there is some additional code that needs to be added for Windows.