This commit is contained in:
Eric 2023-06-10 20:38:47 -07:00
parent 0bf2eeb0e3
commit b329d10c61
No known key found for this signature in database
GPG Key ID: 89C93F0F8D6D5A98
7 changed files with 50 additions and 56 deletions

View File

@ -12,6 +12,9 @@ from efro.util import set_canonical_module_names
import _babase import _babase
from _babase import ( from _babase import (
android_get_external_files_dir,
is_os_playing_music,
getsimplesound,
music_player_set_volume, music_player_set_volume,
music_player_play, music_player_play,
music_player_stop, music_player_stop,
@ -122,6 +125,7 @@ from babase._apputils import (
get_remote_app_name, get_remote_app_name,
) )
from babase._general import ( from babase._general import (
utf8_all,
DisplayTime, DisplayTime,
AppTime, AppTime,
WeakCall, WeakCall,
@ -267,6 +271,10 @@ __all__ = [
'mac_music_app_set_volume', 'mac_music_app_set_volume',
'mac_music_app_get_playlists', 'mac_music_app_get_playlists',
'mac_music_app_play_playlist', 'mac_music_app_play_playlist',
'utf8_all',
'getsimplesound',
'is_os_playing_music',
'android_get_external_files_dir',
] ]
# We want stuff to show up as babase.Foo instead of babase._sub.Foo. # We want stuff to show up as babase.Foo instead of babase._sub.Foo.

View File

@ -96,9 +96,7 @@ def stop_stress_test() -> None:
def start_stress_test(args: dict[str, Any]) -> None: def start_stress_test(args: dict[str, Any]) -> None:
"""(internal)""" """(internal)"""
from babase._general import Call from bascenev1 import DualTeamSession, FreeForAllSession
from bascenev1._dualteamsession import DualTeamSession
from bascenev1._freeforallsession import FreeForAllSession
assert babase.app.classic is not None assert babase.app.classic is not None
@ -121,9 +119,9 @@ def start_stress_test(args: dict[str, Any]) -> None:
appconfig['Team Tournament Playlist Randomize'] = 1 appconfig['Team Tournament Playlist Randomize'] = 1
babase.apptimer( babase.apptimer(
1.0, 1.0,
Call( babase.Call(
babase.pushcall, babase.pushcall,
Call(bascenev1.new_host_session, DualTeamSession), babase.Call(bascenev1.new_host_session, DualTeamSession),
), ),
) )
else: else:
@ -131,26 +129,24 @@ def start_stress_test(args: dict[str, Any]) -> None:
appconfig['Free-for-All Playlist Randomize'] = 1 appconfig['Free-for-All Playlist Randomize'] = 1
babase.apptimer( babase.apptimer(
1.0, 1.0,
Call( babase.Call(
babase.pushcall, babase.pushcall,
Call(bascenev1.new_host_session, FreeForAllSession), babase.Call(bascenev1.new_host_session, FreeForAllSession),
), ),
) )
babase.set_stress_testing(True, args['player_count']) babase.set_stress_testing(True, args['player_count'])
babase.app.classic.stress_test_reset_timer = babase.AppTimer( babase.app.classic.stress_test_reset_timer = babase.AppTimer(
args['round_duration'], Call(_reset_stress_test, args) args['round_duration'], babase.Call(_reset_stress_test, args)
) )
def _reset_stress_test(args: dict[str, Any]) -> None: def _reset_stress_test(args: dict[str, Any]) -> None:
from babase._general import Call
babase.set_stress_testing(False, args['player_count']) babase.set_stress_testing(False, args['player_count'])
babase.screenmessage('Resetting stress test...') babase.screenmessage('Resetting stress test...')
session = bascenev1.get_foreground_host_session() session = bascenev1.get_foreground_host_session()
assert session is not None assert session is not None
session.end() session.end()
babase.apptimer(1.0, Call(start_stress_test, args)) babase.apptimer(1.0, babase.Call(start_stress_test, args))
def run_gpu_benchmark() -> None: def run_gpu_benchmark() -> None:
@ -161,8 +157,6 @@ def run_gpu_benchmark() -> None:
def run_media_reload_benchmark() -> None: def run_media_reload_benchmark() -> None:
"""Kick off a benchmark to test media reloading speeds.""" """Kick off a benchmark to test media reloading speeds."""
from babase._general import Call
babase.reload_media() babase.reload_media()
babase.show_progress_bar() babase.show_progress_bar()
@ -182,8 +176,8 @@ def run_media_reload_benchmark() -> None:
color=(1, 1, 0), color=(1, 1, 0),
) )
babase.add_clean_frame_callback(Call(doit, start_time)) babase.add_clean_frame_callback(babase.Call(doit, start_time))
# The reload starts (should add a completion callback to the # The reload starts (should add a completion callback to the
# reload func to fix this). # reload func to fix this).
babase.apptimer(0.05, Call(delay_add, babase.apptime())) babase.apptimer(0.05, babase.Call(delay_add, babase.apptime()))

