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--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2015 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 vector<Real> values (line_count); | 128 vector<Real> values (line_count); |
129 for (int i = 0; i < line_count; i++) | 129 for (int i = 0; i < line_count; i++) |
130 { | 130 { |
131 values[i] = height - i * 2; | 131 values[i] = height - i * 2; |
132 } | 132 } |
133 return values; | 133 return values; |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 vector<Real> | 137 vector<Real> |
138 Staff_symbol::ledger_positions (Grob *me, int pos) | 138 Staff_symbol::ledger_positions (Grob *me, int pos, Item const *head) |
139 { | 139 { |
| 140 // allow override of ledger positions via note head grob... |
| 141 if (head) |
| 142 { |
| 143 SCM posns = head->get_property ("ledger-positions"); |
| 144 if (scm_is_pair (posns)) |
| 145 return ly_scm2floatvector (posns); |
| 146 } |
| 147 |
| 148 // ...or via custom ledger positions function |
| 149 SCM lp_function = me->get_property ("ledger-positions-function"); |
| 150 if (scm_is_pair (lp_function)) |
| 151 { |
| 152 SCM func = scm_eval (lp_function, scm_interaction_environment ()); |
| 153 if (ly_is_procedure (func)) |
| 154 return ly_scm2floatvector (scm_call_2 (func, |
| 155 me->self_scm (), |
| 156 scm_from_int (pos))); |
| 157 } |
| 158 |
140 SCM ledger_positions = me->get_property ("ledger-positions"); | 159 SCM ledger_positions = me->get_property ("ledger-positions"); |
141 Real ledger_extra = robust_scm2double (me->get_property ("ledger-extra"), 0); | 160 Real ledger_extra = robust_scm2double (me->get_property ("ledger-extra"), 0); |
142 vector<Real> line_positions = Staff_symbol::line_positions (me); | 161 vector<Real> line_positions = Staff_symbol::line_positions (me); |
143 vector<Real> values; | 162 vector<Real> values; |
144 | 163 |
145 if (line_positions.empty ()) | 164 if (line_positions.empty ()) |
146 return values; | 165 return values; |
147 | 166 |
148 // find the staff line nearest to note position | 167 // find the staff line nearest to note position |
149 Real nearest_line = line_positions[0]; | 168 Real nearest_line = line_positions[0]; |
150 Real line_dist = abs (line_positions[0] - pos); | 169 Real line_dist = abs (line_positions[0] - pos); |
151 for (vector<Real>::const_iterator i = line_positions.begin (), | 170 for (vector<Real>::const_iterator i = line_positions.begin (), |
152 e = line_positions.end (); | 171 e = line_positions.end (); |
153 i != e; | 172 i != e; |
154 ++i) | 173 ++i) |
155 { | 174 { |
156 if (abs (*i - pos) < line_dist) | 175 if (abs (*i - pos) < line_dist) |
157 { | 176 { |
158 nearest_line = *i; | 177 nearest_line = *i; |
159 line_dist = abs (*i - pos); | 178 line_dist = abs (*i - pos); |
160 } | 179 } |
161 } | 180 } |
162 | 181 |
163 if (line_dist < .5) | 182 if (line_dist < .5) |
164 return values; | 183 return values; |
165 | 184 |
166 Direction dir = (Direction)sign (pos - nearest_line); | 185 Direction dir = (Direction)sign (pos - nearest_line); |
167 | 186 |
168 if (scm_is_pair (ledger_positions)) | 187 if (scm_is_pair (ledger_positions)) |
169 // custom ledger line positions | 188 // custom ledger positions via StaffSymbol.ledger-positions |
170 { | 189 { |
171 Real min_pos = HUGE_VAL; | 190 Real min_pos = HUGE_VAL; |
172 Real max_pos = -HUGE_VAL; | 191 Real max_pos = -HUGE_VAL; |
173 SCM s2; | 192 SCM s2; |
174 | 193 |
175 // find the extent of the ledger pattern | 194 // find the extent of the ledger pattern |
176 for (SCM s = ledger_positions; scm_is_pair (s); s = scm_cdr (s)) | 195 for (SCM s = ledger_positions; scm_is_pair (s); s = scm_cdr (s)) |
177 { | 196 { |
178 s2 = scm_car (s); | 197 s2 = scm_car (s); |
179 if (!scm_is_number (s2)) | 198 if (!scm_is_number (s2)) |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 " that go by a half staff space are called @emph{positions}." | 414 " that go by a half staff space are called @emph{positions}." |
396 " The center (i.e., middle line or space) is position@tie{}0." | 415 " The center (i.e., middle line or space) is position@tie{}0." |
397 " The length of the symbol may be set by hand through the" | 416 " The length of the symbol may be set by hand through the" |
398 " @code{width} property.", | 417 " @code{width} property.", |
399 | 418 |
400 /* properties */ | 419 /* properties */ |
401 "break-align-symbols " | 420 "break-align-symbols " |
402 "ledger-extra " | 421 "ledger-extra " |
403 "ledger-line-thickness " | 422 "ledger-line-thickness " |
404 "ledger-positions " | 423 "ledger-positions " |
| 424 "ledger-positions-function " |
405 "line-count " | 425 "line-count " |
406 "line-positions " | 426 "line-positions " |
407 "staff-space " | 427 "staff-space " |
408 "thickness " | 428 "thickness " |
409 "width " | 429 "width " |
410 ); | 430 ); |
LEFT | RIGHT |