Skip to content

Commit c5d1b7f

Browse files
committed
Add PressToTalkCommand class for PTT functionality
Introduce PressToTalkCommand class in Loupedeck.Steinerd.AudioSwitcherPlugin.Actions namespace. This class inherits from PluginDynamicCommand and implements INotifyPropertyChanged. It manages PTT functionality, allowing users to hold a button to enable communication and release it to mute. Added PTTState property to track PTT state. Implemented OnPropertyChange to handle property changes and mute/unmute the communication device. Overrode ProcessButtonEvent and ProcessTouchEvent to handle events and update PTTState. Overrode GetCommandImage to provide visual representation of PTT state.
1 parent 8ddbd55 commit c5d1b7f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
namespace Loupedeck.Steinerd.AudioSwitcherPlugin.Actions
2+
{
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
using AudioSwitcher.AudioApi.CoreAudio;
10+
11+
internal class PressToTalkCommand : PluginDynamicCommand, INotifyPropertyChanged
12+
13+
{
14+
public bool PTTState
15+
{
16+
get => this._pttState;
17+
set
18+
{
19+
this._pttState = value;
20+
this.OnPropertyChange(nameof(this.PTTState));
21+
22+
}
23+
}
24+
private bool _pttState = false;
25+
26+
public CoreAudioDevice DefaultCommunicationDevice =>
27+
AudioSwitcherPlugin.Instance.AudioController.GetDefaultDevice(AudioSwitcher.AudioApi.DeviceType.Capture, AudioSwitcher.AudioApi.Role.Communications);
28+
public PressToTalkCommand() : base("PTT", "Hold to PTT", "Controls") { }
29+
30+
public event PropertyChangedEventHandler PropertyChanged;
31+
public void OnPropertyChange(String propertyName)
32+
{
33+
if (propertyName == nameof(this.PTTState))
34+
{
35+
this.DefaultCommunicationDevice.SetMuteAsync(!this.PTTState);
36+
}
37+
38+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
39+
}
40+
41+
protected override Boolean ProcessButtonEvent(String actionParameter, DeviceButtonEvent buttonEvent)
42+
{
43+
if (buttonEvent.IsPressed)
44+
{
45+
this.PTTState = true;
46+
this.ActionImageChanged();
47+
return true;
48+
}
49+
else if (!buttonEvent.IsPressed)
50+
{
51+
this.PTTState = false;
52+
this.ActionImageChanged();
53+
return true;
54+
}
55+
56+
return true;
57+
}
58+
59+
protected override Boolean ProcessTouchEvent(String actionParameter, DeviceTouchEvent touchEvent)
60+
{
61+
62+
if (touchEvent.EventType == DeviceTouchEventType.TouchDown)
63+
{
64+
this.PTTState = true;
65+
this.ActionImageChanged();
66+
return true;
67+
}
68+
else if (touchEvent.EventType == DeviceTouchEventType.TouchUp)
69+
{
70+
this.PTTState = false;
71+
this.ActionImageChanged();
72+
return true;
73+
}
74+
75+
return true;
76+
}
77+
78+
protected override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
79+
{
80+
var builder = new BitmapBuilder(imageSize);
81+
builder.Clear(this.PTTState ? new BitmapColor(0, 255, 0) : new BitmapColor(0, 0, 0));
82+
83+
builder.DrawText("PTT", BitmapColor.White);
84+
85+
86+
return builder.ToImage();
87+
}
88+
}
89+
90+
}

0 commit comments

Comments
 (0)