Thanks Breeder!
This script returns a line from MIDI take chunk:
Code:
-- String functions from Haywoods DROPP Script
function starts_with(text,prefix)
return string.sub(text, 1, string.len(prefix)) == prefix
end
function string:split(sep)
return self:match("([^" .. sep .. "]+)[" .. sep .. "]+(.+)")
end
function string:trim()
return self:match("^%s*(.-)%s*$")
end
function get_MIDI_take_source_line(item, take, first_chars_in_line)
if item ~= nil and take ~= nil then
fs = reaper.SNM_CreateFastString("")
reaper.SNM_GetSetSourceState(item, -1, fs, false)
fs_content = reaper.SNM_GetFastString(fs)
--reaper.ShowConsoleMsg(fs_content)
reaper.SNM_DeleteFastString(fs)
for line in fs_content:gmatch("[^\r\n]+") do
if starts_with(line, first_chars_in_line) then
--reaper.ShowConsoleMsg(line .."\n")
return line
end
end
end
end
-- Test: Get "POOLEDEVTS ..." -line from MIDI take chunk.
item = reaper.GetSelectedMediaItem(0,0)
if item ~= nil then
take = reaper.GetActiveTake(item)
if take ~= nil then
reaper.GetSelectedMediaItem(0,0)
ret_line = get_MIDI_take_source_line(item, take, "POOLEDEVTS")
end
end
if item~=nil and take~=nil then
if ret_line then
reaper.ShowConsoleMsg(ret_line .."\n")
else
reaper.ShowConsoleMsg("Couldn't find the line\n")
end
end
(NOTE: There's no error checking, source type checking etc.)