Make master volume controllable via input

Standard mapping is +/- keys. Setting is written to es_input.cfg.
This commit is contained in:
Bim Overbohm 2013-05-23 11:43:50 +02:00
commit 970aa78cda
5 changed files with 38 additions and 17 deletions

View file

@ -262,6 +262,9 @@ void InputManager::loadDefaultConfig()
cfg->mapInput("select", Input(DEVICE_KEYBOARD, TYPE_KEY, SDLK_F2, 1, true));
cfg->mapInput("pageup", Input(DEVICE_KEYBOARD, TYPE_KEY, SDLK_RIGHTBRACKET, 1, true));
cfg->mapInput("pagedown", Input(DEVICE_KEYBOARD, TYPE_KEY, SDLK_LEFTBRACKET, 1, true));
cfg->mapInput("mastervolup", Input(DEVICE_KEYBOARD, TYPE_KEY, SDLK_PLUS, 1, true));
cfg->mapInput("mastervoldown", Input(DEVICE_KEYBOARD, TYPE_KEY, SDLK_MINUS, 1, true));
}
void InputManager::writeConfig()

View file

@ -24,7 +24,7 @@ VolumeControl::VolumeControl()
init();
//get original volume levels for system
getVolume(originalVolume);
originalVolume = getVolume();
}
VolumeControl::~VolumeControl()
@ -212,9 +212,9 @@ void VolumeControl::deinit()
#endif
}
void VolumeControl::getVolume(uint8_t & volume)
int VolumeControl::getVolume() const
{
volume = 0;
int volume = 0;
#if defined (__APPLE__)
#error TODO: Not implemented for MacOS yet!!!
@ -235,11 +235,6 @@ void VolumeControl::getVolume(uint8_t & volume)
if (rawVolume > 0)
{
volume = (rawVolume * 100) / (maxVolume - minVolume);
//clamp to 0-100 range
if (volume > 100)
{
volume = 100;
}
}
//else volume = 0;
}
@ -289,11 +284,25 @@ void VolumeControl::getVolume(uint8_t & volume)
}
#endif
//clamp to 0-100 range
if (volume < 0)
{
volume = 0;
}
if (volume > 100)
{
volume = 100;
}
return volume;
}
void VolumeControl::setVolume(uint8_t volume)
void VolumeControl::setVolume(int volume)
{
//clamp to 0-100 range
if (volume < 0)
{
volume = 0;
}
if (volume > 100)
{
volume = 100;

View file

@ -36,8 +36,8 @@ class VolumeControl
IAudioEndpointVolume * endpointVolume;
#endif
uint8_t originalVolume;
uint8_t internalVolume;
int originalVolume;
int internalVolume;
static std::shared_ptr<VolumeControl> sInstance;
@ -49,8 +49,8 @@ public:
void init();
void deinit();
void getVolume(uint8_t & volume);
void setVolume(uint8_t volume);
int getVolume() const;
void setVolume(int volume);
virtual ~VolumeControl();
};

View file

@ -2,6 +2,7 @@
#include <iostream>
#include "Renderer.h"
#include "AudioManager.h"
#include "VolumeControl.h"
Window::Window()
{
@ -73,7 +74,15 @@ void Window::deinit()
void Window::input(InputConfig* config, Input input)
{
if(peekGui())
if(config->isMappedTo("mastervolup", input))
{
VolumeControl::getInstance()->setVolume(VolumeControl::getInstance()->getVolume() + 5);
}
else if(config->isMappedTo("mastervoldown", input))
{
VolumeControl::getInstance()->setVolume(VolumeControl::getInstance()->getVolume() - 5);
}
else if(peekGui())
this->peekGui()->input(config, input);
}

View file

@ -5,9 +5,9 @@
#include "GuiGameList.h"
#include "../Log.h"
static int inputCount = 10;
static std::string inputName[10] = { "Up", "Down", "Left", "Right", "A", "B", "Menu", "Select", "PageUp", "PageDown" };
static std::string inputDispName[10] = { "Up", "Down", "Left", "Right", "Accept", "Back", "Menu", "Jump to Letter", "Page Up", "Page Down" };
static int inputCount = 12;
static std::string inputName[12] = { "Up", "Down", "Left", "Right", "A", "B", "Menu", "Select", "PageUp", "PageDown", "MasterVolUp", "MasterVolDown" };
static std::string inputDispName[12] = { "Up", "Down", "Left", "Right", "Accept", "Back", "Menu", "Jump to Letter", "Page Up", "Page Down", "Master volume up", "Master volume down" };
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target) : Gui(window), mTargetConfig(target)
{