Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to toggle speaker on press #403

Merged
merged 3 commits into from
Jan 23, 2025
Merged

Add an option to toggle speaker on press #403

merged 3 commits into from
Jan 23, 2025

Conversation

neilenns
Copy link
Owner

@neilenns neilenns commented Jan 23, 2025

Fixes #402

Summary by CodeRabbit

Release Notes

  • New Features

    • Added options to toggle speaker on press and long press for station status.
    • Introduced new methods to control station audio settings, including mute and speaker toggles.
  • Improvements

    • Streamlined handling of short and long press actions for station status.
    • Enhanced flexibility in managing audio state changes.
  • User Interface

    • Added new checkbox settings for speaker toggle functionality in station status configuration.
  • Spell Checker

    • Added the word "spkr" to the recognized words list for improved spell checking.

@neilenns neilenns self-assigned this Jan 23, 2025
Copy link

coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@neilenns has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c54f881 and 5779ed8.

📒 Files selected for processing (2)
  • src/events/streamDeck/stationStatus/stationStatusLongPress.ts (1 hunks)
  • src/events/streamDeck/stationStatus/stationStatusShortPress.ts (1 hunks)

Walkthrough

This pull request introduces new functionality for managing station audio settings in a Stream Deck plugin. The changes add two new checkbox options for toggling speaker behavior on press and long press actions. The implementation includes updates to the HTML configuration, TypeScript interfaces, and controller methods to support these new toggle features. Additionally, a new word has been added to the spell checker configuration. The changes enhance user control over audio interactions by providing more granular options for managing station audio states.

Changes

File Change Summary
.vscode/settings.json Added "spkr" to cSpell.words array
com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html Added two new checkboxes:
- "Toggle speaker on press"
- "Toggle speaker on long press"
src/actions/stationStatus.ts Updated StationStatusSettings interface with new optional boolean properties:
- toggleSpeakerOnLongPress
- toggleSpeakerOnPress
src/controllers/stationStatus.ts Added new methods and getters:
- toggleMute()
- toggleSpeaker()
- toggleListenTo()
- Getters for toggleSpeakerOnLongPress and toggleSpeakerOnPress
src/events/streamDeck/stationStatus/stationStatusLongPress.ts Updated long press handling to use new toggle methods
- Added speaker toggle logic
- Renamed savedAction to foundAction
src/events/streamDeck/stationStatus/stationStatusShortPress.ts Refactored to use new controller methods for toggling states

Possibly related PRs

  • Add mute on long press option #396: The changes in this PR introduce a new checkbox for toggling mute on long press in the stationStatus.html file, which is directly related to the addition of the toggleMuteOnLongPress property in the StationStatusSettings interface in the main PR.

Suggested Labels

bug

Poem

🎛️ In the realm of audio's dance,
A rabbit's code takes a clever stance,
Toggle speaker, mute with glee,
Stream Deck magic, set audio free!
Hop-hop, press-press, control so bright! 🐰🎚️


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@neilenns neilenns added the enhancement Improvements to existing features label Jan 23, 2025
Copy link

Build for this pull request:
StreamDeck-TrackAudio.zip

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/events/streamDeck/stationStatus/stationStatusShortPress.ts (1)

35-35: Consider enhancing the comment clarity.

The comment could be more descriptive about the fallback behavior.

-  // If mute or speaker isn't set then toggle listenTo.
+  // Fallback: If neither mute nor speaker toggle is enabled, toggle the listenTo state.
src/controllers/stationStatus.ts (2)

548-601: Consider applying DRY principles to toggle methods.

The three toggle methods share similar message structure and could potentially be refactored to reduce code duplication.

Consider creating a helper method to handle the common message structure:

private sendToggleMessage(toggleType: 'mute' | 'speaker' | 'listenTo', value?: string) {
  const message = {
    type: "kSetStationState",
    value: {
      frequency: this.frequency,
      isOutputMuted: toggleType === 'mute' ? 'toggle' : undefined,
      headset: toggleType === 'speaker' ? 'toggle' : undefined,
      rx: toggleType === 'listenTo' && this.listenTo === 'rx' ? 'toggle' : undefined,
      tx: toggleType === 'listenTo' && this.listenTo === 'tx' ? 'toggle' : undefined,
      xc: toggleType === 'listenTo' && this.listenTo === 'xc' ? 'toggle' : undefined,
      xca: toggleType === 'listenTo' && this.listenTo === 'xca' ? 'toggle' : undefined,
    },
  };
  trackAudioManager.sendMessage(message);
}

This would allow simplifying the toggle methods:

public toggleMute() {
  this.sendToggleMessage('mute');
}

public toggleSpeaker() {
  this.sendToggleMessage('speaker');
}

public toggleListenTo() {
  this.sendToggleMessage('listenTo');
}

549-551: Maintain consistent documentation style.

The new methods use XML-style comments (///) while the rest of the codebase uses JSDoc style (/**). Consider maintaining consistency.

-  /// <summary>
-  /// Toggles the mute state of the station.
-  /// </summary>
+  /**
+   * Toggles the mute state of the station.
+   */

Also applies to: 567-569, 585-587

com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html (1)

57-70: Consider specifying default values for the new toggles.

Unlike some other checkboxes in the file (e.g., showTitle), these new toggles don't specify default values. Consider adding default="false" to maintain consistent behavior across all instances.

      <sdpi-checkbox
        setting="toggleSpeakerOnPress"
        label="Toggle speaker on press"
+       default="false"
      ></sdpi-checkbox>

      <sdpi-checkbox
        setting="toggleSpeakerOnLongPress"
        label="Toggle speaker on long press"
+       default="false"
      ></sdpi-checkbox>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 414d4f0 and 16e1fc2.

📒 Files selected for processing (6)
  • .vscode/settings.json (1 hunks)
  • com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html (1 hunks)
  • src/actions/stationStatus.ts (1 hunks)
  • src/controllers/stationStatus.ts (2 hunks)
  • src/events/streamDeck/stationStatus/stationStatusLongPress.ts (1 hunks)
  • src/events/streamDeck/stationStatus/stationStatusShortPress.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
🔇 Additional comments (6)
src/events/streamDeck/stationStatus/stationStatusShortPress.ts (1)

30-33: LGTM! Clean implementation of speaker toggle.

The speaker toggle implementation follows a clear order of operations with early returns to prevent multiple actions from executing.

src/events/streamDeck/stationStatus/stationStatusLongPress.ts (1)

26-29: LGTM! Consistent implementation with short press handler.

The long press implementation maintains consistency with the short press handler, following the same patterns and structure.

src/actions/stationStatus.ts (1)

107-108: LGTM! Well-structured interface additions.

The new settings properties follow existing naming conventions and are properly typed as optional booleans.

src/controllers/stationStatus.ts (1)

256-270: LGTM! Well-documented getter methods.

The new getter methods follow existing patterns and include proper JSDoc documentation.

com.neil-enns.trackaudio.sdPlugin/pi/stationStatus.html (2)

57-70: LGTM! The implementation follows existing patterns.

The new checkbox elements are well-structured and consistently implemented, following the same pattern as the existing mute toggles.


57-70: Verify interaction with auto speaker mode.

These new toggle options might interact with the existing "Automatically enable speaker mode" setting in advanced options. Please verify that these settings work together as intended and don't create conflicting behaviors.

✅ Verification successful

No conflicts found between auto speaker mode and toggle features

The implementation shows these features work independently and complement each other:

  • Auto speaker mode sets initial state on connection
  • Toggle features provide manual override capability regardless of initial state
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for speaker-related logic in the codebase
rg -l "autoSetSpk|toggleSpeaker" --type ts

Length of output: 254


Script:

#!/bin/bash
# Search for auto speaker mode implementation and toggle speaker logic
rg -A 10 "autoSetSpk|toggleSpeaker" --type ts

Length of output: 6776

Copy link

Build for this pull request:
StreamDeck-TrackAudio.zip

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/controllers/stationStatus.ts (1)

548-565: LGTM! Consider adding documentation about the speaker/headset relationship.

The toggleMute and toggleSpeaker methods are well-implemented, following a consistent pattern of explicitly setting undefined for unaffected states. However, it would be helpful to document why the speaker state is controlled via the "headset" property.

Add a comment explaining the relationship:

  /**
   * Toggles the speaker state of the station.
+  * @remarks The speaker state is controlled via the "headset" property in the TrackAudio protocol.
   */
  public toggleSpeaker() {

Also applies to: 567-583

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16e1fc2 and c54f881.

📒 Files selected for processing (1)
  • src/controllers/stationStatus.ts (2 hunks)
🔇 Additional comments (3)
src/controllers/stationStatus.ts (3)

256-270: LGTM! Well-implemented getter methods.

The new getter methods for speaker toggle settings follow the established patterns in the codebase, with proper TypeScript syntax, consistent naming, and appropriate default values.


585-601: LGTM! Well-implemented toggle logic.

The toggleListenTo method correctly handles the conditional toggling of different listen states based on the current listenTo value.


548-604: LGTM! Well-organized code structure.

The new methods are properly organized in a dedicated "Websocket messages" region and integrate well with the existing codebase, maintaining clean separation of concerns.

Copy link

Build for this pull request:
StreamDeck-TrackAudio.zip

@neilenns neilenns merged commit 5ff5297 into main Jan 23, 2025
3 checks passed
@neilenns neilenns deleted the neilenns/issue402 branch January 23, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to toggle speaker on press
1 participant