Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*curses support next/prev & use Playlist's new API

  • Loading branch information...
commit cacce1c5060c41d9671b3cb25456d3328d9dd5c9 1 parent ac37c78
@bsdelf authored
View
11 frontend/cli/main.cpp
@@ -26,10 +26,8 @@ void OnFinished()
{
gMutexForSwitch.Lock();
if (gPlaylist != NULL && !gStop) {
- MediaItem* item = NULL;
- if (gPlaylist->SeqCurrent(item, 1)) {
- gPlaylist->SeqMoveNext();
- gPlaylist->SeqCurrent(item);
+ if (gPlaylist->SeqHasOffset(1)) {
+ MediaItem* item = gPlaylist->SeqItemAtOffset(1, true);
if (gPlayer->Status() != PlayerStatus::Closed)
gPlayer->Close();
gPlayer->Open(item->url);
@@ -251,9 +249,8 @@ int main(int argc, char** argv)
if (playlist.Empty())
return -1;
- MediaItem* item = NULL;
- playlist.SeqCurrent(item);
- assert(item != NULL);
+ const MediaItem* item = playlist.SeqItemAtOffset(0, false);
+
cout << ">>>> Tag Info" << endl;
cout << "\ttitle:" << item->tag.title << endl;
cout << "\tartist:" << item->tag.artist << endl;
View
23 frontend/ncurses/ClientPlayerHandler.cc
@@ -82,30 +82,37 @@ void ClientPlayerHandler::StopSync()
m_SyncSchedule.Stop(true);
}
-void ClientPlayerHandler::PlayMode(bool next)
+void ClientPlayerHandler::VolumeUp()
{
- SEND_PACKET(<< (char)Op::Player::PlayMode << (char)(next ? 1 : 0));
}
-void ClientPlayerHandler::Pause()
+void ClientPlayerHandler::VolumeDown()
{
- SEND_PACKET(<< (char)Op::Player::Pause);
}
-void ClientPlayerHandler::Next()
+void ClientPlayerHandler::QueryPlayMode()
{
+ SEND_PACKET(<< (char)Op::Player::PlayMode << (char)0);
}
-void ClientPlayerHandler::Previous()
+void ClientPlayerHandler::NextPlayMode()
{
+ SEND_PACKET(<< (char)Op::Player::PlayMode << (char)1);
}
-void ClientPlayerHandler::VolumeUp()
+void ClientPlayerHandler::Pause()
{
+ SEND_PACKET(<< (char)Op::Player::Pause);
}
-void ClientPlayerHandler::VolumeDown()
+void ClientPlayerHandler::PlayNext()
+{
+ SEND_PACKET(<< (char)Op::Player::PlayNext << (char)1);
+}
+
+void ClientPlayerHandler::PlayPrev()
{
+ SEND_PACKET(<< (char)Op::Player::PlayNext << (char)-1);
}
void ClientPlayerHandler::OnSyncTask()
View
8 frontend/ncurses/ClientPlayerHandler.h
@@ -37,15 +37,15 @@ class ClientPlayerHandler
void StopSync();
// request
- //
void VolumeUp();
void VolumeDown();
- void PlayMode(bool next);
+ void QueryPlayMode();
+ void NextPlayMode();
void Pause();
- void Next();
- void Previous();
+ void PlayNext();
+ void PlayPrev();
const Signal<void (const std::string&)>& SigPlayMode() const
{
View
2  frontend/ncurses/MainUi.cc
@@ -172,7 +172,7 @@ void MainUi::SlotTryConnect()
void MainUi::SlotConnected()
{
d->client.PlayerHandler().StartSync();
- d->client.PlayerHandler().PlayMode(false);
+ d->client.PlayerHandler().QueryPlayMode();
for (int i = 0; i < PLAYLIST_COUNT; ++i)
d->client.PlaylistHandler().Sync(i);
View
3  frontend/ncurses/Protocol.h
@@ -109,6 +109,9 @@ enum e
// S:op(char) mode(string)
PlayMode,
+ // C:op(char) direction(char -1/1)
+ PlayNext,
+
// C:op(char) running(char 0/1)
// S:op(char) running(char 0/1)
Sync,
View
33 frontend/ncurses/ServerContext.cc
@@ -92,16 +92,27 @@ bool ServerContext::PlayAt(int iList, int iItem)
usedPlaylist = iList;
ServerContext::playlist_t& list = playlists[iList];
- MediaItem* item = NULL;
list.SeqJumpTo(iItem);
- list.SeqCurrent(item);
-
+ const MediaItem* item = list.SeqItemAtOffset(0, false);
return PlayItem(item);
}
+bool ServerContext::PlayNext(char direct)
+{
+ playlist_t& list = playlists[usedPlaylist];
+ if (list.SeqHasOffset(direct)) {
+ const MediaItem* item = list.SeqItemAtOffset(direct, true);
+ PlayItem(item);
+ sigPlayNextItem(item);
+ return true;
+ } else {
+ return false;
+ }
+}
+
void ServerContext::PausePlayer()
{
- MutexLocker locker(&playerMutex);
+ //MutexLocker locker(&playerMutex);
switch (player->Status()) {
case PlayerStatus::Playing:
@@ -119,15 +130,13 @@ void ServerContext::PausePlayer()
const MediaItem* ServerContext::ItemInPlaying() const
{
- MediaItem* item = NULL;
const playlist_t& list = playlists[usedPlaylist];
- list.SeqCurrent(item, 0);
- return item;
+ return list.SeqHasOffset(0) ? list.SeqItemAtOffset(0, false) : NULL;
}
bool ServerContext::PlayItem(const MediaItem* item)
{
- MutexLocker locker(&playerMutex);
+ //MutexLocker locker(&playerMutex);
ClosePlayer();
@@ -161,12 +170,8 @@ void ServerContext::SlotFinished()
MutexLocker locker(&mutex);
playlist_t& list = playlists[usedPlaylist];
- MediaItem* item = NULL;
- if (list.SeqCurrent(item, 1)) {
- list.SeqMoveNext();
- list.SeqCurrent(item);
- }
- if (item != NULL) {
+ if (list.SeqHasOffset(1)) {
+ const MediaItem* item = list.SeqItemAtOffset(1, true);
PlayItem(item);
sigPlayNextItem(item);
}
View
3  frontend/ncurses/ServerContext.h
@@ -23,7 +23,6 @@ struct ServerContext
IPluginManager* mgr;
IMediaLoader* loader;
IPlayer* player;
- Mutex playerMutex;
typedef Playlist<MediaItem*> playlist_t;
vector<playlist_t> playlists;
@@ -47,7 +46,7 @@ struct ServerContext
void NextPlayMode();
bool PlayAt(int iList, int iItem);
- bool PlayNext(bool toNext);
+ bool PlayNext(char direct);
void PausePlayer();
const MediaItem* ItemInPlaying() const;
View
26 frontend/ncurses/Session.cc
@@ -157,6 +157,10 @@ void Session::HandlePlayer(char* _buf, int len)
PlayerPlayMode(buf);
break;
+ case Op::Player::PlayNext:
+ PlayerPlayNext(buf);
+ break;
+
case Op::Player::Sync:
PlayerSync(buf);
break;
@@ -205,15 +209,23 @@ void Session::PlayerPlayMode(BufObj& buf)
}
}
+void Session::PlayerPlayNext(BufObj& buf)
+{
+ char direct = buf.Fetch<char>();
+
+ MutexLocker locker(&m_Context->mutex);
+
+ m_Context->PlayNext(direct);
+}
+
void Session::PlayerSync(BufObj& buf)
{
int running = buf.Fetch<char>();
- MutexLocker dataLocker(&m_Context->mutex);
+ MutexLocker locker(&m_Context->mutex);
- MutexLocker playerLocker(&m_Context->playerMutex);
EmPlayerStatus status = m_Context->player->Status();
- playerLocker.Unlock();
+ //playerLocker.Unlock();
int nowRunning = status == PlayerStatus::Playing ? 1 : 0;
@@ -226,10 +238,10 @@ void Session::PlayerSync(BufObj& buf)
}
case BINARY_MASK(1, 1):
{
- playerLocker.Relock();
+ //playerLocker.Relock();
uint64_t ms = m_Context->player->OffsetMs();
int32_t bitRate = m_Context->player->BitRate();
- playerLocker.Unlock();
+ //playerLocker.Unlock();
SEND_PLAYER_PACKET(<< (char)Op::Player::ItemProgress << ms << bitRate);
}
@@ -243,7 +255,7 @@ void Session::PlayerSync(BufObj& buf)
break;
}
- dataLocker.Unlock();
+ locker.Unlock();
SEND_PLAYER_PACKET(<< (char)Op::Player::Sync << (char)nowRunning);
}
@@ -506,7 +518,7 @@ void Session::SendMediaItemInfo(const MediaItem* item)
char op = Op::Player::ItemInfo;
- MutexLocker locker(&m_Context->playerMutex);
+ MutexLocker locker(&m_Context->mutex);
int32_t sampleRate = m_Context->player->SamleRate();
uint64_t duration = m_Context->player->RangeDuration();
locker.Unlock();
View
1  frontend/ncurses/Session.h
@@ -40,6 +40,7 @@ class Session
void PlayerSeek(BufObj&);
void PlayerVolume(BufObj&);
void PlayerPlayMode(BufObj&);
+ void PlayerPlayNext(BufObj&);
void PlayerSync(BufObj&);
void PlaylistSwitch(BufObj&);
View
14 frontend/ncurses/StatusView.cc
@@ -185,25 +185,29 @@ bool StatusView::InjectKey(int key)
break;
case 'm':
- m_PlayerHandler->PlayMode(true);
+ m_PlayerHandler->NextPlayMode();
break;
- case '>':
+ case 'n':
+ m_PlayerHandler->PlayNext();
break;
- case '<':
+ case 'p':
+ m_PlayerHandler->PlayPrev();
break;
- case 'N':
+ case '>':
break;
- case 'P':
+ case '<':
break;
case '+':
+ case '=':
break;
case '-':
+ case '_':
break;
default:
View
18 frontend/qt/SimplePlaylistView.cpp
@@ -186,22 +186,13 @@ void SimplePlaylistView::SetMediaLoader(const IMediaLoader* loader)
const MediaItem* SimplePlaylistView::GetNextItem() const
{
- MediaItem* item = NULL;
- if (m_Playlist.SeqCurrent(item, 1)) {
- m_Playlist.SeqMoveNext();
- m_Playlist.SeqCurrent(item);
- }
- return item;
+ return m_Playlist.SeqHasOffset(1) ? m_Playlist.SeqItemAtOffset(1, true) : NULL;
+
}
const MediaItem* SimplePlaylistView::GetPreviousItem() const
{
- MediaItem* item = NULL;
- if (m_Playlist.SeqCurrent(item, -1)) {
- m_Playlist.SeqMoveNext(-1);
- m_Playlist.SeqCurrent(item);
- }
- return NULL;
+ return m_Playlist.SeqHasOffset(-1) ? m_Playlist.SeqItemAtOffset(-1, true) : NULL;
}
size_t SimplePlaylistView::GetItemCount() const
@@ -220,8 +211,7 @@ void SimplePlaylistView::mouseDoubleClickEvent(QMouseEvent * event)
qDebug() << index.row();
m_Playlist.SeqJumpTo(index.row());
- MediaItem* item = NULL;
- m_Playlist.SeqCurrent(item);
+ MediaItem* item = m_Playlist.SeqItemAtOffset(0, false);
emit SigPlayMediaItem(this, item);
}
Please sign in to comment.
Something went wrong with that request. Please try again.