Reorganize property access

This commit is contained in:
Matthias Neeracher 2007-12-23 13:14:09 +00:00
parent 80fbc00f56
commit 5615dee186
7 changed files with 19 additions and 15 deletions

View File

@ -28,8 +28,7 @@ VLSystemLayout::VLSystemLayout(const VLProperties & prop, float width)
VLLayout::VLLayout(const VLSong & song, float width)
{
for (size_t meas = 0; meas<song.fMeasures.size(); ) {
const VLProperties & prop = song.fProperties[song.fMeasures[meas].fPropIdx];
push_back(VLSystemLayout(prop, width));
push_back(VLSystemLayout(song.Properties(meas), width));
meas += back().NumMeasures();
}
}

View File

@ -552,7 +552,7 @@ VLSong::VLSong(bool initialize)
void VLSong::AddMeasure()
{
VLFraction dur = fProperties.front().fTime;
VLFraction dur = fProperties.back().fTime;
dur.Normalize();
VLLyricsNote rest(dur);
VLChord rchord(dur);
@ -1914,8 +1914,8 @@ void VLSong::PasteMeasures(size_t beginMeasure, const VLSong & measures, int mod
void VLSong::DeleteMeasures(size_t beginMeasure, size_t endMeasure, int mode)
{
if (mode == kOverwriteMelody) {
VLLyricsNote rest(fProperties.front().fTime);
for (size_t m=beginMeasure; m<endMeasure; ++m) {
VLLyricsNote rest(Properties(m).fTime);
fMeasures[m].fMelody.clear();
fMeasures[m].fMelody.push_back(rest);
}

View File

@ -362,6 +362,12 @@ public:
size_t CountTopLedgers() const;
size_t CountBotLedgers() const;
VLFract TiedDuration(size_t measure);
VLProperties & Properties(size_t measure) {
return fProperties[fMeasures[measure].fPropIdx];
}
const VLProperties & Properties(size_t measure) const {
return fProperties[fMeasures[measure].fPropIdx];
}
private:
void AddMeasure();
};

View File

@ -295,8 +295,7 @@ VLMusicElement sSemi2Accidental[12][12] = {
const VLSystemLayout & kLayout = (*fLayout)[system];
const VLSong * song = [self song];
const VLProperties & kProp =
song->fProperties[song->fMeasures[fLayout->FirstMeasure(system)].fPropIdx];
const VLProperties & kProp = song->Properties(fLayout->FirstMeasure(system));
const float kSystemY = [self systemY:system];
const float kLineW = (*fLayout)[system].SystemWidth();
@ -722,14 +721,15 @@ static int8_t sSharpAcc[] = {
{
fCursorPitch = VLNote::kNoPitch;
const VLProperties & prop = [self song]->fProperties.front();
NSPoint loc = [event locationInWindow];
loc = [self convertPoint:loc fromView:nil];
if (loc.y < 0.0f || loc.y >= fLayout->NumSystems()*kSystemH)
return fCursorRegion = kRegionNowhere;
int system = fLayout->NumSystems() - static_cast<int>(loc.y / kSystemH) - 1;
const VLSong * song = [self song];
int system =
fLayout->NumSystems() - static_cast<int>(loc.y / kSystemH) - 1;
const VLSystemLayout & kLayout = (*fLayout)[system];
const float kMeasureW = kLayout.MeasureWidth();
loc.y = fmodf(loc.y, kSystemH);
@ -760,12 +760,12 @@ static int8_t sSharpAcc[] = {
loc.x -= group*(kLayout.DivPerGroup()+1)*kNoteW;
int div = static_cast<int>(roundf(loc.x / kNoteW))-1;
div = std::min(std::max(div, 0), kLayout.DivPerGroup()-1);
fCursorAt = VLFraction(div+group*kLayout.DivPerGroup(), 4*prop.fDivisions);
fCursorMeasure = measure+fLayout->FirstMeasure(system);
if (fCursorMeasure > [self song]->fMeasures.size())
return fCursorRegion = kRegionNowhere;
fCursorAt = VLFraction(div+group*kLayout.DivPerGroup(), 4*song->Properties(fCursorMeasure).fDivisions);
if (loc.y >= kSystemBaseline+kChordY) {
//
// Chord, round to quarters
@ -1039,4 +1039,4 @@ static int8_t sSharpAcc[] = {
}
@end

View File

@ -103,7 +103,7 @@ std::string NormalizeName(NSString* rawName)
//
VLSoundOut::Instance()->PlayChord(*chord);
const VLProperties & prop = fSong->fProperties.front();
const VLProperties & prop = fSong->Properties(fMeasure);
std::string name, ext, root;
chord->Name(name, ext, root, prop.fKey > 0);

View File

@ -85,7 +85,7 @@
VLFraction at = fAt;
if (!fSong->PrevWord(fStanza, fMeasure, at)) {
fMeasure = fSong->CountMeasures()-1;
at = fSong->fProperties.front().fTime;
at = fSong->Properties(fMeasure).fTime;
fSong->PrevWord(fStanza, fMeasure, at);
}
fAt = at;

View File

@ -279,8 +279,7 @@
{
const int kFirstMeas = fLayout->FirstMeasure(system);
const VLSong * song = [self song];
const VLProperties & kProp =
song->fProperties[song->fMeasures[kFirstMeas].fPropIdx];
const VLProperties & kProp = song->Properties(kFirstMeas);
const VLSystemLayout & kLayout = (*fLayout)[system];
float kSystemY = [self systemY:system];