2018-08-04 21:52:16 +00:00
|
|
|
#include "player.h"
|
|
|
|
|
|
|
|
M::Player::Player(const W::Address& address, QObject* parent):
|
|
|
|
M::Model(address, parent),
|
|
|
|
controls(),
|
|
|
|
views(),
|
2018-12-17 17:15:58 +00:00
|
|
|
playPauseBtn(new M::Button(address + W::Address{u"Play"})),
|
2018-08-04 21:52:16 +00:00
|
|
|
_queueView(new M::List(address + W::Address{u"queueView"})),
|
|
|
|
_queue(),
|
2018-10-28 21:32:44 +00:00
|
|
|
current(0),
|
2018-12-02 15:07:43 +00:00
|
|
|
counter(0),
|
|
|
|
mode(playBack),
|
|
|
|
playing(false)
|
2018-08-04 21:52:16 +00:00
|
|
|
{
|
|
|
|
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->setEnabled(false);
|
|
|
|
connect(playPauseBtn, SIGNAL(activated()), this, SLOT(onPlayPauseBtn()));
|
|
|
|
|
|
|
|
addModel(playPauseBtn);
|
|
|
|
addModel(_queueView);
|
|
|
|
|
|
|
|
controls.insert(std::make_pair(playPause, playPauseBtn->getAddress()));
|
|
|
|
views.insert(std::make_pair(queue, _queueView->getAddress()));
|
|
|
|
}
|
|
|
|
|
|
|
|
M::Player::~Player()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::set(const W::Object& value)
|
|
|
|
{
|
|
|
|
throw 14; //what do you expect here? not implemented, and not sure it ever would be
|
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::set(W::Object* value)
|
|
|
|
{
|
|
|
|
set(*value);
|
|
|
|
}
|
|
|
|
|
|
|
|
M::Model::ModelType M::Player::getType() const
|
|
|
|
{
|
|
|
|
return M::Model::player;
|
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::h_subscribe(const W::Event& ev)
|
|
|
|
{
|
|
|
|
M::Model::h_subscribe(ev);
|
|
|
|
|
|
|
|
h_get(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::h_get(const W::Event& ev)
|
|
|
|
{
|
|
|
|
W::Vector* ctrls = new W::Vector();
|
|
|
|
ItemMap::const_iterator citr = controls.begin();
|
|
|
|
ItemMap::const_iterator cend = controls.end();
|
|
|
|
|
|
|
|
for (; citr != cend; ++citr) {
|
|
|
|
W::Vocabulary* cvc = new W::Vocabulary();
|
2018-10-28 21:32:44 +00:00
|
|
|
cvc->insert(u"type", new W::Uint64(citr->first));
|
|
|
|
cvc->insert(u"address", citr->second);
|
2018-08-04 21:52:16 +00:00
|
|
|
|
|
|
|
ctrls->push(cvc);
|
|
|
|
}
|
|
|
|
|
|
|
|
W::Vector* vws = new W::Vector();
|
|
|
|
ItemMap::const_iterator vitr = views.begin();
|
|
|
|
ItemMap::const_iterator vend = views.end();
|
|
|
|
|
|
|
|
for (; vitr != vend; ++vitr) {
|
|
|
|
W::Vocabulary* vvc = new W::Vocabulary();
|
2018-10-28 21:32:44 +00:00
|
|
|
vvc->insert(u"type", new W::Uint64(vitr->first));
|
|
|
|
vvc->insert(u"address", vitr->second);
|
2018-08-04 21:52:16 +00:00
|
|
|
|
|
|
|
vws->push(vvc);
|
|
|
|
}
|
|
|
|
|
|
|
|
W::Vocabulary* res = new W::Vocabulary();
|
|
|
|
|
|
|
|
res->insert(u"controls", ctrls);
|
|
|
|
res->insert(u"views", vws);
|
2018-12-02 15:07:43 +00:00
|
|
|
res->insert(u"mode", new W::Uint64(mode));
|
2018-08-04 21:52:16 +00:00
|
|
|
|
|
|
|
response(res, W::Address({u"get"}), ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::onPlayPauseBtn()
|
|
|
|
{
|
2018-12-02 15:07:43 +00:00
|
|
|
if (playing) {
|
2018-12-17 17:15:58 +00:00
|
|
|
playPauseBtn->setLabel(W::String(u"Play"));
|
2018-12-02 15:07:43 +00:00
|
|
|
playing = false;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case playBack:
|
|
|
|
broadcast(new W::Vocabulary(), W::Address{u"pause"});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-17 17:15:58 +00:00
|
|
|
playPauseBtn->setLabel(W::String(u"Pause"));
|
2018-12-02 15:07:43 +00:00
|
|
|
playing = true;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case playBack:
|
|
|
|
broadcast(new W::Vocabulary(), W::Address{u"play"});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-04 21:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void M::Player::h_queue(const W::Event& ev)
|
|
|
|
{
|
|
|
|
const W::Vocabulary& data = static_cast<const W::Vocabulary&>(ev.getData());
|
|
|
|
|
|
|
|
const W::Uint64& id = static_cast<const W::Uint64&>(data.at(u"id"));
|
2018-10-28 21:32:44 +00:00
|
|
|
ProxySong* song = new ProxySong(id, address + W::Address{W::String(W::Uint64(counter++).toString())});
|
2018-08-04 21:52:16 +00:00
|
|
|
addModel(song);
|
|
|
|
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"});
|
2018-12-17 17:15:58 +00:00
|
|
|
playPauseBtn->setEnabled(true);
|
2018-08-04 21:52:16 +00:00
|
|
|
} else {
|
|
|
|
_queue.push_back(song);
|
|
|
|
_queueView->push(song->getAddress());
|
|
|
|
}
|
|
|
|
}
|