| 1 | // -*- mode: c++ -*- |
| 2 | |
| 3 | #ifndef __MOUSE_CURSOR_TRACKER_H__ |
| 4 | #define __MOUSE_CURSOR_TRACKER_H__ |
| 5 | |
| 6 | /**** |
| 7 | Copyright (c) 2020 Adrian I. Lam |
| 8 | |
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | of this software and associated documentation files (the "Software"), to deal |
| 11 | in the Software without restriction, including without limitation the rights |
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | copies of the Software, and to permit persons to whom the Software is |
| 14 | furnished to do so, subject to the following conditions: |
| 15 | |
| 16 | The above copyright notice and this permission notice shall be included in all |
| 17 | copies or substantial portions of the Software. |
| 18 | |
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | SOFTWARE. |
| 26 | ****/ |
| 27 | |
| 28 | #include <string> |
| 29 | #include <map> |
| 30 | #include <thread> |
| 31 | extern "C" |
| 32 | { |
| 33 | #include <xdo.h> |
| 34 | #include <pulse/simple.h> |
| 35 | } |
| 36 | |
| 37 | class MouseCursorTracker |
| 38 | { |
| 39 | public: |
| 40 | MouseCursorTracker(std::string cfgPath); |
| 41 | ~MouseCursorTracker(); |
| 42 | |
| 43 | struct Params |
| 44 | { |
| 45 | double leftEyeOpenness; |
| 46 | double rightEyeOpenness; |
| 47 | double leftEyeSmile; |
| 48 | double rightEyeSmile; |
| 49 | double mouthOpenness; |
| 50 | double mouthForm; |
| 51 | double faceXAngle; |
| 52 | double faceYAngle; |
| 53 | double faceZAngle; |
| 54 | bool autoBlink; |
| 55 | bool autoBreath; |
| 56 | bool randomMotion; |
| 57 | bool useLipSync; |
| 58 | double lipSyncParam; |
| 59 | }; |
| 60 | |
| 61 | Params getParams(void) const; |
| 62 | |
| 63 | void stop(void); |
| 64 | |
| 65 | void mainLoop(void); |
| 66 | |
| 67 | private: |
| 68 | struct Coord |
| 69 | { |
| 70 | int x; |
| 71 | int y; |
| 72 | }; |
| 73 | |
| 74 | struct Config |
| 75 | { |
| 76 | int sleepMs; |
| 77 | bool autoBlink; |
| 78 | bool autoBreath; |
| 79 | bool randomMotion; |
| 80 | bool useLipSync; |
| 81 | double lipSyncGain; |
| 82 | double lipSyncCutOff; |
| 83 | unsigned int audioBufSize; |
| 84 | double mouthForm; |
| 85 | int top; |
| 86 | int bottom; |
| 87 | int left; |
| 88 | int right; |
| 89 | int screen; |
| 90 | Coord middle; |
| 91 | } m_cfg; |
| 92 | |
| 93 | bool m_stop; |
| 94 | |
| 95 | Coord m_curPos; |
| 96 | |
| 97 | xdo_t *m_xdo; |
| 98 | |
| 99 | std::thread m_getVolumeThread; |
| 100 | void audioLoop(void); |
| 101 | double m_currentVol; |
| 102 | pa_simple *m_pulse; |
| 103 | |
| 104 | void populateDefaultConfig(void); |
| 105 | void parseConfig(std::string cfgPath); |
| 106 | }; |
| 107 | |
| 108 | #endif |