| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef _MACROINT_H |
| 21 |
#define _MACROINT_H |
| 22 |
|
| 23 |
#include "instrument.h" |
| 24 |
|
| 25 |
class DivEngine; |
| 26 |
|
| 27 |
struct DivMacroStruct { |
| 28 |
int pos, lastPos, lfoPos, delay; |
| 29 |
int val; |
| 30 |
bool has, had, actualHad, finished, will, linger, began, masked, activeRelease; |
| 31 |
unsigned int mode, type; |
| 32 |
unsigned char macroType; |
| 33 |
void doMacro(DivInstrumentMacro& source, bool released, bool tick); |
| 34 |
void init() { |
| 35 |
pos=lastPos=lfoPos=mode=type=delay=0; |
| 36 |
has=had=actualHad=will=false; |
| 37 |
linger=false; |
| 38 |
began=true; |
| 39 |
// TODO: test whether this breaks anything? |
| 40 |
val=0; |
| 41 |
} |
| 42 |
void prepare(DivInstrumentMacro& source, DivEngine* e); |
| 43 |
DivMacroStruct(unsigned char mType): |
| 44 |
pos(0), |
| 45 |
lastPos(0), |
| 46 |
lfoPos(0), |
| 47 |
delay(0), |
| 48 |
val(0), |
| 49 |
has(false), |
| 50 |
had(false), |
| 51 |
actualHad(false), |
| 52 |
finished(false), |
| 53 |
will(false), |
| 54 |
linger(false), |
| 55 |
began(true), |
| 56 |
masked(false), |
| 57 |
activeRelease(false), |
| 58 |
mode(0), |
| 59 |
type(0), |
| 60 |
macroType(mType) {} |
| 61 |
}; |
| 62 |
|
| 63 |
class DivMacroInt { |
| 64 |
DivEngine* e; |
| 65 |
DivInstrument* ins; |
| 66 |
DivMacroStruct* macroList[128]; |
| 67 |
DivInstrumentMacro* macroSource[128]; |
| 68 |
size_t macroListLen; |
| 69 |
int subTick; |
| 70 |
bool released; |
| 71 |
public: |
| 72 |
// common macro |
| 73 |
DivMacroStruct vol; |
| 74 |
DivMacroStruct arp; |
| 75 |
DivMacroStruct duty, wave, pitch, ex1, ex2, ex3; |
| 76 |
DivMacroStruct alg, fb, fms, ams; |
| 77 |
DivMacroStruct panL, panR, phaseReset, ex4, ex5, ex6, ex7, ex8; |
| 78 |
DivMacroStruct ex9, ex10; |
| 79 |
|
| 80 |
// FM operator macro |
| 81 |
struct IntOp { |
| 82 |
DivMacroStruct am, ar, dr, mult; |
| 83 |
DivMacroStruct rr, sl, tl, dt2; |
| 84 |
DivMacroStruct rs, dt, d2r, ssg; |
| 85 |
DivMacroStruct dam, dvb, egt, ksl; |
| 86 |
DivMacroStruct sus, vib, ws, ksr; |
| 87 |
IntOp(): |
| 88 |
am(DIV_MACRO_OP_AM), |
| 89 |
ar(DIV_MACRO_OP_AR), |
| 90 |
dr(DIV_MACRO_OP_DR), |
| 91 |
mult(DIV_MACRO_OP_MULT), |
| 92 |
rr(DIV_MACRO_OP_RR), |
| 93 |
sl(DIV_MACRO_OP_SL), |
| 94 |
tl(DIV_MACRO_OP_TL), |
| 95 |
dt2(DIV_MACRO_OP_DT2), |
| 96 |
rs(DIV_MACRO_OP_RS), |
| 97 |
dt(DIV_MACRO_OP_DT), |
| 98 |
d2r(DIV_MACRO_OP_D2R), |
| 99 |
ssg(DIV_MACRO_OP_SSG), |
| 100 |
dam(DIV_MACRO_OP_DAM), |
| 101 |
dvb(DIV_MACRO_OP_DVB), |
| 102 |
egt(DIV_MACRO_OP_EGT), |
| 103 |
ksl(DIV_MACRO_OP_KSL), |
| 104 |
sus(DIV_MACRO_OP_SUS), |
| 105 |
vib(DIV_MACRO_OP_VIB), |
| 106 |
ws(DIV_MACRO_OP_WS), |
| 107 |
ksr(DIV_MACRO_OP_KSR) {} |
| 108 |
} op[4]; |
| 109 |
|
| 110 |
// state |
| 111 |
bool hasRelease; |
| 112 |
|
| 113 |
/** |
| 114 |
* set mask on macro. |
| 115 |
*/ |
| 116 |
void mask(unsigned char id, bool enabled); |
| 117 |
|
| 118 |
/** |
| 119 |
* trigger macro release. |
| 120 |
*/ |
| 121 |
void release(); |
| 122 |
|
| 123 |
/** |
| 124 |
* restart macro. |
| 125 |
*/ |
| 126 |
void restart(unsigned char id); |
| 127 |
|
| 128 |
/** |
| 129 |
* trigger next macro tick. |
| 130 |
*/ |
| 131 |
void next(); |
| 132 |
|
| 133 |
/** |
| 134 |
* set the engine. |
| 135 |
* @param the engine |
| 136 |
*/ |
| 137 |
void setEngine(DivEngine* eng); |
| 138 |
|
| 139 |
/** |
| 140 |
* initialize the macro interpreter. |
| 141 |
* @param which an instrument, or NULL. |
| 142 |
*/ |
| 143 |
void init(DivInstrument* which); |
| 144 |
|
| 145 |
/** |
| 146 |
* notify this macro interpreter that an instrument has been deleted. |
| 147 |
* @param which the instrument in question. |
| 148 |
*/ |
| 149 |
void notifyInsDeletion(DivInstrument* which); |
| 150 |
|
| 151 |
/** |
| 152 |
* get DivMacroStruct by macro type. |
| 153 |
* @param which the macro type. |
| 154 |
* @return a DivMacroStruct, or NULL if none found. |
| 155 |
*/ |
| 156 |
DivMacroStruct* structByType(unsigned char which); |
| 157 |
|
| 158 |
DivMacroInt(): |
| 159 |
e(NULL), |
| 160 |
ins(NULL), |
| 161 |
macroListLen(0), |
| 162 |
subTick(1), |
| 163 |
released(false), |
| 164 |
vol(DIV_MACRO_VOL), |
| 165 |
arp(DIV_MACRO_ARP), |
| 166 |
duty(DIV_MACRO_DUTY), |
| 167 |
wave(DIV_MACRO_WAVE), |
| 168 |
pitch(DIV_MACRO_PITCH), |
| 169 |
ex1(DIV_MACRO_EX1), |
| 170 |
ex2(DIV_MACRO_EX2), |
| 171 |
ex3(DIV_MACRO_EX3), |
| 172 |
alg(DIV_MACRO_ALG), |
| 173 |
fb(DIV_MACRO_FB), |
| 174 |
fms(DIV_MACRO_FMS), |
| 175 |
ams(DIV_MACRO_AMS), |
| 176 |
panL(DIV_MACRO_PAN_LEFT), |
| 177 |
panR(DIV_MACRO_PAN_RIGHT), |
| 178 |
phaseReset(DIV_MACRO_PHASE_RESET), |
| 179 |
ex4(DIV_MACRO_EX4), |
| 180 |
ex5(DIV_MACRO_EX5), |
| 181 |
ex6(DIV_MACRO_EX6), |
| 182 |
ex7(DIV_MACRO_EX7), |
| 183 |
ex8(DIV_MACRO_EX8), |
| 184 |
ex9(DIV_MACRO_EX9), |
| 185 |
ex10(DIV_MACRO_EX10), |
| 186 |
hasRelease(false) { |
| 187 |
memset(macroList,0,128*sizeof(void*)); |
| 188 |
memset(macroSource,0,128*sizeof(void*)); |
| 189 |
} |
| 190 |
}; |
| 191 |
|
| 192 |
#endif |