furnace/src/engine/macroInt.h

190 lines
4.7 KiB
C
Raw Normal View History

2022-02-14 22:12:20 -05:00
/**
* Furnace Tracker - multi-system chiptune tracker
2024-01-16 21:26:57 -05:00
* Copyright (C) 2021-2024 tildearrow and contributors
2022-02-14 22:12:20 -05:00
*
* 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 _MACROINT_H
#define _MACROINT_H
#include "instrument.h"
2022-04-10 01:01:55 -04:00
class DivEngine;
2022-04-10 01:01:55 -04:00
struct DivMacroStruct {
2022-10-07 15:17:25 -04:00
int pos, lastPos, lfoPos, delay;
2022-04-10 01:01:55 -04:00
int val;
bool has, had, actualHad, finished, will, linger, began, masked, activeRelease;
2022-10-07 05:11:45 -04:00
unsigned int mode, type;
2023-10-06 00:51:34 -04:00
unsigned char macroType;
2022-04-15 15:38:25 -04:00
void doMacro(DivInstrumentMacro& source, bool released, bool tick);
2022-04-10 01:01:55 -04:00
void init() {
2022-10-07 15:17:25 -04:00
pos=lastPos=lfoPos=mode=type=delay=0;
2022-04-15 15:38:25 -04:00
has=had=actualHad=will=false;
linger=false;
2022-08-22 04:52:32 -04:00
began=true;
2022-04-15 04:37:16 -04:00
// TODO: test whether this breaks anything?
val=0;
2022-04-10 01:01:55 -04:00
}
void prepare(DivInstrumentMacro& source, DivEngine* e);
2023-10-06 00:51:34 -04:00
DivMacroStruct(unsigned char mType):
2022-04-10 01:01:55 -04:00
pos(0),
2022-08-22 04:52:32 -04:00
lastPos(0),
2022-10-07 15:17:25 -04:00
lfoPos(0),
2022-08-22 04:52:32 -04:00
delay(0),
2022-04-10 01:01:55 -04:00
val(0),
has(false),
had(false),
2022-04-15 15:38:25 -04:00
actualHad(false),
2022-04-10 01:01:55 -04:00
finished(false),
will(false),
linger(false),
began(true),
2022-12-17 00:09:56 -05:00
masked(false),
activeRelease(false),
2022-10-07 05:11:45 -04:00
mode(0),
2023-10-06 00:51:34 -04:00
type(0),
macroType(mType) {}
2022-04-10 01:01:55 -04:00
};
class DivMacroInt {
DivEngine* e;
DivInstrument* ins;
2022-04-10 19:07:30 -04:00
DivMacroStruct* macroList[128];
DivInstrumentMacro* macroSource[128];
size_t macroListLen;
int subTick;
bool released;
public:
2022-04-10 01:01:55 -04:00
// common macro
DivMacroStruct vol;
DivMacroStruct arp;
DivMacroStruct duty, wave, pitch, ex1, ex2, ex3;
2022-04-10 17:52:03 -04:00
DivMacroStruct alg, fb, fms, ams;
2022-04-10 01:01:55 -04:00
DivMacroStruct panL, panR, phaseReset, ex4, ex5, ex6, ex7, ex8;
// FM operator macro
struct IntOp {
2022-04-10 01:01:55 -04:00
DivMacroStruct am, ar, dr, mult;
DivMacroStruct rr, sl, tl, dt2;
DivMacroStruct rs, dt, d2r, ssg;
DivMacroStruct dam, dvb, egt, ksl;
DivMacroStruct sus, vib, ws, ksr;
IntOp():
2023-10-06 00:51:34 -04:00
am(DIV_MACRO_OP_AM),
ar(DIV_MACRO_OP_AR),
dr(DIV_MACRO_OP_DR),
mult(DIV_MACRO_OP_MULT),
rr(DIV_MACRO_OP_RR),
sl(DIV_MACRO_OP_SL),
tl(DIV_MACRO_OP_TL),
dt2(DIV_MACRO_OP_DT2),
rs(DIV_MACRO_OP_RS),
dt(DIV_MACRO_OP_DT),
d2r(DIV_MACRO_OP_D2R),
ssg(DIV_MACRO_OP_SSG),
dam(DIV_MACRO_OP_DAM),
dvb(DIV_MACRO_OP_DVB),
egt(DIV_MACRO_OP_EGT),
ksl(DIV_MACRO_OP_KSL),
sus(DIV_MACRO_OP_SUS),
vib(DIV_MACRO_OP_VIB),
ws(DIV_MACRO_OP_WS),
ksr(DIV_MACRO_OP_KSR) {}
} op[4];
2022-03-15 23:05:55 -04:00
2022-06-05 17:24:12 -04:00
// state
bool hasRelease;
2022-12-17 00:09:56 -05:00
/**
* set mask on macro.
*/
void mask(unsigned char id, bool enabled);
2022-03-15 23:05:55 -04:00
/**
* trigger macro release.
*/
void release();
2022-03-15 23:05:55 -04:00
2024-01-17 07:28:29 -05:00
/**
* restart macro.
2024-01-17 07:28:29 -05:00
*/
void restart(unsigned char id);
2024-01-17 07:28:29 -05:00
2022-03-15 23:05:55 -04:00
/**
* trigger next macro tick.
*/
void next();
2022-03-15 23:05:55 -04:00
/**
* set the engine.
* @param the engine
*/
void setEngine(DivEngine* eng);
2022-03-15 23:05:55 -04:00
/**
* initialize the macro interpreter.
* @param which an instrument, or NULL.
*/
void init(DivInstrument* which);
2022-03-15 23:05:55 -04:00
/**
* notify this macro interpreter that an instrument has been deleted.
* @param which the instrument in question.
*/
void notifyInsDeletion(DivInstrument* which);
2022-03-15 23:05:55 -04:00
/**
2023-10-06 00:51:34 -04:00
* get DivMacroStruct by macro type.
* @param which the macro type.
* @return a DivMacroStruct, or NULL if none found.
*/
2023-10-06 00:51:34 -04:00
DivMacroStruct* structByType(unsigned char which);
DivMacroInt():
e(NULL),
ins(NULL),
2022-04-10 19:07:30 -04:00
macroListLen(0),
2022-04-15 15:38:25 -04:00
subTick(1),
released(false),
2023-10-06 00:51:34 -04:00
vol(DIV_MACRO_VOL),
arp(DIV_MACRO_ARP),
duty(DIV_MACRO_DUTY),
wave(DIV_MACRO_WAVE),
pitch(DIV_MACRO_PITCH),
ex1(DIV_MACRO_EX1),
ex2(DIV_MACRO_EX2),
ex3(DIV_MACRO_EX3),
alg(DIV_MACRO_ALG),
fb(DIV_MACRO_FB),
fms(DIV_MACRO_FMS),
ams(DIV_MACRO_AMS),
panL(DIV_MACRO_PAN_LEFT),
panR(DIV_MACRO_PAN_RIGHT),
phaseReset(DIV_MACRO_PHASE_RESET),
ex4(DIV_MACRO_EX4),
ex5(DIV_MACRO_EX5),
ex6(DIV_MACRO_EX6),
ex7(DIV_MACRO_EX7),
ex8(DIV_MACRO_EX8),
2022-06-05 17:24:12 -04:00
hasRelease(false) {
2022-04-10 19:07:30 -04:00
memset(macroList,0,128*sizeof(void*));
memset(macroSource,0,128*sizeof(void*));
}
};
#endif