-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_mac.cpp
More file actions
37 lines (31 loc) · 910 Bytes
/
Copy pathaudio_mac.cpp
File metadata and controls
37 lines (31 loc) · 910 Bytes
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
#include "audio_mac.h"
#include <QString>
#include <string>
#include <iostream>
#include <stdio.h>
std::string exec(const char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
int getMasterVolume(long* vol) {
QString str = QString::fromStdString(exec("osascript -e \"output volume of (get volume settings)\""));
str.replace("\"", "");
str.replace("\n", "");
bool ok;
*vol = str.toLong(&ok, 10);
return ok;
}
void setMasterVolume(long* vol) {
QString str = QString("osascript -e \"set volume output volume %1\"").arg(*vol);
const char *c_str2 = str.toLocal8Bit().data();
// char* cstr = str.toStdString().c_str();
std::string s = exec(c_str2);
}