Fixed problem where TransportView stopped updating when next track was started.

Added TrackPtr parameter to some audio events for this.
Square temporarily broken.
This commit is contained in:
bjorn.olievier 2008-05-16 07:41:03 +00:00
parent 53008eef52
commit 767409e346
10 changed files with 97 additions and 69 deletions

View File

@ -98,13 +98,10 @@ void PlaybackQueue::Play(){
TrackPtr track(this->CurrentTrack());
if(track){
// If current track exists
utfstring path(track->GetValue("path"));
this->Stop();
this->playing = true;
this->transport.Start(path);
this->transport.Start(track);
this->paused = false;
}

View File

@ -5,11 +5,12 @@
#include <core/audio/IAudioSource.h>
#include <core/audio/Transport.h>
using namespace musik::core;
using namespace musik::core::audio;
unsigned long AudioStream::streamsCreated = 0;
AudioStream::AudioStream(IAudioSource* source, IAudioOutput* output, Transport* owner)
AudioStream::AudioStream(IAudioSource* source, IAudioOutput* output, Transport* owner, TrackPtr track)
: audioSource(source)
, transport(owner)
, playState(PlayStateUnknown)
@ -19,6 +20,7 @@ AudioStream::AudioStream(IAudioSource* source, IAudioOutput* output, Transport*
, isFinished(false)
, isLast(false)
, samplesOut(0)
, track(track)
{
this->output = output;
this->output->SetCallback(this);
@ -136,7 +138,7 @@ bool AudioStream::GetBuffer(float * pAudioBuffer, unsigned long NumSamples)
//used for repeatnone where this is the end of line.
if(pos >= len && this->isLast)
{
transport->EventPlaybackStoppedOk();
transport->EventPlaybackStoppedOk(this->track);
this->playState = PlayStateStopped;
}
@ -219,7 +221,7 @@ bool AudioStream::SetPositionMs(unsigned long ms)
if(this->fadeState != FadeStateNone)
{
this->volume = 1.0;
this->volume = 1.0;
this->fadeState = FadeStateNone;
}
@ -242,7 +244,7 @@ utfstring AudioStream::ToString() const
{
std::utfstringstream ss;
ss << this->streamId << " " << this->audioSource->GetSource();
ss << this->streamId << " " << this->track->GetValue("path");
return ss.str();
}

View File

@ -4,6 +4,7 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <core/Track.h>
#include <core/audio/AudioPacketizer.h>
#include <core/audio/IAudioCallBack.h>
@ -22,7 +23,7 @@ public:
static const unsigned long UnknownLength = ULONG_MAX;
AudioStream(IAudioSource* source, IAudioOutput* output, Transport *owner);
AudioStream(IAudioSource* source, IAudioOutput* output, Transport *owner, musik::core::TrackPtr track);
~AudioStream();
bool Start();
@ -39,6 +40,8 @@ public:
bool SetPositionMs(unsigned long ms);
bool isFinished;
musik::core::TrackPtr Track() const { return this->track; };
unsigned long GetStreamId() const { return this->streamId; };
utfstring ToString() const;
@ -48,6 +51,8 @@ private:
IAudioOutput* output;
AudioPacketizer packetizer;
musik::core::TrackPtr track;
PlayState playState;
FadeState fadeState;

View File

@ -16,7 +16,7 @@ public: virtual bool GetFormat(unsigned long * SampleRate, unsigned long * Ch
public: virtual bool GetBuffer(float ** ppBuffer, unsigned long * NumSamples) = 0; // return false to signal that we are done decoding.
public: virtual bool Open(const utfchar* source) = 0;
public: virtual const utfchar* GetSource() const = 0;
public: virtual const utfchar* GetSource() const = 0; // TODO: remove?
};
class IAudioSourceSupplier

View File

@ -41,10 +41,13 @@
#include <core/audio/IAudioOutput.h>
#include <core/audio/IAudioSource.h>
using namespace musik::core;
using namespace musik::core::audio;
Transport::Transport() :
currVolume(100) //TODO: preference or previous value
Transport::Transport()
: currVolume(100) //TODO: preference or previous value
, activeStream(NULL)
{
this->registeredSourceSuppliers = PluginFactory::Instance().QueryInterface<
IAudioSourceSupplier,
@ -63,15 +66,17 @@ Transport::~Transport()
delete this->openStreams[i];
}
this->openStreams.clear();
this->activeStream = NULL;
}
void Transport::Start(const utfstring path)
void Transport::Start(TrackPtr trackPtr)
{
this->RemoveFinishedStreams();
bool success = false;
AudioStream * audioStream = this->CreateStream(path.c_str());
AudioStream * audioStream = this->CreateStream(trackPtr);
if (audioStream != NULL)
{
@ -87,21 +92,24 @@ void Transport::Start(const utfstring path)
if (success)
{
this->EventPlaybackStartedOk();
this->activeStream = audioStream;
this->EventPlaybackStartedOk(trackPtr);
}
else
{
this->EventPlaybackStartedFail();
this->EventPlaybackStartedFail(trackPtr);
}
}
void Transport::Stop()
{
//TODO: review
this->RemoveFinishedStreams();
if (this->openStreams.empty())
{
this->EventPlaybackStoppedFail();
// this->EventPlaybackStoppedFail(); //TODO: still necessary ?
return;
}
@ -109,15 +117,18 @@ void Transport::Stop()
if (stream->Stop())
{
if (stream == this->activeStream)
this->activeStream = NULL;
this->EventPlaybackStoppedOk(stream->Track());
delete stream;
this->openStreams.erase(this->openStreams.begin());
this->EventPlaybackStoppedOk();
}
else
{
this->EventPlaybackStoppedFail();
this->EventPlaybackStoppedFail(stream->Track());
}
}
@ -175,14 +186,14 @@ void Transport::SetTrackPosition(unsigned long position)
unsigned long Transport::TrackPosition() const
{
if (this->openStreams.size() > 0) return this->openStreams[0]->PositionMs();
else return 0;
if (this->activeStream) return this->activeStream->PositionMs();
else return 0;
}
unsigned long Transport::TrackLength() const
{
if (this->openStreams.size() > 0) return this->openStreams[0]->LengthMs();
else return 0;
if (this->activeStream) return this->openStreams[0]->LengthMs();
else return 0;
}
void Transport::SetVolume(short volume)
@ -226,7 +237,7 @@ AudioStreamOverview Transport::StreamsOverview() const
return overview;
}
AudioStream* Transport::CreateStream(const utfstring sourcePath)
AudioStream* Transport::CreateStream(TrackPtr trackPtr)
{
boost::shared_ptr<IAudioSourceSupplier> supplier;
IAudioSource* audioSource;
@ -238,14 +249,16 @@ AudioStream* Transport::CreateStream(const utfstring sourcePath)
}
IAudioOutput* audioOutput =
this->registeredOutputSuppliers[0]->CreateAudioOutput(); //TODO: deal with multiple outputs simultaneously
this->registeredOutputSuppliers[0]->CreateAudioOutput();
const utfchar* filePath = trackPtr->GetValue("path");
SourceSupplierList::const_iterator it;
for(it = this->registeredSourceSuppliers.begin(); it != this->registeredSourceSuppliers.end(); it++)
{
supplier = *it;
if (supplier->CanHandle(sourcePath.c_str()))
if (supplier->CanHandle(filePath))
{
break;
}
@ -255,9 +268,9 @@ AudioStream* Transport::CreateStream(const utfstring sourcePath)
{
audioSource = supplier->CreateAudioSource();
if (audioSource != NULL && audioSource->Open(sourcePath.c_str()))
if (audioSource != NULL && audioSource->Open(filePath))
{
audioStream = new AudioStream(audioSource, audioOutput, this);
audioStream = new AudioStream(audioSource, audioOutput, this, trackPtr);
}
}
@ -277,4 +290,4 @@ void Transport::RemoveFinishedStreams()
--i;
}
}
}
}

