Skip to content

Commit

Permalink
#1723 implements left/right channel locking for the talkgroup and sys…
Browse files Browse the repository at this point in the history
…tem of the selected replay call.
  • Loading branch information
sheirerd committed Dec 31, 2023
1 parent 6193e63 commit 0647af8
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.control.Button;
import javafx.scene.control.Separator;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.javafx.IconNode;

Expand All @@ -49,8 +47,6 @@ public class AudioPlaybackControlView extends HBox implements IAudioPlaybackStat
private ToggleButton mPlayButton;
private ToggleButton mPauseButton;
private ToggleButton mStopButton;
private Button mForwardButton;
private Button mBackwardButton;
private boolean mUpdating = false;

/**
Expand All @@ -61,8 +57,7 @@ public AudioPlaybackControlView()
setSpacing(2);
Separator separator = new Separator(Orientation.VERTICAL);
separator.setPadding(new Insets(0, 5, 0 , 7));
getChildren().addAll(getStopButton(), getPlayButton(), getPauseButton(), getAutoRepeatButton(), separator,
getBackwardButton(), getForwardButton());
getChildren().addAll(getStopButton(), getPlayButton(), getPauseButton(), getAutoRepeatButton());
mediaPlayerProperty().addListener((observable, oldValue, newValue) -> updateControls());
}

Expand Down Expand Up @@ -126,8 +121,6 @@ private void updateControls()
getPlayButton().setDisable(disable);
getPauseButton().setDisable(disable);
getAutoRepeatButton().setDisable(disable);
getForwardButton().setDisable(disable);
getBackwardButton().setDisable(disable);
}

/**
Expand Down Expand Up @@ -230,61 +223,6 @@ private ToggleButton getStopButton()
return mStopButton;
}

/**
* Rewind button
*/
private Button getBackwardButton()
{
if(mBackwardButton == null)
{
mBackwardButton = new Button();
mBackwardButton.setTooltip(new Tooltip("Rewind Audio Playback 3 Seconds"));
mBackwardButton.setDisable(true);
IconNode iconNode = new IconNode(FontAwesome.BACKWARD);
iconNode.setIconSize(ICON_SIZE);
iconNode.setFill(Color.BLACK);
mBackwardButton.setGraphic(iconNode);
mBackwardButton.onActionProperty().set(event -> {
MediaPlayer mediaPlayer = mediaPlayerProperty().get();
if(mediaPlayer != null)
{
Duration seek = mediaPlayer.getCurrentTime().subtract(Duration.seconds(2));
mediaPlayer.seek(seek);
}
});
}

return mBackwardButton;
}

/**
* Fast Forward button
*/
private Button getForwardButton()
{
if(mForwardButton == null)
{
mForwardButton = new Button();
mForwardButton.setTooltip(new Tooltip("Fast Forward Audio Playback 3 Seconds"));
mForwardButton.setDisable(true);
IconNode iconNode = new IconNode(FontAwesome.FORWARD);
iconNode.setIconSize(ICON_SIZE);
iconNode.setFill(Color.BLACK);
mForwardButton.setGraphic(iconNode);
mForwardButton.onActionProperty().set(event -> {
MediaPlayer mediaPlayer = mediaPlayerProperty().get();

if(mediaPlayer != null)
{
Duration seek = mediaPlayer.getCurrentTime().add(Duration.seconds(2));
mediaPlayer.seek(seek);
}
});
}

return mForwardButton;
}

