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
|
// padthv1_controls.h
//
/****************************************************************************
Copyright (C) 2012-2017, rncbc aka Rui Nuno Capela. All rights reserved.
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.
*****************************************************************************/
#ifndef __padthv1_controls_h
#define __padthv1_controls_h
#include "padthv1_param.h"
#include "padthv1_sched.h"
#include <QMap>
//-------------------------------------------------------------------------
// padthv1_controls - Controller processs class.
//
class padthv1_controls
{
public:
// ctor.
padthv1_controls(padthv1 *pSynth);
// dtor.
~padthv1_controls();
// operational mode flags.
void enabled(bool on)
{ m_enabled = on; }
bool enabled() const
{ return m_enabled; }
// controller types,
enum Type { None = 0, CC = 0x100, RPN = 0x200, NRPN = 0x300, CC14 = 0x400 };
// controller hash key.
struct Key
{
Key () : status(0), param(0) {}
Key (const Key& key)
: status(key.status), param(key.param) {}
Type type() const
{ return Type(status & 0xf00); }
unsigned short channel() const
{ return (status & 0x1f); }
// hash key comparator.
bool operator< (const Key& key) const
{
if (status != key.status)
return (status < key.status);
else
return (param < key.param);
}
unsigned short status;
unsigned short param;
};
// controller flags,
enum Flag { Logarithmic = 1, Invert = 2, Hook = 4 };
// controller data.
struct Data
{
Data () : index(-1), flags(0), val(0.0f), sync(false) {}
Data (const Data& data)
: index(data.index), flags(data.flags),
val(data.val), sync(data.sync) {}
int index;
int flags;
float val;
bool sync;
};
typedef QMap<Key, Data> Map;
// controller events.
struct Event
{
Key key;
unsigned short value;
};
// controller map methods.
const Map& map() const { return m_map; }
int find_control(const Key& key) const
{ return m_map.value(key).index; }
void add_control(const Key& key, const Data& data)
{ m_map.insert(key, data); }
void remove_control(const Key& key)
{ m_map.remove(key); }
void clear() { m_map.clear(); }
// reset all controllers.
void reset();
// controller queue methods.
void process_enqueue(
unsigned short channel,
unsigned short param,
unsigned short value);
void process_dequeue();
// process timer counter.
void process(unsigned int nframes);
// text utilities.
static Type typeFromText(const QString& sText);
static QString textFromType(Type ctype);
// current/last controller accessor.
const Key& current_key() const;
protected:
// controller action.
void process_event(const Event& event);
// input controller scheduled events (learn)
class SchedIn : public padthv1_sched
{
public:
// ctor.
SchedIn (padthv1 *pSynth)
: padthv1_sched(pSynth, Controller) {}
void schedule_key(const Key& key)
{ m_key = key; schedule(); }
// process (virtual stub).
void process(int) {}
// current controller accessor.
const Key& current_key() const
{ return m_key; }
private:
// instance variables,.
Key m_key;
};
// output controller scheduled events (assignments)
class SchedOut : public padthv1_sched
{
public:
// ctor.
SchedOut (padthv1 *pSynth)
: padthv1_sched(pSynth, Controls) {}
void schedule_event(padthv1::ParamIndex index, float fValue)
{
instance()->setParamValue(index, fValue);
schedule(int(index));
}
// process (virtual stub).
void process(int) {}
};
private:
// instance variables.
class Impl;
Impl *m_pImpl;
// operational mode flags.
bool m_enabled;
// controller schedulers.
SchedIn m_sched_in;
SchedOut m_sched_out;
// controllers map.
Map m_map;
// frame timers.
unsigned int m_timeout;
unsigned int m_timein;
};
#endif // __padthv1_controls_h
// end of padthv1_controls.h
|