You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dexed/Source/PluginParam.cpp

590 lines
17 KiB

11 years ago
/**
*
* Copyright (c) 2013 Pascal Gauthier.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#include "PluginParam.h"
#include "PluginProcessor.h"
#include "PluginEditor.h"
11 years ago
// ************************************************************************
//
Ctrl::Ctrl(String name) {
11 years ago
label << name;
slider = NULL;
button = NULL;
comboBox = NULL;
11 years ago
}
void Ctrl::bind(Slider *s) {
11 years ago
slider = s;
updateComponent();
s->addListener(this);
11 years ago
}
void Ctrl::bind(Button *b) {
11 years ago
button = b;
updateComponent();
b->addListener(this);
11 years ago
}
void Ctrl::bind(ComboBox *c) {
11 years ago
comboBox = c;
updateComponent();
c->addListener(this);
11 years ago
}
void Ctrl::unbind() {
11 years ago
if (slider != NULL) {
11 years ago
slider->removeListener(this);
slider = NULL;
}
11 years ago
if (button != NULL) {
11 years ago
button->removeListener(this);
button = NULL;
}
11 years ago
if (comboBox != NULL) {
11 years ago
comboBox->removeListener(this);
comboBox = NULL;
}
11 years ago
}
void Ctrl::publishValue(float value) {
parent->beginParameterChangeGesture(idx);
parent->setParameterNotifyingHost(idx, value);
parent->endParameterChangeGesture(idx);
}
void Ctrl::sliderValueChanged(Slider* moved) {
publishValue(moved->getValue());
}
void Ctrl::buttonClicked(Button* clicked) {
publishValue(clicked->getToggleStateValue() == 1 ? 1 : 0);
}
void Ctrl::comboBoxChanged(ComboBox* combo) {
publishValue((combo->getSelectedId() - 1) / combo->getNumItems());
}
// ************************************************************************
// CtrlDX - control DX mapping
CtrlFloat::CtrlFloat(String name, float *storageValue) : Ctrl(name) {
11 years ago
vPointer = storageValue;
}
float CtrlFloat::getValueHost() {
11 years ago
return *vPointer;
}
void CtrlFloat::setValueHost(float v) {
11 years ago
*vPointer = v;
}
String CtrlFloat::getValueDisplay() {
11 years ago
String display;
display << *vPointer;
return display;
}
void CtrlFloat::updateComponent() {
if (slider != NULL) {
slider->setValue(*vPointer, NotificationType::dontSendNotification);
}
}
11 years ago
// ************************************************************************
// CtrlDX - control DX mapping
CtrlDX::CtrlDX(String name, int steps, int offset, bool starts1) : Ctrl(name) {
11 years ago
add1 = starts1 == 1;
this->steps = steps;
dxValue = 0;
11 years ago
dxOffset = offset;
11 years ago
}
float CtrlDX::getValueHost() {
return dxValue / steps;
11 years ago
}
void CtrlDX::setValueHost(float f) {
11 years ago
setValue((f * steps));
11 years ago
}
void CtrlDX::setValue(int v) {
11 years ago
if (v >= steps) {
11 years ago
TRACE("WARNING: value too big %s : %d", label.toRawUTF8(), v);
11 years ago
v = steps - 1;
11 years ago
}
dxValue = v;
11 years ago
if (dxOffset >= 0) {
if (parent != NULL)
11 years ago
parent->setDxValue(dxOffset, v);
}
11 years ago
}
int CtrlDX::getValue() {
11 years ago
if (dxOffset >= 0)
dxValue = parent->data[dxOffset];
return dxValue;
11 years ago
}
String CtrlDX::getValueDisplay() {
11 years ago
String ret;
ret << ( getValue() + add1 );
11 years ago
return ret;
11 years ago
}
void CtrlDX::publishValue(float value) {
11 years ago
Ctrl::publishValue(value / steps);
11 years ago
DexedAudioProcessorEditor *editor = (DexedAudioProcessorEditor *) parent->getActiveEditor();
if ( editor == NULL )
11 years ago
return;
String msg;
msg << label << " = " << getValueDisplay();
editor->global.setParamMessage(msg);
11 years ago
}
void CtrlDX::sliderValueChanged(Slider* moved) {
11 years ago
publishValue(((int) moved->getValue() - add1));
11 years ago
}
11 years ago
void CtrlDX::comboBoxChanged(ComboBox* combo) {
publishValue(combo->getSelectedId() - 1);
11 years ago
}
void CtrlDX::updateComponent() {
11 years ago
if (slider != NULL) {
slider->setValue(getValue() + add1,
NotificationType::dontSendNotification);
11 years ago
}
11 years ago
if (button != NULL) {
if (getValue() == 0) {
button->setToggleState(false,
NotificationType::dontSendNotification);
11 years ago
} else {
11 years ago
button->setToggleState(true,
NotificationType::dontSendNotification);
11 years ago
}
}
11 years ago
if (comboBox != NULL) {
11 years ago
int cvalue = getValue() + 1;
11 years ago
if (comboBox->getNumItems() <= cvalue) {
11 years ago
cvalue = comboBox->getNumItems();
}
comboBox->setSelectedId(cvalue, NotificationType::dontSendNotification);
}
11 years ago
}
/***************************************************************
*
*/
11 years ago
void DexedAudioProcessor::initCtrl() {
importSysex(BinaryData::startup_syx);
11 years ago
fxCutoff = new CtrlFloat("Cutoff", &fx.uiCutoff);
ctrl.add(fxCutoff);
fxReso = new CtrlFloat("Resonance", &fx.uiReso);
ctrl.add(fxReso);
algo = new CtrlDX("ALGORITHM", 32, 134, true);
ctrl.add(algo);
feedback = new CtrlDX("FEEDBACK", 8, 135);
ctrl.add(feedback);
oscSync = new CtrlDX("OSC KEY SYNC", 2, 136);
ctrl.add(oscSync);
lfoRate = new CtrlDX("LFO SPEED", 100, 137);
ctrl.add(lfoRate);
lfoDelay = new CtrlDX("LFO DELAY", 100, 138);
ctrl.add(lfoDelay);
lfoPitchDepth = new CtrlDX("LFO PM DEPTH", 100, 139);
ctrl.add(lfoPitchDepth);
lfoAmpDepth = new CtrlDX("LFO AM DEPTH", 100, 140);
ctrl.add(lfoAmpDepth);
lfoSync = new CtrlDX("LFO KEY SYNC", 2, 141);
ctrl.add(lfoSync);
lfoWaveform = new CtrlDX("LFO WAVE", 5, 142);
ctrl.add(lfoWaveform);
transpose = new CtrlDX("MIDDLE C", 49, 144);
ctrl.add(transpose);
pitchModSens = new CtrlDX("P MODE SENS.", 8, 143);
ctrl.add(pitchModSens);
for (int i=0;i<4;i++) {
String rate;
rate << "PITCH EG RATE " << (i+1);
pitchEgRate[i] = new CtrlDX(rate, 99, 126+i);
ctrl.add(pitchEgRate[i]);
}
for (int i=0;i<4;i++) {
String level;
level << "PITCH EG LEVEL " << (i+1);
pitchEgLevel[i] = new CtrlDX(level, 99, 130+i);
ctrl.add(pitchEgLevel[i]);
}
11 years ago
// fill operator values;
11 years ago
for (int i = 0; i < 6; i++) {
//// In the Sysex, OP6 comes first, then OP5...
int opTarget = (5-i) * 21;
int opVal = i;
String opName;
11 years ago
opName << "OP" << (opVal + 1);
for (int j = 0; j < 4; j++) {
11 years ago
String opRate;
opRate << opName << " EG RATE " << (j + 1);
11 years ago
opCtrl[opVal].egRate[j] = new CtrlDX(opRate, 100, opTarget + j);
ctrl.add(opCtrl[opVal].egRate[j]);
}
for (int j = 0; j < 4; j++) {
11 years ago
String opLevel;
opLevel << opName << " EG LEVEL " << (j + 1);
opCtrl[opVal].egLevel[j] = new CtrlDX(opLevel, 100, opTarget + j + 4);
ctrl.add(opCtrl[opVal].egLevel[j]);
11 years ago
}
11 years ago
String opVol;
opVol << opName << " OUTPUT LEVEL";
11 years ago
opCtrl[opVal].level = new CtrlDX(opVol, 100, opTarget + 16);
ctrl.add(opCtrl[opVal].level);
11 years ago
11 years ago
String opMode;
opMode << opName << " MODE";
11 years ago
opCtrl[opVal].opMode = new CtrlDX(opMode, 1, opTarget + 17);
ctrl.add(opCtrl[opVal].opMode);
11 years ago
11 years ago
String coarse;
coarse << opName << " F COARSE";
11 years ago
opCtrl[opVal].coarse = new CtrlDX(coarse, 32, opTarget + 18);
ctrl.add(opCtrl[opVal].coarse);
11 years ago
11 years ago
String fine;
fine << opName << " F FINE";
11 years ago
opCtrl[opVal].fine = new CtrlDX(fine, 100, opTarget + 19);
ctrl.add(opCtrl[opVal].fine);
11 years ago
String detune;
detune << opName << " OSC DETUNE";
11 years ago
opCtrl[opVal].detune = new CtrlDX(detune, 15, opTarget + 20);
ctrl.add(opCtrl[opVal].detune);
String sclBrkPt;
sclBrkPt << opName << " BREAK POINT";
11 years ago
opCtrl[opVal].sclBrkPt = new CtrlDX(sclBrkPt, 100, opTarget + 8);
ctrl.add(opCtrl[opVal].sclBrkPt);
String sclLeftDepth;
sclLeftDepth << opName << " L SCALE DEPTH";
11 years ago
opCtrl[opVal].sclLeftDepth = new CtrlDX(sclLeftDepth, 100,
opTarget + 9);
ctrl.add(opCtrl[opVal].sclLeftDepth);
String sclRightDepth;
sclRightDepth << opName << " R SCALE DEPTH";
11 years ago
opCtrl[opVal].sclRightDepth = new CtrlDX(sclRightDepth, 100,
opTarget + 10);
ctrl.add(opCtrl[opVal].sclRightDepth);
String sclLeftCurve;
sclLeftCurve << opName << " L KEY SCALE";
11 years ago
opCtrl[opVal].sclLeftCurve = new CtrlDX(sclLeftCurve, 4, opTarget + 11);
ctrl.add(opCtrl[opVal].sclLeftCurve);
String sclRightCurve;
sclRightCurve << opName << " R KEY SCALE";
11 years ago
opCtrl[opVal].sclRightCurve = new CtrlDX(sclRightCurve, 4,
opTarget + 12);
ctrl.add(opCtrl[opVal].sclRightCurve);
String sclRate;
sclRate << opName << " RATE SCALING";
11 years ago
opCtrl[opVal].sclRate = new CtrlDX(sclRate, 7, opTarget + 13);
ctrl.add(opCtrl[opVal].sclRate);
String ampModSens;
ampModSens << opName << " A MOD SENS.";
11 years ago
opCtrl[opVal].ampModSens = new CtrlDX(ampModSens, 3, opTarget + 14);
ctrl.add(opCtrl[opVal].ampModSens);
String velModSens;
velModSens << opName << " KEY VELOCITY";
11 years ago
opCtrl[opVal].velModSens = new CtrlDX(velModSens, 8, opTarget + 15);
ctrl.add(opCtrl[opVal].velModSens);
11 years ago
}
for (int i=0; i < ctrl.size(); i++) {
11 years ago
ctrl[i]->idx = i;
ctrl[i]->parent = this;
11 years ago
}
}
int DexedAudioProcessor::importSysex(const char *imported) {
11 years ago
// reset current program
currentProgram = 0;
memcpy(sysex, imported + 6, 4096);
11 years ago
for (int i = 0; i < 32; i++) {
memcpy(patchNames[i], sysex + ((i * 128) + 118), 11);
for (int j = 0; j < 10; j++) {
char c = (unsigned char) patchNames[i][j];
11 years ago
switch (c) {
11 years ago
case 92:
c = 'Y';
break; /* yen */
case 126:
c = '>';
break; /* >> */
case 127:
c = '<';
break; /* << */
11 years ago
default:
11 years ago
if (c < 32 || c > 127)
c = 32;
break;
11 years ago
}
11 years ago
patchNames[i][j] = c;
11 years ago
}
patchNames[i][11] = 0;
}
11 years ago
return 0;
11 years ago
}
11 years ago
void DexedAudioProcessor::exportSysex(char *dest) {
uint8_t header[] = { 0xF0, 0x43, 0x00, 0x09, 0x20, 0x00 };
memcpy(dest, header, 6);
// copy 32 voices
memcpy(dest+6, sysex, 4096);
// make checksum for dump
uint8_t footer[] = { 0x00, 0xF7 };
uint8_t sum = 0;
for (int i=0; i<4096; i++)
sum = (sum + sysex[i]) % (1 << 8);
footer[0] = ((1 << 8) - sum);
memcpy(dest+4102, footer, 2);
}
/*
*/
void DexedAudioProcessor::unpackProgram(int idx) {
11 years ago
char *bulk = sysex + (idx * 128);
11 years ago
11 years ago
for (int op = 0; op < 6; op++) {
// eg rate and level, brk pt, depth, scaling
memcpy(data + op * 21, bulk + op * 17, 11);
char leftrightcurves = bulk[op * 17 + 11];
data[op * 21 + 11] = leftrightcurves & 3;
data[op * 21 + 12] = (leftrightcurves >> 2) & 3;
char detune_rs = bulk[op * 17 + 12];
data[op * 21 + 13] = detune_rs & 7;
char kvs_ams = bulk[op * 17 + 13];
data[op * 21 + 14] = kvs_ams & 3;
data[op * 21 + 15] = kvs_ams >> 2;
data[op * 21 + 16] = bulk[op * 17 + 14]; // output level
char fcoarse_mode = bulk[op * 17 + 15];
data[op * 21 + 17] = fcoarse_mode & 1;
data[op * 21 + 18] = fcoarse_mode >> 1;
data[op * 21 + 19] = bulk[op * 17 + 16]; // fine freq
11 years ago
data[op * 21 + 20] = detune_rs >> 3;
11 years ago
}
memcpy(data + 126, bulk + 102, 9); // pitch env, algo
char oks_fb = bulk[111];
data[135] = oks_fb & 7;
data[136] = oks_fb >> 3;
memcpy(data + 137, bulk + 112, 4); // lfo
char lpms_lfw_lks = bulk[116];
data[141] = lpms_lfw_lks & 1;
data[142] = (lpms_lfw_lks >> 1) & 7;
data[143] = lpms_lfw_lks >> 4;
memcpy(data + 144, bulk + 117, 11); // transpose, name
data[155] = 1; // operator on/off
data[156] = 1;
data[157] = 1;
data[158] = 1;
data[159] = 1;
11 years ago
data[160] = 1;
}
void DexedAudioProcessor::packProgram(int idx, const char *name) {
char *bulk = sysex + (idx * 128);
for(int op = 0; op < 6; op++) {
// eg rate and level, brk pt, depth, scaling
memcpy(bulk + op * 17, data + op * 21, 11);
int pp = op*17;
int up = op*21;
bulk[pp+11] = (data[up+11]&0x03) | ((data[up+12]&0x03) << 2);
bulk[pp+12] = (data[up+13]&0x07) | ((data[up+20]*0x0f) << 3);
bulk[pp+13] = (data[up+14]&0x03) | ((data[up+15]*0x07) << 2);
bulk[pp+14] = data[up+16];
}
memcpy(bulk + 102, data + 126, 9); // pitch env, algo
bulk[111] = (data[135]&0x07) | ((data[136]&0x01) << 3);
memcpy(bulk + 112, data + 137, 4); // lfo
bulk[116] = (data[141]&0x01) | (((data[142]&0x07) << 1) | ((data[143]&0x07) << 4));
int eos = 0;
for(int i=0; i < 10; i++) {
char c = name[i];
if ( c == 0 )
eos = 1;
if ( eos ) {
bulk[117+i] = ' ';
continue;
}
c = c < 32 ? ' ' : c;
c = c > 127 ? ' ' : c;
bulk[117+i] = c;
}
memcpy(patchNames[idx], bulk+117, 10);
patchNames[idx][10] = 0;
11 years ago
}
void DexedAudioProcessor::updateProgramFromSysex(const uint8 *rawdata) {
11 years ago
memcpy(data, rawdata, 160);
refreshUI = true;
}
11 years ago
void DexedAudioProcessor::setDxValue(int offset, int v) {
11 years ago
TRACE("setting dx %d %d", offset, v);
refreshVoice = true;
11 years ago
if (offset >= 0)
11 years ago
data[offset] = v;
11 years ago
if (!sendSysexChange)
return;
uint8 msg[7] = { 0xF0, 0x43, 0x10, offset > 127, 0, (uint8) v, 0xF7 };
msg[4] = offset & 0x7F;
11 years ago
midiOut.addEvent(msg, 7, 0);
11 years ago
}
void DexedAudioProcessor::unbindUI() {
11 years ago
for (int i = 0; i < ctrl.size(); i++) {
11 years ago
ctrl[i]->unbind();
11 years ago
}
}
//==============================================================================
int DexedAudioProcessor::getNumParameters() {
return ctrl.size();
}
11 years ago
float DexedAudioProcessor::getParameter(int index) {
return ctrl[index]->getValueHost();
11 years ago
}
11 years ago
void DexedAudioProcessor::setParameter(int index, float newValue) {
ctrl[index]->setValueHost(newValue);
11 years ago
}
int DexedAudioProcessor::getNumPrograms() {
return 32;
}
int DexedAudioProcessor::getCurrentProgram() {
11 years ago
return currentProgram;
11 years ago
}
11 years ago
void DexedAudioProcessor::setCurrentProgram(int index) {
11 years ago
/*// VST has a naughty problem of calling setCurrentProgram after a host has loaded
11 years ago
// an edited preset. We ignore the 16th value, since we want to keep the user values
if ( index == 32 ) {
return;
}*/
11 years ago
11 years ago
for (int i = 0; i < MAX_ACTIVE_NOTES; i++) {
if (voices[i].keydown == false && voices[i].live == true) {
11 years ago
voices[i].live = false;
}
}
11 years ago
index = index > 31 ? 31 : index;
unpackProgram(index);
11 years ago
currentProgram = index;
11 years ago
lfo.reset(data + 137);
11 years ago
updateUI();
11 years ago
}
11 years ago
const String DexedAudioProcessor::getProgramName(int index) {
if (index >= 32)
11 years ago
index = 31;
11 years ago
return String(patchNames[index]);
}
11 years ago
void DexedAudioProcessor::changeProgramName(int index, const String& newName) {
11 years ago
}
11 years ago
const String DexedAudioProcessor::getParameterName(int index) {
11 years ago
return ctrl[index]->label;
}
11 years ago
const String DexedAudioProcessor::getParameterText(int index) {
11 years ago
return ctrl[index]->getValueDisplay();
}
//==============================================================================
11 years ago
void DexedAudioProcessor::getStateInformation(MemoryBlock& destData) {
11 years ago
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.*/
11 years ago
destData.insert(data, 161, 0);
11 years ago
}
11 years ago
void DexedAudioProcessor::setStateInformation(const void* source,
int sizeInBytes) {
11 years ago
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
11 years ago
memcpy((void *) data, source, sizeInBytes);
11 years ago
updateUI();
11 years ago
}
//==============================================================================
11 years ago
void DexedAudioProcessor::getCurrentProgramStateInformation(
MemoryBlock& destData) {
11 years ago
destData.insert(data, 161, 0);
11 years ago
}
11 years ago
void DexedAudioProcessor::setCurrentProgramStateInformation(const void* source,
int sizeInBytes) {
memcpy((void *) data, source, sizeInBytes);
11 years ago
updateUI();
11 years ago
}