-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessAudioControl.h
105 lines (76 loc) · 2.73 KB
/
ProcessAudioControl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#ifndef __ProcessAudioControl_H__
#define __ProcessAudioControl_H__
#include <string>
#include <tuple>
#include <Windows.h>
#include <audiopolicy.h>
#include <tlhelp32.h>
#include <Mmdeviceapi.h>
#pragma comment(lib, "Kernel32.lib")
#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "User32.lib")
class ProcessAudioControl {
public:
ProcessAudioControl() : channel(nullptr), hwnd(NULL), pid(NULL), needsCleanup(false), autoReconnect(true) {};
// Calls cleanup()
~ProcessAudioControl();
// Select the target executable
// @param _exe the file name of the target e.g. L"Spotify.exe"
void selectExecutableName(const std::wstring& _exe);
// Manually select the target process
// @param _hwnd the target HWND
// @param _pid the target PID
void selectProcess(HWND _hwnd, DWORD _pid);
// Below documentation until prevTrack() is from msdn https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-appcommand
// and describes how programs SHOULD interact.
// Stop playback.
void stop();
// Begin playing at the current position.
// If already paused, it will resume.
void play();
// Pause. If already paused, takes no further action.
void pause();
// Play or pause playback.
void playPause();
// Go to next track.
void nextTrack();
// Go to previous track.
void prevTrack();
// Retrieve target HWND
HWND getHWND() const;
// @return true if the current handles are valid.
// E.g. the current process is running. False otherwise.
bool isValid() const;
// @param _value between 0.0 and 1.0
void volumeUp(float _value);
// @param _value between 0.0 and 1.0
void volumeDown(float _value);
// @param _value between 0.0 and 1.0
void setVolume(float _value);
// Retrieve volume level, value between 0.0 and 1.0
float getVolume();
// Closes open handles and resets internal variables
void cleanup();
// Closes open handles and opens them again (if the target process is running)
void reconnect();
private:
void sendMessage(int _msg);
// checks wether the handles are still valid and
// tries to acquire them again if exe is not empty and autoReconnect is true
void checkConnection();
// releases open handles and calls CoUninitialize()
// does not reset/change variables except channel
void partialCleanup();
// select the executable based on the exe variable
void selectExecutableName();
// select/sets the channel variable based on the pid variable
void findChannel();
IChannelAudioVolume* channel;
HWND hwnd;
DWORD pid;
std::wstring exe;
bool needsCleanup;
bool autoReconnect;
};
#endif // __ProcessAudioControl_H__