-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunity_Tips.lua
More file actions
182 lines (166 loc) · 6.11 KB
/
Copy pathCommunity_Tips.lua
File metadata and controls
182 lines (166 loc) · 6.11 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- Set the path to your spreadsheet file
local spreadsheetPath = "PASTE YOURN FILE PATH HERE - KEEP QUOTATIONS"
function readSpreadsheet(filename)
local file = io.open(filename, "r")
if file then
local data = {}
for line in file:lines() do
local cells = {}
local cell = ""
local inQuotes = false
for i = 1, #line do
local char = line:sub(i, i)
if char == "\"" then
inQuotes = not inQuotes
elseif char == "," and not inQuotes then
table.insert(cells, cell)
cell = ""
else
cell = cell .. char
end
end
table.insert(cells, cell)
table.insert(data, cells)
end
file:close()
return data
end
return nil
end
function clearConsole()
reaper.ShowConsoleMsg("")
end
function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
function decodeText(text)
return text:gsub("Õ", "'"):gsub("É", "...")
end
function getRandomRow()
return math.random(1, 50)
end
function displayCells(data, row)
local rowCells = data[row]
if rowCells then
local output = ""
for i, cell in ipairs(rowCells) do
if i > 1 then
output = output .. "\n\n"
end
output = output .. trim(decodeText(cell))
end
output = trim(output) -- Trim whitespace from output
reaper.ShowConsoleMsg(output .. "\n")
else
reaper.ShowConsoleMsg("Selected row does not exist.\n")
end
end
local function showMessageBox(message, questionMark)
local buttonFlags = 1
if questionMark then
buttonFlags = reaper.ShowMessageBox(decodeText(message), " ", 3)
else
buttonFlags = reaper.ShowMessageBox(decodeText(message), " ", 1)
end
if buttonFlags == 6 then
return "yes"
elseif buttonFlags == 7 then
return "no"
elseif buttonFlags == 1 then
return "ok"
else
return "cancel"
end
end
function shouldCloseMessageBox(lineNum, columnNum)
if lineNum == 6666 and columnNum == 2 then
return true
elseif lineNum == 6735 and columnNum == 2 then
return true
elseif lineNum == 6734 and columnNum == 3 then
return true
else
return false
end
end
-- Code for reading the spreadsheet file
local data = readSpreadsheet(spreadsheetPath)
if data then
-- Code for clearing the console
clearConsole()
local row = getRandomRow()
displayCells(data, row)
local executionCount = tonumber(reaper.GetExtState("Script", "ExecutionCount")) or 0
executionCount = executionCount + 1
if executionCount >= 50 then
local file = io.open(spreadsheetPath, "r")
if file then
local lines = {}
for line in file:lines() do
local row = {}
for value in line:gmatch("[^,]+") do
table.insert(row, value)
end
table.insert(lines, row)
end
file:close()
local lineNum = 6666
local columnNum = 1
while lineNum <= #lines do
local row = lines[lineNum]
if row then
local currentCellValue = row[columnNum]
if currentCellValue and currentCellValue ~= "" then
local questionMark = currentCellValue:sub(-1) == "?"
local result = showMessageBox(currentCellValue, questionMark)
if result == "yes" then
lineNum = lineNum + 1
elseif result == "no" then
columnNum = columnNum + 1
elseif result == "ok" then
if shouldCloseMessageBox(lineNum, columnNum) then
break
else
if lineNum == 6682 and columnNum == 1 then
lineNum = 6681
columnNum = 2
elseif lineNum == 6687 and columnNum == 2 then
lineNum = 6683
columnNum = 3
elseif lineNum == 6691 and columnNum == 3 then
lineNum = 6688
columnNum = 4
elseif lineNum == 6692 and columnNum == 4 then
lineNum = 6696
columnNum = 1
elseif lineNum == 6704 and columnNum == 1 then
lineNum = 6708
columnNum = 2
elseif lineNum == 6708 and columnNum == 1 then
lineNum = 6704
columnNum = 2
else
lineNum = lineNum + 1
end
end
elseif result == "cancel" then
break
end
else
reaper.ShowMessageBox("Empty cell detected.", "ReaScript", 0)
lineNum = lineNum + 1
end
end
end
-- Code for clearing the console
clearConsole()
reaper.SetExtState("Script", "ExecutionCount", "0", true)
else
reaper.ShowMessageBox("Failed to open the spreadsheet file.", "ReaScript", 0)
end
else
reaper.SetExtState("Script", "ExecutionCount", tostring(executionCount), true)
end
else
reaper.ShowConsoleMsg("Failed to open the spreadsheet file.\n")
end