I think he just wants explanations of how to get certain information and work with it.
First, all the MIDI functions need to know what item (called "take" here) you're working in:
Code:
cur_wnd = reaper.MIDIEditor_GetActive()
cur_take = reaper.MIDIEditor_GetTake(cur_wnd)
Then you need some notes to work with:
Code:
-- Get all of the selected notes
local sel_notes = {}
local cur_note = -2
local note_val
while cur_note ~= -1 do
cur_note = reaper.MIDI_EnumSelNotes(cur_take, cur_note)
if cur_note == -1 then break end
cur_arr = {reaper.MIDI_GetNote(cur_take, cur_note)}
table.remove(cur_arr, 1)
table.insert(sel_notes, cur_arr)
end
reaper.MIDI_EnumSelNotes gives you every selected note, one at a time, in a bit of a strange way - you tell it "I've got the fourth note already" and it says "okay, here's the fifth note", and so on until it runs out of notes to give you.
We've now got a table,
cur_arr, that contains a subtable for each selected note with these values:
Code:
retval, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut reaper.MIDI_GetNote(current_take, selected_note)
retval isn't super useful once you've got the note, so you can see in the code above that I used
table.remove to just clear that value from all of the subtables.
Now we can get information about each note simply by accessing the appropriate field of the subtable:
Code:
[1] - Is the note selected, true/false
[2] - Is the note muted, true/false
[3] - Note start position, measured in PPQ
[4] - Note end position, measured in PPQ
[5] - MIDI channel
[6] - MIDI note number
[7] - MIDI velocity
Code:
local pitch_of_note_20 = cur_arr[20][6]
Converting from a MIDI note number to the actual pitch class just takes some division. The
% operator is the same as
mod, that is, a math operation called
modulo.
a % b takes
a / b and gives you the remainder:
Code:
pitch_class = cur_note % 12
Changing a MIDI note's values is just a matter of changing the appropriate value in our table, and then using
reaper.MIDI_SetNote to copy/paste our new values onto the original note.
Code:
reaper.MIDI_SetNote( take, noteidx, selectedInOptional, mutedInOptional, startppqposInOptional, endppqposInOptional, chanInOptional, pitchInOptional, velInOptional, noSortInOptional )
You don't actually need to copy all of the values - just the ones you're changing. Any of the above values that you set as
nil in the function arguments, or omit, will remain as they were.
Code:
cur_arr[20][6] = cur_arr[20][6] + 7
reaper.MIDI_SetNote( cur_take, 20, nil, nil, nil, nil, nil, cur_arr[20][6])
If you're changing multiple notes' parameters in one go, it's more efficient to use the
noSort option on each one, and then tell Reaper to sort them afterward:
Code:
for i = 1, #cur_arr do
reaper.MIDI_SetNote( cur_take, i, nil, nil, nil, nil, nil, cur_arr[i][6], nil, true)
end
reaper.MIDI_Sort(cur_take)
As for your other questions, I'd recommend using the search box on X-Raym's API documentation page:
http://www.extremraym.com/cloud/reascript-doc/
Between that and Ctrl+F, it's usually not too hard to find what you need.