| 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 _CHIP_UTILS_H |
| 21 |
#define _CHIP_UTILS_H |
| 22 |
|
| 23 |
#include "defines.h" |
| 24 |
#include "macroInt.h" |
| 25 |
|
| 26 |
// custom clock limits |
| 27 |
#define MIN_CUSTOM_CLOCK 100000 |
| 28 |
#define MAX_CUSTOM_CLOCK 40000000 |
| 29 |
|
| 30 |
// common shared channel struct |
| 31 |
template<typename T> struct SharedChannel { |
| 32 |
int freq, baseFreq, baseNoteOverride, pitch, pitch2, arpOff; |
| 33 |
int ins, note, sampleNote, sampleNoteDelta; |
| 34 |
bool active, insChanged, freqChanged, fixedArp, keyOn, keyOff, portaPause, inPorta; |
| 35 |
T vol, outVol; |
| 36 |
DivMacroInt std; |
| 37 |
void handleArp(int offset=0) { |
| 38 |
if (std.arp.had) { |
| 39 |
if (std.arp.val<0) { |
| 40 |
if (!(std.arp.val&0x40000000)) { |
| 41 |
baseNoteOverride=(std.arp.val|0x40000000)+offset; |
| 42 |
fixedArp=true; |
| 43 |
} else { |
| 44 |
arpOff=std.arp.val; |
| 45 |
fixedArp=false; |
| 46 |
} |
| 47 |
} else { |
| 48 |
if (std.arp.val&0x40000000) { |
| 49 |
baseNoteOverride=(std.arp.val&(~0x40000000))+offset; |
| 50 |
fixedArp=true; |
| 51 |
} else { |
| 52 |
arpOff=std.arp.val; |
| 53 |
fixedArp=false; |
| 54 |
} |
| 55 |
} |
| 56 |
freqChanged=true; |
| 57 |
} |
| 58 |
} |
| 59 |
void macroInit(DivInstrument* which) { |
| 60 |
std.init(which); |
| 61 |
pitch2=0; |
| 62 |
arpOff=0; |
| 63 |
baseNoteOverride=0; |
| 64 |
fixedArp=false; |
| 65 |
} |
| 66 |
SharedChannel(T initVol): |
| 67 |
freq(0), |
| 68 |
baseFreq(0), |
| 69 |
baseNoteOverride(0), |
| 70 |
pitch(0), |
| 71 |
pitch2(0), |
| 72 |
arpOff(0), |
| 73 |
ins(-1), |
| 74 |
note(0), |
| 75 |
sampleNote(DIV_NOTE_NULL), |
| 76 |
sampleNoteDelta(0), |
| 77 |
active(false), |
| 78 |
insChanged(true), |
| 79 |
freqChanged(false), |
| 80 |
fixedArp(false), |
| 81 |
keyOn(false), |
| 82 |
keyOff(false), |
| 83 |
portaPause(false), |
| 84 |
inPorta(false), |
| 85 |
vol(initVol), |
| 86 |
outVol(initVol), |
| 87 |
std() {} |
| 88 |
}; |
| 89 |
|
| 90 |
#endif |