View File

@ -8,9 +8,9 @@ from typing import TYPE_CHECKING
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum from enum import Enum
import _babase import babase
import _bascenev1 import bascenev1
from bascenev1._music import MusicType from bascenev1 import MusicType
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Callable, Any from typing import Callable, Any
@ -116,7 +116,7 @@ class MusicSubsystem:
# music-player going since it may hitch (better while we're faded # music-player going since it may hitch (better while we're faded
# out than later). # out than later).
try: try:
cfg = _babase.app.config cfg = babase.app.config
if 'Soundtrack' in cfg and cfg['Soundtrack'] not in [ if 'Soundtrack' in cfg and cfg['Soundtrack'] not in [
'__default__', '__default__',
'Default Soundtrack', 'Default Soundtrack',
@ -166,7 +166,7 @@ class MusicSubsystem:
def supports_soundtrack_entry_type(self, entry_type: str) -> bool: def supports_soundtrack_entry_type(self, entry_type: str) -> bool:
"""Return whether provided soundtrack entry type is supported here.""" """Return whether provided soundtrack entry type is supported here."""
uas = _babase.env()['user_agent_string'] uas = babase.env()['user_agent_string']
assert isinstance(uas, str) assert isinstance(uas, str)
# FIXME: Generalize this. # FIXME: Generalize this.
@ -175,7 +175,7 @@ class MusicSubsystem:
if entry_type in ('musicFile', 'musicFolder'): if entry_type in ('musicFile', 'musicFolder'):
return ( return (
'android' in uas 'android' in uas
and _babase.android_get_external_files_dir() is not None and babase.android_get_external_files_dir() is not None
) )
if entry_type == 'default': if entry_type == 'default':
return True return True
@ -246,7 +246,7 @@ class MusicSubsystem:
def on_app_resume(self) -> None: def on_app_resume(self) -> None:
"""Should be run when the app resumes from a suspended state.""" """Should be run when the app resumes from a suspended state."""
if _babase.is_os_playing_music(): if babase.is_os_playing_music():
self.do_play_music(None) self.do_play_music(None)
def do_play_music( def do_play_music(
@ -272,7 +272,7 @@ class MusicSubsystem:
print(f"Invalid music type: '{musictype}'") print(f"Invalid music type: '{musictype}'")
musictype = None musictype = None
with _babase.ContextRef.empty(): with babase.ContextRef.empty():
# If they don't want to restart music and we're already # If they don't want to restart music and we're already
# playing what's requested, we're done. # playing what's requested, we're done.
if continuous and self.music_types[mode] is musictype: if continuous and self.music_types[mode] is musictype:
@ -281,7 +281,7 @@ class MusicSubsystem:
# If the OS tells us there's currently music playing, # If the OS tells us there's currently music playing,
# all our operations default to playing nothing. # all our operations default to playing nothing.
if _babase.is_os_playing_music(): if babase.is_os_playing_music():
musictype = None musictype = None
# If we're not in the mode this music is being set for, # If we're not in the mode this music is being set for,
@ -312,7 +312,7 @@ class MusicSubsystem:
def _get_user_soundtrack(self) -> dict[str, Any]: def _get_user_soundtrack(self) -> dict[str, Any]:
"""Return current user soundtrack or empty dict otherwise.""" """Return current user soundtrack or empty dict otherwise."""
cfg = _babase.app.config cfg = babase.app.config
soundtrack: dict[str, Any] = {} soundtrack: dict[str, Any] = {}
soundtrackname = cfg.get('Soundtrack') soundtrackname = cfg.get('Soundtrack')
if soundtrackname is not None and soundtrackname != '__default__': if soundtrackname is not None and soundtrackname != '__default__':
@ -329,7 +329,7 @@ class MusicSubsystem:
# self._music_node.delete() # self._music_node.delete()
# self._music_node = None # self._music_node = None
if self._playing_internal_music: if self._playing_internal_music:
_bascenev1.set_internal_music(None) bascenev1.set_internal_music(None)
self._playing_internal_music = False self._playing_internal_music = False
# Do the thing. # Do the thing.
@ -345,7 +345,7 @@ class MusicSubsystem:
# self._music_node.delete() # self._music_node.delete()
# self._music_node = None # self._music_node = None
if self._playing_internal_music: if self._playing_internal_music:
_bascenev1.set_internal_music(None) bascenev1.set_internal_music(None)
self._playing_internal_music = False self._playing_internal_music = False
# Start up new internal music. # Start up new internal music.
@ -365,8 +365,8 @@ class MusicSubsystem:
# 'loop': entry.loop, # 'loop': entry.loop,
# }, # },
# ) # )
_bascenev1.set_internal_music( bascenev1.set_internal_music(
_babase.getsimplesound(entry.assetname), babase.getsimplesound(entry.assetname),
volume=entry.volume * 5.0, volume=entry.volume * 5.0,
loop=entry.loop, loop=entry.loop,
) )
@ -408,7 +408,7 @@ class MusicPlayer:
def play(self, entry: Any) -> None: def play(self, entry: Any) -> None:
"""Play provided entry.""" """Play provided entry."""
if not self._have_set_initial_volume: if not self._have_set_initial_volume:
self._volume = _babase.app.config.resolve('Music Volume') self._volume = babase.app.config.resolve('Music Volume')
self.on_set_volume(self._volume) self.on_set_volume(self._volume)
self._have_set_initial_volume = True self._have_set_initial_volume = True
self._entry_to_play = copy.deepcopy(entry) self._entry_to_play = copy.deepcopy(entry)
@ -470,5 +470,5 @@ class MusicPlayer:
def do_play_music(*args: Any, **keywds: Any) -> None: def do_play_music(*args: Any, **keywds: Any) -> None:
"""A passthrough used by the C++ layer.""" """A passthrough used by the C++ layer."""
assert _babase.app.classic is not None assert babase.app.classic is not None
_babase.app.classic.music.do_play_music(*args, **keywds) babase.app.classic.music.do_play_music(*args, **keywds)

View File

@ -75,7 +75,6 @@ class MasterServerV1CallThread(threading.Thread):
import json import json
from efro.error import is_urllib_communication_error from efro.error import is_urllib_communication_error
from babase._general import Call, utf8_all
plus = babase.app.plus plus = babase.app.plus
assert plus is not None assert plus is not None
@ -83,7 +82,7 @@ class MasterServerV1CallThread(threading.Thread):
url: str | None = None url: str | None = None
try: try:
assert babase.app.classic is not None assert babase.app.classic is not None
self._data = utf8_all(self._data) self._data = babase.utf8_all(self._data)
babase.set_thread_name('BA_ServerCallThread') babase.set_thread_name('BA_ServerCallThread')
if self._request_type == 'get': if self._request_type == 'get':
url = ( url = (
@ -149,5 +148,6 @@ class MasterServerV1CallThread(threading.Thread):
if self._callback is not None: if self._callback is not None:
babase.pushcall( babase.pushcall(
Call(self._run_callback, response_data), from_other_thread=True babase.Call(self._run_callback, response_data),
from_other_thread=True,
) )

View File

@ -3,6 +3,7 @@
"""Music playback functionality using the Mac Music (formerly iTunes) app.""" """Music playback functionality using the Mac Music (formerly iTunes) app."""
from __future__ import annotations from __future__ import annotations
import logging
import threading import threading
from collections import deque from collections import deque
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
@ -78,9 +79,6 @@ class _MacMusicAppThread(threading.Thread):
def run(self) -> None: def run(self) -> None:
"""Run the Music.app thread.""" """Run the Music.app thread."""
from babase._general import Call
from babase._language import Lstr
babase.set_thread_name('BA_MacMusicAppThread') babase.set_thread_name('BA_MacMusicAppThread')
babase.mac_music_app_init() babase.mac_music_app_init()
@ -90,9 +88,9 @@ class _MacMusicAppThread(threading.Thread):
def do_print() -> None: def do_print() -> None:
babase.apptimer( babase.apptimer(
1.0, 1.0,
Call( babase.Call(
babase.screenmessage, babase.screenmessage,
Lstr(resource='usingItunesText'), babase.Lstr(resource='usingItunesText'),
(0, 1, 0), (0, 1, 0),
), ),
) )
@ -169,8 +167,6 @@ class _MacMusicAppThread(threading.Thread):
def _handle_get_playlists_command( def _handle_get_playlists_command(
self, target: Callable[[list[str]], None] self, target: Callable[[list[str]], None]
) -> None: ) -> None:
from babase._general import Call
try: try:
playlists = babase.mac_music_app_get_playlists() playlists = babase.mac_music_app_get_playlists()
playlists = [ playlists = [
@ -196,7 +192,7 @@ class _MacMusicAppThread(threading.Thread):
except Exception as exc: except Exception as exc:
print('Error getting iTunes playlists:', exc) print('Error getting iTunes playlists:', exc)
playlists = [] playlists = []
babase.pushcall(Call(target, playlists), from_other_thread=True) babase.pushcall(babase.Call(target, playlists), from_other_thread=True)
def _handle_play_command(self, target: str | None) -> None: def _handle_play_command(self, target: str | None) -> None:
if target is None: if target is None:
@ -239,14 +235,12 @@ class _MacMusicAppThread(threading.Thread):
def _play_current_playlist(self) -> None: def _play_current_playlist(self) -> None:
try: try:
from babase._general import Call
assert self._current_playlist is not None assert self._current_playlist is not None
if babase.mac_music_app_play_playlist(self._current_playlist): if babase.mac_music_app_play_playlist(self._current_playlist):
pass pass
else: else:
babase.pushcall( babase.pushcall(
Call( babase.Call(
babase.screenmessage, babase.screenmessage,
babase.app.lang.get_resource('playlistNotFoundText') babase.app.lang.get_resource('playlistNotFoundText')
+ ': \'' + ': \''
@ -257,10 +251,8 @@ class _MacMusicAppThread(threading.Thread):
from_other_thread=True, from_other_thread=True,
) )
except Exception: except Exception:
from babase import _error logging.exception(
"Error playing playlist '%s'.", self._current_playlist
_error.print_exception(
f'error playing playlist {self._current_playlist}'
) )
def _update_mac_music_app_volume(self) -> None: def _update_mac_music_app_volume(self) -> None:

View File

@ -121,9 +121,6 @@ class _PickFolderSongThread(threading.Thread):
self._path = path self._path = path
def run(self) -> None: def run(self) -> None:
from babase import _language
from babase._general import Call
do_log_error = True do_log_error = True
try: try:
babase.set_thread_name('BA_PickFolderSongThread') babase.set_thread_name('BA_PickFolderSongThread')
@ -141,12 +138,13 @@ class _PickFolderSongThread(threading.Thread):
if not all_files: if not all_files:
do_log_error = False do_log_error = False
raise RuntimeError( raise RuntimeError(
_language.Lstr( babase.Lstr(
resource='internal.noMusicFilesInFolderText' resource='internal.noMusicFilesInFolderText'
).evaluate() ).evaluate()
) )
babase.pushcall( babase.pushcall(
Call(self._callback, all_files, None), from_other_thread=True babase.Call(self._callback, all_files, None),
from_other_thread=True,
) )
except Exception as exc: except Exception as exc:
if do_log_error: if do_log_error:
@ -156,6 +154,6 @@ class _PickFolderSongThread(threading.Thread):
except Exception: except Exception:
err_str = '<ENCERR4523>' err_str = '<ENCERR4523>'
babase.pushcall( babase.pushcall(
Call(self._callback, self._path, err_str), babase.Call(self._callback, self._path, err_str),
from_other_thread=True, from_other_thread=True,
) )

View File

@ -62,6 +62,7 @@ from babase._mgen.enums import (
) )
from _bascenev1 import ( from _bascenev1 import (
set_internal_music,
set_master_server_source, set_master_server_source,
get_foreground_host_session, get_foreground_host_session,
get_foreground_host_activity, get_foreground_host_activity,
@ -216,6 +217,7 @@ from bascenev1._dependency import (
from bascenev1._gameutils import get_trophy_string from bascenev1._gameutils import get_trophy_string
__all__ = [ __all__ = [
'set_internal_music',
'get_trophy_string', 'get_trophy_string',
'app', 'app',
'get_local_active_input_devices_count', 'get_local_active_input_devices_count',