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

選択した再生デバイスがソングでも適用されるようにする #2375

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { EngineId } from "@/type/preload";
import ErrorBoundary from "@/components/ErrorBoundary.vue";
import { useStore } from "@/store";
import { applyDeviceId } from "@/store/singing";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
import AllDialog from "@/components/Dialog/AllDialog.vue";
import MenuBar from "@/components/Menu/MenuBar/MenuBar.vue";
Expand Down Expand Up @@ -97,6 +98,13 @@
setThemeToCss(theme);
});

// 再生デバイスの初期化と変更の監視
watchEffect(() => {
applyDeviceId(store.state.savingSetting.audioOutputDevice).catch((e) => {
console.error(e);

Check warning on line 104 in src/components/App.vue

View workflow job for this annotation

GitHub Actions / build_preview_pages

Unexpected console statement

Check warning on line 104 in src/components/App.vue

View workflow job for this annotation

GitHub Actions / build_preview_pages

Unexpected console statement

Check warning on line 104 in src/components/App.vue

View workflow job for this annotation

GitHub Actions / build-test

Unexpected console statement
});
});

// ソフトウェアを初期化
const { hotkeyManager } = useHotkeyManager();
const isEnginesReady = ref(false);
Expand Down
16 changes: 16 additions & 0 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import { uuid4 } from "@/helpers/random";
import { convertToWavFileData } from "@/sing/convertToWavFileData";
import { generateWriteErrorMessage } from "@/helpers/fileHelper";
import path from "@/helpers/path";
import { showAlertDialog } from "@/components/Dialog/Dialog";

const logger = createLogger("store/singing");

Expand Down Expand Up @@ -753,6 +754,21 @@ const getSelectedTrackWithFallback = (partialState: {
return getOrThrow(partialState.tracks, partialState._selectedTrackId);
};

// AudioContextに再生デバイスのIDを設定
export const applyDeviceId = async (device: string) => {
if (audioContext) {
const sinkId = device === "default" ? "" : device;
audioContext.setSinkId(sinkId).catch((err: unknown) => {
void showAlertDialog({
type: "error",
title: "エラー",
message: "再生デバイスが見つかりません",
});
throw err;
});
}
};
Comment on lines +757 to +770
Copy link
Contributor

@sigprogramming sigprogramming Nov 24, 2024

Choose a reason for hiding this comment

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

関数をexportする形になっていますが、actionにしても良いかもです。
actionにするとApp.vueからstore経由でアクセスできると思います。
App.vuesinging.tsへの依存を無くせると思います)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stateの操作は行わないのでvuexでやると不自然かな、という判断でした。ただ、この関数だけexportしてるのでどちらが馴染むかはなんとも分からないですね

Copy link
Contributor

@sigprogramming sigprogramming Nov 24, 2024

Choose a reason for hiding this comment

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

なるほどです!
確かにこの処理ではstateの操作は行われませんが、audioContextはアプリケーションの状態(グローバルな状態)に含まれるのと、関数にするとビューレイヤー(vueのコンポーネント)アプリケーションレイヤー(src/store以下の処理)の経路が関数とactionの2つになってしまうので、vuexのactionで行うのが良いかなと思います。


export const singingStoreState: SingingStoreState = {
tpqn: DEFAULT_TPQN,
tempos: [createDefaultTempo(0)],
Expand Down
4 changes: 4 additions & 0 deletions src/type/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ declare global {
setSinkId(deviceID: string): Promise<undefined>; // setSinkIdを認識してくれないため
}

interface AudioContext {
setSinkId: (sinkId: string) => Promise<void>;
}

interface Window {
readonly [SandboxKey]: import("./preload").Sandbox;
}
Expand Down
Loading