mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
Made position slider & time indicators update during playback.
Removed some pass-through methods from PlaybackQueue and added getter for Transport. Updated all references.
This commit is contained in:
parent
ec40c854fa
commit
05488a5bd7
@ -198,17 +198,4 @@ void PlaybackQueue::Play(tracklist::IRandomAccess &tracklist){
|
||||
this->currentTrack.reset();
|
||||
this->nowPlaying->CopyTracks(tracklist);
|
||||
this->Play();
|
||||
}
|
||||
|
||||
short PlaybackQueue::Volume() const{
|
||||
return this->transport.Volume();
|
||||
}
|
||||
|
||||
void PlaybackQueue::SetVolume(short volume){
|
||||
this->transport.ChangeVolume(volume);
|
||||
}
|
||||
|
||||
void PlaybackQueue::JumpToPosition(short relativePosition)
|
||||
{
|
||||
this->transport.JumpToPosition(relativePosition);
|
||||
}
|
@ -86,6 +86,12 @@ class PlaybackQueue : public sigslot::has_slots<>{
|
||||
//////////////////////////////////////////
|
||||
static PlaybackQueue& Instance(){ return sInstance; };
|
||||
|
||||
//////////////////////////////////////////
|
||||
///\brief
|
||||
///Get a hold of the Transport
|
||||
//////////////////////////////////////////
|
||||
musik::core::audio::Transport& Transport() { return this->transport; };
|
||||
|
||||
// Now Playing control
|
||||
tracklist::Standard::Ptr NowPlayingTracklist();
|
||||
void Play(tracklist::IRandomAccess &tracklist);
|
||||
@ -97,10 +103,6 @@ class PlaybackQueue : public sigslot::has_slots<>{
|
||||
void Previous();
|
||||
void Stop();
|
||||
|
||||
short Volume() const;
|
||||
void SetVolume(short volume);
|
||||
void JumpToPosition(short relativePosition);
|
||||
|
||||
musik::core::TrackPtr CurrentTrack();
|
||||
|
||||
// Public signals
|
||||
|
@ -121,16 +121,26 @@ void Transport::Stop(size_t idx)
|
||||
}
|
||||
}
|
||||
|
||||
void Transport::JumpToPosition(short relativePosition)
|
||||
void Transport::JumpToPosition(unsigned long position)
|
||||
{
|
||||
AudioStream* stream = this->openStreams[0];
|
||||
|
||||
unsigned long posMS = stream->GetLength() * relativePosition / 100;
|
||||
|
||||
stream->SetPosition(posMS);
|
||||
stream->SetPosition(position);
|
||||
}
|
||||
|
||||
void Transport::ChangeVolume(short volume)
|
||||
unsigned long Transport::FirstTrackPosition() const
|
||||
{
|
||||
if (this->openStreams.size() > 0) return this->openStreams[0]->GetPosition();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
unsigned long Transport::FirstTrackLength() const
|
||||
{
|
||||
if (this->openStreams.size() > 0) return this->openStreams[0]->GetLength();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void Transport::SetVolume(short volume)
|
||||
{
|
||||
if (volume < 0 || volume > 100)
|
||||
{
|
||||
|
@ -59,9 +59,11 @@ public: ~Transport();
|
||||
public: void Start(const utfstring path);
|
||||
public: void Stop(size_t idx);
|
||||
|
||||
public: void JumpToPosition(short relativePosition);
|
||||
public: void JumpToPosition(unsigned long position);
|
||||
public: unsigned long FirstTrackPosition() const;
|
||||
public: unsigned long FirstTrackLength() const;
|
||||
|
||||
public: void ChangeVolume(short volume);
|
||||
public: void SetVolume(short volume);
|
||||
public: short Volume() const { return currVolume; };
|
||||
|
||||
public: size_t NumOfStreams() const;
|
||||
|
@ -37,6 +37,9 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <cube/TransportController.hpp>
|
||||
#include <win32cpp/ApplicationThread.hpp>
|
||||
|
||||
@ -48,6 +51,8 @@ using namespace musik::cube;
|
||||
|
||||
/*ctor*/ TransportController::TransportController(TransportView& transportView)
|
||||
: transportView(transportView)
|
||||
, playbackSliderTimer(500)
|
||||
, playbackSliderMouseDown(false)
|
||||
{
|
||||
this->transportView.Created.connect(
|
||||
this, &TransportController::OnViewCreated);
|
||||
@ -74,12 +79,22 @@ void TransportController::OnViewCreated(Window* window)
|
||||
this, &TransportController::OnVolumeSliderChange);
|
||||
|
||||
this->transportView.volumeSlider->SetPosition(
|
||||
musik::core::PlaybackQueue::Instance().Volume());
|
||||
musik::core::PlaybackQueue::Instance().Transport().Volume());
|
||||
|
||||
musik::core::PlaybackQueue::Instance().CurrentTrackChanged.connect(this,&TransportController::OnTrackChange);
|
||||
|
||||
this->transportView.playbackSlider->Repositioned.connect(
|
||||
this, &TransportController::OnPlaybackSliderChange);
|
||||
|
||||
this->transportView.playbackSlider->MouseButtonDown.connect(
|
||||
this, &TransportController::OnPlaybackSliderMouseDown);
|
||||
|
||||
this->transportView.playbackSlider->MouseButtonUp.connect(
|
||||
this, &TransportController::OnPlaybackSliderMouseUp);
|
||||
|
||||
this->playbackSliderTimer.ConnectToWindow(this->transportView.playbackSlider);
|
||||
|
||||
this->playbackSliderTimer.OnTimout.connect(this, &TransportController::OnPlaybackSliderTimerTimedOut);
|
||||
}
|
||||
|
||||
void TransportController::OnViewResized(Window* window, Size size)
|
||||
@ -94,6 +109,8 @@ void TransportController::OnPlayPressed(Button* button)
|
||||
void TransportController::OnStopPressed(Button* button)
|
||||
{
|
||||
musik::core::PlaybackQueue::Instance().Stop();
|
||||
this->transportView.playbackSlider->SetPosition(0);
|
||||
this->playbackSliderTimer.Stop();
|
||||
}
|
||||
|
||||
void TransportController::OnNextPressed(Button* button)
|
||||
@ -108,7 +125,7 @@ void TransportController::OnPreviousPressed(Button* button)
|
||||
|
||||
void TransportController::OnVolumeSliderChange(Trackbar* trackbar)
|
||||
{
|
||||
musik::core::PlaybackQueue::Instance().SetVolume(transportView.volumeSlider->Position());
|
||||
musik::core::PlaybackQueue::Instance().Transport().SetVolume(transportView.volumeSlider->Position());
|
||||
}
|
||||
|
||||
void TransportController::OnTrackChange(musik::core::TrackPtr track){
|
||||
@ -133,9 +150,54 @@ void TransportController::OnTrackChange(musik::core::TrackPtr track){
|
||||
this->transportView.titleLabel->SetCaption(title);
|
||||
this->transportView.artistLabel->SetCaption(artist);
|
||||
|
||||
this->transportView.timeDurationLabel->SetCaption(this->FormatTime(musik::core::PlaybackQueue::Instance().Transport().FirstTrackLength()));
|
||||
|
||||
this->transportView.playbackSlider->SetPosition(0);
|
||||
this->playbackSliderTimer.Start();
|
||||
}
|
||||
|
||||
void TransportController::OnPlaybackSliderChange(Trackbar *trackBar)
|
||||
{
|
||||
musik::core::PlaybackQueue::Instance().JumpToPosition(trackBar->Position());
|
||||
unsigned long lengthMs = musik::core::PlaybackQueue::Instance().Transport().FirstTrackLength();
|
||||
unsigned long newPosMs = lengthMs * trackBar->Position() / trackBar->Range();
|
||||
|
||||
//this->playbackSliderTimer.Stop();
|
||||
musik::core::PlaybackQueue::Instance().Transport().JumpToPosition(newPosMs);
|
||||
//this->playbackSliderTimer.Start();
|
||||
}
|
||||
|
||||
void TransportController::OnPlaybackSliderTimerTimedOut()
|
||||
{
|
||||
unsigned long currPosMs = musik::core::PlaybackQueue::Instance().Transport().FirstTrackPosition();
|
||||
unsigned long lengthMs = musik::core::PlaybackQueue::Instance().Transport().FirstTrackLength();
|
||||
unsigned long sliderRange = this->transportView.playbackSlider->Range();
|
||||
|
||||
this->transportView.timeElapsedLabel->SetCaption(this->FormatTime(currPosMs));
|
||||
|
||||
if (!this->playbackSliderMouseDown)
|
||||
{
|
||||
this->transportView.playbackSlider->SetPosition(sliderRange * currPosMs / lengthMs);
|
||||
}
|
||||
}
|
||||
|
||||
void TransportController::OnPlaybackSliderMouseDown(Window* windows, MouseEventFlags flags, Point point)
|
||||
{
|
||||
this->playbackSliderMouseDown = true;
|
||||
}
|
||||
|
||||
void TransportController::OnPlaybackSliderMouseUp(Window* windows, MouseEventFlags flags, Point point)
|
||||
{
|
||||
this->playbackSliderMouseDown = false;
|
||||
}
|
||||
|
||||
win32cpp::uistring TransportController::FormatTime(unsigned long ms)
|
||||
{
|
||||
unsigned long seconds = ms / 1000 % 60;
|
||||
unsigned long minutes = ms / 1000 / 60;
|
||||
|
||||
boost::basic_format<uichar> format(_T("%1%:%2$02d"));
|
||||
format % minutes;
|
||||
format % seconds;
|
||||
|
||||
return format.str();
|
||||
}
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include <core/PlaybackQueue.h>
|
||||
#include <cube/TransportView.hpp>
|
||||
#include <win32cpp/Timer.hpp>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -65,8 +66,16 @@ protected: void OnPreviousPressed(Button* button);
|
||||
protected: void OnVolumeSliderChange(Trackbar* trackbar);
|
||||
protected: void OnTrackChange(musik::core::TrackPtr track);
|
||||
protected: 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);
|
||||
|
||||
protected: TransportView& transportView;
|
||||
|
||||
protected: Timer playbackSliderTimer;
|
||||
protected: bool playbackSliderMouseDown;
|
||||
|
||||
protected: win32cpp::uistring FormatTime(unsigned long ms);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -96,7 +96,7 @@ void TransportView::OnCreated()
|
||||
|
||||
// bottom row layout
|
||||
this->timeElapsedLabel = bottomRowLayout->AddChild(new Label(_T("0:00")));
|
||||
this->playbackSlider = bottomRowLayout->AddChild(new Trackbar(0, 100));
|
||||
this->playbackSlider = bottomRowLayout->AddChild(new Trackbar(0, 1000));
|
||||
this->timeDurationLabel = bottomRowLayout->AddChild(new Label(_T("0:00")));
|
||||
//
|
||||
this->playbackSlider->Resize(100, 20);
|
||||
|
@ -247,7 +247,7 @@ void ConsoleUI::SetVolume(Args args)
|
||||
|
||||
void ConsoleUI::SetVolume(short volume)
|
||||
{
|
||||
transport.ChangeVolume(volume);
|
||||
transport.SetVolume(volume);
|
||||
}
|
||||
|
||||
void ConsoleUI::Quit()
|
||||
|
@ -79,6 +79,7 @@ public: /*ctor*/ Trackbar(
|
||||
|
||||
public: // methods
|
||||
void SetRange(short minValue, short maxValue);
|
||||
int Range() const { return this->maxValue - this->minValue; }
|
||||
int MinValue() const { return this->minValue; }
|
||||
int MaxValue() const { return this->maxValue; }
|
||||
void SetTickFrequency(short tickFrequency = 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user