Skip to content

Commit c51d995

Browse files
authored
More clang format (#2019)
* Added more missing folders to the `make format` rule` * Clang format the tests * Clang format the examples Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
1 parent 05416ab commit c51d995

20 files changed

Lines changed: 1241 additions & 2134 deletions

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ format:
155155
ifndef CLANG_FORMAT_PROG
156156
$(error $(newline)$(ccred)clang-format is not available on $$PATH$(ccend))
157157
endif
158-
$(eval DIRS = src/opentime src/opentimelineio src/opentimelineio/algo)
158+
$(eval DIRS = src/opentime)
159+
$(eval DIRS += src/opentimelineio)
160+
$(eval DIRS += src/opentimelineio/algo)
161+
$(eval DIRS += tests)
162+
$(eval DIRS += examples)
159163
$(eval DIRS += src/py-opentimelineio/opentime-bindings)
160164
$(eval DIRS += src/py-opentimelineio/opentimelineio-bindings)
161165
$(eval FILES_TO_FORMAT = $(wildcard $(addsuffix /*.h, $(DIRS)) $(addsuffix /*.cpp, $(DIRS))))
162-
echo "formatting..." $(FILES_TO_FORMAT)
163166
$(shell clang-format -i -style=file $(FILES_TO_FORMAT))
164167

165168
manifest:

examples/conform.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION_NS;
3232

3333
// Look for media with this name in this folder.
34-
std::string find_matching_media(std::string const& name, std::string const& folder)
34+
std::string
35+
find_matching_media(std::string const& name, std::string const& folder)
3536
{
3637
// This function is an example which searches the file system for matching media.
3738
// A real world studio implementation would likely look in an asset management system
@@ -41,9 +42,9 @@ std::string find_matching_media(std::string const& name, std::string const& fold
4142
// shot = asset_database->find_shot(
4243
// otio::any_cast<std::map<std::string, std::string> >(clip->metadata()["mystudio"])["shotID"]);
4344
// new_media = shot->latest_render("mov");
44-
45+
4546
const auto matches = examples::glob(folder, name + ".*");
46-
47+
4748
if (matches.size() == 0)
4849
{
4950
//std::cout << "DEBUG: No match for clip '" << name << "'" << std::endl;
@@ -55,8 +56,9 @@ std::string find_matching_media(std::string const& name, std::string const& fold
5556
}
5657
else
5758
{
58-
std::cout << "WARNING: " << matches.size() << " matches found for clip '" <<
59-
name << "', using '" << matches[0] << "'";
59+
std::cout << "WARNING: " << matches.size()
60+
<< " matches found for clip '" << name << "', using '"
61+
<< matches[0] << "'";
6062
return matches[0];
6163
}
6264
}
@@ -70,21 +72,22 @@ std::string find_matching_media(std::string const& name, std::string const& fold
7072
// internal reference count. For more details on the usage of Retainers see
7173
// the C++ documentation:
7274
// https://opentimelineio.readthedocs.io/en/latest/cxx/cxx.html
73-
int conform_timeline(
75+
int
76+
conform_timeline(
7477
otio::SerializableObject::Retainer<otio::Timeline> const& timeline,
75-
std::string const& folder)
78+
std::string const& folder)
7679
{
7780
int count = 0;
78-
81+
7982
otio::ErrorStatus error_status;
80-
const auto clips = timeline->find_clips(&error_status);
83+
const auto clips = timeline->find_clips(&error_status);
8184
if (otio::is_error(error_status))
8285
{
8386
examples::print_error(error_status);
8487
exit(1);
8588
}
86-
87-
for (const otio::SerializableObject::Retainer<otio::Clip>& clip : clips)
89+
90+
for (const otio::SerializableObject::Retainer<otio::Clip>& clip: clips)
8891
{
8992
// look for a media file that matches the clip's name
9093
const std::string new_path = find_matching_media(clip->name(), folder);
@@ -96,28 +99,31 @@ int conform_timeline(
9699
// relink to the found path
97100
clip->set_media_reference(new otio::ExternalReference(
98101
"file://" + new_path,
99-
std::nullopt // the available range is unknown without opening the file
100-
));
102+
std::
103+
nullopt // the available range is unknown without opening the file
104+
));
101105
count += 1;
102106
}
103-
107+
104108
return count;
105109
}
106110

107-
int main(int argc, char** argv)
111+
int
112+
main(int argc, char** argv)
108113
{
109114
if (argc != 4)
110115
{
111116
std::cout << "Usage: conform (input) (folder) (output)" << std::endl;
112117
return 1;
113118
}
114-
const std::string input = examples::normalize_path(argv[1]);
119+
const std::string input = examples::normalize_path(argv[1]);
115120
const std::string folder = examples::normalize_path(argv[2]);
116121
const std::string output = examples::normalize_path(argv[3]);
117-
118-
otio::ErrorStatus error_status;
122+
123+
otio::ErrorStatus error_status;
119124
otio::SerializableObject::Retainer<otio::Timeline> timeline(
120-
dynamic_cast<otio::Timeline*>(otio::Timeline::from_json_file(input, &error_status)));
125+
dynamic_cast<otio::Timeline*>(
126+
otio::Timeline::from_json_file(input, &error_status)));
121127
if (!timeline || otio::is_error(error_status))
122128
{
123129
examples::print_error(error_status);
@@ -136,7 +142,8 @@ int main(int argc, char** argv)
136142
examples::print_error(error_status);
137143
exit(1);
138144
}
139-
std::cout << "Saved " << output << " with " << clips.size() << " clips." << std::endl;
140-
145+
std::cout << "Saved " << output << " with " << clips.size() << " clips."
146+
<< std::endl;
147+
141148
return 0;
142149
}

examples/flatten_video_tracks.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,37 @@
1111

1212
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION_NS;
1313

14-
int main(int argc, char** argv)
14+
int
15+
main(int argc, char** argv)
1516
{
1617
if (argc != 3)
1718
{
18-
std::cout << "Usage: flatten_video_tracks (inputpath) (outputpath)" << std::endl;
19+
std::cout << "Usage: flatten_video_tracks (inputpath) (outputpath)"
20+
<< std::endl;
1921
return 1;
2022
}
21-
23+
2224
// Read the file
23-
otio::ErrorStatus error_status;
24-
otio::SerializableObject::Retainer<otio::Timeline> timeline(dynamic_cast<otio::Timeline*>(otio::Timeline::from_json_file(argv[1], &error_status)));
25+
otio::ErrorStatus error_status;
26+
otio::SerializableObject::Retainer<otio::Timeline> timeline(
27+
dynamic_cast<otio::Timeline*>(
28+
otio::Timeline::from_json_file(argv[1], &error_status)));
2529
if (!timeline)
2630
{
2731
examples::print_error(error_status);
2832
return 1;
2933
}
3034
auto video_tracks = timeline.value->video_tracks();
3135
auto audio_tracks = timeline.value->audio_tracks();
32-
33-
std::cout << "Read " << video_tracks.size() << " video tracks and " <<
34-
audio_tracks.size() << " audio tracks." << std::endl;
36+
37+
std::cout << "Read " << video_tracks.size() << " video tracks and "
38+
<< audio_tracks.size() << " audio tracks." << std::endl;
3539

3640
// Take just the video tracks - and flatten them into one.
3741
// This will trim away any overlapping segments, collapsing everything
3842
// into a single track.
39-
std::cout << "Flattening " << video_tracks.size() << " video tracks into one..." << std::endl;
43+
std::cout << "Flattening " << video_tracks.size()
44+
<< " video tracks into one..." << std::endl;
4045
auto onetrack = otio::flatten_stack(video_tracks, &error_status);
4146
if (!onetrack || is_error(error_status))
4247
{
@@ -45,22 +50,25 @@ int main(int argc, char** argv)
4550
}
4651

4752
// Now make a new empty Timeline and put that one Track into it
48-
std::string name;
53+
std::string name;
4954
std::stringstream ss(name);
5055
ss << timeline.value->name() << " Flattened";
51-
auto newtimeline = otio::SerializableObject::Retainer<otio::Timeline>(new otio::Timeline(ss.str()));
52-
auto stack = otio::SerializableObject::Retainer<otio::Stack>(new otio::Stack());
56+
auto newtimeline = otio::SerializableObject::Retainer<otio::Timeline>(
57+
new otio::Timeline(ss.str()));
58+
auto stack =
59+
otio::SerializableObject::Retainer<otio::Stack>(new otio::Stack());
5360
newtimeline.value->set_tracks(stack);
5461
if (!stack.value->append_child(onetrack, &error_status))
5562
{
5663
examples::print_error(error_status);
57-
return 1;
64+
return 1;
5865
}
5966

6067
// keep the audio track(s) as-is
61-
for (const auto& audio_track : audio_tracks)
68+
for (const auto& audio_track: audio_tracks)
6269
{
63-
auto clone = dynamic_cast<otio::Track*>(audio_track->clone(&error_status));
70+
auto clone =
71+
dynamic_cast<otio::Track*>(audio_track->clone(&error_status));
6472
if (!clone)
6573
{
6674
examples::print_error(error_status);
@@ -72,10 +80,12 @@ int main(int argc, char** argv)
7280
return 1;
7381
}
7482
}
75-
83+
7684
// ...and save it to disk.
77-
std::cout << "Saving " << newtimeline.value->video_tracks().size() << " video tracks and " <<
78-
newtimeline.value->audio_tracks().size() << " audio tracks." << std::endl;
85+
std::cout << "Saving " << newtimeline.value->video_tracks().size()
86+
<< " video tracks and "
87+
<< newtimeline.value->audio_tracks().size() << " audio tracks."
88+
<< std::endl;
7989
if (!newtimeline.value->to_json_file(argv[2], &error_status))
8090
{
8191
examples::print_error(error_status);

0 commit comments

Comments
 (0)