-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvolume_range_trim.jsfx
More file actions
147 lines (119 loc) · 4.66 KB
/
volume_range_trim.jsfx
File metadata and controls
147 lines (119 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
desc: Volume Range Trim
version: 1.8.3
author: chokehold
tags: utility gain range volume trim
link: https://github.com/chkhld/jsfx/
screenshot: https://github.com/chkhld/jsfx/blob/main/assets/screenshots/volume_range_trim.png
about:
# Volume Range Trim
Volume adjustment in a selectable +/- Decibel range for controlled automation.
Who needs another volume plugin?! Well, it depends. For regular track control
or inter-plugin gain staging, probably nobody.
This plugin is aimed at those unhappy with the way the volume envelopes scale
in Reaper. Insert this plugin where you need it, select the Range you want to
change the volume in, switch the Scaling to make the changes faster or slower,
and then automate the Trim Amount slider instead of the track volume envelope.
Remember drawing many, many points into an envelope and then messing with the
point values and point shapes endlessly, hoping to eventually get them right?
Just insert this plugin instead, set a few linear points on the envelope lane
for the Trim Amount slider, and restrict or scale the linear envelope changes
to more gentle or sudden ones with the Range and Scale options.
// ----------------------------------------------------------------------------
slider1:dBRange=0<0,3,1{6 dB,12 dB, 24 dB, 48 dB}>Range +/-
slider2:scale=0<0,3,1{Linear,Smooth,Slow,Fast}>Scaling
slider3
slider4:amount=0<-1,1,0.000001>Trim amount
slider5
slider6:dBMeter=0<-48,48,0.01>Trim meter [dB]
// By not having any in_pin and out_pin assignments, this plugin will
// automatically adapt to the number of channels of the track.
@init
// Converts dB values to float gain factors
function dBToGain (decibels) (pow(10, decibels * 0.05));
// VALUE INTERPOLATION
//
// Return interpolated value at position [0,1] between
// two not necessarily related input values.
//
// Implemented after Paul Bourke and Lewis Van Winkle
// http://paulbourke.net/miscellaneous/interpolation/
// https://codeplea.com/simple-interpolation
//
// Basic linear interpolation, constant speed
function linearInterpolation (value1, value2, position)
(
(value1 * (1.0 - position) + value2 * position);
);
//
// Slow start, fast stop
function accelerate (value)
(
linearInterpolation(0.0, 1.0, sqr(value));
);
//
// Fast start, slow stop
function decelerate (value)
(
linearInterpolation(0.0, 1.0, 1.0 - sqr(1.0-value));
);
// SMOOTHEST STEP
//
// Particularly nice SmoothStep variation.
//
// Implemented after Kyle McDonald
// https://twitter.com/kcimc/status/580738643347804160?lang=en
//
// Slow start, slow stop
function smoothestStep (value) local (v2, v4, v5, v6, v7)
(
v2 = value*value; v4 = v2*v2; v5 = v4*value; v6 = v5*value; v7 = v6*value;
(-20.0*v7 + 70.0*v6 - 84.0*v5 + 35.0*v4);
);
// Flags to keep track of parameter changes
previousAmount = -100;
previousRange = -1;
previousScale = -1;
// Stores the selected Range value as positive Decibels
decibels = 0;
// Amount slider value after scaling was applied
scaledAmount = 0;
// Stores the Range scaled by the Amount slider as signed Decibels
dBTrim = 0;
@slider
// If the Range value was changed
(dBRange != previousRange) ?
(
// Recalculate the scale of dB to scale with the Amount slider
decibels = 6 * pow(2, dBRange);
// Update the flag to not recalculate this again unless it needs to be
previousRange = dBRange;
);
// If the Amount slider was changed
(amount != previousAmount) || (scale != previousScale) ?
(
// Scale the Amount slider value
/* Default scale Linear */ scaledAmount = amount;
scale == 1 ? /* Smooth */ scaledAmount = smoothestStep(abs(amount)) * sign(amount);
scale == 2 ? /* Slow */ scaledAmount = accelerate(abs(amount)) * sign(amount);
scale == 3 ? /* Fast */ scaledAmount = decelerate(abs(amount)) * sign(amount);
// Update the flags to not recalculate this again unless it needs to be
previousScale = scale;
previousAmount = amount;
);
// Scale the Range by the scaled Amount value and write to buffer variable
dBTrim = scaledAmount * decibels;
// Turn the scaled volume adjustment from Decibels into a float gain factor
trim = dBToGain(dBTrim);
// Make sure the Meter slider always reflects the latest Trim dB value
dBMeter = dBTrim;
@sample
// Set this to 0 to start with first input channel
channel = 0;
// Cycle through all of the plugin's input channels
while (channel < num_ch)
(
// Apply trim gain to the current channel's sample
spl(channel) *= trim;
// Increment counter to next channel
channel += 1;
);