diff --git a/src/contrib/waveout/WaveOut.cpp b/src/contrib/waveout/WaveOut.cpp index 334bfd7b5..e095669b3 100644 --- a/src/contrib/waveout/WaveOut.cpp +++ b/src/contrib/waveout/WaveOut.cpp @@ -56,23 +56,22 @@ WaveOut::~WaveOut() { } void WaveOut::Destroy() { - { - boost::recursive_mutex::scoped_lock lock(this->outputDeviceMutex); + boost::recursive_mutex::scoped_lock lock1(this->bufferQueueMutex); + boost::recursive_mutex::scoped_lock lock2(this->outputDeviceMutex); - /* reset playback immediately. this will invalidate all pending - buffers */ - if (this->waveHandle != NULL) { - waveOutReset(this->waveHandle); - } + /* reset playback immediately. this will invalidate all pending + buffers */ + if (this->waveHandle != NULL) { + waveOutReset(this->waveHandle); + } - /* stop the thread so nothing else is processed */ - this->StopWaveOutThread(); + /* stop the thread so nothing else is processed */ + this->StopWaveOutThread(); - /* close it down after the threadproc has finished */ - if (this->waveHandle != NULL) { - waveOutClose(this->waveHandle); - this->waveHandle = NULL; - } + /* close it down after the threadproc has finished */ + if (this->waveHandle != NULL) { + waveOutClose(this->waveHandle); + this->waveHandle = NULL; } this->ClearBufferQueue(); @@ -99,12 +98,11 @@ void WaveOut::SetVolume(double volume) { } void WaveOut::Stop() { - { - boost::recursive_mutex::scoped_lock lock(this->outputDeviceMutex); + boost::recursive_mutex::scoped_lock lock1(this->bufferQueueMutex); + boost::recursive_mutex::scoped_lock lock2(this->outputDeviceMutex); - if (this->waveHandle != NULL) { - waveOutReset(this->waveHandle); - } + if (this->waveHandle != NULL) { + waveOutReset(this->waveHandle); } this->ClearBufferQueue(); diff --git a/src/core/audio/Buffer.h b/src/core/audio/Buffer.h index 631df1d10..a7a65ca14 100644 --- a/src/core/audio/Buffer.h +++ b/src/core/audio/Buffer.h @@ -42,11 +42,6 @@ namespace musik { namespace core { namespace audio { class Stream; typedef std::shared_ptr BufferPtr; - ////////////////////////////////////////// - ///\brief - ///Buffer is the only implementation of the IBuffer and is used - ///in the audioengine to pass along the raw audio data - ////////////////////////////////////////// class Buffer : public IBuffer { private: Buffer(void); diff --git a/src/core/playback/Transport.cpp b/src/core/playback/Transport.cpp index a728b006e..bf24498ac 100644 --- a/src/core/playback/Transport.cpp +++ b/src/core/playback/Transport.cpp @@ -119,8 +119,6 @@ void Transport::StartWithPlayer(Player* newPlayer) { void Transport::Stop() { musik::debug::info(TAG, "stop"); - PlayerPtr player = NULL; - std::list toDelete; { @@ -136,9 +134,7 @@ void Transport::Stop() { std::for_each(toDelete.begin(), toDelete.end(), deletePlayer); this->active.clear(); - if (player) { - this->SetPlaybackState(PlaybackStopped); - } + this->SetPlaybackState(PlaybackStopped); } bool Transport::Pause() { diff --git a/src/musikbox/app/layout/LibraryLayout.cpp b/src/musikbox/app/layout/LibraryLayout.cpp index a77b162ef..3066f0368 100755 --- a/src/musikbox/app/layout/LibraryLayout.cpp +++ b/src/musikbox/app/layout/LibraryLayout.cpp @@ -11,16 +11,13 @@ using namespace musik::core::library::constants; #define CATEGORY_WIDTH 25 #define TRANSPORT_HEIGHT 3 -#define DEFAULT_CATEGORY Track::ALBUM_ID +#define DEFAULT_CATEGORY constants::Track::ALBUM_ID +using namespace musik::core; +using namespace musik::core::audio; +using namespace musik::core::library; using namespace musik::box; - -using musik::core::LibraryPtr; -using musik::core::audio::Transport; - -using cursespp::LayoutBase; -using cursespp::ListWindow; -using cursespp::Screen; +using namespace cursespp; LibraryLayout::LibraryLayout(PlaybackService& playback, LibraryPtr library) : LayoutBase() @@ -69,6 +66,10 @@ void LibraryLayout::InitializeWindows() { this->Layout(); } +IWindowPtr LibraryLayout::GetFocus() { + return this->focused ? this->focused : LayoutBase::GetFocus(); +} + void LibraryLayout::Show() { LayoutBase::Show(); this->categoryList->Requery(); @@ -97,18 +98,28 @@ bool LibraryLayout::KeyPress(int64 ch) { std::string kn = keyname((int)ch); if (kn == "ALT_1") { - this->categoryList->SetFieldName(Track::ARTIST_ID); + this->categoryList->SetFieldName(constants::Track::ARTIST_ID); return true; } else if (kn == "ALT_2") { - this->categoryList->SetFieldName(Track::ALBUM_ID); + this->categoryList->SetFieldName(constants::Track::ALBUM_ID); return true; } else if (kn == "ALT_3") { - this->categoryList->SetFieldName(Track::GENRE_ID); - return true; + this->categoryList->SetFieldName(constants::Track::GENRE_ID); + return true; } - else if (ch == KEY_F(5)) { + else if (kn == "CTL_DOWN") { + this->focused = this->transportView; + this->transportView->Focus(); + } + else if (kn == "CTL_UP") { + if (this->focused) { + this->focused->Blur(); + this->focused.reset(); + } + } + else if (ch == KEY_END) { this->categoryList->Requery(); return true; } diff --git a/src/musikbox/app/layout/LibraryLayout.h b/src/musikbox/app/layout/LibraryLayout.h index 12d583b97..14e271f35 100755 --- a/src/musikbox/app/layout/LibraryLayout.h +++ b/src/musikbox/app/layout/LibraryLayout.h @@ -25,6 +25,7 @@ namespace musik { virtual void Layout(); virtual void Show(); virtual bool LibraryLayout::KeyPress(int64 ch); + virtual cursespp::IWindowPtr GetFocus(); private: void InitializeWindows(); @@ -43,6 +44,7 @@ namespace musik { std::shared_ptr categoryList; std::shared_ptr trackList; std::shared_ptr transportView; + cursespp::IWindowPtr focused; }; } } diff --git a/src/musikbox/app/layout/MainLayout.cpp b/src/musikbox/app/layout/MainLayout.cpp index b4cf4ff26..150a99a8c 100755 --- a/src/musikbox/app/layout/MainLayout.cpp +++ b/src/musikbox/app/layout/MainLayout.cpp @@ -64,7 +64,7 @@ void MainLayout::Show() { } void MainLayout::ProcessMessage(IMessage &message) { - if (message.MessageType() == MESSAGE_TYPE_UPDATE) { + if (message.Type() == MESSAGE_TYPE_UPDATE) { this->UpdateWindows(); this->PostMessage(MESSAGE_TYPE_UPDATE, 0, 0, UPDATE_INTERVAL_MS); } diff --git a/src/musikbox/app/window/CategoryListView.cpp b/src/musikbox/app/window/CategoryListView.cpp index a6115821d..4c868a6c0 100755 --- a/src/musikbox/app/window/CategoryListView.cpp +++ b/src/musikbox/app/window/CategoryListView.cpp @@ -72,7 +72,7 @@ void CategoryListView::OnQueryCompleted(QueryPtr query) { } void CategoryListView::ProcessMessage(IMessage &message) { - if (message.MessageType() == WINDOW_MESSAGE_QUERY_COMPLETED) { + if (message.Type() == WINDOW_MESSAGE_QUERY_COMPLETED) { this->metadata = activeQuery->GetResult(); activeQuery.reset(); this->OnAdapterChanged(); diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index 1571f7ea2..3db5032c7 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -67,7 +67,7 @@ bool TrackListView::KeyPress(int64 ch) { } void TrackListView::ProcessMessage(IMessage &message) { - if (message.MessageType() == WINDOW_MESSAGE_QUERY_COMPLETED) { + if (message.Type() == WINDOW_MESSAGE_QUERY_COMPLETED) { if (this->query && this->query->GetStatus() == IQuery::Finished) { this->metadata = this->query->GetResult(); this->query.reset(); diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index ebf0704a3..e4e91f09c 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -44,7 +44,7 @@ TransportWindow::TransportWindow(LibraryPtr library, Transport& transport) this->transport->StreamEvent.connect(this, &TransportWindow::OnTransportStreamEvent); this->transport->VolumeChanged.connect(this, &TransportWindow::OnTransportVolumeChanged); this->transport->TimeChanged.connect(this, &TransportWindow::OnTransportTimeChanged); - this->paused = false; + this->paused = this->focused = false; } TransportWindow::~TransportWindow() { @@ -56,7 +56,7 @@ void TransportWindow::Show() { } void TransportWindow::ProcessMessage(IMessage &message) { - int type = message.MessageType(); + int type = message.Type(); if (type == REFRESH_TRANSPORT_READOUT) { this->Update(); @@ -87,38 +87,59 @@ void TransportWindow::OnQueryCompleted(QueryPtr query) { } } +void TransportWindow::Focus() { + this->focused = true; + DEBOUNCE_REFRESH(0) +} + +void TransportWindow::Blur() { + this->focused = false; + DEBOUNCE_REFRESH(0) +} + void TransportWindow::Update() { this->Clear(); WINDOW *c = this->GetContent(); bool paused = (transport->GetPlaybackState() == Transport::PlaybackPaused); - int64 gb = COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK); + + int64 gb = COLOR_PAIR(this->focused + ? BOX_COLOR_RED_ON_BLACK + : BOX_COLOR_GREEN_ON_BLACK); /* playing SONG TITLE from ALBUM NAME */ + std::string duration = "0"; - std::string title, album, duration; - - if (this->currentTrack) { - title = this->currentTrack->GetValue(constants::Track::TITLE); - album = this->currentTrack->GetValue(constants::Track::ALBUM); - duration = this->currentTrack->GetValue(constants::Track::DURATION); + if (transport->GetPlaybackState() == Transport::PlaybackStopped) { + wattron(c, gb); + wprintw(c, "playback is stopped"); + wattroff(c, gb); } + else { + std::string title, album; - title = title.size() ? title : "song title"; - album = album.size() ? album : "album name"; - duration = duration.size() ? duration : "0"; + if (this->currentTrack) { + title = this->currentTrack->GetValue(constants::Track::TITLE); + album = this->currentTrack->GetValue(constants::Track::ALBUM); + duration = this->currentTrack->GetValue(constants::Track::DURATION); + } - wprintw(c, "playing "); + title = title.size() ? title : "song title"; + album = album.size() ? album : "album name"; + duration = duration.size() ? duration : "0"; - wattron(c, gb); - wprintw(c, title.c_str()); - wattroff(c, gb); + wprintw(c, "playing "); - wprintw(c, " from "); + wattron(c, gb); + wprintw(c, title.c_str()); + wattroff(c, gb); - wattron(c, gb); - wprintw(c, album.c_str()); - wattroff(c, gb); + wprintw(c, " from "); + + wattron(c, gb); + wprintw(c, album.c_str()); + wattroff(c, gb); + } /* volume slider */ diff --git a/src/musikbox/app/window/TransportWindow.h b/src/musikbox/app/window/TransportWindow.h index b75d9b9f6..d5b2e557b 100755 --- a/src/musikbox/app/window/TransportWindow.h +++ b/src/musikbox/app/window/TransportWindow.h @@ -19,7 +19,11 @@ namespace musik { ~TransportWindow(); virtual void ProcessMessage(cursespp::IMessage &message); + virtual void Show(); + virtual void Focus(); + virtual void Blur(); + void Update(); private: @@ -28,7 +32,7 @@ namespace musik { void OnTransportTimeChanged(double time); void OnQueryCompleted(musik::core::QueryPtr query); - bool paused; + bool paused, focused; musik::core::LibraryPtr library; musik::core::audio::Transport* transport; musik::core::TrackPtr currentTrack; diff --git a/src/musikbox/cursespp/IMessage.h b/src/musikbox/cursespp/IMessage.h index d8548e82b..4c135e7a3 100755 --- a/src/musikbox/cursespp/IMessage.h +++ b/src/musikbox/cursespp/IMessage.h @@ -11,7 +11,7 @@ namespace cursespp { public: virtual ~IMessage() = 0 { } virtual IMessageTarget* Target() = 0; - virtual int MessageType() = 0; + virtual int Type() = 0; virtual int64 UserData1() = 0; virtual int64 UserData2() = 0; }; diff --git a/src/musikbox/cursespp/Message.cpp b/src/musikbox/cursespp/Message.cpp index 386c0fd1a..3886435e9 100755 --- a/src/musikbox/cursespp/Message.cpp +++ b/src/musikbox/cursespp/Message.cpp @@ -28,7 +28,7 @@ IMessageTarget* Message::Target() { return this->target; } -int Message::MessageType() { +int Message::Type() { return this->messageType; } diff --git a/src/musikbox/cursespp/Message.h b/src/musikbox/cursespp/Message.h index 14706bbb6..6bfd2acec 100755 --- a/src/musikbox/cursespp/Message.h +++ b/src/musikbox/cursespp/Message.h @@ -19,7 +19,7 @@ namespace cursespp { int64 data2); virtual IMessageTarget* Target(); - virtual int MessageType(); + virtual int Type(); virtual int64 UserData1(); virtual int64 UserData2(); diff --git a/src/musikbox/cursespp/MessageQueue.cpp b/src/musikbox/cursespp/MessageQueue.cpp index b57295ab3..643f1e149 100755 --- a/src/musikbox/cursespp/MessageQueue.cpp +++ b/src/musikbox/cursespp/MessageQueue.cpp @@ -67,7 +67,7 @@ void MessageQueue::Remove(IMessageTarget *target, int type) { IMessagePtr current = (*it)->message; if (current->Target() == target) { - if (type == -1 || type == current->MessageType()) { + if (type == -1 || type == current->Type()) { delete (*it); it = this->queue.erase(it); continue;