mirror of
https://github.com/kyleneideck/BackgroundMusic
synced 2025-03-02 13:57:15 +00:00
BGMDriver: Copy settings when a new client matches an existing one.
If the new client has the same bundle ID as an existing one, we now copy its settings (volume, etc.) to the new client. This is to fix app volumes not being applied consistently to apps that play audio through multiple subprocesses (specifically Google Chrome). See #61.
This commit is contained in:
parent
dfad77dc35
commit
f61f998c51
3 changed files with 21 additions and 29 deletions
BGMDriver/BGMDriver/DeviceClients
|
@ -17,7 +17,7 @@
|
|||
// BGM_ClientMap.cpp
|
||||
// BGMDriver
|
||||
//
|
||||
// Copyright © 2016 Kyle Neideck
|
||||
// Copyright © 2016, 2017, 2019 Kyle Neideck
|
||||
// Copyright © 2017 Andrew Tonner
|
||||
//
|
||||
|
||||
|
@ -59,11 +59,13 @@ void BGM_ClientMap::AddClient(BGM_Client inClient)
|
|||
// The shadow maps (which were the main maps until we swapped them) are now missing the new client. Add it again to
|
||||
// keep the sets of maps identical.
|
||||
AddClientToShadowMaps(inClient);
|
||||
|
||||
// Remove the client from the past clients map (if it was in there)
|
||||
|
||||
// Insert the client into the past clients map. We do this here rather than in RemoveClient
|
||||
// because some apps add multiple clients with the same bundle ID and we want to give them all
|
||||
// the same settings (volume, etc.).
|
||||
if(inClient.mBundleID.IsValid())
|
||||
{
|
||||
mPastClientMap.erase(inClient.mBundleID);
|
||||
mPastClientMap[inClient.mBundleID] = inClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,12 +104,6 @@ BGM_Client BGM_ClientMap::RemoveClient(UInt32 inClientID)
|
|||
|
||||
BGM_Client theClient = theClientItr->second;
|
||||
|
||||
// Insert the client into the past clients map
|
||||
if(theClient.mBundleID.IsValid())
|
||||
{
|
||||
mPastClientMap[theClient.mBundleID] = theClient;
|
||||
}
|
||||
|
||||
// Remove the client from the shadow maps
|
||||
mClientMapShadow.erase(theClientItr);
|
||||
mClientMapByPIDShadow.erase(theClient.mProcessID);
|
||||
|
|
|
@ -182,8 +182,8 @@ private:
|
|||
std::map<CACFString, BGM_ClientPtrList> mClientMapByBundleID;
|
||||
std::map<CACFString, BGM_ClientPtrList> mClientMapByBundleIDShadow;
|
||||
|
||||
// Clients are added to mPastClientMap after they're removed so we can restore settings specific to them
|
||||
// if they get added again.
|
||||
// Clients are added to mPastClientMap so we can restore settings specific to them if they get
|
||||
// added again.
|
||||
std::map<CACFString, BGM_Client> mPastClientMap;
|
||||
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
// BGM_Clients.cpp
|
||||
// BGMDriver
|
||||
//
|
||||
// Copyright © 2016 Kyle Neideck
|
||||
// Copyright © 2016, 2017, 2019 Kyle Neideck
|
||||
// Copyright © 2017 Andrew Tonner
|
||||
//
|
||||
|
||||
|
@ -350,23 +350,20 @@ bool BGM_Clients::SetClientsRelativeVolumes(const CACFArray inAppVolumes)
|
|||
// keep the middle volume equal to 1 (meaning apps' volumes are unchanged by default).
|
||||
Float32 theRelativeVolume = mRelativeVolumeCurve.ConvertRawToScalar(theRawRelativeVolume) * 4;
|
||||
|
||||
// Try to update the client's volume, first by PID and then, if that fails, by bundle ID
|
||||
//
|
||||
// TODO: Should we always try both in case an app has multiple clients?
|
||||
// Try to update the client's volume, first by PID and then by bundle ID. Always try
|
||||
// both because apps can have multiple clients.
|
||||
if(mClientMap.SetClientsRelativeVolume(theAppPID, theRelativeVolume))
|
||||
{
|
||||
didChangeAppVolumes = true;
|
||||
}
|
||||
else if(mClientMap.SetClientsRelativeVolume(theAppBundleID, theRelativeVolume))
|
||||
|
||||
if(mClientMap.SetClientsRelativeVolume(theAppBundleID, theRelativeVolume))
|
||||
{
|
||||
didChangeAppVolumes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: The app isn't currently a client, so we should add it to the past clients map, or update its
|
||||
// past volume if it's already in there.
|
||||
}
|
||||
|
||||
|
||||
// TODO: If the app isn't currently a client, we should add it to the past clients
|
||||
// map, or update its past volume if it's already in there.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,15 +380,14 @@ bool BGM_Clients::SetClientsRelativeVolumes(const CACFArray inAppVolumes)
|
|||
{
|
||||
didChangeAppVolumes = true;
|
||||
}
|
||||
else if(mClientMap.SetClientsPanPosition(theAppBundleID, thePanPosition))
|
||||
|
||||
if(mClientMap.SetClientsPanPosition(theAppBundleID, thePanPosition))
|
||||
{
|
||||
didChangeAppVolumes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: The app isn't currently a client, so we should add it to the past clients map, or update its
|
||||
// past pan position if it's already in there.
|
||||
}
|
||||
|
||||
// TODO: If the app isn't currently a client, we should add it to the past clients
|
||||
// map, or update its past pan position if it's already in there.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue