Skip to content

Commit

Permalink
Merge pull request #14 from sandsmark/martin/subgain
Browse files Browse the repository at this point in the history
add support for changing sub gain
  • Loading branch information
janbar committed Sep 22, 2021
2 parents 136297c + b958479 commit 7f24654
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
37 changes: 34 additions & 3 deletions noson/src/renderingcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool RenderingControl::SetMute(uint8_t value, const char* channel)
return false;
}

bool RenderingControl::GetNightmode(uint8_t *value)
bool RenderingControl::GetNightmode(int16_t *value)
{
ElementList args;
args.push_back(ElementPtr(new Element("InstanceID", "0")));
Expand All @@ -132,12 +132,12 @@ bool RenderingControl::GetNightmode(uint8_t *value)
{
ElementList::const_iterator it = vars.FindKey("NightMode");
if (it != vars.end())
return (string_to_uint8((*it)->c_str(), value) == 0);
return (string_to_int16((*it)->c_str(), value) == 0);
}
return false;
}

bool RenderingControl::SetNightmode(uint8_t value)
bool RenderingControl::SetNightmode(int16_t value)
{
ElementList args;
args.push_back(ElementPtr(new Element("InstanceID", "0")));
Expand All @@ -149,6 +149,32 @@ bool RenderingControl::SetNightmode(uint8_t value)
return false;
}

bool RenderingControl::GetSubGain(int16_t *value)
{
ElementList args;
args.push_back(ElementPtr(new Element("InstanceID", "0")));
ElementList vars = Request("GetEQ", args);
if (!vars.empty() && vars[0]->compare("GetEQResponse") == 0)
{
ElementList::const_iterator it = vars.FindKey("SubGain");
if (it != vars.end())
return (string_to_int16((*it)->c_str(), value) == 0);
}
return false;
}

bool RenderingControl::SetSubGain(int16_t value)
{
ElementList args;
args.push_back(ElementPtr(new Element("InstanceID", "0")));
args.push_back(ElementPtr(new Element("EQType", "SubGain")));
args.push_back(ElementPtr(new Element("DesiredValue", std::to_string(value))));
ElementList vars = Request("SetEQ", args);
if (!vars.empty() && vars[0]->compare("SetEQResponse") == 0)
return true;
return false;
}

bool RenderingControl::GetTreble(int8_t* value)
{
ElementList args;
Expand Down Expand Up @@ -334,6 +360,11 @@ void RenderingControl::HandleEventMessage(EventMessagePtr msg)
if (string_to_int32((*++it).c_str(), &num) == 0)
prop->NightMode = num;
}
else if (*it == "SubGain")
{
if (string_to_int32((*++it).c_str(), &num) == 0)
prop->SubGain = num;
}
else if (*it == "Bass")
{
if (string_to_int32((*++it).c_str(), &num) == 0)
Expand Down
8 changes: 6 additions & 2 deletions noson/src/renderingcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ namespace NSROOT

bool SetMute(uint8_t value, const char* channel = CH_MASTER);

bool GetNightmode(uint8_t* value);
bool GetNightmode(int16_t* value);

bool SetNightmode(uint8_t value);
bool SetNightmode(int16_t value);

bool GetSubGain(int16_t* value);

bool SetSubGain(int16_t value);

bool GetTreble(int8_t* value);

Expand Down
24 changes: 22 additions & 2 deletions noson/src/sonosplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool Player::SetMute(const std::string& uuid, uint8_t value)
return false;
}

bool Player::GetNightmode(const std::string &uuid, uint8_t *value)
bool Player::GetNightmode(const std::string &uuid, int16_t *value)
{
for (RCTable::const_iterator it = m_RCTable.begin(); it != m_RCTable.end(); ++it)
{
Expand All @@ -346,7 +346,7 @@ bool Player::GetNightmode(const std::string &uuid, uint8_t *value)
return false;
}

bool Player::SetNightmode(const std::string &uuid, uint8_t value)
bool Player::SetNightmode(const std::string &uuid, int16_t value)
{
for (RCTable::const_iterator it = m_RCTable.begin(); it != m_RCTable.end(); ++it)
{
Expand Down Expand Up @@ -376,6 +376,26 @@ bool Player::SetLoudness(const std::string &uuid, uint8_t value)
return false;
}

bool Player::GetSubGain(const std::string &uuid, int16_t *value)
{
for (RCTable::const_iterator it = m_RCTable.begin(); it != m_RCTable.end(); ++it)
{
if (it->uuid == uuid)
return it->renderingControl->GetSubGain(value);
}
return false;
}

bool Player::SetSubGain(const std::string &uuid, int16_t value)
{
for (RCTable::const_iterator it = m_RCTable.begin(); it != m_RCTable.end(); ++it)
{
if (it->uuid == uuid)
return it->renderingControl->SetSubGain(value);
}
return false;
}

bool Player::GetBass(const std::string &uuid, int8_t* value)
{
for (RCTable::const_iterator it = m_RCTable.begin(); it != m_RCTable.end(); ++it)
Expand Down
6 changes: 4 additions & 2 deletions noson/src/sonosplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ namespace NSROOT
bool GetMute(const std::string& uuid, uint8_t* value);
bool SetMute(const std::string& uuid, uint8_t value);

bool GetNightmode(const std::string& uuid, uint8_t* value);
bool SetNightmode(const std::string& uuid, uint8_t value);
bool GetNightmode(const std::string& uuid, int16_t* value);
bool SetNightmode(const std::string& uuid, int16_t value);
bool GetLoudness(const std::string& uuid, uint8_t* value);
bool SetLoudness(const std::string& uuid, uint8_t value);
bool GetSubGain(const std::string& uuid, int16_t* value);
bool SetSubGain(const std::string& uuid, int16_t value);

bool GetBass(const std::string& uuid, int8_t* value);
bool SetBass(const std::string& uuid, int8_t value);
Expand Down
2 changes: 2 additions & 0 deletions noson/src/sonostypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ namespace NSROOT
, MuteLF(0)
, MuteRF(0)
, NightMode(0)
, SubGain(0)
, Treble(0)
, Bass(0)
, OutputFixed(0)
Expand All @@ -209,6 +210,7 @@ namespace NSROOT
int MuteLF;
int MuteRF;
int NightMode;
int SubGain;
int Treble;
int Bass;
int OutputFixed;
Expand Down

0 comments on commit 7f24654

Please sign in to comment.