Skip to content

Commit

Permalink
chore: Export individual encoder page configs for easier composition …
Browse files Browse the repository at this point in the history
…in device config files
  • Loading branch information
bjoluc committed Apr 24, 2024
1 parent 3f4cc63 commit d103456
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 261 deletions.
31 changes: 9 additions & 22 deletions src/device-configs/behringer_xtouch-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { DeviceConfig } from ".";
import { JogWheel } from "/decorators/surface-elements/JogWheel";
import { Lamp } from "/decorators/surface-elements/Lamp";
import { LedButton } from "/decorators/surface-elements/LedButton";
import { EncoderDisplayMode, LedPushEncoder } from "/decorators/surface-elements/LedPushEncoder";
import { LedPushEncoder } from "/decorators/surface-elements/LedPushEncoder";
import { TouchSensitiveMotorFader } from "/decorators/surface-elements/TouchSensitiveFader";
import * as encoderPageConfigs from "/mapping/encoders/page-configs";
import { createElements } from "/util";

export const deviceConfig: DeviceConfig = {
Expand Down Expand Up @@ -163,38 +164,24 @@ export const deviceConfig: DeviceConfig = {
};
},

configureEncoderAssignments(defaultEncoderMapping, page) {
configureEncoderMapping() {
return [
// Pan, Monitor, Gain, LC, HC (F1)
{
activatorButtonSelector: (device) => device.controlSectionElements.buttons.function[0],
pages: [
...[...defaultEncoderMapping[0].pages, ...defaultEncoderMapping[1].pages].filter((page) =>
["Pan", "Monitor", "Input Gain", "Low Cut", "High Cut"].includes(page.name),
),
encoderPageConfigs.pan,
encoderPageConfigs.monitor,
encoderPageConfigs.inputGain,
encoderPageConfigs.lowCut,
encoderPageConfigs.highCut,
],
},

// Sends 1-3 (F2)
{
activatorButtonSelector: (device) => device.controlSectionElements.buttons.function[1],
pages: createElements(3, (slotId) => {
return {
name: `Send Slot`,
assignments: (channel) => {
const sendSlot = channel.mSends.getByIndex(slotId);

return {
encoderValue: sendSlot.mLevel,
encoderValueName: `Send ${slotId + 1}`,
displayMode: EncoderDisplayMode.SingleDot,
encoderValueDefault: 0.7890865802764893,
pushToggleValue: sendSlot.mOn,
};
},
areAssignmentsChannelRelated: true,
};
}),
pages: createElements(3, (slotId) => encoderPageConfigs.sendSlot(slotId)),
},
];
},
Expand Down
2 changes: 1 addition & 1 deletion src/device-configs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export interface DeviceConfig {
*
* The default config is defined in {@link file://./../mapping/encoders/index.ts}
*/
configureEncoderAssignments?(
configureEncoderMapping?(
defaultEncoderMappings: EncoderMappingConfig[],
page: MR_FactoryMappingPage,
): EncoderMappingConfig[];
Expand Down
18 changes: 4 additions & 14 deletions src/device-configs/ssl_uf1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import { DeviceConfig } from ".";
import { JogWheel } from "/decorators/surface-elements/JogWheel";
import { LedButton } from "/decorators/surface-elements/LedButton";
import { EncoderDisplayMode, LedPushEncoder } from "/decorators/surface-elements/LedPushEncoder";
import { LedPushEncoder } from "/decorators/surface-elements/LedPushEncoder";
import { TouchSensitiveMotorFader } from "/decorators/surface-elements/TouchSensitiveFader";
import { focusedQuickControls as makeFocusedQuickControlsEncoderPageConfig } from "/mapping/encoders/page-configs";
import { createElements } from "/util";

export const deviceConfig: DeviceConfig = {
Expand Down Expand Up @@ -217,22 +218,11 @@ export const deviceConfig: DeviceConfig = {
};
},

configureEncoderAssignments(defaultEncoderMapping, page) {
const focusedQuickControls = page.mHostAccess.mFocusedQuickControls;

configureEncoderMapping(defaultEncoderMapping, page) {
const instrumentEncoderMapping = defaultEncoderMapping.pop()!;

// Replace the instrument encoder assignment with quick controls
instrumentEncoderMapping.pages[0] = {
name: "Quick Controls",
assignments: (_mixerChannel, channelIndex) => {
return {
encoderValue: focusedQuickControls.getByIndex(channelIndex),
displayMode: EncoderDisplayMode.SingleDot,
};
},
areAssignmentsChannelRelated: false,
};
instrumentEncoderMapping.pages[0] = makeFocusedQuickControlsEncoderPageConfig(page.mHostAccess);

// Make it the default encoder mapping by defining it first
return [instrumentEncoderMapping, ...defaultEncoderMapping];
Expand Down
240 changes: 16 additions & 224 deletions src/mapping/encoders/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { mDefaults } from "midiremote_api_v1";
import { EncoderMapper, EncoderMappingConfig } from "./EncoderMapper";
import { EncoderAssignmentConfig } from "./EncoderPage";
import { config, deviceConfig } from "/config";
import { EncoderDisplayMode } from "/decorators/surface-elements/LedPushEncoder";
import * as pageConfigs from "./page-configs";
import { deviceConfig } from "/config";
import { Device, MainDevice } from "/devices";
import { SegmentDisplayManager } from "/midi/managers/SegmentDisplayManager";
import { GlobalState } from "/state";
import { createElements } from "/util";

export function bindEncoders(
page: MR_FactoryMappingPage,
Expand All @@ -26,257 +23,52 @@ export function bindEncoders(
const selectAssignButtons = (device: MainDevice) =>
device.controlSectionElements.buttons.encoderAssign;

const mMixerChannel = page.mHostAccess.mTrackSelection.mMixerChannel;
const mChannelEQ = mMixerChannel.mChannelEQ;
const mSends = mMixerChannel.mSends;
const sendSlotsCount = mDefaults.getNumberOfSendSlots();
const insertEffectsViewer = mMixerChannel.mInsertAndStripEffects
.makeInsertEffectViewer("Inserts")
.followPluginWindowInFocus();
const mStripEffects = mMixerChannel.mInsertAndStripEffects.mStripEffects;
const hostAccess = page.mHostAccess;

let encoderMappingConfigs: EncoderMappingConfig[] = [
// Pan (Defining Pan first so it is activated by default)
{
activatorButtonSelector: (device) => selectAssignButtons(device).pan,
pages: [
{
name: "Pan",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.BoostOrCut,
encoderValue: mixerBankChannel.mValue.mPan,
encoderValueDefault: 0.5,
pushToggleValue: mixerBankChannel.mValue.mMonitorEnable,
onPush: config.resetPanOnEncoderPush
? (context, encoder) => {
encoder.mEncoderValue.setProcessValue(context, 0.5);
}
: undefined,
}),
areAssignmentsChannelRelated: true,
},
],
pages: [pageConfigs.pan],
},

// Track
{
activatorButtonSelector: (device) => selectAssignButtons(device).track,
pages: [
{
name: "Monitor",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.Wrap,
encoderValue: mixerBankChannel.mValue.mMonitorEnable,
encoderValueDefault: 0,
pushToggleValue: mixerBankChannel.mValue.mMonitorEnable,
}),
areAssignmentsChannelRelated: true,
},
{
name: "Input Gain",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.BoostOrCut,
encoderValue: mixerBankChannel.mPreFilter.mGain,
encoderValueDefault: 0.5,
}),
areAssignmentsChannelRelated: true,
},
{
name: "Input Phase",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.Wrap,
encoderValue: mixerBankChannel.mPreFilter.mPhaseSwitch,
encoderValueDefault: 0,
}),
areAssignmentsChannelRelated: true,
},
{
name: "Low Cut",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.Wrap,
encoderValue: mixerBankChannel.mPreFilter.mLowCutFreq,
encoderValueDefault: 0,
pushToggleValue: mixerBankChannel.mPreFilter.mLowCutOn,
}),
areAssignmentsChannelRelated: true,
},
{
name: "High Cut",
assignments: (mixerBankChannel) => ({
displayMode: EncoderDisplayMode.Wrap,
encoderValue: mixerBankChannel.mPreFilter.mHighCutFreq,
encoderValueDefault: 1,
pushToggleValue: mixerBankChannel.mPreFilter.mHighCutOn,
}),
areAssignmentsChannelRelated: true,
},
{
name: "Track Quick Controls",
assignments: (mixerBankChannel, channelIndex) => {
return {
encoderValue: mMixerChannel.mQuickControls.getByIndex(channelIndex),
displayMode: EncoderDisplayMode.SingleDot,
};
},
areAssignmentsChannelRelated: false,
},
pageConfigs.monitor,
pageConfigs.inputGain,
pageConfigs.inputPhase,
pageConfigs.lowCut,
pageConfigs.highCut,
pageConfigs.trackQuickControls(hostAccess),
],
},

