ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit 986a9df1593ab767caffd705013cada724219a22
parent af91213d67a744cf532548803c4c150eef5cb7c1
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Wed, 29 Apr 2020 18:01:17 +0200

Pushed v1.23 code

- Bugfix: The "default dirctories" paths in the config only worked for
  modules and not the other types (fixes GitHub issue #6).
- A much needed code refactoring of data structs. The code now also compiles
  with GCC 10.

Diffstat:
Msrc/ft2_about.c | 16++++++++--------
Msrc/ft2_audio.c | 19++++++++++++-------
Msrc/ft2_audio.h | 16++++++++++------
Msrc/ft2_audioselector.c | 9+++++----
Msrc/ft2_bmp.c | 2++
Msrc/ft2_bmp.h | 6++++--
Msrc/ft2_checkboxes.c | 3++-
Msrc/ft2_config.c | 25+++++++++++++------------
Msrc/ft2_diskop.c | 44+++++++++++++++++++++++++++++---------------
Msrc/ft2_edit.c | 97++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/ft2_events.c | 15++++++++-------
Msrc/ft2_gui.c | 117++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/ft2_header.h | 74+-------------------------------------------------------------------------
Msrc/ft2_help.c | 7++++---
Msrc/ft2_inst_ed.c | 65+++++++++++++++++++++++++++++++++--------------------------------
Msrc/ft2_keyboard.c | 152+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/ft2_keyboard.h | 6++++--
Msrc/ft2_main.c | 8++++----
Msrc/ft2_midi.c | 11+++++++----
Msrc/ft2_midi.h | 6++++--
Msrc/ft2_module_loader.c | 7++++---
Msrc/ft2_module_saver.c | 1+
Msrc/ft2_mouse.c | 79+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/ft2_mouse.h | 6++++--
Msrc/ft2_nibbles.c | 9+++++----
Msrc/ft2_pattern_draw.c | 93++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/ft2_pattern_ed.c | 523+++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/ft2_pattern_ed.h | 6++++--
Msrc/ft2_pushbuttons.c | 5+++--
Msrc/ft2_radiobuttons.c | 3++-
Msrc/ft2_replayer.c | 123++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/ft2_sample_ed.c | 89++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/ft2_sample_ed_features.c | 51++++++++++++++++++++++++++-------------------------
Msrc/ft2_sample_loader.c | 1+
Msrc/ft2_sample_saver.c | 1+
Msrc/ft2_sampling.c | 1+
Msrc/ft2_scopes.c | 3++-
Msrc/ft2_scrollbars.c | 3++-
Asrc/ft2_structs.c | 6++++++
Asrc/ft2_structs.h | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/ft2_sysreqs.c | 50+++++++++++++++++++++++++++-----------------------
Msrc/ft2_sysreqs.h | 6++++--
Msrc/ft2_textboxes.c | 3++-
Msrc/ft2_trim.c | 27++++++++++++++-------------
Msrc/ft2_unicode.h | 2+-
Msrc/ft2_video.c | 81+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/ft2_video.h | 6++++--
Msrc/ft2_wav_renderer.c | 27++++++++++++++-------------
Mvs2019_project/ft2-clone/ft2-clone.vcxproj | 54++++++++++++++++++++++--------------------------------
Mvs2019_project/ft2-clone/ft2-clone.vcxproj.filters | 4++++
50 files changed, 1045 insertions(+), 1005 deletions(-)

diff --git a/src/ft2_about.c b/src/ft2_about.c @@ -6,6 +6,7 @@ #include "ft2_bmp.h" #include "ft2_video.h" #include "ft2_tables.h" +#include "ft2_structs.h" // ported from original FT2 code @@ -235,12 +236,10 @@ extern uint32_t *unpackedData; void showAboutScreen(void) // called once when About screen is opened { #define TEXT_BORDER_COL 0x202020 - - const char *infoString = "Clone by Olav \"8bitbubsy\" S\025rensen - https://16-bits.org"; char verText[32]; uint16_t x, y; - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); @@ -254,24 +253,25 @@ void showAboutScreen(void) // called once when About screen is opened setCustomPalColor(TEXT_BORDER_COL); // sets PAL_CUSTOM - x = 5 + (SCREEN_W - textWidth(infoString)) / 2; + const char *infoString = "Clone by Olav \"8bitbubsy\" S\025rensen"; + x = (SCREEN_W - textWidth(infoString)) >> 1; y = 147; textOutBorder(x, y, PAL_FORGRND, PAL_CUSTOM, infoString); sprintf(verText, "v%s (compiled on %s)", PROG_VER_STR, __DATE__); - x = ((3 + ABOUT_SCREEN_W) - textWidth(verText)) / 2; - y = (3 + ABOUT_SCREEN_H) - ((FONT1_CHAR_H - 2) + 3); + x = (SCREEN_W - textWidth(verText)) >> 1; + y = 159; textOutBorder(x, y, PAL_FORGRND, PAL_CUSTOM, verText); aboutInit(); - editor.ui.aboutScreenShown = true; + ui.aboutScreenShown = true; } void hideAboutScreen(void) { hidePushButton(PB_EXIT_ABOUT); - editor.ui.aboutScreenShown = false; + ui.aboutScreenShown = false; } void exitAboutScreen(void) diff --git a/src/ft2_audio.c b/src/ft2_audio.c @@ -14,9 +14,19 @@ #include "ft2_wav_renderer.h" #include "ft2_mix.h" #include "ft2_tables.h" +#include "ft2_structs.h" #define INITIAL_DITHER_SEED 0x12345000 +// globalized +audio_t audio; +pattSyncData_t *pattSyncEntry; +chSyncData_t *chSyncEntry; +chSync_t chSync; +pattSync_t pattSync; +volatile bool pattQueueReading, pattQueueClearing, chQueueReading, chQueueClearing; + + static int8_t pmpCountDiv, pmpChannels = 2; static uint16_t smpBuffSize; static int32_t masterVol, oldAudioFreq, pmpLeft, randSeed = INITIAL_DITHER_SEED; @@ -31,11 +41,6 @@ static int32_t oldPeriod; static uint32_t oldSFrq, oldSFrqRev; #endif -pattSyncData_t *pattSyncEntry; -chSyncData_t *chSyncEntry; - -volatile bool pattQueueReading, pattQueueClearing, chQueueReading, chQueueClearing; - #if !defined __amd64__ && !defined _WIN64 void resetCachedMixerVars(void) { @@ -93,7 +98,7 @@ bool setNewAudioSettings(void) // only call this from the main input/video threa } // also update config audio radio buttons if we're on that screen at the moment - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) setConfigIORadioButtonStates(); // if it didn't work to use the old settings again, then something is seriously wrong... @@ -1214,7 +1219,7 @@ bool setupAudio(bool showErrorMsg) setLastWorkingAudioDevName(); // update config audio radio buttons if we're on that screen at the moment - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) showConfigScreen(); updateWavRendererSettings(); diff --git a/src/ft2_audio.h b/src/ft2_audio.h @@ -42,7 +42,7 @@ enum // for audio/video sync queue. (2^n-1 - don't change this! Queue buffer is already ~2.7MB in size) #define SYNC_QUEUE_LEN 4095 -struct audio_t +typedef struct audio_t { char *currInputDevice, *currOutputDevice, *lastWorkingAudioDeviceName; char *inputDeviceNames[MAX_AUDIO_DEVICES], *outputDeviceNames[MAX_AUDIO_DEVICES]; @@ -57,7 +57,7 @@ struct audio_t double dAudioLatencyMs, dSpeedValMul, dPianoDeltaMul; SDL_AudioDeviceID dev; uint32_t wantFreq, haveFreq, wantSamples, haveSamples, wantChannels, haveChannels; -} audio; +} audio_t; typedef struct { @@ -86,11 +86,11 @@ typedef struct pattSyncData_t uint64_t timestamp; } pattSyncData_t; -struct pattSync +typedef struct pattSync_t { volatile int32_t readPos, writePos; pattSyncData_t data[SYNC_QUEUE_LEN + 1]; -} pattSync; +} pattSync_t; typedef struct chSyncData_t { @@ -98,14 +98,18 @@ typedef struct chSyncData_t uint64_t timestamp; } chSyncData_t; -struct chSync +typedef struct chSync_t { volatile int32_t readPos, writePos; chSyncData_t data[SYNC_QUEUE_LEN + 1]; -} chSync; +} chSync_t; +// in ft2_audio.c +extern audio_t audio; extern pattSyncData_t *pattSyncEntry; extern chSyncData_t *chSyncEntry; +extern chSync_t chSync; +extern pattSync_t pattSync; extern volatile bool pattQueueReading, pattQueueClearing, chQueueReading, chQueueClearing; diff --git a/src/ft2_audioselector.c b/src/ft2_audioselector.c @@ -11,6 +11,7 @@ #include "ft2_gui.h" #include "ft2_mouse.h" #include "ft2_audioselector.h" +#include "ft2_structs.h" char *getAudioOutputDeviceFromConfig(void) { @@ -220,7 +221,7 @@ bool testAudioDeviceListsMouseDown(void) int32_t mx, my, deviceNum; uint32_t devStringLen; - if (!editor.ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_IO_DEVICES) + if (!ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_IO_DEVICES) return false; mx = mouse.x; @@ -420,7 +421,7 @@ void rescanAudioDevices(void) const char *deviceName; uint32_t stringLen; - listShown = (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES); + listShown = (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES); freeAudioDeviceLists(); @@ -518,7 +519,7 @@ void sbAudOutputSetPos(uint32_t pos) { (void)pos; - if (editor.ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES)) + if (ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES)) drawAudioOutputList(); } @@ -526,6 +527,6 @@ void sbAudInputSetPos(uint32_t pos) { (void)pos; - if (editor.ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES)) + if (ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES)) drawAudioInputList(); } diff --git a/src/ft2_bmp.c b/src/ft2_bmp.c @@ -41,6 +41,8 @@ static uint32_t *loadBMPTo32Bit(const uint8_t *src); static uint8_t *loadBMPTo1Bit(const uint8_t *src); static uint8_t *loadBMPTo4BitPal(const uint8_t *src); +bmp_t bmp; // globalized + // if you match a color in this table, you have the real palette index (LUT pos) #define NUM_CUSTOM_PALS 17 static const uint32_t bmpCustomPalette[NUM_CUSTOM_PALS] = diff --git a/src/ft2_bmp.h b/src/ft2_bmp.h @@ -3,7 +3,7 @@ #include <stdint.h> #include <stdbool.h> -struct +typedef struct bmp_t { uint8_t *font1, *font2, *font3, *font4, *font6, *font7, *font8; uint8_t *ft2LogoBadges, *ft2ByBadges, *radiobuttonGfx, *checkboxGfx; @@ -11,7 +11,9 @@ struct uint8_t *mouseCursors, *mouseCursorBusyClock, *mouseCursorBusyGlass; uint8_t *whitePianoKeys, *blackPianoKeys, *vibratoWaveforms, *scopeRec, *scopeMute; uint32_t *ft2AboutLogo; -} bmp; +} bmp_t; + +extern bmp_t bmp; // ft2_bmp.c bool loadBMPs(void); void freeBMPs(void); diff --git a/src/ft2_checkboxes.c b/src/ft2_checkboxes.c @@ -14,6 +14,7 @@ #include "ft2_mouse.h" #include "ft2_edit.h" #include "ft2_bmp.h" +#include "ft2_structs.h" checkBox_t checkBoxes[NUM_CHECKBOXES] = { @@ -182,7 +183,7 @@ bool testCheckBoxMouseDown(void) uint16_t start, end; checkBox_t *checkBox; - if (editor.ui.sysReqShown) + if (ui.sysReqShown) { // if a system request is open, only test the first three checkboxes (reserved) start = 0; diff --git a/src/ft2_config.c b/src/ft2_config.c @@ -31,6 +31,7 @@ #include "ft2_pattern_draw.h" #include "ft2_tables.h" #include "ft2_bmp.h" +#include "ft2_structs.h" // globals config_t config; @@ -189,7 +190,7 @@ static void loadConfigFromBuffer(void) setMouseShape(config.mouseType); changeLogoType(config.id_FastLogo); changeBadgeType(config.id_TritonProd); - editor.ui.maxVisibleChannels = (uint8_t)(2 + ((config.ptnMaxChannels + 1) * 2)); + ui.maxVisibleChannels = (uint8_t)(2 + ((config.ptnMaxChannels + 1) * 2)); setPal16(palTable[config.cfg_StdPalNr], true); updatePattFontPtrs(); @@ -275,7 +276,7 @@ bool loadConfig(bool showErrorFlag) if (midi.initThreadDone) { setMidiInputDeviceFromConfig(); - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) drawMidiInputList(); } #endif @@ -1083,11 +1084,11 @@ static void setConfigMiscRadioButtonStates(void) void showConfigScreen(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); - editor.ui.configScreenShown = true; + ui.configScreenShown = true; drawFramework(0, 0, 110, 173, FRAMEWORK_TYPE1); @@ -1503,7 +1504,7 @@ void hideConfigScreen(void) hideScrollBar(SB_MIDI_INPUT_SCROLL); #endif - editor.ui.configScreenShown = false; + ui.configScreenShown = false; } void exitConfigScreen(void) @@ -1703,11 +1704,11 @@ void cbConfigDither(void) static void redrawPatternEditor(void) // called after changing some pattern editor settings in config { // if the cursor was on the volume column while we turned volume column off, move it to effect type slot - if (!config.ptnS3M && (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2)) - editor.cursor.object = CURSOR_EFX0; + if (!config.ptnS3M && (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2)) + cursor.object = CURSOR_EFX0; updateChanNums(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void cbConfigPattStretch(void) @@ -1841,7 +1842,7 @@ void rbConfigPatt4Chans(void) { config.ptnMaxChannels = MAX_CHANS_SHOWN_4; checkRadioButton(RB_CONFIG_MAXCHAN_4); - editor.ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); + ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); redrawPatternEditor(); } @@ -1849,7 +1850,7 @@ void rbConfigPatt6Chans(void) { config.ptnMaxChannels = MAX_CHANS_SHOWN_6; checkRadioButton(RB_CONFIG_MAXCHAN_6); - editor.ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); + ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); redrawPatternEditor(); } @@ -1857,7 +1858,7 @@ void rbConfigPatt8Chans(void) { config.ptnMaxChannels = MAX_CHANS_SHOWN_8; checkRadioButton(RB_CONFIG_MAXCHAN_8); - editor.ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); + ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); redrawPatternEditor(); } @@ -1865,7 +1866,7 @@ void rbConfigPatt12Chans(void) { config.ptnMaxChannels = MAX_CHANS_SHOWN_12; checkRadioButton(RB_CONFIG_MAXCHAN_12); - editor.ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); + ui.maxVisibleChannels = 2 + (((uint8_t)config.ptnMaxChannels + 1) * 2); redrawPatternEditor(); } diff --git a/src/ft2_diskop.c b/src/ft2_diskop.c @@ -38,8 +38,9 @@ #include "ft2_events.h" #include "ft2_video.h" #include "ft2_inst_ed.h" +#include "ft2_structs.h" -// hide POSIX warnings +// hide POSIX warnings for chdir() #ifdef _MSC_VER #pragma warning(disable: 4996) #endif @@ -669,7 +670,7 @@ void diskOpSetFilename(uint8_t type, UNICHAR *pathU) free(ansiPath); - if (editor.ui.diskOpShown) + if (ui.diskOpShown) drawTextBox(TB_DISKOP_FILENAME); } @@ -770,14 +771,14 @@ void changeFilenameExt(char *name, char *ext, int32_t nameMaxLen) strcat(name, ext); - if (editor.ui.diskOpShown) + if (ui.diskOpShown) diskOp_DrawDirectory(); } void diskOpChangeFilenameExt(char *ext) { changeFilenameExt(FReq_FileName, ext, PATH_MAX); - if (editor.ui.diskOpShown) + if (ui.diskOpShown) diskOp_DrawDirectory(); } @@ -1136,7 +1137,7 @@ bool testDiskOpMouseDown(bool mouseHeldDlown) { int32_t tmpEntry, max; - if (!editor.ui.diskOpShown || FReq_FileCount == 0) + if (!ui.diskOpShown || FReq_FileCount == 0) return false; max = FReq_FileCount - FReq_DirPos; @@ -1200,7 +1201,7 @@ bool testDiskOpMouseDown(bool mouseHeldDlown) void testDiskOpMouseRelease(void) { - if (editor.ui.diskOpShown && FReq_EntrySelected != -1) + if (ui.diskOpShown && FReq_EntrySelected != -1) { if (mouse.x >= 169 && mouse.x <= 329 && mouse.y >= 4 && mouse.y <= 168) fileListPressed((mouse.y - 4) / (FONT1_CHAR_H + 1)); @@ -2071,7 +2072,7 @@ static void setDiskOpItemRadioButtons(void) if (FReq_Item == DISKOP_ITEM_PATTERN) radioButtons[RB_DISKOP_PAT_SAVEAS_XP].state = RADIOBUTTON_CHECKED; if (FReq_Item == DISKOP_ITEM_TRACK) radioButtons[RB_DISKOP_TRK_SAVEAS_XT].state = RADIOBUTTON_CHECKED; - if (editor.ui.diskOpShown) + if (ui.diskOpShown) { switch (FReq_Item) { @@ -2104,7 +2105,12 @@ static void setDiskOpItem(uint8_t item) case DISKOP_ITEM_MODULE: { FReq_FileName = modTmpFName; + + // FReq_ModCurPathU is always set at this point + FReq_CurPathU = FReq_ModCurPathU; + if (FReq_CurPathU != NULL) + UNICHAR_CHDIR(FReq_CurPathU); } break; @@ -2119,6 +2125,8 @@ static void setDiskOpItem(uint8_t item) } FReq_CurPathU = FReq_InsCurPathU; + if (FReq_CurPathU != NULL) + UNICHAR_CHDIR(FReq_CurPathU); } break; @@ -2133,6 +2141,8 @@ static void setDiskOpItem(uint8_t item) } FReq_CurPathU = FReq_SmpCurPathU; + if (FReq_CurPathU != NULL) + UNICHAR_CHDIR(FReq_CurPathU); } break; @@ -2142,11 +2152,13 @@ static void setDiskOpItem(uint8_t item) if (!patPathSet) { - UNICHAR_STRCPY(FReq_SmpCurPathU, FReq_CurPathU); + UNICHAR_STRCPY(FReq_PatCurPathU, FReq_CurPathU); patPathSet = true; } FReq_CurPathU = FReq_PatCurPathU; + if (FReq_CurPathU != NULL) + UNICHAR_CHDIR(FReq_CurPathU); } break; @@ -2161,6 +2173,8 @@ static void setDiskOpItem(uint8_t item) } FReq_CurPathU = FReq_TrkCurPathU; + if (FReq_CurPathU != NULL) + UNICHAR_CHDIR(FReq_CurPathU); } break; } @@ -2176,7 +2190,7 @@ static void setDiskOpItem(uint8_t item) FReq_ShowAllFiles = false; - if (editor.ui.diskOpShown) + if (ui.diskOpShown) { editor.diskOpReadDir = true; @@ -2275,12 +2289,12 @@ void showDiskOpScreen(void) firstTimeOpeningDiskOp = false; } - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); - editor.ui.diskOpShown = true; - editor.ui.scopesShown = false; + ui.diskOpShown = true; + ui.scopesShown = false; showTopRightMainScreen(); drawDiskOpScreen(); @@ -2322,19 +2336,19 @@ void hideDiskOpScreen(void) hideRadioButtonGroup(RB_GROUP_DISKOP_PAT_SAVEAS); hideRadioButtonGroup(RB_GROUP_DISKOP_TRK_SAVEAS); - editor.ui.diskOpShown = false; + ui.diskOpShown = false; } void exitDiskOpScreen(void) { hideDiskOpScreen(); - editor.ui.oldTopLeftScreen = 0; // disk op. ignores previously opened top screens + ui.oldTopLeftScreen = 0; // disk op. ignores previously opened top screens showTopScreen(true); } void toggleDiskOpScreen(void) { - if (editor.ui.diskOpShown) + if (ui.diskOpShown) exitDiskOpScreen(); else showDiskOpScreen(); diff --git a/src/ft2_edit.c b/src/ft2_edit.c @@ -14,6 +14,7 @@ #include "ft2_sysreqs.h" #include "ft2_textboxes.h" #include "ft2_tables.h" +#include "ft2_structs.h" enum { @@ -70,7 +71,7 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode) uint16_t pattLen; tonTyp *ton; - if (editor.cursor.object == CURSOR_NOTE) + if (cursor.object == CURSOR_NOTE) { // the edit cursor is at the note slot @@ -88,7 +89,7 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode) // convert key to slot data - if (editor.cursor.object == CURSOR_VOL1) + if (cursor.object == CURSOR_VOL1) { // volume column effect type (mixed keys) @@ -101,7 +102,7 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode) if (i == KEY2VOL_ENTRIES) i = -1; // invalid key for slot } - else if (editor.cursor.object == CURSOR_EFX0) + else if (cursor.object == CURSOR_EFX0) { // effect type (mixed keys) @@ -133,8 +134,8 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode) // insert slot data - ton = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + editor.cursor.ch]; - switch (editor.cursor.object) + ton = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch]; + switch (cursor.object) { case CURSOR_INST1: { @@ -234,7 +235,7 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode) if (i == 0) // if we inserted a zero, check if pattern is empty, for killing killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; return true; } @@ -352,7 +353,7 @@ void recordNote(uint8_t note, int8_t vol) } else { - c = editor.cursor.ch; + c = cursor.ch; } for (i = 0; i < song.antChn; i++) @@ -395,7 +396,7 @@ void recordNote(uint8_t note, int8_t vol) } else { - c = editor.cursor.ch; + c = cursor.ch; } for (i = 0; i < song.antChn; i++) @@ -454,7 +455,7 @@ void recordNote(uint8_t note, int8_t vol) } } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } } @@ -525,7 +526,7 @@ void recordNote(uint8_t note, int8_t vol) } } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } } @@ -547,7 +548,7 @@ bool handleEditKeys(SDL_Keycode keycode, SDL_Scancode scancode) if (patt[editor.editPattern] == NULL) return true; - note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + editor.cursor.ch]; + note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch]; if (keyb.leftShiftPressed) { @@ -569,7 +570,7 @@ bool handleEditKeys(SDL_Keycode keycode, SDL_Scancode scancode) } else { - if (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2) + if (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2) { // delete volume column note->vol = 0; @@ -589,7 +590,7 @@ bool handleEditKeys(SDL_Keycode keycode, SDL_Scancode scancode) if (playMode == PLAYMODE_EDIT && pattLen >= 1) setPos(-1, (editor.pattPos + editor.ID_Add) % pattLen, true); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); return true; @@ -615,12 +616,12 @@ void writeToMacroSlot(uint8_t slot) if (patt[editor.editPattern] != NULL) { - note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + editor.cursor.ch]; + note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch]; writeVol = note->vol; writeEff = (note->effTyp << 8) | note->eff; } - if (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2) + if (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2) config.volMacro[slot] = writeVol; else config.comMacro[slot] = writeEff; @@ -639,9 +640,9 @@ void writeFromMacroSlot(uint8_t slot) return; pattLen = pattLens[editor.editPattern]; - note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + editor.cursor.ch]; + note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch]; - if (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2) + if (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2) { note->vol = (uint8_t)config.volMacro[slot]; } @@ -666,7 +667,7 @@ void writeFromMacroSlot(uint8_t slot) killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -691,14 +692,14 @@ void insertPatternNote(void) if (pattLen > 1) { for (int32_t i = pattLen-2; i >= pattPos; i--) - pattPtr[((i + 1) * MAX_VOICES) + editor.cursor.ch] = pattPtr[(i * MAX_VOICES) + editor.cursor.ch]; + pattPtr[((i + 1) * MAX_VOICES) + cursor.ch] = pattPtr[(i * MAX_VOICES) + cursor.ch]; } - memset(&pattPtr[(pattPos * MAX_VOICES) + editor.cursor.ch], 0, sizeof (tonTyp)); + memset(&pattPtr[(pattPos * MAX_VOICES) + cursor.ch], 0, sizeof (tonTyp)); killPatternIfUnused(nr); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -734,7 +735,7 @@ void insertPatternLine(void) killPatternIfUnused(nr); } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -760,9 +761,9 @@ void deletePatternNote(void) editor.pattPos = song.pattPos = pattPos; for (int32_t i = pattPos; i < pattLen-1; i++) - pattPtr[(i * MAX_VOICES) + editor.cursor.ch] = pattPtr[((i + 1) * MAX_VOICES) + editor.cursor.ch]; + pattPtr[(i * MAX_VOICES) + cursor.ch] = pattPtr[((i + 1) * MAX_VOICES) + cursor.ch]; - memset(&pattPtr[((pattLen - 1) * MAX_VOICES) + editor.cursor.ch], 0, sizeof (tonTyp)); + memset(&pattPtr[((pattLen - 1) * MAX_VOICES) + cursor.ch], 0, sizeof (tonTyp)); } } else @@ -776,7 +777,7 @@ void deletePatternNote(void) killPatternIfUnused(nr); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -824,7 +825,7 @@ void deletePatternLine(void) killPatternIfUnused(nr); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -845,7 +846,7 @@ static void countOverflowingNotes(uint8_t currInsOnly, uint8_t transpMode, int8_ if (pattPtr == NULL) return; // empty pattern - pattPtr += editor.cursor.ch; + pattPtr += cursor.ch; pattLen = pattLens[editor.editPattern]; for (row = 0; row < pattLen; row++) @@ -976,7 +977,7 @@ void doTranspose(void) if (pattPtr == NULL) return; // empty pattern - pattPtr += editor.cursor.ch; + pattPtr += cursor.ch; pattLen = pattLens[editor.editPattern]; for (row = 0; row < pattLen; row++) @@ -1094,7 +1095,7 @@ void doTranspose(void) default: break; } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1401,19 +1402,19 @@ void cutTrack(void) { memset(trackCopyBuff, 0, MAX_PATT_LEN * sizeof (tonTyp)); for (i = 0; i < pattLen; i++) - copyNote(&pattPtr[(i * MAX_VOICES) + editor.cursor.ch], &trackCopyBuff[i]); + copyNote(&pattPtr[(i * MAX_VOICES) + cursor.ch], &trackCopyBuff[i]); trkBufLen = pattLen; } pauseMusic(); for (i = 0; i < pattLen; i++) - pasteNote(&clearNote, &pattPtr[(i * MAX_VOICES) + editor.cursor.ch]); + pasteNote(&clearNote, &pattPtr[(i * MAX_VOICES) + cursor.ch]); resumeMusic(); killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1430,7 +1431,7 @@ void copyTrack(void) memset(trackCopyBuff, 0, MAX_PATT_LEN * sizeof (tonTyp)); for (i = 0; i < pattLen; i++) - copyNote(&pattPtr[(i * MAX_VOICES) + editor.cursor.ch], &trackCopyBuff[i]); + copyNote(&pattPtr[(i * MAX_VOICES) + cursor.ch], &trackCopyBuff[i]); trkBufLen = pattLen; } @@ -1448,12 +1449,12 @@ void pasteTrack(void) pauseMusic(); for (i = 0; i < pattLen; i++) - pasteNote(&trackCopyBuff[i], &pattPtr[(i * MAX_VOICES) + editor.cursor.ch]); + pasteNote(&trackCopyBuff[i], &pattPtr[(i * MAX_VOICES) + cursor.ch]); resumeMusic(); killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1490,7 +1491,7 @@ void cutPattern(void) killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1514,7 +1515,7 @@ void copyPattern(void) ptnBufLen = pattLen; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void pastePattern(void) @@ -1547,7 +1548,7 @@ void pastePattern(void) killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1590,7 +1591,7 @@ void cutBlock(void) killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1631,7 +1632,7 @@ void pasteBlock(void) pattLen = pattLens[editor.editPattern]; - xpos = editor.cursor.ch; + xpos = cursor.ch; ypos = editor.pattPos; j = markXSize; @@ -1657,7 +1658,7 @@ void pasteBlock(void) killPatternIfUnused(editor.editPattern); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1702,7 +1703,7 @@ void remapBlock(void) editor.srcInstr, editor.curInstr); resumeMusic(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1713,12 +1714,12 @@ void remapTrack(void) pauseMusic(); remapInstrXY(editor.editPattern, - editor.cursor.ch, 0, - editor.cursor.ch, pattLens[editor.editPattern] - 1, + cursor.ch, 0, + cursor.ch, pattLens[editor.editPattern] - 1, editor.srcInstr, editor.curInstr); resumeMusic(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1734,7 +1735,7 @@ void remapPattern(void) editor.srcInstr, editor.curInstr); resumeMusic(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1757,7 +1758,7 @@ void remapSong(void) } resumeMusic(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } @@ -1882,7 +1883,7 @@ void scaleFadeVolumeTrack(void) pauseMusic(); for (uint16_t row = 0; row < pattLen; row++) { - scaleNote(editor.editPattern, editor.cursor.ch, row, dVol); + scaleNote(editor.editPattern, cursor.ch, row, dVol); dVol += dIPy; } resumeMusic(); diff --git a/src/ft2_events.c b/src/ft2_events.c @@ -31,10 +31,11 @@ #include "ft2_keyboard.h" #include "ft2_sample_ed.h" #include "ft2_sample_ed_features.h" +#include "ft2_structs.h" #define CRASH_TEXT "Oh no!\nThe Fasttracker II clone has crashed...\n\nA backup .xm was hopefully " \ - "saved to the current module directory.\n\nPlease report this to 8bitbubsy " \ - "(IRC or olav.sorensen@live.no).\nTry to mention what you did before the crash happened." + "saved to the current module directory.\n\nPlease report this bug if you can.\n" \ + "Try to mention what you did before the crash happened." static bool backupMadeAfterCrash; @@ -112,7 +113,7 @@ void handleEvents(void) midi.rescanDevicesFlag = false; rescanMidiInputDevices(); - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) drawMidiInputList(); } #endif @@ -158,15 +159,15 @@ void handleEvents(void) if (editor.diskOpReadDone) { editor.diskOpReadDone = false; - if (editor.ui.diskOpShown) + if (ui.diskOpShown) diskOp_DrawDirectory(); } handleLoadMusicEvents(); if (editor.samplingAudioFlag) handleSamplingUpdates(); - if (editor.ui.setMouseBusy) mouseAnimOn(); - if (editor.ui.setMouseIdle) mouseAnimOff(); + if (ui.setMouseBusy) mouseAnimOn(); + if (ui.setMouseIdle) mouseAnimOff(); if (editor.updateWindowTitle) { @@ -495,7 +496,7 @@ static void handleInput(void) } else if (event.type == SDL_QUIT) { - if (editor.ui.sysReqShown) + if (ui.sysReqShown) continue; if (editor.editTextFlag) diff --git a/src/ft2_gui.c b/src/ft2_gui.c @@ -22,6 +22,7 @@ #include "ft2_video.h" #include "ft2_tables.h" #include "ft2_bmp.h" +#include "ft2_structs.h" static void releaseMouseStates(void) { @@ -35,9 +36,9 @@ static void releaseMouseStates(void) mouse.buttonCounter = 0; mouse.lastX = 0; mouse.lastY = 0; - editor.ui.sampleDataOrLoopDrag = -1; - editor.ui.leftLoopPinMoving = false; - editor.ui.rightLoopPinMoving = false; + ui.sampleDataOrLoopDrag = -1; + ui.leftLoopPinMoving = false; + ui.rightLoopPinMoving = false; } void unstuckLastUsedGUIElement(void) @@ -53,16 +54,16 @@ void unstuckLastUsedGUIElement(void) ** sample data loop pins, and unstuck them if so */ - if (editor.ui.leftLoopPinMoving) + if (ui.leftLoopPinMoving) { setLeftLoopPinState(false); - editor.ui.leftLoopPinMoving = false; + ui.leftLoopPinMoving = false; } - if (editor.ui.rightLoopPinMoving) + if (ui.rightLoopPinMoving) { setRightLoopPinState(false); - editor.ui.rightLoopPinMoving = false; + ui.rightLoopPinMoving = false; } releaseMouseStates(); @@ -1052,36 +1053,36 @@ void drawFramework(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t type) void showTopLeftMainScreen(bool restoreScreens) { - editor.ui.diskOpShown = false; - editor.ui.sampleEditorExtShown = false; - editor.ui.instEditorExtShown = false; - editor.ui.transposeShown = false; - editor.ui.advEditShown = false; - editor.ui.wavRendererShown = false; - editor.ui.trimScreenShown = false; - - editor.ui.scopesShown = true; + ui.diskOpShown = false; + ui.sampleEditorExtShown = false; + ui.instEditorExtShown = false; + ui.transposeShown = false; + ui.advEditShown = false; + ui.wavRendererShown = false; + ui.trimScreenShown = false; + + ui.scopesShown = true; if (restoreScreens) { - switch (editor.ui.oldTopLeftScreen) + switch (ui.oldTopLeftScreen) { default: break; - case 1: editor.ui.diskOpShown = true; break; - case 2: editor.ui.sampleEditorExtShown = true; break; - case 3: editor.ui.instEditorExtShown = true; break; - case 4: editor.ui.transposeShown = true; break; - case 5: editor.ui.advEditShown = true; break; - case 6: editor.ui.wavRendererShown = true; break; - case 7: editor.ui.trimScreenShown = true; break; + case 1: ui.diskOpShown = true; break; + case 2: ui.sampleEditorExtShown = true; break; + case 3: ui.instEditorExtShown = true; break; + case 4: ui.transposeShown = true; break; + case 5: ui.advEditShown = true; break; + case 6: ui.wavRendererShown = true; break; + case 7: ui.trimScreenShown = true; break; } - if (editor.ui.oldTopLeftScreen > 0) - editor.ui.scopesShown = false; + if (ui.oldTopLeftScreen > 0) + ui.scopesShown = false; } - editor.ui.oldTopLeftScreen = 0; + ui.oldTopLeftScreen = 0; - if (editor.ui.diskOpShown) + if (ui.diskOpShown) { showDiskOpScreen(); } @@ -1157,7 +1158,7 @@ void showTopLeftMainScreen(bool restoreScreens) textOutShadow(4, 80, PAL_FORGRND, PAL_DSKTOP2, "Global volume"); drawGlobalVol(song.globVol); - editor.ui.updatePosSections = true; + ui.updatePosSections = true; textOutShadow(204, 80, PAL_FORGRND, PAL_DSKTOP2, "Time"); charOutShadow(250, 80, PAL_FORGRND, PAL_DSKTOP2, ':'); @@ -1165,14 +1166,14 @@ void showTopLeftMainScreen(bool restoreScreens) drawPlaybackTime(); - if (editor.ui.sampleEditorExtShown) drawSampleEditorExt(); - else if (editor.ui.instEditorExtShown) drawInstEditorExt(); - else if (editor.ui.transposeShown) drawTranspose(); - else if (editor.ui.advEditShown) drawAdvEdit(); - else if (editor.ui.wavRendererShown) drawWavRenderer(); - else if (editor.ui.trimScreenShown) drawTrimScreen(); + if (ui.sampleEditorExtShown) drawSampleEditorExt(); + else if (ui.instEditorExtShown) drawInstEditorExt(); + else if (ui.transposeShown) drawTranspose(); + else if (ui.advEditShown) drawAdvEdit(); + else if (ui.wavRendererShown) drawWavRenderer(); + else if (ui.trimScreenShown) drawTrimScreen(); - if (editor.ui.scopesShown) + if (ui.scopesShown) drawScopeFramework(); } } @@ -1187,7 +1188,7 @@ void hideTopLeftMainScreen(void) hideWavRenderer(); hideTrimScreen(); - editor.ui.scopesShown = false; + ui.scopesShown = false; // position editor hideScrollBar(SB_POS_ED); @@ -1251,7 +1252,7 @@ void showTopRightMainScreen(void) showPushButton(PB_HELP); // instrument switcher - editor.ui.instrSwitcherShown = true; + ui.instrSwitcherShown = true; showInstrumentSwitcher(); // song name @@ -1275,7 +1276,7 @@ void hideTopRightMainScreen(void) // instrument switcher hideInstrumentSwitcher(); - editor.ui.instrSwitcherShown = false; + ui.instrSwitcherShown = false; hideTextBox(TB_SONG_NAME); } @@ -1284,13 +1285,13 @@ void hideTopRightMainScreen(void) void setOldTopLeftScreenFlag(void) { - if (editor.ui.diskOpShown) editor.ui.oldTopLeftScreen = 1; - else if (editor.ui.sampleEditorExtShown) editor.ui.oldTopLeftScreen = 2; - else if (editor.ui.instEditorExtShown) editor.ui.oldTopLeftScreen = 3; - else if (editor.ui.transposeShown) editor.ui.oldTopLeftScreen = 4; - else if (editor.ui.advEditShown) editor.ui.oldTopLeftScreen = 5; - else if (editor.ui.wavRendererShown) editor.ui.oldTopLeftScreen = 6; - else if (editor.ui.trimScreenShown) editor.ui.oldTopLeftScreen = 7; + if (ui.diskOpShown) ui.oldTopLeftScreen = 1; + else if (ui.sampleEditorExtShown) ui.oldTopLeftScreen = 2; + else if (ui.instEditorExtShown) ui.oldTopLeftScreen = 3; + else if (ui.transposeShown) ui.oldTopLeftScreen = 4; + else if (ui.advEditShown) ui.oldTopLeftScreen = 5; + else if (ui.wavRendererShown) ui.oldTopLeftScreen = 6; + else if (ui.trimScreenShown) ui.oldTopLeftScreen = 7; } void hideTopLeftScreen(void) @@ -1315,44 +1316,44 @@ void hideTopScreen(void) hideAboutScreen(); hideHelpScreen(); - editor.ui.instrSwitcherShown = false; - editor.ui.scopesShown = false; + ui.instrSwitcherShown = false; + ui.scopesShown = false; } void showTopScreen(bool restoreScreens) { - editor.ui.scopesShown = false; + ui.scopesShown = false; - if (editor.ui.aboutScreenShown) + if (ui.aboutScreenShown) { showAboutScreen(); } - else if (editor.ui.configScreenShown) + else if (ui.configScreenShown) { showConfigScreen(); } - else if (editor.ui.helpScreenShown) + else if (ui.helpScreenShown) { showHelpScreen(); } - else if (editor.ui.nibblesShown) + else if (ui.nibblesShown) { showNibblesScreen(); } else { - showTopLeftMainScreen(restoreScreens); // updates editor.ui.scopesShown + showTopLeftMainScreen(restoreScreens); // updates ui.scopesShown showTopRightMainScreen(); } } void showBottomScreen(void) { - if (editor.ui.extended || editor.ui.patternEditorShown) + if (ui.extended || ui.patternEditorShown) showPatternEditor(); - else if (editor.ui.instEditorShown) + else if (ui.instEditorShown) showInstEditor(); - else if (editor.ui.sampleEditorShown) + else if (ui.sampleEditorShown) showSampleEditor(); } @@ -1363,5 +1364,5 @@ void drawGUIOnRunTime(void) showTopScreen(false); // false = don't restore screens showPatternEditor(); - editor.ui.updatePosSections = true; + ui.updatePosSections = true; } diff --git a/src/ft2_header.h b/src/ft2_header.h @@ -12,7 +12,7 @@ #endif #include "ft2_replayer.h" -#define PROG_VER_STR "1.22" +#define PROG_VER_STR "1.23" // do NOT change these! It will only mess things up... @@ -75,75 +75,3 @@ (((uint32_t)((value) & 0x00FF0000)) >> 8) | \ (((uint32_t)((value) & 0xFF000000)) >> 24) \ ) - -struct cpu_t -{ - bool hasSSE, hasSSE2; -} cpu; - -struct editor_t -{ - struct ui_t - { - volatile bool setMouseBusy, setMouseIdle; - bool sysReqEnterPressed; - char fullscreenButtonText[24]; - - // all screens - bool extended, sysReqShown; - - // top screens - bool instrSwitcherShown, aboutScreenShown, helpScreenShown, configScreenShown; - bool scopesShown, diskOpShown, nibblesShown, transposeShown, instEditorExtShown; - bool sampleEditorExtShown, advEditShown, wavRendererShown, trimScreenShown; - bool drawBPMFlag, drawSpeedFlag, drawGlobVolFlag, drawPosEdFlag, drawPattNumLenFlag; - bool updatePosSections, updatePosEdScrollBar; - uint8_t oldTopLeftScreen; - - // bottom screens - bool patternEditorShown, instEditorShown, sampleEditorShown, pattChanScrollShown; - bool leftLoopPinMoving, rightLoopPinMoving; - bool drawReplayerPianoFlag, drawPianoFlag, updatePatternEditor; - uint8_t channelOffset, numChannelsShown, maxVisibleChannels; - uint16_t patternChannelWidth; - int32_t sampleDataOrLoopDrag; - - // backup flag for when entering/exiting extended pattern editor (TODO: this is lame and shouldn't be hardcoded) - bool _aboutScreenShown, _helpScreenShown, _configScreenShown, _diskOpShown; - bool _nibblesShown, _transposeShown, _instEditorShown; - bool _instEditorExtShown, _sampleEditorExtShown, _patternEditorShown; - bool _sampleEditorShown, _advEditShown, _wavRendererShown, _trimScreenShown; - // ------------------------------------------------------------------------- - } ui; - - struct cursor_t - { - uint8_t ch; - int8_t object; - } cursor; - - UNICHAR binaryPathU[PATH_MAX + 2]; - UNICHAR *tmpFilenameU, *tmpInstrFilenameU; // used by saving/loading threads - UNICHAR *configFileLocation, *audioDevConfigFileLocation, *midiConfigFileLocation; - - volatile bool mainLoopOngoing; - volatile bool busy, scopeThreadMutex, programRunning, wavIsRendering, wavReachedEndFlag; - volatile bool updateCurSmp, updateCurInstr, diskOpReadDir, diskOpReadDone, updateWindowTitle; - volatile uint8_t loadMusicEvent; - volatile FILE *wavRendererFileHandle; - - bool autoPlayOnDrop, trimThreadWasDone, throwExit, editTextFlag; - bool copyMaskEnable, diskOpReadOnOpen, samplingAudioFlag, editSampleFlag; - bool instrBankSwapped, chnMode[MAX_VOICES], NI_Play; - - uint8_t curPlayInstr, curPlaySmp, curSmpChannel, currPanEnvPoint, currVolEnvPoint; - uint8_t copyMask[5], pasteMask[5], transpMask[5], smpEd_NoteNr, instrBankOffset, sampleBankOffset; - uint8_t srcInstr, curInstr, srcSmp, curSmp, currHelpScreen, currConfigScreen, textCursorBlinkCounter; - uint8_t keyOnTab[MAX_VOICES], ID_Add, curOctave; - uint8_t sampleSaveMode, moduleSaveMode, ptnJumpPos[4]; - int16_t globalVol, songPos, pattPos; - uint16_t tmpPattern, editPattern, speed, tempo, timer, ptnCursorY; - int32_t keyOffNr, keyOffTime[MAX_VOICES]; - uint32_t framesPassed, wavRendererTime; - double dPerfFreq, dPerfFreqMulMicro, dPerfFreqMulMs; -} editor; diff --git a/src/ft2_help.c b/src/ft2_help.c @@ -11,6 +11,7 @@ #include "ft2_video.h" #include "ft2_pattern_ed.h" #include "ft2_bmp.h" +#include "ft2_structs.h" #include "helpdata/ft2_help_data.h" typedef struct @@ -386,11 +387,11 @@ void showHelpScreen(void) { uint16_t tmpID; - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); - editor.ui.helpScreenShown = true; + ui.helpScreenShown = true; drawFramework(0, 0, 128, 173, FRAMEWORK_TYPE1); drawFramework(128, 0, 504, 173, FRAMEWORK_TYPE1); @@ -437,7 +438,7 @@ void hideHelpScreen(void) hideRadioButtonGroup(RB_GROUP_HELP); hideScrollBar(SB_HELP_SCROLL); - editor.ui.helpScreenShown = false; + ui.helpScreenShown = false; } void exitHelpScreen(void) diff --git a/src/ft2_inst_ed.c b/src/ft2_inst_ed.c @@ -21,6 +21,7 @@ #include "ft2_module_loader.h" #include "ft2_tables.h" #include "ft2_bmp.h" +#include "ft2_structs.h" #ifdef _MSC_VER #pragma pack(push) @@ -339,15 +340,15 @@ void sbMidiBendPos(uint32_t pos) void updateNewSample(void) { - if (editor.ui.instrSwitcherShown) + if (ui.instrSwitcherShown) updateInstrumentSwitcher(); updateSampleEditorSample(); - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) updateSampleEditor(); - if (editor.ui.instEditorShown || editor.ui.instEditorExtShown) + if (ui.instEditorShown || ui.instEditorExtShown) updateInstEditor(); } @@ -355,7 +356,7 @@ void updateNewInstrument(void) { updateTextBoxPointers(); - if (editor.ui.instrSwitcherShown) + if (ui.instrSwitcherShown) updateInstrumentSwitcher(); editor.currVolEnvPoint = 0; @@ -363,13 +364,13 @@ void updateNewInstrument(void) updateSampleEditorSample(); - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) updateSampleEditor(); - if (editor.ui.instEditorShown || editor.ui.instEditorExtShown) + if (ui.instEditorShown || ui.instEditorExtShown) updateInstEditor(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -1604,7 +1605,7 @@ bool testPianoKeysMouseDown(bool mouseButtonDown) uint8_t key, note, octave; int32_t mx, my, quotient, remainder; - if (!editor.ui.instEditorShown) + if (!ui.instEditorShown) return false; // area not clicked if (editor.curInstr == 0 || instr[editor.curInstr] == NULL) @@ -2024,7 +2025,7 @@ void handleInstEditorRedrawing(void) void hideInstEditor(void) { - editor.ui.instEditorShown = false; + ui.instEditorShown = false; hideScrollBar(SB_INST_VOL); hideScrollBar(SB_INST_PAN); @@ -2110,7 +2111,7 @@ void updateInstEditor(void) s = &ins->samp[editor.curSmp]; // update instrument editor extension - if (editor.ui.instEditorExtShown) + if (ui.instEditorExtShown) { checkBoxes[CB_INST_EXT_MIDI].checked = ins->midiOn ? true : false; checkBoxes[CB_INST_EXT_MUTE].checked = ins->mute ? true : false; @@ -2127,7 +2128,7 @@ void updateInstEditor(void) drawMIDIBend(); } - if (!editor.ui.instEditorShown) + if (!ui.instEditorShown) return; drawVolEnvSus(); @@ -2197,12 +2198,12 @@ void updateInstEditor(void) void showInstEditor(void) { - if (editor.ui.extended) exitPatternEditorExtended(); - if (editor.ui.sampleEditorShown) hideSampleEditor(); - if (editor.ui.sampleEditorExtShown) hideSampleEditorExt(); + if (ui.extended) exitPatternEditorExtended(); + if (ui.sampleEditorShown) hideSampleEditor(); + if (ui.sampleEditorExtShown) hideSampleEditorExt(); hidePatternEditor(); - editor.ui.instEditorShown = true; + ui.instEditorShown = true; drawFramework(0, 173, 438, 87, FRAMEWORK_TYPE1); drawFramework(0, 260, 438, 87, FRAMEWORK_TYPE1); @@ -2315,10 +2316,10 @@ void showInstEditor(void) void toggleInstEditor(void) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) hideSampleEditor(); - if (editor.ui.instEditorShown) + if (ui.instEditorShown) { exitInstEditor(); } @@ -2335,7 +2336,7 @@ bool testInstrVolEnvMouseDown(bool mouseButtonDown) int32_t x, y, mx, my, minX, maxX; instrTyp *ins; - if (!editor.ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL) + if (!ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL) return false; ins = instr[editor.curInstr]; @@ -2434,7 +2435,7 @@ bool testInstrPanEnvMouseDown(bool mouseButtonDown) int32_t x, y, mx, my, minX, maxX; instrTyp *ins; - if (!editor.ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL) + if (!ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL) return false; ins = instr[editor.curInstr]; @@ -2606,14 +2607,14 @@ void drawInstEditorExt(void) void showInstEditorExt(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); showTopScreen(false); - editor.ui.instEditorExtShown = true; - editor.ui.scopesShown = false; + ui.instEditorExtShown = true; + ui.scopesShown = false; drawInstEditorExt(); } @@ -2631,14 +2632,14 @@ void hideInstEditorExt(void) hidePushButton(PB_INST_EXT_MIDI_BEND_DOWN); hidePushButton(PB_INST_EXT_MIDI_BEND_UP); - editor.ui.instEditorExtShown = false; - editor.ui.scopesShown = true; + ui.instEditorExtShown = false; + ui.scopesShown = true; drawScopeFramework(); } void toggleInstEditorExt(void) { - if (editor.ui.instEditorExtShown) + if (ui.instEditorExtShown) hideInstEditorExt(); else showInstEditorExt(); @@ -2686,7 +2687,7 @@ static bool testInstrSwitcherNormal(void) // Welcome to the Jungle editor.srcInstr = newEntry; updateInstrumentSwitcher(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -2711,8 +2712,8 @@ static bool testInstrSwitcherNormal(void) // Welcome to the Jungle updateInstrumentSwitcher(); updateSampleEditorSample(); - if (editor.ui.sampleEditorShown) updateSampleEditor(); - else if (editor.ui.instEditorShown) updateInstEditor(); + if (ui.sampleEditorShown) updateSampleEditor(); + else if (ui.instEditorShown) updateInstEditor(); } return true; @@ -2763,7 +2764,7 @@ static bool testInstrSwitcherExtended(void) // Welcome to the Jungle 2 - The Hap editor.srcInstr = newEntry; updateInstrumentSwitcher(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -2805,7 +2806,7 @@ static bool testInstrSwitcherExtended(void) // Welcome to the Jungle 2 - The Hap editor.srcInstr = newEntry; updateInstrumentSwitcher(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -2836,10 +2837,10 @@ static bool testInstrSwitcherExtended(void) // Welcome to the Jungle 2 - The Hap bool testInstrSwitcherMouseDown(void) { - if (!editor.ui.instrSwitcherShown) + if (!ui.instrSwitcherShown) return false; - if (editor.ui.extended) + if (ui.extended) return testInstrSwitcherExtended(); else return testInstrSwitcherNormal(); diff --git a/src/ft2_keyboard.c b/src/ft2_keyboard.c @@ -22,9 +22,9 @@ #include "ft2_audio.h" #include "ft2_trim.h" #include "ft2_sample_ed_features.h" +#include "ft2_structs.h" -static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey); -static bool checkModifiedKeys(SDL_Keycode keycode); +keyb_t keyb; // globalized static const uint8_t scancodeKey2Note[52] = // keys (USB usage page standard) to FT2 notes look-up table { @@ -37,6 +37,9 @@ static const uint8_t scancodeKey2Note[52] = // keys (USB usage page standard) to 0x00, 0x0D, 0x0F, 0x11 }; +static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey); +static bool checkModifiedKeys(SDL_Keycode keycode); + int8_t scancodeKeyToNote(SDL_Scancode scancode) { int8_t note; @@ -76,18 +79,19 @@ void keyUpHandler(SDL_Scancode scancode, SDL_Keycode keycode) { (void)keycode; - if (editor.editTextFlag || editor.ui.sysReqShown) + if (editor.editTextFlag || ui.sysReqShown) return; // kludge: don't handle key up! (XXX: Is this hack really needed anymore?) /* Yet another kludge for not leaving a ghost key-up event after an inputBox/okBox - ** was exited with a key press. They could be picked up as note release events. */ + ** was exited with a key press. They could be picked up as note release events. + */ if (keyb.ignoreCurrKeyUp) { keyb.ignoreCurrKeyUp = false; return; } - if (editor.cursor.object == CURSOR_NOTE && !keyb.keyModifierDown) + if (cursor.object == CURSOR_NOTE && !keyb.keyModifierDown) testNoteKeysRelease(scancode); if (scancode == SDL_SCANCODE_KP_PLUS) @@ -105,12 +109,12 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode, bool keyWasRepea if (mouse.mode != MOUSE_MODE_NORMAL) setMouseMode(MOUSE_MODE_NORMAL); - if (editor.ui.sysReqShown) + if (ui.sysReqShown) { if (keycode == SDLK_RETURN) - editor.ui.sysReqEnterPressed = true; + ui.sysReqEnterPressed = true; else if (keycode == SDLK_ESCAPE) - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return; } @@ -161,7 +165,6 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode, bool keyWasRepea static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) { - bool audioWasntLocked; uint16_t pattLen; // if we're holding numpad plus but not pressing bank keys, don't check any other key @@ -308,9 +311,9 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) editor.ID_Add++; } - if (!editor.ui.nibblesShown && !editor.ui.configScreenShown && - !editor.ui.aboutScreenShown && !editor.ui.diskOpShown && - !editor.ui.helpScreenShown && !editor.ui.extended) + if (!ui.nibblesShown && !ui.configScreenShown && + !ui.aboutScreenShown && !ui.diskOpShown && + !ui.helpScreenShown && !ui.extended) { drawIDAdd(); } @@ -320,7 +323,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) default: break; } - // no normal key (keycode) pressed (XXX: shouldn't happen? Whatever...) + // no normal key (keycode) pressed (XXX: shouldn't happen..?) if (keycode == SDLK_UNKNOWN) return; @@ -331,7 +334,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_DELETE: // non-FT2 addition { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampCut(); } break; @@ -345,18 +348,19 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!allocatePattern(editor.editPattern)) break; - patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + editor.cursor.ch].ton = 97; + patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch].ton = 97; pattLen = pattLens[editor.editPattern]; if (playMode == PLAYMODE_EDIT && pattLen >= 1) setPos(-1, (editor.pattPos + editor.ID_Add) % pattLen, true); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; setSongModifiedFlag(); } } break; + // This is maybe not ideal to implement... //case SDLK_PRINTSCREEN: togglePatternEditorExtended(); break; // EDIT/PLAY KEYS @@ -382,7 +386,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) lockMixerCallback(); memset(editor.keyOnTab, 0, sizeof (editor.keyOnTab)); playMode = PLAYMODE_EDIT; - editor.ui.updatePosSections = true; // for updating mode text + ui.updatePosSections = true; // for updating mode text unlockMixerCallback(); } else @@ -482,7 +486,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } unlockAudio(); @@ -500,7 +504,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } unlockAudio(); @@ -518,7 +522,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } unlockAudio(); @@ -536,7 +540,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } unlockAudio(); @@ -556,7 +560,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_BACKSPACE: { - if (editor.ui.diskOpShown) diskOpGoParent(); + if (ui.diskOpShown) diskOpGoParent(); else if (keyb.leftShiftPressed) deletePatternLine(); else deletePatternNote(); } @@ -597,7 +601,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_PAGEUP: { - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -609,7 +613,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -619,7 +623,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_PAGEDOWN: { - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -631,7 +635,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -641,7 +645,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_HOME: { - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -649,7 +653,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -659,7 +663,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) case SDLK_END: { - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -667,7 +671,7 @@ static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -753,7 +757,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_a: if (keyb.leftCtrlPressed || keyb.leftCommandPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) rangeAll(); else showAdvEdit(); @@ -762,7 +766,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) } else if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) rangeAll(); else jumpToChannel(8); @@ -774,7 +778,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_b: if (keyb.leftCtrlPressed) { - if (!editor.ui.aboutScreenShown) + if (!ui.aboutScreenShown) showAboutScreen(); return true; @@ -784,26 +788,26 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_c: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) { sampCopy(); } else { // mark current track (non-FT2 feature) - pattMark.markX1 = editor.cursor.ch; + pattMark.markX1 = cursor.ch; pattMark.markX2 = pattMark.markX1; pattMark.markY1 = 0; pattMark.markY2 = pattLens[editor.editPattern]; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } return true; } else if (keyb.leftCtrlPressed || keyb.leftCommandPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampCopy(); else showConfigScreen(); @@ -820,7 +824,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) } else if (keyb.leftCtrlPressed) { - if (!editor.ui.diskOpShown) + if (!ui.diskOpShown) showDiskOpScreen(); return true; @@ -835,10 +839,10 @@ static bool checkModifiedKeys(SDL_Keycode keycode) } else if (keyb.leftCtrlPressed) { - if (editor.ui.aboutScreenShown) hideAboutScreen(); - if (editor.ui.configScreenShown) hideConfigScreen(); - if (editor.ui.helpScreenShown) hideHelpScreen(); - if (editor.ui.nibblesShown) hideNibblesScreen(); + if (ui.aboutScreenShown) hideAboutScreen(); + if (ui.configScreenShown) hideConfigScreen(); + if (ui.helpScreenShown) hideHelpScreen(); + if (ui.nibblesShown) hideNibblesScreen(); showSampleEditorExt(); return true; @@ -860,7 +864,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) video.showFPSCounter ^= 1; if (!video.showFPSCounter) { - if (editor.ui.extended) // yet another kludge... + if (ui.extended) // yet another kludge... exitPatternEditorExtended(); showTopScreen(false); @@ -926,10 +930,10 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_m: if (keyb.leftCtrlPressed) { - if (editor.ui.aboutScreenShown) hideAboutScreen(); - if (editor.ui.configScreenShown) hideConfigScreen(); - if (editor.ui.helpScreenShown) hideHelpScreen(); - if (editor.ui.nibblesShown) hideNibblesScreen(); + if (ui.aboutScreenShown) hideAboutScreen(); + if (ui.configScreenShown) hideConfigScreen(); + if (ui.helpScreenShown) hideHelpScreen(); + if (ui.nibblesShown) hideNibblesScreen(); showInstEditorExt(); @@ -948,11 +952,11 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_p: if (keyb.leftCtrlPressed) { - if (!editor.ui.patternEditorShown) + if (!ui.patternEditorShown) { - if (editor.ui.sampleEditorShown) hideSampleEditor(); - if (editor.ui.sampleEditorExtShown) hideSampleEditorExt(); - if (editor.ui.instEditorShown) hideInstEditor(); + if (ui.sampleEditorShown) hideSampleEditor(); + if (ui.sampleEditorExtShown) hideSampleEditorExt(); + if (ui.instEditorShown) hideInstEditor(); showPatternEditor(); } @@ -972,7 +976,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_r: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampCrop(); else jumpToChannel(3); @@ -989,7 +993,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_s: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) showRange(); else jumpToChannel(9); @@ -1027,25 +1031,25 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_v: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampPaste(); - else if (!editor.ui.instEditorShown) + else if (!ui.instEditorShown) scaleFadeVolumeBlock(); return true; } else if (keyb.leftCtrlPressed || keyb.leftCommandPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampPaste(); - else if (!editor.ui.instEditorShown) + else if (!ui.instEditorShown) scaleFadeVolumePattern(); return true; } else if (keyb.leftShiftPressed) { - if (!editor.ui.sampleEditorShown && !editor.ui.instEditorShown) + if (!ui.sampleEditorShown && !ui.instEditorShown) { keyb.ignoreTextEditKey = true; // ignore key from first frame scaleFadeVolumeTrack(); @@ -1066,29 +1070,29 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_x: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) sampCut(); return true; } else if (keyb.leftCtrlPressed || keyb.leftCommandPressed) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); - if (editor.ui.sampleEditorShown) hideSampleEditor(); - if (editor.ui.sampleEditorExtShown) hideSampleEditorExt(); - if (editor.ui.instEditorShown) hideInstEditor(); - if (editor.ui.instEditorExtShown) hideInstEditorExt(); - if (editor.ui.transposeShown) hideTranspose(); - if (editor.ui.aboutScreenShown) hideAboutScreen(); - if (editor.ui.configScreenShown) hideConfigScreen(); - if (editor.ui.helpScreenShown) hideHelpScreen(); - if (editor.ui.nibblesShown) hideNibblesScreen(); - if (editor.ui.diskOpShown) hideDiskOpScreen(); - if (editor.ui.advEditShown) hideAdvEdit(); - if (editor.ui.wavRendererShown) hideWavRenderer(); - if (editor.ui.trimScreenShown) hideTrimScreen(); + if (ui.sampleEditorShown) hideSampleEditor(); + if (ui.sampleEditorExtShown) hideSampleEditorExt(); + if (ui.instEditorShown) hideInstEditor(); + if (ui.instEditorExtShown) hideInstEditorExt(); + if (ui.transposeShown) hideTranspose(); + if (ui.aboutScreenShown) hideAboutScreen(); + if (ui.configScreenShown) hideConfigScreen(); + if (ui.helpScreenShown) hideHelpScreen(); + if (ui.nibblesShown) hideNibblesScreen(); + if (ui.diskOpShown) hideDiskOpScreen(); + if (ui.advEditShown) hideAdvEdit(); + if (ui.wavRendererShown) hideWavRenderer(); + if (ui.trimScreenShown) hideTrimScreen(); showTopScreen(false); showBottomScreen(); @@ -1110,7 +1114,7 @@ static bool checkModifiedKeys(SDL_Keycode keycode) case SDLK_z: if (keyb.leftAltPressed) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) zoomOut(); return true; diff --git a/src/ft2_keyboard.h b/src/ft2_keyboard.h @@ -4,13 +4,15 @@ #include <stdbool.h> #include <SDL2/SDL.h> -struct keyb_t +typedef struct keyb_t { uint8_t keyRepeat, keyPressed; bool ignoreCurrKeyUp, ignoreTextEditKey, numPadPlusPressed; bool keyModifierDown, commandPressed, leftCommandPressed; bool leftShiftPressed, leftCtrlPressed, ctrlPressed, leftAltPressed; -} keyb; +} keyb_t; + +extern keyb_t keyb; // ft2_keyboard.c int8_t scancodeKeyToNote(SDL_Scancode scancode); void keyUpHandler(SDL_Scancode scancode, SDL_Keycode keycode); diff --git a/src/ft2_main.c b/src/ft2_main.c @@ -32,6 +32,7 @@ #include "ft2_midi.h" #include "ft2_events.h" #include "ft2_bmp.h" +#include "ft2_structs.h" #ifdef HAS_MIDI static SDL_Thread *initMidiThread; @@ -77,8 +78,7 @@ int main(int argc, char *argv[]) #ifdef _WIN32 showErrorMsgBox("SDL2.dll is not the expected version, the program will terminate.\n\n" \ "Loaded dll version: %d.%d.%d\n" \ - "Required (compiled with) version: %d.%d.%d\n\n" \ - "The needed SDL2.dll is located in the .zip from 16-bits.org/ft2.php\n", + "Required (compiled with) version: %d.%d.%d\n\n", sdlVer.major, sdlVer.minor, sdlVer.patch, SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL); #else @@ -277,14 +277,14 @@ static void initializeVars(void) audio.locked = true; audio.rescanAudioDevicesSupported = true; - strcpy(editor.ui.fullscreenButtonText, "Go fullscreen"); + strcpy(ui.fullscreenButtonText, "Go fullscreen"); // set non-zero values editor.moduleSaveMode = MOD_SAVE_MODE_XM; editor.sampleSaveMode = SMP_SAVE_MODE_WAV; - editor.ui.sampleDataOrLoopDrag = -1; + ui.sampleDataOrLoopDrag = -1; mouse.lastUsedObjectID = OBJECT_ID_NONE; diff --git a/src/ft2_midi.c b/src/ft2_midi.c @@ -15,6 +15,7 @@ #include "ft2_audio.h" #include "ft2_mouse.h" #include "ft2_pattern_ed.h" +#include "ft2_structs.h" #include "rtmidi/rtmidi_c.h" // hide POSIX warnings @@ -22,7 +23,9 @@ #pragma warning(disable: 4996) #endif -// MIDI INPUT ONLY! +// This implements MIDI input only! + +midi_t midi; // globalized static volatile bool midiDeviceOpened; static bool recMIDIValidChn = true; @@ -251,7 +254,7 @@ void recordMIDIEffect(uint8_t effTyp, uint8_t effData) if (!allocatePattern(nr)) return; - note = &patt[nr][(editor.pattPos * MAX_VOICES) + editor.cursor.ch]; + note = &patt[nr][(editor.pattPos * MAX_VOICES) + cursor.ch]; if (note->effTyp != effTyp || note->eff != effData) setSongModifiedFlag(); @@ -460,7 +463,7 @@ void sbMidiInputSetPos(uint32_t pos) { (void)pos; - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT) drawMidiInputList(); } @@ -468,7 +471,7 @@ bool testMidiInputDeviceListMouseDown(void) { int32_t mx, my, deviceNum; - if (!editor.ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_MIDI_INPUT) + if (!ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_MIDI_INPUT) return false; // we didn't click the area if (!midi.initThreadDone) diff --git a/src/ft2_midi.h b/src/ft2_midi.h @@ -9,7 +9,7 @@ #define MIDI_INPUT_SELECTOR_BOX_WIDTH 247 #define MAX_MIDI_DEVICES 99 -struct midi_t +typedef struct midi_t { char *inputDeviceName, *inputDeviceNames[MAX_MIDI_DEVICES]; volatile bool closeMidiOnExit, initThreadDone; @@ -17,7 +17,9 @@ struct midi_t bool enable, rescanDevicesFlag; int16_t currMIDIVibDepth, currMIDIPitch; int32_t numInputDevices; -} midi; +} midi_t; + +extern midi_t midi; // ft2_midi.c void closeMidiInDevice(void); void freeMidiIn(void); diff --git a/src/ft2_module_loader.c b/src/ft2_module_loader.c @@ -25,6 +25,7 @@ #include "ft2_events.h" #include "ft2_video.h" #include "ft2_tables.h" +#include "ft2_structs.h" /* This is a *HUGE* mess! ** I hope you never have to modify it, and you probably shouldn't either. @@ -2461,7 +2462,7 @@ static void setupLoadedModule(void) diskOpSetFilename(DISKOP_ITEM_MODULE, editor.tmpFilenameU); // redraw top part of screen - if (editor.ui.extended) + if (ui.extended) { togglePatternEditorExtended(); // exit togglePatternEditorExtended(); // re-enter (force redrawing) @@ -2476,7 +2477,7 @@ static void setupLoadedModule(void) updateSampleEditorSample(); showBottomScreen(); // redraw bottom screen (also redraws pattern editor) - if (editor.ui.instEditorShown) + if (ui.instEditorShown) drawPiano(NULL); // redraw piano now (since if playing = wait for next tick update) removeSongModifiedFlag(); @@ -2549,7 +2550,7 @@ void loadDroppedFile(char *fullPathUTF8, bool songModifiedCheck) int32_t fullPathLen, filesize; UNICHAR *fullPathU; - if (editor.ui.sysReqShown || fullPathUTF8 == NULL) + if (ui.sysReqShown || fullPathUTF8 == NULL) return; fullPathLen = (int32_t)strlen(fullPathUTF8); diff --git a/src/ft2_module_saver.c b/src/ft2_module_saver.c @@ -12,6 +12,7 @@ #include "ft2_sample_ed.h" #include "ft2_module_loader.h" #include "ft2_tables.h" +#include "ft2_structs.h" /* These savers are directly ported, so they should act identical to FT2 ** except for some very minor changes. diff --git a/src/ft2_mouse.c b/src/ft2_mouse.c @@ -19,23 +19,26 @@ #include "ft2_audioselector.h" #include "ft2_midi.h" #include "ft2_bmp.h" +#include "ft2_structs.h" #define NUM_CURSORS 6 +mouse_t mouse; // globalized + static bool mouseBusyGfxBackwards; static int16_t mouseShape; static int32_t mouseModeGfxOffs, mouseBusyGfxFrame; static SDL_Cursor *cursors[NUM_CURSORS]; -static bool setSystemCursor(SDL_Cursor *cursor) +static bool setSystemCursor(SDL_Cursor *cur) { - if (cursor == NULL) + if (cur == NULL) { SDL_SetCursor(SDL_GetDefaultCursor()); return false; } - SDL_SetCursor(cursor); + SDL_SetCursor(cur); return true; } @@ -298,7 +301,7 @@ static void changeCursorIfOverTextBoxes(void) for (i = 0; i < NUM_TEXTBOXES; i++) { - if (editor.ui.sysReqShown && i > 0) + if (ui.sysReqShown && i > 0) continue; t = &textBoxes[i]; @@ -345,20 +348,20 @@ void setMouseBusy(bool busy) // can be called from other threads { if (busy) { - editor.ui.setMouseIdle = false; - editor.ui.setMouseBusy = true; + ui.setMouseIdle = false; + ui.setMouseBusy = true; } else { - editor.ui.setMouseBusy = false; - editor.ui.setMouseIdle = true; + ui.setMouseBusy = false; + ui.setMouseIdle = true; } } void mouseAnimOn(void) { - editor.ui.setMouseBusy = false; - editor.ui.setMouseIdle = false; + ui.setMouseBusy = false; + ui.setMouseIdle = false; editor.busy = true; setMouseShape(config.mouseAnimType); @@ -366,8 +369,8 @@ void mouseAnimOn(void) void mouseAnimOff(void) { - editor.ui.setMouseBusy = false; - editor.ui.setMouseIdle = false; + ui.setMouseBusy = false; + ui.setMouseIdle = false; editor.busy = false; setMouseShape(config.mouseType); @@ -403,10 +406,10 @@ static void mouseWheelIncRow(void) void mouseWheelHandler(bool directionUp) { - if (editor.ui.sysReqShown || editor.editTextFlag) + if (ui.sysReqShown || editor.editTextFlag) return; - if (editor.ui.extended) + if (ui.extended) { if (mouse.y <= 52) { @@ -425,7 +428,7 @@ void mouseWheelHandler(bool directionUp) { // top screens - if (editor.ui.helpScreenShown) + if (ui.helpScreenShown) { // help screen @@ -440,7 +443,7 @@ void mouseWheelHandler(bool directionUp) helpScrollDown(); } } - else if (editor.ui.diskOpShown) + else if (ui.diskOpShown) { // disk op - 3x speed if (mouse.x <= 355) @@ -459,7 +462,7 @@ void mouseWheelHandler(bool directionUp) } } } - else if (editor.ui.configScreenShown) + else if (ui.configScreenShown) { if (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) { @@ -482,15 +485,15 @@ void mouseWheelHandler(bool directionUp) #endif } - if (!editor.ui.aboutScreenShown && !editor.ui.helpScreenShown && - !editor.ui.configScreenShown && !editor.ui.nibblesShown) + if (!ui.aboutScreenShown && !ui.helpScreenShown && + !ui.configScreenShown && !ui.nibblesShown) { if (mouse.x >= 421 && mouse.y <= 173) { if (mouse.y <= 93) directionUp ? decCurIns() : incCurIns(); else if (mouse.y >= 94) directionUp ? decCurSmp() : incCurSmp(); } - else if (!editor.ui.diskOpShown && mouse.x <= 111 && mouse.y <= 76) + else if (!ui.diskOpShown && mouse.x <= 111 && mouse.y <= 76) { directionUp ? decSongPos() : incSongPos(); } @@ -500,12 +503,12 @@ void mouseWheelHandler(bool directionUp) { // bottom screens - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) { if (mouse.y >= 174 && mouse.y <= 328) directionUp ? mouseZoomSampleDataIn() : mouseZoomSampleDataOut(); } - else if (editor.ui.patternEditorShown) + else if (ui.patternEditorShown) { directionUp ? mouseWheelDecRow() : mouseWheelIncRow(); } @@ -514,7 +517,7 @@ void mouseWheelHandler(bool directionUp) static bool testSamplerDataMouseDown(void) { - if (editor.ui.sampleEditorShown && mouse.y >= 174 && mouse.y <= 327 && editor.ui.sampleDataOrLoopDrag == -1) + if (ui.sampleEditorShown && mouse.y >= 174 && mouse.y <= 327 && ui.sampleDataOrLoopDrag == -1) { handleSampleDataMouseDown(false); return true; @@ -527,10 +530,10 @@ static bool testPatternDataMouseDown(void) { uint16_t y1, y2; - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) { - y1 = editor.ui.extended ? 56 : 176; - y2 = editor.ui.pattChanScrollShown ? 382 : 396; + y1 = ui.extended ? 56 : 176; + y2 = ui.pattChanScrollShown ? 382 : 396; if (mouse.y >= y1 && mouse.y <= y2 && mouse.x >= 29 && mouse.x <= 602) { @@ -549,16 +552,16 @@ void mouseButtonUpHandler(uint8_t mouseButton) mouse.leftButtonPressed = false; mouse.leftButtonReleased = true; - if (editor.ui.leftLoopPinMoving) + if (ui.leftLoopPinMoving) { setLeftLoopPinState(false); - editor.ui.leftLoopPinMoving = false; + ui.leftLoopPinMoving = false; } - if (editor.ui.rightLoopPinMoving) + if (ui.rightLoopPinMoving) { setRightLoopPinState(false); - editor.ui.rightLoopPinMoving = false; + ui.rightLoopPinMoving = false; } } else if (mouseButton == SDL_BUTTON_RIGHT) @@ -574,7 +577,7 @@ void mouseButtonUpHandler(uint8_t mouseButton) resumeAudio(); - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) writeSample(true); setSongModifiedFlag(); @@ -591,13 +594,13 @@ void mouseButtonUpHandler(uint8_t mouseButton) if ( mouse.leftButtonPressed && !mouse.rightButtonPressed) return; if (!mouse.leftButtonPressed && mouse.rightButtonPressed) return; - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) testSmpEdMouseUp(); mouse.lastX = 0; mouse.lastY = 0; - editor.ui.sampleDataOrLoopDrag = -1; + ui.sampleDataOrLoopDrag = -1; // check if we released a GUI object testDiskOpMouseRelease(); @@ -622,14 +625,14 @@ void mouseButtonDownHandler(uint8_t mouseButton) // if already holding left button and clicking right, don't do mouse down handling if (mouseButton == SDL_BUTTON_RIGHT && mouse.leftButtonPressed) { - if (editor.ui.sampleDataOrLoopDrag == -1) + if (ui.sampleDataOrLoopDrag == -1) { mouse.rightButtonPressed = true; mouse.rightButtonReleased = false; } // kludge - we must do scope solo/unmute all here - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) testScopesMouseDown(); return; @@ -638,14 +641,14 @@ void mouseButtonDownHandler(uint8_t mouseButton) // if already holding right button and clicking left, don't do mouse down handling if (mouseButton == SDL_BUTTON_LEFT && mouse.rightButtonPressed) { - if (editor.ui.sampleDataOrLoopDrag == -1) + if (ui.sampleDataOrLoopDrag == -1) { mouse.leftButtonPressed = true; mouse.leftButtonReleased = false; } // kludge - we must do scope solo/unmute all here - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) testScopesMouseDown(); return; @@ -701,7 +704,7 @@ void mouseButtonDownHandler(uint8_t mouseButton) if (testRadioButtonMouseDown()) return; // at this point, we don't need to test more widgets if a system request is shown - if (editor.ui.sysReqShown) + if (ui.sysReqShown) return; if (testInstrVolEnvMouseDown(false)) return; diff --git a/src/ft2_mouse.h b/src/ft2_mouse.h @@ -13,7 +13,7 @@ enum MOUSE_WHEEL_UP = 1 }; -struct mouse_t +typedef struct mouse_t { volatile bool setPosFlag; bool leftButtonPressed, rightButtonPressed, leftButtonReleased, rightButtonReleased; @@ -23,7 +23,9 @@ struct mouse_t int32_t x, y, lastX, lastY, xBias, yBias, setPosX, setPosY; int32_t lastScrollX, lastScrollXTmp, lastScrollY, saveMouseX, saveMouseY; uint32_t buttonState; -} mouse; +} mouse_t; + +extern mouse_t mouse; // ft2_mouse.c // do not change these! #define MOUSE_CURSOR_W 26 diff --git a/src/ft2_nibbles.c b/src/ft2_nibbles.c @@ -10,6 +10,7 @@ #include "ft2_pattern_ed.h" #include "ft2_bmp.h" #include "ft2_tables.h" +#include "ft2_structs.h" #define NI_MAXLEVEL 30 @@ -561,7 +562,7 @@ void moveNibblePlayers(void) { int16_t i, j; - if (editor.ui.sysReqShown || --NI_CurTick60Hz != 0) + if (ui.sysReqShown || --NI_CurTick60Hz != 0) return; if (nibblesBufferFull(0)) @@ -731,11 +732,11 @@ NoMove: void showNibblesScreen(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); - editor.ui.nibblesShown = true; + ui.nibblesShown = true; drawFramework(0, 0, 632, 3, FRAMEWORK_TYPE1); drawFramework(0, 3, 148, 49, FRAMEWORK_TYPE1); @@ -812,7 +813,7 @@ void hideNibblesScreen(void) hideCheckBox(CB_NIBBLES_GRID); hideCheckBox(CB_NIBBLES_WRAP); - editor.ui.nibblesShown = false; + ui.nibblesShown = false; } void exitNibblesScreen(void) diff --git a/src/ft2_pattern_draw.c b/src/ft2_pattern_draw.c @@ -12,6 +12,7 @@ #include "ft2_video.h" #include "ft2_tables.h" #include "ft2_bmp.h" +#include "ft2_structs.h" static tonTyp emptyPattern[MAX_VOICES * MAX_PATT_LEN]; @@ -58,14 +59,14 @@ void drawPatternBorders(void) const pattCoord2_t *pattCoord; // get heights/pos/rows depending on configuration - pattCoord = &pattCoord2Table[config.ptnUnpressed][editor.ui.pattChanScrollShown][editor.ui.extended]; + pattCoord = &pattCoord2Table[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended]; // set pattern cursor Y position editor.ptnCursorY = pattCoord->lowerRowsY - 9; - chans = editor.ui.numChannelsShown; - if (chans > editor.ui.maxVisibleChannels) - chans = editor.ui.maxVisibleChannels; + chans = ui.numChannelsShown; + if (chans > ui.maxVisibleChannels) + chans = ui.maxVisibleChannels; // in some configurations, there will be two empty channels to the right, fix that if (chans == 2) @@ -78,14 +79,14 @@ void drawPatternBorders(void) chanWidth = chanWidths[(chans / 2) - 1] + 2; // fill scrollbar framework (if needed) - if (editor.ui.pattChanScrollShown) + if (ui.pattChanScrollShown) drawFramework(0, 383, 632, 17, FRAMEWORK_TYPE1); if (config.ptnFrmWrk) { // pattern editor w/ framework - if (editor.ui.extended) + if (ui.extended) { vLine(0, 54, 345, PAL_DSKTOP1); vLine(631, 53, 346, PAL_DSKTOP2); @@ -96,7 +97,7 @@ void drawPatternBorders(void) hLine(0, 53, 631, PAL_DSKTOP1); hLine(1, 54, 630, PAL_DESKTOP); - if (!editor.ui.pattChanScrollShown) + if (!ui.pattChanScrollShown) { hLine(1, 398, 630, PAL_DESKTOP); hLine(0, 399, 632, PAL_DSKTOP2); @@ -113,7 +114,7 @@ void drawPatternBorders(void) hLine(0, 173, 631, PAL_DSKTOP1); hLine(1, 174, 630, PAL_DESKTOP); - if (!editor.ui.pattChanScrollShown) + if (!ui.pattChanScrollShown) { hLine(1, 398, 630, PAL_DESKTOP); hLine(0, 399, 632, PAL_DSKTOP2); @@ -149,21 +150,21 @@ void drawPatternBorders(void) { // pattern editor without framework - if (editor.ui.extended) + if (ui.extended) { - clearSize = editor.ui.pattChanScrollShown ? (SCREEN_W * sizeof (int32_t) * 330) : (SCREEN_W * sizeof (int32_t) * 347); + clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof (int32_t) * 330) : (SCREEN_W * sizeof (int32_t) * 347); memset(&video.frameBuffer[53 * SCREEN_W], 0, clearSize); } else { - clearSize = editor.ui.pattChanScrollShown ? (SCREEN_W * sizeof(int32_t) * 210) : (SCREEN_W * sizeof(int32_t) * 227); + clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof(int32_t) * 210) : (SCREEN_W * sizeof(int32_t) * 227); memset(&video.frameBuffer[173 * SCREEN_W], 0, clearSize); } drawFramework(0, pattCoord->lowerRowsY - 10, SCREEN_W, 11, FRAMEWORK_TYPE1); } - if (editor.ui.pattChanScrollShown) + if (ui.pattChanScrollShown) { showScrollBar(SB_CHAN_SCROLL); showPushButton(PB_CHAN_SCROLL_LEFT); @@ -183,13 +184,13 @@ static void writeCursor(void) { uint32_t *dstPtr, xPos, width, tabOffset; - tabOffset = (config.ptnS3M * 32) + (columnModeTab[editor.ui.numChannelsShown - 1] * 8) + editor.cursor.object; + tabOffset = (config.ptnS3M * 32) + (columnModeTab[ui.numChannelsShown - 1] * 8) + cursor.object; xPos = pattCursorXTab[tabOffset]; width = pattCursorWTab[tabOffset]; assert(editor.ptnCursorY > 0 && xPos > 0 && width > 0); - xPos += ((editor.cursor.ch - editor.ui.channelOffset) * editor.ui.patternChannelWidth); + xPos += ((cursor.ch - ui.channelOffset) * ui.patternChannelWidth); dstPtr = &video.frameBuffer[(editor.ptnCursorY * SCREEN_W) + xPos]; for (uint32_t y = 0; y < 9; y++) @@ -211,8 +212,8 @@ static void writePatternBlockMark(int32_t currRow, uint32_t rowHeight, const pat if (pattMark.markY1 > pattMark.markY2) return; - startCh = editor.ui.channelOffset; - endCh = editor.ui.channelOffset + (editor.ui.numChannelsShown - 1); + startCh = ui.channelOffset; + endCh = ui.channelOffset + (ui.numChannelsShown - 1); startRow = currRow - pattCoord->numUpperRows; endRow = currRow + pattCoord->numLowerRows; @@ -220,18 +221,18 @@ static void writePatternBlockMark(int32_t currRow, uint32_t rowHeight, const pat if (pattMark.markX1 > endCh || pattMark.markX2 < startCh || pattMark.markY1 > endRow || pattMark.markY2 < startRow) return; - markCoord = &markCoordTable[config.ptnUnpressed][editor.ui.pattChanScrollShown][editor.ui.extended]; + markCoord = &markCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended]; pattYStart = markCoord->upperRowsY; // X1 - x1 = 32 + ((pattMark.markX1 - editor.ui.channelOffset) * editor.ui.patternChannelWidth); + x1 = 32 + ((pattMark.markX1 - ui.channelOffset) * ui.patternChannelWidth); if (x1 < 32) x1 = 32; // X2 - x2 = (32 - 8) + (((pattMark.markX2 + 1) - editor.ui.channelOffset) * editor.ui.patternChannelWidth); + x2 = (32 - 8) + (((pattMark.markX2 + 1) - ui.channelOffset) * ui.patternChannelWidth); if (x2 > 608) x2 = 608; @@ -272,7 +273,7 @@ static void writePatternBlockMark(int32_t currRow, uint32_t rowHeight, const pat } // kludge! (some mark situations could overwrite illegal areas) - if (config.ptnUnpressed && editor.ui.pattChanScrollShown) + if (config.ptnUnpressed && ui.pattChanScrollShown) { if (y1 == pattCoord->upperRowsY-1 || y1 == pattCoord->lowerRowsY-1) y1++; @@ -310,9 +311,9 @@ static void drawChannelNumbering(uint16_t yPos) #define CH_NUM_XPOS 30 uint16_t xPos = CH_NUM_XPOS; - int32_t ch = editor.ui.channelOffset + 1; + int32_t ch = ui.channelOffset + 1; - for (uint8_t i = 0; i < editor.ui.numChannelsShown; i++) + for (uint8_t i = 0; i < ui.numChannelsShown; i++) { if (ch < 10) { @@ -325,7 +326,7 @@ static void drawChannelNumbering(uint16_t yPos) } ch++; - xPos += editor.ui.patternChannelWidth; + xPos += ui.patternChannelWidth; } } @@ -385,7 +386,7 @@ static void showNoteNum(uint32_t xPos, uint32_t yPos, int16_t ton, uint32_t colo assert(ton >= 0 && ton <= 97); - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { if (ton <= 0 || ton > 97) drawEmptyNoteBig(xPos, yPos, color); @@ -409,13 +410,13 @@ static void showInstrNum(uint32_t xPos, uint32_t yPos, uint8_t ins, uint32_t col { uint8_t chr1, chr2, charW, fontType; - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; xPos += 67; } - else if (editor.ui.numChannelsShown <= 6) + else if (ui.numChannelsShown <= 6) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -450,7 +451,7 @@ static void showVolEfx(uint32_t xPos, uint32_t yPos, uint8_t vol, uint32_t color { uint8_t char1, char2, fontType, charW; - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -462,7 +463,7 @@ static void showVolEfx(uint32_t xPos, uint32_t yPos, uint8_t vol, uint32_t color else char2 = vol & 0x0F; } - else if (editor.ui.numChannelsShown <= 6) + else if (ui.numChannelsShown <= 6) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -495,13 +496,13 @@ static void showEfx(uint32_t xPos, uint32_t yPos, uint8_t effTyp, uint8_t eff, u { uint8_t fontType, charW; - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; xPos += 115; } - else if (editor.ui.numChannelsShown <= 6) + else if (ui.numChannelsShown <= 6) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -527,7 +528,7 @@ static void showNoteNumNoVolColumn(uint32_t xPos, uint32_t yPos, int16_t ton, ui assert(ton >= 0 && ton <= 97); - if (editor.ui.numChannelsShown <= 6) + if (ui.numChannelsShown <= 6) { if (ton <= 0 || ton > 97) drawEmptyNoteBig(xPos, yPos, color); @@ -536,7 +537,7 @@ static void showNoteNumNoVolColumn(uint32_t xPos, uint32_t yPos, int16_t ton, ui else drawNoteBig(xPos, yPos, ton, color); } - else if (editor.ui.numChannelsShown <= 8) + else if (ui.numChannelsShown <= 8) { if (ton <= 0 || ton > 97) drawEmptyNoteMedium(xPos, yPos, color); @@ -560,19 +561,19 @@ static void showInstrNumNoVolColumn(uint32_t xPos, uint32_t yPos, uint8_t ins, u { uint8_t chr1, chr2, charW, fontType; - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { fontType = FONT_TYPE5; charW = FONT5_CHAR_W; xPos += 59; } - else if (editor.ui.numChannelsShown <= 6) + else if (ui.numChannelsShown <= 6) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; xPos += 51; } - else if (editor.ui.numChannelsShown <= 8) + else if (ui.numChannelsShown <= 8) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -616,19 +617,19 @@ static void showEfxNoVolColumn(uint32_t xPos, uint32_t yPos, uint8_t effTyp, uin { uint8_t charW, fontType; - if (editor.ui.numChannelsShown <= 4) + if (ui.numChannelsShown <= 4) { fontType = FONT_TYPE5; charW = FONT5_CHAR_W; xPos += 91; } - else if (editor.ui.numChannelsShown <= 6) + else if (ui.numChannelsShown <= 6) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; xPos += 67; } - else if (editor.ui.numChannelsShown <= 8) + else if (ui.numChannelsShown <= 8) { fontType = FONT_TYPE4; charW = FONT4_CHAR_W; @@ -667,19 +668,19 @@ void writePattern(int32_t currRow, int32_t pattern) // setup variables - chans = editor.ui.numChannelsShown; - if (chans > editor.ui.maxVisibleChannels) - chans = editor.ui.maxVisibleChannels; + chans = ui.numChannelsShown; + if (chans > ui.maxVisibleChannels) + chans = ui.maxVisibleChannels; assert(chans >= 2 && chans <= 12); // get channel width chanWidth = chanWidths[(chans / 2) - 1]; - editor.ui.patternChannelWidth = (uint16_t)(chanWidth + 3); + ui.patternChannelWidth = (uint16_t)(chanWidth + 3); // get heights/pos/rows depending on configuration rowHeight = config.ptnUnpressed ? 11 : 8; - pattCoord = &pattCoordTable[config.ptnUnpressed][editor.ui.pattChanScrollShown][editor.ui.extended]; + pattCoord = &pattCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended]; midRowTextY = pattCoord->midRowTextY; lowerRowsTextY = pattCoord->lowerRowsTextY; row = currRow - pattCoord->numUpperRows; @@ -687,7 +688,7 @@ void writePattern(int32_t currRow, int32_t pattern) textY = pattCoord->upperRowsTextY; afterCurrRow = currRow + 1; - numChannels = editor.ui.numChannelsShown; + numChannels = ui.numChannelsShown; pattPtr = patt[pattern]; numRows = pattLens[pattern]; noteTextColors[0] = video.palette[PAL_PATTEXT]; // not selected @@ -695,7 +696,7 @@ void writePattern(int32_t currRow, int32_t pattern) // increment pattern data pointer by horizontal scrollbar offset/channel if (pattPtr != NULL) - pattPtr += editor.ui.channelOffset; + pattPtr += ui.channelOffset; // set up function pointers for drawing if (config.ptnS3M) @@ -728,7 +729,7 @@ void writePattern(int32_t currRow, int32_t pattern) note = &pattPtr[(uint32_t)row * MAX_VOICES]; xPos = 29; - xWidth = editor.ui.patternChannelWidth; + xWidth = ui.patternChannelWidth; color = noteTextColors[selectedRowFlag]; for (int32_t j = 0; j < numChannels; j++) diff --git a/src/ft2_pattern_ed.c b/src/ft2_pattern_ed.c @@ -21,6 +21,9 @@ #include "ft2_video.h" #include "ft2_tables.h" #include "ft2_bmp.h" +#include "ft2_structs.h" + +pattMark_t pattMark; // globalized // for pattern marking w/ keyboard static int8_t lastChMark; @@ -41,14 +44,12 @@ static int32_t last_TimeH, last_TimeM, last_TimeS; bool allocatePattern(uint16_t nr) // for tracker use only, not in loader! { - bool audioWasntLocked; + const bool audioWasntLocked = !audio.locked; + if (audioWasntLocked) + lockAudio(); if (patt[nr] == NULL) { - audioWasntLocked = !audio.locked; - if (audioWasntLocked) - lockAudio(); - /* Original FT2 allocates only the amount of rows needed, but we don't ** do that to avoid out of bondary row look-up between out-of-sync replayer ** state and tracker state (yes it used to happen, rarely). We're not wasting @@ -67,33 +68,31 @@ bool allocatePattern(uint16_t nr) // for tracker use only, not in loader! // XXX: Do we really need this? Sounds redundant. song.pattLen = pattLens[nr]; - - if (audioWasntLocked) - unlockAudio(); } + if (audioWasntLocked) + unlockAudio(); + return true; } void killPatternIfUnused(uint16_t nr) // for tracker use only, not in loader! { - bool audioWasntLocked; + const bool audioWasntLocked = !audio.locked; + if (audioWasntLocked) + lockAudio(); if (patternEmpty(nr)) { - audioWasntLocked = !audio.locked; - if (audioWasntLocked) - lockAudio(); - if (patt[nr] != NULL) { free(patt[nr]); patt[nr] = NULL; } - - if (audioWasntLocked) - unlockAudio(); } + + if (audioWasntLocked) + unlockAudio(); } uint8_t getMaxVisibleChannels(void) @@ -119,12 +118,12 @@ uint8_t getMaxVisibleChannels(void) void updatePatternWidth(void) { - if (editor.ui.numChannelsShown > editor.ui.maxVisibleChannels) - editor.ui.numChannelsShown = editor.ui.maxVisibleChannels; + if (ui.numChannelsShown > ui.maxVisibleChannels) + ui.numChannelsShown = ui.maxVisibleChannels; - assert(editor.ui.numChannelsShown >= 2 && editor.ui.numChannelsShown <= 12); + assert(ui.numChannelsShown >= 2 && ui.numChannelsShown <= 12); - editor.ui.patternChannelWidth = chanWidths[(editor.ui.numChannelsShown / 2) - 1] + 3; + ui.patternChannelWidth = chanWidths[(ui.numChannelsShown / 2) - 1] + 3; } void updateAdvEdit(void) @@ -205,7 +204,7 @@ void drawAdvEdit(void) void hideAdvEdit(void) { - editor.ui.advEditShown = false; + ui.advEditShown = false; hidePushButton(PB_REMAP_TRACK); hidePushButton(PB_REMAP_PATTERN); @@ -229,26 +228,26 @@ void hideAdvEdit(void) hideCheckBox(CB_TRANSP_MASK_3); hideCheckBox(CB_TRANSP_MASK_4); - editor.ui.scopesShown = true; + ui.scopesShown = true; drawScopeFramework(); } void showAdvEdit(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); showTopScreen(false); - editor.ui.advEditShown = true; - editor.ui.scopesShown = false; + ui.advEditShown = true; + ui.scopesShown = false; drawAdvEdit(); } void toggleAdvEdit(void) { - if (editor.ui.advEditShown) + if (ui.advEditShown) hideAdvEdit(); else showAdvEdit(); @@ -307,14 +306,14 @@ void drawTranspose(void) void showTranspose(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); showTopScreen(false); - editor.ui.transposeShown = true; - editor.ui.scopesShown = false; + ui.transposeShown = true; + ui.scopesShown = false; drawTranspose(); } @@ -353,14 +352,14 @@ void hideTranspose(void) hidePushButton(PB_TRANSP_ALL_INS_BLK_12UP); hidePushButton(PB_TRANSP_ALL_INS_BLK_12DN); - editor.ui.transposeShown = false; - editor.ui.scopesShown = true; + ui.transposeShown = false; + ui.scopesShown = true; drawScopeFramework(); } void toggleTranspose(void) { - if (editor.ui.transposeShown) + if (ui.transposeShown) hideTranspose(); else showTranspose(); @@ -370,20 +369,20 @@ void toggleTranspose(void) void cursorChannelLeft(void) { - editor.cursor.object = CURSOR_EFX2; + cursor.object = CURSOR_EFX2; - if (editor.cursor.ch == 0) + if (cursor.ch == 0) { - editor.cursor.ch = (uint8_t)(song.antChn - 1); - if (editor.ui.pattChanScrollShown) + cursor.ch = (uint8_t)(song.antChn - 1); + if (ui.pattChanScrollShown) setScrollBarPos(SB_CHAN_SCROLL, song.antChn, true); } else { - editor.cursor.ch--; - if (editor.ui.pattChanScrollShown) + cursor.ch--; + if (ui.pattChanScrollShown) { - if (editor.cursor.ch < editor.ui.channelOffset) + if (cursor.ch < ui.channelOffset) scrollBarScrollUp(SB_CHAN_SCROLL, 1); } } @@ -391,96 +390,96 @@ void cursorChannelLeft(void) void cursorChannelRight(void) { - editor.cursor.object = CURSOR_NOTE; + cursor.object = CURSOR_NOTE; - if (editor.cursor.ch >= song.antChn-1) + if (cursor.ch >= song.antChn-1) { - editor.cursor.ch = 0; - if (editor.ui.pattChanScrollShown) + cursor.ch = 0; + if (ui.pattChanScrollShown) setScrollBarPos(SB_CHAN_SCROLL, 0, true); } else { - editor.cursor.ch++; - if (editor.ui.pattChanScrollShown && editor.cursor.ch >= editor.ui.channelOffset+editor.ui.numChannelsShown) + cursor.ch++; + if (ui.pattChanScrollShown && cursor.ch >= ui.channelOffset+ui.numChannelsShown) scrollBarScrollDown(SB_CHAN_SCROLL, 1); } } void cursorTabLeft(void) { - if (editor.cursor.object == CURSOR_NOTE) + if (cursor.object == CURSOR_NOTE) cursorChannelLeft(); - editor.cursor.object = CURSOR_NOTE; - editor.ui.updatePatternEditor = true; + cursor.object = CURSOR_NOTE; + ui.updatePatternEditor = true; } void cursorTabRight(void) { cursorChannelRight(); - editor.cursor.object = CURSOR_NOTE; - editor.ui.updatePatternEditor = true; + cursor.object = CURSOR_NOTE; + ui.updatePatternEditor = true; } void chanLeft(void) { cursorChannelLeft(); - editor.cursor.object = CURSOR_NOTE; - editor.ui.updatePatternEditor = true; + cursor.object = CURSOR_NOTE; + ui.updatePatternEditor = true; } void chanRight(void) { cursorChannelRight(); - editor.cursor.object = CURSOR_NOTE; - editor.ui.updatePatternEditor = true; + cursor.object = CURSOR_NOTE; + ui.updatePatternEditor = true; } void cursorLeft(void) { - editor.cursor.object--; + cursor.object--; if (!config.ptnS3M) { - while (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2) - editor.cursor.object--; + while (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2) + cursor.object--; } - if (editor.cursor.object == -1) + if (cursor.object == -1) { - editor.cursor.object = CURSOR_EFX2; + cursor.object = CURSOR_EFX2; cursorChannelLeft(); } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void cursorRight(void) { - editor.cursor.object++; + cursor.object++; if (!config.ptnS3M) { - while (editor.cursor.object == CURSOR_VOL1 || editor.cursor.object == CURSOR_VOL2) - editor.cursor.object++; + while (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2) + cursor.object++; } - if (editor.cursor.object == 8) + if (cursor.object == 8) { - editor.cursor.object = CURSOR_NOTE; + cursor.object = CURSOR_NOTE; cursorChannelRight(); } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void showPatternEditor(void) { - editor.ui.patternEditorShown = true; + ui.patternEditorShown = true; updateChanNums(); drawPatternBorders(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void hidePatternEditor(void) @@ -489,7 +488,7 @@ void hidePatternEditor(void) hidePushButton(PB_CHAN_SCROLL_LEFT); hidePushButton(PB_CHAN_SCROLL_RIGHT); - editor.ui.patternEditorShown = false; + ui.patternEditorShown = false; } static void updatePatternEditorGUI(void) @@ -498,7 +497,7 @@ static void updatePatternEditorGUI(void) pushButton_t *p; textBox_t *t; - if (editor.ui.extended) + if (ui.extended) { // extended pattern editor @@ -625,29 +624,29 @@ static void updatePatternEditorGUI(void) void patternEditorExtended(void) { // backup old screen flags - editor.ui._aboutScreenShown = editor.ui.aboutScreenShown; - editor.ui._helpScreenShown = editor.ui.helpScreenShown; - editor.ui._configScreenShown = editor.ui.configScreenShown; - editor.ui._diskOpShown = editor.ui.diskOpShown; - editor.ui._nibblesShown = editor.ui.nibblesShown; - editor.ui._transposeShown = editor.ui.transposeShown; - editor.ui._instEditorShown = editor.ui.instEditorShown; - editor.ui._instEditorExtShown = editor.ui.instEditorExtShown; - editor.ui._sampleEditorExtShown = editor.ui.sampleEditorExtShown; - editor.ui._patternEditorShown = editor.ui.patternEditorShown; - editor.ui._sampleEditorShown = editor.ui.sampleEditorShown; - editor.ui._advEditShown= editor.ui.advEditShown; - editor.ui._wavRendererShown = editor.ui.wavRendererShown; - editor.ui._trimScreenShown = editor.ui.trimScreenShown; + ui._aboutScreenShown = ui.aboutScreenShown; + ui._helpScreenShown = ui.helpScreenShown; + ui._configScreenShown = ui.configScreenShown; + ui._diskOpShown = ui.diskOpShown; + ui._nibblesShown = ui.nibblesShown; + ui._transposeShown = ui.transposeShown; + ui._instEditorShown = ui.instEditorShown; + ui._instEditorExtShown = ui.instEditorExtShown; + ui._sampleEditorExtShown = ui.sampleEditorExtShown; + ui._patternEditorShown = ui.patternEditorShown; + ui._sampleEditorShown = ui.sampleEditorShown; + ui._advEditShown= ui.advEditShown; + ui._wavRendererShown = ui.wavRendererShown; + ui._trimScreenShown = ui.trimScreenShown; hideTopScreen(); hideSampleEditor(); hideInstEditor(); - editor.ui.extended = true; - editor.ui.patternEditorShown = true; + ui.extended = true; + ui.patternEditorShown = true; updatePatternEditorGUI(); // change pattern editor layout (based on ui.extended flag) - editor.ui.updatePatternEditor = true; // redraw pattern editor + ui.updatePatternEditor = true; // redraw pattern editor drawFramework(0, 0, 112, 53, FRAMEWORK_TYPE1); drawFramework(112, 0, 106, 33, FRAMEWORK_TYPE1); @@ -684,7 +683,7 @@ void patternEditorExtended(void) textOutShadow(222, 39, PAL_FORGRND, PAL_DSKTOP2, "Ptn."); textOutShadow(305, 39, PAL_FORGRND, PAL_DSKTOP2, "Ln."); - editor.ui.instrSwitcherShown = true; + ui.instrSwitcherShown = true; showInstrumentSwitcher(); drawSongLength(); @@ -692,7 +691,7 @@ void patternEditorExtended(void) drawEditPattern(editor.editPattern); drawPatternLength(editor.editPattern); drawPosEdNums(editor.songPos); - editor.ui.updatePosSections = true; + ui.updatePosSections = true; // kludge to fix scrollbar thumb when the scrollbar height changes during playback if (songPlaying) @@ -701,27 +700,27 @@ void patternEditorExtended(void) void exitPatternEditorExtended(void) { - editor.ui.extended = false; + ui.extended = false; updatePatternEditorGUI(); hidePushButton(PB_EXIT_EXT_PATT); // set back top screen button maps // set back old screen flags - editor.ui.aboutScreenShown = editor.ui._aboutScreenShown; - editor.ui.helpScreenShown = editor.ui._helpScreenShown; - editor.ui.configScreenShown = editor.ui._configScreenShown; - editor.ui.diskOpShown = editor.ui._diskOpShown; - editor.ui.nibblesShown = editor.ui._nibblesShown; - editor.ui.transposeShown = editor.ui._transposeShown; - editor.ui.instEditorShown = editor.ui._instEditorShown; - editor.ui.instEditorExtShown = editor.ui._instEditorExtShown; - editor.ui.sampleEditorExtShown = editor.ui._sampleEditorExtShown; - editor.ui.patternEditorShown = editor.ui._patternEditorShown; - editor.ui.sampleEditorShown = editor.ui._sampleEditorShown; - editor.ui.advEditShown = editor.ui._advEditShown; - editor.ui.wavRendererShown = editor.ui._wavRendererShown; - editor.ui.trimScreenShown = editor.ui.trimScreenShown; + ui.aboutScreenShown = ui._aboutScreenShown; + ui.helpScreenShown = ui._helpScreenShown; + ui.configScreenShown = ui._configScreenShown; + ui.diskOpShown = ui._diskOpShown; + ui.nibblesShown = ui._nibblesShown; + ui.transposeShown = ui._transposeShown; + ui.instEditorShown = ui._instEditorShown; + ui.instEditorExtShown = ui._instEditorExtShown; + ui.sampleEditorExtShown = ui._sampleEditorExtShown; + ui.patternEditorShown = ui._patternEditorShown; + ui.sampleEditorShown = ui._sampleEditorShown; + ui.advEditShown = ui._advEditShown; + ui.wavRendererShown = ui._wavRendererShown; + ui.trimScreenShown = ui.trimScreenShown; showTopScreen(true); showBottomScreen(); @@ -733,7 +732,7 @@ void exitPatternEditorExtended(void) void togglePatternEditorExtended(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); else patternEditorExtended(); @@ -771,16 +770,16 @@ static int8_t mouseXToCh(void) // used to get channel num from mouse x (for patt int8_t ch, chEnd; int32_t mouseX; - assert(editor.ui.patternChannelWidth > 0); - if (editor.ui.patternChannelWidth == 0) + assert(ui.patternChannelWidth > 0); + if (ui.patternChannelWidth == 0) return 0; mouseX = mouse.x - 29; mouseX = CLAMP(mouseX, 0, 573); - chEnd = (editor.ui.channelOffset + editor.ui.numChannelsShown) - 1; + chEnd = (ui.channelOffset + ui.numChannelsShown) - 1; - ch = editor.ui.channelOffset + (int8_t)(mouseX / editor.ui.patternChannelWidth); + ch = ui.channelOffset + (int8_t)(mouseX / ui.patternChannelWidth); ch = CLAMP(ch, 0, chEnd); // in some setups there can be non-used channels to the right, do clamping @@ -796,10 +795,10 @@ static int16_t mouseYToRow(void) // used to get row num from mouse y (for patter int16_t row, patternLen, my, maxY, maxRow; const pattCoordsMouse_t *pattCoordsMouse; - pattCoordsMouse = &pattCoordMouseTable[config.ptnUnpressed][editor.ui.pattChanScrollShown][editor.ui.extended]; + pattCoordsMouse = &pattCoordMouseTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended]; // clamp mouse y to boundaries - maxY = editor.ui.pattChanScrollShown ? 382 : 396; + maxY = ui.pattChanScrollShown ? 382 : 396; my = (int16_t)(CLAMP(mouse.y, pattCoordsMouse->upperRowsY, maxY)); charHeight = config.ptnUnpressed ? 11 : 8; @@ -825,7 +824,7 @@ static int16_t mouseYToRow(void) // used to get row num from mouse y (for patter row = (editor.pattPos + 1) + ((my - pattCoordsMouse->lowerRowsY) / charHeight); // prevent being able to mark the next unseen row on the bottom (in some configurations) - mode = (editor.ui.extended * 4) + (config.ptnUnpressed * 2) + editor.ui.pattChanScrollShown; + mode = (ui.extended * 4) + (config.ptnUnpressed * 2) + ui.pattChanScrollShown; maxRow = (ptnAntLine[mode] + (editor.pattPos - ptnLineSub[mode])) - 1; if (row > maxRow) @@ -850,7 +849,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) if (mouse.rightButtonPressed) { clearPattMark(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; return; } @@ -873,7 +872,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) checkMarkLimits(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; return; } @@ -882,7 +881,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) forceMarking = songPlaying; // scroll left/right with mouse - if (editor.ui.pattChanScrollShown) + if (ui.pattChanScrollShown) { if (mouse.x < 29) { @@ -916,7 +915,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) if (lastMarkX1 != pattMark.markX1 || lastMarkX2 != pattMark.markX2) { checkMarkLimits(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; lastMarkX1 = pattMark.markX1; lastMarkX2 = pattMark.markX2; @@ -926,8 +925,8 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) // scroll down/up with mouse (if song is not playing) if (!songPlaying) { - y1 = editor.ui.extended ? 56 : 176; - y2 = editor.ui.pattChanScrollShown ? 382 : 396; + y1 = ui.extended ? 56 : 176; + y2 = ui.pattChanScrollShown ? 382 : 396; if (mouse.y < y1) { @@ -936,7 +935,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) setPos(-1, editor.pattPos - 1, true); forceMarking = true; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } else if (mouse.y > y2) { @@ -945,7 +944,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) setPos(-1, editor.pattPos + 1, true); forceMarking = true; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } } @@ -969,7 +968,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) if (lastMarkY1 != pattMark.markY1 || lastMarkY2 != pattMark.markY2) { checkMarkLimits(); - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; lastMarkY1 = pattMark.markY1; lastMarkY2 = pattMark.markY2; @@ -979,7 +978,7 @@ void handlePatternDataMouseDown(bool mouseButtonHeld) void rowOneUpWrap(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -987,7 +986,7 @@ void rowOneUpWrap(void) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -996,7 +995,7 @@ void rowOneUpWrap(void) void rowOneDownWrap(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1008,7 +1007,7 @@ void rowOneDownWrap(void) { song.pattPos = (song.pattPos + 1 + song.pattLen) % song.pattLen; editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -1017,7 +1016,7 @@ void rowOneDownWrap(void) void rowUp(uint16_t amount) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1028,7 +1027,7 @@ void rowUp(uint16_t amount) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -1037,7 +1036,7 @@ void rowUp(uint16_t amount) void rowDown(uint16_t amount) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1048,7 +1047,7 @@ void rowDown(uint16_t amount) if (!songPlaying) { editor.pattPos = (uint8_t)song.pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (audioWasntLocked) @@ -1060,7 +1059,7 @@ void keybPattMarkUp(void) int8_t xPos; int16_t pattPos; - xPos = editor.cursor.ch; + xPos = cursor.ch; pattPos = editor.pattPos; if (xPos != pattMark.markX1 && xPos != pattMark.markX2) @@ -1097,7 +1096,7 @@ void keybPattMarkDown(void) int8_t xPos; int16_t pattPos; - xPos = editor.cursor.ch; + xPos = cursor.ch; pattPos = editor.pattPos; if (xPos != pattMark.markX1 && xPos != pattMark.markX2) @@ -1133,7 +1132,7 @@ void keybPattMarkLeft(void) int8_t xPos; int16_t pattPos; - xPos = editor.cursor.ch; + xPos = cursor.ch; pattPos = editor.pattPos; if (pattPos != pattMark.markY1-1 && pattPos != pattMark.markY2) @@ -1167,7 +1166,7 @@ void keybPattMarkRight(void) int8_t xPos; int16_t pattPos; - xPos = editor.cursor.ch; + xPos = cursor.ch; pattPos = editor.pattPos; if (pattPos != pattMark.markY1-1 && pattPos != pattMark.markY2) @@ -1248,7 +1247,7 @@ bool loadTrack(UNICHAR *filenameU) lockMixerCallback(); for (uint16_t i = 0; i < pattLen; i++) { - pattPtr = &patt[nr][(i * MAX_VOICES) + editor.cursor.ch]; + pattPtr = &patt[nr][(i * MAX_VOICES) + cursor.ch]; *pattPtr = loadBuff[i]; // non-FT2 security fix: remove overflown (illegal) stuff @@ -1266,8 +1265,8 @@ bool loadTrack(UNICHAR *filenameU) fclose(f); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; diskOpSetFilename(DISKOP_ITEM_TRACK, filenameU); setSongModifiedFlag(); @@ -1304,7 +1303,7 @@ bool saveTrack(UNICHAR *filenameU) pattLen = pattLens[nr]; for (i = 0; i < pattLen; i++) - saveBuff[i] = pattPtr[(i * MAX_VOICES) + editor.cursor.ch]; + saveBuff[i] = pattPtr[(i * MAX_VOICES) + cursor.ch]; th.len = pattLen; th.ver = 1; @@ -1400,8 +1399,8 @@ bool loadPattern(UNICHAR *filenameU) fclose(f); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; diskOpSetFilename(DISKOP_ITEM_PATTERN, filenameU); setSongModifiedFlag(); @@ -1471,61 +1470,61 @@ void scrollChannelRight(void) void setChannelScrollPos(uint32_t pos) { - if (!editor.ui.pattChanScrollShown) + if (!ui.pattChanScrollShown) { - editor.ui.channelOffset = 0; + ui.channelOffset = 0; return; } - if (editor.ui.channelOffset == (uint8_t)pos) + if (ui.channelOffset == (uint8_t)pos) return; - editor.ui.channelOffset = (uint8_t)pos; + ui.channelOffset = (uint8_t)pos; - assert(song.antChn > editor.ui.numChannelsShown); - if (editor.ui.channelOffset >= song.antChn-editor.ui.numChannelsShown) - editor.ui.channelOffset = (uint8_t)(song.antChn-editor.ui.numChannelsShown); + assert(song.antChn > ui.numChannelsShown); + if (ui.channelOffset >= song.antChn-ui.numChannelsShown) + ui.channelOffset = (uint8_t)(song.antChn-ui.numChannelsShown); - if (editor.cursor.ch >= editor.ui.channelOffset+editor.ui.numChannelsShown) + if (cursor.ch >= ui.channelOffset+ui.numChannelsShown) { - editor.cursor.object = CURSOR_NOTE; - editor.cursor.ch = (editor.ui.channelOffset + editor.ui.numChannelsShown) - 1; + cursor.object = CURSOR_NOTE; + cursor.ch = (ui.channelOffset + ui.numChannelsShown) - 1; } - else if (editor.cursor.ch < editor.ui.channelOffset) + else if (cursor.ch < ui.channelOffset) { - editor.cursor.object = CURSOR_NOTE; - editor.cursor.ch = editor.ui.channelOffset; + cursor.object = CURSOR_NOTE; + cursor.ch = ui.channelOffset; } - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } void jumpToChannel(uint8_t channel) // for ALT+q..i ALT+a..k { - if (editor.ui.sampleEditorShown || editor.ui.instEditorShown) + if (ui.sampleEditorShown || ui.instEditorShown) return; channel %= song.antChn; - if (editor.cursor.ch == channel) + if (cursor.ch == channel) return; - if (editor.ui.pattChanScrollShown) + if (ui.pattChanScrollShown) { - assert(song.antChn > editor.ui.numChannelsShown); + assert(song.antChn > ui.numChannelsShown); - if (channel >= editor.ui.channelOffset+editor.ui.numChannelsShown) - scrollBarScrollDown(SB_CHAN_SCROLL, (channel - (editor.ui.channelOffset + editor.ui.numChannelsShown)) + 1); - else if (channel < editor.ui.channelOffset) - scrollBarScrollUp(SB_CHAN_SCROLL, editor.ui.channelOffset - channel); + if (channel >= ui.channelOffset+ui.numChannelsShown) + scrollBarScrollDown(SB_CHAN_SCROLL, (channel - (ui.channelOffset + ui.numChannelsShown)) + 1); + else if (channel < ui.channelOffset) + scrollBarScrollUp(SB_CHAN_SCROLL, ui.channelOffset - channel); } - editor.cursor.ch = channel; // set it here since scrollBarScrollX() changes it... - editor.ui.updatePatternEditor = true; + cursor.ch = channel; // set it here since scrollBarScrollX() changes it... + ui.updatePatternEditor = true; } void sbPosEdPos(uint32_t pos) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1538,7 +1537,7 @@ void sbPosEdPos(uint32_t pos) void pbPosEdPosUp(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1551,7 +1550,7 @@ void pbPosEdPosUp(void) void pbPosEdPosDown(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1578,8 +1577,8 @@ void pbPosEdIns(void) song.len++; - editor.ui.updatePosSections = true; - editor.ui.updatePosEdScrollBar = true; + ui.updatePosSections = true; + ui.updatePosEdScrollBar = true; setSongModifiedFlag(); unlockMixerCallback(); @@ -1608,8 +1607,8 @@ void pbPosEdDel(void) setPos(song.songPos, -1, false); } - editor.ui.updatePosSections = true; - editor.ui.updatePosEdScrollBar = true; + ui.updatePosSections = true; + ui.updatePosEdScrollBar = true; setSongModifiedFlag(); unlockMixerCallback(); @@ -1628,8 +1627,8 @@ void pbPosEdPattUp(void) editor.editPattern = (uint8_t)song.pattNr; song.pattLen = pattLens[editor.editPattern]; - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; setSongModifiedFlag(); } unlockMixerCallback(); @@ -1648,8 +1647,8 @@ void pbPosEdPattDown(void) editor.editPattern = (uint8_t)song.pattNr; song.pattLen = pattLens[editor.editPattern]; - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; setSongModifiedFlag(); } unlockMixerCallback(); @@ -1657,19 +1656,17 @@ void pbPosEdPattDown(void) void pbPosEdLenUp(void) { - bool audioWasntLocked; - if (song.len >= 255) return; - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); song.len++; - editor.ui.updatePosSections = true; - editor.ui.updatePosEdScrollBar = true; + ui.updatePosSections = true; + ui.updatePosEdScrollBar = true; setSongModifiedFlag(); if (audioWasntLocked) @@ -1678,12 +1675,10 @@ void pbPosEdLenUp(void) void pbPosEdLenDown(void) { - bool audioWasntLocked; - if (song.len <= 1) return; - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1698,8 +1693,8 @@ void pbPosEdLenDown(void) setPos(song.songPos, -1, false); } - editor.ui.updatePosSections = true; - editor.ui.updatePosEdScrollBar = true; + ui.updatePosSections = true; + ui.updatePosEdScrollBar = true; setSongModifiedFlag(); if (audioWasntLocked) @@ -1708,14 +1703,14 @@ void pbPosEdLenDown(void) void pbPosEdRepSUp(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); if (song.repS < song.len-1) { song.repS++; - editor.ui.updatePosSections = true; + ui.updatePosSections = true; setSongModifiedFlag(); } @@ -1725,14 +1720,14 @@ void pbPosEdRepSUp(void) void pbPosEdRepSDown(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); if (song.repS > 0) { song.repS--; - editor.ui.updatePosSections = true; + ui.updatePosSections = true; setSongModifiedFlag(); } @@ -1745,7 +1740,7 @@ void pbBPMUp(void) if (song.speed == 255) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1771,7 +1766,7 @@ void pbBPMDown(void) if (song.speed == 32) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1797,7 +1792,7 @@ void pbSpeedUp(void) if (song.tempo == 31) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1822,7 +1817,7 @@ void pbSpeedDown(void) if (song.tempo == 0) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1874,7 +1869,7 @@ void pbAddChan(void) showTopLeftMainScreen(true); showTopRightMainScreen(); - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) showPatternEditor(); setSongModifiedFlag(); @@ -1896,7 +1891,7 @@ void pbSubChan(void) showTopLeftMainScreen(true); showTopRightMainScreen(); - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) showPatternEditor(); setSongModifiedFlag(); @@ -1919,18 +1914,7 @@ static void updatePtnLen(void) void pbEditPattUp(void) { - if (songPlaying) - { - if (song.pattNr == 255) - return; - } - else - { - if (editor.editPattern == 255) - return; - } - - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1941,8 +1925,8 @@ void pbEditPattUp(void) song.pattNr++; updatePtnLen(); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; } } else @@ -1954,8 +1938,8 @@ void pbEditPattUp(void) song.pattNr = editor.editPattern; updatePtnLen(); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; } } @@ -1965,18 +1949,7 @@ void pbEditPattUp(void) void pbEditPattDown(void) { - if (songPlaying) - { - if (song.pattNr == 0) - return; - } - else - { - if (editor.editPattern == 0) - return; - } - - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -1987,8 +1960,8 @@ void pbEditPattDown(void) song.pattNr--; updatePtnLen(); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; } } else @@ -2000,8 +1973,8 @@ void pbEditPattDown(void) song.pattNr = editor.editPattern; updatePtnLen(); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; } } @@ -2011,26 +1984,20 @@ void pbEditPattDown(void) void pbPattLenUp(void) { - bool audioWasntLocked; - uint16_t pattLen; - - if (pattLens[editor.editPattern] >= 256) + const uint16_t pattLen = pattLens[editor.editPattern]; + if (pattLen >= 256) return; - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); + + setPatternLen(editor.editPattern, pattLen + 1); + checkMarkLimits(); - pattLen = pattLens[editor.editPattern]; - if (pattLen < 256) - { - setPatternLen(editor.editPattern, pattLen + 1); - checkMarkLimits(); - - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; - setSongModifiedFlag(); - } + ui.updatePatternEditor = true; + ui.updatePosSections = true; + setSongModifiedFlag(); if (audioWasntLocked) unlockAudio(); @@ -2038,26 +2005,20 @@ void pbPattLenUp(void) void pbPattLenDown(void) { - bool audioWasntLocked; - uint16_t pattLen; - - if (pattLens[editor.editPattern] <= 1) + const uint16_t pattLen = pattLens[editor.editPattern]; + if (pattLen <= 1) return; - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); + + setPatternLen(editor.editPattern, pattLen - 1); + checkMarkLimits(); - pattLen = pattLens[editor.editPattern]; - if (pattLen > 1) - { - setPatternLen(editor.editPattern, pattLen - 1); - checkMarkLimits(); - - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; - setSongModifiedFlag(); - } + ui.updatePatternEditor = true; + ui.updatePosSections = true; + setSongModifiedFlag(); if (audioWasntLocked) unlockAudio(); @@ -2076,7 +2037,7 @@ void drawPosEdNums(int16_t songPos) songPos = song.len - 1; // clear - if (editor.ui.extended) + if (ui.extended) { clearRect(8, 4, 39, 16); fillRect(8, 23, 39, 7, PAL_DESKTOP); @@ -2098,7 +2059,7 @@ void drawPosEdNums(int16_t songPos) assert(entry < 256); - if (editor.ui.extended) + if (ui.extended) { pattTwoHexOut(8, 4 + (y * 9), (uint8_t)entry, color1); pattTwoHexOut(32, 4 + (y * 9), song.songTab[entry], color1); @@ -2113,7 +2074,7 @@ void drawPosEdNums(int16_t songPos) assert(songPos < 256); // middle - if (editor.ui.extended) + if (ui.extended) { pattTwoHexOut(8, 23, (uint8_t)songPos, color2); pattTwoHexOut(32, 23, song.songTab[songPos], color2); @@ -2131,7 +2092,7 @@ void drawPosEdNums(int16_t songPos) if (entry >= song.len) break; - if (editor.ui.extended) + if (ui.extended) { pattTwoHexOut(8, 33 + (y * 9), (uint8_t)entry, color1); pattTwoHexOut(32, 33 + (y * 9), song.songTab[entry], color1); @@ -2148,7 +2109,7 @@ void drawSongLength(void) { int16_t x, y; - if (editor.ui.extended) + if (ui.extended) { x = 165; y = 5; @@ -2166,7 +2127,7 @@ void drawSongRepS(void) { int16_t x, y; - if (editor.ui.extended) + if (ui.extended) { x = 165; y = 19; @@ -2185,7 +2146,7 @@ void drawSongBPM(uint16_t val) char str[4]; const char *strOut; - if (editor.ui.extended) + if (ui.extended) return; if (val <= 255) @@ -2210,7 +2171,7 @@ void drawSongBPM(uint16_t val) void drawSongSpeed(uint16_t val) { - if (editor.ui.extended) + if (ui.extended) return; if (val > 99) @@ -2223,7 +2184,7 @@ void drawEditPattern(uint16_t editPattern) { int16_t x, y; - if (editor.ui.extended) + if (ui.extended) { x = 252; y = 39; @@ -2241,7 +2202,7 @@ void drawPatternLength(uint16_t editPattern) { int16_t x, y; - if (editor.ui.extended) + if (ui.extended) { x = 326; y = 39; @@ -2257,7 +2218,7 @@ void drawPatternLength(uint16_t editPattern) void drawGlobalVol(uint16_t val) { - if (editor.ui.extended) + if (ui.extended) return; assert(val <= 64); @@ -2342,7 +2303,7 @@ void updateInstrumentSwitcher(void) int8_t i; int16_t y; - if (editor.ui.extended) // extended pattern editor + if (ui.extended) // extended pattern editor { //INSTRUMENTS @@ -2449,13 +2410,13 @@ void showInstrumentSwitcher(void) { uint16_t i; - if (!editor.ui.instrSwitcherShown) + if (!ui.instrSwitcherShown) return; for (i = 0; i < 8; i++) showTextBox(TB_INST1 + i); - if (editor.ui.extended) + if (ui.extended) { hidePushButton(PB_SAMPLE_LIST_UP); hidePushButton(PB_SAMPLE_LIST_DOWN); @@ -2531,7 +2492,7 @@ void pbSwapInstrBank(void) updateTextBoxPointers(); - if (editor.ui.instrSwitcherShown) + if (ui.instrSwitcherShown) { updateInstrumentSwitcher(); for (uint16_t i = 0; i < 8; i++) @@ -2755,9 +2716,9 @@ static void zapInstrs(void) updateSampleEditorSample(); - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) updateSampleEditor(); - else if (editor.ui.instEditorShown || editor.ui.instEditorExtShown) + else if (ui.instEditorShown || ui.instEditorExtShown) updateInstEditor(); unlockMixerCallback(); @@ -2816,11 +2777,11 @@ void pbToggleBadge(void) void resetChannelOffset(void) { - editor.ui.pattChanScrollShown = song.antChn > getMaxVisibleChannels(); - editor.cursor.object = CURSOR_NOTE; - editor.cursor.ch = 0; + ui.pattChanScrollShown = song.antChn > getMaxVisibleChannels(); + cursor.object = CURSOR_NOTE; + cursor.ch = 0; setScrollBarPos(SB_CHAN_SCROLL, 0, true); - editor.ui.channelOffset = 0; + ui.channelOffset = 0; } void shrinkPattern(void) @@ -2859,8 +2820,8 @@ void shrinkPattern(void) editor.pattPos = song.pattPos; - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; unlockMixerCallback(); setSongModifiedFlag(); @@ -2916,8 +2877,8 @@ void expandPattern(void) editor.pattPos = song.pattPos; - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; unlockMixerCallback(); setSongModifiedFlag(); diff --git a/src/ft2_pattern_ed.h b/src/ft2_pattern_ed.h @@ -52,10 +52,12 @@ typedef struct markCoord_t uint16_t upperRowsY, midRowY, lowerRowsY; } markCoord_t; -struct pattMark_t +typedef struct pattMark_t { int16_t markX1, markX2, markY1, markY2; -} pattMark; +} pattMark_t; + +extern pattMark_t pattMark; // ft2_pattern_ed.c void resetPlaybackTime(void); diff --git a/src/ft2_pushbuttons.c b/src/ft2_pushbuttons.c @@ -29,6 +29,7 @@ #include "ft2_edit.h" #include "ft2_sample_ed_features.h" #include "ft2_palette.h" +#include "ft2_structs.h" pushButton_t pushButtons[NUM_PUSHBUTTONS] = { @@ -335,7 +336,7 @@ pushButton_t pushButtons[NUM_PUSHBUTTONS] = // ------ CONFIG MISCELLANEOUS PUSHBUTTONS ------ //x, y, w, h, p, d, text #1, text #2, funcOnDown, funcOnUp - { 113, 155, 93, 16, 0, 0, editor.ui.fullscreenButtonText, NULL, NULL, toggleFullScreen }, + { 113, 155, 93, 16, 0, 0, ui.fullscreenButtonText, NULL, NULL, toggleFullScreen }, { 370, 121, 18, 13, 1, 4, ARROW_UP_STRING, NULL, configQuantizeUp, NULL }, { 387, 121, 18, 13, 1, 4, ARROW_DOWN_STRING, NULL, configQuantizeDown, NULL }, { 594, 106, 18, 13, 1, 4, ARROW_UP_STRING, NULL, configMIDIChnUp, NULL }, @@ -560,7 +561,7 @@ bool testPushButtonMouseDown(void) uint16_t start, end; pushButton_t *pushButton; - if (editor.ui.sysReqShown) + if (ui.sysReqShown) { // if a system request is open, only test the first eight pushbuttons (reserved) start = 0; diff --git a/src/ft2_radiobuttons.c b/src/ft2_radiobuttons.c @@ -16,6 +16,7 @@ #include "ft2_mouse.h" #include "ft2_wav_renderer.h" #include "ft2_bmp.h" +#include "ft2_structs.h" radioButton_t radioButtons[NUM_RADIOBUTTONS] = { @@ -321,7 +322,7 @@ bool testRadioButtonMouseDown(void) { radioButton_t *radioButton; - if (editor.ui.sysReqShown) + if (ui.sysReqShown) return false; for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++) diff --git a/src/ft2_replayer.c b/src/ft2_replayer.c @@ -19,6 +19,7 @@ #include "ft2_mouse.h" #include "ft2_sample_loader.h" #include "ft2_tables.h" +#include "ft2_structs.h" /* This is a *huge* mess, directly ported from the original FT2 code (and modified). ** You will experience a lot of headaches if you dig into it... @@ -97,17 +98,14 @@ void fixSampleName(int16_t nr) // removes spaces from right side of ins/smp name void resetChannels(void) { - bool audioWasntLocked; - stmTyp *ch; - - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); memset(stm, 0, sizeof (stm)); - for (uint8_t i = 0; i < MAX_VOICES; i++) + for (int32_t i = 0; i < MAX_VOICES; i++) { - ch = &stm[i]; + stmTyp *ch = &stm[i]; ch->instrSeg = instr[0]; ch->status = IS_Vol; @@ -153,14 +151,11 @@ void tuneSample(sampleTyp *s, int32_t midCFreq) void setPatternLen(uint16_t nr, int16_t len) { - bool audioWasntLocked; - assert(nr < MAX_PATTERNS); - if ((len < 1 || len > MAX_PATT_LEN) || len == pattLens[nr]) return; - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -181,8 +176,8 @@ void setPatternLen(uint16_t nr, int16_t len) if (audioWasntLocked) unlockAudio(); - editor.ui.updatePatternEditor = true; - editor.ui.updatePosSections = true; + ui.updatePatternEditor = true; + ui.updatePosSections = true; } int16_t getUsedSamples(int16_t nr) @@ -298,7 +293,7 @@ void setFrqTab(bool linear) resumeAudio(); // update "frequency table" radiobutton, if it's shown - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES) setConfigIORadioButtonStates(); } @@ -2185,7 +2180,7 @@ void mainPlayer(void) // periodically called from audio callback void resetMusic(void) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -2206,7 +2201,7 @@ void resetMusic(void) void setPos(int16_t songPos, int16_t pattPos, bool resetTimer) { - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -2236,14 +2231,14 @@ void setPos(int16_t songPos, int16_t pattPos, bool resetTimer) if (pattPos > -1) { editor.pattPos = (uint8_t)pattPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } if (songPos > -1) { editor.editPattern = (uint8_t)song.pattNr; editor.songPos = song.songPos; - editor.ui.updatePosSections = true; + ui.updatePosSections = true; } } @@ -2373,19 +2368,16 @@ void samp2Delta(int8_t *p, int32_t len, uint8_t typ) bool allocateInstr(int16_t nr) { - bool audioWasntLocked; - instrTyp *p; - if (instr[nr] != NULL) return false; // already allocated - p = (instrTyp *)malloc(sizeof (instrTyp)); + instrTyp *p = (instrTyp *)malloc(sizeof (instrTyp)); if (p == NULL) return false; memset(p, 0, sizeof (instrTyp)); - for (int8_t i = 0; i < 16; i++) // set standard sample pan/vol + for (int32_t i = 0; i < MAX_SMP_PER_INST; i++) // set standard sample pan/vol { p->samp[i].pan = 128; p->samp[i].vol = 64; @@ -2393,7 +2385,7 @@ bool allocateInstr(int16_t nr) setStdEnvelope(p, 0, 3); - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -2592,50 +2584,50 @@ void updateChanNums(void) else if (song.antChn >= 12) pageLen = 12; } - editor.ui.numChannelsShown = pageLen; + ui.numChannelsShown = pageLen; if (song.antChn == 2) - editor.ui.numChannelsShown = 2; + ui.numChannelsShown = 2; if (config.ptnMaxChannels == 0) { - if (editor.ui.numChannelsShown > 4) - editor.ui.numChannelsShown = 4; + if (ui.numChannelsShown > 4) + ui.numChannelsShown = 4; } else if (config.ptnMaxChannels == 1) { - if (editor.ui.numChannelsShown > 6) - editor.ui.numChannelsShown = 6; + if (ui.numChannelsShown > 6) + ui.numChannelsShown = 6; } else if (config.ptnMaxChannels == 2) { - if (editor.ui.numChannelsShown > 8) - editor.ui.numChannelsShown = 8; + if (ui.numChannelsShown > 8) + ui.numChannelsShown = 8; } else if (config.ptnMaxChannels == 3) { if (config.ptnS3M) { - if (editor.ui.numChannelsShown > 8) - editor.ui.numChannelsShown = 8; + if (ui.numChannelsShown > 8) + ui.numChannelsShown = 8; } else { - if (editor.ui.numChannelsShown > 12) - editor.ui.numChannelsShown = 12; + if (ui.numChannelsShown > 12) + ui.numChannelsShown = 12; } } - editor.ui.pattChanScrollShown = song.antChn > getMaxVisibleChannels(); + ui.pattChanScrollShown = song.antChn > getMaxVisibleChannels(); - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) { - if (editor.ui.channelOffset > song.antChn-editor.ui.numChannelsShown) - setScrollBarPos(SB_CHAN_SCROLL, song.antChn - editor.ui.numChannelsShown, true); + if (ui.channelOffset > song.antChn-ui.numChannelsShown) + setScrollBarPos(SB_CHAN_SCROLL, song.antChn - ui.numChannelsShown, true); } - if (editor.ui.pattChanScrollShown) + if (ui.pattChanScrollShown) { - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) { showScrollBar(SB_CHAN_SCROLL); showPushButton(PB_CHAN_SCROLL_LEFT); @@ -2643,7 +2635,7 @@ void updateChanNums(void) } setScrollBarEnd(SB_CHAN_SCROLL, song.antChn); - setScrollBarPageLength(SB_CHAN_SCROLL, editor.ui.numChannelsShown); + setScrollBarPageLength(SB_CHAN_SCROLL, ui.numChannelsShown); } else { @@ -2653,11 +2645,11 @@ void updateChanNums(void) setScrollBarPos(SB_CHAN_SCROLL, 0, false); - editor.ui.channelOffset = 0; + ui.channelOffset = 0; } - if (editor.cursor.ch >= editor.ui.channelOffset+editor.ui.numChannelsShown) - editor.cursor.ch = editor.ui.channelOffset+editor.ui.numChannelsShown - 1; + if (cursor.ch >= ui.channelOffset+ui.numChannelsShown) + cursor.ch = ui.channelOffset+ui.numChannelsShown - 1; } void conv8BitSample(int8_t *p, int32_t len, bool stereo) @@ -2822,8 +2814,8 @@ void startPlaying(int8_t mode, int16_t row) unlockMixerCallback(); - editor.ui.updatePosSections = true; - editor.ui.updatePatternEditor = true; + ui.updatePosSections = true; + ui.updatePatternEditor = true; } void stopPlaying(void) @@ -2862,13 +2854,13 @@ void stopPlaying(void) memset(editor.keyOnTab, 0, sizeof (editor.keyOnTab)); - editor.ui.updatePosSections = true; - editor.ui.updatePatternEditor = true; + ui.updatePosSections = true; + ui.updatePatternEditor = true; // certain non-FT2 fixes song.timer = editor.timer = 1; song.globVol = editor.globalVol = 64; - editor.ui.drawGlobVolFlag = true; + ui.drawGlobVolFlag = true; } // from keyboard/smp. ed. @@ -3064,16 +3056,13 @@ void playRange(uint8_t stmm, uint8_t inst, uint8_t smpNr, uint8_t ton, uint16_t void stopVoices(void) { - bool audioWasntLocked; - stmTyp *ch; - - audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); - for (uint8_t i = 0; i < MAX_VOICES; i++) + for (int32_t i = 0; i < MAX_VOICES; i++) { - ch = &stm[i]; + stmTyp *ch = &stm[i]; lastChInstr[i].sampleNr = 255; lastChInstr[i].instrNr = 255; @@ -3121,7 +3110,7 @@ void decSongPos(void) if (song.songPos == 0) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -3137,7 +3126,7 @@ void incSongPos(void) if (song.songPos == song.len-1) return; - bool audioWasntLocked = !audio.locked; + const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); @@ -3162,7 +3151,7 @@ void decCurIns(void) updateTextBoxPointers(); updateNewInstrument(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -3182,7 +3171,7 @@ void incCurIns(void) updateTextBoxPointers(); updateNewInstrument(); - if (editor.ui.advEditShown) + if (ui.advEditShown) updateAdvEdit(); } @@ -3304,7 +3293,7 @@ void setSyncedReplayerVars(void) if (chSyncEntry != NULL) { handleScopesFromChQueue(chSyncEntry, scopeUpdateStatus); - editor.ui.drawReplayerPianoFlag = true; + ui.drawReplayerPianoFlag = true; } if (!songPlaying || pattSyncEntry == NULL) @@ -3317,25 +3306,25 @@ void setSyncedReplayerVars(void) if (editor.speed != pattSyncEntry->speed) { editor.speed = pattSyncEntry->speed; - editor.ui.drawBPMFlag = true; + ui.drawBPMFlag = true; } if (editor.tempo != pattSyncEntry->tempo) { editor.tempo = pattSyncEntry->tempo; - editor.ui.drawSpeedFlag = true; + ui.drawSpeedFlag = true; } if (editor.globalVol != pattSyncEntry->globalVol) { editor.globalVol = pattSyncEntry->globalVol; - editor.ui.drawGlobVolFlag = true; + ui.drawGlobVolFlag = true; } if (editor.songPos != pattSyncEntry->songPos) { editor.songPos = pattSyncEntry->songPos; - editor.ui.drawPosEdFlag = true; + ui.drawPosEdFlag = true; } // somewhat of a kludge... @@ -3344,10 +3333,10 @@ void setSyncedReplayerVars(void) // set pattern number editor.editPattern = editor.tmpPattern = pattSyncEntry->pattern; checkMarkLimits(); - editor.ui.drawPattNumLenFlag = true; + ui.drawPattNumLenFlag = true; // set row editor.pattPos = (uint8_t)pattSyncEntry->patternPos; - editor.ui.updatePatternEditor = true; + ui.updatePatternEditor = true; } } diff --git a/src/ft2_sample_ed.c b/src/ft2_sample_ed.c @@ -23,6 +23,7 @@ #include "ft2_mouse.h" #include "ft2_diskop.h" #include "ft2_keyboard.h" +#include "ft2_structs.h" static const char sharpNote1Char[12] = { 'C', 'C', 'D', 'D', 'E', 'F', 'F', 'G', 'G', 'A', 'A', 'B' }; static const char sharpNote2Char[12] = { '-', '#', '-', '#', '-', '-', '#', '-', '#', '-', '#', '-' }; @@ -400,10 +401,10 @@ static void fixRepeatGadgets(void) bool showLoopPins = true; s = getCurSample(); - if (s == NULL || s->len <= 0 || s->pek == NULL || (s->typ & 3) == 0 || !editor.ui.sampleEditorShown) + if (s == NULL || s->len <= 0 || s->pek == NULL || (s->typ & 3) == 0 || !ui.sampleEditorShown) showLoopPins = false; - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) { // draw Repeat/Replen. numbers hexOutBg(536, 375, PAL_FORGRND, PAL_DESKTOP, curSmpRepS, 8); @@ -577,7 +578,7 @@ static void writeRange(void) uint32_t *ptr32; // very first sample (rx1=0,rx2=0) is the "no range" special case - if (!editor.ui.sampleEditorShown || smpEd_ViewSize == 0 || (smpEd_Rx1 == 0 && smpEd_Rx2 == 0)) + if (!ui.sampleEditorShown || smpEd_ViewSize == 0 || (smpEd_Rx1 == 0 && smpEd_Rx2 == 0)) return; // test if range is outside of view (passed it by scrolling) @@ -1084,18 +1085,18 @@ void writeSample(bool forceSmpRedraw) } // handle updating - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) { // check if we need to redraw sample data if (forceSmpRedraw || (old_SmpScrPos != smpEd_ScrPos || old_ViewSize != smpEd_ViewSize)) { - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) writeWaveform(); old_SmpScrPos = smpEd_ScrPos; old_ViewSize = smpEd_ViewSize; - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) writeRange(); // range was overwritten, draw it again smpEd_OldSmpPosLine = -1; @@ -1114,14 +1115,14 @@ void writeSample(bool forceSmpRedraw) smpEd_Rx1 = old_Rx1; smpEd_Rx2 = old_Rx2; - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) writeRange(); // write new range smpEd_Rx1 = tmpRx1; smpEd_Rx2 = tmpRx2; - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) writeRange(); old_Rx1 = smpEd_Rx1; @@ -1131,7 +1132,7 @@ void writeSample(bool forceSmpRedraw) fixRepeatGadgets(); } - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) fixSampleDrag(); updateSampleEditor(); @@ -1191,7 +1192,7 @@ void updateSampleEditor(void) uint8_t note, typ; int32_t sampleLen; - if (!editor.ui.sampleEditorShown) + if (!ui.sampleEditorShown) return; if (instr[editor.curInstr] == NULL) @@ -1344,17 +1345,17 @@ void scrollSampleData(uint32_t pos) void sampPlayWave(void) { - playSample(editor.cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0); + playSample(cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0); } void sampPlayDisplay(void) { - playRange(editor.cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0, smpEd_ScrPos, smpEd_ViewSize); + playRange(cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0, smpEd_ScrPos, smpEd_ViewSize); } void sampPlayRange(void) { - playRange(editor.cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0, smpEd_Rx1, smpEd_Rx2 - smpEd_Rx1); + playRange(cursor.ch, editor.curInstr, editor.curSmp, editor.smpEd_NoteNr, 0, 0, smpEd_Rx1, smpEd_Rx2 - smpEd_Rx1); } void showRange(void) @@ -2813,7 +2814,7 @@ void hideSampleEditor(void) hideScrollBar(SB_SAMP_SCROLL); - editor.ui.sampleEditorShown = false; + ui.sampleEditorShown = false; hideSprite(SPRITE_LEFT_LOOP_PIN); hideSprite(SPRITE_RIGHT_LOOP_PIN); @@ -2823,7 +2824,7 @@ void exitSampleEditor(void) { hideSampleEditor(); - if (editor.ui.sampleEditorExtShown) + if (ui.sampleEditorExtShown) hideSampleEditorExt(); showPatternEditor(); @@ -2831,12 +2832,12 @@ void exitSampleEditor(void) void showSampleEditor(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideInstEditor(); hidePatternEditor(); - editor.ui.sampleEditorShown = true; + ui.sampleEditorShown = true; drawFramework(0, 329, 632, 17, FRAMEWORK_TYPE1); drawFramework(0, 346, 115, 54, FRAMEWORK_TYPE1); @@ -2903,7 +2904,7 @@ void toggleSampleEditor(void) { hideInstEditor(); - if (editor.ui.sampleEditorShown) + if (ui.sampleEditorShown) { exitSampleEditor(); } @@ -2980,7 +2981,7 @@ void handleSamplerRedrawing(void) { // update sample editor - if (!editor.ui.sampleEditorShown || editor.samplingAudioFlag) + if (!ui.sampleEditorShown || editor.samplingAudioFlag) return; if (writeSampleFlag) @@ -3262,9 +3263,9 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) if (!mouseButtonHeld) { - editor.ui.rightLoopPinMoving = false; - editor.ui.leftLoopPinMoving = false; - editor.ui.sampleDataOrLoopDrag = -1; + ui.rightLoopPinMoving = false; + ui.leftLoopPinMoving = false; + ui.sampleDataOrLoopDrag = -1; mouseXOffs = 0; lastMouseX = mx; @@ -3282,12 +3283,12 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) { mouseXOffs = (leftLoopPinPos + 8) - mx; - editor.ui.sampleDataOrLoopDrag = true; + ui.sampleDataOrLoopDrag = true; setLeftLoopPinState(true); lastMouseX = mx; - editor.ui.leftLoopPinMoving = true; + ui.leftLoopPinMoving = true; return; } } @@ -3298,26 +3299,26 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) { mouseXOffs = (rightLoopPinPos + 8) - mx; - editor.ui.sampleDataOrLoopDrag = true; + ui.sampleDataOrLoopDrag = true; setRightLoopPinState(true); lastMouseX = mx; - editor.ui.rightLoopPinMoving = true; + ui.rightLoopPinMoving = true; return; } } // mark data lastMouseX = mx; - editor.ui.sampleDataOrLoopDrag = mx; + ui.sampleDataOrLoopDrag = mx; setSampleRange(mx, mx); } else if (mouse.rightButtonPressed) { // edit data - editor.ui.sampleDataOrLoopDrag = true; + ui.sampleDataOrLoopDrag = true; editSampleData(false); } @@ -3334,27 +3335,27 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) { if (mouse.leftButtonPressed) { - if (editor.ui.leftLoopPinMoving) + if (ui.leftLoopPinMoving) { lastMouseX = mx; setLeftLoopPinPos(mouseXOffs + mx); } - else if (editor.ui.rightLoopPinMoving) + else if (ui.rightLoopPinMoving) { lastMouseX = mx; setRightLoopPinPos(mouseXOffs + mx); } - else if (editor.ui.sampleDataOrLoopDrag >= 0) + else if (ui.sampleDataOrLoopDrag >= 0) { // mark data lastMouseX = mx; - if (lastMouseX > editor.ui.sampleDataOrLoopDrag) - setSampleRange(editor.ui.sampleDataOrLoopDrag, mx); - else if (lastMouseX == editor.ui.sampleDataOrLoopDrag) - setSampleRange(editor.ui.sampleDataOrLoopDrag, editor.ui.sampleDataOrLoopDrag); - else if (lastMouseX < editor.ui.sampleDataOrLoopDrag) - setSampleRange(mx, editor.ui.sampleDataOrLoopDrag); + if (lastMouseX > ui.sampleDataOrLoopDrag) + setSampleRange(ui.sampleDataOrLoopDrag, mx); + else if (lastMouseX == ui.sampleDataOrLoopDrag) + setSampleRange(ui.sampleDataOrLoopDrag, ui.sampleDataOrLoopDrag); + else if (lastMouseX < ui.sampleDataOrLoopDrag) + setSampleRange(mx, ui.sampleDataOrLoopDrag); } } } @@ -3409,20 +3410,20 @@ void showSampleEditorExt(void) hideTopScreen(); showTopScreen(false); - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); - if (!editor.ui.sampleEditorShown) + if (!ui.sampleEditorShown) showSampleEditor(); - editor.ui.sampleEditorExtShown = true; - editor.ui.scopesShown = false; + ui.sampleEditorExtShown = true; + ui.scopesShown = false; drawSampleEditorExt(); } void hideSampleEditorExt(void) { - editor.ui.sampleEditorExtShown = false; + ui.sampleEditorExtShown = false; hidePushButton(PB_SAMP_EXT_CLEAR_COPYBUF); hidePushButton(PB_SAMP_EXT_CONV); @@ -3437,13 +3438,13 @@ void hideSampleEditorExt(void) hidePushButton(PB_SAMP_EXT_RESAMPLE); hidePushButton(PB_SAMP_EXT_MIX_SAMPLE); - editor.ui.scopesShown = true; + ui.scopesShown = true; drawScopeFramework(); } void toggleSampleEditorExt(void) { - if (editor.ui.sampleEditorExtShown) + if (ui.sampleEditorExtShown) hideSampleEditorExt(); else showSampleEditorExt(); diff --git a/src/ft2_sample_ed_features.c b/src/ft2_sample_ed_features.c @@ -24,6 +24,7 @@ #include "ft2_sample_ed.h" #include "ft2_keyboard.h" #include "ft2_tables.h" +#include "ft2_structs.h" static volatile bool stopThread; @@ -35,14 +36,14 @@ static SDL_Thread *thread; static void pbExit(void) { - editor.ui.sysReqShown = false; + ui.sysReqShown = false; exitFlag = true; } static void windowOpen(void) { - editor.ui.sysReqShown = true; - editor.ui.sysReqEnterPressed = false; + ui.sysReqShown = true; + ui.sysReqEnterPressed = false; unstuckLastUsedGUIElement(); SDL_EventState(SDL_DROPFILE, SDL_DISABLE); @@ -108,7 +109,7 @@ static int32_t SDLCALL resampleThread(void *ptr) { outOfMemory = true; setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -188,7 +189,7 @@ static int32_t SDLCALL resampleThread(void *ptr) setSongModifiedFlag(); setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -346,10 +347,10 @@ void pbSampleResample(void) outOfMemory = false; exitFlag = false; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { readInput(); - if (editor.ui.sysReqEnterPressed) + if (ui.sysReqEnterPressed) pbDoResampling(); setSyncedReplayerVars(); @@ -456,7 +457,7 @@ static int32_t SDLCALL createEchoThread(void *ptr) if (echo_nEcho < 1) { - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -472,7 +473,7 @@ static int32_t SDLCALL createEchoThread(void *ptr) if (nEchoes < 1) { - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -499,7 +500,7 @@ static int32_t SDLCALL createEchoThread(void *ptr) { outOfMemory = true; setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return false; } @@ -614,7 +615,7 @@ static int32_t SDLCALL createEchoThread(void *ptr) setSongModifiedFlag(); setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -848,10 +849,10 @@ void pbSampleEcho(void) outOfMemory = false; exitFlag = false; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { readInput(); - if (editor.ui.sysReqEnterPressed) + if (ui.sysReqEnterPressed) pbCreateEcho(); setSyncedReplayerVars(); @@ -895,7 +896,7 @@ static int32_t SDLCALL mixThread(void *ptr) if (destIns == mixIns && destSmp == mixSmp) { setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -948,7 +949,7 @@ static int32_t SDLCALL mixThread(void *ptr) if (maxLen <= 0) { setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -957,7 +958,7 @@ static int32_t SDLCALL mixThread(void *ptr) { outOfMemory = true; setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -965,7 +966,7 @@ static int32_t SDLCALL mixThread(void *ptr) { outOfMemory = true; setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -1023,7 +1024,7 @@ static int32_t SDLCALL mixThread(void *ptr) setSongModifiedFlag(); setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return true; } @@ -1165,10 +1166,10 @@ void pbSampleMix(void) outOfMemory = false; exitFlag = false; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { readInput(); - if (editor.ui.sysReqEnterPressed) + if (ui.sysReqEnterPressed) pbMix(); setSyncedReplayerVars(); @@ -1346,7 +1347,7 @@ static int32_t SDLCALL applyVolumeThread(void *ptr) applyVolumeExit: setMouseBusy(false); - editor.ui.sysReqShown = false; + ui.sysReqShown = false; (void)ptr; return true; @@ -1356,7 +1357,7 @@ static void pbApplyVolume(void) { if (vol_StartVol == 100 && vol_EndVol == 100) { - editor.ui.sysReqShown = false; + ui.sysReqShown = false; return; // no volume change to be done } @@ -1692,10 +1693,10 @@ void pbSampleVolume(void) windowOpen(); exitFlag = false; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { readInput(); - if (editor.ui.sysReqEnterPressed) + if (ui.sysReqEnterPressed) { pbApplyVolume(); keyb.ignoreCurrKeyUp = true; // don't handle key up event for this key release @@ -1705,7 +1706,7 @@ void pbSampleVolume(void) handleRedrawing(); // this is needed for the "Get maximum scale" button - if (editor.ui.setMouseIdle) mouseAnimOff(); + if (ui.setMouseIdle) mouseAnimOff(); drawSampleVolumeBox(); setScrollBarPos(0, 500 + vol_StartVol, false); diff --git a/src/ft2_sample_loader.c b/src/ft2_sample_loader.c @@ -14,6 +14,7 @@ #include "ft2_sample_ed.h" #include "ft2_mouse.h" #include "ft2_diskop.h" +#include "ft2_structs.h" /* All of these routines were written from scratch and were not present ** in original FT2. diff --git a/src/ft2_sample_saver.c b/src/ft2_sample_saver.c @@ -14,6 +14,7 @@ #include "ft2_sample_ed.h" #include "ft2_diskop.h" #include "ft2_mouse.h" +#include "ft2_structs.h" typedef struct wavHeader_t { diff --git a/src/ft2_sampling.c b/src/ft2_sampling.c @@ -11,6 +11,7 @@ #include "ft2_sample_ed.h" #include "ft2_video.h" #include "ft2_sampling.h" +#include "ft2_structs.h" // these may very well change after opening the audio input device #define SAMPLING_BUFFER_SIZE 2048 diff --git a/src/ft2_scopes.c b/src/ft2_scopes.c @@ -21,6 +21,7 @@ #include "ft2_video.h" #include "ft2_scopedraw.h" #include "ft2_tables.h" +#include "ft2_structs.h" enum { @@ -273,7 +274,7 @@ bool testScopesMouseDown(void) const uint16_t *scopeLens; int32_t i, chansPerRow, chanToToggle; - if (!editor.ui.scopesShown) + if (!ui.scopesShown) return false; if (mouse.y >= 95 && mouse.y <= 169 && mouse.x >= 3 && mouse.x <= 288) diff --git a/src/ft2_scrollbars.c b/src/ft2_scrollbars.c @@ -19,6 +19,7 @@ #include "ft2_mouse.h" #include "ft2_video.h" #include "ft2_palette.h" +#include "ft2_structs.h" /* Prevent the scrollbar thumbs from being so small that ** it's difficult to use them. In units of pixels. @@ -501,7 +502,7 @@ bool testScrollBarMouseDown(void) double dTmp; scrollBar_t *scrollBar; - if (editor.ui.sysReqShown) + if (ui.sysReqShown) { // if a system request is open, only test the first three scrollbars (reserved) start = 0; diff --git a/src/ft2_structs.c b/src/ft2_structs.c @@ -0,0 +1,6 @@ +#include "ft2_structs.h" + +cpu_t cpu; +editor_t editor; +ui_t ui; +cursor_t cursor; diff --git a/src/ft2_structs.h b/src/ft2_structs.h @@ -0,0 +1,82 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> +#include "ft2_header.h" + +typedef struct cpu_t +{ + bool hasSSE, hasSSE2; +} cpu_t; + +typedef struct editor_t +{ + UNICHAR binaryPathU[PATH_MAX + 2]; + UNICHAR *tmpFilenameU, *tmpInstrFilenameU; // used by saving/loading threads + UNICHAR *configFileLocation, *audioDevConfigFileLocation, *midiConfigFileLocation; + + volatile bool mainLoopOngoing; + volatile bool busy, scopeThreadMutex, programRunning, wavIsRendering, wavReachedEndFlag; + volatile bool updateCurSmp, updateCurInstr, diskOpReadDir, diskOpReadDone, updateWindowTitle; + volatile uint8_t loadMusicEvent; + volatile FILE *wavRendererFileHandle; + + bool autoPlayOnDrop, trimThreadWasDone, throwExit, editTextFlag; + bool copyMaskEnable, diskOpReadOnOpen, samplingAudioFlag, editSampleFlag; + bool instrBankSwapped, chnMode[MAX_VOICES], NI_Play; + + uint8_t curPlayInstr, curPlaySmp, curSmpChannel, currPanEnvPoint, currVolEnvPoint; + uint8_t copyMask[5], pasteMask[5], transpMask[5], smpEd_NoteNr, instrBankOffset, sampleBankOffset; + uint8_t srcInstr, curInstr, srcSmp, curSmp, currHelpScreen, currConfigScreen, textCursorBlinkCounter; + uint8_t keyOnTab[MAX_VOICES], ID_Add, curOctave; + uint8_t sampleSaveMode, moduleSaveMode, ptnJumpPos[4]; + int16_t globalVol, songPos, pattPos; + uint16_t tmpPattern, editPattern, speed, tempo, timer, ptnCursorY; + int32_t keyOffNr, keyOffTime[MAX_VOICES]; + uint32_t framesPassed, wavRendererTime; + double dPerfFreq, dPerfFreqMulMicro, dPerfFreqMulMs; +} editor_t; + +typedef struct ui_t +{ + volatile bool setMouseBusy, setMouseIdle; + bool sysReqEnterPressed; + char fullscreenButtonText[24]; + + // all screens + bool extended, sysReqShown; + + // top screens + bool instrSwitcherShown, aboutScreenShown, helpScreenShown, configScreenShown; + bool scopesShown, diskOpShown, nibblesShown, transposeShown, instEditorExtShown; + bool sampleEditorExtShown, advEditShown, wavRendererShown, trimScreenShown; + bool drawBPMFlag, drawSpeedFlag, drawGlobVolFlag, drawPosEdFlag, drawPattNumLenFlag; + bool updatePosSections, updatePosEdScrollBar; + uint8_t oldTopLeftScreen; + + // bottom screens + bool patternEditorShown, instEditorShown, sampleEditorShown, pattChanScrollShown; + bool leftLoopPinMoving, rightLoopPinMoving; + bool drawReplayerPianoFlag, drawPianoFlag, updatePatternEditor; + uint8_t channelOffset, numChannelsShown, maxVisibleChannels; + uint16_t patternChannelWidth; + int32_t sampleDataOrLoopDrag; + + // backup flag for when entering/exiting extended pattern editor (TODO: this is lame and shouldn't be hardcoded) + bool _aboutScreenShown, _helpScreenShown, _configScreenShown, _diskOpShown; + bool _nibblesShown, _transposeShown, _instEditorShown; + bool _instEditorExtShown, _sampleEditorExtShown, _patternEditorShown; + bool _sampleEditorShown, _advEditShown, _wavRendererShown, _trimScreenShown; + // ------------------------------------------------------------------------- +} ui_t; + +typedef struct cursor_t +{ + uint8_t ch; + int8_t object; +} cursor_t; + +extern cpu_t cpu; +extern editor_t editor; +extern ui_t ui; +extern cursor_t cursor; diff --git a/src/ft2_sysreqs.c b/src/ft2_sysreqs.c @@ -6,6 +6,8 @@ #include "ft2_keyboard.h" #include "ft2_textboxes.h" #include "ft2_video.h" +#include "ft2_sysreqs.h" +#include "ft2_structs.h" #define SYSTEM_REQUEST_H 67 #define SYSTEM_REQUEST_Y 249 @@ -13,6 +15,8 @@ #define NUM_SYSREQ_TYPES 10 +okBoxData_t okBoxData; // globalized + static char *buttonText[NUM_SYSREQ_TYPES][5] = { { "OK", "","","","" }, @@ -75,8 +79,8 @@ static void drawWindow(uint16_t w) const uint16_t h = SYSTEM_REQUEST_H; uint16_t x, y; - x = (SCREEN_W - w) / 2; - y = editor.ui.extended ? 91 : SYSTEM_REQUEST_Y; + x = (SCREEN_W - w) >> 1; + y = ui.extended ? 91 : SYSTEM_REQUEST_Y; // main fill fillRect(x + 1, y + 1, w - 2, h - 2, PAL_BUTTONS); @@ -168,12 +172,12 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) if (mouse.mode != MOUSE_MODE_NORMAL) setMouseMode(MOUSE_MODE_NORMAL); - if (editor.ui.sysReqShown) + if (ui.sysReqShown) return 0; SDL_EventState(SDL_DROPFILE, SDL_DISABLE); - editor.ui.sysReqShown = true; + ui.sysReqShown = true; mouseAnimOff(); oldLastUsedObjectID = mouse.lastUsedObjectID; @@ -204,7 +208,7 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) x = (SCREEN_W - wlen) >> 1; // the box y position differs in extended pattern editor mode - y = editor.ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y; + y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y; // set up buttons for (i = 0; i < knp; i++) @@ -250,7 +254,7 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) // input/rendering loop returnVal = 0; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { beginFPSCounter(); readMouseXY(); @@ -271,12 +275,12 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) if (inputEvent.key.keysym.sym == SDLK_ESCAPE) { returnVal = 0; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; } else if (inputEvent.key.keysym.sym == SDLK_RETURN) { returnVal = 1; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; keyb.ignoreCurrKeyUp = true; // don't handle key up event for any keys that were pressed } @@ -285,7 +289,7 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) if (shortCut[typ][i] == inputEvent.key.keysym.sym) { returnVal = i + 1; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; keyb.ignoreCurrKeyUp = true; // don't handle key up event for any keys that were pressed break; } @@ -300,7 +304,7 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) returnVal = testPushButtonMouseRelease(false) + 1; if (returnVal > 0) - editor.ui.sysReqShown = false; + ui.sysReqShown = false; mouse.lastUsedObjectID = OBJECT_ID_NONE; mouse.lastUsedObjectType = OBJECT_NONE; @@ -315,11 +319,11 @@ int16_t okBox(int16_t typ, const char *headline, const char *text) } } - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) break; } - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) break; handleRedrawing(); @@ -378,7 +382,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt if (mouse.mode != MOUSE_MODE_NORMAL) setMouseMode(MOUSE_MODE_NORMAL); - if (editor.ui.sysReqShown) + if (ui.sysReqShown) return 0; oldLastUsedObjectID = mouse.lastUsedObjectID; @@ -408,7 +412,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt SDL_EventState(SDL_DROPFILE, SDL_DISABLE); - editor.ui.sysReqShown = true; + ui.sysReqShown = true; mouseAnimOff(); wlen = textWidth(headline); @@ -432,7 +436,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt wlen = 600; // the box y position differs in extended pattern editor mode - y = editor.ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y; + y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y; // set further text box settings t->x = (SCREEN_W - TEXTBOX_W) >> 1; @@ -466,7 +470,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt // input/rendering loop returnVal = 0; - while (editor.ui.sysReqShown) + while (ui.sysReqShown) { beginFPSCounter(); readMouseXY(); @@ -508,12 +512,12 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt if (inputEvent.key.keysym.sym == SDLK_ESCAPE) { returnVal = 0; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; } else if (inputEvent.key.keysym.sym == SDLK_RETURN) { returnVal = 1; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; keyb.ignoreCurrKeyUp = true; // don't handle key up event for any keys that were pressed } @@ -528,7 +532,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt if (shortCut[1][i] == inputEvent.key.keysym.sym) { returnVal = i + 1; - editor.ui.sysReqShown = false; + ui.sysReqShown = false; keyb.ignoreCurrKeyUp = true; // don't handle key up event for any keys that were pressed break; } @@ -541,7 +545,7 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt { returnVal = testPushButtonMouseRelease(false) + 1; if (returnVal > 0) - editor.ui.sysReqShown = false; + ui.sysReqShown = false; mouse.lastUsedObjectID = OBJECT_ID_NONE; mouse.lastUsedObjectType = OBJECT_NONE; @@ -556,11 +560,11 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt } } - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) break; } - if (!editor.ui.sysReqShown) + if (!ui.sysReqShown) break; handleRedrawing(); @@ -648,7 +652,7 @@ bool askUnsavedChanges(uint8_t type) int16_t quitBox(bool skipQuitMsg) { - if (editor.ui.sysReqShown) + if (ui.sysReqShown) return 0; if (!song.isModified && skipQuitMsg) diff --git a/src/ft2_sysreqs.h b/src/ft2_sysreqs.h @@ -10,12 +10,14 @@ int16_t inputBox(int16_t typ, const char *headline, char *edText, uint16_t maxSt bool askUnsavedChanges(uint8_t type); // for thread-safe version of okBox() -struct +typedef struct okBoxData_t { volatile bool active; int16_t typ, returnData; const char *headline, *text; -} okBoxData; +} okBoxData_t; + +extern okBoxData_t okBoxData; // ft2_sysreqs.c enum { diff --git a/src/ft2_textboxes.c b/src/ft2_textboxes.c @@ -13,6 +13,7 @@ #include "ft2_keyboard.h" #include "ft2_mouse.h" #include "ft2_bmp.h" +#include "ft2_structs.h" textBox_t textBoxes[NUM_TEXTBOXES] = { @@ -699,7 +700,7 @@ bool testTextBoxMouseDown(void) oldMouseX = mouse.x; oldCursorPos = 0; - if (editor.ui.sysReqShown) + if (ui.sysReqShown) { // if a system request is open, only test the first textbox (reserved) start = 0; diff --git a/src/ft2_trim.c b/src/ft2_trim.c @@ -15,6 +15,7 @@ #include "ft2_replayer.h" #include "ft2_audio.h" #include "ft2_mouse.h" +#include "ft2_structs.h" // this is truly a mess, but it works... @@ -999,14 +1000,14 @@ void trimThreadDone(void) if (removeChans) { - if (editor.ui.patternEditorShown) + if (ui.patternEditorShown) { - if (editor.ui.channelOffset > song.antChn-editor.ui.numChannelsShown) - setScrollBarPos(SB_CHAN_SCROLL, song.antChn - editor.ui.numChannelsShown, true); + if (ui.channelOffset > song.antChn-ui.numChannelsShown) + setScrollBarPos(SB_CHAN_SCROLL, song.antChn - ui.numChannelsShown, true); } - if (editor.cursor.ch >= editor.ui.channelOffset+editor.ui.numChannelsShown) - editor.cursor.ch = editor.ui.channelOffset+editor.ui.numChannelsShown - 1; + if (cursor.ch >= ui.channelOffset+ui.numChannelsShown) + cursor.ch = ui.channelOffset+ui.numChannelsShown - 1; } checkMarkLimits(); @@ -1137,28 +1138,28 @@ void hideTrimScreen(void) hidePushButton(PB_TRIM_CALC); hidePushButton(PB_TRIM_TRIM); - editor.ui.trimScreenShown = false; - editor.ui.scopesShown = true; + ui.trimScreenShown = false; + ui.scopesShown = true; drawScopeFramework(); } void showTrimScreen(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); showTopScreen(false); - editor.ui.trimScreenShown = true; - editor.ui.scopesShown = false; + ui.trimScreenShown = true; + ui.scopesShown = false; drawTrimScreen(); } void toggleTrimScreen(void) { - if (editor.ui.trimScreenShown) + if (ui.trimScreenShown) hideTrimScreen(); else showTrimScreen(); @@ -1220,7 +1221,7 @@ void pbTrimCalc(void) if (xmAfterTrimSize64 < 0) xmAfterTrimSize64 = 0; - if (editor.ui.trimScreenShown) + if (ui.trimScreenShown) drawTrimScreen(); } @@ -1252,6 +1253,6 @@ void resetTrimSizes(void) xmAfterTrimSize64 = -1; spaceSaved64 = -1; - if (editor.ui.trimScreenShown) + if (ui.trimScreenShown) drawTrimScreen(); } diff --git a/src/ft2_unicode.h b/src/ft2_unicode.h @@ -17,7 +17,7 @@ typedef wchar_t UNICHAR; #define UNICHAR_STRCMP(a, b) wcscmp(a, b) #define UNICHAR_STRNCMP(a, b, c) wcsncmp(a, b, c) #define UNICHAR_STRCAT(a, b) wcscat(a, b) -#define UNICHAR_STRDUP(a) wcsdup(a) +#define UNICHAR_STRDUP(a) _wcsdup(a) #define UNICHAR_FOPEN(a, b) _wfopen(a, L ## b) #define UNICHAR_CHDIR(a) _wchdir(a) #define UNICHAR_GETCWD(a, b) _wgetcwd(a, b) diff --git a/src/ft2_video.c b/src/ft2_video.c @@ -33,6 +33,7 @@ #include "ft2_module_loader.h" #include "ft2_midi.h" #include "ft2_bmp.h" +#include "ft2_structs.h" static const uint8_t textCursorData[12] = { @@ -42,6 +43,8 @@ static const uint8_t textCursorData[12] = PAL_FORGRND, PAL_FORGRND, PAL_FORGRND }; +video_t video; // globalized + static bool songIsModified; static char wndTitle[128 + PATH_MAX]; static uint64_t timeNext64, timeNext64Frac; @@ -282,8 +285,8 @@ void enterFullscreen(void) { SDL_DisplayMode dm; - strcpy(editor.ui.fullscreenButtonText, "Go windowed"); - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MISCELLANEOUS) + strcpy(ui.fullscreenButtonText, "Go windowed"); + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MISCELLANEOUS) showConfigScreen(); // redraw so that we can see the new button text if (config.windowFlags & FILTERING) @@ -307,8 +310,8 @@ void enterFullscreen(void) void leaveFullScreen(void) { - strcpy(editor.ui.fullscreenButtonText, "Go fullscreen"); - if (editor.ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MISCELLANEOUS) + strcpy(ui.fullscreenButtonText, "Go fullscreen"); + if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MISCELLANEOUS) showConfigScreen(); // redraw so that we can see the new button text SDL_SetWindowFullscreen(video.window, 0); @@ -1034,24 +1037,24 @@ void handleRedrawing(void) { textBox_t *txt; - if (!editor.ui.configScreenShown && !editor.ui.helpScreenShown) + if (!ui.configScreenShown && !ui.helpScreenShown) { - if (editor.ui.aboutScreenShown) + if (ui.aboutScreenShown) { aboutFrame(); } - else if (editor.ui.nibblesShown) + else if (ui.nibblesShown) { if (editor.NI_Play) moveNibblePlayers(); } else { - if (editor.ui.updatePosSections) + if (ui.updatePosSections) { - editor.ui.updatePosSections = false; + ui.updatePosSections = false; - if (!editor.ui.diskOpShown) + if (!ui.diskOpShown) { drawSongRepS(); drawSongLength(); @@ -1066,7 +1069,7 @@ void handleRedrawing(void) setScrollBarPos(SB_POS_ED, editor.songPos, false); // draw current mode text (not while in extended pattern editor mode) - if (!editor.ui.extended) + if (!ui.extended) { fillRect(115, 80, 74, 10, PAL_DESKTOP); @@ -1078,21 +1081,21 @@ void handleRedrawing(void) } } - if (editor.ui.updatePosEdScrollBar) + if (ui.updatePosEdScrollBar) { - editor.ui.updatePosEdScrollBar = false; + ui.updatePosEdScrollBar = false; setScrollBarPos(SB_POS_ED, song.songPos, false); setScrollBarEnd(SB_POS_ED, (song.len - 1) + 5); } - if (!editor.ui.extended) + if (!ui.extended) { - if (!editor.ui.diskOpShown) + if (!ui.diskOpShown) drawPlaybackTime(); - if (editor.ui.sampleEditorExtShown) + if (ui.sampleEditorExtShown) handleSampleEditorExtRedrawing(); - else if (editor.ui.scopesShown) + else if (ui.scopesShown) drawScopes(); } } @@ -1100,9 +1103,9 @@ void handleRedrawing(void) drawReplayerData(); - if (editor.ui.instEditorShown) + if (ui.instEditorShown) handleInstEditorRedrawing(); - else if (editor.ui.sampleEditorShown) + else if (ui.sampleEditorShown) handleSamplerRedrawing(); // blink text edit cursor @@ -1131,66 +1134,66 @@ static void drawReplayerData(void) if (songPlaying) { - if (editor.ui.drawReplayerPianoFlag) + if (ui.drawReplayerPianoFlag) { - editor.ui.drawReplayerPianoFlag = false; - if (editor.ui.instEditorShown && chSyncEntry != NULL) + ui.drawReplayerPianoFlag = false; + if (ui.instEditorShown && chSyncEntry != NULL) drawPiano(chSyncEntry); } drawPosText = true; - if (editor.ui.configScreenShown || editor.ui.nibblesShown || - editor.ui.helpScreenShown || editor.ui.aboutScreenShown || - editor.ui.diskOpShown) + if (ui.configScreenShown || ui.nibblesShown || + ui.helpScreenShown || ui.aboutScreenShown || + ui.diskOpShown) { drawPosText = false; } if (drawPosText) { - if (editor.ui.drawBPMFlag) + if (ui.drawBPMFlag) { - editor.ui.drawBPMFlag = false; + ui.drawBPMFlag = false; drawSongBPM(editor.speed); } - if (editor.ui.drawSpeedFlag) + if (ui.drawSpeedFlag) { - editor.ui.drawSpeedFlag = false; + ui.drawSpeedFlag = false; drawSongSpeed(editor.tempo); } - if (editor.ui.drawGlobVolFlag) + if (ui.drawGlobVolFlag) { - editor.ui.drawGlobVolFlag = false; + ui.drawGlobVolFlag = false; drawGlobalVol(editor.globalVol); } - if (editor.ui.drawPosEdFlag) + if (ui.drawPosEdFlag) { - editor.ui.drawPosEdFlag = false; + ui.drawPosEdFlag = false; drawPosEdNums(editor.songPos); setScrollBarPos(SB_POS_ED, editor.songPos, false); } - if (editor.ui.drawPattNumLenFlag) + if (ui.drawPattNumLenFlag) { - editor.ui.drawPattNumLenFlag = false; + ui.drawPattNumLenFlag = false; drawEditPattern(editor.editPattern); drawPatternLength(editor.editPattern); } } } - else if (editor.ui.instEditorShown) + else if (ui.instEditorShown) { drawPiano(NULL); } // handle pattern data updates - if (editor.ui.updatePatternEditor) + if (ui.updatePatternEditor) { - editor.ui.updatePatternEditor = false; - if (editor.ui.patternEditorShown) + ui.updatePatternEditor = false; + if (ui.patternEditorShown) writePattern(editor.pattPos, editor.editPattern); } } diff --git a/src/ft2_video.h b/src/ft2_video.h @@ -16,7 +16,7 @@ enum SPRITE_NUM }; -struct video_t +typedef struct video_t { bool fullscreen, showFPSCounter; uint32_t xScale, yScale; @@ -33,7 +33,7 @@ struct video_t SDL_Renderer *renderer; SDL_Texture *texture; SDL_Surface *iconSurface; -} video; +} video_t; typedef struct { @@ -44,6 +44,8 @@ typedef struct uint16_t w, h; } sprite_t; +extern video_t video; // ft2_video.c + void resetFPSCounter(void); void beginFPSCounter(void); void endFPSCounter(void); diff --git a/src/ft2_wav_renderer.c b/src/ft2_wav_renderer.c @@ -17,6 +17,7 @@ #include "ft2_inst_ed.h" #include "ft2_audio.h" #include "ft2_wav_renderer.h" +#include "ft2_structs.h" #define TICKS_PER_RENDER_CHUNK 64 @@ -117,20 +118,20 @@ void resetWavRenderer(void) WDStartPos = 0; WDStopPos = (uint8_t)song.len - 1; - if (editor.ui.wavRendererShown) + if (ui.wavRendererShown) updateWavRenderer(); } void showWavRenderer(void) { - if (editor.ui.extended) + if (ui.extended) exitPatternEditorExtended(); hideTopScreen(); showTopScreen(false); - editor.ui.wavRendererShown = true; - editor.ui.scopesShown = false; + ui.wavRendererShown = true; + ui.scopesShown = false; WDStartPos = 0; WDStopPos = (uint8_t)song.len - 1; @@ -140,7 +141,7 @@ void showWavRenderer(void) void hideWavRenderer(void) { - editor.ui.wavRendererShown = false; + ui.wavRendererShown = false; hidePushButton(PB_WAV_RENDER); hidePushButton(PB_WAV_EXIT); @@ -154,7 +155,7 @@ void hideWavRenderer(void) hidePushButton(PB_WAV_END_DOWN); hideRadioButtonGroup(RB_GROUP_WAV_RENDER_BITDEPTH); - editor.ui.scopesShown = true; + ui.scopesShown = true; drawScopeFramework(); } @@ -288,13 +289,13 @@ static void updateVisuals(void) editor.tempo = song.tempo; editor.globalVol = song.globVol; - editor.ui.drawPosEdFlag = true; - editor.ui.drawPattNumLenFlag = true; - editor.ui.drawReplayerPianoFlag = true; - editor.ui.drawBPMFlag = true; - editor.ui.drawSpeedFlag = true; - editor.ui.drawGlobVolFlag = true; - editor.ui.updatePatternEditor = true; + ui.drawPosEdFlag = true; + ui.drawPattNumLenFlag = true; + ui.drawReplayerPianoFlag = true; + ui.drawBPMFlag = true; + ui.drawSpeedFlag = true; + ui.drawGlobVolFlag = true; + ui.updatePatternEditor = true; drawPlaybackTime(); } diff --git a/vs2019_project/ft2-clone/ft2-clone.vcxproj b/vs2019_project/ft2-clone/ft2-clone.vcxproj @@ -27,13 +27,13 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PlatformToolset>v142</PlatformToolset> - <CharacterSet>MultiByte</CharacterSet> + <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <UseDebugLibraries>true</UseDebugLibraries> @@ -94,38 +94,30 @@ </AdditionalIncludeDirectories> <PreprocessorDefinitions>__WINDOWS_MM__;NDEBUG;WIN32;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;HAVE_M_PI;HAS_MIDI</PreprocessorDefinitions> <MultiProcessorCompilation>true</MultiProcessorCompilation> - <CompileAsManaged>false</CompileAsManaged> <IntrinsicFunctions>true</IntrinsicFunctions> <StringPooling>true</StringPooling> <MinimalRebuild>false</MinimalRebuild> <BasicRuntimeChecks>Default</BasicRuntimeChecks> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <FunctionLevelLinking>true</FunctionLevelLinking> - <ExceptionHandling>false</ExceptionHandling> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FloatingPointModel>Fast</FloatingPointModel> - <EnableParallelCodeGeneration>false</EnableParallelCodeGeneration> - <FloatingPointExceptions>false</FloatingPointExceptions> <OmitFramePointers>true</OmitFramePointers> <CompileAsWinRT>false</CompileAsWinRT> - <ControlFlowGuard>false</ControlFlowGuard> - <CreateHotpatchableImage>false</CreateHotpatchableImage> - <RuntimeTypeInfo>false</RuntimeTypeInfo> - <OpenMPSupport>false</OpenMPSupport> <BufferSecurityCheck>false</BufferSecurityCheck> <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> <DebugInformationFormat>None</DebugInformationFormat> - <LanguageStandard>stdcpplatest</LanguageStandard> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> + <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType> + <RuntimeTypeInfo>false</RuntimeTypeInfo> </ClCompile> <Link> <AdditionalLibraryDirectories> </AdditionalLibraryDirectories> <SubSystem>Windows</SubSystem> - <AdditionalDependencies>SDL2main.lib;SDL2.lib;winmm.lib;shlwapi.lib;libcmt.lib;libvcruntime.lib;libucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> - <IgnoreSpecificDefaultLibraries> - </IgnoreSpecificDefaultLibraries> - <AdditionalOptions>/NODEFAULTLIB:MSVCRT "notelemetry.obj" %(AdditionalOptions)</AdditionalOptions> + <AdditionalDependencies>SDL2main.lib;SDL2.lib;winmm.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> + <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries> + <AdditionalOptions>"notelemetry.obj" %(AdditionalOptions)</AdditionalOptions> <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors> <MinimumRequiredVersion>5.1</MinimumRequiredVersion> <FullProgramDatabaseFile> @@ -133,16 +125,20 @@ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <OptimizeReferences>true</OptimizeReferences> <EnableCOMDATFolding>true</EnableCOMDATFolding> - <DataExecutionPrevention>false</DataExecutionPrevention> - <ImageHasSafeExceptionHandlers>true</ImageHasSafeExceptionHandlers> <LargeAddressAware>true</LargeAddressAware> <GenerateDebugInformation>false</GenerateDebugInformation> + <SetChecksum>true</SetChecksum> + <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers> + <FixedBaseAddress>false</FixedBaseAddress> </Link> <PostBuildEvent /> <Manifest /> <Manifest> <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness> </Manifest> + <ResourceCompile> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ResourceCompile> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> @@ -152,38 +148,29 @@ </AdditionalIncludeDirectories> <PreprocessorDefinitions>__WINDOWS_MM__;NDEBUG;WIN32;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;HAVE_M_PI;HAS_MIDI</PreprocessorDefinitions> <MultiProcessorCompilation>true</MultiProcessorCompilation> - <CompileAsManaged>false</CompileAsManaged> <IntrinsicFunctions>true</IntrinsicFunctions> <StringPooling>true</StringPooling> <MinimalRebuild>false</MinimalRebuild> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <FunctionLevelLinking>true</FunctionLevelLinking> - <ExceptionHandling>false</ExceptionHandling> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FloatingPointModel>Fast</FloatingPointModel> - <EnableParallelCodeGeneration>false</EnableParallelCodeGeneration> - <FloatingPointExceptions>false</FloatingPointExceptions> <OmitFramePointers>true</OmitFramePointers> - <CompileAsWinRT>false</CompileAsWinRT> <BasicRuntimeChecks>Default</BasicRuntimeChecks> - <ControlFlowGuard>false</ControlFlowGuard> - <CreateHotpatchableImage>false</CreateHotpatchableImage> - <RuntimeTypeInfo>false</RuntimeTypeInfo> - <OpenMPSupport>false</OpenMPSupport> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <BufferSecurityCheck>false</BufferSecurityCheck> <DebugInformationFormat>None</DebugInformationFormat> - <LanguageStandard>stdcpplatest</LanguageStandard> + <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType> + <RuntimeTypeInfo>false</RuntimeTypeInfo> </ClCompile> <Link> <AdditionalLibraryDirectories> </AdditionalLibraryDirectories> <SubSystem>Windows</SubSystem> - <AdditionalDependencies>SDL2main.lib;SDL2.lib;winmm.lib;shlwapi.lib;libcmt.lib;libvcruntime.lib;libucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies>SDL2main.lib;SDL2.lib;winmm.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <IgnoreAllDefaultLibraries> </IgnoreAllDefaultLibraries> - <IgnoreSpecificDefaultLibraries> - </IgnoreSpecificDefaultLibraries> + <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries> <AdditionalOptions>/NODEFAULTLIB:MSVCRT "notelemetry.obj" %(AdditionalOptions)</AdditionalOptions> <TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors> <MinimumRequiredVersion> @@ -193,11 +180,12 @@ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <OptimizeReferences>true</OptimizeReferences> <EnableCOMDATFolding>true</EnableCOMDATFolding> - <DataExecutionPrevention>false</DataExecutionPrevention> <ImageHasSafeExceptionHandlers> </ImageHasSafeExceptionHandlers> <LargeAddressAware>true</LargeAddressAware> <GenerateDebugInformation>false</GenerateDebugInformation> + <SetChecksum>true</SetChecksum> + <FixedBaseAddress>false</FixedBaseAddress> </Link> <PostBuildEvent> <Message> @@ -208,7 +196,7 @@ <Manifest /> <ResourceCompile /> <ResourceCompile> - <PreprocessorDefinitions>_WIN64</PreprocessorDefinitions> + <PreprocessorDefinitions>_WIN64;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ResourceCompile> <Manifest /> <Manifest> @@ -359,6 +347,7 @@ <ClCompile Include="..\..\src\ft2_scopedraw.c" /> <ClCompile Include="..\..\src\ft2_scopes.c" /> <ClCompile Include="..\..\src\ft2_scrollbars.c" /> + <ClCompile Include="..\..\src\ft2_structs.c" /> <ClCompile Include="..\..\src\ft2_sysreqs.c" /> <ClCompile Include="..\..\src\ft2_tables.c" /> <ClCompile Include="..\..\src\ft2_textboxes.c" /> @@ -430,6 +419,7 @@ <ClInclude Include="..\..\src\ft2_scopedraw.h" /> <ClInclude Include="..\..\src\ft2_scopes.h" /> <ClInclude Include="..\..\src\ft2_scrollbars.h" /> + <ClInclude Include="..\..\src\ft2_structs.h" /> <ClInclude Include="..\..\src\ft2_sysreqs.h" /> <ClInclude Include="..\..\src\ft2_tables.h" /> <ClInclude Include="..\..\src\ft2_textboxes.h" /> diff --git a/vs2019_project/ft2-clone/ft2-clone.vcxproj.filters b/vs2019_project/ft2-clone/ft2-clone.vcxproj.filters @@ -76,6 +76,7 @@ <ClCompile Include="..\..\src\gfxdata\ft2_bmp_gui.c"> <Filter>graphics</Filter> </ClCompile> + <ClCompile Include="..\..\src\ft2_structs.c" /> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\src\ft2_audio.h"> @@ -216,6 +217,9 @@ <ClInclude Include="..\..\src\ft2_bmp.h"> <Filter>headers</Filter> </ClInclude> + <ClInclude Include="..\..\src\ft2_structs.h"> + <Filter>headers</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="headers">