Next and Prev buttons for Corax and Lorgar, debugging
This commit is contained in:
parent
22323b504f
commit
0e31c5fdf2
14 changed files with 394 additions and 72 deletions
|
@ -4,27 +4,43 @@ M::Player::Player(const W::Address& address, QObject* parent):
|
|||
M::Model(address, parent),
|
||||
controls(),
|
||||
views(),
|
||||
playPauseBtn(new M::Button(address + W::Address{u"Play"})),
|
||||
playPauseBtn(new M::Button(address + W::Address{u"play"})),
|
||||
nextBtn(new M::Button(address + W::Address{u"next"})),
|
||||
prevBtn(new M::Button(address + W::Address{u"prev"})),
|
||||
_queueView(new M::List(address + W::Address{u"queueView"})),
|
||||
_queue(),
|
||||
current(0),
|
||||
counter(0),
|
||||
currentIndex(0),
|
||||
mode(playBack),
|
||||
playing(false)
|
||||
playing(false),
|
||||
scheduledToplay(false)
|
||||
{
|
||||
W::Handler* get = W::Handler::create(address + W::Address({u"get"}), this, &M::Player::_h_get);
|
||||
W::Handler* hqueue = W::Handler::create(address + W::Address({u"queue"}), this, &M::Player::_h_queue);
|
||||
addHandler(get);
|
||||
addHandler(hqueue);
|
||||
|
||||
playPauseBtn->setLabel(W::String(u"play"));
|
||||
playPauseBtn->setLabel(W::String(u"Play"));
|
||||
playPauseBtn->setEnabled(false);
|
||||
connect(playPauseBtn, SIGNAL(activated()), this, SLOT(onPlayPauseBtn()));
|
||||
|
||||
nextBtn->setLabel(W::String(u"Next"));
|
||||
nextBtn->setEnabled(false);
|
||||
connect(nextBtn, SIGNAL(activated()), this, SLOT(onNextBtn()));
|
||||
|
||||
prevBtn->setLabel(W::String(u"Prev"));
|
||||
prevBtn->setEnabled(false);
|
||||
connect(prevBtn, SIGNAL(activated()), this, SLOT(onPrevBtn()));
|
||||
|
||||
addModel(playPauseBtn);
|
||||
addModel(nextBtn);
|
||||
addModel(prevBtn);
|
||||
addModel(_queueView);
|
||||
|
||||
controls.insert(std::make_pair(playPause, playPauseBtn->getAddress()));
|
||||
controls.insert(std::make_pair(next, nextBtn->getAddress()));
|
||||
controls.insert(std::make_pair(prev, prevBtn->getAddress()));
|
||||
views.insert(std::make_pair(queue, _queueView->getAddress()));
|
||||
}
|
||||
|
||||
|
@ -93,23 +109,9 @@ void M::Player::h_get(const W::Event& ev)
|
|||
void M::Player::onPlayPauseBtn()
|
||||
{
|
||||
if (playing) {
|
||||
playPauseBtn->setLabel(W::String(u"Play"));
|
||||
playing = false;
|
||||
|
||||
switch (mode) {
|
||||
case playBack:
|
||||
broadcast(new W::Vocabulary(), W::Address{u"pause"});
|
||||
break;
|
||||
}
|
||||
pause();
|
||||
} else {
|
||||
playPauseBtn->setLabel(W::String(u"Pause"));
|
||||
playing = true;
|
||||
|
||||
switch (mode) {
|
||||
case playBack:
|
||||
broadcast(new W::Vocabulary(), W::Address{u"play"});
|
||||
break;
|
||||
}
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,24 +122,174 @@ void M::Player::h_queue(const W::Event& ev)
|
|||
const W::Uint64& id = static_cast<const W::Uint64&>(data.at(u"id"));
|
||||
ProxySong* song = new ProxySong(id, address + W::Address{W::String(W::Uint64(counter++).toString())});
|
||||
addModel(song);
|
||||
_queue.push_back(song);
|
||||
_queueView->push(song->getAddress());
|
||||
|
||||
if (current == 0) {
|
||||
current = song;
|
||||
views.insert(std::make_pair(currentPlayback, song->getAddress()));
|
||||
W::Vocabulary* avc = new W::Vocabulary();
|
||||
avc->insert(u"type", new W::Uint64(currentPlayback));
|
||||
avc->insert(u"address", song->getAddress());
|
||||
|
||||
W::Vector* add = new W::Vector();
|
||||
add->push(avc);
|
||||
|
||||
W::Vocabulary* res = new W::Vocabulary();
|
||||
res->insert(u"add", add);
|
||||
res->insert(u"remove", new W::Vector());
|
||||
|
||||
broadcast(res, W::Address{u"viewsChange"});
|
||||
playPauseBtn->setEnabled(true);
|
||||
} else {
|
||||
_queue.push_back(song);
|
||||
_queueView->push(song->getAddress());
|
||||
scheduledToplay = true;
|
||||
setActive(song);
|
||||
}
|
||||
|
||||
if (currentIndex + 1 < _queue.size()) {
|
||||
nextBtn->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::play()
|
||||
{
|
||||
if (!playing) {
|
||||
playPauseBtn->setLabel(W::String(u"Pause"));
|
||||
playing = true;
|
||||
|
||||
switch (mode) {
|
||||
case playBack:
|
||||
if (current == 0) {
|
||||
scheduledToplay = true;
|
||||
} else {
|
||||
if (current->isReady()) {
|
||||
scheduledToplay = false;
|
||||
broadcast(new W::Vocabulary(), W::Address{u"play"});
|
||||
break;
|
||||
} else {
|
||||
scheduledToplay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::pause()
|
||||
{
|
||||
if (playing) {
|
||||
playPauseBtn->setLabel(W::String(u"Play"));
|
||||
playing = false;
|
||||
|
||||
switch (mode) {
|
||||
case playBack:
|
||||
scheduledToplay = false;
|
||||
broadcast(new W::Vocabulary(), W::Address{u"pause"});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::onSongReady()
|
||||
{
|
||||
emit serviceMessage("Song is ready");
|
||||
playPauseBtn->setEnabled(true);
|
||||
if (scheduledToplay) {
|
||||
scheduledToplay = false;
|
||||
if (playing) {
|
||||
scheduledToplay = false;
|
||||
broadcast(new W::Vocabulary(), W::Address{u"play"});
|
||||
} else {
|
||||
play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::onSongNotReady()
|
||||
{
|
||||
playPauseBtn->setEnabled(false);
|
||||
emit serviceMessage("Something happend to the current song, not sure yet what to do");
|
||||
}
|
||||
|
||||
void M::Player::onNextBtn()
|
||||
{
|
||||
if (currentIndex + 1 < _queue.size()) {
|
||||
if (playing) {
|
||||
pause();
|
||||
scheduledToplay = true;
|
||||
}
|
||||
setActive(currentIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::onPrevBtn()
|
||||
{
|
||||
if (currentIndex > 0) {
|
||||
if (playing) {
|
||||
pause();
|
||||
scheduledToplay = true;
|
||||
}
|
||||
setActive(currentIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::setActive(ProxySong* song)
|
||||
{
|
||||
if (current == song) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
int index;
|
||||
for (index = 0; index < _queue.size(); ++index) {
|
||||
if (_queue.at(index) == song) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
setActive(index);
|
||||
} else {
|
||||
emit serviceMessage("An attempt to set active a song which is no in the queue, not supposed to happen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void M::Player::setActive(uint64_t index)
|
||||
{
|
||||
if (index >= _queue.size()) {
|
||||
emit serviceMessage("An attempt to set active a song which is no in the queue, not supposed to happen");
|
||||
return;
|
||||
}
|
||||
|
||||
ProxySong* song = _queue.at(index);
|
||||
currentIndex = index;
|
||||
if (currentIndex + 1 < _queue.size()) {
|
||||
nextBtn->setEnabled(true);
|
||||
} else {
|
||||
nextBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
if (currentIndex > 0) {
|
||||
prevBtn->setEnabled(true);
|
||||
} else {
|
||||
prevBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
W::Vocabulary* res = new W::Vocabulary();
|
||||
W::Vector* add = new W::Vector();
|
||||
W::Vector* remove = new W::Vector();
|
||||
if (current != 0) {
|
||||
disconnect(current, SIGNAL(ready()), this, SLOT(onSongReady()));
|
||||
disconnect(current, SIGNAL(notReady()), this, SLOT(onSongNotReady()));
|
||||
remove->push(new W::Uint64(currentPlayback));
|
||||
}
|
||||
current = song;
|
||||
connect(song, SIGNAL(ready()), this, SLOT(onSongReady()));
|
||||
connect(song, SIGNAL(notReady()), this, SLOT(onSongNotReady()));
|
||||
views.insert(std::make_pair(currentPlayback, song->getAddress()));
|
||||
W::Vocabulary* avc = new W::Vocabulary();
|
||||
avc->insert(u"type", new W::Uint64(currentPlayback));
|
||||
avc->insert(u"address", song->getAddress());
|
||||
|
||||
add->push(avc);
|
||||
|
||||
res->insert(u"add", add);
|
||||
res->insert(u"remove", remove);
|
||||
|
||||
|
||||
broadcast(res, W::Address{u"viewsChange"});
|
||||
if (song->isReady()) {
|
||||
playPauseBtn->setEnabled(true);
|
||||
if (scheduledToplay) {
|
||||
play();
|
||||
}
|
||||
} else {
|
||||
playPauseBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,18 @@ namespace M {
|
|||
playPause,
|
||||
currentPlayback,
|
||||
queue,
|
||||
picture
|
||||
picture,
|
||||
prev,
|
||||
next
|
||||
};
|
||||
|
||||
enum Mode {
|
||||
playBack
|
||||
};
|
||||
|
||||
void play();
|
||||
void pause();
|
||||
|
||||
protected:
|
||||
void h_subscribe(const W::Event & ev) override;
|
||||
|
||||
|
@ -52,15 +57,26 @@ namespace M {
|
|||
ItemMap controls;
|
||||
ItemMap views;
|
||||
M::Button* playPauseBtn;
|
||||
M::Button* nextBtn;
|
||||
M::Button* prevBtn;
|
||||
M::List* _queueView;
|
||||
Queue _queue;
|
||||
ProxySong* current;
|
||||
uint64_t counter;
|
||||
uint64_t currentIndex;
|
||||
Mode mode;
|
||||
bool playing;
|
||||
bool scheduledToplay;
|
||||
|
||||
void setActive(ProxySong* song);
|
||||
void setActive(uint64_t index);
|
||||
|
||||
private slots:
|
||||
void onPlayPauseBtn();
|
||||
void onNextBtn();
|
||||
void onPrevBtn();
|
||||
void onSongReady();
|
||||
void onSongNotReady();
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue