-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/Steinerd.AudioSwitcherPlugin/Actions/PressToTalkCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
namespace Loupedeck.Steinerd.AudioSwitcherPlugin.Actions | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using AudioSwitcher.AudioApi.CoreAudio; | ||
|
||
internal class PressToTalkCommand : PluginDynamicCommand, INotifyPropertyChanged | ||
|
||
{ | ||
public bool PTTState | ||
{ | ||
get => this._pttState; | ||
set | ||
{ | ||
this._pttState = value; | ||
this.OnPropertyChange(nameof(this.PTTState)); | ||
|
||
} | ||
} | ||
private bool _pttState = false; | ||
|
||
public CoreAudioDevice DefaultCommunicationDevice => | ||
AudioSwitcherPlugin.Instance.AudioController.GetDefaultDevice(AudioSwitcher.AudioApi.DeviceType.Capture, AudioSwitcher.AudioApi.Role.Communications); | ||
public PressToTalkCommand() : base("PTT", "Hold to PTT", "Controls") { } | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
public void OnPropertyChange(String propertyName) | ||
{ | ||
if (propertyName == nameof(this.PTTState)) | ||
{ | ||
this.DefaultCommunicationDevice.SetMuteAsync(!this.PTTState); | ||
} | ||
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
protected override Boolean ProcessButtonEvent(String actionParameter, DeviceButtonEvent buttonEvent) | ||
{ | ||
if (buttonEvent.IsPressed) | ||
{ | ||
this.PTTState = true; | ||
this.ActionImageChanged(); | ||
return true; | ||
} | ||
else if (!buttonEvent.IsPressed) | ||
{ | ||
this.PTTState = false; | ||
this.ActionImageChanged(); | ||
return true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected override Boolean ProcessTouchEvent(String actionParameter, DeviceTouchEvent touchEvent) | ||
{ | ||
|
||
if (touchEvent.EventType == DeviceTouchEventType.TouchDown) | ||
{ | ||
this.PTTState = true; | ||
this.ActionImageChanged(); | ||
return true; | ||
} | ||
else if (touchEvent.EventType == DeviceTouchEventType.TouchUp) | ||
{ | ||
this.PTTState = false; | ||
this.ActionImageChanged(); | ||
return true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize) | ||
{ | ||
var builder = new BitmapBuilder(imageSize); | ||
builder.Clear(this.PTTState ? new BitmapColor(0, 255, 0) : new BitmapColor(0, 0, 0)); | ||
|
||
builder.DrawText("PTT", BitmapColor.White); | ||
|
||
|
||
return builder.ToImage(); | ||
} | ||
} | ||
|
||
} |