audio panel can be enabled in config; audio recording debug statements
This commit is contained in:
parent
74cb3c7b1e
commit
6f8985d3f4
|
@ -22,7 +22,10 @@ class Audio(Animation):
|
|||
if self.check_command_line("-mute"):
|
||||
self.get_configuration().set("audio", "volume", 0)
|
||||
self.register(self.play_sfx)
|
||||
self.audio_panel = AudioPanel(self)
|
||||
if self.get_configuration("audio", "panel-enabled"):
|
||||
self.audio_panel = AudioPanel(self)
|
||||
else:
|
||||
self.audio_panel = None
|
||||
self.subscribe(self.respond)
|
||||
self.sfx = {}
|
||||
self.load_sfx()
|
||||
|
@ -199,9 +202,13 @@ class Audio(Animation):
|
|||
return False
|
||||
return True
|
||||
|
||||
def is_audio_panel_active(self):
|
||||
return self.audio_panel and self.audio_panel.active
|
||||
|
||||
def update(self):
|
||||
Animation.update(self)
|
||||
self.audio_panel.update()
|
||||
if self.audio_panel:
|
||||
self.audio_panel.update()
|
||||
|
||||
|
||||
class BGM(GameChild):
|
||||
|
|
|
@ -105,8 +105,10 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "directory-name-format", "%Y%m%d%H%M%S", False)
|
||||
set_option(section, "file-extension", "png", False)
|
||||
set_option(section, "frame-format", "RGB", False)
|
||||
set_option(section, "framerate", "100", False)
|
||||
set_option(section, "framerate", "40", False)
|
||||
set_option(section, "temp-directory", "", False)
|
||||
set_option(section, "record-audio", "yes", False)
|
||||
set_option(section, "filename-digits", "6", False)
|
||||
section = "mouse"
|
||||
add_section(section)
|
||||
set_option(section, "visible", "yes", False)
|
||||
|
@ -152,6 +154,7 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "sfx-volume", "1.0", False)
|
||||
set_option(section, "bgm-volume", "1.0", False)
|
||||
set_option(section, "volume", "1.0", False)
|
||||
set_option(section, "panel-enabled", "no", False)
|
||||
set_option(section, "panel-font", None, False)
|
||||
section = "interpolator-gui"
|
||||
add_section(section)
|
||||
|
@ -416,9 +419,9 @@ class TypeDeclarations(dict):
|
|||
|
||||
"video-recordings": {"path": ["rel-path", "path"],
|
||||
|
||||
"int": "framerate",
|
||||
"int": ["framerate", "filename-digits"],
|
||||
|
||||
"bool": "enable"},
|
||||
"bool": ["enable", "record-audio"]},
|
||||
|
||||
"setup": {"list": ["classifiers", "resource-search-path",
|
||||
"requirements", "data-exclude",
|
||||
|
@ -452,7 +455,10 @@ class TypeDeclarations(dict):
|
|||
"bgm-repository-path", "bgm-project-path"
|
||||
],
|
||||
|
||||
"float": ["sfx-volume", "bgm-volume", "volume"]
|
||||
"float": ["sfx-volume", "bgm-volume", "volume"],
|
||||
|
||||
"bool": "panel-enabled"
|
||||
|
||||
},
|
||||
|
||||
"event": {"int": "command-id-offset"},
|
||||
|
|
|
@ -59,7 +59,7 @@ class Game(Animation):
|
|||
def frame(self):
|
||||
self.time_filter.update()
|
||||
self.delegate.dispatch()
|
||||
if not self.interpolator.is_gui_active() and not self.get_audio().audio_panel.active:
|
||||
if not self.interpolator.is_gui_active() and not self.get_audio().is_audio_panel_active():
|
||||
Animation.update(self)
|
||||
if self.confirming_quit:
|
||||
self.time_filter.close()
|
||||
|
|
|
@ -45,6 +45,10 @@ class VideoRecorder(GameChild):
|
|||
elif compare(event, "reset-game"):
|
||||
self.reset()
|
||||
|
||||
def is_audio_recording_enabled(self):
|
||||
return self.get_configuration("video-recordings", "record-audio") or\
|
||||
self.check_command_line("-enable-sound-recording")
|
||||
|
||||
def toggle_record(self):
|
||||
recording = not self.recording
|
||||
if recording:
|
||||
|
@ -53,7 +57,8 @@ class VideoRecorder(GameChild):
|
|||
if temp_dir == "":
|
||||
temp_dir = None
|
||||
self.frames = TemporaryFile(dir=temp_dir)
|
||||
if self.check_command_line("-enable-sound-recording"):
|
||||
print("writing video frames to {}".format(self.frames.name))
|
||||
if self.is_audio_recording_enabled():
|
||||
import pyaudio
|
||||
import wave
|
||||
self.audio_frames = []
|
||||
|
@ -61,9 +66,12 @@ class VideoRecorder(GameChild):
|
|||
def audio_callback(in_data, frame_count, time_info, status):
|
||||
self.audio_frames.append(in_data)
|
||||
return (in_data, pyaudio.paContinue)
|
||||
for ii in range(self.audio_recorder.get_device_count()):
|
||||
print("device {}: {}".format(ii, self.audio_recorder.get_device_info_by_index(ii)))
|
||||
self.audio_stream = self.audio_recorder.open(format=pyaudio.paInt32, channels=2, rate=44100,
|
||||
frames_per_buffer=1024,
|
||||
input=True, stream_callback=audio_callback)
|
||||
print("writing audio data to {}".format(self.audio_stream))
|
||||
else:
|
||||
self.write_frames()
|
||||
self.recording = recording
|
||||
|
@ -75,7 +83,7 @@ class VideoRecorder(GameChild):
|
|||
root = join(self.root, strftime(self.directory_name_format))
|
||||
if not exists(root):
|
||||
makedirs(root)
|
||||
if self.check_command_line("-enable-sound-recording"):
|
||||
if self.is_audio_recording_enabled():
|
||||
import pyaudio
|
||||
import wave
|
||||
self.audio_stream.stop_stream()
|
||||
|
@ -87,14 +95,16 @@ class VideoRecorder(GameChild):
|
|||
wf.setframerate(44100)
|
||||
wf.writeframes(b"".join(self.audio_frames))
|
||||
wf.close()
|
||||
print("saved audio in {}".format(root))
|
||||
size = self.display_surface.get_size()
|
||||
frames = self.frames
|
||||
frames.seek(0)
|
||||
for ii, frame in enumerate(
|
||||
iter(lambda: frames.read(self.frame_length), b'')):
|
||||
path = join(root, "%04i.png" % ii)
|
||||
path = join(root, "{:0{digits}}.png".format(
|
||||
ii, digits=self.get_configuration("video-recordings", "filename-digits")))
|
||||
save(frombuffer(frame, size, self.frame_format), path)
|
||||
print("wrote video frames to " + root)
|
||||
print("saved video frames in {}".format(root))
|
||||
|
||||
def update(self):
|
||||
ticks = get_ticks()
|
||||
|
|
Loading…
Reference in New Issue