a draft of player view, debug

This commit is contained in:
Blue 2018-10-29 00:32:44 +03:00 committed by Gitea
parent 46560924ce
commit c8b432fe57
13 changed files with 183 additions and 33 deletions

View File

@ -125,6 +125,7 @@ void Corax::start()
} }
commands->enableCommand(W::String(u"clearCache"), true); commands->enableCommand(W::String(u"clearCache"), true);
commands->enableCommand(W::String(u"givePlayer"), true);
started = true; started = true;
cout << "Corax is ready" << endl; cout << "Corax is ready" << endl;
@ -262,7 +263,6 @@ void Corax::onNodeConnected(const W::String& name)
cout << "connected node " << name.toString() << endl; cout << "connected node " << name.toString() << endl;
if (name == u"Perturabo") { if (name == u"Perturabo") {
commands->enableCommand(W::String(u"parseDirectory"), true); commands->enableCommand(W::String(u"parseDirectory"), true);
commands->enableCommand(W::String(u"givePlayer"), true);
} }
} }
@ -271,7 +271,6 @@ void Corax::onNodeDisconnected(const W::String& name)
cout << "disconnected node " << name.toString() << endl; cout << "disconnected node " << name.toString() << endl;
if (name == u"Perturabo") { if (name == u"Perturabo") {
commands->enableCommand(W::String(u"parseDirectory"), false); commands->enableCommand(W::String(u"parseDirectory"), false);
commands->enableCommand(W::String(u"givePlayer"), false);
} }
} }

View File

