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/msfa/controllers.h

121 lines
2.6 KiB

11 years ago
/*
* Copyright 2013 Google Inc.
*
11 years ago
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
11 years ago
* http://www.apache.org/licenses/LICENSE-2.0
*
11 years ago
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CONTROLLERS_H
#define __CONTROLLERS_H
10 years ago
#include "synth.h"
#include "../Dexed.h"
#include <stdio.h>
10 years ago
9 years ago
#ifdef _WIN32
#define snprintf _snprintf
#endif
11 years ago
// State of MIDI controllers
const int kControllerPitch = 128;
const int kControllerPitchRange = 129;
const int kControllerPitchStep = 130;
11 years ago
10 years ago
class FmCore;
struct FmMod {
9 years ago
int range;
bool pitch;
bool amp;
bool eg;
9 years ago
FmMod() {
range = 0;
pitch = false;
amp = false;
eg = false;
}
void parseConfig(const char *cfg) {
int r = 0, p = 0, a = 0, e = 0;
sscanf(cfg, "%d %d %d %d", &r, &p, &a, &e);
range = r < 0 && r > 127 ? 0 : r;
pitch = p != 0;
amp = a != 0;
eg = e != 0;
}
void setConfig(char *cfg) {
snprintf(cfg, 13, "%d %d %d %d", range, pitch, amp, eg);
}
};
11 years ago
class Controllers {
void applyMod(int cc, FmMod &mod) {
float range = 0.01 * mod.range;
int total = cc * range;
if ( mod.amp )
amp_mod = max(amp_mod, total);
if ( mod.pitch )
pitch_mod = max(pitch_mod, total);
if ( mod.eg )
eg_mod = max(eg_mod, total);
}
public:
int values_[131];
9 years ago
int amp_mod;
int pitch_mod;
int eg_mod;
int aftertouch_cc;
int breath_cc;
int foot_cc;
int modwheel_cc;
FmMod wheel;
FmMod foot;
FmMod breath;
FmMod at;
9 years ago
Controllers() {
amp_mod = 0;
pitch_mod = 0;
eg_mod = 0;
}
void refresh() {
amp_mod = 0;
pitch_mod = 0;
eg_mod = 0;
applyMod(modwheel_cc, wheel);
applyMod(breath_cc, breath);
applyMod(foot_cc, foot);
applyMod(aftertouch_cc, at);
if ( ! ((wheel.eg || foot.eg) || (breath.eg || at.eg)) )
eg_mod = 127;
TRACE("amp_mod %d pitch_mod %d", amp_mod, pitch_mod);
}
10 years ago
FmCore *core;
11 years ago
};
#endif // __CONTROLLERS_H