View File

@ -41,6 +41,7 @@
#include <sigslot/sigslot.h>
#include <core/config.h>
#include <core/Track.h>
namespace musik { namespace core { namespace audio {
@ -64,14 +65,15 @@ public:
Transport();
~Transport();
///\brief Start a new audiostream based on a file path or URL.
void Start(const utfstring path);
///\brief Start a new audiostream based on a Track.
///\param trackPtr Pointer to the track
void Start(TrackPtr trackPtr);
///\brief Stop the active stream. All resources used are released.
void Stop();
void Stop();
///\brief Pause the active stream. All resources stay in use.
bool Pause();
bool Pause();
///\brief Resume the active stream
bool Resume();
bool Resume();
///\brief Jump to a given position in the active stream.
///\param position New position in milliseconds
@ -102,8 +104,9 @@ private:
OutputSupplierList registeredOutputSuppliers;
std::vector<AudioStream*> openStreams;
AudioStream* activeStream;
AudioStream* CreateStream(const utfstring sourceString);
AudioStream* CreateStream(TrackPtr trackPtr);
void RemoveFinishedStreams();
short currVolume;
@ -111,13 +114,13 @@ private:
// Signals
public:
///\brief Emitted when Start() completed successfully
sigslot::signal0<> EventPlaybackStartedOk;
sigslot::signal1<TrackPtr> EventPlaybackStartedOk;
///\brief Emitted when Start() failed
sigslot::signal0<> EventPlaybackStartedFail;
sigslot::signal1<TrackPtr> EventPlaybackStartedFail;
///\brief Emitted when Stop() completed successfully
sigslot::signal0<> EventPlaybackStoppedOk;
sigslot::signal1<TrackPtr> EventPlaybackStoppedOk;
///\brief Emitted when Stop() failed
sigslot::signal0<> EventPlaybackStoppedFail;
sigslot::signal1<TrackPtr> EventPlaybackStoppedFail;
///\brief Emitted when Pause() completed successfully
sigslot::signal0<> EventPlaybackPausedOk;

View File

@ -193,11 +193,11 @@ void TransportController::OnPlaybackSliderMouseUp(Window* windows, MouseEventFla
this->playbackSliderMouseDown = false;
}
void TransportController::OnPlaybackStarted()
void TransportController::OnPlaybackStarted(musik::core::TrackPtr track)
{
if(!win32cpp::ApplicationThread::InMainThread())
{
win32cpp::ApplicationThread::Call0(this, &TransportController::OnPlaybackStarted);
win32cpp::ApplicationThread::Call1(this, &TransportController::OnPlaybackStarted, track);
return;
}
@ -205,16 +205,20 @@ void TransportController::OnPlaybackStarted()
this->transportView.playButton->SetCaption(_T("Pause"));
this->transportView.timeDurationLabel->SetCaption(this->FormatTime(musik::core::PlaybackQueue::Instance().Transport().TrackLength()));
// this->transportView.timeDurationLabel->SetCaption(track->GetValue("duration"));
this->transportView.playbackSlider->SetPosition(0);
this->playbackSliderTimer.Start();
this->displayedTrack = track;
}
void TransportController::OnPlaybackStopped()
void TransportController::OnPlaybackStopped(musik::core::TrackPtr track)
{
if(!win32cpp::ApplicationThread::InMainThread())
{
win32cpp::ApplicationThread::Call0(this, &TransportController::OnPlaybackStopped);
win32cpp::ApplicationThread::Call1(this, &TransportController::OnPlaybackStopped, track);
return;
}
@ -222,11 +226,14 @@ void TransportController::OnPlaybackStopped()
this->paused = false;
this->transportView.playButton->SetCaption(_T("Play"));
this->transportView.playbackSlider->SetPosition(0);
this->playbackSliderTimer.Stop();
this->transportView.timeElapsedLabel->SetCaption(_T("0:00"));
this->transportView.timeDurationLabel->SetCaption(_T("0:00"));
if (this->displayedTrack->id == track->id) // For out of order signals
{
this->transportView.playbackSlider->SetPosition(0);
this->playbackSliderTimer.Stop();
this->transportView.timeElapsedLabel->SetCaption(_T("0:00"));
this->transportView.timeDurationLabel->SetCaption(_T("0:00"));
}
}
void TransportController::OnPlaybackPaused()

View File

@ -58,8 +58,8 @@ public:
/*ctor*/ TransportController(TransportView& transportView);
protected:
void OnViewCreated(Window* window);
void OnViewResized(Window* window, Size size);
void OnViewCreated(Window* window);
void OnViewResized(Window* window, Size size);
void OnPlayPressed(Button* button);
void OnStopPressed(Button* button);
@ -68,12 +68,12 @@ protected:
void OnVolumeSliderChange(Trackbar* trackbar);
void OnTrackChange(musik::core::TrackPtr track);
void OnPlaybackSliderChange(Trackbar* trackBar);
protected: void OnPlaybackSliderTimerTimedOut();
protected: void OnPlaybackSliderMouseDown(Window* windows, MouseEventFlags flags, Point point);
protected: void OnPlaybackSliderMouseUp(Window* windows, MouseEventFlags flags, Point point);
void OnPlaybackSliderTimerTimedOut();
void OnPlaybackSliderMouseDown(Window* windows, MouseEventFlags flags, Point point);
void OnPlaybackSliderMouseUp(Window* windows, MouseEventFlags flags, Point point);
void OnPlaybackStarted();
void OnPlaybackStopped();
void OnPlaybackStarted(musik::core::TrackPtr track);
void OnPlaybackStopped(musik::core::TrackPtr track);
void OnPlaybackPaused();
void OnPlaybackResumed();
@ -82,10 +82,11 @@ protected: void OnPlaybackSliderMouseUp(Window* windows, MouseEventFlags fla
bool paused;
bool playing;
protected: Timer playbackSliderTimer;
protected: bool playbackSliderMouseDown;
Timer playbackSliderTimer;
bool playbackSliderMouseDown;
protected: win32cpp::uistring FormatTime(unsigned long ms);
musik::core::TrackPtr displayedTrack;
win32cpp::uistring FormatTime(unsigned long ms);
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -60,10 +60,10 @@ void TransportView::OnCreated()
topRowLayout->SetDefaultChildFill(false);
topRowLayout->SetDefaultChildAlignment(ChildAlignMiddle);
this->prevButton = topRowLayout->AddChild(new Button(_T("prev")));
this->playButton = topRowLayout->AddChild(new Button(_T("play")));
this->stopButton = topRowLayout->AddChild(new Button(_T("stop")));
this->nextButton = topRowLayout->AddChild(new Button(_T("next")));
this->prevButton = topRowLayout->AddChild(new Button(_T("Prev")));
this->playButton = topRowLayout->AddChild(new Button(_T("Play")));
this->stopButton = topRowLayout->AddChild(new Button(_T("Stop")));
this->nextButton = topRowLayout->AddChild(new Button(_T("Next")));
//
this->prevButton->Resize(50, 28);
this->playButton->Resize(50, 28);

View File

@ -49,11 +49,11 @@ ConsoleUI::ConsoleUI()
: shouldQuit(false)
, audioEventHandler(this)
{
this->transport.EventPlaybackStartedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
this->transport.EventPlaybackStartedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedFail);
// this->transport.EventPlaybackStartedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
// this->transport.EventPlaybackStartedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedFail);
this->transport.EventPlaybackStoppedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedOk);
this->transport.EventPlaybackStoppedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
// this->transport.EventPlaybackStoppedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedOk);
// this->transport.EventPlaybackStoppedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
this->transport.EventVolumeChangedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnVolumeChangedOk);
this->transport.EventVolumeChangedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnVolumeChangedFail);
@ -171,7 +171,7 @@ void ConsoleUI::PlayFile(Args args)
for (int i = 0; i < repeat; ++i)
{
transport.Start(filename.c_str());
// transport.Start(filename.c_str()); //TODO: fix to use TrackPtr
if (delay)
{
Sleep(delay);