Skip to content
Snippets Groups Projects
Commit ff85e873 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#187 - Update feedback on page change, add option for pad index based feedback

parent aa8a5ab9
No related branches found
No related tags found
No related merge requests found
...@@ -12,11 +12,25 @@ module.exports = async function (self) { ...@@ -12,11 +12,25 @@ module.exports = async function (self) {
type: 'textinput', type: 'textinput',
label: 'Pad Name', label: 'Pad Name',
default: '', default: '',
required: false
},
{
id: 'index',
type: 'number',
label: 'Pad ID',
default: '',
required: false
}, },
], ],
callback: (feedback, context) => { callback: (feedback, context) => {
let pad;
if (feedback.options.name) {
self.log('debug', `Update feedback for pad name ${feedback.options.name}`); self.log('debug', `Update feedback for pad name ${feedback.options.name}`);
const pad = self.currentProject.findPadByName(feedback.options.name); pad = self.currentProject.findPadByName(feedback.options.name);
} else {
self.log('debug', `Update feedback for pad index ${feedback.options.index}`);
pad = self.currentProject.findPadByIndexInCurrentPage(feedback.options.index - 1);
}
if (pad != null) { if (pad != null) {
self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`); self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`);
if (pad.status === 'PLAY') { if (pad.status === 'PLAY') {
......
...@@ -7,6 +7,7 @@ const ProjectUpdate = require("./receive/project_update"); ...@@ -7,6 +7,7 @@ const ProjectUpdate = require("./receive/project_update");
const Project = require("./project"); const Project = require("./project");
const PadNameUpdate = require("./receive/pad_name_update"); const PadNameUpdate = require("./receive/pad_name_update");
const PadStatusUpdate = require("./receive/pad_status_update"); const PadStatusUpdate = require("./receive/pad_status_update");
const CurrentPageUpdate = require("./receive/current_page_update");
const uuid = require('uuid'); const uuid = require('uuid');
class ModuleInstance extends InstanceBase { class ModuleInstance extends InstanceBase {
...@@ -17,7 +18,8 @@ class ModuleInstance extends InstanceBase { ...@@ -17,7 +18,8 @@ class ModuleInstance extends InstanceBase {
messageHandlers = { messageHandlers = {
'project-current': new ProjectUpdate(), 'project-current': new ProjectUpdate(),
'pad-name-changed': new PadNameUpdate(), 'pad-name-changed': new PadNameUpdate(),
'pad-status-changed': new PadStatusUpdate() 'pad-status-changed': new PadStatusUpdate(),
'current-page-changed': new CurrentPageUpdate()
}; };
currentProject = new Project({}); currentProject = new Project({});
......
module.exports = class Project { module.exports = class Project {
constructor(data) { constructor(data) {
this.padCache = {} this.padCache = {}
this.currentPage = 0;
// Prefill with current project // Prefill with current project
if (data) { if (data) {
this.data = data;
console.log('Create pad cache') console.log('Create pad cache')
for (const pageId in data.pages) { for (const pageId in data.pages) {
const page = data.pages[pageId] const page = data.pages[pageId]
...@@ -18,6 +20,30 @@ module.exports = class Project { ...@@ -18,6 +20,30 @@ module.exports = class Project {
} }
} }
/*
Page
*/
/**
*
* @returns {number}
*/
getCurrentPage() {
return this.currentPage;
}
/**
*
* @param {number} newPage
*/
updateCurrentPage(newPage) {
this.currentPage = newPage;
}
/*
Pads
*/
/** /**
* *
* @param {string} oldName * @param {string} oldName
...@@ -49,6 +75,25 @@ module.exports = class Project { ...@@ -49,6 +75,25 @@ module.exports = class Project {
return this.padCache[name]; return this.padCache[name];
} }
/**
*
* @param {number} index
*/
findPadByIndexInCurrentPage(index) {
for (const pageId in this.data.pages) {
const page = this.data.pages[pageId]
if (page.position === this.currentPage) {
for (const padId in page.pads) {
const pad = page.pads[padId];
if (pad.position === index) {
return pad;
}
}
}
}
return null;
}
/** /**
* *
* @param {string} padId * @param {string} padId
......
const MessageExecutable = require("./message_executable");
module.exports = class CurrentPageUpdate extends MessageExecutable {
handleMessage(plugin, message) {
plugin.currentProject.updateCurrentPage(message.newPage);
plugin.checkFeedbacks();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment