+int
+measure_duration_log (Grob *me)
+{
+ SCM sml = dynamic_cast<Spanner *> (me)->get_bound (LEFT)
+ ->get_property ("measure-length");
+ bool round = to_boolean (me->get_property ("round-to-longer-rest"));
+ Rational ml = (unsmob_moment (sml)) ? unsmob_moment (sml)->main_part_ : Rational (1);
+
+ double duration_log = -log_2 (ml.Rational::to_double ());
+ int measure_duration_log = int (ceil (duration_log));
+ if (round && duration_log - measure_duration_log < 0)
+ measure_duration_log--;
+
+ SCM duration_logs_list = me->get_property ("usable-duration-logs");
+ int closest_list_elt = -15; // -15 is out of range.
+
+ for (int i = 0; i < scm_to_int (scm_length (duration_logs_list)); i++)
+ {
+ int list_elt = scm_to_int (scm_list_ref (duration_logs_list, scm_from_int (i)));
+ int shortest_distance = abs (measure_duration_log - closest_list_elt);
+ int distance = abs (measure_duration_log - list_elt);
+ if (distance < shortest_distance)
+ closest_list_elt = list_elt;
+ }
+
+ return closest_list_elt;
+}
+