Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2209)

Side by Side Diff: lily/pitch.cc

Issue 581580043: Make Pitch::to_string() more robust (Closed)
Patch Set: dan, round 2 Created 5 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) 1998--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> 4 Copyright (C) 1998--2020 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 char const *accname[] = {"eses", "eseh", "es", "eh", "", 151 char const *accname[] = {"eses", "eseh", "es", "eh", "",
152 "ih", "is", "isih", "isis" 152 "ih", "is", "isih", "isis"
153 }; 153 };
154 154
155 string 155 string
156 Pitch::to_string () const 156 Pitch::to_string () const
157 { 157 {
158 int n = (notename_ + 2) % scale_->step_count (); 158 int n = (notename_ + 2) % scale_->step_count ();
159 string s (1, static_cast<char> (n + 'a')); 159 string s (1, static_cast<char> (n + 'a'));
160 Rational qtones = alteration_ * Rational (4, 1); 160 Rational qtones = alteration_ * Rational (4, 1);
161 int qt = int (rint (Real (qtones))); 161 size_t qt = size_t (rint (Real (qtones) + 4.0));
162 if (qt < sizeof (accname) / sizeof (accname[0]))
163 {
164 s += string (accname[qt]);
165 }
166 else
167 {
168 s += "??";
169 }
162 170
163 s += string (accname[qt + 4]);
164 if (octave_ >= 0) 171 if (octave_ >= 0)
165 { 172 {
166 int o = octave_ + 1; 173 int o = octave_ + 1;
167 while (o--) 174 while (o--)
168 s += "'"; 175 s += "'";
169 } 176 }
170 else if (octave_ < 0) 177 else if (octave_ < 0)
171 { 178 {
172 int o = (-octave_) - 1; 179 int o = (-octave_) - 1;
173 while (o--) 180 while (o--)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 Rational NATURAL_ALTERATION (0); 307 Rational NATURAL_ALTERATION (0);
301 Rational FLAT_ALTERATION (-1, 2); 308 Rational FLAT_ALTERATION (-1, 2);
302 Rational DOUBLE_FLAT_ALTERATION (-1); 309 Rational DOUBLE_FLAT_ALTERATION (-1);
303 Rational SHARP_ALTERATION (1, 2); 310 Rational SHARP_ALTERATION (1, 2);
304 311
305 Pitch 312 Pitch
306 Pitch::negated () const 313 Pitch::negated () const
307 { 314 {
308 return pitch_interval (*this, Pitch ()); 315 return pitch_interval (*this, Pitch ());
309 } 316 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b