diff --git a/feedbacks.js b/feedbacks.js index 531f879e9f8baf1c040d516516b5b88cced9aedd..f713107c64cedb5338ccd38e274063de26579b11 100644 --- a/feedbacks.js +++ b/feedbacks.js @@ -12,11 +12,25 @@ module.exports = async function (self) { type: 'textinput', label: 'Pad Name', default: '', + required: false + }, + { + id: 'index', + type: 'number', + label: 'Pad ID', + default: '', + required: false }, ], callback: (feedback, context) => { - self.log('debug', `Update feedback for pad name ${feedback.options.name}`); - const pad = self.currentProject.findPadByName(feedback.options.name); + let pad; + if (feedback.options.name) { + self.log('debug', `Update feedback for pad name ${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) { self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`); if (pad.status === 'PLAY') { diff --git a/main.js b/main.js index 7763ee355ff6d2346503e345a39b94bc30e949d4..e3233ca1cc78aa6b3d7246ffa424b615af1f7863 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,7 @@ const ProjectUpdate = require("./receive/project_update"); const Project = require("./project"); const PadNameUpdate = require("./receive/pad_name_update"); const PadStatusUpdate = require("./receive/pad_status_update"); +const CurrentPageUpdate = require("./receive/current_page_update"); const uuid = require('uuid'); class ModuleInstance extends InstanceBase { @@ -17,7 +18,8 @@ class ModuleInstance extends InstanceBase { messageHandlers = { 'project-current': new ProjectUpdate(), 'pad-name-changed': new PadNameUpdate(), - 'pad-status-changed': new PadStatusUpdate() + 'pad-status-changed': new PadStatusUpdate(), + 'current-page-changed': new CurrentPageUpdate() }; currentProject = new Project({}); diff --git a/project.js b/project.js index 57530b344368a9ccde4bacf3fd1a46e022a484e0..603ba84d737b7488c5ce5c039fad7eb122d76d33 100644 --- a/project.js +++ b/project.js @@ -1,9 +1,11 @@ module.exports = class Project { constructor(data) { this.padCache = {} + this.currentPage = 0; // Prefill with current project if (data) { + this.data = data; console.log('Create pad cache') for (const pageId in data.pages) { const page = data.pages[pageId] @@ -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 @@ -49,6 +75,25 @@ module.exports = class Project { 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 diff --git a/receive/current_page_update.js b/receive/current_page_update.js new file mode 100644 index 0000000000000000000000000000000000000000..a03d93654e2cc6ffd2fe049444a3e3a7b23bff80 --- /dev/null +++ b/receive/current_page_update.js @@ -0,0 +1,9 @@ +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