// EQ
{
activatorButtonSelector: (device) => selectAssignButtons(device).eq,
pages: [
{
name: "EQ",
assignments: [
mChannelEQ.mBand1,
mChannelEQ.mBand2,
mChannelEQ.mBand3,
mChannelEQ.mBand4,
].flatMap<EncoderAssignmentConfig>((band, bandIndex) => [
{
displayMode: EncoderDisplayMode.SingleDot,
encoderValue: band.mFreq,
encoderValueDefault: [
0.2810622751712799, 0.47443774342536926, 0.5877489447593689, 0.889056384563446,
][bandIndex],
pushToggleValue: band.mOn,
},
{
displayMode: EncoderDisplayMode.BoostOrCut,
encoderValue: band.mGain,
pushToggleValue: band.mOn,
onShiftPush: (context, encoder) => {
encoder.mEncoderValue.setProcessValue(
context,
1 - encoder.mEncoderValue.getProcessValue(context),
);
},
},
{
displayMode: EncoderDisplayMode.SingleDot,
encoderValue: band.mQ,
pushToggleValue: band.mOn,
encoderValueDefault: 0.0833333358168602,
},
{
displayMode: EncoderDisplayMode.SingleDot,
encoderValue: band.mFilterType,
pushToggleValue: band.mOn,
encoderValueDefault: [0.7142857313156128, 1, 1, 0.7142857313156128][bandIndex],
},
]),
areAssignmentsChannelRelated: false,
},
],
pages: [pageConfigs.eq(hostAccess)],
},

