reapy.core.reaper package¶
Submodules¶
reapy.core.reaper.audio module¶
Audio handling functions.
-
reapy.core.reaper.audio.
get_input_latency
(unit='second')[source]¶ Return input latency.
Parameters: unit ({"sample", "second"}) – Whether to return latency in samples or seconds (default=”second”). Returns: latency – Input latency. Return type: float
-
reapy.core.reaper.audio.
get_input_names
()[source]¶ Return names of all input channels.
Returns: names – Names of input channels. Return type: list of str
-
reapy.core.reaper.audio.
get_n_inputs
()[source]¶ Return number of audio inputs.
Returns: n_inputs – Number of audio inputs. Return type: int
-
reapy.core.reaper.audio.
get_n_outputs
()[source]¶ Return number of audio outputs.
Returns: n_outputs – Number of audio outputs. Return type: int
-
reapy.core.reaper.audio.
get_output_latency
(unit='second')[source]¶ Return output latency.
Parameters: unit ({"sample", "second"}) – Whether to return latency in samples or seconds (default=”second”). Returns: latency – Output latency. Return type: float
-
reapy.core.reaper.audio.
get_output_names
()[source]¶ Return names of all output channels.
Returns: names – Names of output channels. Return type: list of str
-
reapy.core.reaper.audio.
is_prebuffer
()[source]¶ Return whether audio is in pre-buffer (threadsafe).
Returns: is_prebuffer – Whether audio is in pre-buffer. Return type: bool
reapy.core.reaper.defer module¶
Define reapy.defer and reapy.at_exit.
-
class
reapy.core.reaper.defer.
Deferrer
[source]¶ Bases:
object
Class to register and run deferred calls.
-
class
reapy.core.reaper.defer.
ReaperConsole
[source]¶ Bases:
object
File-like wrapper around the Reaper Console.
-
reapy.core.reaper.defer.
at_exit
(f, *args, **kwargs)[source]¶ Make REAPER call a function after script execution.
The function is also called if excution is terminated by user.
Parameters: - f (callable) – Function to be called later.
- args (tuple, optional) – Positional arguments to pass to
f
. - kwargs (dict, optional) – Keyword arguments to pass to
f
.
Raises: AssertionError
– When called from outside REAPER.Examples
Typical use case of
at_exit
is cleaning up after adefer
loop.The following example opens a file and starts a loop that indefinitely writes integers to that file. Since we want the file to be closed when the user terminates script execution, call to its
close
method is deferred toreapy.at_exit
.>>> import reapy >>> file = open("somefile.txt", "w") >>> def stupid_loop(i): ... file.write(i) ... reapy.defer(stupid_loop, i + 1) ... >>> reapy.at_exit(file.close) >>> stupid_loop(0)
-
reapy.core.reaper.defer.
defer
(f, *args, **kwargs)[source]¶ Make REAPER call a function later.
Parameters: - f (callable) – Function to be called later.
- args (tuple, optional) – Positional arguments to pass to
f
. - kwargs (dict, optional) – Keyword arguments to pass to
f
.
Raises: AssertionError
– When called from outside REAPER.Notes
The average time before a defered call is actually run is about 0.03 seconds (around 30 defered calls are allowed per second).
Examples
Typical use case of
defer
is running loops that don’t block REAPER GUI.The following example creates a loop that indefinitely prints integers to the REAPER console, without blocking REAPER GUI.
>>> import reapy >>> def stupid_loop(i): ... reapy.print(i) ... reapy.defer(stupid_loop, i + 1) ... >>> stupid_loop(0)
reapy.core.reaper.midi module¶
-
reapy.core.reaper.midi.
get_active_editor
()[source]¶ Return active MIDI editor, or None if no editor is active.
Returns: editor – Active MIDI editor, or None if no editor is active. Return type: MIDIEditor or None
-
reapy.core.reaper.midi.
get_input_names
()[source]¶ Return names of all input channels.
Returns: names – Names of input channels. Return type: list of str
-
reapy.core.reaper.midi.
get_max_inputs
()[source]¶ Return maximum number of MIDI inputs.
Returns: max_inputs – Maximum number of MIDI inputs. Return type: int
-
reapy.core.reaper.midi.
get_max_outputs
()[source]¶ Return maximum number of MIDI outputs.
Returns: max_outputs – Maximum number of MIDI outputs. Return type: int
-
reapy.core.reaper.midi.
get_n_inputs
()[source]¶ Return number of MIDI inputs.
Returns: n_inputs – Number of MIDI inputs. Return type: int
-
reapy.core.reaper.midi.
get_n_outputs
()[source]¶ Return number of MIDI outputs.
Returns: n_outputs – Number of MIDI outputs. Return type: int
reapy.core.reaper.reaper module¶
-
reapy.core.reaper.reaper.
add_project_tab
(make_current_project=True)[source]¶ Open new project tab and return it.
Parameters: make_current_project (bool) – Whether to select new project as current project (default=`True`). Returns: project – New project. Return type: Project
-
reapy.core.reaper.reaper.
add_reascript
(path, section_id=0, commit=True)[source]¶ Add a ReaScript and return the new action ID.
Parameters: - path (str) – Path to script.
- section_id (int, optional (default=0, corresponds to main section)) – Action section ID to which the script must be added.
- commit (bool, optional) – Whether to commit change. Use it when adding a single script. You can optimize bulk adding n scripts by setting commit=False for the first n-1 calls and commit=True for the last call.
Returns: action_id – New ReaScript action ID.
Return type: int
-
reapy.core.reaper.reaper.
arm_command
(command_id, section='')[source]¶ Arm or disarm command.
Parameters: - command_id (int) – Command ID. If 0, disarm command.
- section (str, optional) – Command section. Empty string for main section. Default=””.
-
reapy.core.reaper.reaper.
browse_for_file
(window_title='', extension='')[source]¶ Ask the user to select a file.
Parameters: - window_title (str, optional) – Window title (default=””)
- extension (str, optional) – Extension for file (e.g. “mp3”, “txt”…) (default=all types).
Returns: path – Path to file, or None if user cancelled.
Return type: str or NoneType
-
reapy.core.reaper.reaper.
clear_console
()[source]¶ Clear Reaper console.
See also
ReaProject.show_console_message()
-
reapy.core.reaper.reaper.
dB_to_slider
(db)[source]¶ Convert decibel value to slider.
Parameters: db (float) – Decibel value. Returns: slider – Slider value. Return type: float See also
-
reapy.core.reaper.reaper.
delete_ext_state
(section, key, persist=False)[source]¶ Delete extended state value for a given section and key.
Parameters: - section (str) – Extended state section.
- key (str) – Extended state key.
- persist (bool) – Whether extended state should remain deleted next time REAPER is opened.
-
reapy.core.reaper.reaper.
get_command_id
(command_name)[source]¶ Return ID of command with a given name.
Parameters: command_name (str) – Command name. Returns: command_id – Command ID, or None if name can’t be found. Return type: int or None
-
reapy.core.reaper.reaper.
get_command_name
(command_id)[source]¶ Return name of command with a given ID.
Parameters: command_id (int) – Command ID. Returns: command_name – Command name, or None for a native command. Return type: str, None
-
reapy.core.reaper.reaper.
get_exe_dir
()[source]¶ Return REAPER.exe directory (e.g. “C:Program FilesREAPER”).
Returns: path – Path to REAPER.exe directory. Return type: str
-
reapy.core.reaper.reaper.
get_ext_state
(section, key)[source]¶ Get the extended state value for a specific section and key.
Parameters: - section (str) – Extended state section.
- key (str) – Extended state key for section section.
Returns: value – Extended state value.
Return type: str
See also
-
reapy.core.reaper.reaper.
get_global_automation_mode
()[source]¶ Return global automation override mode.
Returns: override_mode – - One of the following values:
- ”bypass” “latch” “none” “read” “touch” “trim/read” “write”
Return type: str
-
reapy.core.reaper.reaper.
get_ini_file
()[source]¶ Return path to REAPER.ini file.
Returns: path – Path to REAPER.ini file. Return type: str
-
reapy.core.reaper.reaper.
get_last_touched_track
()[source]¶ Return last touched track, or None if no track has been touched.
Returns: track Return type: Track or None if no track has been touched.
-
reapy.core.reaper.reaper.
get_main_window
()[source]¶ Return main window.
Returns: window – Main window. Return type: Window
-
reapy.core.reaper.reaper.
get_projects
()[source]¶ Return list of all opened projects.
Returns: projects – List of all projects. Return type: list of Project
-
reapy.core.reaper.reaper.
get_resource_path
()[source]¶ Return path to directory where .ini files are stored.
Returns: path – Path to directory where .ini files are stored. Return type: str
-
reapy.core.reaper.reaper.
get_user_inputs
(title, captions, retvals_size=1024)[source]¶ Show text inputs to user and get values from them.
Parameters: - title (str) – Popup title.
- captions (List[str]) – Names of input fields.
- retvals_size (int, optional) – Maximum number of characters that will be retrieved for each field. User may enter more, but only the first retvals_size will be returned. (default=1024)
Returns: Dictionary of pairs {caption: response}.
Return type: Dict[str,str]
Raises: RuntimeError
– When user clicked the Cancel button.
-
reapy.core.reaper.reaper.
has_ext_state
(section, key)[source]¶ Return whether extended state exists for given section and key.
Parameters: - section (str) – Extended state section.
- key (str) – Extended state key.
Returns: has_ext_state
Return type: bool
-
reapy.core.reaper.reaper.
open_project
(filepath, in_new_tab=False, make_current_project=True)[source]¶ Open project and return it.
Parameters: - filepath (str) –
- in_new_tab (bool, optional) – Whether to open project in new tab (default=`False`).
- make_current_project (bool, optional) – Whether to make opened project current project (has no effect if in_new_tab is False).
Returns: project – Opened project.
Return type:
-
reapy.core.reaper.reaper.
perform_action
(action_id)[source]¶ Perform action with ID action_id in the main Actions section.
Parameters: action_id (int) – Action ID in the main Actions section.
-
class
reapy.core.reaper.reaper.
prevent_ui_refresh
[source]¶ Bases:
contextlib.ContextDecorator
Class to prevent UI refresh on certain pieces of code.
Its instance can be used both as decorator and as context manager:
>>> with reapy.prevent_ui_refresh(): ... reapy.Project.add_track()
>>> @prevent_ui_refresh() >>> def some_function(*args, **kwargs): ... reapy.Project.add_track()
-
class
reapy.core.reaper.reaper.
reaprint
[source]¶ Bases:
contextlib.ContextDecorator
Class to send all prints to ReaperConsole.
Its instance can be used both as decorator and context manager:
>>> with reapy.reaprint(): ... print('This will go to the console!') ... print('All these contexted will go to the console!')
>>> @reapy.reaprint() >>> def some_function(*args, **kwargs): ... print('This will go to the console!') ... print('All these decorated prints will go to the console!')
-
reapy.core.reaper.reaper.
remove_reascript
(path, section_id=0, commit=True)[source]¶ Remove a ReaScript.
Parameters: - path (str) – Path to script.
- section_id (int, optional (default=0, corresponds to main section)) – Action section ID to which the script must be added.
- commit (bool, optional) – Whether to commit change. Use it when removing a single script. You can optimize bulk removing n scripts by setting commit=False for the first n-1 calls and commit=True for the last call.
-
reapy.core.reaper.reaper.
rgb_from_native
(native_color)[source]¶ Extract RGB values from a native (OS-dependent) color.
Parameters: native_color (int) – Native color. Returns: r, g, b – RGB values between 0 and 255. Return type: (int, int, int)
-
reapy.core.reaper.reaper.
rgb_to_native
(rgb)[source]¶ Make a native (OS-dependent) color from RGB values.
Parameters: rgb ((int, int, int)) – RGB triplet of integers between 0 and 255. Returns: native_color – Native color. Return type: int
-
reapy.core.reaper.reaper.
set_ext_state
(section, key, value, persist=False)[source]¶ Set the extended state value for a specific section and key.
Parameters: - section (str) – Extended state section.
- key (str) – Extended state key for section section.
- value (str) – Extended state value for section section and key key.
- persist (bool) – Whether the value should be stored and reloaded the next time REAPER is opened.
See also
-
reapy.core.reaper.reaper.
set_global_automation_mode
(mode)[source]¶ Set global automation mode.
Parameters: mode (str) – - One of the following values:
- ”bypass” “latch” “none” “read” “touch” “trim/read” “write”
-
reapy.core.reaper.reaper.
show_console_message
(*args, sep=' ', end='\n')[source]¶ Print a message to the Reaper console.
- args : tuple
- Values to print.
- sep : str, optional
- String inserted between values (default=” “).
- end : str, optional
- String appended after the last value (default=”
“).
-
reapy.core.reaper.reaper.
show_message_box
(text='', title='', type='ok')[source]¶ Show message box.
Parameters: - text (str) – Box message
- title (str) – Box title
- type (str) –
One of the following values.
”ok” “ok-cancel” “abort-retry-ignore” “yes-no-cancel” “yes-no” “retry-cancel”
Returns: status – One of the following values.
”ok” “cancel” “abort” “retry” “ignore” “yes” “no”
Return type: str
-
reapy.core.reaper.reaper.
slider_to_dB
(slider)[source]¶ Convert slider value to decibel.
Parameters: slider (float) – Slider value. Returns: db – Decibel value. Return type: float See also
-
reapy.core.reaper.reaper.
test_api
()[source]¶ Display a message window if the API can successfully be called.
-
class
reapy.core.reaper.reaper.
undo_block
(undo_name, flags=0)[source]¶ Bases:
contextlib.ContextDecorator
Class to register undo block.
Its instance can be used both as decorator and context manager:
>>> with reapy.undo_block('add track'): ... reapy.Project.add_track()
>>> @reapy.undo_block('add track') >>> def some_function(*args, **kwargs): ... reapy.Project.add_track()
Parameters: - undo_name – Str to register undo name (shown later in Undo menu)
- flags – Int to pass to Undo_EndBlock (leave default if you don’t know what it is)
reapy.core.reaper.ui module¶
User interface-related functions.
-
reapy.core.reaper.ui.
get_color_theme
()[source]¶ Return path to last color theme file.
Returns: color_theme – Path to last color theme file. Return type: str