Debian Codegraph @

src/engine/engine.h

raw
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 _ENGINE_H
21 #define _ENGINE_H
22 #include "config.h"
23 #include "instrument.h"
24 #include "song.h"
25 #include "dispatch.h"
26 #include "effect.h"
27 #include "export.h"
28 #include "dataErrors.h"
29 #include "safeWriter.h"
30 #include "cmdStream.h"
31 #include "../audio/taAudio.h"
32 #include "blip_buf.h"
33 #include <functional>
34 #include <initializer_list>
35 #include <thread>
36 #include "../fixedQueue.h"
37
38 class DivWorkPool;
39
40 #define addWarning(x) \
41 if (warnings.empty()) { \
42 warnings+=x; \
43 } else { \
44 warnings+=(String("\n")+x); \
45 }
46
47 #define BUSY_BEGIN softLocked=false; isBusy.lock();
48 #define BUSY_BEGIN_SOFT softLocked=true; isBusy.lock();
49 #define BUSY_END isBusy.unlock(); softLocked=false;
50
51 #define EXTERN_BUSY_BEGIN e->softLocked=false; e->isBusy.lock();
52 #define EXTERN_BUSY_BEGIN_SOFT e->softLocked=true; e->isBusy.lock();
53 #define EXTERN_BUSY_END e->isBusy.unlock(); e->softLocked=false;
54
55 #define DIV_UNSTABLE
56
57 #define DIV_VERSION "dev233"
58 #define DIV_ENGINE_VERSION 233
59 // for imports
60 #define DIV_VERSION_MOD 0xff01
61 #define DIV_VERSION_FC 0xff02
62 #define DIV_VERSION_S3M 0xff03
63 #define DIV_VERSION_FTM 0xff04
64 #define DIV_VERSION_TFE 0xff05
65 #define DIV_VERSION_XM 0xff06
66 #define DIV_VERSION_IT 0xff07
67
68 enum DivStatusView {
69 DIV_STATUS_NOTHING=0,
70 DIV_STATUS_PATTERN,
71 DIV_STATUS_COMMANDS
72 };
73
74 enum DivAudioEngines {
75 DIV_AUDIO_JACK=0,
76 DIV_AUDIO_SDL=1,
77 DIV_AUDIO_PORTAUDIO=2,
78 DIV_AUDIO_PIPE=3,
79
80 DIV_AUDIO_NULL=126,
81 DIV_AUDIO_DUMMY=127
82 };
83
84 enum DivAudioExportModes {
85 DIV_EXPORT_MODE_ONE=0,
86 DIV_EXPORT_MODE_MANY_SYS,
87 DIV_EXPORT_MODE_MANY_CHAN
88 };
89
90 enum DivHaltPositions {
91 DIV_HALT_NONE=0,
92 DIV_HALT_TICK,
93 DIV_HALT_ROW,
94 DIV_HALT_PATTERN,
95 DIV_HALT_BREAKPOINT
96 };
97
98 enum DivMIDIModes {
99 DIV_MIDI_MODE_OFF=0,
100 DIV_MIDI_MODE_NOTE,
101 DIV_MIDI_MODE_LIGHT_SHOW
102 };
103
104 enum DivAudioExportFormats {
105 DIV_EXPORT_FORMAT_S16=0,
106 DIV_EXPORT_FORMAT_F32
107 };
108
109 struct DivAudioExportOptions {
110 DivAudioExportModes mode;
111 DivAudioExportFormats format;
112 int sampleRate;
113 int chans;
114 int loops;
115 double fadeOut;
116 int orderBegin, orderEnd;
117 bool channelMask[DIV_MAX_CHANS];
118 DivAudioExportOptions():
119 mode(DIV_EXPORT_MODE_ONE),
120 format(DIV_EXPORT_FORMAT_S16),
121 sampleRate(44100),
122 chans(2),
123 loops(0),
124 fadeOut(0.0),
125 orderBegin(-1),
126 orderEnd(-1) {
127 for (int i=0; i<DIV_MAX_CHANS; i++) {
128 channelMask[i]=true;
129 }
130 }
131 };
132
133 struct DivChannelState {
134 std::vector<DivDelayedCommand> delayed;
135 int note, oldNote, lastIns, pitch, portaSpeed, portaNote;
136 int volume, volSpeed, volSpeedTarget, cut, volCut, legatoDelay, legatoTarget, rowDelay, volMax;
137 int delayOrder, delayRow, retrigSpeed, retrigTick;
138 int vibratoDepth, vibratoRate, vibratoPos, vibratoPosGiant, vibratoShape, vibratoFine;
139 int tremoloDepth, tremoloRate, tremoloPos;
140 int panDepth, panRate, panPos, panSpeed;
141 int sampleOff;
142 unsigned char arp, arpStage, arpTicks, panL, panR, panRL, panRR, lastVibrato, lastPorta, cutType;
143 bool doNote, legato, portaStop, keyOn, keyOff, nowYouCanStop, stopOnOff, releasing;
144 bool arpYield, delayLocked, inPorta, scheduledSlideReset, shorthandPorta, wasShorthandPorta, noteOnInhibit, resetArp, sampleOffSet;
145 bool wentThroughNote, goneThroughNote;
146
147 int midiNote, curMidiNote, midiPitch;
148 size_t midiAge;
149 bool midiAftertouch;
150
151 DivChannelState():
152 note(-1),
153 oldNote(-1),
154 lastIns(-1),
155 pitch(0),
156 portaSpeed(-1),
157 portaNote(-1),
158 volume(0x7f00),
159 volSpeed(0),
160 volSpeedTarget(-1),
161 cut(-1),
162 volCut(-1),
163 legatoDelay(-1),
164 legatoTarget(0),
165 rowDelay(0),
166 volMax(0),
167 delayOrder(0),
168 delayRow(0),
169 retrigSpeed(0),
170 retrigTick(0),
171 vibratoDepth(0),
172 vibratoRate(0),
173 vibratoPos(0),
174 vibratoPosGiant(0),
175 vibratoShape(0),
176 vibratoFine(15),
177 tremoloDepth(0),
178 tremoloRate(0),
179 tremoloPos(0),
180 panDepth(0),
181 panRate(0),
182 panPos(0),
183 panSpeed(0),
184 sampleOff(0),
185 arp(0),
186 arpStage(-1),
187 arpTicks(1),
188 panL(255),
189 panR(255),
190 panRL(0),
191 panRR(0),
192 lastVibrato(0),
193 lastPorta(0),
194 cutType(0),
195 doNote(false),
196 legato(false),
197 portaStop(false),
198 keyOn(false),
199 keyOff(false),
200 nowYouCanStop(true),
201 stopOnOff(false),
202 releasing(false),
203 arpYield(false),
204 delayLocked(false),
205 inPorta(false),
206 scheduledSlideReset(false),
207 shorthandPorta(false),
208 wasShorthandPorta(false),
209 noteOnInhibit(false),
210 resetArp(false),
211 sampleOffSet(false),
212 wentThroughNote(false),
213 goneThroughNote(false),
214 midiNote(-1),
215 curMidiNote(-1),
216 midiPitch(-1),
217 midiAge(0),
218 midiAftertouch(false) {}
219 };
220
221 struct DivNoteEvent {
222 signed char channel;
223 short ins;
224 signed char note, volume;
225 bool on, nop, insChange, fromMIDI;
226 DivNoteEvent(int c, int i, int n, int v, bool o, bool ic=false, bool fm=false):
227 channel(c),
228 ins(i),
229 note(n),
230 volume(v),
231 on(o),
232 nop(false),
233 insChange(ic),
234 fromMIDI(fm) {}
235 DivNoteEvent():
236 channel(-1),
237 ins(0),
238 note(0),
239 volume(-1),
240 on(false),
241 nop(true),
242 insChange(false),
243 fromMIDI(false) {}
244 };
245
246 struct DivDispatchContainer {
247 DivDispatch* dispatch;
248 blip_buffer_t* bb[DIV_MAX_OUTPUTS];
249 size_t bbInLen, runtotal, runLeft, runPos, lastAvail;
250 int temp[DIV_MAX_OUTPUTS], prevSample[DIV_MAX_OUTPUTS];
251 short* bbInMapped[DIV_MAX_OUTPUTS];
252 short* bbIn[DIV_MAX_OUTPUTS];
253 short* bbOut[DIV_MAX_OUTPUTS];
254 bool lowQuality, dcOffCompensation, hiPass;
255 double rateMemory;
256
257 // used in multi-thread
258 int cycles;
259 unsigned int size;
260
261 void setRates(double gotRate);
262 void setQuality(bool lowQual, bool dcHiPass);
263 void grow(size_t size);
264 void acquire(size_t count);
265 void flush(size_t offset, size_t count);
266 void fillBuf(size_t runtotal, size_t offset, size_t size);
267 void clear();
268 void init(DivSystem sys, DivEngine* eng, int chanCount, double gotRate, const DivConfig& flags, bool isRender=false);
269 void quit();
270 DivDispatchContainer():
271 dispatch(NULL),
272 bbInLen(0),
273 runtotal(0),
274 runLeft(0),
275 runPos(0),
276 lastAvail(0),
277 lowQuality(false),
278 dcOffCompensation(false),
279 hiPass(true),
280 rateMemory(0.0),
281 cycles(0),
282 size(0) {
283 memset(bb,0,DIV_MAX_OUTPUTS*sizeof(blip_buffer_t*));
284 memset(temp,0,DIV_MAX_OUTPUTS*sizeof(int));
285 memset(prevSample,0,DIV_MAX_OUTPUTS*sizeof(int));
286 memset(bbIn,0,DIV_MAX_OUTPUTS*sizeof(short*));
287 memset(bbInMapped,0,DIV_MAX_OUTPUTS*sizeof(short*));
288 memset(bbOut,0,DIV_MAX_OUTPUTS*sizeof(short*));
289 }
290 };
291
292 struct DivEffectContainer {
293 DivEffect* effect;
294 float* in[DIV_MAX_OUTPUTS];
295 float* out[DIV_MAX_OUTPUTS];
296 size_t inLen, outLen;
297
298 void preAcquire(size_t count);
299 void acquire(size_t count);
300 bool init(DivEffectType effectType, DivEngine* eng, double rate, unsigned short version, const unsigned char* data, size_t len);
301 void quit();
302 DivEffectContainer():
303 effect(NULL),
304 inLen(0),
305 outLen(0) {
306 memset(in,0,DIV_MAX_OUTPUTS*sizeof(float*));
307 memset(out,0,DIV_MAX_OUTPUTS*sizeof(float*));
308 }
309 };
310
311 typedef int EffectValConversion(unsigned char,unsigned char);
312
313 struct EffectHandler {
314 DivDispatchCmds dispatchCmd;
315 const char* description;
316 EffectValConversion* val;
317 EffectValConversion* val2;
318 EffectHandler(
319 DivDispatchCmds dispatchCmd_,
320 const char* description_,
321 EffectValConversion val_=NULL,
322 EffectValConversion val2_=NULL
323 ):
324 dispatchCmd(dispatchCmd_),
325 description(description_),
326 val(val_),
327 val2(val2_) {}
328 };
329
330 struct DivDoNotHandleEffect {
331 };
332
333 typedef std::unordered_map<unsigned char,const EffectHandler> EffectHandlerMap;
334
335 struct DivSysDef {
336 const char* name;
337 const char* nameJ;
338 const char* description;
339 unsigned char id;
340 unsigned char id_DMF;
341 int channels;
342 bool isFM, isSTD, isCompound;
343 // width 0: variable
344 // height 0: no wavetable support
345 unsigned short waveWidth, waveHeight;
346 unsigned int vgmVersion;
347 unsigned int sampleFormatMask;
348 const char* chanNames[DIV_MAX_CHANS];
349 const char* chanShortNames[DIV_MAX_CHANS];
350 int chanTypes[DIV_MAX_CHANS];
351 // 0: primary
352 // 1: alternate (usually PCM)
353 DivInstrumentType chanInsType[DIV_MAX_CHANS][2];
354 const EffectHandlerMap effectHandlers;
355 const EffectHandlerMap postEffectHandlers;
356 const EffectHandlerMap preEffectHandlers;
357 DivSysDef(
358 const char* sysName, const char* sysNameJ, unsigned char fileID, unsigned char fileID_DMF, int chans,
359 bool isFMChip, bool isSTDChip, unsigned int vgmVer, bool compound, unsigned int formatMask, unsigned short waveWid, unsigned short waveHei,
360 const char* desc,
361 std::initializer_list<const char*> chNames,
362 std::initializer_list<const char*> chShortNames,
363 std::initializer_list<int> chTypes,
364 std::initializer_list<DivInstrumentType> chInsType1,
365 std::initializer_list<DivInstrumentType> chInsType2={},
366 const EffectHandlerMap fxHandlers_={},
367 const EffectHandlerMap postFxHandlers_={},
368 const EffectHandlerMap preFxHandlers_={}):
369 name(sysName),
370 nameJ(sysNameJ),
371 description(desc),
372 id(fileID),
373 id_DMF(fileID_DMF),
374 channels(chans),
375 isFM(isFMChip),
376 isSTD(isSTDChip),
377 isCompound(compound),
378 waveWidth(waveWid),
379 waveHeight(waveHei),
380 vgmVersion(vgmVer),
381 sampleFormatMask(formatMask),
382 effectHandlers(fxHandlers_),
383 postEffectHandlers(postFxHandlers_),
384 preEffectHandlers(preFxHandlers_) {
385 memset(chanNames,0,DIV_MAX_CHANS*sizeof(void*));
386 memset(chanShortNames,0,DIV_MAX_CHANS*sizeof(void*));
387 memset(chanTypes,0,DIV_MAX_CHANS*sizeof(int));
388 for (int i=0; i<DIV_MAX_CHANS; i++) {
389 chanInsType[i][0]=DIV_INS_NULL;
390 chanInsType[i][1]=DIV_INS_NULL;
391 }
392
393 int index=0;
394 for (const char* i: chNames) {
395 chanNames[index++]=i;
396 if (index>=DIV_MAX_CHANS) break;
397 }
398
399 index=0;
400 for (const char* i: chShortNames) {
401 chanShortNames[index++]=i;
402 if (index>=DIV_MAX_CHANS) break;
403 }
404
405 index=0;
406 for (int i: chTypes) {
407 chanTypes[index++]=i;
408 if (index>=DIV_MAX_CHANS) break;
409 }
410
411 index=0;
412 for (DivInstrumentType i: chInsType1) {
413 chanInsType[index++][0]=i;
414 if (index>=DIV_MAX_CHANS) break;
415 }
416
417 index=0;
418 for (DivInstrumentType i: chInsType2) {
419 chanInsType[index++][1]=i;
420 if (index>=DIV_MAX_CHANS) break;
421 }
422 }
423 };
424
425 enum DivChanTypes {
426 DIV_CH_FM=0,
427 DIV_CH_PULSE=1,
428 DIV_CH_NOISE=2,
429 DIV_CH_WAVE=3,
430 DIV_CH_PCM=4,
431 DIV_CH_OP=5
432 };
433
434 extern const char* cmdName[];
435
436 class DivEngine {
437 DivDispatchContainer disCont[DIV_MAX_CHIPS];
438 TAAudio* output;
439 TAAudioDesc want, got;
440 String exportPath;
441 std::thread* exportThread;
442 int chans;
443 bool configLoaded;
444 bool active;
445 bool lowQuality;
446 bool dcHiPass;
447 bool playing;
448 bool freelance;
449 bool shallStop, shallStopSched;
450 bool endOfSong;
451 bool consoleMode;
452 bool disableStatusOut;
453 bool extValuePresent;
454 bool repeatPattern;
455 bool metronome;
456 bool exporting;
457 bool stopExport;
458 bool halted;
459 bool forceMono;
460 bool clampSamples;
461 bool cmdStreamEnabled;
462 bool softLocked;
463 bool firstTick;
464 bool skipping;
465 bool midiIsDirect;
466 bool midiIsDirectProgram;
467 bool lowLatency;
468 bool systemsRegistered;
469 bool romExportsRegistered;
470 bool hasLoadedSomething;
471 bool midiOutClock;
472 bool midiOutTime;
473 bool midiOutProgramChange;
474 int midiOutMode;
475 int midiOutTimeRate;
476 float midiVolExp;
477 int softLockCount;
478 int subticks, ticks, curRow, curOrder, prevRow, prevOrder, remainingLoops, totalLoops, lastLoopPos, exportLoopCount, curExportChan, nextSpeed, prevSpeed, elapsedBars, elapsedBeats, curSpeed;
479 size_t curSubSongIndex;
480 size_t bufferPos;
481 double divider;
482 int cycles;
483 double clockDrift;
484 int midiClockCycles;
485 double midiClockDrift;
486 int midiTimeCycles;
487 double midiTimeDrift;
488 int stepPlay;
489 int changeOrd, changePos, totalSeconds, totalTicks, totalTicksR, curMidiClock, curMidiTime, totalCmds, lastCmds, cmdsPerSecond, globalPitch;
490 double totalTicksOff;
491 int curMidiTimePiece, curMidiTimeCode;
492 unsigned char extValue, pendingMetroTick;
493 DivGroovePattern speeds;
494 short virtualTempoN, virtualTempoD;
495 short tempoAccum;
496 DivStatusView view;
497 DivHaltPositions haltOn;
498 DivChannelState chan[DIV_MAX_CHANS];
499 DivAudioEngines audioEngine;
500 DivAudioExportModes exportMode;
501 DivAudioExportFormats exportFormat;
502 double exportFadeOut;
503 bool isFadingOut;
504 int exportOutputs;
505 bool exportChannelMask[DIV_MAX_CHANS];
506 DivConfig conf;
507 FixedQueue<DivNoteEvent,8192> pendingNotes;
508 // bitfield
509 unsigned char walked[8192];
510 bool isMuted[DIV_MAX_CHANS];
511 std::mutex isBusy, saveLock, playPosLock;
512 String configPath;
513 String configFile;
514 String lastError;
515 String warnings;
516 std::vector<String> audioDevs;
517 std::vector<String> midiIns;
518 std::vector<String> midiOuts;
519 std::vector<DivCommand> cmdStream;
520 std::vector<DivInstrumentType> possibleInsTypes;
521 std::vector<DivEffectContainer> effectInst;
522 std::vector<int> curChanMask;
523 static DivSysDef* sysDefs[DIV_MAX_CHIP_DEFS];
524 static DivSystem sysFileMapFur[DIV_MAX_CHIP_DEFS];
525 static DivSystem sysFileMapDMF[DIV_MAX_CHIP_DEFS];
526 static DivROMExportDef* romExportDefs[DIV_ROM_MAX];
527
528 DivCSPlayer* cmdStreamInt;
529
530 struct SamplePreview {
531 double rate;
532 int sample;
533 int wave;
534 int pos;
535 int pBegin, pEnd;
536 int rateMul, posSub;
537 bool dir;
538 SamplePreview():
539 rate(0.0),
540 sample(-1),
541 wave(-1),
542 pos(0),
543 pBegin(-1),
544 pEnd(-1),
545 rateMul(1),
546 posSub(0),
547 dir(false) {}
548 } sPreview;
549
550 short vibTable[64];
551 short tremTable[128];
552 int reversePitchTable[4096];
553 int pitchTable[4096];
554 short effectSlotMap[4096];
555 int midiBaseChan;
556 bool midiPoly;
557 bool midiDebug;
558 size_t midiAgeCounter;
559
560 blip_buffer_t* samp_bb;
561 size_t samp_bbInLen;
562 int samp_temp, samp_prevSample;
563 short* samp_bbIn;
564 short* samp_bbOut;
565 unsigned char* metroTick;
566 size_t metroTickLen;
567 float* metroBuf;
568 size_t metroBufLen;
569 float metroFreq, metroPos;
570 float metroAmp;
571 float metroVol;
572 float previewVol;
573
574 size_t totalProcessed;
575
576 unsigned int renderPoolThreads;
577 DivWorkPool* renderPool;
578
579 // MIDI stuff
580 std::function<int(const TAMidiMessage&)> midiCallback=[](const TAMidiMessage&) -> int {return -3;};
581
582 void processRowPre(int i);
583 void processRow(int i, bool afterDelay);
584 void nextOrder();
585 void nextRow();
586 void performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool* sampleDir, bool isSecond, int* pendingFreq, int* playingSample, int* setPos, unsigned int* sampleOff8, unsigned int* sampleLen8, size_t bankOffset, bool directStream, bool* sampleStoppable, bool dpcm07, DivDispatch** writeNES, int rateCorrection);
587 // returns true if end of song.
588 bool nextTick(bool noAccum=false, bool inhibitLowLat=false);
589 bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal);
590 bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal);
591 bool perSystemPreEffect(int ch, unsigned char effect, unsigned char effectVal);
592 void recalcChans();
593 void reset();
594 void playSub(bool preserveDrift, int goalRow=0);
595 void runMidiClock(int totalCycles=1);
596 void runMidiTime(int totalCycles=1);
597 bool shallSwitchCores();
598
599 void testFunction();
600
601 bool loadDMF(unsigned char* file, size_t len);
602 bool loadFur(unsigned char* file, size_t len, int variantID=0);
603 bool loadMod(unsigned char* file, size_t len);
604 bool loadS3M(unsigned char* file, size_t len);
605 bool loadXM(unsigned char* file, size_t len);
606 bool loadIT(unsigned char* file, size_t len);
607 bool loadFTM(unsigned char* file, size_t len, bool dnft, bool dnftSig, bool eft);
608 bool loadFC(unsigned char* file, size_t len);
609 bool loadTFMv1(unsigned char* file, size_t len);
610 bool loadTFMv2(unsigned char* file, size_t len);
611
612 void loadDMP(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
613 void loadTFI(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
614 void loadVGI(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
615 void loadS3I(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
616 void loadSBI(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
617 void loadOPLI(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
618 void loadOPNI(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
619 void loadY12(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
620 void loadBNK(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
621 void loadGYB(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
622 void loadOPM(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
623 void loadFF(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
624 void loadWOPL(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
625 void loadWOPN(SafeReader& reader, std::vector<DivInstrument*>& ret, String& stripPath);
626
627 //sample banks
628 void loadP(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
629 void loadPPC(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
630 void loadPPS(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
631 void loadPVI(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
632 void loadPDX(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
633 void loadPZI(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
634 void loadP86(SafeReader& reader, std::vector<DivSample*>& ret, String& stripPath);
635
636
637
638 int loadSampleROM(String path, ssize_t expectedSize, unsigned char*& ret);
639
640 bool initAudioBackend();
641 bool deinitAudioBackend(bool dueToSwitchMaster=false);
642
643 void registerSystems();
644 void registerROMExports();
645 void initSongWithDesc(const char* description, bool inBase64=true, bool oldVol=false);
646
647 void exchangeIns(int one, int two);
648 void exchangeWave(int one, int two);
649 void exchangeSample(int one, int two);
650
651 void swapChannels(int src, int dest);
652 void stompChannel(int ch);
653
654 // recalculate patchbay (UNSAFE)
655 void recalcPatchbay();
656
657 // change song (UNSAFE)
658 void changeSong(size_t songIndex);
659
660 void swapSystemUnsafe(int src, int dest, bool preserveOrder=true);
661
662 // move an asset
663 void moveAsset(std::vector<DivAssetDir>& dir, int before, int after);
664
665 // remove an asset
666 void removeAsset(std::vector<DivAssetDir>& dir, int entry);
667
668 // read/write asset dir
669 void putAssetDirData(SafeWriter* w, std::vector<DivAssetDir>& dir);
670 DivDataErrors readAssetDirData(SafeReader& reader, std::vector<DivAssetDir>& dir);
671
672 // add every export method here
673 friend class DivROMExport;
674 friend class DivExportAmigaValidation;
675 friend class DivExportSAPR;
676 friend class DivExportTiuna;
677 friend class DivExportZSM;
678 friend class DivExportiPod;
679 friend class DivExportGRUB;
680
681 public:
682 DivSong song;
683 DivOrders* curOrders;
684 DivChannelData* curPat;
685 DivSubSong* curSubSong;
686 DivInstrument* tempIns;
687 DivSystem sysOfChan[DIV_MAX_CHANS];
688 int dispatchOfChan[DIV_MAX_CHANS];
689 int dispatchChanOfChan[DIV_MAX_CHANS];
690 int dispatchFirstChan[DIV_MAX_CHANS];
691 bool keyHit[DIV_MAX_CHANS];
692 float* oscBuf[DIV_MAX_OUTPUTS];
693 float oscSize;
694 int oscReadPos, oscWritePos;
695 int tickMult;
696 int lastNBIns, lastNBOuts, lastNBSize;
697 std::atomic<size_t> processTime;
698
699 void runExportThread();
700 void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size);
701 DivInstrument* getIns(int index, DivInstrumentType fallbackType=DIV_INS_FM);
702 DivWavetable* getWave(int index);
703 DivSample* getSample(int index);
704 DivDispatch* getDispatch(int index);
705 // parse old system setup description
706 String decodeSysDesc(String desc);
707 // start fresh
708 void createNew(const char* description, String sysName, bool inBase64=true);
709 void createNewFromDefaults();
710 // load a file.
711 bool load(unsigned char* f, size_t length, const char* nameHint=NULL);
712 // play a binary command stream.
713 bool playStream(unsigned char* f, size_t length);
714 // get the playing stream.
715 DivCSPlayer* getStreamPlayer();
716 // destroy command stream player.
717 bool killStream();
718 // save as .dmf.
719 SafeWriter* saveDMF(unsigned char version);
720 // save as .fur.
721 // if notPrimary is true then the song will not be altered
722 SafeWriter* saveFur(bool notPrimary=false, bool newPatternFormat=true);
723 // return a ROM exporter.
724 DivROMExport* buildROM(DivROMExportOptions sys);
725 // dump to VGM.
726 // set trailingTicks to:
727 // - 0 to add one tick of trailing
728 // - x to add x+1 ticks of trailing
729 // - -1 to auto-determine trailing
730 // - -2 to add a whole loop of trailing
731 SafeWriter* saveVGM(bool* sysToExport=NULL, bool loop=true, int version=0x171, bool patternHints=false, bool directStream=false, int trailingTicks=-1, bool dpcm07=false, int correctedRate=44100);
732 // dump to TIunA.
733 SafeWriter* saveTiuna(const bool* sysToExport, const char* baseLabel, int firstBankSize, int otherBankSize);
734 // dump command stream.
735 SafeWriter* saveCommand(DivCSProgress* progress=NULL, DivCSOptions options=DivCSOptions());
736 // export to text
737 SafeWriter* saveText(bool separatePatterns=true);
738 // export to an audio file
739 bool saveAudio(const char* path, DivAudioExportOptions options);
740 // wait for audio export to finish
741 void waitAudioFile();
742 // stop audio file export
743 bool haltAudioFile();
744 // return back to playback cores if necessary
745 void finishAudioFile();
746 // notify instrument parameter change
747 void notifyInsChange(int ins);
748 // notify wavetable change
749 void notifyWaveChange(int wave);
750
751 // dispatch a command
752 int dispatchCmd(DivCommand c);
753
754 // get system IDs
755 static DivSystem systemFromFileFur(unsigned char val);
756 static unsigned char systemToFileFur(DivSystem val);
757 static DivSystem systemFromFileDMF(unsigned char val);
758 static unsigned char systemToFileDMF(DivSystem val);
759
760 // convert old flags
761 static void convertOldFlags(unsigned int oldFlags, DivConfig& newFlags, DivSystem sys);
762
763 // check whether an asset directory is complete (UNSAFE)
764 void checkAssetDir(std::vector<DivAssetDir>& dir, size_t entries);
765
766 // benchmark (returns time in seconds)
767 double benchmarkPlayback();
768 double benchmarkSeek();
769
770 // returns the minimum VGM version which may carry the specified system, or 0 if none.
771 int minVGMVersion(DivSystem which);
772
773 // determine and setup config dir
774 void initConfDir();
775
776 // save config
777 bool saveConf();
778
779 // load config
780 bool loadConf();
781
782 // get a config value
783 bool getConfBool(String key, bool fallback);
784 int getConfInt(String key, int fallback);
785 float getConfFloat(String key, float fallback);
786 double getConfDouble(String key, double fallback);
787 String getConfString(String key, String fallback);
788
789 // get config object
790 DivConfig& getConfObject();
791
792 // set a config value
793 void setConf(String key, bool value);
794 void setConf(String key, int value);
795 void setConf(String key, float value);
796 void setConf(String key, double value);
797 void setConf(String key, const char* value);
798 void setConf(String key, String value);
799
800 // get whether config value exists
801 bool hasConf(String key);
802
803 // reset all settings
804 void factoryReset();
805
806 // calculate base frequency/period
807 double calcBaseFreq(double clock, double divider, int note, bool period);
808
809 // calculate base frequency in f-num/block format
810 int calcBaseFreqFNumBlock(double clock, double divider, int note, int bits, int fixedBlock);
811
812 // calculate frequency/period
813 int calcFreq(int base, int pitch, int arp, bool arpFixed, bool period=false, int octave=0, int pitch2=0, double clock=1.0, double divider=1.0, int blockBits=0, int fixedBlock=0);
814
815 // calculate arpeggio
816 int calcArp(int note, int arp, int offset=0);
817
818 // convert panning formats
819 int convertPanSplitToLinear(unsigned int val, unsigned char bits, int range);
820 int convertPanSplitToLinearLR(unsigned char left, unsigned char right, int range);
821 unsigned int convertPanLinearToSplit(int val, unsigned char bits, int range);
822
823 // find song loop position
824 void walkSong(int& loopOrder, int& loopRow, int& loopEnd);
825
826 // find song length in rows (up to specified loop point), and find length of every order
827 void findSongLength(int loopOrder, int loopRow, double fadeoutLen, int& rowsForFadeout, bool& hasFFxx, std::vector<int>& orders, int& length);
828
829 // play (returns whether successful)
830 bool play();
831
832 // play to row (returns whether successful)
833 bool playToRow(int row);
834
835 // play by one row
836 void stepOne(int row);
837
838 // stop
839 void stop();
840
841 // reset playback state
842 void syncReset();
843
844 // get C-4 rate for samples
845 double getCenterRate();
846
847 // sample preview query
848 bool isPreviewingSample();
849 int getSamplePreviewSample();
850 int getSamplePreviewPos();
851 double getSamplePreviewRate();
852
853 // set sample preview volume (1.0 = 100%)
854 void setSamplePreviewVol(float vol);
855
856 // trigger sample preview
857 void previewSample(int sample, int note=-1, int pStart=-1, int pEnd=-1);
858 void stopSamplePreview();
859
860 // trigger wave preview
861 void previewWave(int wave, int note);
862 void stopWavePreview();
863
864 // trigger sample preview
865 void previewSampleNoLock(int sample, int note=-1, int pStart=-1, int pEnd=-1);
866 void stopSamplePreviewNoLock();
867
868 // trigger wave preview
869 void previewWaveNoLock(int wave, int note);
870 void stopWavePreviewNoLock();
871
872 // get config path
873 String getConfigPath();
874
875 // get sys channel count
876 int getChannelCount(DivSystem sys);
877
878 // get channel count
879 int getTotalChannelCount();
880
881 // get instrument types available for use
882 std::vector<DivInstrumentType>& getPossibleInsTypes();
883
884 // get effect description
885 const char* getEffectDesc(unsigned char effect, int chan, bool notNull=false);
886
887 // get channel type
888 // - 0: FM
889 // - 1: pulse
890 // - 2: noise
891 // - 3: wave/other
892 // - 4: PCM
893 // - 5: FM operator
894 int getChannelType(int ch);
895
896 // get preferred instrument type
897 DivInstrumentType getPreferInsType(int ch);
898
899 // get alternate instrument type
900 DivInstrumentType getPreferInsSecondType(int ch);
901
902 // get song system name
903 String getSongSystemLegacyName(DivSong& ds, bool isMultiSystemAcceptable=true);
904
905 // get sys name
906 const char* getSystemName(DivSystem sys);
907
908 // get japanese system name
909 const char* getSystemNameJ(DivSystem sys);
910
911 // get sys definition
912 const DivSysDef* getSystemDef(DivSystem sys);
913
914 // get ROM export definition
915 const DivROMExportDef* getROMExportDef(DivROMExportOptions opt);
916 // check whether ROM export option is viable for current song
917 bool isROMExportViable(DivROMExportOptions opt);
918
919 // convert sample rate format
920 int fileToDivRate(int frate);
921 int divToFileRate(int drate);
922
923 // get effective sample rate
924 int getEffectiveSampleRate(int rate);
925
926 // is FM system
927 bool isFMSystem(DivSystem sys);
928
929 // is STD system
930 bool isSTDSystem(DivSystem sys);
931
932 // is channel muted
933 bool isChannelMuted(int chan);
934
935 // toggle mute
936 void toggleMute(int chan);
937
938 // toggle solo
939 void toggleSolo(int chan);
940
941 // set mute status
942 void muteChannel(int chan, bool mute);
943
944 // unmute all
945 void unmuteAll();
946
947 // get channel name
948 const char* getChannelName(int chan);
949
950 // get channel short name
951 const char* getChannelShortName(int chan);
952
953 // get channel max volume
954 int getMaxVolumeChan(int chan);
955
956 // map MIDI velocity to volume
957 int mapVelocity(int ch, float vel);
958
959 // map volume to gain
960 float getGain(int ch, int vol);
961
962 // get current order
963 unsigned char getOrder();
964
965 // get current row
966 int getRow();
967
968 // synchronous get order/row
969 void getPlayPos(int& order, int& row);
970 void getPlayPosTick(int& order, int& row, int& tick, int& speed);
971
972 // get beat/bar
973 int getElapsedBars();
974 int getElapsedBeats();
975
976 // get current subsong
977 size_t getCurrentSubSong();
978
979 // get speeds
980 const DivGroovePattern& getSpeeds();
981
982 // get Hz
983 float getHz();
984
985 // get current Hz
986 float getCurHz();
987
988 // get virtual tempo
989 short getVirtualTempoN();
990 short getVirtualTempoD();
991
992 // tell engine about virtual tempo changes
993 void virtualTempoChanged();
994
995 // get time
996 int getTotalTicks(); // 1/1000000th of a second
997 int getTotalSeconds();
998
999 // get repeat pattern
1000 bool getRepeatPattern();
1001
1002 // set repeat pattern
1003 void setRepeatPattern(bool value);
1004
1005 // has ext value
1006 bool hasExtValue();
1007
1008 // get ext value
1009 unsigned char getExtValue();
1010
1011 // dump song info to stdout
1012 void dumpSongInfo();
1013
1014 // is playing
1015 bool isPlaying();
1016
1017 // is running
1018 bool isRunning();
1019
1020 // is stepping
1021 bool isStepping();
1022
1023 // is exporting
1024 bool isExporting();
1025
1026 // get how many loops is left
1027 void getLoopsLeft(int& loops);
1028
1029 // get how many loops in total export needs to do
1030 void getTotalLoops(int& loops);
1031
1032 // get current position in song
1033 void getCurSongPos(int& row, int& order);
1034
1035 // get how many files export needs to create
1036 void getTotalAudioFiles(int& files);
1037
1038 // get which file is processed right now (progress for e.g. per-channel export)
1039 void getCurFileIndex(int& file);
1040
1041 // get fadeout state
1042 bool getIsFadingOut();
1043
1044 // add instrument
1045 int addInstrument(int refChan=0, DivInstrumentType fallbackType=DIV_INS_STD);
1046
1047 // add instrument from pointer
1048 int addInstrumentPtr(DivInstrument* which);
1049
1050 // get instrument from file
1051 // if the returned vector is empty then there was an error.
1052 std::vector<DivInstrument*> instrumentFromFile(const char* path, bool loadAssets=true, bool readInsName=true);
1053
1054 // load temporary instrument
1055 void loadTempIns(DivInstrument* which);
1056
1057 // delete instrument
1058 void delInstrument(int index);
1059 void delInstrumentUnsafe(int index);
1060
1061 // add wavetable
1062 int addWave();
1063
1064 // add wavetable from pointer
1065 int addWavePtr(DivWavetable* which);
1066
1067 // get wavetable from file
1068 DivWavetable* waveFromFile(const char* path, bool loadRaw=true);
1069
1070 // delete wavetable
1071 void delWave(int index);
1072 void delWaveUnsafe(int index);
1073
1074 // add sample
1075 int addSample();
1076
1077 // add sample from pointer
1078 int addSamplePtr(DivSample* which);
1079
1080 // get sample from file
1081 //DivSample* sampleFromFile(const char* path);
1082 std::vector<DivSample*> sampleFromFile(const char* path);
1083
1084 // get raw sample
1085 DivSample* sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign, bool swapNibbles, int rate);
1086
1087 // delete sample
1088 void delSample(int index);
1089 void delSampleUnsafe(int index, bool render=true);
1090
1091 // add order
1092 void addOrder(int pos, bool duplicate, bool where);
1093
1094 // deep clone orders
1095 void deepCloneOrder(int pos, bool where);
1096
1097 // delete order
1098 void deleteOrder(int pos);
1099
1100 // move order up
1101 void moveOrderUp(int& pos);
1102
1103 // move order down
1104 void moveOrderDown(int& pos);
1105
1106 // move thing up
1107 bool moveInsUp(int which);
1108 bool moveWaveUp(int which);
1109 bool moveSampleUp(int which);
1110
1111 // move thing down
1112 bool moveInsDown(int which);
1113 bool moveWaveDown(int which);
1114 bool moveSampleDown(int which);
1115
1116 // swap things
1117 bool swapInstruments(int a, int b);
1118 bool swapWaves(int a, int b);
1119 bool swapSamples(int a, int b);
1120
1121 // automatic patchbay
1122 void autoPatchbay();
1123 void autoPatchbayP();
1124
1125 // connect in patchbay
1126 // returns false if connection already made
1127 bool patchConnect(unsigned int src, unsigned int dest);
1128
1129 // disconnect in patchbay
1130 // returns false if connection doesn't exist
1131 bool patchDisconnect(unsigned int src, unsigned int dest);
1132
1133 // disconnect all in patchbay
1134 void patchDisconnectAll(unsigned int portSet);
1135
1136 // play note
1137 void noteOn(int chan, int ins, int note, int vol=-1);
1138
1139 // stop note
1140 void noteOff(int chan);
1141
1142 // returns whether it could
1143 bool autoNoteOn(int chan, int ins, int note, int vol=-1);
1144 void autoNoteOff(int chan, int note, int vol=-1);
1145 void autoNoteOffAll();
1146
1147 // set whether autoNoteIn is mono or poly
1148 void setAutoNotePoly(bool poly);
1149
1150 // go to order
1151 void setOrder(unsigned char order);
1152
1153 // update system flags
1154 void updateSysFlags(int system, bool restart, bool render);
1155
1156 // set Hz
1157 void setSongRate(float hz);
1158
1159 // set remaining loops. -1 means loop forever.
1160 void setLoops(int loops);
1161
1162 // get channel state
1163 DivChannelState* getChanState(int chan);
1164
1165 // get dispatch channel state
1166 void* getDispatchChanState(int chan);
1167
1168 // get channel pairs
1169 void getChanPaired(int chan, std::vector<DivChannelPair>& ret);
1170
1171 // get channel mode hints
1172 DivChannelModeHints getChanModeHints(int chan);
1173
1174 // get register pool
1175 unsigned char* getRegisterPool(int sys, int& size, int& depth);
1176
1177 // get macro interpreter
1178 DivMacroInt* getMacroInt(int chan);
1179
1180 // get channel panning
1181 unsigned short getChanPan(int chan);
1182
1183 // get sample position
1184 DivSamplePos getSamplePos(int chan);
1185
1186 // get osc buffer
1187 DivDispatchOscBuffer* getOscBuffer(int chan);
1188
1189 // enable command stream dumping
1190 void enableCommandStream(bool enable);
1191
1192 // get command stream
1193 void getCommandStream(std::vector<DivCommand>& where);
1194
1195 // set the audio system.
1196 void setAudio(DivAudioEngines which);
1197
1198 // set the view mode.
1199 void setView(DivStatusView which);
1200
1201 // get available audio devices
1202 std::vector<String>& getAudioDevices();
1203
1204 // get available MIDI inputs
1205 std::vector<String>& getMidiIns();
1206
1207 // get available MIDI inputs
1208 std::vector<String>& getMidiOuts();
1209
1210 // rescan audio devices
1211 void rescanAudioDevices();
1212
1213 /** rescan midi devices */
1214 void rescanMidiDevices();
1215
1216 // set the console mode.
1217 void setConsoleMode(bool enable, bool statusOut=true);
1218
1219 // get metronome
1220 bool getMetronome();
1221
1222 // set metronome
1223 void setMetronome(bool enable);
1224
1225 // set metronome volume (1.0 = 100%)
1226 void setMetronomeVol(float vol);
1227
1228 // get buffer position
1229 int getBufferPos();
1230
1231 // halt now
1232 void halt();
1233
1234 // resume from halt
1235 void resume();
1236
1237 // halt on next something
1238 void haltWhen(DivHaltPositions when);
1239
1240 // is engine halted
1241 bool isHalted();
1242
1243 // get register cheatsheet
1244 const char** getRegisterSheet(int sys);
1245
1246 // load sample ROMs
1247 int loadSampleROMs();
1248
1249 // get the sample format mask
1250 unsigned int getSampleFormatMask();
1251
1252 // UNSAFE render samples - only execute when locked
1253 void renderSamples(int whichSample=-1);
1254
1255 // public render samples
1256 // values for whichSample
1257 // -2: don't render anything - just update chip sample memory
1258 // -1: render all samples
1259 // >=0: render specific sample
1260 void renderSamplesP(int whichSample=-1);
1261
1262 // public swap channels
1263 void swapChannelsP(int src, int dest);
1264
1265 // public change song
1266 void changeSongP(size_t index);
1267
1268 // add subsong
1269 int addSubSong();
1270
1271 // duplicate subsong
1272 int duplicateSubSong(int index);
1273
1274 // remove subsong
1275 bool removeSubSong(int index);
1276
1277 // move subsong
1278 void moveSubSongUp(size_t index);
1279 void moveSubSongDown(size_t index);
1280
1281 // clear all subsong data
1282 void clearSubSongs();
1283
1284 // optimize assets
1285 void delUnusedIns();
1286 void delUnusedWaves();
1287 void delUnusedSamples();
1288
1289 // change system
1290 bool changeSystem(int index, DivSystem which, bool preserveOrder=true);
1291
1292 // add system
1293 bool addSystem(DivSystem which);
1294
1295 // duplicate system
1296 bool duplicateSystem(int index, bool pat=true, bool end=false);
1297
1298 // remove system
1299 bool removeSystem(int index, bool preserveOrder=true);
1300
1301 // move system
1302 bool swapSystem(int src, int dest, bool preserveOrder=true);
1303
1304 // add effect
1305 bool addEffect(DivEffectType which);
1306
1307 // remove effect
1308 bool removeEffect(int index);
1309
1310 // write to register on system
1311 void poke(int sys, unsigned int addr, unsigned short val);
1312
1313 // write to register on system
1314 void poke(int sys, std::vector<DivRegWrite>& wlist);
1315
1316 // get last error
1317 String getLastError();
1318
1319 // get warnings
1320 String getWarnings();
1321
1322 // get debug info
1323 String getPlaybackDebugInfo();
1324
1325 // switch master
1326 bool switchMaster(bool full=false);
1327
1328 // set MIDI base channel
1329 void setMidiBaseChan(int chan);
1330
1331 // set MIDI direct channel map
1332 void setMidiDirect(bool value);
1333
1334 // set MIDI direct program change
1335 void setMidiDirectProgram(bool value);
1336
1337 // set MIDI volume curve exponent
1338 void setMidiVolExp(float value);
1339
1340 // set MIDI input callback
1341 // if the specified function returns -3, note feedback will be inhibited.
1342 void setMidiCallback(std::function<int(const TAMidiMessage&)> what);
1343
1344 // send MIDI message
1345 bool sendMidiMessage(TAMidiMessage& msg);
1346
1347 // enable MIDI debug
1348 void setMidiDebug(bool enable);
1349
1350 // perform secure/sync operation
1351 void synchronized(const std::function<void()>& what);
1352
1353 // perform secure/sync operation (soft)
1354 void synchronizedSoft(const std::function<void()>& what);
1355
1356 // perform secure/sync song operation
1357 void lockSave(const std::function<void()>& what);
1358
1359 // perform secure/sync song operation (and lock audio too)
1360 void lockEngine(const std::function<void()>& what);
1361
1362 // get audio desc want
1363 TAAudioDesc& getAudioDescWant();
1364
1365 // get audio desc
1366 TAAudioDesc& getAudioDescGot();
1367
1368 // init dispatch
1369 void initDispatch(bool isRender=false);
1370
1371 // quit dispatch
1372 void quitDispatch();
1373
1374 // pre-pre-initialize the engine.
1375 bool prePreInit();
1376
1377 // pre-initialize the engine. returns whether Furnace should run in safe mode.
1378 bool preInit(bool noSafeMode=true);
1379
1380 // initialize the engine.
1381 bool init();
1382
1383 // confirm that the engine is running (delete safe mode file).
1384 void everythingOK();
1385
1386 // terminate the engine.
1387 bool quit(bool saveConfig=true);
1388
1389 unsigned char* yrw801ROM;
1390 unsigned char* tg100ROM;
1391 unsigned char* mu5ROM;
1392
1393 DivEngine():
1394 output(NULL),
1395 exportThread(NULL),
1396 chans(0),
1397 configLoaded(false),
1398 active(false),
1399 lowQuality(false),
1400 dcHiPass(true),
1401 playing(false),
1402 freelance(false),
1403 shallStop(false),
1404 shallStopSched(false),
1405 endOfSong(false),
1406 consoleMode(false),
1407 disableStatusOut(false),
1408 extValuePresent(false),
1409 repeatPattern(false),
1410 metronome(false),
1411 exporting(false),
1412 stopExport(false),
1413 halted(false),
1414 forceMono(false),
1415 cmdStreamEnabled(false),
1416 softLocked(false),
1417 firstTick(false),
1418 skipping(false),
1419 midiIsDirect(false),
1420 midiIsDirectProgram(false),
1421 lowLatency(false),
1422 systemsRegistered(false),
1423 romExportsRegistered(false),
1424 hasLoadedSomething(false),
1425 midiOutClock(false),
1426 midiOutTime(false),
1427 midiOutProgramChange(false),
1428 midiOutMode(DIV_MIDI_MODE_NOTE),
1429 midiOutTimeRate(0),
1430 midiVolExp(2.0f), // General MIDI standard
1431 softLockCount(0),
1432 subticks(0),
1433 ticks(0),
1434 curRow(0),
1435 curOrder(0),
1436 prevRow(0),
1437 prevOrder(0),
1438 remainingLoops(-1),
1439 totalLoops(0),
1440 lastLoopPos(0),
1441 exportLoopCount(0),
1442 curExportChan(0),
1443 nextSpeed(3),
1444 prevSpeed(6),
1445 elapsedBars(0),
1446 elapsedBeats(0),
1447 curSpeed(0),
1448 curSubSongIndex(0),
1449 bufferPos(0),
1450 divider(60),
1451 cycles(0),
1452 clockDrift(0),
1453 midiClockCycles(0),
1454 midiClockDrift(0),
1455 midiTimeCycles(0),
1456 midiTimeDrift(0),
1457 stepPlay(0),
1458 changeOrd(-1),
1459 changePos(0),
1460 totalSeconds(0),
1461 totalTicks(0),
1462 totalTicksR(0),
1463 curMidiClock(0),
1464 curMidiTime(0),
1465 totalCmds(0),
1466 lastCmds(0),
1467 cmdsPerSecond(0),
1468 globalPitch(0),
1469 totalTicksOff(0.0),
1470 curMidiTimePiece(0),
1471 curMidiTimeCode(0),
1472 extValue(0),
1473 pendingMetroTick(0),
1474 virtualTempoN(150),
1475 virtualTempoD(150),
1476 tempoAccum(0),
1477 view(DIV_STATUS_NOTHING),
1478 haltOn(DIV_HALT_NONE),
1479 audioEngine(DIV_AUDIO_NULL),
1480 exportMode(DIV_EXPORT_MODE_ONE),
1481 exportFormat(DIV_EXPORT_FORMAT_S16),
1482 exportFadeOut(0.0),
1483 isFadingOut(false),
1484 exportOutputs(2),
1485 cmdStreamInt(NULL),
1486 midiBaseChan(0),
1487 midiPoly(true),
1488 midiDebug(false),
1489 midiAgeCounter(0),
1490 samp_bb(NULL),
1491 samp_bbInLen(0),
1492 samp_temp(0),
1493 samp_prevSample(0),
1494 samp_bbIn(NULL),
1495 samp_bbOut(NULL),
1496 metroTick(NULL),
1497 metroTickLen(0),
1498 metroBuf(NULL),
1499 metroBufLen(0),
1500 metroFreq(0),
1501 metroPos(0),
1502 metroAmp(0.0f),
1503 metroVol(1.0f),
1504 previewVol(1.0f),
1505 totalProcessed(0),
1506 renderPoolThreads(0),
1507 renderPool(NULL),
1508 curOrders(NULL),
1509 curPat(NULL),
1510 tempIns(NULL),
1511 oscSize(1),
1512 oscReadPos(0),
1513 oscWritePos(0),
1514 tickMult(1),
1515 lastNBIns(0),
1516 lastNBOuts(0),
1517 lastNBSize(0),
1518 processTime(0),
1519 yrw801ROM(NULL),
1520 tg100ROM(NULL),
1521 mu5ROM(NULL) {
1522 memset(isMuted,0,DIV_MAX_CHANS*sizeof(bool));
1523 memset(keyHit,0,DIV_MAX_CHANS*sizeof(bool));
1524 memset(dispatchFirstChan,0,DIV_MAX_CHANS*sizeof(int));
1525 memset(dispatchChanOfChan,0,DIV_MAX_CHANS*sizeof(int));
1526 memset(dispatchOfChan,0,DIV_MAX_CHANS*sizeof(int));
1527 memset(sysOfChan,0,DIV_MAX_CHANS*sizeof(int));
1528 memset(vibTable,0,64*sizeof(short));
1529 memset(tremTable,0,128*sizeof(short));
1530 memset(reversePitchTable,0,4096*sizeof(int));
1531 memset(pitchTable,0,4096*sizeof(int));
1532 memset(effectSlotMap,-1,4096*sizeof(short));
1533 memset(sysDefs,0,DIV_MAX_CHIP_DEFS*sizeof(void*));
1534 memset(romExportDefs,0,DIV_ROM_MAX*sizeof(void*));
1535 memset(walked,0,8192);
1536 memset(oscBuf,0,DIV_MAX_OUTPUTS*(sizeof(float*)));
1537 memset(exportChannelMask,1,DIV_MAX_CHANS*sizeof(bool));
1538
1539 for (int i=0; i<DIV_MAX_CHIP_DEFS; i++) {
1540 sysFileMapFur[i]=DIV_SYSTEM_NULL;
1541 sysFileMapDMF[i]=DIV_SYSTEM_NULL;
1542 }
1543
1544 changeSong(0);
1545 }
1546 };
1547 #endif