Changed from config files from being user-centric to system. Some refactoring. Added install script
This commit is contained in:
+8
-5
@@ -1,22 +1,25 @@
|
||||
#ifndef AUDIODUMP_H
|
||||
#define AUDIODUMP_H
|
||||
|
||||
#include<string>
|
||||
#include"stdio.h"
|
||||
#include"stdlib.h"
|
||||
|
||||
class AudioDump
|
||||
{
|
||||
public:
|
||||
AudioDump()
|
||||
{
|
||||
|
||||
}
|
||||
AudioDump() { }
|
||||
|
||||
void dump()
|
||||
{
|
||||
system("amixer -c 1 get Master > audio.txt");
|
||||
//system("amixer -c 1 get Master > " + audioDump);
|
||||
command += audioDump;
|
||||
system(command.c_str() );
|
||||
}
|
||||
|
||||
private:
|
||||
std::string command{"amixer -c 1 get Master > "};
|
||||
std::string audioDump{"/usr/lib/AudioControl/audio.txt"};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,18 +17,15 @@ AudioInformation::AudioInformation()
|
||||
void AudioInformation::stripInformation()
|
||||
{
|
||||
std::fstream readAudio;
|
||||
readAudio.open("audio.txt", std::ios::in);
|
||||
readAudio.open(audioInfoPath, std::ios::in);
|
||||
|
||||
while (!readAudio.eof())
|
||||
{
|
||||
std::string data;
|
||||
readAudio >> data;
|
||||
|
||||
|
||||
if (data.compare("Playback") == 0)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
if (count == 3)
|
||||
{
|
||||
readAudio >> data;
|
||||
@@ -36,7 +33,6 @@ void AudioInformation::stripInformation()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
readAudio.close();
|
||||
readAudio.open("currentVolume.txt", std::ios::out);
|
||||
|
||||
@@ -46,7 +42,4 @@ void AudioInformation::stripInformation()
|
||||
}
|
||||
|
||||
|
||||
unsigned short AudioInformation::getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
unsigned short AudioInformation::getVolume() const { return volume; }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef AUDIOINFORMATION_H
|
||||
#define AUDIOINFORMATION_H
|
||||
|
||||
#include<string>
|
||||
|
||||
class AudioInformation
|
||||
{
|
||||
public:
|
||||
@@ -11,6 +13,7 @@ public:
|
||||
private:
|
||||
void stripInformation();
|
||||
|
||||
std::string audioInfoPath{"/usr/lib/AudioControl/audio.txt"};
|
||||
unsigned short volume = 0;
|
||||
unsigned short count = 0;
|
||||
const unsigned short MAXCOUNTS = 3;
|
||||
|
||||
@@ -19,13 +19,9 @@ DecreaseVolume::DecreaseVolume()
|
||||
void DecreaseVolume::newVolume()
|
||||
{
|
||||
if ((volume - AFFECTAMOUNT) > playBackOrigin)
|
||||
{
|
||||
volume = volume - AFFECTAMOUNT;
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = 0;
|
||||
}
|
||||
}
|
||||
void DecreaseVolume::updateVolume()
|
||||
{
|
||||
|
||||
@@ -19,13 +19,9 @@ IncreaseVolume::IncreaseVolume()
|
||||
void IncreaseVolume::newVolume()
|
||||
{
|
||||
if ((volume + AFFECTAMOUNT) < playBackEnd)
|
||||
{
|
||||
volume = volume + AFFECTAMOUNT;
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = playBackEnd;
|
||||
}
|
||||
}
|
||||
void IncreaseVolume::updateVolume()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,5 @@ public:
|
||||
|
||||
void newVolume();
|
||||
void updateVolume();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,18 +8,11 @@ int main(int argc, char* argv[])
|
||||
std::string action = *(argv + 1);
|
||||
|
||||
if (action.compare("up") == 0)
|
||||
{
|
||||
IncreaseVolume iv;
|
||||
|
||||
}
|
||||
else if (action.compare("down") == 0)
|
||||
{
|
||||
DecreaseVolume dv;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Choose correct action, up or down" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ void Volume::updateTheCurrentVolume()
|
||||
{
|
||||
std::fstream updateFile;
|
||||
|
||||
updateFile.open("currentVolume.txt", std::ios::out);
|
||||
updateFile.open(curVolumePath, std::ios::out);
|
||||
|
||||
updateFile << volume;
|
||||
|
||||
|
||||
@@ -6,32 +6,20 @@
|
||||
class Volume
|
||||
{
|
||||
public:
|
||||
Volume() { }
|
||||
void setVolume(const unsigned short& volume) { this->volume = volume; }
|
||||
|
||||
Volume()
|
||||
{
|
||||
|
||||
}
|
||||
void setVolume(const unsigned short& volume)
|
||||
{
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
unsigned short getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
unsigned short getVolume() const { return volume; }
|
||||
void updateTheCurrentVolume();
|
||||
virtual void updateVolume() = 0;
|
||||
virtual void newVolume() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
short volume;
|
||||
std::string curVolumePath{"/usr/lib/AudioControl/currentvolume.txt"};
|
||||
unsigned short volume;
|
||||
unsigned short playBackOrigin = 0;
|
||||
unsigned short playBackEnd = 127;
|
||||
const unsigned short AFFECTAMOUNT = 13;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
executabledir="/usr/bin/"
|
||||
configdir="/usr/lib/AudioControl/"
|
||||
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
echo "Not running as root"
|
||||
exit
|
||||
else
|
||||
make
|
||||
if [ ! -d $configdir ]; then
|
||||
umask 000
|
||||
mkdir $configdir
|
||||
echo "Created configuration directory"
|
||||
fi
|
||||
cp AudioControl $executabledir
|
||||
fi
|
||||
@@ -1,2 +1,2 @@
|
||||
AudioVolume : AudioDump.h AudioInformation.cpp AudioInformation.h DecreaseVolume.cpp DecreaseVolume.h IncreaseVolume.cpp IncreaseVolume.h MainVolumeControl.cpp Volume.cpp Volume.h
|
||||
g++ AudioDump.h AudioInformation.cpp AudioInformation.h DecreaseVolume.cpp DecreaseVolume.h IncreaseVolume.cpp IncreaseVolume.h MainVolumeControl.cpp Volume.cpp Volume.h -o AudioVolume
|
||||
AudioControl : AudioDump.h AudioInformation.cpp AudioInformation.h DecreaseVolume.cpp DecreaseVolume.h IncreaseVolume.cpp IncreaseVolume.h MainVolumeControl.cpp Volume.cpp Volume.h
|
||||
g++ AudioDump.h AudioInformation.cpp AudioInformation.h DecreaseVolume.cpp DecreaseVolume.h IncreaseVolume.cpp IncreaseVolume.h MainVolumeControl.cpp Volume.cpp Volume.h -o AudioControl
|
||||
|
||||
Reference in New Issue
Block a user