| 1 | // for finding memory leaks in debug mode with Visual Studio cxx . . $ `<file>/src/pt2_module_loader.c`/ |
| 2 | #if defined _DEBUG && defined _MSC_VER |
| 3 | #include <crtdbg.h> |
| 4 | #endif |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <stdint.h> |
| 9 | #include <stdbool.h> |
| 10 | #include <string.h> |
| 11 | #ifdef _WIN32 |
| 12 | #include <io.h> |
| 13 | #else |
| 14 | #include <unistd.h> |
| 15 | #endif |
| 16 | #include <fcntl.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include "pt2_mouse.h"cxx . . $ `<file>/src/pt2_mouse.h`/ |
| 20 | #include "pt2_sampler.h"cxx . . $ `<file>/src/pt2_sampler.h`/ |
| 21 | #include "pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/ |
| 22 | #include "pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/ |
| 23 | #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/ |
| 24 | #include "pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/ |
| 25 | #include "pt2_visuals.h"cxx . . $ `<file>/src/pt2_visuals.h`/ |
| 26 | #include "pt2_sample_loader.h"cxx . . $ `<file>/src/pt2_sample_loader.h`/ |
| 27 | #include "pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/ |
| 28 | #include "modloaders/pt2_load_mod15.h"cxx . . $ `<file>/src/modloaders/pt2_load_mod15.h`/ |
| 29 | #include "modloaders/pt2_load_mod31.h"cxx . . $ `<file>/src/modloaders/pt2_load_mod31.h`/ |
| 30 | #include "modloaders/pt2_xpk_unpack.h"cxx . . $ `<file>/src/modloaders/pt2_xpk_unpack.h`/ |
| 31 | #include "modloaders/pt2_pp_unpack.h"cxx . . $ `<file>/src/modloaders/pt2_pp_unpack.h`/ |
| 32 | #include "pt2_askbox.h"cxx . . $ `<file>/src/pt2_askbox.h`/ |
| 33 | #include "pt2_posed.h"cxx . . $ `<file>/src/pt2_posed.h`/ |
| 34 | |
| 35 | static void fixZeroesInStringcxx . . $ fixZeroesInString(2ae3250752bf8d86).(char *str, uint32_tcxx . . $ uint32_t# maxLength); // converts zeroes to spaces in a string, up until the last zero found |
| 36 | |
| 37 | module_tcxx . . $ module_t# *modLoadcxx . . $ modLoad(eee069cd8a65e1b3).(UNICHARcxx . . $ UNICHAR# *fileName) |
| 38 | { |
| 39 | uint32_tcxx . . $ uint32_t# powerPackerID; |
| 40 | |
| 41 | uint8_tcxx . . $ uint8_t# *modBuffer = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 42 | module_tcxx . . $ module_t# *newMod = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 43 | |
| 44 | FILEcxx . . $ FILE# *f = UNICHAR_FOPENcxx . . $ `src/pt2_unicode.h:35:9`!(fileName, "rb"); |
| 45 | if (f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 46 | { |
| 47 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("FILE I/O ERROR !"); |
| 48 | goto loadError; |
| 49 | } |
| 50 | |
| 51 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 0, SEEK_ENDcxx . . $ `<external>/14710646456994434043/fcntl.h:139:10`!); |
| 52 | uint32_tcxx . . $ uint32_t# filesize = ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f); |
| 53 | rewindcxx . . $ rewind(8d4262d45fc644ab).(f); |
| 54 | |
| 55 | // check if mod is a powerpacker mod |
| 56 | freadcxx . . $ fread(738fc8ac1d711e58).(&powerPackerID, 4, 1, f); |
| 57 | if (powerPackerID == 0x30325850) // "PX20" |
| 58 | { |
| 59 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("ENCRYPTED MOD !"); |
| 60 | goto loadError; |
| 61 | } |
| 62 | else if (powerPackerID == 0x30325050) // "PP20" |
| 63 | { |
| 64 | modBuffer = unpackPPcxx . . $ unpackPP(194f2cbfed1acdc7).(f, &filesize); |
| 65 | if (modBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 66 | { |
| 67 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("PP UNPACK ERROR !"); |
| 68 | goto loadError; // error msg is set in unpackPPModule() |
| 69 | } |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | if (detectXPKcxx . . $ detectXPK(dc9e5a301483124c).(f)) |
| 74 | { |
| 75 | if (!unpackXPKcxx . . $ unpackXPK(6c33868bbccc6760).(f, &filesize, &modBuffer)) |
| 76 | { |
| 77 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("XPK UNPACK ERROR"); |
| 78 | goto loadError; |
| 79 | } |
| 80 | |
| 81 | if (modBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 82 | { |
| 83 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 84 | goto loadError; |
| 85 | } |
| 86 | |
| 87 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(f); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | modBuffer = (uint8_tcxx . . $ uint8_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(filesize); |
| 92 | if (modBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 93 | { |
| 94 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 95 | goto loadError; |
| 96 | } |
| 97 | |
| 98 | rewindcxx . . $ rewind(8d4262d45fc644ab).(f); |
| 99 | freadcxx . . $ fread(738fc8ac1d711e58).(modBuffer, 1, filesize, f); |
| 100 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(f); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // read module is in now in modBuffer, time to load... |
| 105 | |
| 106 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! isMod31 = detectMod31cxx . . $ detectMod31(f3e7299796ab6c6f).(modBuffer, filesize); |
| 107 | if (isMod31) |
| 108 | newMod = loadMod31cxx . . $ loadMod31(abcad8371f3628e2).(modBuffer, filesize); |
| 109 | else |
| 110 | newMod = loadMod15cxx . . $ loadMod15(abcad8371f3628e2).(modBuffer, filesize); |
| 111 | |
| 112 | freecxx . . $ free(5d22bdacc48458e8).(modBuffer); |
| 113 | modBuffer = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 114 | |
| 115 | if (newMod == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 116 | { |
| 117 | // error message is shown in the mod loader |
| 118 | goto loadError; |
| 119 | } |
| 120 | |
| 121 | // module is loaded, do some sanitation... |
| 122 | |
| 123 | newMod->headercxx . . $ module_t#header..namecxx . . $ moduleHeader_t#name.[20] = '\0'; |
| 124 | |
| 125 | // convert illegal song name characters to space |
| 126 | for (int32_tcxx . . $ int32_t# i = 0; i < 20; i++) |
| 127 | { |
| 128 | char tmpChar = newMod->headercxx . . $ module_t#header..namecxx . . $ moduleHeader_t#name.[i]; |
| 129 | if ((tmpChar < ' ' || tmpChar > '~') && tmpChar != '\0') |
| 130 | tmpChar = ' '; |
| 131 | |
| 132 | newMod->headercxx . . $ module_t#header..namecxx . . $ moduleHeader_t#name.[i] = tmpChar; |
| 133 | } |
| 134 | |
| 135 | fixZeroesInStringcxx . . $ fixZeroesInString(2ae3250752bf8d86).(newMod->headercxx . . $ module_t#header..namecxx . . $ moduleHeader_t#name., 20); |
| 136 | |
| 137 | moduleSample_tcxx . . $ moduleSample_t# *s = newMod->samplescxx . . $ module_t#samples.; |
| 138 | for (int32_tcxx . . $ int32_t# i = 0; i < MOD_SAMPLEScxx . . $ `src/pt2_header.h:74:9`!; i++, s++) |
| 139 | { |
| 140 | s->textcxx . . $ moduleSample_t#text.[22] = '\0'; |
| 141 | |
| 142 | // convert illegal sample name characters to space |
| 143 | for (int32_tcxx . . $ int32_t# j = 0; j < 22; j++) |
| 144 | { |
| 145 | char tmpChar = s->textcxx . . $ moduleSample_t#text.[j]; |
| 146 | if ((tmpChar < ' ' || tmpChar > '~') && tmpChar != '\0') |
| 147 | tmpChar = ' '; |
| 148 | |
| 149 | s->textcxx . . $ moduleSample_t#text.[j] = tmpChar; |
| 150 | } |
| 151 | |
| 152 | fixZeroesInStringcxx . . $ fixZeroesInString(2ae3250752bf8d86).(s->textcxx . . $ moduleSample_t#text., 22); |
| 153 | |
| 154 | if (s->lengthcxx . . $ moduleSample_t#length. > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 155 | s->lengthcxx . . $ moduleSample_t#length. = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 156 | |
| 157 | if ((uint8_tcxx . . $ uint8_t#)s->volumecxx . . $ moduleSample_t#volume. > 64) |
| 158 | s->volumecxx . . $ moduleSample_t#volume. = 64; |
| 159 | |
| 160 | if (s->loopLengthcxx . . $ moduleSample_t#loopLength. < 2) |
| 161 | s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2; |
| 162 | |
| 163 | // we don't support samples bigger than 65534 (or 128kB) bytes, disable uncompatible loops |
| 164 | if (s->loopStartcxx . . $ moduleSample_t#loopStart. > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. || s->loopStartcxx . . $ moduleSample_t#loopStart.+s->loopLengthcxx . . $ moduleSample_t#loopLength. > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 165 | { |
| 166 | s->loopStartcxx . . $ moduleSample_t#loopStart. = 0; |
| 167 | s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2; |
| 168 | } |
| 169 | |
| 170 | // some modules are broken like this, adjust sample length if possible (this is ok if we have room) |
| 171 | if (s->lengthcxx . . $ moduleSample_t#length. > 0 && s->loopLengthcxx . . $ moduleSample_t#loopLength. > 2 && s->loopStartcxx . . $ moduleSample_t#loopStart.+s->loopLengthcxx . . $ moduleSample_t#loopLength. > s->lengthcxx . . $ moduleSample_t#length.) |
| 172 | { |
| 173 | int32_tcxx . . $ int32_t# loopOverflowVal = (s->loopStartcxx . . $ moduleSample_t#loopStart. + s->loopLengthcxx . . $ moduleSample_t#loopLength.) - s->lengthcxx . . $ moduleSample_t#length.; |
| 174 | if (s->lengthcxx . . $ moduleSample_t#length.+loopOverflowVal <= configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 175 | { |
| 176 | s->lengthcxx . . $ moduleSample_t#length. += loopOverflowVal; // this is safe, we're allocating 65534 bytes per sample slot |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | s->loopStartcxx . . $ moduleSample_t#loopStart. = 0; |
| 181 | s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // clear first two bytes of non-looping samples to prevent beep after sample has been played |
| 186 | if (s->lengthcxx . . $ moduleSample_t#length. >= 2 && s->loopStartcxx . . $ moduleSample_t#loopStart.+s->loopLengthcxx . . $ moduleSample_t#loopLength. <= 2) |
| 187 | { |
| 188 | newMod->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset.+0] = 0; |
| 189 | newMod->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset.+1] = 0; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | initializeModuleChannelscxx . . $ initializeModuleChannels(c4f6a69956ee5af3).(newMod); |
| 194 | return newMod; |
| 195 | |
| 196 | loadError: |
| 197 | if (modBuffer != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 198 | freecxx . . $ free(5d22bdacc48458e8).(modBuffer); |
| 199 | |
| 200 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 201 | } |
| 202 | |
| 203 | static void fixZeroesInStringcxx . . $ fixZeroesInString(2ae3250752bf8d86).(char *str, uint32_tcxx . . $ uint32_t# maxLength) |
| 204 | { |
| 205 | int32_tcxx . . $ int32_t# i; |
| 206 | |
| 207 | for (i = maxLength-1; i >= 0; i--) |
| 208 | { |
| 209 | if (str[i] != '\0') |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | // convert zeroes to spaces |
| 214 | if (i > 0) |
| 215 | { |
| 216 | for (int32_tcxx . . $ int32_t# j = 0; j < i; j++) |
| 217 | { |
| 218 | if (str[j] == '\0') |
| 219 | str[j] = ' '; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void setupLoadedModcxx . . $ setupLoadedMod(49f6e7a06ebc5aa8).(void) |
| 225 | { |
| 226 | for (uint8_tcxx . . $ uint8_t# i = 0; i < MOD_SAMPLEScxx . . $ `src/pt2_header.h:74:9`!; i++) |
| 227 | fillSampleRedoBuffercxx . . $ fillSampleRedoBuffer(4af4fd0e2b26c4ac).(i); |
| 228 | |
| 229 | modSetPoscxx . . $ modSetPos(af780a7c10c7990f).(0, 0); |
| 230 | modSetPatterncxx . . $ modSetPattern(ac50b47256ae7414).(0); // set pattern to 00 instead of first order's pattern |
| 231 | |
| 232 | posEdClearNamescxx . . $ posEdClearNames(49f6e7a06ebc5aa8).(); |
| 233 | |
| 234 | // setup GUI text pointers |
| 235 | editorcxx . . $ editor..currEditPatternDispcxx . . $ editor_t#currEditPatternDisp. = &songcxx . . $ song.->currPatterncxx . . $ module_t#currPattern.; |
| 236 | editorcxx . . $ editor..currPosDispcxx . . $ editor_t#currPosDisp. = &songcxx . . $ song.->currPoscxx . . $ module_t#currPos.; |
| 237 | editorcxx . . $ editor..currPatternDispcxx . . $ editor_t#currPatternDisp. = &songcxx . . $ song.->headercxx . . $ module_t#header..patternTablecxx . . $ moduleHeader_t#patternTable.[0]; |
| 238 | editorcxx . . $ editor..currPosEdPattDispcxx . . $ editor_t#currPosEdPattDisp. = &songcxx . . $ song.->headercxx . . $ module_t#header..patternTablecxx . . $ moduleHeader_t#patternTable.[0]; |
| 239 | editorcxx . . $ editor..currLengthDispcxx . . $ editor_t#currLengthDisp. = &songcxx . . $ song.->headercxx . . $ module_t#header..songLengthcxx . . $ moduleHeader_t#songLength.; |
| 240 | |
| 241 | // calculate MOD size |
| 242 | uicxx . . $ ui..updateSongSizecxx . . $ ui_t#updateSongSize. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 243 | |
| 244 | editorcxx . . $ editor..mutedcxx . . $ editor_t#muted.[0] = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 245 | editorcxx . . $ editor..mutedcxx . . $ editor_t#muted.[1] = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 246 | editorcxx . . $ editor..mutedcxx . . $ editor_t#muted.[2] = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 247 | editorcxx . . $ editor..mutedcxx . . $ editor_t#muted.[3] = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 248 | |
| 249 | editorcxx . . $ editor..editMoveAddcxx . . $ editor_t#editMoveAdd. = 1; |
| 250 | editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample. = 0; |
| 251 | |
| 252 | editorcxx . . $ editor..playbackSecondscxx . . $ editor_t#playbackSeconds. = editorcxx . . $ editor..playbackSecondsFraccxx . . $ editor_t#playbackSecondsFrac. = 0; |
| 253 | editorcxx . . $ editor..modLoadedcxx . . $ editor_t#modLoaded. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 254 | editorcxx . . $ editor..blockMarkFlagcxx . . $ editor_t#blockMarkFlag. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 255 | editorcxx . . $ editor..sampleZerocxx . . $ editor_t#sampleZero. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 256 | editorcxx . . $ editor..hiLowInstrcxx . . $ editor_t#hiLowInstr. = 0; |
| 257 | |
| 258 | // disable LED filter after module load (real PT doesn't do this) |
| 259 | setLEDFiltercxx . . $ setLEDFilter(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 260 | |
| 261 | updateWindowTitlecxx . . $ updateWindowTitle(b45ddcbc8423892c).(MOD_NOT_MODIFIEDcxx . . $ MOD_NOT_MODIFIED.); |
| 262 | |
| 263 | editorcxx . . $ editor..timingModecxx . . $ editor_t#timingMode. = TEMPO_MODE_CIAcxx . . $ TEMPO_MODE_CIA.; |
| 264 | updateReplayerTimingModecxx . . $ updateReplayerTimingMode(49f6e7a06ebc5aa8).(); |
| 265 | |
| 266 | modSetSpeedcxx . . $ modSetSpeed(d4f767463ce0a6b3).(6); |
| 267 | modSetTempocxx . . $ modSetTempo(918ebd27a9ddbad3).(songcxx . . $ song.->headercxx . . $ module_t#header..initialTempocxx . . $ moduleHeader_t#initialTempo., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); // 125 for normal MODs, custom value for certain STK/UST MODs |
| 268 | |
| 269 | updateCurrSamplecxx . . $ updateCurrSample(49f6e7a06ebc5aa8).(); |
| 270 | editorcxx . . $ editor..samplePoscxx . . $ editor_t#samplePos. = 0; |
| 271 | updateSamplePoscxx . . $ updateSamplePos(49f6e7a06ebc5aa8).(); |
| 272 | } |
| 273 | |
| 274 | void loadModFromArgcxx . . $ loadModFromArg(fda57c8427c60377).(char *arg) |
| 275 | { |
| 276 | statusAllRightcxx . . $ statusAllRight(49f6e7a06ebc5aa8).(); |
| 277 | |
| 278 | uint32_tcxx . . $ uint32_t# filenameLen = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(arg); |
| 279 | |
| 280 | UNICHARcxx . . $ UNICHAR# *filenameU = (UNICHARcxx . . $ UNICHAR# *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(filenameLen + 2, sizeof (UNICHARcxx . . $ UNICHAR#)); |
| 281 | if (filenameU == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 282 | { |
| 283 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | #ifdef _WIN32 |
| 288 | MultiByteToWideChar(CP_UTF8, 0, arg, -1, filenameU, filenameLen); |
| 289 | #else |
| 290 | strcpycxx . . $ strcpy(b7b3a83273496486).(filenameU, arg); |
| 291 | #endif |
| 292 | |
| 293 | module_tcxx . . $ module_t# *newSong = modLoadcxx . . $ modLoad(eee069cd8a65e1b3).(filenameU); |
| 294 | if (newSong != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 295 | { |
| 296 | songcxx . . $ song.->loadedcxx . . $ module_t#loaded. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 297 | modFreecxx . . $ modFree(49f6e7a06ebc5aa8).(); |
| 298 | songcxx . . $ song. = newSong; |
| 299 | setupLoadedModcxx . . $ setupLoadedMod(49f6e7a06ebc5aa8).(); |
| 300 | songcxx . . $ song.->loadedcxx . . $ module_t#loaded. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | editorcxx . . $ editor..errorMsgActivecxx . . $ editor_t#errorMsgActive. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 305 | editorcxx . . $ editor..errorMsgBlockcxx . . $ editor_t#errorMsgBlock. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 306 | editorcxx . . $ editor..errorMsgCountercxx . . $ editor_t#errorMsgCounter. = 0; |
| 307 | |
| 308 | // status/error message is set in the mod loader |
| 309 | setErrPointercxx . . $ setErrPointer(49f6e7a06ebc5aa8).(); |
| 310 | } |
| 311 | |
| 312 | freecxx . . $ free(5d22bdacc48458e8).(filenameU); |
| 313 | } |
| 314 | |
| 315 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! testExtensioncxx . . $ testExtension(1dd49168424a2fc4).(char *ext, uint8_tcxx . . $ uint8_t# extLen, char *fullPath) |
| 316 | { |
| 317 | // checks for EXT.filename and filename.EXT |
| 318 | |
| 319 | extLen++; // add one to length (dot) |
| 320 | |
| 321 | char *fileName = strrchrcxx . . $ strrchr(2050848944e00d54).(fullPath, DIR_DELIMITERcxx . . $ `src/pt2_header.h:33:9`!); |
| 322 | if (fileName != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 323 | fileName++; |
| 324 | else |
| 325 | fileName = fullPath; |
| 326 | |
| 327 | uint32_tcxx . . $ uint32_t# fileNameLen = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(fileName); |
| 328 | if (fileNameLen >= extLen) |
| 329 | { |
| 330 | char begStr[8], endStr[8]; |
| 331 | |
| 332 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(begStr, "%s.", ext); |
| 333 | if (!_strnicmpcxx . . $ `src/pt2_header.h:35:9`!(begStr, fileName, extLen)) |
| 334 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 335 | |
| 336 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(endStr, ".%s", ext); |
| 337 | if (!_strnicmpcxx . . $ `src/pt2_header.h:35:9`!(endStr, fileName + (fileNameLen - extLen), extLen)) |
| 338 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 339 | } |
| 340 | |
| 341 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 342 | } |
| 343 | |
| 344 | void loadDroppedFilecxx . . $ loadDroppedFile(90acc2fa0970f3e0).(char *fullPath, uint32_tcxx . . $ uint32_t# fullPathLen, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! autoPlay, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! songModifiedCheck) |
| 345 | { |
| 346 | // don't allow drag n' drop if the tracker is busy |
| 347 | if (uicxx . . $ ui..pointerModecxx . . $ ui_t#pointerMode. == POINTER_MODE_MSG1cxx . . $ POINTER_MODE_MSG1. || diskopcxx . . $ diskop..isFillingcxx . . $ diskop_t#isFilling. || |
| 348 | editorcxx . . $ editor..mod2WavOngoingcxx . . $ editor_t#mod2WavOngoing. || editorcxx . . $ editor..pat2SmpOngoingcxx . . $ editor_t#pat2SmpOngoing. || |
| 349 | uicxx . . $ ui..samplerFiltersBoxShowncxx . . $ ui_t#samplerFiltersBoxShown. || uicxx . . $ ui..samplerVolBoxShowncxx . . $ ui_t#samplerVolBoxShown. || uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown.) |
| 350 | { |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | char *ansiName = (char *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(fullPathLen + 10, sizeof (char)); |
| 355 | if (ansiName == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 356 | { |
| 357 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | UNICHARcxx . . $ UNICHAR# *fullPathU = (UNICHARcxx . . $ UNICHAR# *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(fullPathLen + 2, sizeof (UNICHARcxx . . $ UNICHAR#)); |
| 362 | if (fullPathU == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 363 | { |
| 364 | freecxx . . $ free(5d22bdacc48458e8).(ansiName); |
| 365 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | #ifdef _WIN32 |
| 370 | MultiByteToWideChar(CP_UTF8, 0, fullPath, -1, fullPathU, fullPathLen); |
| 371 | #else |
| 372 | strcpycxx . . $ strcpy(b7b3a83273496486).(fullPathU, fullPath); |
| 373 | #endif |
| 374 | |
| 375 | unicharToAnsicxx . . $ unicharToAnsi(9105ef05e8145e1).(ansiName, fullPathU, fullPathLen); |
| 376 | |
| 377 | // make a new pointer point to filename (strip path) |
| 378 | char *fileName = strrchrcxx . . $ strrchr(2050848944e00d54).(ansiName, DIR_DELIMITERcxx . . $ `src/pt2_header.h:33:9`!); |
| 379 | if (fileName != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 380 | fileName++; |
| 381 | else |
| 382 | fileName = ansiName; |
| 383 | |
| 384 | // check if the file extension is a module (FIXME: check module by content instead..?) |
| 385 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! isMod = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 386 | if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("MOD", 3, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 387 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("M15", 3, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 388 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("STK", 3, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 389 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("NST", 3, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 390 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("UST", 3, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 391 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("PP", 2, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 392 | else if (testExtensioncxx . . $ testExtension(1dd49168424a2fc4).("NT", 2, fileName)) isMod = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 393 | |
| 394 | if (isMod) |
| 395 | { |
| 396 | if (songModifiedCheck && songcxx . . $ song.->modifiedcxx . . $ module_t#modified.) |
| 397 | { |
| 398 | if (!askBoxcxx . . $ askBox(7371ee129cebb502).(ASKBOX_YES_NOcxx . . $ ASKBOX_YES_NO., "SONG IS UNSAVED !")) |
| 399 | goto DropExit; |
| 400 | } |
| 401 | |
| 402 | module_tcxx . . $ module_t# *newSong = modLoadcxx . . $ modLoad(eee069cd8a65e1b3).(fullPathU); |
| 403 | if (newSong != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 404 | { |
| 405 | uint8_tcxx . . $ uint8_t# oldMode = editorcxx . . $ editor..currModecxx . . $ editor_t#currMode.; |
| 406 | uint8_tcxx . . $ uint8_t# oldPlayMode = editorcxx . . $ editor..playModecxx . . $ editor_t#playMode.; |
| 407 | |
| 408 | modStopcxx . . $ modStop(49f6e7a06ebc5aa8).(); |
| 409 | modFreecxx . . $ modFree(49f6e7a06ebc5aa8).(); |
| 410 | |
| 411 | songcxx . . $ song. = newSong; |
| 412 | setupLoadedModcxx . . $ setupLoadedMod(49f6e7a06ebc5aa8).(); |
| 413 | songcxx . . $ song.->loadedcxx . . $ module_t#loaded. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 414 | |
| 415 | statusAllRightcxx . . $ statusAllRight(49f6e7a06ebc5aa8).(); |
| 416 | |
| 417 | if (autoPlay) |
| 418 | { |
| 419 | editorcxx . . $ editor..playModecxx . . $ editor_t#playMode. = PLAY_MODE_NORMALcxx . . $ PLAY_MODE_NORMAL.; |
| 420 | editorcxx . . $ editor..currModecxx . . $ editor_t#currMode. = MODE_PLAYcxx . . $ MODE_PLAY.; |
| 421 | |
| 422 | // start normal playback |
| 423 | modPlaycxx . . $ modPlay(7b7bc4ff97a2e5fe).(DONT_SET_PATTERNcxx . . $ DONT_SET_PATTERN., 0, 0); |
| 424 | |
| 425 | pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_PLAYcxx . . $ POINTER_MODE_PLAY., DO_CARRYcxx . . $ DO_CARRY.); |
| 426 | } |
| 427 | else if (oldMode == MODE_PLAYcxx . . $ MODE_PLAY. || oldMode == MODE_RECORDcxx . . $ MODE_RECORD.) |
| 428 | { |
| 429 | // use last mode |
| 430 | editorcxx . . $ editor..playModecxx . . $ editor_t#playMode. = oldPlayMode; |
| 431 | if (oldPlayMode == PLAY_MODE_PATTERNcxx . . $ PLAY_MODE_PATTERN. || oldMode == MODE_RECORDcxx . . $ MODE_RECORD.) |
| 432 | modPlaycxx . . $ modPlay(7b7bc4ff97a2e5fe).(0, 0, 0); |
| 433 | else |
| 434 | modPlaycxx . . $ modPlay(7b7bc4ff97a2e5fe).(DONT_SET_PATTERNcxx . . $ DONT_SET_PATTERN., 0, 0); |
| 435 | editorcxx . . $ editor..currModecxx . . $ editor_t#currMode. = oldMode; |
| 436 | |
| 437 | if (oldMode == MODE_RECORDcxx . . $ MODE_RECORD.) |
| 438 | pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_RECORDcxx . . $ POINTER_MODE_RECORD., DO_CARRYcxx . . $ DO_CARRY.); |
| 439 | else |
| 440 | pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_PLAYcxx . . $ POINTER_MODE_PLAY., DO_CARRYcxx . . $ DO_CARRY.); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | // stop playback |
| 445 | editorcxx . . $ editor..playModecxx . . $ editor_t#playMode. = PLAY_MODE_NORMALcxx . . $ PLAY_MODE_NORMAL.; |
| 446 | editorcxx . . $ editor..currModecxx . . $ editor_t#currMode. = MODE_IDLEcxx . . $ MODE_IDLE.; |
| 447 | editorcxx . . $ editor..songPlayingcxx . . $ editor_t#songPlaying. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 448 | pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_IDLEcxx . . $ POINTER_MODE_IDLE., DO_CARRYcxx . . $ DO_CARRY.); |
| 449 | } |
| 450 | |
| 451 | displayMainScreencxx . . $ displayMainScreen(49f6e7a06ebc5aa8).(); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | editorcxx . . $ editor..errorMsgActivecxx . . $ editor_t#errorMsgActive. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 456 | editorcxx . . $ editor..errorMsgBlockcxx . . $ editor_t#errorMsgBlock. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 457 | editorcxx . . $ editor..errorMsgCountercxx . . $ editor_t#errorMsgCounter. = 0; |
| 458 | setErrPointercxx . . $ setErrPointer(49f6e7a06ebc5aa8).(); // status/error message is set in the mod loader |
| 459 | } |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | loadSamplecxx . . $ loadSample(14223ed414283e68).(fullPathU, fileName); |
| 464 | } |
| 465 | |
| 466 | DropExit: |
| 467 | freecxx . . $ free(5d22bdacc48458e8).(ansiName); |
| 468 | freecxx . . $ free(5d22bdacc48458e8).(fullPathU); |
| 469 | } |