+ if (content->cpl ()) {
+ /* Use the CPL that the content was using before */
+ BOOST_FOREACH (shared_ptr<dcp::CPL> i, cpls()) {
+ if (i->id() == content->cpl().get()) {
+ cpl = i;
+ }
+ }
+ } else {
+ /* Choose the CPL with the fewest unsatisfied references */
+
+ int least_unsatisfied = INT_MAX;
+
+ BOOST_FOREACH (shared_ptr<dcp::CPL> i, cpls()) {
+ int unsatisfied = 0;
+ BOOST_FOREACH (shared_ptr<dcp::Reel> j, i->reels()) {
+ if (j->main_picture() && !j->main_picture()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ if (j->main_sound() && !j->main_sound()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ if (j->main_subtitle() && !j->main_subtitle()->asset_ref().resolved()) {
+ ++unsatisfied;
+ }
+ }
+
+ if (unsatisfied < least_unsatisfied) {
+ least_unsatisfied = unsatisfied;
+ cpl = i;
+ }
+ }