mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
set default device type per platform
This commit is contained in:
@@ -198,7 +198,7 @@ class AudioEngine:
|
||||
"""Load a sound file and return sound ID"""
|
||||
try:
|
||||
if platform.system() == 'Windows':
|
||||
# Use Windows ANSI codepage (e.g., cp932 for Japanese, cp1252 for Western)
|
||||
# Use Windows ANSI codepage (cp932 for Japanese)
|
||||
file_path_str = str(file_path).encode('cp932', errors='replace')
|
||||
else:
|
||||
file_path_str = str(file_path).encode('utf-8')
|
||||
@@ -319,7 +319,7 @@ class AudioEngine:
|
||||
def load_music_stream(self, file_path: Path, name: str) -> str:
|
||||
"""Load a music stream and return music ID"""
|
||||
if platform.system() == 'Windows':
|
||||
# Use Windows ANSI codepage (e.g., cp932 for Japanese, cp1252 for Western)
|
||||
# Use Windows ANSI codepage (cp932 for Japanese)
|
||||
file_path_str = str(file_path).encode('cp932', errors='replace')
|
||||
else:
|
||||
file_path_str = str(file_path).encode('utf-8')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional, TypedDict
|
||||
from typing import Any, TypedDict
|
||||
|
||||
class GeneralConfig(TypedDict):
|
||||
fps_counter: bool
|
||||
@@ -56,7 +56,6 @@ class AudioConfig(TypedDict):
|
||||
device_type: int
|
||||
sample_rate: int
|
||||
buffer_size: int
|
||||
exclusive: bool
|
||||
|
||||
class VolumeConfig(TypedDict):
|
||||
sound: float
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
import logging
|
||||
import time
|
||||
import json
|
||||
import cffi
|
||||
from libs.global_data import Config, global_data
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
@@ -82,7 +83,29 @@ def get_config() -> Config:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
config_file = tomlkit.load(f)
|
||||
|
||||
return json.loads(json.dumps(config_file))
|
||||
config: Config = json.loads(json.dumps(config_file))
|
||||
if config["audio"]["device_type"] == -1:
|
||||
if sys.platform == "win32":
|
||||
ffi = cffi.FFI()
|
||||
ffi.cdef("""
|
||||
const char* get_host_api_name(PaHostApiIndex hostApi);
|
||||
""")
|
||||
lib = ffi.dlopen("libaudio.dll")
|
||||
for i in range(5):
|
||||
result = lib.get_host_api_name(i) # type: ignore
|
||||
result = ffi.string(result)
|
||||
if isinstance(result, bytes):
|
||||
result = result.decode('utf-8')
|
||||
if "WDM" in result:
|
||||
config["audio"]["device_type"] = i
|
||||
break
|
||||
else:
|
||||
config["audio"]["device_type"] = 0
|
||||
else:
|
||||
config["audio"]["device_type"] = 0
|
||||
save_config(config)
|
||||
|
||||
return config
|
||||
|
||||
def save_config(config: Config) -> None:
|
||||
"""Save the configuration to the TOML file"""
|
||||
|
||||
Reference in New Issue
Block a user