Draw triplet brackets

This commit is contained in:
Matthias Neeracher 2009-03-14 23:06:13 +00:00
parent 9459873006
commit d8fd57b94a
2 changed files with 56 additions and 12 deletions

View File

@ -10,6 +10,7 @@
const float kLineX = 5.0; const float kLineX = 5.0;
const float kLineH = 10.0; const float kLineH = 10.0;
const float kTripletH = 5.0;
#define kSystemBaseline ((fNumBotLedgers+1)*kLineH+fNumStanzas*kLyricsH) #define kSystemBaseline ((fNumBotLedgers+1)*kLineH+fNumStanzas*kLyricsH)
#define kSystemAscent ((fNumTopLedgers+7)*kLineH+kChordH) #define kSystemAscent ((fNumTopLedgers+7)*kLineH+kChordH)
#define kSystemH (kSystemBaseline+kSystemAscent) #define kSystemH (kSystemBaseline+kSystemAscent)

View File

@ -312,14 +312,41 @@
operation: NSCompositeSourceOver]; operation: NSCompositeSourceOver];
} }
- (void) drawTripletBracketFrom:(int)startX to:(int)endX atY:(int)y
{
static NSDictionary * sTripletFont = nil;
if (!sTripletFont)
sTripletFont =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont fontWithName: @"Helvetica" size: 12],
NSFontAttributeName,
nil];
NSBezierPath * bz = [NSBezierPath bezierPath];
[bz moveToPoint: NSMakePoint(startX, y-kTripletH)];
[bz lineToPoint: NSMakePoint(startX, y)];
[bz lineToPoint: NSMakePoint(endX, y)];
[bz lineToPoint: NSMakePoint(endX, y-kTripletH)];
[bz stroke];
[@"3" drawAtPoint: NSMakePoint((startX+endX)*0.5f, y+kTripletH)
withAttributes: sTripletFont];
}
- (void) drawNotesForSystem:(int)system - (void) drawNotesForSystem:(int)system
{ {
const int kFirstMeas = fLayout->FirstMeasure(system); const int kFirstMeas = fLayout->FirstMeasure(system);
const VLSong * song = [self song]; const VLSong * song = [self song];
const VLProperties & kProp = song->Properties(kFirstMeas); const VLProperties & kProp = song->Properties(kFirstMeas);
const VLSystemLayout & kLayout = (*fLayout)[system]; const VLSystemLayout & kLayout = (*fLayout)[system];
const float kSystemY = [self systemY:system];
float tripletStartX;
float tripletEndX;
float tripletY;
bool hasTriplets = false;
float kSystemY = [self systemY:system];
for (int m = 0; m<kLayout.NumMeasures(); ++m) { for (int m = 0; m<kLayout.NumMeasures(); ++m) {
VLMusicElement accidentals[7]; VLMusicElement accidentals[7];
memset(accidentals, 0, 7*sizeof(VLMusicElement)); memset(accidentals, 0, 7*sizeof(VLMusicElement));
@ -337,18 +364,18 @@
BOOL tied = (note != melody.begin() || m) BOOL tied = (note != melody.begin() || m)
&& note->fTied & VLNote::kTiedWithPrev; && note->fTied & VLNote::kTiedWithPrev;
int pitch = note->fPitch; int pitch = note->fPitch;
NSPoint pos;
if (pitch != VLNote::kNoPitch) { if (pitch != VLNote::kNoPitch) {
[self drawLedgerLinesInSection:measure.fPropIdx withPitch:pitch [self drawLedgerLinesInSection:measure.fPropIdx withPitch:pitch
visual:note->fVisual visual:note->fVisual
at:NSMakePoint([self noteXInMeasure:measIdx at:at], at:NSMakePoint([self noteXInMeasure:measIdx at:at],
kSystemY)]; kSystemY)];
VLMusicElement accidental; VLMusicElement accidental;
NSPoint pos = pos = NSMakePoint([self noteXInMeasure:measIdx at:at],
NSMakePoint([self noteXInMeasure:measIdx at:at], kSystemY+[self noteYInSection:measure.fPropIdx
kSystemY+[self noteYInSection:measure.fPropIdx withPitch:pitch
withPitch:pitch visual:note->fVisual
visual:note->fVisual accidental:&accidental]);
accidental:&accidental]);
VLMusicElement acc = accidental; VLMusicElement acc = accidental;
int step= [self stepInSection:measure.fPropIdx int step= [self stepInSection:measure.fPropIdx
withPitch:pitch withPitch:pitch
@ -367,16 +394,32 @@
accidentals[step] = accidental; accidentals[step] = accidental;
} else { } else {
VLMusicElement accidental; VLMusicElement accidental;
NSPoint pos = pos = NSMakePoint([self noteXInMeasure:measIdx at:at],
NSMakePoint([self noteXInMeasure:measIdx at:at], kSystemY+[self noteYInSection:measure.fPropIdx
kSystemY+[self noteYInSection:measure.fPropIdx withPitch:65 visual:0
withPitch:65 visual:0 accidental:&accidental]);
accidental:&accidental]);
[self drawRest:note->fVisual & VLNote::kNoteHead at: pos]; [self drawRest:note->fVisual & VLNote::kNoteHead at: pos];
} }
if (note->fVisual & VLNote::kTriplet) {
tripletEndX = pos.x+kNoteW*0.5f;
if (hasTriplets) {
tripletY = std::max(tripletY, pos.y+kLineH);
} else {
tripletY = std::max(kSystemY+5.0f*kLineH, pos.y+kLineH);
tripletStartX = pos.x-kNoteW*0.5f;
hasTriplets = true;
}
} else if (hasTriplets) {
[self drawTripletBracketFrom:tripletStartX to:tripletEndX atY:tripletY];
hasTriplets = false;
}
at += note->fDuration; at += note->fDuration;
} }
} }
if (hasTriplets) {
[self drawTripletBracketFrom:tripletStartX to:tripletEndX atY:tripletY];
}
if (fCursorPitch != VLNote::kNoPitch && fLayout->SystemForMeasure(fCursorMeasure) == system) if (fCursorPitch != VLNote::kNoPitch && fLayout->SystemForMeasure(fCursorMeasure) == system)
[self drawNoteCursor]; [self drawNoteCursor];
} }