Fixed accidental handling in songs with key changes

This commit is contained in:
Matthias Neeracher 2008-04-17 01:18:25 +00:00
parent 2d33c80489
commit 3126ae3b03
3 changed files with 27 additions and 16 deletions

View File

@ -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;

View File

@ -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

View File

@ -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];
}