UNPKG

reaper-osc

Version:
137 lines 4.74 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TrackFx = exports.Fx = void 0; /** * Contains classes for controlling FX in Reaper * @module */ const Notify_1 = require("./Notify"); const Handlers_1 = require("./Handlers"); const Messages_1 = require("./Messages"); /** * A Reaper FX. * * @example * ```typescript * // Open an FX UI window * fx.openUi(); * // Bypass the FX * fx.bypass(); * ``` */ let Fx = class Fx { /** * @param name The FX name * @param oscAddress The OSC address of the FX * @param sendOscMessage A callback used to send OSC messages to Reaper */ constructor(name, oscAddress, sendOscMessage) { this.oscAddress = oscAddress; this._isBypassed = false; this._isUiOpen = false; this._preset = 'No preset'; this._handlers = [ new Handlers_1.StringMessageHandler(this.oscAddress + '/name', value => (this._name = value)), new Handlers_1.BooleanMessageHandler(this.oscAddress + '/bypass', value => (this._isBypassed = !value)), new Handlers_1.BooleanMessageHandler(this.oscAddress + '/openui', value => (this._isUiOpen = value)), new Handlers_1.StringMessageHandler(this.oscAddress + '/preset', value => (this._preset = value)), ]; this._sendOscMessage = sendOscMessage; this._name = name; } /** Bypass the FX */ bypass() { this._sendOscMessage(new Messages_1.BooleanMessage(this.oscAddress + '/bypass', false)); // false to bypass } /** Close the UI of the FX */ closeUi() { this._sendOscMessage(new Messages_1.BooleanMessage(this.oscAddress + '/openui', false)); } /** Indicates whether the FX is bypassed */ get isBypassed() { return this._isBypassed; } /** Indicates whether the FX's UI is open */ get isUiOpen() { return this._isUiOpen; } /** The name of the FX */ get name() { return this._name; } /** Load the next FX preset */ nextPreset() { this._sendOscMessage(new Messages_1.OscMessage(this.oscAddress + '/preset+')); } // eslint-disable-next-line @typescript-eslint/no-unused-vars onPropertyChanged(property, callback) { throw new Error('not implemented'); } /** Open the UI of the FX */ openUi() { this._sendOscMessage(new Messages_1.BooleanMessage(this.oscAddress + '/openui', true)); } /** The name of the current preset, if any */ get preset() { return this._preset; } /** Load the previous FX preset */ previousPreset() { this._sendOscMessage(new Messages_1.OscMessage(this.oscAddress + '/preset-')); } /** * Receive and handle an OSC message * @param message The message to be handled */ receive(message) { for (const handler of this._handlers) { if (handler.handle(message)) { return true; } } return false; } /** Unbypass the FX */ unbypass() { this._sendOscMessage(new Messages_1.BooleanMessage(this.oscAddress + '/bypass', true)); // true to unbypass } }; __decorate([ Notify_1.notify('isBypassed') ], Fx.prototype, "_isBypassed", void 0); __decorate([ Notify_1.notify('isUiOpen') ], Fx.prototype, "_isUiOpen", void 0); __decorate([ Notify_1.notify('name') ], Fx.prototype, "_name", void 0); __decorate([ Notify_1.notify('preset') ], Fx.prototype, "_preset", void 0); Fx = __decorate([ Notify_1.notifyOnPropertyChanged ], Fx); exports.Fx = Fx; /** * An FX on a {@link Track} */ class TrackFx extends Fx { /** * @param trackNumber The number of the track the FX is on * @param fxNumber The FX number in the current bank * @param sendOscMessage A callback used to send OSC messages to Reaper */ constructor(trackNumber, fxNumber, sendOscMessage) { super(`Fx ${fxNumber}`, `/track/${trackNumber}/fx/${fxNumber}`, sendOscMessage); this.trackNumber = trackNumber; this.fxNumber = fxNumber; } } exports.TrackFx = TrackFx; //# sourceMappingURL=Fx.js.map