LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 : x->relative_coordinate (common, X_AXIS)); | 73 : x->relative_coordinate (common, X_AXIS)); |
74 } | 74 } |
75 | 75 |
76 span_points[d] -= d * t / 2; | 76 span_points[d] -= d * t / 2; |
77 } | 77 } |
78 while (flip (&d) != LEFT); | 78 while (flip (&d) != LEFT); |
79 | 79 |
80 Stencil m; | 80 Stencil m; |
81 | 81 |
82 vector<Real> line_positions = Staff_symbol::line_positions (me); | 82 vector<Real> line_positions = Staff_symbol::line_positions (me); |
83 int line_count = line_positions.size (); | |
84 | 83 |
85 Stencil line | 84 Stencil line |
86 = Lookup::horizontal_line (span_points | 85 = Lookup::horizontal_line (span_points |
87 - me->relative_coordinate (common, X_AXIS), | 86 - me->relative_coordinate (common, X_AXIS), |
88 t); | 87 t); |
89 | 88 |
90 Real space = staff_space (me); | 89 Real space = staff_space (me); |
91 for (int i = 0; i < line_count; i++) | 90 for (vector<Real>::const_iterator i = line_positions.begin (), |
| 91 e = line_positions.end (); |
| 92 i != e; |
| 93 ++i) |
92 { | 94 { |
93 Stencil b (line); | 95 Stencil b (line); |
94 b.translate_axis (line_positions[i] * 0.5 * space, Y_AXIS); | 96 b.translate_axis (*i * 0.5 * space, Y_AXIS); |
95 m.add_stencil (b); | 97 m.add_stencil (b); |
96 } | 98 } |
97 return m.smobbed_copy (); | 99 return m.smobbed_copy (); |
98 } | 100 } |
99 | 101 |
100 vector<Real> | 102 vector<Real> |
101 Staff_symbol::line_positions (Grob *me) | 103 Staff_symbol::line_positions (Grob *me) |
102 { | 104 { |
103 SCM line_positions = me->get_property ("line-positions"); | 105 SCM line_positions = me->get_property ("line-positions"); |
104 if (scm_is_pair (line_positions)) | 106 if (scm_is_pair (line_positions)) |
(...skipping 25 matching lines...) Expand all Loading... |
130 Staff_symbol::ledger_positions (Grob *me, int pos) | 132 Staff_symbol::ledger_positions (Grob *me, int pos) |
131 { | 133 { |
132 SCM ledger_positions = me->get_property ("ledger-positions"); | 134 SCM ledger_positions = me->get_property ("ledger-positions"); |
133 Real ledger_extra = robust_scm2double (me->get_property ("ledger-extra"), 0); | 135 Real ledger_extra = robust_scm2double (me->get_property ("ledger-extra"), 0); |
134 vector<Real> line_positions = Staff_symbol::line_positions (me); | 136 vector<Real> line_positions = Staff_symbol::line_positions (me); |
135 vector<Real> values; | 137 vector<Real> values; |
136 | 138 |
137 if (line_positions.empty ()) | 139 if (line_positions.empty ()) |
138 return values; | 140 return values; |
139 | 141 |
140 int line_count = line_positions.size (); | |
141 | |
142 // find the staff line nearest to note position | 142 // find the staff line nearest to note position |
143 Real nearest_line = line_positions[0]; | 143 Real nearest_line = line_positions[0]; |
144 Real line_dist = abs (line_positions[0] - pos); | 144 Real line_dist = abs (line_positions[0] - pos); |
145 for (int i = 1; i < line_count; i++) | 145 for (vector<Real>::const_iterator i = line_positions.begin (), |
146 { | 146 e = line_positions.end (); |
147 if (abs (line_positions[i] - pos) < line_dist) | 147 i != e; |
148 { | 148 ++i) |
149 nearest_line = line_positions[i]; | 149 { |
150 line_dist = abs (line_positions[i] - pos); | 150 if (abs (*i - pos) < line_dist) |
| 151 { |
| 152 nearest_line = *i; |
| 153 line_dist = abs (*i - pos); |
151 } | 154 } |
152 } | 155 } |
153 | 156 |
154 if (line_dist < .5) | 157 if (line_dist < .5) |
155 return values; | 158 return values; |
156 | 159 |
157 Direction dir = (Direction)sign (pos - nearest_line); | 160 Direction dir = (Direction)sign (pos - nearest_line); |
158 | 161 |
159 if (scm_is_pair (ledger_positions)) | 162 if (scm_is_pair (ledger_positions)) |
160 // custom ledger line positions | 163 // custom ledger line positions |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 { | 299 { |
297 int l = Staff_symbol::line_count (me); | 300 int l = Staff_symbol::line_count (me); |
298 Real height = (l - 1) * staff_space (me) / 2; | 301 Real height = (l - 1) * staff_space (me) / 2; |
299 y_ext = Interval (-height, height); | 302 y_ext = Interval (-height, height); |
300 } | 303 } |
301 y_ext.widen (t / 2); | 304 y_ext.widen (t / 2); |
302 return ly_interval2scm (y_ext); | 305 return ly_interval2scm (y_ext); |
303 } | 306 } |
304 | 307 |
305 bool | 308 bool |
306 Staff_symbol::on_line (Grob *me, int pos) | 309 Staff_symbol::on_line (Grob *me, int pos, bool allow_ledger) |
307 { | 310 { |
308 SCM line_positions = me->get_property ("line-positions"); | 311 SCM line_positions = me->get_property ("line-positions"); |
309 if (scm_is_pair (line_positions)) | 312 if (scm_is_pair (line_positions)) |
310 { | 313 { |
311 Real min_line = HUGE_VAL; | 314 Real min_line = HUGE_VAL; |
312 Real max_line = -HUGE_VAL; | 315 Real max_line = -HUGE_VAL; |
313 for (SCM s = line_positions; scm_is_pair (s); s = scm_cdr (s)) | 316 for (SCM s = line_positions; scm_is_pair (s); s = scm_cdr (s)) |
314 { | 317 { |
315 Real current_line = scm_to_double (scm_car (s)); | 318 Real current_line = scm_to_double (scm_car (s)); |
316 if (pos == current_line) | 319 if (pos == current_line) |
317 return true; | 320 return true; |
318 if (current_line > max_line) | 321 if (current_line > max_line) |
319 max_line = current_line; | 322 max_line = current_line; |
320 if (current_line < min_line) | 323 if (current_line < min_line) |
321 min_line = current_line; | 324 min_line = current_line; |
322 | 325 |
323 } | 326 } |
324 if (pos < min_line) | 327 |
325 return (( (int) (rint (pos - min_line)) % 2) == 0); | 328 if (allow_ledger) |
326 if (pos > max_line) | 329 { |
327 return (( (int) (rint (pos - max_line)) % 2) == 0); | 330 if (pos < min_line) |
| 331 return (( (int) (rint (pos - min_line)) % 2) == 0); |
| 332 if (pos > max_line) |
| 333 return (( (int) (rint (pos - max_line)) % 2) == 0); |
| 334 } |
328 | 335 |
329 return false; | 336 return false; |
330 } | 337 } |
331 else | 338 else |
332 return ((abs (pos + line_count (me)) % 2) == 1); | 339 { |
| 340 int const line_cnt = line_count (me); |
| 341 bool result = abs (pos + line_cnt) % 2 == 1; |
| 342 if (result && !allow_ledger) |
| 343 { |
| 344 result = -line_cnt < pos && pos < line_cnt; |
| 345 } |
| 346 return result; |
| 347 } |
333 } | 348 } |
334 | 349 |
335 Interval | 350 Interval |
336 Staff_symbol::line_span (Grob *me) | 351 Staff_symbol::line_span (Grob *me) |
337 { | 352 { |
338 SCM line_positions = me->get_property ("line-positions"); | 353 SCM line_positions = me->get_property ("line-positions"); |
339 Interval iv; | 354 Interval iv; |
340 | 355 |
341 if (scm_is_pair (line_positions)) | 356 if (scm_is_pair (line_positions)) |
342 for (SCM s = line_positions; scm_is_pair (s); s = scm_cdr (s)) | 357 for (SCM s = line_positions; scm_is_pair (s); s = scm_cdr (s)) |
(...skipping 18 matching lines...) Expand all Loading... |
361 /* properties */ | 376 /* properties */ |
362 "ledger-extra " | 377 "ledger-extra " |
363 "ledger-line-thickness " | 378 "ledger-line-thickness " |
364 "ledger-positions " | 379 "ledger-positions " |
365 "line-count " | 380 "line-count " |
366 "line-positions " | 381 "line-positions " |
367 "staff-space " | 382 "staff-space " |
368 "thickness " | 383 "thickness " |
369 "width " | 384 "width " |
370 ); | 385 ); |
LEFT | RIGHT |