mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
When using the CrossfadeTransport, fade music out if stopped (or the app is exited).
This commit is contained in:
parent
105a72457e
commit
eb175cd66c
@ -61,6 +61,7 @@ CrossfadeTransport::CrossfadeTransport()
|
||||
|
||||
CrossfadeTransport::~CrossfadeTransport() {
|
||||
this->Stop();
|
||||
this->crossfader.Drain();
|
||||
}
|
||||
|
||||
PlaybackState CrossfadeTransport::GetPlaybackState() {
|
||||
@ -93,9 +94,8 @@ void CrossfadeTransport::ReloadOutput() {
|
||||
void CrossfadeTransport::Stop() {
|
||||
{
|
||||
Lock lock(this->stateMutex);
|
||||
this->crossfader.Stop();
|
||||
this->active.Stop();
|
||||
this->next.Stop();
|
||||
this->active.Reset();
|
||||
this->next.Reset();
|
||||
}
|
||||
|
||||
this->SetPlaybackState(PlaybackStopped);
|
||||
|
@ -125,6 +125,18 @@ void Crossfader::Stop() {
|
||||
this->contextList.clear();
|
||||
}
|
||||
|
||||
void Crossfader::Drain() {
|
||||
LOCK(this->contextListLock);
|
||||
|
||||
if (this->contextList.size()) {
|
||||
for (FadeContextPtr context : this->contextList) {
|
||||
context->direction = FadeOut;
|
||||
}
|
||||
|
||||
this->drainCondition.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
void Crossfader::OnPlayerDestroying(Player* player) {
|
||||
if (player) {
|
||||
LOCK(this->contextListLock);
|
||||
@ -269,6 +281,7 @@ void Crossfader::ProcessMessage(IMessage &message) {
|
||||
}
|
||||
else {
|
||||
this->Emptied();
|
||||
this->drainCondition.notify_all();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -72,6 +72,7 @@ namespace musik { namespace core { namespace audio {
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Stop();
|
||||
void Drain();
|
||||
|
||||
private:
|
||||
void ThreadLoop();
|
||||
@ -96,6 +97,7 @@ namespace musik { namespace core { namespace audio {
|
||||
musik::core::runtime::MessageQueue messageQueue;
|
||||
std::list<FadeContextPtr> contextList;
|
||||
std::atomic<bool> quit, paused;
|
||||
std::condition_variable_any drainCondition;
|
||||
ITransport& transport;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user