-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathX-Raym_Export markers and regions as tab-delimited CSV file.lua
106 lines (89 loc) · 2.65 KB
/
X-Raym_Export markers and regions as tab-delimited CSV file.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--[[
* ReaScript Name: Export markers and regions from tab-delimited CSV file
* Instructions: Select a track. Run.
* Author: X-Raym
* Author URI: https://www.extremraym.com
* Repository: GitHub > X-Raym > REAPER-ReaScripts
* Repository URI: https://github.com/X-Raym/REAPER-ReaScripts
* Links
Forum Thread https://forum.cockos.com/showthread.php?p=1670961
* Licence: GPL v3
* REAPER: 5.0
* Version: 1.1
--]]
--[[
* Changelog:
* v1.1 (2020-06-03)
+ Support for Markers and Regions subtitles notes
* v1.0.4 (2020-04-24)
# Force .csv extension
* v1.0.3 (2019-12-20)
# Msg
* v1.0.2 (2019-11-20)
# Header tab
* v1.0.1 (2019-01-26)
# Extension
* v1.0 (2019-01-26)
+ Initial Release
--]]
function Msg(val)
reaper.ShowConsoleMsg(tostring(val).."\n")
end
function export(f, variable)
f:write(variable)
f:write("\n")
end
function rgbToHex(r, g, b)
return string.format("#%0.2X%0.2X%0.2X", r, g, b)
end
function Main()
local f = io.open(file, "w")
sub_header = ""
if reaper.NF_GetSWSMarkerRegionSub then
sub_header = "\tSubtitles"
end
export(f, "#\tName\tStart\tEnd\tLength\tColor" .. sub_header)
i=0
repeat
iRetval, bIsrgnOut, iPosOut, iRgnendOut, name, iMarkrgnindexnumberOut, iColorOur = reaper.EnumProjectMarkers3(0,i)
if iRetval >= 1 then
local t, duration
if bIsrgnOut then
t = "R"
duration = iRgnendOut - iPosOut
else
t = "M"
duration = 0
iRgnendOut = iPosOut
end
local color = 0
if iColorOur > 0 then
r,g,b = reaper.ColorFromNative(iColorOur)
color = rgbToHex(r, g, b)
end
sub = "\t"
if reaper.NF_GetSWSMarkerRegionSub then
sub = sub .. reaper.NF_GetSWSMarkerRegionSub( i )
sub = sub:gsub('\r\n', '<br>')
sub = sub:gsub('\n\n', '<br>')
sub = sub:gsub('\n', '<br>')
sub = sub:gsub('\r', '<br>')
end
-- [start time HH:MM:SS.F] [end time HH:MM:SS.F] [name]
line = t .. iMarkrgnindexnumberOut .. "\t\"" .. name .. "\"\t" .. iPosOut .. "\t" .. iRgnendOut .. "\t" .. duration .. "\t" .. color .. sub
export(f, line)
end
i = i+1
until iRetval == 0
-- CLOSE FILE
f:close() -- never forget to close the file
end
if not reaper.JS_Dialog_BrowseForSaveFile then
Msg("Please install JS_ReaScript REAPER extension, available in Reapack extension, under ReaTeam Extensions repository.")
else
retval, file = reaper.JS_Dialog_BrowseForSaveFile( "Save Markers and Regions", '', "", 'csv files (.csv)\0*.csv\0All Files (*.*)\0*.*\0' )
if retval and file ~= '' then
if not file:find('.csv') then file = file .. ".csv" end
reaper.defer(Main)
end
end