@ -7,7 +7,8 @@ M::Player::Player(const W::Address& address, QObject* parent):
playPauseBtn(new M::Button(address + W::Address{u"play"})), playPauseBtn(new M::Button(address + W::Address{u"play"})),
_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)
{ {
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);
@ -52,7 +53,6 @@ void M::Player::h_subscribe(const W::Event& ev)
h_get(ev); h_get(ev);
} }
void M::Player::h_get(const W::Event& ev) void M::Player::h_get(const W::Event& ev)
{ {
W::Vector* ctrls = new W::Vector(); W::Vector* ctrls = new W::Vector();
@ -61,8 +61,8 @@ void M::Player::h_get(const W::Event& ev)
for (; citr != cend; ++citr) { for (; citr != cend; ++citr) {
W::Vocabulary* cvc = new W::Vocabulary(); W::Vocabulary* cvc = new W::Vocabulary();
cvc->insert(u"type", new W::Uint64(cend->first)); cvc->insert(u"type", new W::Uint64(citr->first));
cvc->insert(u"address", cend->second); cvc->insert(u"address", citr->second);
ctrls->push(cvc); ctrls->push(cvc);
} }
@ -73,8 +73,8 @@ void M::Player::h_get(const W::Event& ev)
for (; vitr != vend; ++vitr) { for (; vitr != vend; ++vitr) {
W::Vocabulary* vvc = new W::Vocabulary(); W::Vocabulary* vvc = new W::Vocabulary();
vvc->insert(u"type", new W::Uint64(vend->first)); vvc->insert(u"type", new W::Uint64(vitr->first));
vvc->insert(u"address", vend->second); vvc->insert(u"address", vitr->second);
vws->push(vvc); vws->push(vvc);
} }
@ -97,7 +97,7 @@ void M::Player::h_queue(const W::Event& ev)
const W::Vocabulary& data = static_cast<const W::Vocabulary&>(ev.getData()); const W::Vocabulary& data = static_cast<const W::Vocabulary&>(ev.getData());
const W::Uint64& id = static_cast<const W::Uint64&>(data.at(u"id")); const W::Uint64& id = static_cast<const W::Uint64&>(data.at(u"id"));
ProxySong* song = new ProxySong(id, address + W::Address{u"currentPlayback"}); ProxySong* song = new ProxySong(id, address + W::Address{W::String(W::Uint64(counter++).toString())});
addModel(song); addModel(song);
if (current == 0) { if (current == 0) {
current = song; current = song;

View File

@ -41,7 +41,7 @@ namespace M {
handler(queue); handler(queue);
private: private:
typedef std::map<ItemType, const W::Address&> ItemMap; typedef std::map<ItemType, W::Address> ItemMap;
typedef std::deque<ProxySong*> Queue; typedef std::deque<ProxySong*> Queue;
ItemMap controls; ItemMap controls;
@ -50,6 +50,7 @@ namespace M {
M::List* _queueView; M::List* _queueView;
Queue _queue; Queue _queue;
ProxySong* current; ProxySong* current;
uint64_t counter;
private slots: private slots:
void onPlayPauseBtn(); void onPlayPauseBtn();

View File

@ -23,7 +23,7 @@ var Enum = Class.inherit({
this.additional = Object.create(null); this.additional = Object.create(null);
this._additionals = additional || []; this._additionals = additional || [];
this._lastId = 0; this._lastId = -1;
storage[name] = this; storage[name] = this;
}, },

View File

@ -34,6 +34,8 @@ var Button = Controller.inherit({
this._h_setLabel(ev); this._h_setLabel(ev);
this._h_setImage(ev); this._h_setImage(ev);
this._h_setEnabled(ev); this._h_setEnabled(ev);
this.initialized = true;
}, },
"_h_setEnabled": function(ev) { "_h_setEnabled": function(ev) {
var data = ev.getData(); var data = ev.getData();

View File

@ -4,7 +4,7 @@ var Subscribable = require("../utils/subscribable");
var LocalModel = Subscribable.inherit({ var LocalModel = Subscribable.inherit({
"className": "LocalModel", "className": "LocalModel",
"constructor": function(properties) { "constructor": function(properties, data) {
Subscribable.fn.constructor.call(this); Subscribable.fn.constructor.call(this);
this.properties = []; this.properties = [];
@ -18,6 +18,11 @@ var LocalModel = Subscribable.inherit({
} }
} }
} }
if (data !== undefined) {
this.data = data;
this.initialized = true;
}
}, },
"setData": function(data) { "setData": function(data) {
this.data = data; this.data = data;

View File

@ -30,6 +30,7 @@ var Player = Controller.inherit({
btn.itemType = t; btn.itemType = t;
this.controls[t] = btn; this.controls[t] = btn;
this.addController(btn); this.addController(btn);
this.trigger("newElement", btn, t);
break; break;
default: default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to controls of the Player, but it's not qualified to be a control"); this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to controls of the Player, but it's not qualified to be a control");
@ -55,6 +56,8 @@ var Player = Controller.inherit({
cpb.ItemType = t; cpb.ItemType = t;
this.views[t] = cpb; this.views[t] = cpb;
this.addController(cpb); this.addController(cpb);
this.trigger("newElement", cpb, t);
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");
} }
@ -78,8 +81,11 @@ var Player = Controller.inherit({
size = views.length(); size = views.length();
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
vc = views.at(i); vc = views.at(i);
this._addview(vc.at("type"), vc.at("address")); this._addView(vc.at("type"), vc.at("address"));
} }
this.initialized = true;
this.trigger("data");
}, },
_h_viewsChange: function(ev) { _h_viewsChange: function(ev) {
var data = ev.getData(); var data = ev.getData();
@ -96,7 +102,7 @@ var Player = Controller.inherit({
size = add.length(); size = add.length();
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
vc = add.at(i); vc = add.at(i);
this._addview(vc.at("type"), vc.at("address")); this._addView(vc.at("type"), vc.at("address"));
} }
}, },
_removeControl: function(type) { _removeControl: function(type) {

View File

@ -19,6 +19,7 @@
defineArray.push("lib/wController/pageStorage"); defineArray.push("lib/wController/pageStorage");
defineArray.push("lib/wController/page"); defineArray.push("lib/wController/page");
defineArray.push("lib/wController/localModel"); defineArray.push("lib/wController/localModel");
defineArray.push("lib/wController/player");
defineArray.push("views/view"); defineArray.push("views/view");
defineArray.push("views/layout"); defineArray.push("views/layout");
@ -43,6 +44,7 @@
var PageStorage = require("lib/wController/pageStorage"); var PageStorage = require("lib/wController/pageStorage");
var PageController = require("lib/wController/page"); var PageController = require("lib/wController/page");
var LocalModel = require("lib/wController/localModel"); var LocalModel = require("lib/wController/localModel");
var PlayerModel = require("lib/wController/player");
var View = require("views/view"); var View = require("views/view");
var Layout = require("views/layout"); var Layout = require("views/layout");
@ -204,9 +206,20 @@
var node = this._nodes[name]; var node = this._nodes[name];
node.connected = false; node.connected = false;
switch (name) {
case "Corax":
if (this._playerCtl) {
this._mainLayout.removePlayer();
this._playerCtl._onSocketDisconnected();
this._playerCtl.uneregister();
this._playerCtl.destructor();
this._playerCtl = undefined;
}
}
for (var id in node.foreigns) { for (var id in node.foreigns) {
if (node.foreigns[id].subscribed) { if (node.foreigns[id].subscribed) {
node.foreigns[id].controller._onSocketDisconnected; node.foreigns[id].controller._onSocketDisconnected();
} }
} }
node.state.setData(SocketState.straight.disconnected); node.state.setData(SocketState.straight.disconnected);
@ -242,14 +255,14 @@
this._nodes[name] = obj; this._nodes[name] = obj;
}, },
"registerForeignController": function(node, controller) { "registerForeignController": function(nodeName, controller) {
var node = this._nodes[node]; var node = this._nodes[nodeName];
if (node === undefined) { if (node === undefined) {
throw new Error("An attempt to register controller to an unknown node " + node); throw new Error("An attempt to register controller to an unknown node " + nodeName);
} }
if (node.foreigns[controller.id] !== undefined) { if (node.foreigns[controller.id] !== undefined) {
throw new Error("An attempt to register a controller under node " + node + " for a second time"); throw new Error("An attempt to register a controller under node " + nodeName + " for a second time");
} }
var obj = Object.create(null); var obj = Object.create(null);
obj.controller = controller; obj.controller = controller;
@ -271,43 +284,46 @@
"_responsePlayer": function(ev) { "_responsePlayer": function(ev) {
var data = ev.getData(); var data = ev.getData();
console.log('Received player address: ' + data.at("address").toString()); this._playerCtl = new PlayerModel(data.at("address").clone());
this._playerCtl.register(this.dispatcher, this._nodes["Corax"].socket);
this._playerCtl.subscribe();
this._mainLayout.appendPlayer(this._playerCtl);
}, },
"setTheme": function(theme) { "setTheme": function(theme) {
View.setTheme(theme); View.setTheme(theme);
}, },
"subscribeForeignController": function(node, controller) { "subscribeForeignController": function(nodeName, controller) {
var node = this._nodes[node]; var node = this._nodes[nodeName];
if (node === undefined) { if (node === undefined) {
throw new Error("An attempt to subscribe a controller to an unknown node " + node); throw new Error("An attempt to subscribe a controller to an unknown node " + nodeName);
} }
if (node.foreigns[controller.id] === undefined) { if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to subscribe not registered controller to node " + node); throw new Error("An attempt to subscribe not registered controller to node " + nodeName);
} }
node.foreigns[controller.id].subscribed = true; node.foreigns[controller.id].subscribed = true;
controller.subscribe(); controller.subscribe();
}, },
"unregisterForeignController": function(node, controller) { "unregisterForeignController": function(nodeName, controller) {
var node = this._nodes[node]; var node = this._nodes[nodeName];
if (node === undefined) { if (node === undefined) {
throw new Error("An attempt to unregister a controller from an unknown node " + node); throw new Error("An attempt to unregister a controller from an unknown node " + nodeName);
} }
if (node.foreigns[controller.id] === undefined) { if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unregister not registered controller from node " + node); throw new Error("An attempt to unregister not registered controller from node " + nodeName);
} }
delete node.foreigns[controller.id]; delete node.foreigns[controller.id];
controller.unregister(); controller.unregister();
}, },
"unsubscribeForeignController": function(node, controller) { "unsubscribeForeignController": function(nodeName, controller) {
var node = this._nodes[node]; var node = this._nodes[nodeName];
if (node === undefined) { if (node === undefined) {
throw new Error("An attempt to unsubscribe a controller from an unknown node " + node); throw new Error("An attempt to unsubscribe a controller from an unknown node " + nodeName);
} }
if (node.foreigns[controller.id] === undefined) { if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unsubscribe not registered controller from node " + node); throw new Error("An attempt to unsubscribe not registered controller from node " + nodeName);
} }
node.foreigns[controller.id].subscribed = false; node.foreigns[controller.id].subscribed = false;
controller.unsubscribe(); controller.unsubscribe();

View File

@ -18,3 +18,4 @@ add_jslib(wController/imagePane.js lib/wController/imagePane ${LORGAR_DIR} brows
add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} browser) add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} browser)
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)

View File

@ -13,5 +13,6 @@ configure_file(pane.js pane.js)
configure_file(image.js image.js) configure_file(image.js image.js)
configure_file(button.js button.js) configure_file(button.js button.js)
configure_file(enumeration.js enumeration.js) configure_file(enumeration.js enumeration.js)
configure_file(player.js player.js)
add_subdirectory(helpers) add_subdirectory(helpers)

View File

@ -9,6 +9,7 @@
defineArray.push("views/navigationPanel"); defineArray.push("views/navigationPanel");
defineArray.push("views/layout"); defineArray.push("views/layout");
defineArray.push("views/enumeration"); defineArray.push("views/enumeration");
defineArray.push("views/player");
defineArray.push("lib/wController/localModel"); defineArray.push("lib/wController/localModel");
define(moduleName, defineArray, function mainLayout_module() { define(moduleName, defineArray, function mainLayout_module() {
@ -18,6 +19,7 @@
var ViewNavigationPanel = require("views/navigationPanel"); var ViewNavigationPanel = require("views/navigationPanel");
var Layout = require("views/layout"); var Layout = require("views/layout");
var Enumeration = require("views/enumeration"); var Enumeration = require("views/enumeration");
var Player = require("views/player");
var LocalModel = require("lib/wController/localModel"); var LocalModel = require("lib/wController/localModel");
var MainLayout = GridLayout.inherit({ var MainLayout = GridLayout.inherit({
@ -26,6 +28,7 @@
GridLayout.fn.constructor.call(this, controller, options); GridLayout.fn.constructor.call(this, controller, options);
this._statusBarPosition = 2; this._statusBarPosition = 2;
this._player = undefined;
this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"}); this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"});
this._statusBarModel = new LocalModel({backgroundColor: "secondaryColor"}); this._statusBarModel = new LocalModel({backgroundColor: "secondaryColor"});
@ -72,6 +75,21 @@
this._statusBar.append(e, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter); this._statusBar.append(e, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter);
this._uncyclic.push(lm.destructor.bind(lm)); this._uncyclic.push(lm.destructor.bind(lm));
},
appendPlayer: function(playerModel) {
if (this._player !== undefined) {
throw new Error("An attempt to add player to main layout for the second time");
}
this._player = new Player(playerModel);
this.append(this._player, 2, 0, 1, 3);
},
removePlayer: function() {
if (this._player === undefined) {
throw new Error("An attempt to remove non existing player from mainLayout");
}
this.removeChild(this._player);
this._player.destructor();
this._player = undefined;
} }
}); });

99
lorgar/views/player.js Normal file
View File

@ -0,0 +1,99 @@
"use strict";
(function() {
var moduleName = "views/player"
var deps = [];
deps.push("views/gridLayout");
deps.push("views/button");
deps.push("views/label");
deps.push("lib/wController/localModel");
deps.push("lib/utils/enum");
define(moduleName, deps, function() {
var GridLayout = require("views/gridLayout");
var Button = require("views/button");
var Label = require("views/label");
var Model = require("lib/wController/localModel");
var Enum = require("lib/utils/enum");
var Player = GridLayout.inherit({
className: "Player",
constructor: function(ctrl, options) {
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._cpbCtrl = null;
this._infoModels = {
artist: new Model(null, "artist: unknown"),
album: new Model(null, "album: unknown"),
song: new Model(null, "song: unknown")
}
ctrl.on("newElement", this._onNewElement, this);
var artist = new Label(this._infoModels.artist);
var album = new Label(this._infoModels.album);
var song = new Label(this._infoModels.song);
this.append(artist, 0, 2, 1, 1)
this.append(song, 1, 2, 1, 1)
this.append(album, 2, 2, 1, 1)
this._uncyclic.push(this._infoModels.artist.destructor.bind(this._infoModels.artist));
this._uncyclic.push(this._infoModels.song.destructor.bind(this._infoModels.song));
this._uncyclic.push(this._infoModels.album.destructor.bind(this._infoModels.album));
},
destructor: function() {
this._f.off("newElement", this._onNewElement, this);
this._clearCpbCtrl();
GridLayout.fn.destructor.call(this);
},
_clearCpbCtrl: function() {
if (this._cpbCtrl !== null) {
this._cpbCtrl.off("newElement", this._onCpbNewElement, this);
this._cpbCtrl.off("removeElement", this._onCpbRemoveElement, this);
this._cpbCtrl = null;
}
},
_onNewElement: function(ctrl, type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause = new Button(ctrl);
this.append(this._playPause, 0, 1, 3, 1);
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
this._cpbCtrl = ctrl;
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
}
},
_onCpbNewElement: function(key, value) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": " + value.toString());
}
},
_onCpbRemoveElement: function(key) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": unknown");
}
}
});
return Player;
});
})()

View File

@ -54,7 +54,9 @@
for (var i = 0; i < this._f._controllers.length; ++i) { for (var i = 0; i < this._f._controllers.length; ++i) {
this._onNewController(this._f._controllers[i]); this._onNewController(this._f._controllers[i]);
} }
//if (this._f.initialized) {
this._onData(this._f); this._onData(this._f);
//}
View.collection[this._id] = this; View.collection[this._id] = this;
this._applyProperties(); this._applyProperties();