1 #ifndef _PC_MIXER_BACKEND_H
2 #define _PC_MIXER_BACKEND_H
3 
4 #include <QProcess>
5 #include <QStringList>
6 #include <QString>
7 
8 class Mixer{
9 
10 public:
11 	//Process Run
quickRun(QString cmd)12 	static QString quickRun(QString cmd){ //"mixer -S" always returns a single line
13 	  QProcess p;
14 		p.start(cmd);
15 		p.waitForFinished(-1);
16 	  QString out = p.readAllStandardOutput();
17 	  return out;
18 	}
19 
20 	//Mixer Interaction functions
getDevices()21 	static QStringList getDevices(){ //Returns: QStringList[device:Lval:Rval]
22 	  QStringList out = Mixer::quickRun("mixer -S").split(" ").filter(":");
23 	  return out;
24 	}
25 
26 	static void setValues(QString device, int Lpercent, int Rpercent=-1){
27 	  if(Lpercent < 0){ Lpercent = 0; }
28 	  else if(Lpercent > 100){ Lpercent = 100; }
29 	  if(Rpercent < 0){ Rpercent = Lpercent; }
30 	  else if(Rpercent > 100){ Rpercent = 100; }
31 	  Mixer::quickRun("mixer "+device+" "+QString::number(Lpercent)+":"+QString::number(Rpercent));
32 	}
33 
getValues(QString device)34 	static QString getValues(QString device){  //Returns: "Lval:Rval"
35 	  QString out = Mixer::quickRun("mixer -S "+device).section(":",1,2); //trim off the device
36 	  return out;
37 	}
38 
getRecDevice()39 	static QString getRecDevice(){
40 	  return Mixer::quickRun("mixer -S").section("=rec ",-1).simplified();
41 	}
42 
setRecDevice(QString device)43 	static void setRecDevice(QString device){
44 	  Mixer::quickRun("mixer =rec "+device);
45 	}
46 
47 };
48 
49 #endif