From b68fc2dd5afc223d339097e72831d73920b9cd81 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sun, 6 Jul 2008 11:07:41 +0000 Subject: [PATCH] Track tempo while playing --- Sources/VLDocument.h | 1 + Sources/VLDocument.mm | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sources/VLDocument.h b/Sources/VLDocument.h index 11b18b4..6a33d7e 100644 --- a/Sources/VLDocument.h +++ b/Sources/VLDocument.h @@ -53,6 +53,7 @@ enum { PDFDocument * printDoc; NSRange previewRange; float playRate; + float baseTempo; } - (VLSong *) song; diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index a081a5c..2e92a4e 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -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]; @@ -523,8 +534,10 @@ VLMIDIWriter annotate(music, countIn); annotate.Visit(*song); - hasMusicSequence = true; + hasMusicSequence = true; [sheetWin willPlaySequence:music]; + baseTempo = [songTempo floatValue]; + VLSoundOut::Instance()->SetPlayRate(playRate); VLSoundOut::Instance()->PlaySequence(music); } } @@ -568,7 +581,8 @@ const float kMinRate = 0.2f; const float kUpScale = 1.1f; 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]) { 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);