WIP Merging basic player to master #6

Merged
blue merged 17 commits from player into master 2019-02-01 22:32:52 +00:00
10 changed files with 192 additions and 10 deletions
Showing only changes of commit 98a443e298 - Show all commits

View File

@ -8,7 +8,9 @@ M::Player::Player(const W::Address& address, QObject* parent):
_queueView(new M::List(address + W::Address{u"queueView"})),
_queue(),
current(0),
counter(0)
counter(0),
mode(playBack),
playing(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);
@ -83,13 +85,32 @@ void M::Player::h_get(const W::Event& ev)
res->insert(u"controls", ctrls);
res->insert(u"views", vws);
res->insert(u"mode", new W::Uint64(mode));
response(res, W::Address({u"get"}), ev);
}
void M::Player::onPlayPauseBtn()
{
if (playing) {
playPauseBtn->setLabel(W::String(u"Pause"));
playing = false;
switch (mode) {
case playBack:
broadcast(new W::Vocabulary(), W::Address{u"pause"});
break;
}
} else {
playPauseBtn->setLabel(W::String(u"Play"));
playing = true;
switch (mode) {
case playBack:
broadcast(new W::Vocabulary(), W::Address{u"play"});
break;
}
}
}
void M::Player::h_queue(const W::Event& ev)

View File

