Track tempo while playing

This commit is contained in:
Matthias Neeracher 2008-07-06 11:07:41 +00:00
parent 0a71cc8cae
commit b68fc2dd5a
2 changed files with 18 additions and 3 deletions

View File

@ -53,6 +53,7 @@ enum {
PDFDocument * printDoc;
NSRange previewRange;
float playRate;
float baseTempo;
}
- (VLSong *) song;

View File

@ -80,6 +80,7 @@
songArranger = @"";
songGroove = @"Swing";
songTempo = [[NSNumber alloc] initWithInt:120];
baseTempo = 120.0f;
chordSize = 6.0f;
lyricSize = 0.0f;
staffSize = 20.0f;
@ -266,6 +267,16 @@
[self didChangeSong];
}
- (void) setSongTempo:(int)tempo
{
[self willChangeSong];
[songTempo autorelease];
songTempo = [[NSNumber numberWithInt:tempo] retain];
if (VLSoundOut::Instance()->Playing())
VLSoundOut::Instance()->SetPlayRate(playRate*tempo/baseTempo);
[self didChangeSong];
}
- (void) setGroove:(NSString *)groove inSections:(NSRange)sections
{
const char * grv = [groove UTF8String];
@ -525,6 +536,8 @@
hasMusicSequence = true;
[sheetWin willPlaySequence:music];
baseTempo = [songTempo floatValue];
VLSoundOut::Instance()->SetPlayRate(playRate);
VLSoundOut::Instance()->PlaySequence(music);
}
}
@ -569,6 +582,7 @@
const float kUpScale = 1.1f;
const float kDownScale = 1.0f/kUpScale;
bool nowPlaying = VLSoundOut::Instance()->Playing();
const float tempoRate = [songTempo floatValue] / baseTempo;
switch (int tag = [sender tag]) {
case 0: // Play
VLSoundOut::Instance()->SetPlayRate(playRate = 1.0f);
@ -587,7 +601,7 @@
playRate *= kUpScale;
else
playRate *= kDownScale;
VLSoundOut::Instance()->SetPlayRate(playRate);
VLSoundOut::Instance()->SetPlayRate(playRate*tempoRate);
break;
case -2: // To Start
VLSoundOut::Instance()->SetTime(0);