From 74cb6433b4f6345f402398760044b1a98ccda274 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sun, 6 Jul 2008 11:07:57 +0000 Subject: [PATCH] Restart play when at end --- Sources/VLDocument.mm | 4 ++++ Sources/VLSoundOut.cpp | 9 ++++++++- Sources/VLSoundOut.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index 2e92a4e..cbf434d 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -588,6 +588,8 @@ VLSoundOut::Instance()->SetPlayRate(playRate = 1.0f); if (!nowPlaying) [self play:sender]; + else if (VLSoundOut::Instance()->AtEnd()) + VLSoundOut::Instance()->SetTime(0); break; case 1: // Fwd case -1: // Rew @@ -604,6 +606,8 @@ VLSoundOut::Instance()->SetPlayRate(playRate*tempoRate); break; case -2: // To Start + if (playRate < 0) + VLSoundOut::Instance()->SetPlayRate(playRate = -playRate); VLSoundOut::Instance()->SetTime(0); break; case 2: // To End diff --git a/Sources/VLSoundOut.cpp b/Sources/VLSoundOut.cpp index ef0052c..717aadf 100644 --- a/Sources/VLSoundOut.cpp +++ b/Sources/VLSoundOut.cpp @@ -29,6 +29,7 @@ public: virtual void PlaySequence(MusicSequence music); virtual void Stop(bool pause); virtual bool Playing(); + virtual bool AtEnd(); virtual void SetPlayRate(float rate); virtual void SetTime(MusicTimeStamp time); @@ -218,7 +219,6 @@ void VLAUSoundOut::SetPlayRate(float rate) void VLAUSoundOut::SetTime(MusicTimeStamp time) { - SetPlayRate(1.0f); MusicPlayerSetTime(fPlayer, time); } @@ -238,6 +238,13 @@ bool VLAUSoundOut::Playing() return fRunning; } +bool VLAUSoundOut::AtEnd() +{ + MusicTimeStamp time; + + return !MusicPlayerGetTime(fPlayer, &time) && time >= fMusicLength; +} + void VLAUSoundOut::PlayNote(const VLNote & note) { Play(¬e.fPitch); diff --git a/Sources/VLSoundOut.h b/Sources/VLSoundOut.h index 88571e2..6f7c7f4 100644 --- a/Sources/VLSoundOut.h +++ b/Sources/VLSoundOut.h @@ -41,6 +41,7 @@ public: virtual void PlaySequence(MusicSequence music) = 0; virtual void Stop(bool pause=true) = 0; virtual bool Playing() = 0; + virtual bool AtEnd() = 0; virtual void SetPlayRate(float rate) = 0; virtual void SetTime(MusicTimeStamp time) = 0;