feat: ledlab
This commit is contained in:
86
presets/base-preset.js
Normal file
86
presets/base-preset.js
Normal file
@@ -0,0 +1,86 @@
|
||||
// Base preset class for LEDLab
|
||||
|
||||
const { createFrame, frameToPayload } = require('./frame-utils');
|
||||
|
||||
class BasePreset {
|
||||
constructor(width = 16, height = 16) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.frameCount = 0;
|
||||
this.isActive = false;
|
||||
this.parameters = {};
|
||||
this.defaultParameters = {};
|
||||
}
|
||||
|
||||
// Initialize the preset with default parameters
|
||||
init() {
|
||||
this.frameCount = 0;
|
||||
this.resetToDefaults();
|
||||
}
|
||||
|
||||
// Reset parameters to their default values
|
||||
resetToDefaults() {
|
||||
this.parameters = { ...this.defaultParameters };
|
||||
}
|
||||
|
||||
// Set a parameter value
|
||||
setParameter(name, value) {
|
||||
this.parameters[name] = value;
|
||||
}
|
||||
|
||||
// Get a parameter value
|
||||
getParameter(name) {
|
||||
return this.parameters[name];
|
||||
}
|
||||
|
||||
// Get all parameters
|
||||
getParameters() {
|
||||
return { ...this.parameters };
|
||||
}
|
||||
|
||||
// Start the preset
|
||||
start() {
|
||||
this.isActive = true;
|
||||
this.init();
|
||||
}
|
||||
|
||||
// Stop the preset
|
||||
stop() {
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
// Generate the next frame
|
||||
generateFrame() {
|
||||
if (!this.isActive) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const frame = this.renderFrame();
|
||||
this.frameCount++;
|
||||
|
||||
if (frame) {
|
||||
return frameToPayload(frame);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Override in subclasses to render a frame
|
||||
renderFrame() {
|
||||
// Default implementation returns a blank frame
|
||||
return createFrame(this.width, this.height, '000000');
|
||||
}
|
||||
|
||||
// Get preset metadata
|
||||
getMetadata() {
|
||||
return {
|
||||
name: this.constructor.name,
|
||||
description: 'Base preset class',
|
||||
parameters: this.defaultParameters,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BasePreset;
|
||||
Reference in New Issue
Block a user