Add command-line interface to control model
[mouse-tracker-for-cubism.git] / include / mouse_cursor_tracker.h
CommitLineData
126d8fa4
AIL
1// -*- mode: c++ -*-
2
3#ifndef __MOUSE_CURSOR_TRACKER_H__
4#define __MOUSE_CURSOR_TRACKER_H__
5
6/****
7Copyright (c) 2020 Adrian I. Lam
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in all
17copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25SOFTWARE.
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
34extern "C"
35{
36#include <xdo.h>
37#include <pulse/simple.h>
38}
39
40class MouseCursorTracker
41{
42public:
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
80private:
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