forked from ReaTeam/ReaScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLokasenna_Repeat Action - Add new action.lua
62 lines (39 loc) · 1.42 KB
/
Lokasenna_Repeat Action - Add new action.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
--[[
NoIndex: true
--]]
-- Licensed under the GNU GPL v3
local function Msg(str)
reaper.ShowConsoleMsg(tostring(str).."\n")
end
local ret, csv = reaper.GetUserInputs("Repeat Action - Add new action", 4, "Action ID:,File alias:,How often (s),MIDI (y/n):", ",,0.6,n")
if ret then
local act, alias, interval, midi = string.match(csv, "([^,]+),([^,]*),([^,]+),([^,]+)")
if not (act and interval and midi) then
reaper.ShowMessageBox("Invalid parameters.", "Whoops", 0)
return 0
end
local script_path = debug.getinfo(1,'S').source:match[[^@?(.*[\/])[^\/]-$]]
.. "Lokasenna_Repeat Action - "
.. (alias or tostring(act))
.. ".lua"
local file = io.open(script_path, "w+") or nil
if not file then
reaper.ShowMessageBox("Couldn't create the file.", "Whoops", 0)
return 0
end
local str_pre =
[=[--[[
This file was generated by Lokasenna_Repeat Action - Add new action.lua
--]]
]=]
local str_vars = 'act = "'..act..'"\n'
.."interval = "..interval.."\n"
.."midi = "..tostring(midi == "y").."\n\n"
local str_suff =
[=[script_path = debug.getinfo(1,'S').source:match[[^@?(.*[\/])[^\/]-$]]
dofile(script_path .. "Lokasenna_Repeat Action.lua")]=]
local str = str_pre .. str_vars .. str_suff
file:write(str)
io.close(file)
reaper.AddRemoveReaScript( true, (midi == "n" and 0 or 32060), script_path, true )
end