--[[ ReaScript Name: Add markers for lyrics in selected items About: Looks through the lyrics in an item and adds a marker at each lyric. Instructions: - Select items - Run the script Author: beaunus Licence: GPL v3 REAPER: 5.0 Version: 1.0.1 ]] --[[ Changelog: * v1.0 (2017-02-20) + Initial Release * v1.0.1 (2017-08-02) + Fix "u/0005 appears at beginning of all markers" bug ]] Info = [[Select a MIDI Text Event Number to import to Markers or Regions: 1 = Text 2 = Copyright 3 = Sequence/Track Name 4 = Instrument 5 = Lyric 6 = Marker 7 = Cue 8 = Program 9 = Device ]] reaper.MB(Info, "MIDI Text Event to Region/Marker", 0) retval, text_type = reaper.GetUserInputs("Choose MIDI Text Type", 1, "Number 1-9", "1") if not retval then goto finish end -- Count the number of selected items. num_selected_items = reaper.CountSelectedMediaItems() -- Iterate through all selected items. for i = 0, num_selected_items - 1 do item = reaper.GetSelectedMediaItem(0, i) -- Get the active take take = reaper.GetActiveTake(item) -- Process the take IFF the take contains MIDI if reaper.TakeIsMIDI(take) then -- Get all the MIDI events for this take ok, buf = reaper.MIDI_GetAllEvts(take, "") -- Proceed only if there are MIDI events to pr+ocess if ok and buf:len() > 0 then --[[ Since messages offsets are relative to the previous message, track the total offset, in order to know the position of the MIDI events --]] total_offset = 0 pos = 1 while pos <= buf:len() do offs, flag, msg = string.unpack("IBs4", buf, pos) total_offset = total_offset + offs adv = 4 + 1 + 4 + msg:len() -- Determine if this event is a lyric message 5 or text 1 --0x01 = Text --0x02 = Copyright --0x03 = Sequence/Track Name --0x04 = Instrument --0x05 = Lyric --0x06 = Marker --0x07 = Cue --0x08 = Program --0x09 = Device if msg:byte(1) == 255 and msg:byte(2) == tonumber(text_type) then --5 then --for lyrics lyric = msg:sub(3) position = reaper.MIDI_GetProjTimeFromPPQPos(take, total_offset) -- Create the marker reaper.AddProjectMarker(0, false, position, 0, lyric, -1) end pos = pos+adv end end end --retval, yes_no = reaper.GetUserInputs("Convert Markers to Regions", 1, "OK yes Cancel no", "yes") choice = reaper.MB( "Markers to Regions", "Convert Markers to Regions", 4 ) --if not retval then goto finish end if choice == 6 then commandID1 = reaper.NamedCommandLookup("_SWSMARKERLIST13") reaper.Main_OnCommand(commandID1, 0) -- SWS: Convert markers to regions "_SWSMARKERLIST13" end end ::finish::