|
|
|
05-24-2019, 11:13 AM
|
#1
|
Human being with feelings
Join Date: Aug 2016
Posts: 91
|
How to return a midi note?
When I use the FNG functions to return midi notes into a table, I later get an error (on the 3rd last line) saying that the argument got light userdata instead of a number. I've tried using other functions such as 'reaper.MIDI_GetNote' but in Lua it doesn't seem to return a midi note. Is there a function available that returns a midi note or am I using the FNG functions wrong?
Code:
item = reaper.GetMediaItem(0, 0) -- NEED TO CHANGE TO GET SELECTED ITEM!
take = reaper.GetMediaItemTake(item, 0)
midi_take = reaper.FNG_AllocMidiTake(take)
midi_note_count = reaper.FNG_CountMidiNotes(midi_take)
function get_notes_table(all_notes)
for i = 0, midi_note_count - 1 do
local midi_note = reaper.FNG_GetMidiNote(midi_take, i)
table.insert(all_notes, midi_note)
end
return all_notes
end
reaper.ShowConsoleMsg(tostring(all_notes))
all_notes = {}
notes_table = get_notes_table(all_notes)
for i = 0, midi_note_count - 1 do
local midi_note, selected, muted, startppqpos, endppqpos = reaper.MIDI_GetNote(take, i)
if i + 1 > midi_note_count - 1 then
break
else
local midi_note_next, selected, muted, startppqpos_next, endppqpos_next = reaper.MIDI_GetNote(take, i + 1)
reaper.MIDI_SetNote(take, notes_table[i + 2], nil, nil, endppqpos, endppqpos_next - (startppqpos_next - endppqpos))
end
end
Last edited by Sonorityscape; 05-24-2019 at 11:18 AM.
|
|
|
05-24-2019, 03:07 PM
|
#2
|
Human being with feelings
Join Date: Aug 2016
Posts: 91
|
I seemed to have gotten the script to work except for the end where the MIDI note position values are being set (4th last written line). From my debugging, the note positions are being updated each iteration through the loop to reflect exactly what I want, but they're not changing position in the MIDI editor. Does anyone know how to fix this?
Code:
item = reaper.GetMediaItem(0, 0)
take = reaper.GetMediaItemTake(item, 0)
take_fng = reaper.FNG_AllocMidiTake(take)
note_count = reaper.FNG_CountMidiNotes(take_fng)
function get_notes_table(all_notes)
for i = 0, note_count - 1 do
local note_fng = reaper.FNG_GetMidiNote(take_fng, i)
table.insert(all_notes, note_fng)
end
return all_notes
end
all_notes = {}
notes_table = get_notes_table(all_notes)
for i = 0, note_count - 1 do
local note_start = reaper.FNG_GetMidiNoteIntProperty(notes_table[i+1], "POSITION")
local note_end = (reaper.FNG_GetMidiNoteIntProperty(notes_table[i+1], "LENGTH")) + (note_start)
--DEBUG
reaper.ShowConsoleMsg("start note " .. i .. ": " .. tostring(note_start) .. "\n")
reaper.ShowConsoleMsg("end note " .. i .. ": " .. tostring(note_end) .. "\n")
if i + 1 > note_count - 1 then
break
else
reaper.FNG_SetMidiNoteIntProperty(notes_table[i + 2], "POSITION", note_end)
end
end
reaper.UpdateArrange()
|
|
|
05-24-2019, 06:39 PM
|
#3
|
Human being with feelings
Join Date: Aug 2016
Posts: 91
|
It works after deallocating the memory.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:56 PM.
|