temporal: fix operator>> for Beats when handling pre-nutempo formats (double)
This commit is contained in:
parent
300ca3124b
commit
1904c4aa29
|
@ -120,10 +120,15 @@ Beats::round_to_subdivision (int subdivision, RoundMode dir) const {
|
||||||
std::istream&
|
std::istream&
|
||||||
Temporal::operator>>(std::istream& istr, Beats& b)
|
Temporal::operator>>(std::istream& istr, Beats& b)
|
||||||
{
|
{
|
||||||
|
double dbeats;
|
||||||
int32_t beats, ticks;
|
int32_t beats, ticks;
|
||||||
char d; /* delimiter, whatever it is */
|
char d; /* delimiter, whatever it is */
|
||||||
|
|
||||||
istr >> beats;
|
/* use double first to handle pre-nutempo values that would be
|
||||||
|
* serialized as double.
|
||||||
|
*/
|
||||||
|
|
||||||
|
istr >> dbeats;
|
||||||
|
|
||||||
if (!istr) {
|
if (!istr) {
|
||||||
throw std::invalid_argument (_("illegal or missing value for beat count"));
|
throw std::invalid_argument (_("illegal or missing value for beat count"));
|
||||||
|
@ -132,9 +137,23 @@ Temporal::operator>>(std::istream& istr, Beats& b)
|
||||||
istr >> d; /* we don't care what the delimiter is */
|
istr >> d; /* we don't care what the delimiter is */
|
||||||
|
|
||||||
if (!istr) {
|
if (!istr) {
|
||||||
|
|
||||||
|
if (istr.eof()) {
|
||||||
|
/* just a number. Convert dbeats and get out */
|
||||||
|
b = Beats::from_double (dbeats);
|
||||||
|
return istr;
|
||||||
|
}
|
||||||
|
|
||||||
throw std::invalid_argument (_("illegal or missing delimiter for beat value"));
|
throw std::invalid_argument (_("illegal or missing delimiter for beat value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* we just assuming, since the input format included a delimiter
|
||||||
|
* character, that the numerical value was integral and convert without
|
||||||
|
* checking.
|
||||||
|
*/
|
||||||
|
|
||||||
|
beats = (int32_t) dbeats;
|
||||||
|
|
||||||
istr >> ticks;
|
istr >> ticks;
|
||||||
|
|
||||||
if (!istr) {
|
if (!istr) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user