an image to player, first ideas to make a playback
This commit is contained in:
parent
fd255bad0a
commit
2a4dce3616
@ -8,7 +8,9 @@ M::Player::Player(const W::Address& address, QObject* parent):
|
|||||||
_queueView(new M::List(address + W::Address{u"queueView"})),
|
_queueView(new M::List(address + W::Address{u"queueView"})),
|
||||||
_queue(),
|
_queue(),
|
||||||
current(0),
|
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* 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);
|
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"controls", ctrls);
|
||||||
res->insert(u"views", vws);
|
res->insert(u"views", vws);
|
||||||
|
res->insert(u"mode", new W::Uint64(mode));
|
||||||
|
|
||||||
response(res, W::Address({u"get"}), ev);
|
response(res, W::Address({u"get"}), ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void M::Player::onPlayPauseBtn()
|
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)
|
void M::Player::h_queue(const W::Event& ev)
|
||||||
|
@ -31,7 +31,12 @@ namespace M {
|
|||||||
enum ItemType {
|
enum ItemType {
|
||||||
playPause,
|
playPause,
|
||||||
currentPlayback,
|
currentPlayback,
|
||||||
queue
|
queue,
|
||||||
|
picture
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Mode {
|
||||||
|
playBack
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -51,6 +56,8 @@ namespace M {
|
|||||||
Queue _queue;
|
Queue _queue;
|
||||||
ProxySong* current;
|
ProxySong* current;
|
||||||
uint64_t counter;
|
uint64_t counter;
|
||||||
|
Mode mode;
|
||||||
|
bool playing;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPlayPauseBtn();
|
void onPlayPauseBtn();
|
||||||
|
@ -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"album"), new W::String(u"undefined"));
|
||||||
insert(W::String(u"song"), 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"image"), new W::Uint64(0));
|
||||||
|
insert(W::String(u"audio"), new W::Uint64(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProxySong::isReady() const
|
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);
|
fileId = static_cast<const W::Uint64&>(element);
|
||||||
|
insert(key, element);
|
||||||
_ready = true;
|
_ready = true;
|
||||||
emit ready();
|
emit ready();
|
||||||
} else if (key == u"artist") {
|
} else if (key == u"artist") {
|
||||||
@ -73,6 +75,7 @@ void ProxySong::onSongRemoveElement(const W::String& key)
|
|||||||
if (key == u"name") {
|
if (key == u"name") {
|
||||||
insert(key, new W::String(u"undefined"));
|
insert(key, new W::String(u"undefined"));
|
||||||
} else if (key == u"audio") {
|
} else if (key == u"audio") {
|
||||||
|
insert(key, new W::Uint64(0));
|
||||||
if (_ready) {
|
if (_ready) {
|
||||||
_ready = false;
|
_ready = false;
|
||||||
fileId = W::Uint64(0);
|
fileId = W::Uint64(0);
|
||||||
|
@ -18,3 +18,4 @@ configure_file(catalogue.js catalogue.js)
|
|||||||
configure_file(imagePane.js imagePane.js)
|
configure_file(imagePane.js imagePane.js)
|
||||||
configure_file(file/file.js file/file.js)
|
configure_file(file/file.js file/file.js)
|
||||||
configure_file(player.js player.js)
|
configure_file(player.js player.js)
|
||||||
|
configure_file(imageById.js imageById.js)
|
||||||
|
46
libjs/wController/imageById.js
Normal file
46
libjs/wController/imageById.js
Normal 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;
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var Subscribable = require("../utils/subscribable");
|
var Subscribable = require("../utils/subscribable");
|
||||||
|
var Controller = require("./controller");
|
||||||
|
|
||||||
var LocalModel = Subscribable.inherit({
|
var LocalModel = Subscribable.inherit({
|
||||||
"className": "LocalModel",
|
"className": "LocalModel",
|
||||||
@ -9,6 +10,7 @@ var LocalModel = Subscribable.inherit({
|
|||||||
|
|
||||||
this.properties = [];
|
this.properties = [];
|
||||||
this._controllers = [];
|
this._controllers = [];
|
||||||
|
this._foreignControllers = [];
|
||||||
|
|
||||||
if (properties) {
|
if (properties) {
|
||||||
for (var key in properties) {
|
for (var key in properties) {
|
||||||
@ -25,6 +27,14 @@ var LocalModel = Subscribable.inherit({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"destructor": function() {
|
"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) {
|
for (var i = 0; i < this._controllers.length; ++i) {
|
||||||
this._controllers[i].destructor();
|
this._controllers[i].destructor();
|
||||||
}
|
}
|
||||||
@ -34,6 +44,40 @@ var LocalModel = Subscribable.inherit({
|
|||||||
"addController": function(ctrl) {
|
"addController": function(ctrl) {
|
||||||
this._controllers.push(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) {
|
"setData": function(data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var Uint64 = require("../wType/uint64");
|
||||||
|
var Address = require("../wType/address");
|
||||||
|
|
||||||
var Controller = require("./controller");
|
var Controller = require("./controller");
|
||||||
var Button = require("./button");
|
var Button = require("./button");
|
||||||
|
var ImageById = require("./imageById");
|
||||||
var Vocabulary = require("./vocabulary");
|
var Vocabulary = require("./vocabulary");
|
||||||
var Enum = require("../utils/enum");
|
var Enum = require("../utils/enum");
|
||||||
|
|
||||||
@ -12,6 +16,7 @@ var Player = Controller.inherit({
|
|||||||
|
|
||||||
this.controls = Object.create(null);
|
this.controls = Object.create(null);
|
||||||
this.views = Object.create(null);
|
this.views = Object.create(null);
|
||||||
|
this.mode = PlayerMode.straight.playback;
|
||||||
|
|
||||||
this.addHandler("get");
|
this.addHandler("get");
|
||||||
this.addHandler("viewsChange");
|
this.addHandler("viewsChange");
|
||||||
@ -41,6 +46,8 @@ var Player = Controller.inherit({
|
|||||||
},
|
},
|
||||||
_addView: function(type, address) {
|
_addView: function(type, address) {
|
||||||
var t = type.valueOf();
|
var t = type.valueOf();
|
||||||
|
var ctrl;
|
||||||
|
var supported = false;
|
||||||
|
|
||||||
if (this.views[t] !== undefined) {
|
if (this.views[t] !== undefined) {
|
||||||
throw new Error("An attempt to add multiple instances of " + ItemType.reversed[t] + " into Player");
|
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");
|
this.trigger("serviceMessage", "Queue is not supported yet in Player");
|
||||||
break;
|
break;
|
||||||
case ItemType.straight.currentPlayback:
|
case ItemType.straight.currentPlayback:
|
||||||
var cpb = new Vocabulary(address.clone());
|
ctrl = new Vocabulary(address.clone());
|
||||||
cpb.ItemType = t;
|
ctrl.on("newElement", this._onNewPlayBackElement, this);
|
||||||
this.views[t] = cpb;
|
ctrl.on("removeElement", this._onNewRemoveBackElement, this);
|
||||||
this.addController(cpb);
|
supported = true;
|
||||||
this.trigger("newElement", cpb, t);
|
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;
|
break;
|
||||||
default:
|
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");
|
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 {
|
} else {
|
||||||
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t);
|
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) {
|
_h_get: function(ev) {
|
||||||
var data = ev.getData();
|
var data = ev.getData();
|
||||||
|
|
||||||
var controls = data.at("controls");
|
var controls = data.at("controls");
|
||||||
var views = data.at("views");
|
var views = data.at("views");
|
||||||
|
var mode = data.at("mode").valueOf();
|
||||||
var size, i, vc;
|
var size, i, vc;
|
||||||
|
|
||||||
size = controls.length();
|
size = controls.length();
|
||||||
@ -84,6 +107,13 @@ var Player = Controller.inherit({
|
|||||||
this._addView(vc.at("type"), vc.at("address"));
|
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.initialized = true;
|
||||||
this.trigger("data");
|
this.trigger("data");
|
||||||
},
|
},
|
||||||
@ -105,19 +135,38 @@ var Player = Controller.inherit({
|
|||||||
this._addView(vc.at("type"), vc.at("address"));
|
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) {
|
_removeControl: function(type) {
|
||||||
//TODO
|
//TODO
|
||||||
},
|
},
|
||||||
_removeView: function(type) {
|
_removeView: function(type) {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var ItemType = new Enum("ItemType");
|
var ItemType = new Enum("ItemType");
|
||||||
ItemType.add("playPause");
|
ItemType.add("playPause");
|
||||||
ItemType.add("currentPlayback");
|
ItemType.add("currentPlayback");
|
||||||
ItemType.add("queue");
|
ItemType.add("queue");
|
||||||
|
ItemType.add("picture");
|
||||||
|
|
||||||
|
var PlayerMode = new Enum("PlayerMode");
|
||||||
|
PlayerMode.add("playback");
|
||||||
|
|
||||||
Player.ItemType = ItemType;
|
Player.ItemType = ItemType;
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@
|
|||||||
if (this._playerCtl) {
|
if (this._playerCtl) {
|
||||||
this._mainLayout.removePlayer();
|
this._mainLayout.removePlayer();
|
||||||
this._playerCtl._onSocketDisconnected();
|
this._playerCtl._onSocketDisconnected();
|
||||||
this._playerCtl.uneregister();
|
this._playerCtl.unregister();
|
||||||
this._playerCtl.destructor();
|
this._playerCtl.destructor();
|
||||||
this._playerCtl = undefined;
|
this._playerCtl = undefined;
|
||||||
}
|
}
|
||||||
|
@ -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/image.js lib/wController/image ${LORGAR_DIR} browser)
|
||||||
add_jslib(wController/button.js lib/wController/button ${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/player.js lib/wController/player ${LORGAR_DIR} browser)
|
||||||
|
add_jslib(wController/imageById.js lib/wController/imageById ${LORGAR_DIR} browser)
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
deps.push("views/button");
|
deps.push("views/button");
|
||||||
deps.push("views/label");
|
deps.push("views/label");
|
||||||
deps.push("views/view");
|
deps.push("views/view");
|
||||||
|
deps.push("views/image");
|
||||||
|
|
||||||
deps.push("lib/wController/localModel");
|
deps.push("lib/wController/localModel");
|
||||||
|
|
||||||
@ -17,6 +18,7 @@
|
|||||||
var Button = require("views/button");
|
var Button = require("views/button");
|
||||||
var Label = require("views/label");
|
var Label = require("views/label");
|
||||||
var View = require("views/view");
|
var View = require("views/view");
|
||||||
|
var Image = require("views/image");
|
||||||
|
|
||||||
var Model = require("lib/wController/localModel");
|
var Model = require("lib/wController/localModel");
|
||||||
|
|
||||||
@ -28,6 +30,7 @@
|
|||||||
GridLayout.fn.constructor.call(this, ctrl, options);
|
GridLayout.fn.constructor.call(this, ctrl, options);
|
||||||
|
|
||||||
this._playPause = null;
|
this._playPause = null;
|
||||||
|
this._picture = null;
|
||||||
this._cpbCtrl = null;
|
this._cpbCtrl = null;
|
||||||
this._infoModels = {
|
this._infoModels = {
|
||||||
artist: new Model(null, "artist: unknown"),
|
artist: new Model(null, "artist: unknown"),
|
||||||
@ -80,6 +83,13 @@
|
|||||||
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
|
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
|
||||||
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
|
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
|
||||||
break;
|
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) {
|
_onCpbNewElement: function(key, value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user