Breeder has coded an all-important suite of functions for SWS that return details of the mouse position:
BR_GetMouseCursorContext
BR_GetMouseCursorContext_MIDI
BR_GetMouseCursorContext_Position
BR_GetMouseCursorContext_Take
etc
In the case of BR_GetMouseCursorContext_MIDI, the function returns PPQ position, pitch, CC value, CC lane, etc:
Code:
identifier retval, boolean inlineEditor, number noteRow, number ccLane, number ccLaneVal, number ccLaneId = reaper.BR_GetMouseCursorContext_MIDI()
[BR] Returns midi editor under mouse cursor that was captured with the last call to BR_GetMouseCursorContext.
inlineEditor: if mouse was captured in inline MIDI editor, this will be true (consequentially, returned MIDI editor will be NULL)
noteRow: note row or piano key under mouse cursor (0-127)
ccLane: CC lane under mouse cursor
ccLaneVal: value in CC lane under mouse cursor (0-127 or 0-16383)
ccLaneId: lane position, counting from the top (0 based)
This allows scripts to track the mouse movement, and to insert MIDI events at the mouse position. For example:
Unfortunately, the SWS functions do not work in the new notation editor, so scripts are blind with regard to mouse position.
Since SWS isn't actively being developed anymore, it would be great if Cockos could provide the missing API function to return the mouse pitch and PPQ position in the notation editor.
(The notation editor is arranged somewhat differently than the piano roll, with different takes on different staves, so the new function may need to return an additional value or two to indicate the take under the mouse.)
Even better than a new function just for the notation editor, would be to replace BR_GetMouseCursorContext_MIDI() with a new, more general function that would work in the notation editor as well as the piano roll and the inline editor.
Since REAPER already tracks mouse movement internally and displays the PPQ position, pitch and/or CC value in the top left corner of the MIDI editor. I expect that this new API function would be easy to implement: the function simply needs to return the values that REAPER already has available.
An added benefit would be improved speed: The SWS functions get slower and slower as the number of MIDI events in the take increase (I suspect that these functions didn't have direct access to the aforementioned internal variables, and had to use some 'trick' to figure out the mouse position). A new, native function would likely be much faster, and would speed up deferred scripts that need to poll the mouse position in each cycle.