From 870a574324d28d4b2a4574e33de5c690a0ed55ad Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 5 Jul 2018 00:39:23 +0100 Subject: [PATCH] Sort audio timeline views in order of DCP audio channel mappings (#1279). --- src/wx/timeline.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 5babcfea1..2e90b3a81 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -306,6 +306,27 @@ place (TimelineViewList& views, int& tracks) return tracks - base; } +/** Compare the mapped output channels of two TimelineViews, so we can into + * order of first mapped DCP channel. + */ +struct AudioMappingComparator { + bool operator()(shared_ptr a, shared_ptr b) { + int la = -1; + shared_ptr cva = dynamic_pointer_cast(a); + if (cva) { + list oc = cva->content()->audio->mapping().mapped_output_channels(); + la = *min_element(begin(oc), end(oc)); + } + int lb = -1; + shared_ptr cvb = dynamic_pointer_cast(b); + if (cvb) { + list oc = cvb->content()->audio->mapping().mapped_output_channels(); + lb = *min_element(begin(oc), end(oc)); + } + return la < lb; + } +}; + void Timeline::assign_tracks () { @@ -373,9 +394,13 @@ Timeline::assign_tracks () ++_tracks; } - /* Audio */ + /* Audio. We're sorting the views so that we get the audio views in order of increasing + DCP channel index. + */ - int const audio_tracks = place (_views, _tracks); + TimelineViewList views = _views; + sort(views.begin(), views.end(), AudioMappingComparator()); + int const audio_tracks = place (views, _tracks); _labels_view->set_3d (have_3d); _labels_view->set_audio_tracks (audio_tracks); -- 2.30.2