From 5468cf0394f95d3fcdf95acb5760a82c9fb8cc47 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sat, 10 Sep 2011 23:33:40 +0200 Subject: [PATCH] Refactor lyrics selection system --- Sources/VLSheetView.h | 7 +++--- Sources/VLSheetView.mm | 2 -- Sources/VLSheetViewLyrics.h | 5 ++-- Sources/VLSheetViewLyrics.mm | 42 ++++++++++++++++++++------------- Sources/VLSheetViewSelection.mm | 4 +++- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Sources/VLSheetView.h b/Sources/VLSheetView.h index f87c9dc..154ea20 100644 --- a/Sources/VLSheetView.h +++ b/Sources/VLSheetView.h @@ -95,11 +95,12 @@ enum VLCursorVisual { size_t fVolta; size_t fVoltaOK; VLLayout * fLayout; - int fHighlightMeasure; - VLFract fHighlightAt; + int fHighlightStartMeasure; + VLFract fHighlightStartAt; + int fHighlightEndMeasure; + VLFract fHighlightEndAt; size_t fHighlightStanza; bool fHighlightNow; - bool fHighlightOne; VLKeyValueUndo * fUndo; IBOutlet id fFieldEditor; diff --git a/Sources/VLSheetView.mm b/Sources/VLSheetView.mm index c87e1e9..d2609a1 100644 --- a/Sources/VLSheetView.mm +++ b/Sources/VLSheetView.mm @@ -109,7 +109,6 @@ static float sFlatPos[] = { fNumBotLedgers = 2; fNumStanzas = 2; fLastMeasures = 0; - fHighlightOne = false; fUndo = [[VLKeyValueUndo alloc] initWithOwner:self keysAndNames:[NSDictionary dictionaryWithObjectsAndKeys: @@ -922,7 +921,6 @@ const float kSemiFloor = -1.0f*kLineH; default: [editable autorelease]; fHighlightStanza = 0xFFFFFFFF; - fHighlightOne = false; editable = nil; } [self setEditTarget:editable]; diff --git a/Sources/VLSheetViewLyrics.h b/Sources/VLSheetViewLyrics.h index 0a9a465..7e0c3e4 100644 --- a/Sources/VLSheetViewLyrics.h +++ b/Sources/VLSheetViewLyrics.h @@ -5,7 +5,7 @@ // // (MN) Matthias Neeracher // -// Copyright © 2006-2007 Matthias Neeracher +// Copyright © 2006-2011 Matthias Neeracher // #import "VLSheetWindow.h" @@ -39,7 +39,8 @@ - (void) editLyrics; - (void) drawLyricsForSystem:(int)system stanza:(size_t)stanza; - (void) highlightLyricsInStanza:(size_t)stanza measure:(int)measure at:(VLFraction)at; -- (void) highlightTextInStanza:(size_t)stanza measure:(int)measure at:(VLFraction)at one:(BOOL)one; +- (void) highlightTextInStanza:(size_t)stanza startMeasure:(int)startMeasure at:(VLFraction)startAt + endMeasure:(int)endMeasure at:(VLFraction)endAt; @end diff --git a/Sources/VLSheetViewLyrics.mm b/Sources/VLSheetViewLyrics.mm index ad54b4f..5c9ebdc 100644 --- a/Sources/VLSheetViewLyrics.mm +++ b/Sources/VLSheetViewLyrics.mm @@ -18,6 +18,14 @@ @implementation VLLyricsEditable +- (void)highlightWord +{ + size_t endMeas = fMeasure; + VLFraction endAt = fAt; + fSong->NextWord(fStanza, endMeas, endAt); + [fView highlightTextInStanza:fStanza startMeasure:fMeasure at:fAt endMeasure:endMeas at:endAt]; +} + - (VLLyricsEditable *)initWithView:(VLSheetView *)view song:(VLSong *)song stanza:(int)stanza @@ -36,9 +44,7 @@ VLFraction At = fAt; fSong->FindWord(fStanza, fMeasure, At); fAt = At; - [fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; - - [fView setNeedsDisplay: YES]; + [self highlightWord]; return self; } @@ -79,7 +85,7 @@ } fNextMeas = fMeasure; fNextAt = fAt; - [fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; + [self highlightWord]; [fView scrollMeasureToVisible:fMeasure]; } @@ -94,7 +100,7 @@ fAt = at; fNextMeas = fMeasure; fNextAt = fAt; - [fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; + [self highlightWord]; [fView scrollMeasureToVisible:fMeasure]; } @@ -188,19 +194,21 @@ float VLCocoaFontHandler::Width(const char * utf8Text) } else { if (!fHighlightNow) { fHighlightNow = stanza == fHighlightStanza - && measIdx == fHighlightMeasure - && at == fHighlightAt; + && measIdx == fHighlightStartMeasure + && at == fHighlightStartAt; if (fHighlightNow && !sHighlightColor) sHighlightColor = [[self textBackgroundColorForSystem:system] shadowWithLevel:0.2]; - } + } else { + fHighlightNow = fHighlightNow && stanza == fHighlightStanza + && (measIdx < fHighlightEndMeasure + ||(measIdx == fHighlightEndMeasure && at < fHighlightEndAt)); + } text.AddSyllable(note->fLyrics[stanza-1], [self noteXInMeasure:measIdx at:at], fHighlightNow); - fHighlightNow = fHighlightNow && !fHighlightOne && - note->fLyrics[stanza-1].fKind & VLSyllable::kHasNext; } at += note->fDuration; } @@ -233,13 +241,15 @@ float VLCocoaFontHandler::Width(const char * utf8Text) NSRectFillUsingOperation(r, NSCompositePlusDarker); } -- (void) highlightTextInStanza:(size_t)stanza measure:(int)measure at:(VLFraction)at one:(BOOL)one +- (void) highlightTextInStanza:(size_t)stanza startMeasure:(int)startMeasure at:(VLFraction)startAt + endMeasure:(int)endMeasure at:(VLFraction)endAt { - fHighlightStanza = stanza; - fHighlightMeasure= measure; - fHighlightAt = at; - fHighlightNow = false; - fHighlightOne = one; + fHighlightStanza = stanza; + fHighlightStartMeasure = startMeasure; + fHighlightStartAt = startAt; + fHighlightEndMeasure = endMeasure; + fHighlightEndAt = endAt; + fHighlightNow = false; } @end diff --git a/Sources/VLSheetViewSelection.mm b/Sources/VLSheetViewSelection.mm index 9b6ff08..a9d8f81 100644 --- a/Sources/VLSheetViewSelection.mm +++ b/Sources/VLSheetViewSelection.mm @@ -58,7 +58,9 @@ else fNoteVert = VLPitchToGrid(event->fPitch, fNoteVisual, [fView song]->Properties(fNoteMeasure).fKey); fStanza = event->fStanza; - [fView highlightTextInStanza:fStanza measure:fNoteMeasure at:fNoteAt one:YES]; + VLFraction endAt= fNoteAt+VLFraction(1,128); + [fView highlightTextInStanza:fStanza startMeasure:fNoteMeasure at:fNoteAt + endMeasure:fNoteMeasure at:endAt]; } else { fChordMeasure = event->fMeasure; fChordAt = event->fAt;