Old 09-14-2021, 07:34 AM   #1
JRTaylorMusic
Human being with feelings
 
Join Date: Feb 2019
Location: Austin, TX
Posts: 413
Default MIDI Editor: how to determine if last note

I think I understand how to work
If [note is selected] then
DO THIS
but I want to specify
If [note is selected] then
If [is selected note the last note?] then —how do I do this??
DO THIS else
DO THAT
I thought MIDI_EnumSelNotes but now I’m completely stumped.
In my searching for answers I came across these additional functions, like FNG_GetMidiNote which are apparently SWS functions… now I feel stumped in the dark!

Hoping for a wise guide to help me find my way…
JRTaylorMusic is offline   Reply With Quote
Old 09-14-2021, 08:32 AM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Not a MIDI guy (so maybe someone knows a better way), but in one script I made I put the index of the selected notes into a table first, then I loop thru that table to do stuff.

So one way might be to use the length of the table to determine if the last selected note, something like,...

Code:
local take=reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
if take ~= nil then
  -- add selected notes index to a table
  local cnt, index = 0, {}
  local val = reaper.MIDI_EnumSelNotes(take, -1)
  while val ~= - 1 do
    cnt = cnt + 1
    index[cnt] = val
    val = reaper.MIDI_EnumSelNotes(take, val)
  end
  
  -- loop thru selected note table
  for i = 1, #index do
    local retval, sel, muted, ppq_start, ppq_end, chan, pitch, vel = reaper.MIDI_GetNote(take, index[i])
   
    if i ~= #index then
      -- do this
      reaper.ShowConsoleMsg("Sel note #" .. i .. ", pitch = " .. pitch ..'\n')
    else
      -- do this for last selected note
      reaper.ShowConsoleMsg("Last sel note #" .. i .. ", pitch = " .. pitch ..'\n')
    end
  end
  
end
Edgemeal is offline   Reply With Quote
Old 09-14-2021, 08:47 AM   #3
JRTaylorMusic
Human being with feelings
 
Join Date: Feb 2019
Location: Austin, TX
Posts: 413
Default

Ah! I was on this path last night but fell into the abyss. 🤪

In my case, I mean "last note" to refer to the last note in the current MIDI take, but I think this should help me get back on track. Thank you!!
JRTaylorMusic is offline   Reply With Quote
Old 09-14-2021, 08:57 AM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Maybe use the reaper.MIDI_CountEvts() function?

Doc says, Count the number of notes, CC events, and text/sysex events in a given MIDI item.

EDIT seems to work as expected here,
Code:
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
retval, notecnt, ccevtcnt, textsyxevtcnt = reaper.MIDI_CountEvts(take)
reaper.ShowConsoleMsg( notecnt ) -- number of notes in take

Last edited by Edgemeal; 09-14-2021 at 09:10 AM.
Edgemeal is offline   Reply With Quote
Old 09-14-2021, 08:58 AM   #5
JRTaylorMusic
Human being with feelings
 
Join Date: Feb 2019
Location: Austin, TX
Posts: 413
Default

working with that now... will report back, hopefully with success!
Thanks again!
JRTaylorMusic is offline   Reply With Quote
Old 09-16-2021, 01:20 PM   #6
JRTaylorMusic
Human being with feelings
 
Join Date: Feb 2019
Location: Austin, TX
Posts: 413
Default

Quote:
Originally Posted by Edgemeal View Post
Maybe use the reaper.MIDI_CountEvts() function?

Doc says, Count the number of notes, CC events, and text/sysex events in a given MIDI item.

EDIT seems to work as expected here,
Code:
take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
retval, notecnt, ccevtcnt, textsyxevtcnt = reaper.MIDI_CountEvts(take)
reaper.ShowConsoleMsg( notecnt ) -- number of notes in take
THANK YOU!! This got me back up and running and I was able to accomplish EXACTLY what I set out to do!
JRTaylorMusic 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 05:33 PM.


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