@ -31,7 +31,12 @@ namespace M {
enum ItemType {
playPause,
currentPlayback,
queue
queue,
picture
};
enum Mode {
playBack
};
protected:
@ -51,6 +56,8 @@ namespace M {
Queue _queue;
ProxySong* current;
uint64_t counter;
Mode mode;
bool playing;
private slots:
void onPlayPauseBtn();

View File

@ -17,6 +17,7 @@ ProxySong::ProxySong(const W::Uint64& p_id, const W::Address& p_address, QObject
insert(W::String(u"album"), new W::String(u"undefined"));
insert(W::String(u"song"), new W::String(u"undefined"));
insert(W::String(u"image"), new W::Uint64(0));
insert(W::String(u"audio"), new W::Uint64(0));
}
bool ProxySong::isReady() const
@ -39,6 +40,7 @@ void ProxySong::onSongNewElement(const W::String& key, const W::Object& element)
}
fileId = static_cast<const W::Uint64&>(element);
insert(key, element);
_ready = true;
emit ready();
} else if (key == u"artist") {
@ -73,6 +75,7 @@ void ProxySong::onSongRemoveElement(const W::String& key)
if (key == u"name") {
insert(key, new W::String(u"undefined"));
} else if (key == u"audio") {
insert(key, new W::Uint64(0));
if (_ready) {
_ready = false;
fileId = W::Uint64(0);

View File

@ -18,3 +18,4 @@ configure_file(catalogue.js catalogue.js)
configure_file(imagePane.js imagePane.js)
configure_file(file/file.js file/file.js)
configure_file(player.js player.js)
configure_file(imageById.js imageById.js)

View File

@ -0,0 +1,46 @@
"use strict";
var LocalModel = require("./localModel");
var File = require("./file/file");
var Address = require("../wType/address");
var ImageById = LocalModel.inherit({
className: "ImageById",
constructor: function(properties, id) {
LocalModel.fn.constructor.call(this, properties);
this._imageId = id;
this._fileCtrl = new File(new Address(["images", this._imageId.toString()]));
this._need = 0;
this._fileCtrl.on("data", this._onControllerData, this);
this.addForeignController("Corax", this._fileCtrl);
},
dontNeedData: function() {
--this._need;
if (this._need === 0) {
this._fileCtrl.dontNeedData();
}
},
getMimeType: function () {
return this._fileCtrl.getMimeType();
},
hasData: function() {
return this._fileCtrl.hasData();
},
needData: function() {
if (this._need === 0) {
this._fileCtrl.needData();
}
++this._need;
},
_onControllerData: function() {
this.data = this._fileCtrl.data;
this.trigger("data");
}
});
module.exports = ImageById;

View File

@ -1,6 +1,7 @@
"use strict";
var counter = 0;
var Subscribable = require("../utils/subscribable");
var Controller = require("./controller");
var LocalModel = Subscribable.inherit({
"className": "LocalModel",
@ -9,6 +10,7 @@ var LocalModel = Subscribable.inherit({
this.properties = [];
this._controllers = [];
this._foreignControllers = [];
if (properties) {
for (var key in properties) {
@ -25,6 +27,14 @@ var LocalModel = Subscribable.inherit({
}
},
"destructor": function() {
for (i = 0; i < this._foreignControllers.length; ++i) {
var pair = this._foreignControllers[i];
global.unsubscribeForeignController(pair.n, pair.c);
global.registerForeignController(pair.n, pair.c);
pair.c.destructor();
}
for (var i = 0; i < this._controllers.length; ++i) {
this._controllers[i].destructor();
}
@ -34,6 +44,40 @@ var LocalModel = Subscribable.inherit({
"addController": function(ctrl) {
this._controllers.push(ctrl);
},
"addForeignController": function(nodeName, ctrl) {
if (!(ctrl instanceof Controller)) {
throw new Error("An attempt to add not a controller into " + this.className);
}
this._foreignControllers.push({n: nodeName, c: ctrl});
ctrl.on("serviceMessage", this._onControllerServiceMessage, this);
global.registerForeignController(nodeName, ctrl);
global.subscribeForeignController(nodeName, ctrl);
},
"_onControllerServiceMessage": Controller.fn._onControllerServiceMessage,
"removeForeignController": function(ctrl) {
if (!(ctrl instanceof Controller)) {
throw new Error("An attempt to remove not a controller from " + this.className);
}
for (var i = 0; i < this._foreignControllers.length; ++i) {
if (this._foreignControllers[i].c === ctrl) {
break;
}
}
if (i === this._foreignControllers.length) {
throw new Error("An attempt to remove not not existing controller from " + this.className);
} else {
var pair = this._foreignControllers[i];
global.unsubscribeForeignController(pair.n, pair.c);
global.registerForeignController(pair.n, pair.c);
pair.c.off("serviceMessage", this._onControllerServiceMessage, this);
this._foreignControllers.splice(i, 1);
}
},
"setData": function(data) {
this.data = data;
this.initialized = true;

View File

@ -1,7 +1,11 @@
"use strict";
var Uint64 = require("../wType/uint64");
var Address = require("../wType/address");
var Controller = require("./controller");
var Button = require("./button");
var ImageById = require("./imageById");
var Vocabulary = require("./vocabulary");
var Enum = require("../utils/enum");
@ -12,6 +16,7 @@ var Player = Controller.inherit({
this.controls = Object.create(null);
this.views = Object.create(null);
this.mode = PlayerMode.straight.playback;
this.addHandler("get");
this.addHandler("viewsChange");
@ -41,6 +46,8 @@ var Player = Controller.inherit({
},
_addView: function(type, address) {
var t = type.valueOf();
var ctrl;
var supported = false;
if (this.views[t] !== undefined) {
throw new Error("An attempt to add multiple instances of " + ItemType.reversed[t] + " into Player");
@ -52,11 +59,18 @@ var Player = Controller.inherit({
this.trigger("serviceMessage", "Queue is not supported yet in Player");
break;
case ItemType.straight.currentPlayback:
var cpb = new Vocabulary(address.clone());
cpb.ItemType = t;
this.views[t] = cpb;
this.addController(cpb);
this.trigger("newElement", cpb, t);
ctrl = new Vocabulary(address.clone());
ctrl.on("newElement", this._onNewPlayBackElement, this);
ctrl.on("removeElement", this._onNewRemoveBackElement, this);
supported = true;
break;
case ItemType.straight.picture:
ctrl = new ImageById(null, address.back());
ctrl.ItemType = t;
this.views[t] = ctrl;
this.trigger("newElement", ctrl, t);
supported = false; //just to avoid adding with addController, since ImageById is not a controller
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to views of the Player, but it's not qualified to be a view");
@ -64,12 +78,21 @@ var Player = Controller.inherit({
} else {
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t);
}
if (supported) {
ctrl.ItemType = t;
this.views[t] = ctrl;
this.addController(ctrl);
this.trigger("newElement", ctrl, t);
}
},
_h_get: function(ev) {
var data = ev.getData();
var controls = data.at("controls");
var views = data.at("views");
var mode = data.at("mode").valueOf();
var size, i, vc;
size = controls.length();
@ -84,6 +107,13 @@ var Player = Controller.inherit({
this._addView(vc.at("type"), vc.at("address"));
}
if (this.mode !== mode) {
if (PlayerMode.reversed[mode] === undefined) {
throw new Error("Unsupported mode of player: " + mode);
}
this.mode = mode;
}
this.initialized = true;
this.trigger("data");
},
@ -105,19 +135,38 @@ var Player = Controller.inherit({
this._addView(vc.at("type"), vc.at("address"));
}
},
_onNewPlayBackElement: function(key, element) {
switch (key) {
case "image":
var address = new Address(["images", element.toString()]);
this._addView(new Uint64(ItemType.straight.picture), address);
address.destructor();
break;
}
},
_onNewRemoveBackElement: function(key) {
switch (key) {
case "image":
this._removeView(new Uint64(ItemType.straight.picture));
break;
}
},
_removeControl: function(type) {
//TODO
},
_removeView: function(type) {
//TODO
}
});
var ItemType = new Enum("ItemType");
ItemType.add("playPause");
ItemType.add("currentPlayback");
ItemType.add("queue");
ItemType.add("picture");
var PlayerMode = new Enum("PlayerMode");
PlayerMode.add("playback");
Player.ItemType = ItemType;

View File

@ -211,7 +211,7 @@
if (this._playerCtl) {
this._mainLayout.removePlayer();
this._playerCtl._onSocketDisconnected();
this._playerCtl.uneregister();
this._playerCtl.unregister();
this._playerCtl.destructor();
this._playerCtl = undefined;
}

View File

@ -19,3 +19,4 @@ add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} brows
add_jslib(wController/image.js lib/wController/image ${LORGAR_DIR} browser)
add_jslib(wController/button.js lib/wController/button ${LORGAR_DIR} browser)
add_jslib(wController/player.js lib/wController/player ${LORGAR_DIR} browser)
add_jslib(wController/imageById.js lib/wController/imageById ${LORGAR_DIR} browser)

View File

@ -7,6 +7,7 @@
deps.push("views/button");
deps.push("views/label");
deps.push("views/view");
deps.push("views/image");
deps.push("lib/wController/localModel");
@ -17,6 +18,7 @@
var Button = require("views/button");
var Label = require("views/label");
var View = require("views/view");
var Image = require("views/image");
var Model = require("lib/wController/localModel");
@ -28,6 +30,7 @@
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._picture = null;
this._cpbCtrl = null;
this._infoModels = {
artist: new Model(null, "artist: unknown"),
@ -80,6 +83,13 @@
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
case ItemType.straight.picture:
this._picture = new Image(ctrl, {
maxWidth: 100,
maxHeight: 100
});
this.append(this._picture, 0, 0, 3, 1);
break;
}
},
_onCpbNewElement: function(key, value) {