Commit | Line | Data |
---|---|---|
126d8fa4 AIL |
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> | |
126d8fa4 | 29 | #include <thread> |
eba2eb3a AIL |
30 | #include <vector> |
31 | #include <utility> | |
32 | #include <mutex> | |
33 | #include <map> | |
126d8fa4 AIL |
34 | extern "C" |
35 | { | |
36 | #include <xdo.h> | |
37 | #include <pulse/simple.h> | |
38 | } | |
39 | ||
40 | class MouseCursorTracker | |
41 | { | |
42 | public: | |
eba2eb3a AIL |
43 | MouseCursorTracker(std::string cfgPath, |
44 | std::vector<std::pair<std::string, int> > motions = {}, | |
45 | std::vector<std::string> expressions = {}); | |
126d8fa4 AIL |
46 | ~MouseCursorTracker(); |
47 | ||
eba2eb3a AIL |
48 | enum class MotionPriority |
49 | { | |
50 | // See LAppDefine.cpp in Demo | |
51 | none, | |
52 | idle, | |
53 | normal, | |
54 | force | |
55 | }; | |
56 | ||
126d8fa4 AIL |
57 | struct Params |
58 | { | |
eba2eb3a AIL |
59 | std::map<std::string, double> live2d; |
60 | ||
126d8fa4 AIL |
61 | bool autoBlink; |
62 | bool autoBreath; | |
eba2eb3a | 63 | bool randomIdleMotion; |
126d8fa4 AIL |
64 | bool useLipSync; |
65 | double lipSyncParam; | |
eba2eb3a AIL |
66 | |
67 | MotionPriority motionPriority; | |
68 | std::string motionGroup; | |
69 | int motionNumber; | |
70 | ||
71 | std::string expression; | |
126d8fa4 AIL |
72 | }; |
73 | ||
eba2eb3a | 74 | Params getParams(void); |
126d8fa4 AIL |
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; | |
eba2eb3a | 92 | bool randomIdleMotion; |
126d8fa4 AIL |
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; | |
eba2eb3a | 103 | Coord origin; |
126d8fa4 AIL |
104 | } m_cfg; |
105 | ||
eba2eb3a AIL |
106 | std::map<std::string, double> m_overrideMap; |
107 | ||
126d8fa4 AIL |
108 | bool m_stop; |
109 | ||
110 | Coord m_curPos; | |
111 | ||
112 | xdo_t *m_xdo; | |
113 | ||
114 | std::thread m_getVolumeThread; | |
eba2eb3a | 115 | std::thread m_parseCommandThread; |
126d8fa4 | 116 | void audioLoop(void); |
eba2eb3a AIL |
117 | void cliLoop(void); |
118 | void processCommand(std::string); | |
126d8fa4 AIL |
119 | double m_currentVol; |
120 | pa_simple *m_pulse; | |
121 | ||
eba2eb3a AIL |
122 | MotionPriority m_motionPriority; |
123 | std::string m_motionGroup; | |
124 | int m_motionNumber; | |
125 | std::mutex m_motionMutex; | |
126 | std::string m_expression; | |
127 | ||
126d8fa4 AIL |
128 | void populateDefaultConfig(void); |
129 | void parseConfig(std::string cfgPath); | |
130 | }; | |
131 | ||
132 | #endif |