feat: automatically fix left over sink/source
This commit is contained in:
parent
ada83ea246
commit
db569034ed
@ -65,6 +65,9 @@ namespace Soundux::Objects
|
|||||||
passThroughLoopback.end());
|
passThroughLoopback.end());
|
||||||
data.passthroughLoopbackMonitorModuleId = std::stoi(passThroughLoopback);
|
data.passthroughLoopbackMonitorModuleId = std::stoi(passThroughLoopback);
|
||||||
|
|
||||||
|
refreshPlaybackStreams(true);
|
||||||
|
refreshRecordingStreams(true);
|
||||||
|
|
||||||
static const std::regex sourceRegex(R"rgx((.*#(\d+))$|(Name: (.+)))rgx");
|
static const std::regex sourceRegex(R"rgx((.*#(\d+))$|(Name: (.+)))rgx");
|
||||||
auto sources = exec("LC_ALL=C pactl list sources");
|
auto sources = exec("LC_ALL=C pactl list sources");
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
@ -185,7 +188,7 @@ namespace Soundux::Objects
|
|||||||
}
|
}
|
||||||
return true; //* Not having anything to moveback should count as a failure
|
return true; //* Not having anything to moveback should count as a failure
|
||||||
}
|
}
|
||||||
void Pulse::refreshRecordingStreams()
|
void Pulse::refreshRecordingStreams(const bool &fix)
|
||||||
{
|
{
|
||||||
auto sourceList = exec("LC_ALL=C pactl list source-outputs");
|
auto sourceList = exec("LC_ALL=C pactl list source-outputs");
|
||||||
|
|
||||||
@ -208,6 +211,12 @@ namespace Soundux::Objects
|
|||||||
if (recordingStreams.find(stream.name) != recordingStreams.end())
|
if (recordingStreams.find(stream.name) != recordingStreams.end())
|
||||||
{
|
{
|
||||||
stream.source = recordingStreams.at(stream.name).source;
|
stream.source = recordingStreams.at(stream.name).source;
|
||||||
|
if (fix)
|
||||||
|
{
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
system(("pactl move-source-output " + std::to_string(stream.id) + " " + stream.source)
|
||||||
|
.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recordingStreamMutex.unlock_shared();
|
recordingStreamMutex.unlock_shared();
|
||||||
fetchedStreams.emplace_back(stream);
|
fetchedStreams.emplace_back(stream);
|
||||||
@ -252,7 +261,7 @@ namespace Soundux::Objects
|
|||||||
recordingStreams.insert({stream.name, stream});
|
recordingStreams.insert({stream.name, stream});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Pulse::refreshPlaybackStreams()
|
void Pulse::refreshPlaybackStreams(const bool &fix)
|
||||||
{
|
{
|
||||||
auto sourceList = exec("LC_ALL=C pactl list sink-inputs");
|
auto sourceList = exec("LC_ALL=C pactl list sink-inputs");
|
||||||
|
|
||||||
@ -275,6 +284,13 @@ namespace Soundux::Objects
|
|||||||
if (playbackStreams.find(stream.name) != playbackStreams.end())
|
if (playbackStreams.find(stream.name) != playbackStreams.end())
|
||||||
{
|
{
|
||||||
stream.sink = playbackStreams.at(stream.name).sink;
|
stream.sink = playbackStreams.at(stream.name).sink;
|
||||||
|
if (fix)
|
||||||
|
{
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
system(("pactl move-sink-input " + std::to_string(stream.id) + " " + stream.sink +
|
||||||
|
" &>/dev/null")
|
||||||
|
.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
playbackStreamMutex.unlock_shared();
|
playbackStreamMutex.unlock_shared();
|
||||||
fetchedStreams.emplace_back(stream);
|
fetchedStreams.emplace_back(stream);
|
||||||
@ -393,5 +409,9 @@ namespace Soundux::Objects
|
|||||||
{
|
{
|
||||||
system("pactl unload-module module-switch-on-connect &>/dev/null"); // NOLINT
|
system("pactl unload-module module-switch-on-connect &>/dev/null"); // NOLINT
|
||||||
}
|
}
|
||||||
|
bool Pulse::currentlyPassingthrough()
|
||||||
|
{
|
||||||
|
return currentApplicationPassthrough.has_value();
|
||||||
|
}
|
||||||
} // namespace Soundux::Objects
|
} // namespace Soundux::Objects
|
||||||
#endif
|
#endif
|
@ -49,6 +49,7 @@ namespace Soundux
|
|||||||
};
|
};
|
||||||
class Pulse
|
class Pulse
|
||||||
{
|
{
|
||||||
|
void fixLeftOvers();
|
||||||
void unloadLeftOverModules();
|
void unloadLeftOverModules();
|
||||||
void fetchDefaultPulseSource();
|
void fetchDefaultPulseSource();
|
||||||
|
|
||||||
@ -74,12 +75,13 @@ namespace Soundux
|
|||||||
bool revertDefaultSourceToOriginal() const;
|
bool revertDefaultSourceToOriginal() const;
|
||||||
bool moveApplicationToSinkMonitor(const std::string &);
|
bool moveApplicationToSinkMonitor(const std::string &);
|
||||||
|
|
||||||
void refreshRecordingStreams();
|
void refreshRecordingStreams(const bool &fix = false);
|
||||||
std::vector<PulseRecordingStream> getRecordingStreams();
|
std::vector<PulseRecordingStream> getRecordingStreams();
|
||||||
|
|
||||||
void refreshPlaybackStreams();
|
void refreshPlaybackStreams(const bool &fix = false);
|
||||||
std::vector<PulsePlaybackStream> getPlaybackStreams();
|
std::vector<PulsePlaybackStream> getPlaybackStreams();
|
||||||
|
|
||||||
|
bool currentlyPassingthrough();
|
||||||
bool moveBackApplicationFromPassthrough();
|
bool moveBackApplicationFromPassthrough();
|
||||||
std::optional<PulsePlaybackStream> moveApplicationToApplicationPassthrough(const std::string &);
|
std::optional<PulsePlaybackStream> moveApplicationToApplicationPassthrough(const std::string &);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user