aboutsummaryrefslogtreecommitdiff
path: root/utils/adlmidi-2/input.cc
diff options
context:
space:
mode:
authorWohlstand <admin@wohlnet.ru>2017-11-09 22:50:32 +0300
committerWohlstand <admin@wohlnet.ru>2017-11-09 22:50:32 +0300
commit0be25a41ca793c3c03814f529890492adfac8ad5 (patch)
treea099d0025109b689bb0d6847e83b9890e34d5d35 /utils/adlmidi-2/input.cc
parent265ae7a37afb087b9e16f4ddd0eaef28a21826de (diff)
downloadlibADLMIDI-0be25a41ca793c3c03814f529890492adfac8ad5.tar.gz
libADLMIDI-0be25a41ca793c3c03814f529890492adfac8ad5.tar.bz2
libADLMIDI-0be25a41ca793c3c03814f529890492adfac8ad5.zip
Resolve weird crash caused by Tetris inside ADLMIDI2 and other changes
- Move most of inline classes methods into own CC file - Move Input into own header with own CC file to share it with the puzzle game - Created virtual destructors and resolved weak vtable trouble between of Tetris's classes - Remove static declarisons of Tetris class. Instead, let it be member of UserInterface - Fixed forgot note-offs while sorting events row with zero length notes - Fixed crash caused by unsafe access by reference to element of array that was modified/reallocated one or multiple times - Stabilize dealing with zero-length notes
Diffstat (limited to 'utils/adlmidi-2/input.cc')
-rw-r--r--utils/adlmidi-2/input.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/utils/adlmidi-2/input.cc b/utils/adlmidi-2/input.cc
new file mode 100644
index 0000000..9d69469
--- /dev/null
+++ b/utils/adlmidi-2/input.cc
@@ -0,0 +1,56 @@
+#include "input.hpp"
+
+xInput::xInput()
+{
+#ifdef _WIN32
+ inhandle = GetStdHandle(STD_INPUT_HANDLE);
+#endif
+#if (!defined(_WIN32) || defined(__CYGWIN__)) && !defined(__DJGPP__)
+ ioctl(0, TCGETA, &back);
+ struct termio term = back;
+ term.c_lflag &= ~(ICANON | ECHO);
+ term.c_cc[VMIN] = 0; // 0=no block, 1=do block
+ if(ioctl(0, TCSETA, &term) < 0)
+ fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
+#endif
+}
+
+xInput::~xInput()
+{
+#if (!defined(_WIN32) || defined(__CYGWIN__)) && !defined(__DJGPP__)
+ if(ioctl(0, TCSETA, &back) < 0)
+ fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~ O_NONBLOCK);
+#endif
+}
+
+char xInput::PeekInput()
+{
+#ifdef __DJGPP__
+ if(kbhit())
+ {
+ int c = getch();
+ return c ? c : getch();
+ }
+#endif
+#ifdef _WIN32
+ DWORD nread = 0;
+ INPUT_RECORD inbuf[1];
+ while(PeekConsoleInput(inhandle, inbuf, sizeof(inbuf) / sizeof(*inbuf), &nread) && nread)
+ {
+ ReadConsoleInput(inhandle, inbuf, sizeof(inbuf) / sizeof(*inbuf), &nread);
+ if(inbuf[0].EventType == KEY_EVENT
+ && inbuf[0].Event.KeyEvent.bKeyDown)
+ {
+ char c = inbuf[0].Event.KeyEvent.uChar.AsciiChar;
+ unsigned s = inbuf[0].Event.KeyEvent.wVirtualScanCode;
+ if(c == 0) c = s;
+ return c;
+ }
+ }
+#endif
+#if (!defined(_WIN32) || defined(__CYGWIN__)) && !defined(__DJGPP__)
+ char c = 0;
+ if(read(0, &c, 1) == 1) return c;
+#endif
+ return '\0';
+}