analyze_loudness
Render a REAPER project to a temporary file and measure integrated loudness in LUFS and true peak in dBTP per the ITU-R BS.1770 standard for loudness analysis.
Instructions
Render the project to a temp file and measure integrated loudness (LUFS) and true peak (dBTP) using the ITU-R BS.1770 standard.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main handler function for the 'analyze_loudness' tool. It renders the project to a temp WAV file, measures integrated loudness (LUFS) using pyloudnorm and true peak (dBTP) using numpy, then returns the results.
@mcp.tool() def analyze_loudness() -> dict: """ Render the project to a temp file and measure integrated loudness (LUFS) and true peak (dBTP) using the ITU-R BS.1770 standard. """ try: import soundfile as sf import pyloudnorm as pyln import numpy as np from reaper_mcp.render_tools import render_to_temp_file tmp = render_to_temp_file() try: data, rate = sf.read(tmp) meter = pyln.Meter(rate) integrated = meter.integrated_loudness(data) peak_linear = float(np.max(np.abs(data))) peak_db = float(20 * np.log10(peak_linear)) if peak_linear > 0 else -120.0 return { "success": True, "integrated_lufs": round(integrated, 1), "true_peak_dbtp": round(peak_db, 1), "sample_rate": rate, } finally: if os.path.exists(tmp): os.unlink(tmp) except Exception as e: logger.error(f"analyze_loudness failed: {e}") return {"success": False, "error": str(e)} - src/reaper_mcp/server.py:17-28 (registration)The tool is registered via the master registration function. 'register_tools' from mastering_tools.py is imported and called with the mcp instance on line 27, which decorates analyze_loudness with @mcp.tool().
from reaper_mcp.mastering_tools import register_tools as _reg_mastering from reaper_mcp.analysis_tools import register_tools as _reg_analysis _reg_project(mcp) _reg_track(mcp) _reg_midi(mcp) _reg_fx(mcp) _reg_audio(mcp) _reg_mixing(mcp) _reg_render(mcp) _reg_mastering(mcp) _reg_analysis(mcp) - src/reaper_mcp/mastering_tools.py:18-18 (registration)The outer 'register_tools(mcp)' function that contains the @mcp.tool() decoration for analyze_loudness (line 131-132). All mastering tools are registered inside this function.
def register_tools(mcp): - src/reaper_mcp/render_tools.py:47-56 (helper)The 'render_to_temp_file' helper function used by analyze_loudness to render the current REAPER project to a temporary WAV file before analysis.
def render_to_temp_file(sample_rate: int = 48000) -> str: """ Render the current project to a temporary WAV file and return its path. Used by analysis and mastering tools. Caller is responsible for deleting the file. """ import tempfile tmp = tempfile.mktemp(suffix=".wav") _set_render_settings(tmp, "wav", sample_rate, 24, 2, bounds=0) RPR.Main_OnCommand(41824, 0) return tmp