furnace/src/engine/dispatch.h

265 lines
5.6 KiB
C
Raw Normal View History

#ifndef _DISPATCH_H
#define _DISPATCH_H
2021-12-06 21:12:16 -05:00
#include <stdlib.h>
2022-01-16 23:21:27 -05:00
#include <vector>
#define ONE_SEMITONE 2200
2022-01-17 13:29:35 -05:00
#define addWrite(a,v) regWrites.push_back(DivRegWrite(a,v));
enum DivDispatchCmds {
DIV_CMD_NOTE_ON=0,
DIV_CMD_NOTE_OFF,
DIV_CMD_INSTRUMENT,
DIV_CMD_VOLUME,
DIV_CMD_GET_VOLUME,
DIV_CMD_GET_VOLMAX,
2021-05-14 04:23:40 -04:00
DIV_CMD_NOTE_PORTA,
DIV_CMD_PITCH,
DIV_CMD_PANNING,
DIV_CMD_LEGATO,
2021-05-17 02:51:14 -04:00
DIV_CMD_PRE_PORTA,
DIV_CMD_PRE_NOTE, // used in C64
DIV_CMD_SAMPLE_MODE,
2021-12-08 18:29:50 -05:00
DIV_CMD_SAMPLE_FREQ,
2021-12-09 03:13:37 -05:00
DIV_CMD_SAMPLE_BANK,
2021-06-06 00:27:02 -04:00
DIV_CMD_FM_LFO,
DIV_CMD_FM_LFO_WAVE,
DIV_CMD_FM_TL,
DIV_CMD_FM_AR,
DIV_CMD_FM_FB,
DIV_CMD_FM_MULT,
DIV_CMD_FM_EXTCH,
DIV_CMD_GENESIS_LFO,
DIV_CMD_ARCADE_LFO,
DIV_CMD_STD_NOISE_FREQ,
DIV_CMD_STD_NOISE_MODE,
DIV_CMD_WAVE,
DIV_CMD_GB_SWEEP_TIME,
DIV_CMD_GB_SWEEP_DIR,
2021-06-09 02:08:42 -04:00
DIV_CMD_PCE_LFO_MODE,
DIV_CMD_PCE_LFO_SPEED,
DIV_CMD_C64_CUTOFF,
DIV_CMD_C64_RESONANCE,
DIV_CMD_C64_FILTER_MODE,
DIV_CMD_C64_RESET_TIME,
DIV_CMD_C64_RESET_MASK,
DIV_CMD_C64_FILTER_RESET,
DIV_CMD_C64_DUTY_RESET,
DIV_CMD_C64_EXTENDED,
DIV_CMD_C64_FINE_DUTY,
DIV_CMD_C64_FINE_CUTOFF,
2021-12-09 17:06:28 -05:00
DIV_CMD_AY_ENVELOPE_SET,
DIV_CMD_AY_ENVELOPE_LOW,
DIV_CMD_AY_ENVELOPE_HIGH,
DIV_CMD_AY_ENVELOPE_SLIDE,
2021-12-09 17:06:28 -05:00
2022-01-14 23:26:22 -05:00
DIV_CMD_SAA_ENVELOPE,
DIV_ALWAYS_SET_VOLUME,
DIV_CMD_MAX
};
struct DivCommand {
DivDispatchCmds cmd;
2022-01-08 16:03:32 -05:00
unsigned char chan, dis;
int value, value2;
DivCommand(DivDispatchCmds c, unsigned char ch, int val, int val2):
cmd(c),
chan(ch),
2022-01-08 16:03:32 -05:00
dis(ch),
value(val),
value2(val2) {}
DivCommand(DivDispatchCmds c, unsigned char ch, int val):
cmd(c),
chan(ch),
2022-01-08 16:03:32 -05:00
dis(ch),
value(val),
value2(0) {}
DivCommand(DivDispatchCmds c, unsigned char ch):
cmd(c),
chan(ch),
2022-01-08 16:03:32 -05:00
dis(ch),
value(0),
value2(0) {}
};
struct DivDelayedCommand {
int ticks;
DivCommand cmd;
};
2022-01-16 23:21:27 -05:00
struct DivRegWrite {
/**
* an address of 0xffffff00 indicates a Furnace specific command.
* the following addresses are available:
* - 0xffffff00: start sample playback
* - data is the sample number
*/
unsigned int addr;
unsigned char val;
2022-01-17 13:29:35 -05:00
DivRegWrite(unsigned int a, unsigned char v):
addr(a), val(v) {}
2022-01-16 23:21:27 -05:00
};
class DivEngine;
class DivDispatch {
protected:
DivEngine* parent;
2022-01-16 23:21:27 -05:00
std::vector<DivRegWrite> regWrites;
/**
2022-01-16 23:21:27 -05:00
* please honor these variables if needed.
*/
2022-01-16 23:21:27 -05:00
bool skipRegisterWrites, dumpWrites;
public:
/**
* the rate the samples are provided.
* the engine shall resample to the output rate.
*/
int rate;
2021-12-18 03:25:42 -05:00
/**
* fill a buffer with sound data.
* @param bufL the left or mono channel buffer.
* @param bufR the right channel buffer.
* @param start the start offset.
* @param len the amount of samples to fill.
*/
virtual void acquire(short* bufL, short* bufR, size_t start, size_t len);
2021-12-18 03:25:42 -05:00
/**
* send a command to this dispatch.
* @param c a DivCommand.
* @return a return value which varies depending on the command.
*/
virtual int dispatch(DivCommand c);
2021-12-18 03:25:42 -05:00
/**
* reset the state of this dispatch.
*/
2021-12-11 03:34:43 -05:00
virtual void reset();
2021-12-18 03:25:42 -05:00
/**
* ticks this dispatch.
*/
virtual void tick();
2021-12-18 03:25:42 -05:00
/**
* get this dispatch's state.
* @return a pointer to the dispatch's state. must be deallocated manually!
*/
virtual void* getState();
/**
* set this dispatch's state.
* @param state a pointer to a state pertaining to this dispatch,
* or NULL if this dispatch does not support state saves.
*/
virtual void setState(void* state);
/**
* mute a channel.
* @param ch the channel to mute.
* @param mute whether to mute or unmute.
*/
virtual void muteChannel(int ch, bool mute);
/**
* test whether this dispatch outputs audio in two channels.
* @return whether it does.
*/
virtual bool isStereo();
2021-12-18 03:25:42 -05:00
/**
* test whether sending a key off command to a channel should reset arp too.
* @param ch the channel in question.
* @return whether it does.
*/
2021-12-08 00:33:00 -05:00
virtual bool keyOffAffectsArp(int ch);
2021-12-18 03:25:42 -05:00
/**
* test whether sending a key off command to a channel should reset slides too.
* @param ch the channel in question.
* @return whether it does.
*/
virtual bool keyOffAffectsPorta(int ch);
/**
* get the lowest note in a portamento.
* @param ch the channel in question.
* @return the lowest note.
*/
virtual int getPortaFloor(int ch);
2021-12-18 03:25:42 -05:00
/**
* set the region to PAL.
* @param pal whether to set it to PAL.
*/
2021-12-15 17:32:08 -05:00
virtual void setPAL(bool pal);
/**
* set skip reg writes.
*/
void setSkipRegisterWrites(bool value);
2022-01-17 23:59:52 -05:00
/**
* notify instrument change.
*/
virtual void notifyInsChange(int ins);
2022-01-18 00:25:10 -05:00
/**
* notify wavetable change.
*/
virtual void notifyWaveChange(int wave);
2022-01-13 17:40:29 -05:00
/**
* notify deletion of an instrument.
*/
virtual void notifyInsDeletion(void* ins);
/**
* force-retrigger instruments.
*/
virtual void forceIns();
2022-01-16 23:21:27 -05:00
/**
* enable register dumping.
*/
void toggleRegisterDump(bool enable);
/**
* get register writes.
*/
std::vector<DivRegWrite>& getRegisterWrites();
/**
* initialize this DivDispatch.
* @param parent the parent DivEngine.
* @param channels the number of channels to acquire.
* @param sugRate the suggested rate. this may change, so don't rely on it.
* @return the number of channels allocated.
*/
virtual int init(DivEngine* parent, int channels, int sugRate, bool pal);
/**
* quit the DivDispatch.
*/
virtual void quit();
virtual ~DivDispatch();
};
#endif