private void Knob_ValueChanged(object sender, EventArgs e) // If knob value is changed { NumericUpDown N = (NumericUpDown)sender; int index = 7 + Int32.Parse(N.Tag.ToString().Last().ToString()); float value = (float)N.Value; // interface value if (value != parameters.Control[index]) // if the current value on the interface differs from stored parameter { HardwareSetup.FormSender = true; parameters.setX(index, value); if (HardwareSetup.BCF2000_i != null) { HardwareSetup.controlMess(index, value); } HardwareSetup.FormSender = false; } }
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]); } }