"""Audio handling functions."""
import reapy
import reapy.reascript_api as RPR
[docs]def get_n_outputs():
"""
Return number of audio outputs.
Returns
-------
n_outputs : int
Number of audio outputs.
"""
n_outputs = RPR.GetNumAudioOutputs()
return n_outputs
[docs]def get_output_latency(unit="second"):
"""
Return output latency.
Parameters
----------
unit : {"sample", "second"}
Whether to return latency in samples or seconds
(default="second").
Returns
-------
latency : float
Output latency.
"""
latency, out_latency = RPR.GetInputOutputLatency(0, 0)
if unit == "second":
latency = RPR.GetOutputLatency()
else:
latency = RPR.GetInputOutputLatency(0, 0)[1]
return latency
[docs]@reapy.inside_reaper()
def get_output_names():
"""
Return names of all output channels.
Returns
-------
names : list of str
Names of output channels.
"""
n_channels = reapy.audio.get_n_outputs()
return tuple(map(RPR.GetOutputChannelName, range(n_channels)))
[docs]def init():
"""
Open all audio and MIDI devices (if not opened).
"""
RPR.Audio_Init()
[docs]def is_prebuffer():
"""
Return whether audio is in pre-buffer (threadsafe).
Returns
-------
is_prebuffer : bool
Whether audio is in pre-buffer.
"""
is_prebuffer = bool(RPR.Audio_IsPreBuffer())
return is_prebuffer
[docs]def is_running():
"""
Return whether audio is running (threadsafe).
Returns
-------
is_running : bool
Whether audio is running.
"""
is_running = bool(RPR.Audio_IsRunning())
return is_running
[docs]def quit():
"""
Close all audio and MIDI devices (if opened).
"""
RPR.Audio_Quit()