Repository navigation
Expand file tree
/
Copy pathparameters.cs
More file actions
274 lines (235 loc) · 11 KB
/
Copy pathparameters.cs
File metadata and controls
274 lines (235 loc) · 11 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Sanford.Multimedia.Midi;
using System.IO;
using System.Configuration;
namespace MIDI_Interface
{
public static class parameters
{
// Contains all variables and methods for changing variable values:
// -----------------------------------------
// PUBLIC METHODS:
//=================
// loadScale() - load scaling parameters from Properties.Settings
// saveScale() - save any changed scaling parameters to Properties.Settings
// setScale(int pair, float low, float, hi) - sets the scaling parameters for a fader/knob pair
// setSensitivity(int pair, float value) - Sets the sensitivity of the fader for a fader/knob pair
// setX(int index, float val) - sets the value of Control[index] to val, also updates device and form if necessary,
// changes in Control[] affect Faders[] and/or Knobs[] as well when performed with this
// method
// setY(int index, bool val) - Changes Button[index] to val, also updates form and device.
// returnAllX() - returns the Control array
// returnScaledX() - returns the Faders array
// returnY() - returns the Button array
// PUBLIC VARIABLES:
//=================
// float Control[16] - Contains unscaled control values, 0 to 7 correspond to the faders, 8 to 15 the knobs (left to right)
// bool Button[20] - Contains button values, on or off. buttons go left to right then top to bottom so 0 to 7 = top row,
// 8 to 15 = second row, and 16 to 19 are the buttons at the bottom right of the controller
// float Faders[8] - Contains weighted fader values, taking into account fader/knob pairs and scale adjustments
// float Knobs[8] - Contains weighted knob values, taking into account knob value and scale adjustments
// INTERNAL METHODS:
//=================
// setForm(InterfaceForm mainForm) - as in HardwareSetup
private static Properties.Settings My = new Properties.Settings();
private static InterfaceForm inForm;
public static float[] Control = new float[16];
public static bool[] Button = new bool[20];
public static float[] Faders = new float[8];
public static float[] Knobs = new float[8];
internal static float[] ScaleUpperBound = new float[8];
internal static float[] ScaleLowerBound = new float[8];
internal static float[] FineScaleRatio = new float[8] { 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f };
internal static void setForm(InterfaceForm mainForm) // sets inForm to the current form
{
inForm = mainForm;
}
public static void loadScale() // Loads settings for scaling from Properties.Settings
{
for (int i = 0; i < 8; i++)
float.TryParse(My.scaling_hi[i], out ScaleUpperBound[i]);
for (int i = 0; i < 8; i++)
float.TryParse(My.scaling_lo[i], out ScaleLowerBound[i]);
for (int i = 0; i < 8; i++)
setScale(i, ScaleLowerBound[i], ScaleUpperBound[i]);
}
public static void saveScale() // Saves all scaling parameters
{
StringCollection scale = new StringCollection();
for (int i = 0; i < 8; i++)
scale.Add(ScaleLowerBound[i].ToString());
My.scaling_lo = scale;
scale = null;
scale = new StringCollection();
for (int i = 0; i < 8; i++)
scale.Add(ScaleUpperBound[i].ToString());
My.scaling_hi = scale;
scale = null;
scale = new StringCollection();
for (int i = 0; i < 8; i++)
scale.Add(FineScaleRatio[i].ToString());
My.sensitivity = scale;
My.Save();
}
public static void setScale(int pair, float low, float hi) // Set the scale of a fader/knob pair
{
ScaleLowerBound[pair] = low;
ScaleUpperBound[pair] = hi;
if (inForm != null)
{
switch (pair)
{
case 0:
inForm.Pair1_lo.Value = (Decimal)low;
inForm.Pair1_hi.Value = (Decimal)hi;
break;
case 1:
inForm.Pair2_lo.Value = (Decimal)low;
inForm.Pair2_hi.Value = (Decimal)hi;
break;
case 2:
inForm.Pair3_lo.Value = (Decimal)low;
inForm.Pair3_hi.Value = (Decimal)hi;
break;
case 3:
inForm.Pair4_lo.Value = (Decimal)low;
inForm.Pair4_hi.Value = (Decimal)hi;
break;
case 4:
inForm.Pair5_lo.Value = (Decimal)low;
inForm.Pair5_hi.Value = (Decimal)hi;
break;
case 5:
inForm.Pair6_lo.Value = (Decimal)low;
inForm.Pair6_hi.Value = (Decimal)hi;
break;
case 6:
inForm.Pair7_lo.Value = (Decimal)low;
inForm.Pair7_hi.Value = (Decimal)hi;
break;
case 7:
inForm.Pair8_lo.Value = (Decimal)low;
inForm.Pair8_hi.Value = (Decimal)hi;
break;
default:
break;
}
}
}
public static void setSensitivity(int pair, float value)
{
FineScaleRatio[pair] = value;
if (HardwareSetup.FormSender == false)
if (inForm != null)
{
switch (pair)
{
case 0:
inForm.Sensitivity1.Value = (Decimal)value;
break;
case 1:
inForm.Sensitivity2.Value = (Decimal)value;
break;
case 2:
inForm.Sensitivity3.Value = (Decimal)value;
break;
case 3:
inForm.Sensitivity4.Value = (Decimal)value;
break;
case 4:
inForm.Sensitivity5.Value = (Decimal)value;
break;
case 5:
inForm.Sensitivity6.Value = (Decimal)value;
break;
case 6:
inForm.Sensitivity7.Value = (Decimal)value;
break;
case 7:
inForm.Sensitivity8.Value = (Decimal)value;
break;
default:
break;
}
}
setX(pair, Control[pair]);
}
public static void setX(int index, float val) // Set the value of a fader/knob
{
Control[index] = val;
if (!HardwareSetup.FormSender && !HardwareSetup.ControlSender && (HardwareSetup.BCF2000_i != null && HardwareSetup.BCF2000_o != null))
{
HardwareSetup.controlMess(index, val);
}
// Old method of setting fader values:
//if (index < 8)
//{
// /*
// float increment = (ScaleUpperBound[index] - ScaleLowerBound[index]) / (float)127.0;
// Knobs[index] = ScaleLowerBound[index] + (increment * Control[index + 8]);
// increment /= (float)127.0;
// * Faders[index] = Knobs[index] + (increment * Control[index]);
// */
// float Range = ScaleUpperBound[index] - ScaleLowerBound[index];
// float StepCoarse = Range/127f;
// float ValueCoarse = ScaleLowerBound[index] + ((float)Control[index + 8] / 127f) * Range;
// float RangeFine = StepCoarse * FineScaleRatio[index];
// float ValueFine = (((float)Control[index] - 63f) / 127f) * RangeFine;
// Faders[index] = ValueCoarse + ValueFine;
//}
//else
//{
// index -= 8;
// float Range = ScaleUpperBound[index] - ScaleLowerBound[index];
// float ValueCoarse = ScaleLowerBound[index] + ((float)Control[index + 8] / 127f) * Range;
// float RangeFine = Range * FineScaleRatio[index];
// float ValueFine = (((float)Control[index] - 63f) / 127f) * RangeFine;
// Faders[index] = ValueCoarse + ValueFine;
// /*
// float increment = (ScaleUpperBound[index] - ScaleLowerBound[index]) / (float)127.0;
// Knobs[index] = ScaleLowerBound[index] + (increment * Control[index + 8]);
// increment /= (float)127.0;
// Faders[index] = Knobs[index] + (increment * Control[index]);
// */
//}
if (index > 7) // if index is greater than 7, it refers to a knob, hence reduce by 8 for associated pair
index -= 8;
float Range = ScaleUpperBound[index] - ScaleLowerBound[index]; // Total range of faders
float StepCoarse = Range / 127f;
float ValueCoarse = ScaleLowerBound[index] + (Control[index + 8] * StepCoarse); // Knob value
float RangeFine = Range * (1f - FineScaleRatio[index]); // Range of fader within coarse range
if (RangeFine == 0)
RangeFine += 0.01f; // Make sure faders always do something at least
float ValueFine = ((Control[index] - 63f) / 127f) * RangeFine;
Faders[index] = ValueCoarse + ValueFine;
if (inForm != null)
inForm.ChangePair(index, Faders[index]);
}
public static void setY(int index, bool val) // Set the value of a button
{
Button[index] = val;
if (!HardwareSetup.FormSender && !HardwareSetup.ControlSender && HardwareSetup.BCF2000_i != null)
{
HardwareSetup.noteMess(index, val);
if (inForm != null)
inForm.setButton(index, val);
}
}
public static float[] returnAllX() // Returns unscaled array of all controls
{
return Control;
}
public static float[] returnScaledX() // Returns the array of scaled faders
{
return Faders;
}
public static bool[] returnY() // Returns array of button values
{
return Button;
}
}
}