From b8dac8dd6366300542e982729e063e64fc058a08 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sat, 26 Jan 2008 10:53:24 +0000 Subject: [PATCH] Fix reading of documents with multiple time values --- Sources/VLModel.cpp | 20 ++++++++++++++++++++ Sources/VLModel.h | 1 + Sources/VLPListDocument.mm | 5 ++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index 8b712b6..f28b480 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -558,12 +558,32 @@ void VLSong::AddMeasure() VLChord rchord(dur); VLMeasure meas; + meas.fPropIdx = fProperties.size()-1; meas.fChords.push_back(rchord); meas.fMelody.push_back(rest); fMeasures.push_back(meas); } +void VLSong::SetProperties(size_t measure, int propIdx) +{ + VLFraction dur = fProperties[propIdx].fTime; + dur.Normalize(); + VLLyricsNote rest(dur); + VLChord rchord(dur); + VLMeasure meas; + + meas.fPropIdx = propIdx; + meas.fChords.push_back(rchord); + meas.fMelody.push_back(rest); + + if (measure < fMeasures.size()) + fMeasures[measure] = meas; + else + while (fMeasures.size() <= measure) + fMeasures.push_back(meas); +} + void VLSong::swap(VLSong & other) { fProperties.swap(other.fProperties); diff --git a/Sources/VLModel.h b/Sources/VLModel.h index 5c18833..7ee6c42 100644 --- a/Sources/VLModel.h +++ b/Sources/VLModel.h @@ -377,6 +377,7 @@ public: const VLProperties & Properties(size_t measure) const { return fProperties[fMeasures[measure].fPropIdx]; } + void SetProperties(size_t measure, int propIdx); bool DoesBeginSection(size_t measure) const; void AddSection(size_t measure); diff --git a/Sources/VLPListDocument.mm b/Sources/VLPListDocument.mm index fee13f2..8380ec8 100644 --- a/Sources/VLPListDocument.mm +++ b/Sources/VLPListDocument.mm @@ -310,6 +310,8 @@ advanceAt: ) { if (NSNumber * mNo = [mdict objectForKey:@"measure"]) measNo = static_cast([mNo intValue]); + if (NSNumber * mPx = [mdict objectForKey:@"properties"]) + song->SetProperties(measNo, [mPx intValue]); [self readMelody:[mdict objectForKey:@"melody"] inMeasure:measNo onsets:onsets]; [self readChords:[mdict objectForKey:@"chords"] inMeasure:measNo]; @@ -322,9 +324,6 @@ advanceAt: song->fMeasures[measNo].fBreak |= VLMeasure::kNewSystem; if ([[mdict objectForKey:@"new-page"] boolValue]) song->fMeasures[measNo].fBreak |= VLMeasure::kNewPage; - if (NSNumber * mPx = [mdict objectForKey:@"properties"]) - song->fMeasures[measNo].fPropIdx= - static_cast([mPx intValue]); if (NSDictionary * beginRep = [mdict objectForKey:@"begin-repeat"]) { VLRepeat rep;