private ToggleButton getAutoRepeatButton()
{
if(mAutoRepeatButton == null)
Expand Down
104 changes: 99 additions & 5 deletions src/main/java/io/github/dsheirer/audio/call/CallView.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class CallView extends VBox implements IPageRequestListener
private AudioPlaybackControlView mAudioPlaybackControlView;
private Button mAutoModeLeftButton;
private Button mAutoModeRightButton;
private Button mLockModeLeftButton;
private Button mLockModeRightButton;

/**
* Constructs an instance
Expand Down Expand Up @@ -128,17 +130,22 @@ public void postConstruct()
mAudioPlaybackController.getPrimaryController().add(getAudioPlaybackControlView());

HBox controlBox = new HBox();
controlBox.setSpacing(10);
controlBox.setAlignment(Pos.CENTER);
controlBox.setSpacing(2);
controlBox.setPadding(new Insets(5, 5, 5, 5));
getAudioPlaybackControlView().setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(getSearchBox(), Priority.ALWAYS);
getSearchBox().setAlignment(Pos.CENTER_RIGHT);

Separator separator = new Separator(Orientation.VERTICAL);
Separator separator1 = new Separator(Orientation.VERTICAL);
separator1.setPadding(new Insets(0, 10, 0, 10));
Separator separator2 = new Separator(Orientation.VERTICAL);
separator2.setPadding(new Insets(0, 10, 0, 10));
Label autoLabel = new Label("Auto:");
autoLabel.setAlignment(Pos.CENTER); //TODO: fix this ... alignment is not right
controlBox.getChildren().addAll(getAudioPlaybackControlView(), separator, autoLabel, getAutoModeLeftButton(),
getAutoModeRightButton(), getSearchBox());
Label lockLabel = new Label("Lock:");
controlBox.getChildren().addAll(getAudioPlaybackControlView(), separator1, autoLabel, getAutoModeLeftButton(),
getAutoModeRightButton(), separator2, lockLabel, getLockModeLeftButton(), getLockModeRightButton(),
getSearchBox());

VBox.setVgrow(getCallTableView(), Priority.ALWAYS);
getChildren().addAll(controlBox, getCallTableView(), getPagingBox());
Expand Down Expand Up @@ -301,6 +308,7 @@ private Button getAutoModeLeftButton()
if(mAutoModeLeftButton == null)
{
mAutoModeLeftButton = new Button("Left");
mAutoModeLeftButton.setTooltip(new Tooltip("Set left audio channel to auto playback mode"));
AudioPlaybackChannelController left = mAudioPlaybackController.getChannelController(MixerChannel.LEFT);
mAutoModeLeftButton.disableProperty().bind(left.playbackModeProperty().isEqualTo(PlaybackMode.AUTO));
mAutoModeLeftButton.setOnAction(event -> {
Expand All @@ -324,6 +332,7 @@ private Button getAutoModeRightButton()
if(mAutoModeRightButton == null)
{
mAutoModeRightButton = new Button("Right");
mAutoModeRightButton.setTooltip(new Tooltip("Set right audio channel to auto playback mode"));
AudioPlaybackChannelController right = mAudioPlaybackController.getChannelController(MixerChannel.RIGHT);
mAutoModeRightButton.disableProperty().bind(right.playbackModeProperty().isEqualTo(PlaybackMode.AUTO));
mAutoModeRightButton.setOnAction(event -> {
Expand All @@ -339,6 +348,86 @@ private Button getAutoModeRightButton()
return mAutoModeRightButton;
}

/**
* Sets playback mode to auto - locked to the currently selected TO identifier to the left channel
*/
private Button getLockModeLeftButton()
{
if(mLockModeLeftButton == null)
{
mLockModeLeftButton = new Button("Left");
mLockModeLeftButton.setTooltip(new Tooltip("Lock the left audio channel for auto playback of selected call talkgroup"));
mLockModeLeftButton.setDisable(true);
mLockModeLeftButton.setOnAction(event -> {
final AudioPlaybackChannelController left = mAudioPlaybackController.getChannelController(MixerChannel.LEFT);
if(left != null)
{
final Call selected = getCallTableView().getSelectionModel().getSelectedItem();
getCallTableView().getSelectionModel().clearSelection();
getLockModeLeftButton().setDisable(true);

if(selected != null)
{
//If the right controller is locked for this same call, reset it to auto so that only 1 is locked
final AudioPlaybackChannelController right = mAudioPlaybackController.getChannelController(MixerChannel.RIGHT);
if(right.isLockedFor(selected))
{
right.auto();
}

left.autoLockedTo(selected.getToId(), selected.getSystem());
}
else
{
left.auto();
}
}
});
}

return mLockModeLeftButton;
}

/**
* Sets playback mode to auto - locked to the currently selected TO identifier to the left channel
*/
private Button getLockModeRightButton()
{
if(mLockModeRightButton == null)
{
mLockModeRightButton = new Button("Right");
mLockModeRightButton.setTooltip(new Tooltip("Lock the left audio channel for auto playback of selected call talkgroup"));
mLockModeRightButton.setDisable(true);
mLockModeRightButton.setOnAction(event -> {
final AudioPlaybackChannelController right = mAudioPlaybackController.getChannelController(MixerChannel.RIGHT);
if(right != null)
{
final Call selected = getCallTableView().getSelectionModel().getSelectedItem();
getCallTableView().getSelectionModel().clearSelection();
getLockModeRightButton().setDisable(true);

if(selected != null)
{
//If the left controller is locked for this same call, reset it to auto so that only 1 is locked
final AudioPlaybackChannelController left = mAudioPlaybackController.getChannelController(MixerChannel.RIGHT);
if(left.isLockedFor(selected))
{
left.auto();
}

right.autoLockedTo(selected.getToId(), selected.getSystem());
}
else
{
right.auto();
}
}
});
}

return mLockModeRightButton;
}

/**
* Audio playback control view.
*/
Expand Down Expand Up @@ -573,6 +662,11 @@ private TableView<Call> getCallTableView()
{
mAudioPlaybackController.replay(MixerChannel.LEFT, selectedCall);
}

AudioPlaybackChannelController left = mAudioPlaybackController.getChannelController(MixerChannel.LEFT);
AudioPlaybackChannelController right = mAudioPlaybackController.getChannelController(MixerChannel.RIGHT);
getLockModeLeftButton().setDisable(selectedCall == null || left.isLockedFor(selectedCall));
getLockModeRightButton().setDisable(selectedCall == null || right.isLockedFor(selectedCall));
});
getPlaceholderProgressIndicator().setVisible(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public class AudioPlaybackChannelController implements ChangeListener<MediaPlaye
private StringProperty mTo = new SimpleStringProperty();
private StringProperty mToAlias = new SimpleStringProperty();
private ObjectProperty<PlaybackMode> mPlaybackMode = new SimpleObjectProperty<>();
private StringProperty mLockedSystem = new SimpleStringProperty();
private StringProperty mLockedIdentifier = new SimpleStringProperty();
private StringProperty mMediaPlayerStatus = new SimpleStringProperty(EMPTY);
private Call mCall;
private double mBalance;
Expand Down Expand Up @@ -98,10 +96,10 @@ public boolean isLocked()
public boolean isLockedFor(Call call)
{
return playbackModeProperty().get().equals(PlaybackMode.LOCKED) &&
lockedIdentifierProperty().get() != null &&
(lockedIdentifierProperty().get().equals(call.getToId()) || lockedIdentifierProperty().get().equals(call.getFromId())) &&
((mLockedSystem.get() == null && call.getSystem() == null) ||
(lockedSystemProperty().get() != null && lockedSystemProperty().get().equals(call.getSystem())));
toProperty().get() != null &&
(toProperty().get().equals(call.getToId()) || toProperty().get().equals(call.getFromId())) &&
((systemProperty().get() == null && call.getSystem() == null) ||
(systemProperty().get() != null && systemProperty().get().equals(call.getSystem())));
}

/**
Expand Down Expand Up @@ -153,20 +151,18 @@ private void broadcastEndOfMedia()
}

/**
* Sets playback mode to AUTO if the identifier is null or LOCKED if the identifier is non-null.
* Sets playback mode to LOCKED for the identifier and system, or AUTO if the arguments are null.
* @param identifier optional identifier for LOCKED playback mode.
* @param system optional system name for LOCKED playback mode.
*/
public void auto(String identifier, String system)
public void autoLockedTo(String identifier, String system)
{
System.out.println("Setting " + nameProperty().get() + " to auto playback mode");
Platform.runLater(() -> {
//TODO: if the current call matches the identifier and system ... don't clear the media player, but do set the mode/lock
clearMediaPlayerAndCall();
//TODO: if we're now locked, leave the identifier and system name displayed in the call metadata
playbackModeProperty().set(identifier == null ? PlaybackMode.AUTO : PlaybackMode.LOCKED);
lockedIdentifierProperty().set(identifier);
lockedSystemProperty().set(system);
toProperty().set(identifier);
//Only set the system value if the identifier is non-null
systemProperty().set(identifier != null ? system : null);
});
}

Expand All @@ -175,7 +171,7 @@ public void auto(String identifier, String system)
*/
public void auto()
{
auto(null, null);
autoLockedTo(null, null);
}

/**
Expand All @@ -186,7 +182,6 @@ public void mute()
Platform.runLater(() -> {
clearMediaPlayerAndCall();
playbackModeProperty().set(PlaybackMode.MUTE);
mLockedIdentifier.set(null);
});
}

Expand Down Expand Up @@ -296,23 +291,33 @@ private void updateCallMetadata()
{
if(mCall != null)
{
updateProperty(toProperty(), mCall.getToId());
//Only change TO and SYSTEM when we're not in locked mode
if(!playbackModeProperty().get().equals(PlaybackMode.LOCKED))
{
updateProperty(toProperty(), mCall.getToId());
updateProperty(systemProperty(), mCall.getSystem());
}

updateProperty(toAliasProperty(), mCall.getToAlias());
updateProperty(fromProperty(), mCall.getFromId());
updateProperty(fromAliasProperty(), mCall.getFromAlias());
updateProperty(systemProperty(), mCall.getSystem());
updateProperty(siteProperty(), mCall.getSite());
updateProperty(frequencyProperty(), String.valueOf(mCall.getFrequency()));
updateProperty(siteProperty(), mCall.getSite());
}
else
{
updateProperty(toProperty(), null);
//Only change TO and SYSTEM when we're not in locked mode
if(!playbackModeProperty().get().equals(PlaybackMode.LOCKED))
{
updateProperty(toProperty(), null);
updateProperty(systemProperty(), null);
}

updateProperty(toAliasProperty(), null);
updateProperty(fromProperty(), null);
updateProperty(fromAliasProperty(), null);
updateProperty(systemProperty(), null);
updateProperty(siteProperty(), null);
updateProperty(frequencyProperty(), null);
updateProperty(siteProperty(), null);
}
}

Expand Down Expand Up @@ -401,23 +406,6 @@ public ObjectProperty<PlaybackMode> playbackModeProperty()
return mPlaybackMode;
}

/**
* Locked identifier property
*/
public StringProperty lockedIdentifierProperty()
{
return mLockedIdentifier;
}

/**
* Locked system property
* @return locked system.
*/
public StringProperty lockedSystemProperty()
{
return mLockedSystem;
}

/**
* Implements the change listener interface for MediaPlayer status changes.
*/
Expand Down
Loading

0 comments on commit 0647af8

Please sign in to comment.