Start introducing section support

This commit is contained in:
Matthias Neeracher 2007-12-25 13:12:07 +00:00
parent ee87f6a76b
commit efbc96a7f8
6 changed files with 1042 additions and 967 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -29,8 +29,9 @@ VLSystemLayout::VLSystemLayout(const VLProperties & prop, float width, int maxMe
static size_t NextBreak(const VLSong & song, size_t after=0)
{
size_t propIdx = song.fMeasures[after].fPropIdx;
while (++after < song.fMeasures.size())
if (song.fMeasures[after].fBreak)
if (song.fMeasures[after].fBreak || song.fMeasures[after].fPropIdx != propIdx)
return after;
return song.fMeasures.size();
}

View File

@ -1985,6 +1985,36 @@ VLFract VLSong::TiedDuration(size_t measure)
return total;
}
bool VLSong::DoesBeginSection(size_t measure)
{
return measure && measure < fMeasures.size()
&& fMeasures[measure-1].fPropIdx!=fMeasures[measure].fPropIdx;
}
void VLSong::AddSection(size_t measure)
{
int splitIdx = fMeasures[measure].fPropIdx;
VLProperties newProp = fProperties[splitIdx];
if (splitIdx < fProperties.size()-1)
fProperties.insert(fProperties.begin()+splitIdx, newProp);
else
fProperties.push_back(newProp);
while (measure < fMeasures.size())
++fMeasures[measure++].fPropIdx;
}
void VLSong::DelSection(size_t measure)
{
int delIdx = fMeasures[measure].fPropIdx;
fProperties.erase(fProperties.begin()+delIdx);
while (measure < fMeasures.size())
--fMeasures[measure++].fPropIdx;
}
//////////////////////// VLSongVisitor ////////////////////////////////
VLSongVisitor::~VLSongVisitor()
{
}

View File

@ -360,7 +360,6 @@ public:
void PasteMeasures(size_t beginMeasure, const VLSong & measures,
int mode = kInsert);
void DeleteMeasures(size_t beginMeasure, size_t endMeasure, int mode = kInsert);
size_t CountMeasures() const { return fMeasures.size(); }
size_t EmptyEnding() const;
size_t CountStanzas() const;
@ -373,6 +372,10 @@ public:
const VLProperties & Properties(size_t measure) const {
return fProperties[fMeasures[measure].fPropIdx];
}
bool DoesBeginSection(size_t measure);
void AddSection(size_t measure);
void DelSection(size_t measure);
private:
void AddMeasure();
};

View File

@ -80,9 +80,13 @@ static VLSong sPasteboard;
return NO;
else if (action == @selector(insertBreak:))
if (fSelStart == fSelEnd && fSelStart > 0) {
VLSong * song = [self song];
[item setState:fSelStart < song->fMeasures.size()
&& song->fMeasures[fSelStart].fBreak == [item tag]];
VLSong * song = [self song];
bool checked = fSelStart < song->fMeasures.size();
if ([item tag] == 256)
checked = checked && song->DoesBeginSection(fSelStart);
else
checked = checked && song->fMeasures[fSelStart].fBreak == [item tag];
[item setState:checked];
return YES;
} else
@ -275,11 +279,18 @@ static VLSong sPasteboard;
{
[[self document] willChangeSong];
VLSong * song = [self song];
VLMeasure & meas = song->fMeasures[fSelStart];
if (meas.fBreak == [sender tag])
meas.fBreak = 0;
else
meas.fBreak = [sender tag];
if ([sender tag] == 256) {
if (song->DoesBeginSection(fSelStart))
song->DelSection(fSelStart);
else
song->AddSection(fSelStart);
} else {
VLMeasure & meas = song->fMeasures[fSelStart];
if (meas.fBreak == [sender tag])
meas.fBreak = 0;
else
meas.fBreak = [sender tag];
}
fNeedsRecalc = kRecalc;
[self setNeedsDisplay:YES];
[[self document] didChangeSong];