Add Giant PTT: a full-screen talk button on Android and a resizable window on desktop
Holding it forces transmission in any input mode, past the voice-activation gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,7 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
private final AtomicBoolean localMuted = new AtomicBoolean(false);
|
||||
private final AtomicBoolean transmitting = new AtomicBoolean(false);
|
||||
private final AtomicBoolean pttDown = new AtomicBoolean(false);
|
||||
private final AtomicBoolean forceDown = new AtomicBoolean(false);
|
||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private volatile Settings.InputMode mode;
|
||||
@@ -270,6 +271,11 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
this.pttDown.set(down);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForceTransmit(boolean down) {
|
||||
this.forceDown.set(down);
|
||||
}
|
||||
|
||||
public void setMuted(boolean m) {
|
||||
this.muted.set(m);
|
||||
}
|
||||
@@ -478,6 +484,7 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
return false;
|
||||
}
|
||||
mutedTalking = false;
|
||||
if (forceDown.get()) return true;
|
||||
switch (mode) {
|
||||
case CONTINUOUS:
|
||||
return true;
|
||||
|
||||
@@ -71,6 +71,9 @@ public interface VoiceInput extends Microphone {
|
||||
|
||||
void setPushToTalk(boolean pressed);
|
||||
|
||||
/** Transmits while held, whatever the input mode or the gate says; a mute still wins. */
|
||||
void setForceTransmit(boolean pressed);
|
||||
|
||||
/** Receives the live input level on {@link InputLevel}'s scale, once per captured frame. */
|
||||
void setLevelListener(Consumer<Double> listener);
|
||||
|
||||
|
||||
@@ -107,6 +107,12 @@ public final class Sessions {
|
||||
if (mic != null) mic.setPushToTalk(talking);
|
||||
}
|
||||
|
||||
/** Transmits on the server holding the microphone while held, in any input mode. */
|
||||
public void setForceTransmit(boolean talking) {
|
||||
VoiceInput mic = microphoneOf(microphoneOwner);
|
||||
if (mic != null) mic.setForceTransmit(talking);
|
||||
}
|
||||
|
||||
/** Tells every connected microphone about a key press, as TS3 tells all its connections. */
|
||||
public void keyPressed() {
|
||||
for (ServerSession s : sessions) {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.ts3client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A resizable window that is one big push-to-talk button. Pressing it transmits in any
|
||||
* input mode, past the voice-activation gate.
|
||||
*/
|
||||
final class GiantPttWindow extends JDialog {
|
||||
|
||||
private static final Color IDLE = new Color(0x1C, 0x6F, 0xB8);
|
||||
private static final Color TALKING = new Color(0x2E, 0x9B, 0xF0);
|
||||
|
||||
private final Consumer<Boolean> transmit;
|
||||
private final BooleanSupplier talking;
|
||||
private final Pad pad = new Pad();
|
||||
private boolean pressed;
|
||||
|
||||
/**
|
||||
* @param transmit forces transmission on the server holding the microphone while given {@code true}
|
||||
* @param talking whether we are talking on that server, as it reports
|
||||
*/
|
||||
GiantPttWindow(JFrame owner, Consumer<Boolean> transmit, BooleanSupplier talking) {
|
||||
super(owner, "Giant PTT", false);
|
||||
this.transmit = transmit;
|
||||
this.talking = talking;
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setContentPane(pad);
|
||||
pad.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
press(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
press(false);
|
||||
}
|
||||
});
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
press(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
press(false);
|
||||
}
|
||||
});
|
||||
pad.setPreferredSize(new Dimension(UIScale.scale(360), UIScale.scale(360)));
|
||||
pack();
|
||||
setLocationRelativeTo(owner);
|
||||
}
|
||||
|
||||
/** Our talking state changed on some server. */
|
||||
void refresh() {
|
||||
pad.repaint();
|
||||
}
|
||||
|
||||
private void press(boolean down) {
|
||||
if (pressed == down) return;
|
||||
pressed = down;
|
||||
transmit.accept(down);
|
||||
pad.repaint();
|
||||
}
|
||||
|
||||
private final class Pad extends JComponent {
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2.setColor(Theme.windowBg());
|
||||
g2.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
boolean lit = pressed || talking.getAsBoolean();
|
||||
int margin = UIScale.scale(12);
|
||||
int arc = UIScale.scale(32);
|
||||
g2.setColor(lit ? TALKING : IDLE);
|
||||
g2.fillRoundRect(margin, margin, getWidth() - 2 * margin, getHeight() - 2 * margin, arc, arc);
|
||||
|
||||
String text = lit ? "Talking…" : "Hold to talk";
|
||||
float size = Math.max(UIScale.scale(12f), Math.min(getWidth() / 8f, getHeight() / 4f));
|
||||
g2.setFont(Theme.uiFont().deriveFont(Font.BOLD, size));
|
||||
FontMetrics fm = g2.getFontMetrics();
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString(text, (getWidth() - fm.stringWidth(text)) / 2,
|
||||
(getHeight() - fm.getHeight()) / 2 + fm.getAscent());
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
/** Mirrors the active server's own client state next to the clock; set once the window is up. */
|
||||
private volatile TrayController tray;
|
||||
private GiantPttWindow giantPtt;
|
||||
private final DesktopNotifier notifier;
|
||||
|
||||
private MainToolbar toolbar;
|
||||
@@ -292,6 +293,11 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
if (selected != null) selected.avatar().delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGiantPtt() {
|
||||
showGiantPtt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowIdentities() {
|
||||
showIdentities();
|
||||
@@ -554,7 +560,9 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
/** The local client on {@code tab} started or stopped talking, muted itself, … */
|
||||
void selfStateChanged(ServerTab tab) {
|
||||
if (tabs.contains(tab)) updateTray();
|
||||
if (!tabs.contains(tab)) return;
|
||||
updateTray();
|
||||
if (giantPtt != null) giantPtt.refresh();
|
||||
}
|
||||
|
||||
void tabConnected(ServerTab tab) {
|
||||
@@ -624,6 +632,18 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
sessions.setPushToTalk(talking);
|
||||
}
|
||||
|
||||
private void showGiantPtt() {
|
||||
if (giantPtt == null || !giantPtt.isDisplayable()) {
|
||||
giantPtt = new GiantPttWindow(this, sessions::setForceTransmit, () -> {
|
||||
ServerSession owner = sessions.microphoneOwner();
|
||||
SelfState state = owner == null ? null : owner.selfState();
|
||||
return state == SelfState.TALKING || state == SelfState.COMMANDER_TALKING;
|
||||
});
|
||||
}
|
||||
giantPtt.setVisible(true);
|
||||
giantPtt.toFront();
|
||||
}
|
||||
|
||||
void moveMicrophoneToSelectedTab() {
|
||||
if (selected != null && selected.session().isConnected()) sessions.giveMicrophoneTo(selected.session());
|
||||
updateToolbar();
|
||||
|
||||
@@ -72,6 +72,8 @@ final class MainMenuBar extends JMenuBar {
|
||||
|
||||
void onDeleteAvatar();
|
||||
|
||||
void onGiantPtt();
|
||||
|
||||
void onShowIdentities();
|
||||
|
||||
void onShowContacts();
|
||||
@@ -223,10 +225,13 @@ final class MainMenuBar extends JMenuBar {
|
||||
avatarItem.addActionListener(e -> listener.onSetAvatar());
|
||||
deleteAvatarItem = new JMenuItem("Delete avatar", Icons.of("DELETE_AVATAR"));
|
||||
deleteAvatarItem.addActionListener(e -> listener.onDeleteAvatar());
|
||||
JMenuItem giantPtt = new JMenuItem("Giant PTT", Icons.of("CAPTURE"));
|
||||
giantPtt.addActionListener(e -> listener.onGiantPtt());
|
||||
self.add(awayMenu);
|
||||
self.add(activateItem);
|
||||
self.add(muteItem);
|
||||
self.add(deafItem);
|
||||
self.add(giantPtt);
|
||||
self.addSeparator();
|
||||
self.add(commanderItem);
|
||||
self.addSeparator();
|
||||
|
||||
Reference in New Issue
Block a user