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; PDFDocument * printDoc;
NSRange previewRange; NSRange previewRange;
float playRate; float playRate;
float baseTempo;
} }
- (VLSong *) song; - (VLSong *) song;

View File

@ -80,6 +80,7 @@
songArranger = @""; songArranger = @"";
songGroove = @"Swing"; songGroove = @"Swing";
songTempo = [[NSNumber alloc] initWithInt:120]; songTempo = [[NSNumber alloc] initWithInt:120];
baseTempo = 120.0f;
chordSize = 6.0f; chordSize = 6.0f;
lyricSize = 0.0f; lyricSize = 0.0f;
staffSize = 20.0f; staffSize = 20.0f;
@ -266,6 +267,16 @@
[self didChangeSong]; [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 - (void) setGroove:(NSString *)groove inSections:(NSRange)sections
{ {
const char * grv = [groove UTF8String]; const char * grv = [groove UTF8String];
@ -523,8 +534,10 @@
VLMIDIWriter annotate(music, countIn); VLMIDIWriter annotate(music, countIn);
annotate.Visit(*song); annotate.Visit(*song);
hasMusicSequence = true; hasMusicSequence = true;
[sheetWin willPlaySequence:music]; [sheetWin willPlaySequence:music];
baseTempo = [songTempo floatValue];
VLSoundOut::Instance()->SetPlayRate(playRate);
VLSoundOut::Instance()->PlaySequence(music); VLSoundOut::Instance()->PlaySequence(music);
} }
} }
@ -568,7 +581,8 @@
const float kMinRate = 0.2f; const float kMinRate = 0.2f;
const float kUpScale = 1.1f; const float kUpScale = 1.1f;
const float kDownScale = 1.0f/kUpScale; const float kDownScale = 1.0f/kUpScale;
bool nowPlaying = VLSoundOut::Instance()->Playing(); bool nowPlaying = VLSoundOut::Instance()->Playing();
const float tempoRate = [songTempo floatValue] / baseTempo;
switch (int tag = [sender tag]) { switch (int tag = [sender tag]) {
case 0: // Play case 0: // Play
VLSoundOut::Instance()->SetPlayRate(playRate = 1.0f); VLSoundOut::Instance()->SetPlayRate(playRate = 1.0f);
@ -587,7 +601,7 @@
playRate *= kUpScale; playRate *= kUpScale;
else else
playRate *= kDownScale; playRate *= kDownScale;
VLSoundOut::Instance()->SetPlayRate(playRate); VLSoundOut::Instance()->SetPlayRate(playRate*tempoRate);
break; break;
case -2: // To Start case -2: // To Start
VLSoundOut::Instance()->SetTime(0); VLSoundOut::Instance()->SetTime(0);