Refactor lyrics selection system

This commit is contained in:
Matthias Neeracher 2011-09-10 23:33:40 +02:00
parent 5dbd60e9d4
commit 5468cf0394
5 changed files with 36 additions and 24 deletions

View File

@ -95,11 +95,12 @@ enum VLCursorVisual {
size_t fVolta; size_t fVolta;
size_t fVoltaOK; size_t fVoltaOK;
VLLayout * fLayout; VLLayout * fLayout;
int fHighlightMeasure; int fHighlightStartMeasure;
VLFract fHighlightAt; VLFract fHighlightStartAt;
int fHighlightEndMeasure;
VLFract fHighlightEndAt;
size_t fHighlightStanza; size_t fHighlightStanza;
bool fHighlightNow; bool fHighlightNow;
bool fHighlightOne;
VLKeyValueUndo * fUndo; VLKeyValueUndo * fUndo;
IBOutlet id fFieldEditor; IBOutlet id fFieldEditor;

View File

@ -109,7 +109,6 @@ static float sFlatPos[] = {
fNumBotLedgers = 2; fNumBotLedgers = 2;
fNumStanzas = 2; fNumStanzas = 2;
fLastMeasures = 0; fLastMeasures = 0;
fHighlightOne = false;
fUndo = [[VLKeyValueUndo alloc] fUndo = [[VLKeyValueUndo alloc]
initWithOwner:self initWithOwner:self
keysAndNames:[NSDictionary dictionaryWithObjectsAndKeys: keysAndNames:[NSDictionary dictionaryWithObjectsAndKeys:
@ -922,7 +921,6 @@ const float kSemiFloor = -1.0f*kLineH;
default: default:
[editable autorelease]; [editable autorelease];
fHighlightStanza = 0xFFFFFFFF; fHighlightStanza = 0xFFFFFFFF;
fHighlightOne = false;
editable = nil; editable = nil;
} }
[self setEditTarget:editable]; [self setEditTarget:editable];

View File

@ -5,7 +5,7 @@
// //
// (MN) Matthias Neeracher // (MN) Matthias Neeracher
// //
// Copyright © 2006-2007 Matthias Neeracher // Copyright © 2006-2011 Matthias Neeracher
// //
#import "VLSheetWindow.h" #import "VLSheetWindow.h"
@ -39,7 +39,8 @@
- (void) editLyrics; - (void) editLyrics;
- (void) drawLyricsForSystem:(int)system stanza:(size_t)stanza; - (void) drawLyricsForSystem:(int)system stanza:(size_t)stanza;
- (void) highlightLyricsInStanza:(size_t)stanza measure:(int)measure at:(VLFraction)at; - (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 @end

View File

@ -18,6 +18,14 @@
@implementation VLLyricsEditable @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 - (VLLyricsEditable *)initWithView:(VLSheetView *)view
song:(VLSong *)song song:(VLSong *)song
stanza:(int)stanza stanza:(int)stanza
@ -36,9 +44,7 @@
VLFraction At = fAt; VLFraction At = fAt;
fSong->FindWord(fStanza, fMeasure, At); fSong->FindWord(fStanza, fMeasure, At);
fAt = At; fAt = At;
[fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; [self highlightWord];
[fView setNeedsDisplay: YES];
return self; return self;
} }
@ -79,7 +85,7 @@
} }
fNextMeas = fMeasure; fNextMeas = fMeasure;
fNextAt = fAt; fNextAt = fAt;
[fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; [self highlightWord];
[fView scrollMeasureToVisible:fMeasure]; [fView scrollMeasureToVisible:fMeasure];
} }
@ -94,7 +100,7 @@
fAt = at; fAt = at;
fNextMeas = fMeasure; fNextMeas = fMeasure;
fNextAt = fAt; fNextAt = fAt;
[fView highlightTextInStanza:fStanza measure:fMeasure at:fAt one:NO]; [self highlightWord];
[fView scrollMeasureToVisible:fMeasure]; [fView scrollMeasureToVisible:fMeasure];
} }
@ -188,19 +194,21 @@ float VLCocoaFontHandler::Width(const char * utf8Text)
} else { } else {
if (!fHighlightNow) { if (!fHighlightNow) {
fHighlightNow = stanza == fHighlightStanza fHighlightNow = stanza == fHighlightStanza
&& measIdx == fHighlightMeasure && measIdx == fHighlightStartMeasure
&& at == fHighlightAt; && at == fHighlightStartAt;
if (fHighlightNow && !sHighlightColor) if (fHighlightNow && !sHighlightColor)
sHighlightColor = sHighlightColor =
[[self textBackgroundColorForSystem:system] [[self textBackgroundColorForSystem:system]
shadowWithLevel:0.2]; shadowWithLevel:0.2];
} } else {
fHighlightNow = fHighlightNow && stanza == fHighlightStanza
&& (measIdx < fHighlightEndMeasure
||(measIdx == fHighlightEndMeasure && at < fHighlightEndAt));
}
text.AddSyllable(note->fLyrics[stanza-1], text.AddSyllable(note->fLyrics[stanza-1],
[self noteXInMeasure:measIdx at:at], [self noteXInMeasure:measIdx at:at],
fHighlightNow); fHighlightNow);
fHighlightNow = fHighlightNow && !fHighlightOne &&
note->fLyrics[stanza-1].fKind & VLSyllable::kHasNext;
} }
at += note->fDuration; at += note->fDuration;
} }
@ -233,13 +241,15 @@ float VLCocoaFontHandler::Width(const char * utf8Text)
NSRectFillUsingOperation(r, NSCompositePlusDarker); 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; fHighlightStanza = stanza;
fHighlightMeasure= measure; fHighlightStartMeasure = startMeasure;
fHighlightAt = at; fHighlightStartAt = startAt;
fHighlightNow = false; fHighlightEndMeasure = endMeasure;
fHighlightOne = one; fHighlightEndAt = endAt;
fHighlightNow = false;
} }
@end @end

View File

@ -58,7 +58,9 @@
else else
fNoteVert = VLPitchToGrid(event->fPitch, fNoteVisual, [fView song]->Properties(fNoteMeasure).fKey); fNoteVert = VLPitchToGrid(event->fPitch, fNoteVisual, [fView song]->Properties(fNoteMeasure).fKey);
fStanza = event->fStanza; 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 { } else {
fChordMeasure = event->fMeasure; fChordMeasure = event->fMeasure;
fChordAt = event->fAt; fChordAt = event->fAt;