reaper-osc
Version:
Controls Cockos Reaper using OSC
383 lines • 13.3 kB
JavaScript
"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.SelectedTrack = void 0;
/**
* Contains classes for the OSC device's currently selected track
* @module
*/
const Fx_1 = require("./Fx");
const Send_1 = require("./Send");
const Receive_1 = require("./Receive");
const Notify_1 = require("./Notify");
const Events_1 = require("./Client/Events");
const Commands_1 = require("./Client/Commands");
/**
* The OSC device's currently selected track.
*
* Receives state via the `/track/` (no index) address space, which Reaper populates
* with a full sync burst whenever the device's focused track changes.
*
* @see {@link DeviceState.selectTrack} to change which track is selected
*/
let SelectedTrack = class SelectedTrack {
/**
* @param numberOfFx The number of FX slots in the device FX bank
* @param numberOfSends The number of sends in the device send bank
* @param numberOfReceives The number of receives in the device receive bank
* @param send A callback used to send typed commands to Reaper
*/
constructor(numberOfFx, numberOfSends, numberOfReceives, send) {
this._isMuted = false;
this._isRecordArmed = false;
this._isSelected = false;
this._isSoloed = false;
this._name = '';
this._pan = 0;
this._pan2 = 0;
this._panMode = '';
this._recordMonitoring = Events_1.RecordMonitoringMode.OFF;
this._volumeDb = 0;
this._volumeFaderPosition = 0;
this._vu = 0;
this._vuLeft = 0;
this._vuRight = 0;
this._fx = [];
this._sends = [];
this._receives = [];
this._send = send;
for (let i = 0; i < numberOfFx; i++) {
this._fx[i] = new Fx_1.SelectedTrackFxSlot(i + 1, send);
}
this._selectedFx = new Fx_1.DeviceSelectedFx(send);
for (let i = 0; i < numberOfSends; i++) {
this._sends[i] = new Send_1.SelectedTrackSend(i + 1, send);
}
for (let i = 0; i < numberOfReceives; i++) {
this._receives[i] = new Receive_1.SelectedTrackReceive(i + 1, send);
}
}
/** Deselect this track in Reaper */
deselect() {
this._send(Commands_1.SetSelectedTrackSelect(false));
}
/** The FX bank for this track */
get fx() {
return this._fx;
}
/** The sends for this track */
get sends() {
return this._sends;
}
/** The receives for this track */
get receives() {
return this._receives;
}
/**
* Handle a typed incoming event
* @param event The event to handle
*/
handleEvent(event) {
switch (event.type) {
case 'selectedTrack:name':
this._name = event.name;
break;
case 'selectedTrack:mute':
this._isMuted = event.muted;
break;
case 'selectedTrack:solo':
this._isSoloed = event.soloed;
break;
case 'selectedTrack:recordArm':
this._isRecordArmed = event.armed;
break;
case 'selectedTrack:monitoringMode':
this._recordMonitoring = event.mode;
break;
case 'selectedTrack:select':
this._isSelected = event.selected;
break;
case 'selectedTrack:pan':
this._pan = event.pan;
break;
case 'selectedTrack:pan2':
this._pan2 = event.pan2;
break;
case 'selectedTrack:panMode':
this._panMode = event.panMode;
break;
case 'selectedTrack:volume':
this._volumeFaderPosition = event.volume;
break;
case 'selectedTrack:volumeDb':
this._volumeDb = event.volumeDb;
break;
case 'selectedTrack:vu':
this._vu = event.vu;
break;
case 'selectedTrack:vuLeft':
this._vuLeft = event.vuLeft;
break;
case 'selectedTrack:vuRight':
this._vuRight = event.vuRight;
break;
case 'selectedTrack:fx:name':
case 'selectedTrack:fx:bypass':
case 'selectedTrack:fx:openUi':
case 'selectedTrack:fx:preset': {
const slot = this._fx[event.fxNumber - 1];
if (slot)
slot.handleEvent(event);
break;
}
case 'selectedFx:name':
case 'selectedFx:bypass':
case 'selectedFx:openUi':
case 'selectedFx:preset':
this._selectedFx.handleEvent(event);
break;
case 'selectedTrack:send:name':
case 'selectedTrack:send:volume':
case 'selectedTrack:send:volumeStr':
case 'selectedTrack:send:pan':
case 'selectedTrack:send:panStr': {
const send = this._sends[event.sendNumber - 1];
if (send)
send.handleEvent(event);
break;
}
case 'selectedTrack:recv:name':
case 'selectedTrack:recv:volume':
case 'selectedTrack:recv:volumeStr':
case 'selectedTrack:recv:pan':
case 'selectedTrack:recv:panStr': {
const receive = this._receives[event.receiveNumber - 1];
if (receive)
receive.handleEvent(event);
break;
}
}
}
/** Indicates whether the track is muted */
get isMuted() {
return this._isMuted;
}
/** Indicates whether the track is armed for recording */
get isRecordArmed() {
return this._isRecordArmed;
}
/**
* Indicates whether this track is selected in the Reaper project.
* @see {@link DeviceState.selectTrack} to change the device's focused track
*/
get isSelected() {
return this._isSelected;
}
/** Indicates whether the track is soloed */
get isSoloed() {
return this._isSoloed;
}
/** Mute the track */
mute() {
this._send(Commands_1.SetSelectedTrackMute(true));
}
/** The track name */
get name() {
return this._name;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onPropertyChanged(property, callback) {
throw new Error('not implemented');
}
/** A floating-point value between -1 and 1 that indicates the pan position, with -1 being 100% left and 1 being 100% right */
get pan() {
return this._pan;
}
/** A floating-point value between -1 and 1 that indicates the pan 2 position, with -1 being 100% left and 1 being 100% right */
get pan2() {
return this._pan2;
}
/** The current pan mode */
get panMode() {
return this._panMode;
}
/** Arm the track for recording */
recordArm() {
this._send(Commands_1.SetSelectedTrackRecordArm(true));
}
/** Indicates the record monitoring mode */
get recordMonitoring() {
return this._recordMonitoring;
}
/** Disarm track recording */
recordDisarm() {
this._send(Commands_1.SetSelectedTrackRecordArm(false));
}
/**
* Renames the track
* @param name The new name for the track
*/
rename(name) {
this._send(Commands_1.SetSelectedTrackName(name));
this._name = name;
}
/**
* Select this track in Reaper.
* Note: this selects the track in the Reaper project. To change which track the
* device is focused on, use {@link DeviceState.selectTrack} instead.
*/
select() {
this._send(Commands_1.SetSelectedTrackSelect(true));
}
/** The device's currently focused FX on this track */
get selectedFx() {
return this._selectedFx;
}
/**
* Set the record monitoring mode
* @param value The monitoring mode to set
*/
setMonitoringMode(value) {
this._send(Commands_1.SetSelectedTrackMonitoringMode(value));
}
/**
* Sets the pan
* @param value A floating-point value between -1 and 1, where -1 is 100% left and 1 is 100% right
*/
setPan(value) {
if (value < -1 || value > 1) {
throw new RangeError('Must be between -1 and 1');
}
this._send(Commands_1.SetSelectedTrackPan(value));
this._pan = value;
}
/**
* Sets the pan 2
* @param value A floating-point value between -1 and 1, where -1 is 100% left and 1 is 100% right
*/
setPan2(value) {
if (value < -1 || value > 1) {
throw new RangeError('Must be between -1 and 1');
}
this._send(Commands_1.SetSelectedTrackPan2(value));
this._pan2 = value;
}
/**
* Sets the volume to a specific dB value.
* @param value Value (in dB) to set the volume to. Valid range is -100 to 12.
*/
setVolumeDb(value) {
if (value < -100 || value > 12) {
throw new RangeError('Must be between -100 and 12');
}
this._send(Commands_1.SetSelectedTrackVolumeDb(value));
this._volumeDb = value;
}
/**
* Sets the volume by moving the fader to a specific position
* @param position A value for the fader position between 0 and 1, where 0 is all the way down and 1 is all the way up
*/
setVolumeFaderPosition(position) {
if (position < 0 || position > 1) {
throw new RangeError('Must be between 0 and 1');
}
this._send(Commands_1.SetSelectedTrackVolume(position));
this._volumeFaderPosition = position;
}
/** Solo the track */
solo() {
this._send(Commands_1.SetSelectedTrackSolo(true));
}
/** Toggle mute on/off */
toggleMute() {
this._send(Commands_1.ToggleSelectedTrackMute());
}
/** Toggle record arm on/off */
toggleRecordArm() {
this._send(Commands_1.ToggleSelectedTrackRecordArm());
}
/** Toggle solo on/off */
toggleSolo() {
this._send(Commands_1.ToggleSelectedTrackSolo());
}
/** Unmute the track */
unmute() {
this._send(Commands_1.SetSelectedTrackMute(false));
}
/** Unsolo the track */
unsolo() {
this._send(Commands_1.SetSelectedTrackSolo(false));
}
/** The track volume in dB */
get volumeDb() {
return this._volumeDb;
}
/** A floating-point value between 0 and 1 that indicates the fader position, with 0 being all the way down and 1 being all the way up */
get volumeFaderPosition() {
return this._volumeFaderPosition;
}
/** A floating-point value between 0 and 1 that indicates the VU level */
get vu() {
return this._vu;
}
/** A floating-point value between 0 and 1 that indicates the Left VU level */
get vuLeft() {
return this._vuLeft;
}
/** A floating-point value between 0 and 1 that indicates the Right VU level */
get vuRight() {
return this._vuRight;
}
};
__decorate([
Notify_1.notify('isMuted')
], SelectedTrack.prototype, "_isMuted", void 0);
__decorate([
Notify_1.notify('isRecordArmed')
], SelectedTrack.prototype, "_isRecordArmed", void 0);
__decorate([
Notify_1.notify('isSelected')
], SelectedTrack.prototype, "_isSelected", void 0);
__decorate([
Notify_1.notify('isSoloed')
], SelectedTrack.prototype, "_isSoloed", void 0);
__decorate([
Notify_1.notify('name')
], SelectedTrack.prototype, "_name", void 0);
__decorate([
Notify_1.notify('pan')
], SelectedTrack.prototype, "_pan", void 0);
__decorate([
Notify_1.notify('pan2')
], SelectedTrack.prototype, "_pan2", void 0);
__decorate([
Notify_1.notify('panMode')
], SelectedTrack.prototype, "_panMode", void 0);
__decorate([
Notify_1.notify('recordMonitoring')
], SelectedTrack.prototype, "_recordMonitoring", void 0);
__decorate([
Notify_1.notify('volumeDb')
], SelectedTrack.prototype, "_volumeDb", void 0);
__decorate([
Notify_1.notify('volumeFaderPosition')
], SelectedTrack.prototype, "_volumeFaderPosition", void 0);
__decorate([
Notify_1.notify('vu')
], SelectedTrack.prototype, "_vu", void 0);
__decorate([
Notify_1.notify('vuLeft')
], SelectedTrack.prototype, "_vuLeft", void 0);
__decorate([
Notify_1.notify('vuRight')
], SelectedTrack.prototype, "_vuRight", void 0);
SelectedTrack = __decorate([
Notify_1.notifyOnPropertyChanged
], SelectedTrack);
exports.SelectedTrack = SelectedTrack;
//# sourceMappingURL=SelectedTrack.js.map