From f3acce05fa2fbdd429ab2c40aa65f5a63b1a813e Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Thu, 8 Sep 2011 04:10:49 +0200 Subject: [PATCH] Implement Insert Measure --- English.lproj/MainMenu.xib | 233 ++++++++++++++++++++++++-------- Sources/VLModel.cpp | 40 ++++++ Sources/VLModel.h | 1 + Sources/VLSheetViewSelection.h | 1 + Sources/VLSheetViewSelection.mm | 10 ++ 5 files changed, 225 insertions(+), 60 deletions(-) diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index aa742cc..b319c31 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -2,10 +2,10 @@ 1070 - 11B26 + 11C48 1617 - 1138 - 566.00 + 1138.18 + 567.00 com.apple.InterfaceBuilder.CocoaPlugin 1617 @@ -417,6 +417,15 @@ 3 + + + Insert Measure + i + 1048576 + 2147483647 + + + Delete @@ -2173,6 +2182,14 @@ 100332 + + + insertMeasure: + + + + 100334 + @@ -2491,6 +2508,7 @@ + @@ -3132,6 +3150,11 @@ + + 100333 + + + @@ -3197,6 +3220,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3293,7 +3317,7 @@ - 100332 + 100334 @@ -3501,60 +3525,41 @@ VLDocument NSDocument - - id - id - id - id - id - id - id - id - id - - - - adjustTempo: - id - - + + dump: + id + + + dump: + dump: id - - play: - id - - - playMusic: - id - - - playStop: - id - - - showLog: - id - - - showOutput: - id - - - stop: - id - - - togglePlayElements: - id - - + IBProjectSource ./Classes/VLDocument.h + + VLLogWindow + NSWindowController + + log + id + + + log + + log + id + + + + IBProjectSource + ./Classes/VLLogWindow.h + + VLMirrorWindow NSWindowController @@ -3574,6 +3579,28 @@ ./Classes/VLMirrorWindow.h + + VLPDFWindow + NSWindowController + + PDFView + NSWindowController + + + + pdfView + PDFView + + + sheetWin + NSWindowController + + + + IBProjectSource + ./Classes/VLPDFWindow.h + + VLSheetView NSView @@ -3581,13 +3608,13 @@ id id id - id id id id id id id + id id id id @@ -3595,6 +3622,8 @@ id id id + id + id @@ -3609,10 +3638,6 @@ delete: id - - editDisplayOptions: - id - editRepeat: id @@ -3637,6 +3662,10 @@ insertJumpToCoda: id + + insertMeasure: + id + insertStartCoda: id @@ -3665,9 +3694,16 @@ transposeOctave: id + + zoomIn: + id + + + zoomOut: + id + - id id id id @@ -3679,10 +3715,6 @@ id - - fDisplaySheet - id - fDivisionMenu id @@ -3725,6 +3757,87 @@ ./Classes/VLSheetView.h + + VLSheetWindow + NSWindowController + + id + id + id + id + id + id + id + id + + + + adjustTempo: + id + + + playMusic: + id + + + playStop: + id + + + showOutput: + id + + + stop: + id + + + togglePlayElements: + id + + + zoomIn: + id + + + zoomOut: + id + + + + NSWindow + VLLogWindow + VLPDFWindow + NSProgressIndicator + VLSheetView + + + + displaySheet + NSWindow + + + logWin + VLLogWindow + + + pdfWin + VLPDFWindow + + + progressIndicator + NSProgressIndicator + + + sheetView + VLSheetView + + + + IBProjectSource + ./Classes/VLSheetWindow.h + + 0 diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index 447801f..e4f0adf 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -418,6 +418,46 @@ void VLSong::AddMeasure() fMeasures.push_back(meas); } +void VLSong::InsertMeasure(size_t beginMeasure) +{ + if (beginMeasure == fMeasures.size()) { + AddMeasure(); + } else { + VLSong insertion(false); + VLFraction dur = Properties(beginMeasure).fTime; + dur.Normalize(); + VLChord rchord(dur); + VLLyricsNote note(dur); + + VLLyricsNote nextNote = fMeasures[beginMeasure].fMelody.front(); + if (nextNote.fTied & VLNote::kTiedWithPrev) { + note.fPitch = nextNote.fPitch; + note.fVisual= nextNote.fVisual & VLNote::kAccidentalsMask; + note.fTied = VLNote::kTiedWithPrev|VLNote::kTiedWithNext; + } + + VLMeasure meas; + meas.fPropIdx = fMeasures[beginMeasure].fPropIdx; + meas.fChords.push_back(rchord); + meas.fMelody.push_back(note); + fMeasures.insert(fMeasures.begin()+beginMeasure, meas); + + for (size_t r=0; r= beginMeasure) + ++repeat.fEndings[e].fBegin; + if (repeat.fEndings[e].fEnd >= beginMeasure) + ++repeat.fEndings[e].fEnd; + } + } + if (fGoToCoda >= (int)beginMeasure) + ++fGoToCoda; + if (fCoda >= (int)beginMeasure) + ++fCoda; + } +} + void VLSong::SetProperties(size_t measure, int propIdx) { VLFraction dur = fProperties[propIdx].fTime; diff --git a/Sources/VLModel.h b/Sources/VLModel.h index 09a222c..4fecec9 100644 --- a/Sources/VLModel.h +++ b/Sources/VLModel.h @@ -407,6 +407,7 @@ public: void PasteMeasures(size_t beginMeasure, const VLSong & measures, int mode = kInsert); void DeleteMeasures(size_t beginMeasure, size_t endMeasure, int mode = kInsert); + void InsertMeasure(size_t beginMeasure); size_t CountMeasures() const { return fMeasures.size(); } size_t EmptyEnding() const; size_t CountStanzas() const; diff --git a/Sources/VLSheetViewSelection.h b/Sources/VLSheetViewSelection.h index 61be7ba..d994014 100644 --- a/Sources/VLSheetViewSelection.h +++ b/Sources/VLSheetViewSelection.h @@ -21,6 +21,7 @@ - (IBAction)copy:(id)sender; - (IBAction)paste:(id)sender; - (IBAction)delete:(id)sender; +- (IBAction)insertMeasure:(id)sender; - (IBAction)editRepeat:(id)sender; - (IBAction)editRepeatEnding:(id)sender; diff --git a/Sources/VLSheetViewSelection.mm b/Sources/VLSheetViewSelection.mm index a12624e..9b6ff08 100644 --- a/Sources/VLSheetViewSelection.mm +++ b/Sources/VLSheetViewSelection.mm @@ -225,6 +225,8 @@ VLSequenceCallback( && [self song]->CanBeEnding(fSelStart, fSelEnd); else if (action == @selector(paste:)) return fSelStart <= fSelEnd; + else if (action == @selector(insertMeasure:)) + return fSelStart == fSelEnd; else return YES; } @@ -269,6 +271,14 @@ VLSequenceCallback( [self setNeedsDisplay:YES]; } +- (IBAction)insertMeasure:(id)sender +{ + [[self document] willChangeSong]; + [self song]->InsertMeasure(fSelStart); + [[self document] didChangeSong]; + [self setNeedsDisplay:YES]; +} + - (IBAction)editRepeat:(id)sender { int volta;