| 1 | #pragma once |
| 2 | |
| 3 | #ifdef _WIN32 |
| 4 | #define WIN32_MEAN_AND_LEAN |
| 5 | #include <windows.h> |
| 6 | #endif |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | #include <stdbool.h> |
| 10 | #include "pt2_header.h" |
| 11 | #include "pt2_hpc.h" |
| 12 | #include "pt2_paula.h" |
| 13 | |
| 14 | // for .WAV sample loading/saving |
| 15 | typedef struct wavHeader_t |
| 16 | { |
| 17 | uint32_t chunkID, chunkSize, format, subchunk1ID, subchunk1Size; |
| 18 | uint16_t audioFormat, numChannels; |
| 19 | uint32_t sampleRate, byteRate; |
| 20 | uint16_t blockAlign, bitsPerSample; |
| 21 | uint32_t subchunk2ID, subchunk2Size; |
| 22 | } wavHeader_t; |
| 23 | |
| 24 | typedef struct sampleLoop_t |
| 25 | { |
| 26 | uint32_t dwIdentifier, dwType, dwStart; |
| 27 | uint32_t dwEnd, dwFraction, dwPlayCount; |
| 28 | } sampleLoop_t; |
| 29 | |
| 30 | typedef struct samplerChunk_t |
| 31 | { |
| 32 | uint32_t chunkID, chunkSize, dwManufacturer, dwProduct; |
| 33 | uint32_t dwSamplePeriod, dwMIDIUnityNote, wMIDIPitchFraction; |
| 34 | uint32_t dwSMPTEFormat, dwSMPTEOffset, cSampleLoops, cbSamplerData; |
| 35 | sampleLoop_t loop; |
| 36 | } samplerChunk_t; |
| 37 | |
| 38 | typedef struct mptExtraChunk_t |
| 39 | { |
| 40 | uint32_t chunkID, chunkSize, flags; |
| 41 | uint16_t defaultPan, defaultVolume, globalVolume, reserved; |
| 42 | uint8_t vibratoType, vibratoSweep, vibratoDepth, vibratoRate; |
| 43 | } mptExtraChunk_t; |
| 44 | // ----------------------------------------- |
| 45 | |
| 46 | typedef struct note_t |
| 47 | { |
| 48 | uint8_t param, sample, command; |
| 49 | uint16_t period; |
| 50 | } note_t; |
| 51 | |
| 52 | typedef struct moduleHeader_t |
| 53 | { |
| 54 | char name[20 + 1]; |
| 55 | uint16_t patternTable[128], songLength; |
| 56 | uint16_t initialTempo; // used for STK/UST modules after module is loaded |
| 57 | } moduleHeader_t; |
| 58 | |
| 59 | typedef struct moduleSample_t |
| 60 | { |
| 61 | volatile int8_t *volumeDisp; |
| 62 | volatile int32_t *lengthDisp, *loopStartDisp, *loopLengthDisp; |
| 63 | char text[22 + 1]; |
| 64 | int8_t volume; |
| 65 | uint8_t fineTune; |
| 66 | int32_t offset, length, loopStart, loopLength; |
| 67 | } moduleSample_t; |
| 68 | |
| 69 | typedef struct moduleChannel_t |
| 70 | { |
| 71 | int8_t *n_start, *n_wavestart, *n_loopstart, n_volume, n_dmabit; |
| 72 | int8_t n_toneportdirec, n_pattpos, n_loopcount; |
| 73 | uint8_t n_wavecontrol, n_glissfunk, n_sampleoffset, n_toneportspeed; |
| 74 | uint8_t n_vibratocmd, n_tremolocmd, n_finetune, n_funkoffset, n_samplenum; |
| 75 | uint8_t n_vibratopos, n_tremolopos; |
| 76 | int16_t n_period, n_note, n_wantedperiod; |
| 77 | uint16_t n_cmd, n_length, n_replen; |
| 78 | uint32_t n_scopedelta, n_chanindex; |
| 79 | |
| 80 | // for pt2_sync.c |
| 81 | uint8_t syncFlags; |
| 82 | int8_t syncAnalyzerVolume, syncVuVolume; |
| 83 | uint16_t syncAnalyzerPeriod; |
| 84 | } moduleChannel_t; |
| 85 | |
| 86 | typedef struct module_t |
| 87 | { |
| 88 | bool loaded, modified; |
| 89 | int8_t *sampleData; |
| 90 | |
| 91 | volatile int32_t tick, speed; |
| 92 | |
| 93 | int8_t row; // used for different things, so must not be internal to replayer |
| 94 | |
| 95 | moduleHeader_t header; |
| 96 | moduleSample_t samples[MOD_SAMPLES]; |
| 97 | moduleChannel_t channels[PAULA_VOICES]; |
| 98 | note_t *patterns[MAX_PATTERNS]; |
| 99 | |
| 100 | // for pattern viewer |
| 101 | int8_t currRow; |
| 102 | int32_t currSpeed, currBPM; |
| 103 | uint16_t currPos, currPattern; |
| 104 | |
| 105 | // for MOD2WAV progress bar |
| 106 | uint32_t rowsCounter, rowsInTotal; |
| 107 | } module_t; |
| 108 | |
| 109 | typedef struct keyb_t |
| 110 | { |
| 111 | bool repeatKey, delayKey; |
| 112 | bool shiftPressed, leftCtrlPressed, leftAltPressed; |
| 113 | bool leftCommandPressed, leftAmigaPressed, keypadEnterPressed; |
| 114 | uint8_t repeatCounter, delayCounter; |
| 115 | uint32_t repeatFrac; |
| 116 | SDL_Scancode lastRepKey, lastKey; |
| 117 | } keyb_t; |
| 118 | |
| 119 | typedef struct mouse_t |
| 120 | { |
| 121 | volatile bool setPosFlag, updatePointerColorFlag; |
| 122 | bool buttonWaiting, leftButtonPressed, rightButtonPressed; |
| 123 | uint8_t repeatCounter, buttonWaitCounter; |
| 124 | int32_t absX, absY, rawX, rawY, x, y, lastMouseX, setPosX, setPosY, lastGUIButton, prevX, prevY; |
| 125 | int32_t lastSmpFilterButton, lastSamplingButton; |
| 126 | uint32_t buttonState; |
| 127 | } mouse_t; |
| 128 | |
| 129 | typedef struct video_t |
| 130 | { |
| 131 | bool fullscreen, vsync60HzPresent, windowHidden, useCustomRenderRect, debug; |
| 132 | int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH; |
| 133 | uint32_t mouseCursorUpscaleFactor, *frameBuffer, palette[PALETTE_NUM]; |
| 134 | double dMonitorRefreshRate, dMouseXMul, dMouseYMul; |
| 135 | #ifdef _WIN32 |
| 136 | HWND hWnd; |
| 137 | #endif |
| 138 | hpc_t vblankHpc; |
| 139 | SDL_Window *window; |
| 140 | SDL_Rect renderRect; |
| 141 | SDL_Renderer *renderer; |
| 142 | SDL_Texture *texture; |
| 143 | } video_t; |
| 144 | |
| 145 | typedef struct editor_t |
| 146 | { |
| 147 | volatile uint8_t vuMeterVolumes[PAULA_VOICES], spectrumVolumes[SPECTRUM_BAR_NUM]; |
| 148 | volatile int8_t *sampleFromDisp, *sampleToDisp, *currSampleDisp, realVuMeterVolumes[PAULA_VOICES], mod2WavNumLoops, mod2WavFadeOutSeconds; |
| 149 | volatile bool songPlaying, programRunning, mod2WavOngoing, pat2SmpOngoing, mainLoopOngoing, abortMod2Wav, mod2WavFadeOut; |
| 150 | volatile uint16_t *quantizeValueDisp, *metroSpeedDisp, *metroChannelDisp, *sampleVolDisp; |
| 151 | volatile uint16_t *vol1Disp, *vol2Disp, *currEditPatternDisp, *currPosDisp, *currPatternDisp; |
| 152 | volatile uint16_t *currPosEdPattDisp, *currLengthDisp, *lpCutOffDisp, *hpCutOffDisp; |
| 153 | volatile int32_t *samplePosDisp, *chordLengthDisp; |
| 154 | |
| 155 | char mixText[16+1]; |
| 156 | char *entryNameTmp, *currPath, *dropTempFileName; |
| 157 | UNICHAR *fileNameTmpU, *currPathU, *modulesPathU, *samplesPathU; |
| 158 | |
| 159 | bool errorMsgActive, errorMsgBlock, multiFlag, metroFlag, keypadToggle8CFlag, normalizeFiltersFlag; |
| 160 | bool sampleAllFlag, halveSampleFlag, newOldFlag, pat2SmpHQ, mixFlag; |
| 161 | bool modLoaded, autoInsFlag, repeatKeyFlag, sampleZero, tuningToneFlag; |
| 162 | bool stepPlayEnabled, stepPlayBackwards, blockBufferFlag, blockMarkFlag, didQuantize; |
| 163 | bool swapChannelFlag, configFound, chordLengthMin, rowVisitTable[128 * MOD_ROWS]; |
| 164 | bool muted[PAULA_VOICES]; |
| 165 | |
| 166 | int8_t smpRedoFinetunes[MOD_SAMPLES], smpRedoVolumes[MOD_SAMPLES], multiModeNext[4], trackPattFlag; |
| 167 | int8_t *smpRedoBuffer[MOD_SAMPLES], currSample, recordMode, sampleFrom, sampleTo, autoInsSlot; |
| 168 | int8_t hiLowInstr, note1, note2, note3, note4, oldNote1, oldNote2, oldNote3, oldNote4, stepPlayLastMode; |
| 169 | uint8_t playMode, currMode, tuningChan, tuningVol, errorMsgCounter, buffFromPos, buffToPos; |
| 170 | uint8_t blockFromPos, blockToPos, timingMode, f6Pos, f7Pos, f8Pos, f9Pos, f10Pos, keyOctave, pNoteFlag; |
| 171 | uint8_t tuningNote, resampleNote, initialTempo, initialSpeed, editMoveAdd; |
| 172 | |
| 173 | int16_t modulateSpeed; |
| 174 | uint16_t metroSpeed, metroChannel, sampleVol; |
| 175 | uint16_t effectMacros[10], currPlayNote, vol1, vol2, lpCutOff, hpCutOff; |
| 176 | int32_t smpRedoLoopStarts[MOD_SAMPLES], smpRedoLoopLengths[MOD_SAMPLES], smpRedoLengths[MOD_SAMPLES]; |
| 177 | int32_t oldTempo, markStartOfs, markEndOfs, samplePos, chordLength; |
| 178 | uint32_t playbackSeconds, playbackSecondsFrac; |
| 179 | |
| 180 | uint32_t framesPassed; |
| 181 | |
| 182 | note_t trackBuffer[MOD_ROWS], cmdsBuffer[MOD_ROWS], blockBuffer[MOD_ROWS]; |
| 183 | note_t patternBuffer[MOD_ROWS * PAULA_VOICES], undoBuffer[MOD_ROWS * PAULA_VOICES]; |
| 184 | SDL_Thread *mod2WavThread, *pat2SmpThread; |
| 185 | |
| 186 | #ifdef __APPLE__ |
| 187 | bool macCmdQIssued; |
| 188 | #endif |
| 189 | } editor_t; |
| 190 | |
| 191 | typedef struct diskop_t |
| 192 | { |
| 193 | volatile bool cached, isFilling, forceStopReading; |
| 194 | bool modPackFlg; |
| 195 | int8_t mode, smpSaveType; |
| 196 | int32_t numEntries, scrollOffset; |
| 197 | SDL_Keycode lastEntryJumpKey; |
| 198 | SDL_Thread *fillThread; |
| 199 | } diskop_t; |
| 200 | |
| 201 | typedef struct cursor_t |
| 202 | { |
| 203 | uint8_t lastPos, pos, mode, channel; |
| 204 | uint32_t bgBuffer[11 * 14]; |
| 205 | } cursor_t; |
| 206 | |
| 207 | typedef struct ui_t |
| 208 | { |
| 209 | char statusMessage[18], prevStatusMessage[18]; |
| 210 | volatile bool askBoxShown, throwExit; |
| 211 | bool editTextFlag, samplerScreenShown; |
| 212 | bool leftLoopPinMoving, rightLoopPinMoving, changingSmpResample, changingDrumPadNote; |
| 213 | bool forceSampleDrag, forceSampleEdit; |
| 214 | bool aboutScreenShown, posEdScreenShown, diskOpScreenShown; |
| 215 | bool samplerVolBoxShown, samplerFiltersBoxShown, samplingBoxShown, editOpScreenShown; |
| 216 | bool changingSamplingNote; |
| 217 | bool disableVisualizer; // ask boxes (f.ex. MOD2WAV) |
| 218 | int8_t pointerMode, editOpScreen; |
| 219 | int8_t visualizerMode, previousPointerMode, forceVolDrag, changingChordNote; |
| 220 | int16_t sampleMarkingPos; |
| 221 | uint16_t lastSampleOffset; |
| 222 | |
| 223 | // render/update flags |
| 224 | bool updateStatusText, updatePatternData; |
| 225 | bool updateSongName, updateMod2WavDialog, mod2WavFinished; |
| 226 | |
| 227 | // edit op. #2 |
| 228 | bool updateRecordText, updateQuantizeText, updateMetro1Text, updateMetro2Text; |
| 229 | bool updateFromText, updateKeysText, updateToText; |
| 230 | |
| 231 | // edit op. #3 |
| 232 | bool updateMixText, updatePosText, updateModText, updateVolText; |
| 233 | |
| 234 | // edit op. #4 (sample chord editor) |
| 235 | bool updateChordLengthText, updateChordNote1Text, updateChordNote2Text; |
| 236 | bool updateChordNote3Text, updateChordNote4Text; |
| 237 | |
| 238 | // sampler |
| 239 | bool updateResampleNote, updateVolFromText, updateVolToText, updateLPText; |
| 240 | bool updateHPText, updateNormFlag, update9xxPos; |
| 241 | |
| 242 | // general |
| 243 | bool updateSongPos, updateSongPattern, updateSongLength, updateCurrSampleFineTune; |
| 244 | bool updateCurrSampleNum, updateCurrSampleVolume, updateCurrSampleLength; |
| 245 | bool updateCurrSampleRepeat, updateCurrSampleReplen, updateCurrSampleName; |
| 246 | bool updateSongSize, updateSongTiming, updateSongBPM; |
| 247 | bool updateCurrPattText, updateTrackerFlags; |
| 248 | |
| 249 | // disk op. |
| 250 | bool updateLoadMode, updatePackText, updateSaveFormatText, updateDiskOpPathText; |
| 251 | |
| 252 | // pos ed. |
| 253 | bool updatePosEd, updateDiskOpFileList; |
| 254 | } ui_t; |
| 255 | |
| 256 | typedef struct textEdit_t |
| 257 | { |
| 258 | bool endReached, scrollable, force32BitNumPtr; |
| 259 | char *textPtr, *textEndPtr, *textStartPtr; |
| 260 | int8_t *numPtr8, tmpDisp8, type; |
| 261 | uint8_t numDigits, numBits; |
| 262 | int16_t cursorStartX, cursorStartY, object; |
| 263 | uint16_t *numPtr16, tmpDisp16, cursorBlock, numBlocks; |
| 264 | int32_t scrollOffset, *numPtr32, tmpDisp32; |
| 265 | } textEdit_t; |
| 266 | |
| 267 | extern keyb_t keyb; |
| 268 | extern mouse_t mouse; |
| 269 | extern video_t video; |
| 270 | extern editor_t editor; |
| 271 | extern diskop_t diskop; |
| 272 | extern cursor_t cursor; |
| 273 | extern ui_t ui; |
| 274 | extern textEdit_t textEdit; |
| 275 | extern module_t *song; // pt2_main.c |