Fix bugs in Delete, add Delete Melody

This commit is contained in:
Matthias Neeracher 2007-05-07 04:01:29 +00:00
parent 93d835d975
commit 07c3318006
5 changed files with 1083 additions and 1051 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -2259,8 +2259,16 @@ void VLSong::PasteMeasures(size_t beginMeasure, const VLSong & measures, int mod
} }
} }
void VLSong::DeleteMeasures(size_t beginMeasure, size_t endMeasure) void VLSong::DeleteMeasures(size_t beginMeasure, size_t endMeasure, int mode)
{ {
if (mode == kOverwriteMelody) {
VLLyricsNote rest(VLRest(fProperties.front().fTime));
for (size_t m=beginMeasure; m<endMeasure; ++m) {
fMeasures[m].fMelody.clear();
fMeasures[m].fMelody.push_back(rest);
}
return;
}
int8_t firstProp = fMeasures[beginMeasure].fPropIdx; int8_t firstProp = fMeasures[beginMeasure].fPropIdx;
int8_t lastProp = fMeasures[endMeasure-1].fPropIdx+1; int8_t lastProp = fMeasures[endMeasure-1].fPropIdx+1;
@ -2268,6 +2276,8 @@ void VLSong::DeleteMeasures(size_t beginMeasure, size_t endMeasure)
++firstProp; ++firstProp;
if (endMeasure < CountMeasures() && fMeasures[endMeasure].fPropIdx == lastProp) if (endMeasure < CountMeasures() && fMeasures[endMeasure].fPropIdx == lastProp)
--lastProp; --lastProp;
if (lastProp - firstProp == fProperties.size())
++firstProp;
if (lastProp > firstProp) { if (lastProp > firstProp) {
fProperties.erase(fProperties.begin()+firstProp, fProperties.erase(fProperties.begin()+firstProp,
fProperties.begin()+lastProp); fProperties.begin()+lastProp);
@ -2300,6 +2310,11 @@ void VLSong::DeleteMeasures(size_t beginMeasure, size_t endMeasure)
++r; ++r;
} }
} }
//
// Keep an empty meausure at the end
//
if (!EmptyEnding())
AddMeasure();
} }
VLFract VLSong::TiedDuration(size_t measure) VLFract VLSong::TiedDuration(size_t measure)

View File

@ -352,7 +352,7 @@ struct VLSong {
VLSong CopyMeasures(size_t beginMeasure, size_t endMeasure); VLSong CopyMeasures(size_t beginMeasure, size_t endMeasure);
void PasteMeasures(size_t beginMeasure, const VLSong & measures, void PasteMeasures(size_t beginMeasure, const VLSong & measures,
int mode = kInsert); int mode = kInsert);
void DeleteMeasures(size_t beginMeasure, size_t endMeasure); void DeleteMeasures(size_t beginMeasure, size_t endMeasure, int mode = kInsert);
size_t CountMeasures() const { return fMeasures.size(); } size_t CountMeasures() const { return fMeasures.size(); }
size_t EmptyEnding() const; size_t EmptyEnding() const;

View File

@ -136,7 +136,7 @@ static VLSong sPasteboard;
- (IBAction)delete:(id)sender - (IBAction)delete:(id)sender
{ {
[[self document] willChangeSong]; [[self document] willChangeSong];
[self song]->DeleteMeasures(fSelStart, fSelEnd); [self song]->DeleteMeasures(fSelStart, fSelEnd, [sender tag]);
[[self document] didChangeSong]; [[self document] didChangeSong];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }