Skip to content

Commit

Permalink
Merge pull request #340 from neilenns/neilenns/issue331
Browse files Browse the repository at this point in the history
Add main volume action
  • Loading branch information
neilenns authored Jan 8, 2025
2 parents d629b10 + 4271be4 commit e1a3192
Show file tree
Hide file tree
Showing 24 changed files with 582 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"[svg]": {
"editor.formatOnSave": false
},
"svg.preview.background": "editor"
"svg.preview.background": "editor",
"cSpell.words": ["elgato", "streamdeck"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion com.neil-enns.trackaudio.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
"Version": "0.1.0.0",
"Author": "Neil Enns",
"Actions": [
{
"Name": "Main volume",
"UUID": "com.neil-enns.trackaudio.mainvolume",
"Icon": "images/plugin/volume",
"PropertyInspectorPath": "pi/mainVolume.html",
"Tooltip": "Controls the main volume for TrackAudio.",
"Controllers": ["Encoder"],
"Encoder": {
"layout": "$B1",
"TriggerDescription": {
"Push": "Toggle mute",
"Rotate": "Adjust volume"
}
},
"DisableAutomaticStates": true,
"States": [
{
"Image": "images/actions/default",
"TitleAlignment": "middle"
}
]
},
{
"Name": "Station volume",
"UUID": "com.neil-enns.trackaudio.stationvolume",
"Icon": "images/plugin/volume",
"PropertyInspectorPath": "pi/stationVolume.html",
"Tooltip": "Controlls the volume for the specified station.",
"Tooltip": "Controls the volume for the specified station.",
"Controllers": ["Encoder"],
"Encoder": {
"layout": "$B1",
"TriggerDescription": {
"Push": "Toggle mute",
"Touch": "Toggle mute",
"Rotate": "Adjust volume"
}
},
Expand Down
33 changes: 33 additions & 0 deletions com.neil-enns.trackaudio.sdPlugin/pi/mainVolume.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/gh/geekyeggo/sdpi-components@v2/dist/sdpi-components.js"></script>
</head>
<body>
<sdpi-item label="Change amount">
<sdpi-range
setting="changeAmount"
min="1"
max="10"
default="1"
showlabels
required
></sdpi-range>
</sdpi-item>

<sdpi-item label="Connected">
<sdpi-file
setting="connectedImagePath"
accept="image/png, image/jpeg, image/svg+xml"
></sdpi-file>
</sdpi-item>

<sdpi-item label="Not connected">
<sdpi-file
setting="notConnectedImagePath"
accept="image/png, image/jpeg, image/svg+xml"
></sdpi-file>
</sdpi-item>
</body>
</html>
8 changes: 0 additions & 8 deletions com.neil-enns.trackaudio.sdPlugin/pi/stationVolume.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
<script src="https://cdn.jsdelivr.net/gh/geekyeggo/sdpi-components@v2/dist/sdpi-components.js"></script>
</head>
<body>
<sdpi-item label="Title">
<sdpi-textarea
setting="title"
placeholder="Optional title"
rows="1"
></sdpi-textarea>
</sdpi-item>

<sdpi-item label="Callsign">
<sdpi-textfield
setting="callsign"
Expand Down
71 changes: 71 additions & 0 deletions src/actions/mainVolume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
action,
DialAction,
DialRotateEvent,
DidReceiveSettingsEvent,
JsonValue,
SingletonAction,
WillAppearEvent,
WillDisappearEvent,
} from "@elgato/streamdeck";
import { handleAddMainVolume } from "@events/streamDeck/mainVolume/addMainVolume";
import { handleRemove } from "@events/streamDeck/remove";
import { handleMainVolumeDialRotate } from "@events/streamDeck/mainVolume/mainVolumeDialRotate";
import debounce from "debounce";
import { handleUpdateMainVolumeSettings } from "@events/streamDeck/mainVolume/updateMainVolumeSettings";

@action({ UUID: "com.neil-enns.trackaudio.mainvolume" })
/**
* Represents the volume of a TrackAudio station
*/
export class MainVolume extends SingletonAction<MainVolumeSettings> {
debouncedUpdate = debounce(
(action: DialAction, settings: MainVolumeSettings) => {
handleUpdateMainVolumeSettings(action, settings);
},
300
);

override onWillAppear(
ev: WillAppearEvent<MainVolumeSettings>
): Promise<void> | void {
// This should never happen. Typeguard to ensure the rest of the code can just use
// DialAction.
if (!ev.action.isDial()) {
return;
}

handleAddMainVolume(ev.action, ev.payload.settings);
}

override onDialRotate(
ev: DialRotateEvent<MainVolumeSettings>
): Promise<void> | void {
handleMainVolumeDialRotate(ev.action, ev.payload.ticks);
}

override onDidReceiveSettings(
ev: DidReceiveSettingsEvent<MainVolumeSettings>
): Promise<void> | void {
// This should never happen. Typeguard to ensure the rest of the code can just use
// DialAction.
if (!ev.action.isDial()) {
return;
}

this.debouncedUpdate(ev.action, ev.payload.settings);
}

override onWillDisappear(
ev: WillDisappearEvent<MainVolumeSettings>
): Promise<void> | void {
handleRemove(ev.action);
}
}

export interface MainVolumeSettings {
changeAmount?: number;
connectedImagePath?: string;
notConnectedImagePath?: string;
[key: string]: JsonValue;
}
28 changes: 23 additions & 5 deletions src/actions/stationVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
DidReceiveSettingsEvent,
JsonValue,
SingletonAction,
TouchTapEvent,
WillAppearEvent,
WillDisappearEvent,
} from "@elgato/streamdeck";
import { handleStationVolumeDialRotate } from "@events/streamDeck/stationVolume/stationVolumeDialRotate";
import { handleRemove } from "@events/streamDeck/remove";
import { handleAddStationVolume } from "@events/streamDeck/stationVolume/addStationVolume";
import { handleDialPress } from "@events/streamDeck/stationVolume/dialPress";
import { handleDialRotate } from "@events/streamDeck/stationVolume/dialRotate";
import { handleStationVolumeDialPress } from "@events/streamDeck/stationVolume/stationVolumeDialPress";
import { handleUpdateStationVolumeSettings } from "@events/streamDeck/stationVolume/updateStationVolumeSettings";
import debounce from "debounce";

Expand Down Expand Up @@ -43,7 +44,7 @@ export class StationVolume extends SingletonAction<StationVolumeSettings> {
override onDialRotate(
ev: DialRotateEvent<StationVolumeSettings>
): Promise<void> | void {
handleDialRotate(ev.action, ev.payload.ticks);
handleStationVolumeDialRotate(ev.action, ev.payload.ticks);
}

override onDidReceiveSettings(
Expand All @@ -61,7 +62,25 @@ export class StationVolume extends SingletonAction<StationVolumeSettings> {
override onDialDown(
ev: DialDownEvent<StationVolumeSettings>
): Promise<void> | void {
handleDialPress(ev.action);
// This should never happen. Typeguard to ensure the rest of the code can just use
// DialAction.
if (!ev.action.isDial()) {
return;
}

handleStationVolumeDialPress(ev.action);
}

override onTouchTap(
ev: TouchTapEvent<StationVolumeSettings>
): Promise<void> | void {
// This should never happen. Typeguard to ensure the rest of the code can just use
// DialAction.
if (!ev.action.isDial()) {
return;
}

handleStationVolumeDialPress(ev.action);
}

override onWillDisappear(
Expand All @@ -77,6 +96,5 @@ export interface StationVolumeSettings {
changeAmount?: number;
mutedImagePath?: string;
notMutedImagePath?: string;
title?: string;
[key: string]: JsonValue;
}
Loading

0 comments on commit e1a3192

Please sign in to comment.