Olav SørensenPushed v1.66 codef56d9f63 years agoHistory
1433 lines · 25.9 KB · C
RawDownload
// for finding memory leaks in debug mode with Visual Studio#if defined _DEBUG && defined _MSC_VER#include <crtdbg.h>#endif #include <stdint.h>#include <stdbool.h>#include <string.h>#include "ft2_header.h"#include "ft2_keyboard.h"#include "ft2_gui.h"#include "ft2_about.h"#include "ft2_video.h"#include "ft2_edit.h"#include "ft2_config.h"#include "ft2_help.h"#include "ft2_mouse.h"#include "ft2_nibbles.h"#include "ft2_inst_ed.h"#include "ft2_pattern_ed.h"#include "ft2_diskop.h"#include "ft2_wav_renderer.h"#include "ft2_sample_ed.h"#include "ft2_audio.h"#include "ft2_trim.h"#include "ft2_sample_ed_features.h"#include "ft2_structs.h" keyb_t keyb; // globalized static const uint8_t scancodeKey2Note[52] = // keys (USB usage page standard) to FT2 notes look-up table{	0x08, 0x05, 0x04, 0x11, 0x00, 0x07, 0x09, 0x19,	0x0B, 0x00, 0x0E, 0x0C, 0x0A, 0x1B, 0x1D, 0x0D,	0x12, 0x02, 0x14, 0x18, 0x06, 0x0F, 0x03, 0x16,	0x01, 0x00, 0x0E, 0x10, 0x00, 0x13, 0x15, 0x17,	0x00, 0x1A, 0x1C, 0x22, 0x00, 0x00, 0x00, 0x00,	0x00, 0x1F, 0x1E, 0x20, 0x13, 0x00, 0x10, 0x00,	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){	if (scancode == SDL_SCANCODE_CAPSLOCK || scancode == SDL_SCANCODE_NONUSBACKSLASH)		return NOTE_OFF; 	// translate key to note	int8_t note = 0;	if (scancode >= SDL_SCANCODE_B && scancode <= SDL_SCANCODE_SLASH)		note = scancodeKey2Note[(int32_t)scancode - SDL_SCANCODE_B]; 	if (note == 0)		return -1; // not a note key, do further key handling 	return note + (editor.curOctave * 12);} void readKeyModifiers(void){	const SDL_Keymod modState = SDL_GetModState(); 	keyb.leftCtrlPressed = (modState & KMOD_LCTRL) ? true : false;	keyb.leftAltPressed = (modState & KMOD_LALT) ? true : false;	keyb.leftShiftPressed = (modState & KMOD_LSHIFT) ? true : false;#ifdef __APPLE__	keyb.leftCommandPressed = (modState & KMOD_LGUI) ? true : false;#endif	keyb.keyModifierDown = (modState & (KMOD_LSHIFT | KMOD_LCTRL | KMOD_LALT | KMOD_LGUI)) ? true : false;} void keyUpHandler(SDL_Scancode scancode, SDL_Keycode keycode){	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.	*/	if (keyb.ignoreCurrKeyUp)	{		keyb.ignoreCurrKeyUp = false;		return;	} 	if (cursor.object == CURSOR_NOTE && !keyb.keyModifierDown)		testNoteKeysRelease(scancode); 	if (scancode == SDL_SCANCODE_KP_PLUS)		keyb.numPadPlusPressed = false; 	keyb.keyRepeat = false; 	(void)keycode;} void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode, bool keyWasRepeated){	if (keycode == SDLK_UNKNOWN)		return; 	// revert "delete/rename" mouse modes (disk op.)	if (mouse.mode != MOUSE_MODE_NORMAL)		setMouseMode(MOUSE_MODE_NORMAL); 	if (ui.sysReqShown)	{		if (keycode == SDLK_RETURN)			ui.sysReqEnterPressed = true;		else if (keycode == SDLK_ESCAPE)			ui.sysReqShown = false; 		return;	} 	if (testNibblesCheatCodes(keycode))		return; // current key (+ modifiers) matches nibbles cheat code sequence, ignore current key here 	if (keyWasRepeated)	{		if (editor.NI_Play || !keyb.keyRepeat)			return; // do NOT repeat keys in Nibbles or if keyRepeat is disabled	} 	if (scancode != SDL_SCANCODE_ESCAPE)		keyb.keyRepeat = true; 	// handle certain keys (home/end/left/right etc) when editing text	if (editor.editTextFlag)	{		handleTextEditControl(keycode);		return;	} 	if (editor.NI_Play)	{		nibblesKeyAdministrator(scancode);		return;	} 	if (keycode == SDLK_ESCAPE)	{		if (quitBox(false) == 1)			editor.throwExit = true; 		return;	} 	if (scancode == SDL_SCANCODE_KP_PLUS)		keyb.numPadPlusPressed = true; 	if (handleEditKeys(keycode, scancode))		return; 	if (keyb.keyModifierDown && checkModifiedKeys(keycode))		return; 	handleKeys(keycode, scancode); // no pattern editing, do general key handling} static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey){	// if we're holding numpad plus but not pressing bank keys, don't check any other key	if (keyb.numPadPlusPressed && !keyb.leftCtrlPressed)	{		if (scanKey != SDL_SCANCODE_NUMLOCKCLEAR && scanKey != SDL_SCANCODE_KP_DIVIDE &&			scanKey != SDL_SCANCODE_KP_MULTIPLY  && scanKey != SDL_SCANCODE_KP_MINUS)		{			return;		}	} 	// handle scankeys (actual key on keyboard, using US keyb. layout)	switch (scanKey)	{		case SDL_SCANCODE_KP_ENTER: pbSwapInstrBank(); return; 		case SDL_SCANCODE_NUMLOCKCLEAR:		{			if (keyb.numPadPlusPressed)			{				if (editor.instrBankSwapped)					pbSetInstrBank13();				else					pbSetInstrBank5();			}			else			{				if (editor.instrBankSwapped)					pbSetInstrBank9();				else					pbSetInstrBank1();			}		}		return; 		case SDL_SCANCODE_KP_DIVIDE:		{			if (keyb.numPadPlusPressed)			{				if (editor.instrBankSwapped)					pbSetInstrBank14();				else					pbSetInstrBank6();			}			else			{				if (editor.instrBankSwapped)					pbSetInstrBank10();				else					pbSetInstrBank2();			}		}		return; 		case SDL_SCANCODE_KP_MULTIPLY:		{			if (keyb.numPadPlusPressed)			{				if (editor.instrBankSwapped)					pbSetInstrBank15();				else					pbSetInstrBank7();			}			else			{				if (editor.instrBankSwapped)					pbSetInstrBank11();				else					pbSetInstrBank3();			}		}		return; 		case SDL_SCANCODE_KP_MINUS:		{			if (keyb.leftCtrlPressed) // non-FT2 feature: Decrease master volume by 16			{				if (config.masterVol >= 16)					config.masterVol -= 16;				else					config.masterVol = 0; 				setAudioAmp(config.boostLevel, config.masterVol, !!(config.specialFlags & BITDEPTH_32));				if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_AUDIO)					showConfigScreen();			}			else			{				if (keyb.numPadPlusPressed)				{					if (editor.instrBankSwapped)						pbSetInstrBank16();					else						pbSetInstrBank8();				}				else				{					if (editor.instrBankSwapped)						pbSetInstrBank12();					else						pbSetInstrBank4();				}			}		}		return; 		case SDL_SCANCODE_KP_PLUS:		{			if (keyb.leftCtrlPressed) // non-FT2 feature: Increase master volume by 16			{				if (config.masterVol <= 256-16)					config.masterVol += 16;				else					config.masterVol = 256; 				setAudioAmp(config.boostLevel, config.masterVol, !!(config.specialFlags & BITDEPTH_32));				if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_AUDIO)					showConfigScreen();			}		}		return; 		case SDL_SCANCODE_KP_PERIOD:		{			if (editor.curInstr > 0)			{				if (keyb.leftShiftPressed) // this only triggers if num lock is off. Probably an SDL bug...				{					clearSample();				}				else				{					if (editor.curInstr == 0 || instr[editor.curInstr] == NULL)						return; 					if (okBox(1, "System request", "Clear instrument?") == 1)					{						freeInstr(editor.curInstr);						memset(song.instrName[editor.curInstr], 0, sizeof(song.instrName[editor.curInstr]));						updateNewInstrument();						setSongModifiedFlag();					}				}			}		}		return; 		case SDL_SCANCODE_KP_0: setNewInstr(0); return;		case SDL_SCANCODE_KP_1: setNewInstr(editor.instrBankOffset+1); return;		case SDL_SCANCODE_KP_2: setNewInstr(editor.instrBankOffset+2); return;		case SDL_SCANCODE_KP_3: setNewInstr(editor.instrBankOffset+3); return;		case SDL_SCANCODE_KP_4: setNewInstr(editor.instrBankOffset+4); return;		case SDL_SCANCODE_KP_5: setNewInstr(editor.instrBankOffset+5); return;		case SDL_SCANCODE_KP_6: setNewInstr(editor.instrBankOffset+6); return;		case SDL_SCANCODE_KP_7: setNewInstr(editor.instrBankOffset+7); return;		case SDL_SCANCODE_KP_8: setNewInstr(editor.instrBankOffset+8); return; 		case SDL_SCANCODE_GRAVE: // "key below esc"		{			if (keyb.leftShiftPressed)			{				// decrease edit skip				if (editor.editRowSkip == 0)					editor.editRowSkip = 16;				else					editor.editRowSkip--;			}			else			{				// increase edit skip				if (editor.editRowSkip == 16)					editor.editRowSkip = 0;				else					editor.editRowSkip++;			} 			if (!ui.nibblesShown     && !ui.configScreenShown &&				!ui.aboutScreenShown && !ui.diskOpShown       &&				!ui.helpScreenShown  && !ui.extended)			{				drawIDAdd();			}		}		return; 		default: break;	} 	// no normal key (keycode) pressed (XXX: shouldn't happen..?)	if (keycode == SDLK_UNKNOWN)		return; 	// handle normal keys (keycodes - affected by keyb. layout in OS)	switch (keycode)	{		default: return; 		case SDLK_DELETE: // non-FT2 addition		{			if (ui.sampleEditorShown)				sampCut();		}		break; 		// This is maybe not an ideal key for this anymore...		//case SDLK_PRINTSCREEN: togglePatternEditorExtended(); break; 		// EDIT/PLAY KEYS 		// record pattern		case SDLK_RSHIFT: startPlaying(PLAYMODE_RECPATT, 0); break; 		// play song#ifdef __APPLE__		case SDLK_RGUI: // fall-through for Apple keyboards#endif		case SDLK_RCTRL:			startPlaying(PLAYMODE_SONG, 0);		break; 		// play pattern		case SDLK_RALT:		{			if (!keyb.leftCtrlPressed) // kludge for Mac (toggle fullscreen)				startPlaying(PLAYMODE_PATT, 0);		}		break; 		case SDLK_SPACE:		{			if (playMode == PLAYMODE_IDLE)			{				lockMixerCallback();				memset(editor.keyOnTab, 0, sizeof (editor.keyOnTab));				playMode = PLAYMODE_EDIT;				ui.updatePosSections = true; // for updating mode text				unlockMixerCallback();			}			else			{				stopPlaying();			}		}		break; 		case SDLK_TAB:		{			if (keyb.leftShiftPressed)				cursorTabLeft();			else				cursorTabRight();		}		break; 		case SDLK_LEFT:  cursorLeft();  break;		case SDLK_RIGHT: cursorRight(); break; 		// function Keys (F1..F12) 		case SDLK_F1:		{			     if (keyb.leftShiftPressed) trackTranspAllInsDn();			else if (keyb.leftCtrlPressed)  pattTranspAllInsDn();			else if (keyb.leftAltPressed)   blockTranspAllInsDn();			else                            editor.curOctave = 0;		}		break; 		case SDLK_F2:		{			     if (keyb.leftShiftPressed) trackTranspAllInsUp();			else if (keyb.leftCtrlPressed)  pattTranspAllInsUp();			else if (keyb.leftAltPressed)   blockTranspAllInsUp();			else                            editor.curOctave = 1;		}		break; 		case SDLK_F3:		{			     if (keyb.leftShiftPressed) cutTrack();			else if (keyb.leftCtrlPressed)  cutPattern();			else if (keyb.leftAltPressed)   cutBlock();			else                            editor.curOctave = 2;		}		break; 		case SDLK_F4:		{			     if (keyb.leftShiftPressed) copyTrack();			else if (keyb.leftCtrlPressed)  copyPattern();			else if (keyb.leftAltPressed)   copyBlock();			else                            editor.curOctave = 3;		}		break; 		case SDLK_F5:		{			     if (keyb.leftShiftPressed) pasteTrack();			else if (keyb.leftCtrlPressed)  pastePattern();			else if (keyb.leftAltPressed)   pasteBlock();			else                            editor.curOctave = 4;		}		break; 		case SDLK_F6: editor.curOctave = 5; break; 		case SDLK_F7:		{			     if (keyb.leftShiftPressed) trackTranspCurInsDn();			else if (keyb.leftCtrlPressed)  pattTranspCurInsDn();			else if (keyb.leftAltPressed)   blockTranspCurInsDn();			else                            editor.curOctave = 6;		}		break; 		case SDLK_F8:		{			     if (keyb.leftShiftPressed) trackTranspCurInsUp();			else if (keyb.leftCtrlPressed)  pattTranspCurInsUp();			else if (keyb.leftAltPressed)   blockTranspCurInsUp();			else                            editor.curOctave = 6;		}		break; 		case SDLK_F9:		{			lockAudio(); 			song.row = editor.ptnJumpPos[0];			if (song.row >= song.currNumRows)				song.row = song.currNumRows - 1; 			if (!songPlaying)			{				editor.row = (uint8_t)song.row;				ui.updatePatternEditor = true;			}

Lines 1–500 of 1433.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t