NAM A2 Calibration
This commit is contained in:
@@ -27,14 +27,20 @@ import { withStyles } from "tss-react/mui";
|
||||
|
||||
import IControlViewFactory from './IControlViewFactory';
|
||||
import { PiPedalModelFactory, PiPedalModel, ListenHandle, State } from "./PiPedalModel";
|
||||
import { PedalboardItem,ControlValue } from './Pedalboard';
|
||||
import { PedalboardItem, ControlValue } from './Pedalboard';
|
||||
import PluginControlView, { ICustomizationHost, ControlGroup, ControlViewCustomization } from './PluginControlView';
|
||||
import { UiPlugin,UiControl, ControlType } from './Lv2Plugin';
|
||||
import { UiPlugin, UiControl, ControlType } from './Lv2Plugin';
|
||||
import Select from '@mui/material/Select/Select';
|
||||
import MenuItem from '@mui/material/MenuItem/MenuItem';
|
||||
import { CustomPluginControl } from './PluginControl';
|
||||
|
||||
|
||||
const TOOB_NAM__MODEL_METADATA = "http://two-play.com/plugins/toob-nam#model_metadata";
|
||||
const TOOB_NAM__MODEL_METADATA_URI = "http://two-play.com/plugins/toob-nam#model_metadata";
|
||||
const TOOB_NAM__MODEL_WEIGHT_URI = "http://two-play.com/plugins/toob-nam#modelWeight";
|
||||
|
||||
// offset 0: an integer with the folloing bits set.
|
||||
// Must match ToobAmp/src/NeuralAmpModeler_Lv2Extensions.hpp enum TOOB_NAM_METADATA_OFFSETS
|
||||
const MAX_SLIMMABLE_WEIGHTS = 16;
|
||||
class TOOB_NAM_METADATA_OFFSETS {
|
||||
static readonly flags = 0;
|
||||
static readonly preset_version = 1;
|
||||
@@ -42,7 +48,11 @@ class TOOB_NAM_METADATA_OFFSETS {
|
||||
static readonly gain = 3;
|
||||
static readonly input_level_dbu = 4;
|
||||
static readonly output_level_dbu = 5;
|
||||
static readonly max_medatadata = 6;
|
||||
static readonly is_a2 = 6;
|
||||
static readonly model_weight = 7;
|
||||
static readonly slimmable_weights_size = 8;
|
||||
static readonly slimmable_weights = 9;
|
||||
static readonly max_medatadata = TOOB_NAM_METADATA_OFFSETS.slimmable_weights + MAX_SLIMMABLE_WEIGHTS;
|
||||
};
|
||||
|
||||
|
||||
@@ -55,10 +65,9 @@ class TOOB_NAM_METADATA_FLAGS {
|
||||
};
|
||||
|
||||
class ModelMetadata {
|
||||
constructor(metadataValues?: number[])
|
||||
{
|
||||
constructor(metadataValues?: number[]) {
|
||||
|
||||
|
||||
|
||||
if (metadataValues) {
|
||||
let flags = metadataValues[TOOB_NAM_METADATA_OFFSETS.flags];
|
||||
this.hasModel = (flags & TOOB_NAM_METADATA_FLAGS.has_model) !== 0;
|
||||
@@ -72,6 +81,12 @@ class ModelMetadata {
|
||||
this.inputlevelDBU = metadataValues[TOOB_NAM_METADATA_OFFSETS.input_level_dbu];
|
||||
this.outputlevelDBU = metadataValues[TOOB_NAM_METADATA_OFFSETS.output_level_dbu];
|
||||
this.preset_version = metadataValues[TOOB_NAM_METADATA_OFFSETS.preset_version];
|
||||
this.isA2 = metadataValues[TOOB_NAM_METADATA_OFFSETS.is_a2] !== 0;
|
||||
this.modelWeight = metadataValues[TOOB_NAM_METADATA_OFFSETS.model_weight];
|
||||
let slimmableWeightsSize = metadataValues[TOOB_NAM_METADATA_OFFSETS.slimmable_weights_size];
|
||||
for (let i = 0; i < slimmableWeightsSize && i < 16; ++i) {
|
||||
this.slimmable_weights.push(metadataValues[TOOB_NAM_METADATA_OFFSETS.slimmable_weights + i]);
|
||||
}
|
||||
} else {
|
||||
this.hasModel = false;
|
||||
this.hasLoudness = false;
|
||||
@@ -84,11 +99,16 @@ class ModelMetadata {
|
||||
this.inputlevelDBU = 0;
|
||||
this.outputlevelDBU = 0;
|
||||
this.preset_version = 1;
|
||||
this.modelWeight = -1;
|
||||
this.isA2 = false;
|
||||
this.slimmable_weights = [];
|
||||
}
|
||||
}
|
||||
|
||||
preset_version: number;
|
||||
|
||||
isA2: boolean = false;
|
||||
modelWeight: number = 1.0;
|
||||
slimmable_weights: number[] = [];
|
||||
hasModel: boolean;
|
||||
hasLoudness: boolean;
|
||||
hasGain: boolean;
|
||||
@@ -100,6 +120,10 @@ class ModelMetadata {
|
||||
inputlevelDBU: number;
|
||||
outputlevelDBU: number;
|
||||
|
||||
hasSlimmableWeights(): boolean {
|
||||
return this.slimmable_weights.length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -114,8 +138,10 @@ interface ToobNamViewProps extends WithStyles<typeof styles> {
|
||||
interface ToobNamViewState {
|
||||
showEqSection: boolean;
|
||||
enableCalibration: boolean;
|
||||
showCalibration: boolean;
|
||||
enableOutputNormalization: boolean;
|
||||
modelMetadata: ModelMetadata;
|
||||
modelWeight: number,
|
||||
}
|
||||
|
||||
const ToobNamView =
|
||||
@@ -133,18 +159,18 @@ const ToobNamView =
|
||||
this.model = PiPedalModelFactory.getInstance();
|
||||
this.state = {
|
||||
showEqSection: false,
|
||||
showCalibration: false,
|
||||
enableCalibration: false,
|
||||
enableOutputNormalization: false,
|
||||
modelMetadata: new ModelMetadata()
|
||||
modelMetadata: new ModelMetadata(),
|
||||
modelWeight: -1
|
||||
}
|
||||
let pluginInfo: UiPlugin | null = this.model.getUiPlugin(this.props.item.uri);
|
||||
if (pluginInfo === null)
|
||||
{
|
||||
if (pluginInfo === null) {
|
||||
throw new Error("Plugin not fouund.");
|
||||
}
|
||||
let inputCalibrationControl = pluginInfo.getControl("inputCalibrationMode");
|
||||
if (!inputCalibrationControl)
|
||||
{
|
||||
if (!inputCalibrationControl) {
|
||||
throw new Error("Control not found.");
|
||||
}
|
||||
let patchedInputControl = new UiControl().deserialize(inputCalibrationControl);
|
||||
@@ -152,14 +178,13 @@ const ToobNamView =
|
||||
this.patchedInputControl = patchedInputControl
|
||||
|
||||
let outputCalibrationControl = pluginInfo.getControl("outputCalibration");
|
||||
if (!outputCalibrationControl)
|
||||
{
|
||||
if (!outputCalibrationControl) {
|
||||
throw new Error("Control not found.");
|
||||
}
|
||||
let patchedOutputControl = new UiControl().deserialize(outputCalibrationControl);
|
||||
patchedOutputControl.controlType = ControlType.Select;
|
||||
this.noCalibrationOutputControl = patchedOutputControl
|
||||
this.noCalibrationOutputControl.scale_points.splice(1,1);
|
||||
this.noCalibrationOutputControl.scale_points.splice(1, 1);
|
||||
}
|
||||
|
||||
private patchedInputControl: UiControl;
|
||||
@@ -171,7 +196,7 @@ const ToobNamView =
|
||||
disableControl(control: React.ReactNode, key: string) {
|
||||
return (
|
||||
<div style={{ opacity: 0.3, pointerEvents: "none" }}
|
||||
key={key}
|
||||
key={key}
|
||||
|
||||
onPointerDownCapture={(e) => {
|
||||
e.stopPropagation();
|
||||
@@ -189,42 +214,94 @@ const ToobNamView =
|
||||
|
||||
modifyControls(host: ICustomizationHost, controls: (React.ReactNode | ControlGroup)[]): (React.ReactNode | ControlGroup)[] {
|
||||
let EqPos = 7;
|
||||
let CalibrationGroupPos = 8;
|
||||
const CalibrationGroupPos = 8;
|
||||
const ModelSizeControlPos = 9;
|
||||
const ModelWeightControlPos = 10;
|
||||
|
||||
|
||||
let calibrationGroup = controls[CalibrationGroupPos] as ControlGroup;
|
||||
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl,this.props.item.controlValues);
|
||||
|
||||
if (this.state.enableCalibration)
|
||||
{
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl,this.props.item.controlValues);
|
||||
if (this.state.showCalibration) {
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl, this.props.item.controlValues);
|
||||
|
||||
} else {
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl,
|
||||
[ new ControlValue("inputCalibrationMode",0.0)]
|
||||
);
|
||||
calibrationGroup.controls[0] = this.disableControl(calibrationGroup.controls[0], "cg_01d");
|
||||
calibrationGroup.controls[1] = this.disableControl(calibrationGroup.controls[1], "cg_02d");
|
||||
if (this.state.enableCalibration) {
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl, this.props.item.controlValues);
|
||||
|
||||
if (this.state.enableOutputNormalization)
|
||||
{
|
||||
calibrationGroup.controls[2] = host.makeStandardControl(this.noCalibrationOutputControl, this.props.item.controlValues);
|
||||
} else {
|
||||
let tControl: UiControl = this.noCalibrationOutputControl.clone();
|
||||
tControl.symbol = "_disabled_output";
|
||||
calibrationGroup.controls[2] = host.makeStandardControl(
|
||||
tControl,
|
||||
[ new ControlValue("_disabled_output",2.0)]);
|
||||
calibrationGroup.controls[2] = this.disableControl(calibrationGroup.controls[2], "cg_03d");
|
||||
calibrationGroup.controls[0] = host.makeStandardControl(this.patchedInputControl,
|
||||
[new ControlValue("inputCalibrationMode", 0.0)]
|
||||
);
|
||||
calibrationGroup.controls[0] = this.disableControl(calibrationGroup.controls[0], "cg_01d");
|
||||
calibrationGroup.controls[1] = this.disableControl(calibrationGroup.controls[1], "cg_02d");
|
||||
|
||||
if (this.state.enableOutputNormalization) {
|
||||
calibrationGroup.controls[2] = host.makeStandardControl(this.noCalibrationOutputControl, this.props.item.controlValues);
|
||||
} else {
|
||||
let tControl: UiControl = this.noCalibrationOutputControl.clone();
|
||||
tControl.symbol = "_disabled_output";
|
||||
calibrationGroup.controls[2] = host.makeStandardControl(
|
||||
tControl,
|
||||
[new ControlValue("_disabled_output", 2.0)]);
|
||||
calibrationGroup.controls[2] = this.disableControl(calibrationGroup.controls[2], "cg_03d");
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
controls[CalibrationGroupPos] = null;
|
||||
}
|
||||
controls[ModelSizeControlPos] = null;
|
||||
controls[ModelWeightControlPos] = null;
|
||||
if (!this.state.showEqSection) {
|
||||
controls.splice(EqPos, 1);
|
||||
}
|
||||
if (this.state.modelMetadata.hasSlimmableWeights()) {
|
||||
controls.splice(3, 0, this.MakeModelWeightSelector(host));
|
||||
}
|
||||
return controls;
|
||||
}
|
||||
|
||||
ModelWeightToString(weight: number): string {
|
||||
switch (weight) {
|
||||
case 1.0: return "Standard";
|
||||
case 0.5: return "Lite";
|
||||
case 0.25: return "Feather";
|
||||
default: return weight.toString();
|
||||
}
|
||||
}
|
||||
|
||||
SelectModelWeight(weight: number) {
|
||||
this.setState({ modelWeight: weight });
|
||||
this.model.setPatchProperty(this.props.instanceId, TOOB_NAM__MODEL_WEIGHT_URI, weight);
|
||||
|
||||
}
|
||||
MakeModelWeightSelector(host: ICustomizationHost): React.ReactNode {
|
||||
if ((this.state.modelMetadata.modelWeight === undefined || this.state.modelMetadata.modelWeight || this.state.modelMetadata.hasSlimmableWeights()) === false) {
|
||||
return null;
|
||||
}
|
||||
let selectControl = (
|
||||
<Select key="model_weight_control" variant="standard" size="small" value={this.state.modelMetadata.modelWeight}
|
||||
onChange={(e) => { this.SelectModelWeight(Number(e.target.value)) }}
|
||||
style={{ marginLeft: 4, marginRight: 4, width: 140, fontSize: 12, marginTop: 4 }}
|
||||
>
|
||||
{this.state.modelMetadata.slimmable_weights.map((weight, index) => {
|
||||
return (
|
||||
<MenuItem key={weight.toString()} value={weight}
|
||||
style={{ fontSize: 14 }}
|
||||
>
|
||||
{this.ModelWeightToString(weight)}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
|
||||
</Select>
|
||||
);
|
||||
return (
|
||||
<div style={{ marginLeft: 12 }}>
|
||||
<CustomPluginControl title="Model Weight" mainControl={selectControl} isSelect={true} />
|
||||
</div>);
|
||||
}
|
||||
|
||||
private handleConnectionStateChanged(state: State) {
|
||||
if (state === State.Ready) {
|
||||
this.unsubscribeFromMetadata();
|
||||
@@ -235,11 +312,16 @@ const ToobNamView =
|
||||
handleModelMetadata(atomData: any) {
|
||||
if (atomData && atomData.otype_ === "Vector" && atomData.value) {
|
||||
let metadata = new ModelMetadata(atomData.value as number[]);
|
||||
this.setState({
|
||||
metadata.hasInputLevelDBU || metadata.hasOutputLevelDBU
|
||||
this.setState({
|
||||
modelMetadata: metadata,
|
||||
showEqSection: metadata.preset_version === 0,
|
||||
showCalibration: (
|
||||
metadata.hasInputLevelDBU || metadata.hasOutputLevelDBU ||
|
||||
(metadata.hasLoudness && metadata.hasGain)) && metadata.hasModel,
|
||||
enableCalibration: metadata.hasInputLevelDBU && metadata.hasModel,
|
||||
enableOutputNormalization: metadata.hasLoudness && metadata.hasModel
|
||||
enableOutputNormalization: metadata.hasLoudness && metadata.hasModel,
|
||||
modelWeight: metadata.modelWeight
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -248,13 +330,13 @@ const ToobNamView =
|
||||
this.subscribedId = this.props.instanceId;
|
||||
this.listenHandle = this.model.monitorPatchProperty(
|
||||
this.props.instanceId,
|
||||
TOOB_NAM__MODEL_METADATA,
|
||||
TOOB_NAM__MODEL_METADATA_URI,
|
||||
(instanceId, propertyUri, atomData) => {
|
||||
this.handleModelMetadata(atomData);
|
||||
});
|
||||
this.model.getPatchProperty(
|
||||
this.props.instanceId,
|
||||
TOOB_NAM__MODEL_METADATA
|
||||
TOOB_NAM__MODEL_METADATA_URI
|
||||
).then((atomData) => {
|
||||
this.handleModelMetadata(atomData);
|
||||
}).catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user