LEFT | RIGHT |
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--2011 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1997--2011 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 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
| 19 |
| 20 #include <algorithm> // for reverse |
19 | 21 |
20 #include "paper-column.hh" | 22 #include "paper-column.hh" |
21 #include "output-def.hh" | 23 #include "output-def.hh" |
22 #include "side-position-interface.hh" | 24 #include "side-position-interface.hh" |
23 #include "engraver.hh" | 25 #include "engraver.hh" |
24 #include "context.hh" | 26 #include "context.hh" |
25 #include "grob-array.hh" | 27 #include "grob-array.hh" |
26 #include "stream-event.hh" | 28 #include "stream-event.hh" |
27 | 29 |
28 #include "translator.icc" | 30 #include "translator.icc" |
(...skipping 29 matching lines...) Expand all Loading... |
58 return; | 60 return; |
59 | 61 |
60 alternative_event_ = ev; | 62 alternative_event_ = ev; |
61 int current_barnumber = robust_scm2int (get_property ("currentBarNumber"), 0); | 63 int current_barnumber = robust_scm2int (get_property ("currentBarNumber"), 0); |
62 Direction alternative_dir = robust_scm2dir (ev->get_property ("alternative-dir
"), CENTER); | 64 Direction alternative_dir = robust_scm2dir (ev->get_property ("alternative-dir
"), CENTER); |
63 bool make_alternative = get_property ("alternativeNumberingStyle") == ly_symbo
l2scm ("numbers") | 65 bool make_alternative = get_property ("alternativeNumberingStyle") == ly_symbo
l2scm ("numbers") |
64 || get_property ("alternativeNumberingStyle") == ly_sy
mbol2scm ("numbers-with-letters"); | 66 || get_property ("alternativeNumberingStyle") == ly_sy
mbol2scm ("numbers-with-letters"); |
65 if (make_alternative) | 67 if (make_alternative) |
66 { | 68 { |
67 /* | 69 /* |
68 if we're starting an alternative, we set the starting | 70 if we're starting the first alternative, we set the starting |
69 bar number to the current bar number | 71 bar number to the current bar number |
70 */ | 72 */ |
71 if (alternative_dir == LEFT) | 73 if (alternative_dir == LEFT) |
72 alternative_starting_bar_number_ = current_barnumber; | 74 alternative_starting_bar_number_ = current_barnumber; |
73 | 75 |
74 /* | 76 /* |
75 if the alternative is not the last one, we send the | 77 if the alternative is not the last one, we send the |
76 current bar number back to the alternative bar number. | 78 current bar number back to the alternative bar number. |
77 */ | 79 */ |
78 if (alternative_dir < RIGHT) | 80 if (alternative_dir < RIGHT) |
79 current_barnumber = alternative_starting_bar_number_; | 81 current_barnumber = alternative_starting_bar_number_; |
80 | 82 |
81 context ()->set_property ("currentBarNumber", scm_from_int (current_barnum
ber)); | 83 context ()->set_property ("currentBarNumber", scm_from_int (current_barnum
ber)); |
82 } | 84 } |
| 85 } |
| 86 |
| 87 int |
| 88 int_pow (int n, int i) |
| 89 { |
| 90 if (i == 1) |
| 91 return n; |
| 92 if (i <= 0) |
| 93 return 1; |
| 94 return int_pow (n * n, i - 1); |
83 } | 95 } |
84 | 96 |
85 void | 97 void |
86 Bar_number_engraver::process_music () | 98 Bar_number_engraver::process_music () |
87 { | 99 { |
88 SCM wb = get_property ("whichBar"); | 100 SCM wb = get_property ("whichBar"); |
89 | 101 |
90 if (scm_is_string (wb)) | 102 if (scm_is_string (wb)) |
91 { | 103 { |
92 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)
)); | 104 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)
)); |
(...skipping 25 matching lines...) Expand all Loading... |
118 default: | 130 default: |
119 assert (false); | 131 assert (false); |
120 } | 132 } |
121 alternative_number_ += alternative_number_increment_; | 133 alternative_number_ += alternative_number_increment_; |
122 ······················ | 134 ······················ |
123 alternative_number_increment_ = robust_scm2int (alternativ
e_event_->get_property ("alternative-increment"), 1); | 135 alternative_number_increment_ = robust_scm2int (alternativ
e_event_->get_property ("alternative-increment"), 1); |
124 } | 136 } |
125 if (alternative_number_ >= 0) | 137 if (alternative_number_ >= 0) |
126 { | 138 { |
127 string alphabet = "abcdefghijklmnopqrstuvwxyz"; | 139 string alphabet = "abcdefghijklmnopqrstuvwxyz"; |
128 for (int i = 0; i < alternative_number_ / 26; i++) | 140 int power = 0; |
129 text_tag += alphabet.at (alternative_number_ / 26); | 141 int running_sum = 0; |
130 text_tag += alphabet.at (alternative_number_ % 26); | 142 int scratch = alternative_number_; |
| 143 while (running_sum <= alternative_number_) |
| 144 { |
| 145 power++; |
| 146 running_sum += int_pow (26, power); |
| 147 } |
| 148 scratch += int_pow (26, power) - running_sum; |
| 149 for (int i = power; i--;) |
| 150 text_tag += alphabet.at ((scratch / int_pow (26, i)) % 2
6); |
131 } | 151 } |
132 } | 152 } |
133 // guh. | 153 // guh. |
134 text_->set_property | 154 text_->set_property |
135 ("text", | 155 ("text", |
136 scm_string_concatenate (scm_list_2 (scm_number_to_string (bn,
scm_from_int (10)), | 156 scm_string_concatenate (scm_list_2 (scm_number_to_string (bn,
scm_from_int (10)), |
137 ly_string2scm (text_tag)))
); | 157 ly_string2scm (text_tag)))
); |
138 } | 158 } |
139 } | 159 } |
140 } | 160 } |
141 } | 161 } |
142 | 162 |
143 Bar_number_engraver::Bar_number_engraver () | 163 Bar_number_engraver::Bar_number_engraver () |
144 { | 164 { |
145 text_ = 0; | 165 text_ = 0; |
146 alternative_starting_bar_number_ = 0; | 166 alternative_starting_bar_number_ = 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 /* read */ | 218 /* read */ |
199 "currentBarNumber " | 219 "currentBarNumber " |
200 "whichBar " | 220 "whichBar " |
201 "stavesFound " | 221 "stavesFound " |
202 "barNumberVisibility " | 222 "barNumberVisibility " |
203 "alternativeNumberingStyle ", | 223 "alternativeNumberingStyle ", |
204 | 224 |
205 /* write */ | 225 /* write */ |
206 "currentBarNumber " | 226 "currentBarNumber " |
207 ); | 227 ); |
LEFT | RIGHT |