Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 11-29-2016, 07:21 AM   #1
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default Action for selecting only the note under mouse cursor ?

I guess, i must be overseeing something very obvious but i just can't find an Action that does this:

In Midi Editor, when i hover my mouse over a note, the searched for Action selects that note, and only that note.
Not other notes above or beneath the pointed note, just that one note where the mouse pointer is on.
vanhaze is offline   Reply With Quote
Old 11-29-2016, 10:03 AM   #2
me2beats
Human being with feelings
 
me2beats's Avatar
 
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
Default

Quote:
Originally Posted by vanhaze View Post
I guess, i must be overseeing something very obvious but i just can't find an Action that does this:

In Midi Editor, when i hover my mouse over a note, the searched for Action selects that note, and only that note.
Not other notes above or beneath the pointed note, just that one note where the mouse pointer is on.
https://github.com/me2beats/rea-me2/...er%20mouse.lua

Code:
local r = reaper; local function nothing() end; local function bla() r.defer(nothing) end

take = r.MIDIEditor_GetTake(r.MIDIEditor_GetActive())
if not take then bla() return end
notes = r.MIDI_CountEvts(take)
window, segment, details = r.BR_GetMouseCursorContext()
_, noteRow = r.BR_GetMouseCursorContext_MIDI()
if noteRow == -1 then bla() return end

mouse_time = r.BR_GetMouseCursorContext_Position()
mouse_ppq_pos = r.MIDI_GetPPQPosFromProjTime(take, mouse_time)

r.Undo_BeginBlock() r.PreventUIRefresh(1)

for i = 0, notes - 1 do
  _, sel, muted, start_note, end_note, chan, pitch, vel = r.MIDI_GetNote(take, i)
  if start_note < mouse_ppq_pos and end_note > mouse_ppq_pos and noteRow == pitch then
    if sel == false then
      r.MIDI_SetNote(take, i, 1, muted, start_note, end_note, chan, pitch, vel)
    end
  elseif sel == true then
    r.MIDI_SetNote(take, i, 0, muted, start_note, end_note, chan, pitch, vel)
  end
end

r.PreventUIRefresh(-1) r.Undo_EndBlock('Select only note under mouse', 2)
me2beats is offline   Reply With Quote
Old 11-29-2016, 11:18 AM   #3
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Many thanks for your help !

But doesn't seem to work for me ..

- I imported the script into Action List / midi editor context.
- I assigned a keyboard shortcut to it.
- I made a simple midi item in Midi Editor.
- now i place my mouse cursor on one note and hit the keyboard shortcut.
Outcome:
1) Already selected notes become deselected, but the note on which the mouse cursor is, isn't selected.
2) When no notes were selected beforehand, nothing happens when your script is executed,the note on which the mouse cursor is, isn't selected.

OSX 10.12.1
Reaper 5.30pre3.
vanhaze is offline   Reply With Quote
Old 05-20-2017, 02:26 PM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,107
Default

This version should work (at least it does here):

Code:
local r = reaper; local function nothing() end; local function bla() r.defer(nothing) end

take = r.MIDIEditor_GetTake(r.MIDIEditor_GetActive())
if not take then bla() return end
notes = r.MIDI_CountEvts(take)
window, segment, details = r.BR_GetMouseCursorContext()
_, _, noteRow = r.BR_GetMouseCursorContext_MIDI() -- see http://forum.cockos.com/showpost.php?p=1749178&postcount=13
if noteRow == -1 then bla() return end

mouse_time = r.BR_GetMouseCursorContext_Position()
mouse_ppq_pos = r.MIDI_GetPPQPosFromProjTime(take, mouse_time)

r.Undo_BeginBlock() r.PreventUIRefresh(1)

for i = 0, notes - 1 do
  _, sel, muted, start_note, end_note, chan, pitch, vel = r.MIDI_GetNote(take, i)
  if start_note < mouse_ppq_pos and end_note > mouse_ppq_pos and noteRow == pitch then
    if sel == false then
      r.MIDI_SetNote(take, i, 1, muted, start_note, end_note, chan, pitch, vel)
    elseif sel == true then
      r.MIDI_SetNote(take, i, 0, muted, start_note, end_note, chan, pitch, vel)
    end
  end
end

r.PreventUIRefresh(-1) r.Undo_EndBlock('Select only note under mouse', 2)

Last edited by nofish; 05-20-2017 at 04:48 PM.
nofish is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.