From 3126ae3b039fe83df1142cbf79db7a376891cc54 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Thu, 17 Apr 2008 01:18:25 +0000 Subject: [PATCH] Fixed accidental handling in songs with key changes --- Sources/VLSheetView.h | 4 ++-- Sources/VLSheetView.mm | 20 +++++++++++++------- Sources/VLSheetViewNotes.mm | 19 ++++++++++++------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Sources/VLSheetView.h b/Sources/VLSheetView.h index 35481cc..29db3e0 100644 --- a/Sources/VLSheetView.h +++ b/Sources/VLSheetView.h @@ -109,9 +109,9 @@ enum VLRecalc { - (VLSong *) song; - (NSImage *) musicElement:(VLMusicElement)elt; -- (int) stepWithPitch:(int)pitch; +- (int) stepInSection:(int)section withPitch:(int)pitch; - (float) systemY:(int)system; -- (float) noteYWithPitch:(int)pitch accidental:(VLMusicElement*)accidental; +- (float) noteYInSection:(int)section withPitch:(int)pitch accidental:(VLMusicElement*)accidental; - (float) noteYInMeasure:(int)measure withPitch:(int)pitch accidental:(VLMusicElement*)accidental; - (float) noteXInMeasure:(int)measure at:(VLFraction)at; diff --git a/Sources/VLSheetView.mm b/Sources/VLSheetView.mm index 7366c80..78acd6b 100644 --- a/Sources/VLSheetView.mm +++ b/Sources/VLSheetView.mm @@ -173,30 +173,33 @@ VLMusicElement sSemi2Accidental[12][12] = { #undef N #undef _ -- (int) stepWithPitch:(int)pitch +- (int) stepInSection:(int)section withPitch:(int)pitch { int semi = pitch % 12; - int key = [self song]->fProperties.front().fKey; + int key = [self song]->fProperties[section].fKey; bool useSharps = key > 0; return sSemi2Pitch[useSharps][semi]; } -- (float) noteYWithPitch:(int)pitch accidental:(VLMusicElement*)accidental +- (float) noteYInSection:(int)section + withPitch:(int)pitch accidental:(VLMusicElement*)accidental { int semi = pitch % 12; int octave = (pitch / 12) - 5; - int key = [self song]->fProperties.front().fKey; + int key = [self song]->fProperties[section].fKey; *accidental = sSemi2Accidental[key+6][semi]; - return (octave*3.5f+[self stepWithPitch:pitch]*0.5f-1.0f)*kLineH; + return (octave*3.5f + + [self stepInSection:section withPitch:pitch]*0.5f-1.0f)*kLineH; } - (float) noteYInMeasure:(int)measure withPitch:(int)pitch accidental:(VLMusicElement*)accidental { return [self systemY:fLayout->SystemForMeasure(measure)] - + [self noteYWithPitch:pitch accidental:accidental]; + + [self noteYInSection:[self song]->fMeasures[measure].fPropIdx + withPitch:pitch accidental:accidental]; } - (float) noteXInMeasure:(int)measure at:(VLFraction)at @@ -716,7 +719,10 @@ static int8_t sSharpAcc[] = { fCursorAccidental = kMusicExtendCursor; return; } - const VLProperties & prop = [self song]->fProperties.front(); + int cursorSection = + [self song]->fMeasures[fCursorMeasure].fPropIdx; + const VLProperties & prop = + [self song]->fProperties[cursorSection]; if (prop.fKey >= 0) { if (prop.fKey >= sSharpAcc[fCursorPitch % 12]) { // Sharp in Key diff --git a/Sources/VLSheetViewNotes.mm b/Sources/VLSheetViewNotes.mm index af82fe9..1d5cd2c 100644 --- a/Sources/VLSheetViewNotes.mm +++ b/Sources/VLSheetViewNotes.mm @@ -49,11 +49,11 @@ } } -- (void) drawLedgerLinesWithPitch:(int)pitch at:(NSPoint)p +- (void) drawLedgerLinesInSection:(int)section withPitch:(int)pitch at:(NSPoint)p { p.x += kLedgerX; int octave = (pitch / 12) - 5; - int step = (octave*7+[self stepWithPitch:pitch]-2)/2; + int step = (octave*7+[self stepInSection:section withPitch:pitch]-2)/2; for (int i=0; i-- > step; ) { NSPoint p0 = p; @@ -75,6 +75,7 @@ { int cursorX; int cursorY; + int cursorSect; VLMusicElement accidental; VLMusicElement cursorElt; @@ -91,7 +92,8 @@ cursorY = [self noteYInMeasure:fCursorMeasure withPitch:fCursorPitch accidental:&accidental] - kNoteY; - [self drawLedgerLinesWithPitch:fCursorPitch + cursorSect = [self song]->fMeasures[fCursorMeasure].fPropIdx; + [self drawLedgerLinesInSection:cursorSect withPitch:fCursorPitch at:NSMakePoint(cursorX, [self systemY:fLayout->SystemForMeasure(fCursorMeasure)])]; cursorElt = kMusicNoteCursor; @@ -301,15 +303,17 @@ && note->fTied & VLNote::kTiedWithPrev; int pitch = note->fPitch; if (pitch != VLNote::kNoPitch) { - [self drawLedgerLinesWithPitch:pitch + [self drawLedgerLinesInSection:measure.fPropIdx withPitch:pitch at:NSMakePoint([self noteXInMeasure:measIdx at:at], kSystemY)]; VLMusicElement accidental; NSPoint pos = NSMakePoint([self noteXInMeasure:measIdx at:at], - kSystemY+[self noteYWithPitch:pitch + kSystemY+[self noteYInSection:measure.fPropIdx + withPitch:pitch accidental:&accidental]); VLMusicElement acc = accidental; - int step= [self stepWithPitch:pitch]; + int step= [self stepInSection:measure.fPropIdx + withPitch:pitch]; if (acc == accidentals[step]) acc = kMusicNothing; // Don't repeat accidentals else if (acc == kMusicNothing) @@ -326,7 +330,8 @@ VLMusicElement accidental; NSPoint pos = NSMakePoint([self noteXInMeasure:measIdx at:at], - kSystemY+[self noteYWithPitch:65 + kSystemY+[self noteYInSection:measure.fPropIdx + withPitch:65 accidental:&accidental]); [self drawRest:note->fVisual & VLNote::kNoteHead at: pos]; }