| 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 <thread> |
| 30 | #include <vector> |
| 31 | #include <utility> |
| 32 | #include <mutex> |
| 33 | #include <map> |
| 34 | extern "C" |
| 35 | { |
| 36 | #include <xdo.h> |
| 37 | #include <pulse/simple.h> |
| 38 | } |
| 39 | |
| 40 | class MouseCursorTracker |
| 41 | { |
| 42 | public: |
| 43 | MouseCursorTracker(std::string cfgPath, |
| 44 | std::vector<std::pair<std::string, int> > motions = {}, |
| 45 | std::vector<std::string> expressions = {}); |
| 46 | ~MouseCursorTracker(); |
| 47 | |
| 48 | enum class MotionPriority |
| 49 | { |
| 50 | // See LAppDefine.cpp in Demo |
| 51 | none, |
| 52 | idle, |
| 53 | normal, |
| 54 | force |
| 55 | }; |
| 56 | |
| 57 | struct Params |
| 58 | { |
| 59 | std::map<std::string, double> live2d; |
| 60 | |
| 61 | bool autoBlink; |
| 62 | bool autoBreath; |
| 63 | bool randomIdleMotion; |
| 64 | bool useLipSync; |
| 65 | double lipSyncParam; |
| 66 | |
| 67 | MotionPriority motionPriority; |
| 68 | std::string motionGroup; |
| 69 | int motionNumber; |
| 70 | |
| 71 | std::string expression; |
| 72 | }; |
| 73 | |
| 74 | Params getParams(void); |
| 75 | |
| 76 | void stop(void); |
| 77 | |
| 78 | void mainLoop(void); |
| 79 | |
| 80 | private: |
| 81 | struct Coord |
| 82 | { |
| 83 | int x; |
| 84 | int y; |
| 85 | }; |
| 86 | |
| 87 | struct Config |
| 88 | { |
| 89 | int sleepMs; |
| 90 | bool autoBlink; |
| 91 | bool autoBreath; |
| 92 | bool randomIdleMotion; |
| 93 | bool useLipSync; |
| 94 | double lipSyncGain; |
| 95 | double lipSyncCutOff; |
| 96 | unsigned int audioBufSize; |
| 97 | double mouthForm; |
| 98 | int top; |
| 99 | int bottom; |
| 100 | int left; |
| 101 | int right; |
| 102 | int screen; |
| 103 | Coord origin; |
| 104 | } m_cfg; |
| 105 | |
| 106 | std::map<std::string, double> m_overrideMap; |
| 107 | |
| 108 | bool m_stop; |
| 109 | |
| 110 | Coord m_curPos; |
| 111 | |
| 112 | xdo_t *m_xdo; |
| 113 | |
| 114 | std::thread m_getVolumeThread; |
| 115 | std::thread m_parseCommandThread; |
| 116 | void audioLoop(void); |
| 117 | void cliLoop(void); |
| 118 | void processCommand(std::string); |
| 119 | double m_currentVol; |
| 120 | pa_simple *m_pulse; |
| 121 | |
| 122 | MotionPriority m_motionPriority; |
| 123 | std::string m_motionGroup; |
| 124 | int m_motionNumber; |
| 125 | std::mutex m_motionMutex; |
| 126 | std::string m_expression; |
| 127 | |
| 128 | void populateDefaultConfig(void); |
| 129 | void parseConfig(std::string cfgPath); |
| 130 | }; |
| 131 | |
| 132 | #endif |