VocalEasel/Sources/VLSheetViewLyrics.mm

173 lines
3.7 KiB
Plaintext
Raw Normal View History

2006-12-02 03:35:21 +00:00
//
2007-04-27 06:41:34 +00:00
// File: VLSheetViewLyrics.mm - Lyrics editing functionality
2006-12-02 03:35:21 +00:00
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
// Copyright © 2006-2007 Matthias Neeracher
2006-12-02 03:35:21 +00:00
//
#import "VLSheetView.h"
#import "VLSheetViewLyrics.h"
#import "VLSheetViewInternal.h"
#import "VLDocument.h"
2006-12-02 03:35:21 +00:00
#import "VLModel.h"
#import "VLSoundOut.h"
@implementation VLLyricsEditable
- (VLLyricsEditable *)initWithView:(VLSheetView *)view
song:(VLSong *)song
2006-12-02 09:02:44 +00:00
stanza:(int)stanza
2006-12-02 03:35:21 +00:00
measure:(int)measure
at:(VLFract)at
{
2007-04-13 04:26:35 +00:00
self = [super init];
fView = view;
fSong = song;
fStanza = stanza;
fMeasure = measure;
fAt = at;
fNextMeas = fMeasure;
fNextAt = fAt;
2006-12-02 03:35:21 +00:00
2006-12-04 07:04:24 +00:00
VLFraction At = fAt;
fSong->FindWord(fStanza, fMeasure, At);
fAt = At;
2006-12-02 09:02:44 +00:00
2006-12-02 03:35:21 +00:00
[fView setNeedsDisplay: YES];
return self;
}
- (NSString *) stringValue
{
2006-12-02 09:02:44 +00:00
std::string word = fSong->GetWord(fStanza, fMeasure, fAt);
return [NSString stringWithUTF8String:word.c_str()];
2006-12-02 03:35:21 +00:00
}
- (void) setStringValue:(NSString *)val
{
2006-12-04 07:04:24 +00:00
[[fView document] willChangeSong];
2007-04-13 04:26:35 +00:00
fSong->SetWord(fStanza, fMeasure, fAt, [val UTF8String], &fNextMeas, &fNextAt);
2006-12-04 07:04:24 +00:00
[[fView document] didChangeSong];
2006-12-02 03:35:21 +00:00
}
- (BOOL) validValue:(NSString *)val
{
return YES;
}
- (void) moveToNext
2006-12-02 09:02:44 +00:00
{
2007-04-13 04:26:35 +00:00
if (fNextMeas != fMeasure || fNextAt != fAt) {
fMeasure = fNextMeas;
VLFraction at = fNextAt;
2006-12-04 07:04:24 +00:00
fSong->FindWord(fStanza, fMeasure, at);
2007-04-13 04:26:35 +00:00
fAt = at;
} else {
VLFraction at = fAt;
if (!fSong->NextWord(fStanza, fMeasure, at)) {
fMeasure = 0;
at = 0;
fSong->FindWord(fStanza, fMeasure, at);
}
fAt = at;
2006-12-02 09:02:44 +00:00
}
2007-04-13 04:26:35 +00:00
fNextMeas = fMeasure;
fNextAt = fAt;
2006-12-02 03:35:21 +00:00
}
- (void) moveToPrev
{
2006-12-04 07:04:24 +00:00
VLFraction at = fAt;
if (!fSong->PrevWord(fStanza, fMeasure, at)) {
2006-12-02 09:02:44 +00:00
fMeasure = fSong->CountMeasures()-1;
2006-12-04 07:04:24 +00:00
at = fSong->fProperties.front().fTime;
fSong->PrevWord(fStanza, fMeasure, at);
2006-12-02 09:02:44 +00:00
}
2006-12-04 07:04:24 +00:00
fAt = at;
2007-04-13 04:26:35 +00:00
fNextMeas = fMeasure;
fNextAt = fAt;
2006-12-02 03:35:21 +00:00
}
- (void) highlightCursor
{
2006-12-02 09:02:44 +00:00
[fView highlightLyricsInStanza:fStanza measure:fMeasure at:fAt];
2006-12-02 03:35:21 +00:00
}
@end
@implementation VLSheetView (Lyrics)
- (void) drawLyricsForSystem:(int)system stanza:(size_t)stanza
{
static NSDictionary * sLyricsFont = nil;
if (!sLyricsFont)
sLyricsFont =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont fontWithName: @"Helvetica" size: 12],
NSFontAttributeName,
nil];
const VLSong * song = [self song];
const float kSystemY = [self systemY:system];
//
// Build new list
//
for (int m = 0; m<fMeasPerSystem; ++m) {
int measIdx = m+system*fMeasPerSystem;
if (measIdx >= song->CountMeasures())
break;
const VLMeasure measure = song->fMeasures[measIdx];
const VLNoteList & notes = measure.fMelody;
VLFraction at(0);
for (VLNoteList::const_iterator note = notes.begin();
note != notes.end();
++note
) {
if (note->fLyrics.size() < stanza
|| !note->fLyrics[stanza-1].fText.size()
) {
;
} else {
NSString * syll =
[NSString stringWithUTF8String:
note->fLyrics[stanza-1].fText.c_str()];
NSSize sz =
[syll sizeWithAttributes:sLyricsFont];
NSPoint syllLoc =
2007-04-22 06:19:50 +00:00
NSMakePoint([self noteXInMeasure:m at:at]
- 0.5f*sz.width,
2006-12-02 03:35:21 +00:00
kSystemY+kLyricsY-stanza*kLyricsH);
if (note->fLyrics[stanza-1].fKind & VLSyllable::kHasNext)
syll = [syll stringByAppendingString:@" -"];
[syll drawAtPoint:syllLoc withAttributes:sLyricsFont];
}
at += note->fDuration;
}
}
}
- (void) editLyrics
{
VLEditable * e =
[[VLLyricsEditable alloc]
initWithView:self
song:[self song]
2006-12-02 09:02:44 +00:00
stanza:fCursorStanza
2006-12-02 03:35:21 +00:00
measure:fCursorMeasure
at:fCursorAt];
[self setEditTarget:e];
[fFieldEditor selectText:self];
}
2006-12-02 09:02:44 +00:00
- (void) highlightLyricsInStanza:(size_t)stanza measure:(int)measure at:(VLFraction)at
2006-12-02 03:35:21 +00:00
{
}
@end