add_midi_note
Insert a MIDI note into an existing MIDI item on a given track. Define pitch (middle C=60), start and length in seconds, velocity, and channel (9 for drums).
Instructions
Add a MIDI note to an existing MIDI item. pitch: MIDI note number 0–127 (60 = middle C, 69 = A4). start/length: seconds, relative to the item's start. channel: MIDI channel 0–15 (use 9 for drums).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| track_index | Yes | ||
| item_index | Yes | ||
| pitch | Yes | ||
| start | Yes | ||
| length | Yes | ||
| velocity | No | ||
| channel | No |
Implementation Reference
- src/reaper_mcp/midi_tools.py:83-125 (handler)The add_midi_note tool handler function, decorated with @mcp.tool(). It adds a MIDI note to an existing MIDI item at a given track_index, item_index with specified pitch (0-127), start/length (seconds relative to item start), velocity, and channel. Uses reapy's take.add_note() under the hood.
@mcp.tool() def add_midi_note( track_index: int, item_index: int, pitch: int, start: float, length: float, velocity: int = 100, channel: int = 0, ) -> dict: """ Add a MIDI note to an existing MIDI item. pitch: MIDI note number 0–127 (60 = middle C, 69 = A4). start/length: seconds, relative to the item's start. channel: MIDI channel 0–15 (use 9 for drums). """ try: project = get_project() track = project.tracks[track_index] item = track.items[item_index] take = item.active_take if not take.is_midi: return {"success": False, "error": "Item is not a MIDI item"} take.add_note( start=start, end=start + length, pitch=pitch, velocity=velocity, channel=channel, ) return { "success": True, "track_index": track_index, "item_index": item_index, "pitch": pitch, "start": start, "length": length, "velocity": velocity, "channel": channel, } except Exception as e: logger.error(f"add_midi_note failed: {e}") return {"success": False, "error": str(e)} - src/reaper_mcp/server.py:22-22 (registration)The registration call where register_tools from midi_tools is invoked with the mcp instance, which registers add_midi_note as an MCP tool.
_reg_midi(mcp) - src/reaper_mcp/server.py:12-12 (registration)Import of register_tools from midi_tools module into the server, aliased as _reg_midi.
from reaper_mcp.midi_tools import register_tools as _reg_midi - src/reaper_mcp/connection.py:7-27 (helper)The get_project helper function used by add_midi_note to obtain the current REAPER project via reapy.
def ensure_connected() -> None: global _connected if _connected: return try: reapy.connect() _connected = True logger.info("Connected to REAPER") except Exception as e: raise RuntimeError( f"Cannot connect to REAPER: {e}. " "Make sure REAPER is running and the distant API is enabled. " "To enable it: run the setup script (scripts/enable_reapy.py) or " "in REAPER go to Actions > Run ReaScript, then run: " "import reapy; reapy.config.enable_dist_api()" ) from e def get_project() -> reapy.Project: - src/reaper_mcp/midi_tools.py:84-92 (schema)The type-annotated function signature serves as the input schema for add_midi_note: track_index (int), item_index (int), pitch (int), start (float), length (float), velocity (int, default 100), channel (int, default 0).
def add_midi_note( track_index: int, item_index: int, pitch: int, start: float, length: float, velocity: int = 100, channel: int = 0, ) -> dict: