mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
separate audience section in voice
This commit is contained in:
1 parent
eca1a9f0e0
commit
1367e162c0
6 files changed
+97
-35
No files matched your search
@@ -7,7 +7,8 @@
|
||||
#include "abaddon.hpp"
|
||||
#include "audio/manager.hpp"
|
||||
#include "components/lazyimage.hpp"
|
||||
#include "voicewindowuserlistentry.hpp"
|
||||
#include "voicewindowaudiencelistentry.hpp"
|
||||
#include "voicewindowspeakerlistentry.hpp"
|
||||
#include "windows/voicesettingswindow.hpp"
|
||||
|
||||
// clang-format on
|
||||
@@ -196,7 +197,13 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
|
||||
},
|
||||
*this));
|
||||
|
||||
m_scroll.add(m_user_list);
|
||||
m_TMP_speakers_label.set_markup("<b>Speakers</b>");
|
||||
m_listing.pack_start(m_TMP_speakers_label, false, true);
|
||||
m_listing.pack_start(m_speakers_list, false, true);
|
||||
m_TMP_audience_label.set_markup("<b>Audience</b>");
|
||||
m_listing.pack_start(m_TMP_audience_label, false, true);
|
||||
m_listing.pack_start(m_audience_list, false, true);
|
||||
m_scroll.add(m_listing);
|
||||
m_controls.add(m_mute);
|
||||
m_controls.add(m_deafen);
|
||||
m_controls.add(m_noise_suppression);
|
||||
@@ -221,15 +228,16 @@ void VoiceWindow::SetUsers(const std::unordered_set<Snowflake> &user_ids) {
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto me = discord.GetUserData().ID;
|
||||
for (auto id : user_ids) {
|
||||
if (id == me) continue;
|
||||
if (discord.IsUserSpeaker(id)) {
|
||||
m_user_list.add(*CreateRow(id));
|
||||
if (id != me) m_speakers_list.add(*CreateSpeakerRow(id));
|
||||
} else {
|
||||
m_audience_list.add(*CreateAudienceRow(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gtk::ListBoxRow *VoiceWindow::CreateRow(Snowflake id) {
|
||||
auto *row = Gtk::make_managed<VoiceWindowUserListEntry>(id);
|
||||
Gtk::ListBoxRow *VoiceWindow::CreateSpeakerRow(Snowflake id) {
|
||||
auto *row = Gtk::make_managed<VoiceWindowSpeakerListEntry>(id);
|
||||
m_rows[id] = row;
|
||||
auto &vc = Abaddon::Get().GetDiscordClient().GetVoiceClient();
|
||||
row->RestoreGain(vc.GetUserVolume(id));
|
||||
@@ -239,7 +247,14 @@ Gtk::ListBoxRow *VoiceWindow::CreateRow(Snowflake id) {
|
||||
row->signal_volume().connect([this, id](double volume) {
|
||||
m_signal_user_volume_changed.emit(id, volume);
|
||||
});
|
||||
row->show_all();
|
||||
row->show();
|
||||
return row;
|
||||
}
|
||||
|
||||
Gtk::ListBoxRow *VoiceWindow::CreateAudienceRow(Snowflake id) {
|
||||
auto *row = Gtk::make_managed<VoiceWindowAudienceListEntry>(id);
|
||||
m_rows[id] = row;
|
||||
row->show();
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -251,6 +266,13 @@ void VoiceWindow::OnDeafenChanged() {
|
||||
m_signal_deafen.emit(m_deafen.get_active());
|
||||
}
|
||||
|
||||
void VoiceWindow::TryDeleteRow(Snowflake id) {
|
||||
if (auto it = m_rows.find(id); it != m_rows.end()) {
|
||||
delete it->second;
|
||||
m_rows.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
bool VoiceWindow::UpdateVoiceMeters() {
|
||||
auto &audio = Abaddon::Get().GetAudio();
|
||||
switch (audio.GetVADMethod()) {
|
||||
@@ -267,7 +289,9 @@ bool VoiceWindow::UpdateVoiceMeters() {
|
||||
for (auto [id, row] : m_rows) {
|
||||
const auto ssrc = Abaddon::Get().GetDiscordClient().GetSSRCOfUser(id);
|
||||
if (ssrc.has_value()) {
|
||||
row->SetVolumeMeter(audio.GetSSRCVolumeLevel(*ssrc));
|
||||
if (auto *speaker_row = dynamic_cast<VoiceWindowSpeakerListEntry *>(row)) {
|
||||
speaker_row->SetVolumeMeter(audio.GetSSRCVolumeLevel(*ssrc));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -291,32 +315,25 @@ void VoiceWindow::OnUserConnect(Snowflake user_id, Snowflake to_channel_id) {
|
||||
if (m_channel_id == to_channel_id) {
|
||||
if (auto it = m_rows.find(user_id); it == m_rows.end()) {
|
||||
if (Abaddon::Get().GetDiscordClient().IsUserSpeaker(user_id)) {
|
||||
m_user_list.add(*CreateRow(user_id));
|
||||
m_speakers_list.add(*CreateSpeakerRow(user_id));
|
||||
} else {
|
||||
m_audience_list.add(*CreateAudienceRow(user_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VoiceWindow::OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id) {
|
||||
if (m_channel_id == from_channel_id) {
|
||||
if (auto it = m_rows.find(user_id); it != m_rows.end()) {
|
||||
delete it->second;
|
||||
m_rows.erase(it);
|
||||
}
|
||||
}
|
||||
if (m_channel_id == from_channel_id) TryDeleteRow(user_id);
|
||||
}
|
||||
|
||||
void VoiceWindow::OnSpeakerStateChanged(Snowflake channel_id, Snowflake user_id, bool is_speaker) {
|
||||
if (m_channel_id != channel_id) return;
|
||||
TryDeleteRow(user_id);
|
||||
if (is_speaker) {
|
||||
if (auto it = m_rows.find(user_id); it == m_rows.end()) {
|
||||
m_user_list.add(*CreateRow(user_id));
|
||||
}
|
||||
m_speakers_list.add(*CreateSpeakerRow(user_id));
|
||||
} else {
|
||||
if (auto it = m_rows.find(user_id); it != m_rows.end()) {
|
||||
delete it->second;
|
||||
m_rows.erase(it);
|
||||
}
|
||||
m_audience_list.add(*CreateAudienceRow(user_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include <unordered_set>
|
||||
// clang-format on
|
||||
|
||||
class VoiceWindowUserListEntry;
|
||||
|
||||
class VoiceWindow : public Gtk::Window {
|
||||
public:
|
||||
VoiceWindow(Snowflake channel_id);
|
||||
@@ -25,7 +23,8 @@ public:
|
||||
private:
|
||||
void SetUsers(const std::unordered_set<Snowflake> &user_ids);
|
||||
|
||||
Gtk::ListBoxRow *CreateRow(Snowflake id);
|
||||
Gtk::ListBoxRow *CreateSpeakerRow(Snowflake id);
|
||||
Gtk::ListBoxRow *CreateAudienceRow(Snowflake id);
|
||||
|
||||
void OnUserConnect(Snowflake user_id, Snowflake to_channel_id);
|
||||
void OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id);
|
||||
@@ -34,6 +33,8 @@ private:
|
||||
void OnMuteChanged();
|
||||
void OnDeafenChanged();
|
||||
|
||||
void TryDeleteRow(Snowflake id);
|
||||
|
||||
bool UpdateVoiceMeters();
|
||||
|
||||
void UpdateVADParamValue();
|
||||
@@ -45,7 +46,9 @@ private:
|
||||
Gtk::CheckButton m_deafen;
|
||||
|
||||
Gtk::ScrolledWindow m_scroll;
|
||||
Gtk::ListBox m_user_list;
|
||||
Gtk::VBox m_listing;
|
||||
Gtk::ListBox m_speakers_list;
|
||||
Gtk::ListBox m_audience_list;
|
||||
|
||||
// Shows volume for gate VAD method
|
||||
// Shows probability for RNNoise VAD method
|
||||
@@ -65,7 +68,7 @@ private:
|
||||
Snowflake m_channel_id;
|
||||
bool m_is_stage;
|
||||
|
||||
std::unordered_map<Snowflake, VoiceWindowUserListEntry *> m_rows;
|
||||
std::unordered_map<Snowflake, Gtk::ListBoxRow *> m_rows;
|
||||
|
||||
Gtk::MenuBar m_menu_bar;
|
||||
Gtk::MenuItem m_menu_view;
|
||||
@@ -73,6 +76,8 @@ private:
|
||||
Gtk::MenuItem m_menu_view_settings;
|
||||
|
||||
Gtk::Label m_TMP_stagelabel;
|
||||
Gtk::Label m_TMP_speakers_label;
|
||||
Gtk::Label m_TMP_audience_label;
|
||||
|
||||
public:
|
||||
using type_signal_mute = sigc::signal<void(bool)>;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "voicewindowaudiencelistentry.hpp"
|
||||
|
||||
VoiceWindowAudienceListEntry::VoiceWindowAudienceListEntry(Snowflake id)
|
||||
: m_main(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_avatar(32, 32) {
|
||||
m_name.set_halign(Gtk::ALIGN_START);
|
||||
m_name.set_hexpand(true);
|
||||
|
||||
m_main.add(m_avatar);
|
||||
m_main.add(m_name);
|
||||
add(m_main);
|
||||
show_all_children();
|
||||
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto user = discord.GetUser(id);
|
||||
if (user.has_value()) {
|
||||
m_name.set_text(user->GetUsername());
|
||||
m_avatar.SetURL(user->GetAvatarURL("png", "32"));
|
||||
} else {
|
||||
m_name.set_text("Unknown user");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/lazyimage.hpp"
|
||||
#include "discord/snowflake.hpp"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/listboxrow.h>
|
||||
|
||||
class VoiceWindowAudienceListEntry : public Gtk::ListBoxRow {
|
||||
public:
|
||||
VoiceWindowAudienceListEntry(Snowflake id);
|
||||
|
||||
private:
|
||||
Gtk::Box m_main;
|
||||
LazyImage m_avatar;
|
||||
Gtk::Label m_name;
|
||||
};
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
#include "voicewindowuserlistentry.hpp"
|
||||
#include "voicewindowspeakerlistentry.hpp"
|
||||
|
||||
#include "abaddon.hpp"
|
||||
|
||||
VoiceWindowUserListEntry::VoiceWindowUserListEntry(Snowflake id)
|
||||
VoiceWindowSpeakerListEntry::VoiceWindowSpeakerListEntry(Snowflake id)
|
||||
: m_main(Gtk::ORIENTATION_VERTICAL)
|
||||
, m_horz(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_avatar(32, 32)
|
||||
@@ -41,18 +41,18 @@ VoiceWindowUserListEntry::VoiceWindowUserListEntry(Snowflake id)
|
||||
});
|
||||
}
|
||||
|
||||
void VoiceWindowUserListEntry::SetVolumeMeter(double frac) {
|
||||
void VoiceWindowSpeakerListEntry::SetVolumeMeter(double frac) {
|
||||
m_meter.SetVolume(frac);
|
||||
}
|
||||
|
||||
void VoiceWindowUserListEntry::RestoreGain(double frac) {
|
||||
void VoiceWindowSpeakerListEntry::RestoreGain(double frac) {
|
||||
m_volume.set_value(frac * 100.0);
|
||||
}
|
||||
|
||||
VoiceWindowUserListEntry::type_signal_mute_cs VoiceWindowUserListEntry::signal_mute_cs() {
|
||||
VoiceWindowSpeakerListEntry::type_signal_mute_cs VoiceWindowSpeakerListEntry::signal_mute_cs() {
|
||||
return m_signal_mute_cs;
|
||||
}
|
||||
|
||||
VoiceWindowUserListEntry::type_signal_volume VoiceWindowUserListEntry::signal_volume() {
|
||||
VoiceWindowSpeakerListEntry::type_signal_volume VoiceWindowSpeakerListEntry::signal_volume() {
|
||||
return m_signal_volume;
|
||||
}
|
||||
+2
-2
@@ -10,9 +10,9 @@
|
||||
#include <gtkmm/listboxrow.h>
|
||||
#include <gtkmm/scale.h>
|
||||
|
||||
class VoiceWindowUserListEntry : public Gtk::ListBoxRow {
|
||||
class VoiceWindowSpeakerListEntry : public Gtk::ListBoxRow {
|
||||
public:
|
||||
VoiceWindowUserListEntry(Snowflake id);
|
||||
VoiceWindowSpeakerListEntry(Snowflake id);
|
||||
|
||||
void SetVolumeMeter(double frac);
|
||||
void RestoreGain(double frac);
|
||||
Reference in new issue
Block a user