// Send
{
activatorButtonSelector: (device) => selectAssignButtons(device).send,
pages: [
{
name: "Sends",
assignments: [
...createElements<EncoderAssignmentConfig>(sendSlotsCount, (slotIndex) => {
const sendSlot = mSends.getByIndex(slotIndex);
return {
encoderValue: sendSlot.mLevel,
displayMode: EncoderDisplayMode.SingleDot,
encoderValueDefault: 0.7890865802764893,
pushToggleValue: sendSlot.mOn,
};
}),
...createElements<EncoderAssignmentConfig>(sendSlotsCount, (slotIndex) => {
const sendSlot = mSends.getByIndex(slotIndex);
return {
encoderValue: sendSlot.mPrePost,
displayMode: EncoderDisplayMode.Wrap,
encoderValueDefault: 0,
pushToggleValue: sendSlot.mPrePost,
};
}),
],
areAssignmentsChannelRelated: false,
},
],
pages: [pageConfigs.sends(hostAccess)],
},

// Plug-In
{
activatorButtonSelector: (device) => selectAssignButtons(device).plugin,
pages: [
{
name: "Plugin",
assignments: () => {
const parameterValue = insertEffectsViewer.mParameterBankZone.makeParameterValue();
return {
encoderValue: parameterValue,
displayMode: EncoderDisplayMode.SingleDot,
};
},
areAssignmentsChannelRelated: false,
},
],
enhanceMapping: ([pluginEncoderPage], activatorButtons) => {
for (const button of activatorButtons) {
for (const subPage of [
pluginEncoderPage.subPages.default,
pluginEncoderPage.subPages.flip,
]) {
page
.makeActionBinding(
button.mSurfaceValue,
insertEffectsViewer.mParameterBankZone.mAction.mNextBank,
)
.setSubPage(subPage);
}
}
},
},
pageConfigs.pluginMappingConfig(page, (device) => selectAssignButtons(device).plugin),

// Instrument
{
activatorButtonSelector: (device) => selectAssignButtons(device).instrument,
pages: [
{
name: "VST Quick Controls",
assignments: () => {
return {
encoderValue:
mMixerChannel.mInstrumentPluginSlot.mParameterBankZone.makeParameterValue(),
displayMode: EncoderDisplayMode.SingleDot,
};
},
areAssignmentsChannelRelated: false,
},
{
name: "Channel Strip",
assignments: [
mStripEffects.mGate,
mStripEffects.mCompressor,
mStripEffects.mTools,
mStripEffects.mSaturator,
mStripEffects.mLimiter,
].flatMap((stripEffect) => {
return createElements(8, () => {
const parameterValue = stripEffect.mParameterBankZone.makeParameterValue();
return {
encoderValue: parameterValue,
displayMode: EncoderDisplayMode.SingleDot,
pushToggleValue: stripEffect.mBypass,
};
});
}),
areAssignmentsChannelRelated: false,
},
],
pages: [pageConfigs.vstQuickControls(hostAccess), pageConfigs.stripEffects(hostAccess)],
},
];

if (deviceConfig.configureEncoderAssignments) {
encoderMappingConfigs = deviceConfig.configureEncoderAssignments(encoderMappingConfigs, page);
if (deviceConfig.configureEncoderMapping) {
encoderMappingConfigs = deviceConfig.configureEncoderMapping(encoderMappingConfigs, page);
}

encoderMapper.applyEncoderMappingConfigs(encoderMappingConfigs);
Expand Down
Loading

0 comments on commit d103456

Please sign in to comment.