/
TJF Surround Toggle 2.0.lua
156 lines (104 loc) · 4.88 KB
/
TJF Surround Toggle 2.0.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
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
--[[
@description TJF Toggle Session Stereo or Surround (Rename file for default number of channels)
@version 2.0
@author Tim Farrell
@link http://github.com/sonictim/TJF-Scripts/
@date 2020 04 26
@about
# Toggles Stereo or Number of Channels in filename on all tracks
Will Enable/Disable any surround plugins on all tracks and takes
Initially will use number of tracks listed in filename.
Mill mimic/populate master track track count.
Will create a toggle stage for this function, that can be button mapped.
--]]
function GetChannelsFromFilename()
local info = debug.getinfo(1,'S') -- Builds a table with info about the lua script
info.channels = tonumber(string.match(info.source, "%d+")) -- info.source is filename in the table
if info.channels % 2 ~= 0 then
info.channels = info.channels + 1
end
info.channels = math.max(2, math.min(info.channels, 64))
return info.channels
end
--[[
local cmd_id = ({reaper.get_action_context()})[4] -- gets command ID for this script
local state = reaper.GetToggleCommandStateEx(0,cmd_id)
local track = reaper.GetMasterTrack(0)
local channels = tonumber(reaper.GetExtState("TJF", "SurroundChannels"))
if not channels then
channels = GetChannelsFromFilename()
reaper.SetExtState("TJF", "SurroundChannels", channels, 0)
end
local current = reaper.GetMediaTrackInfo_Value(track, "I_NCHAN")
if current ~= channels then
if current ~= 2 then
channels = current
reaper.SetExtState("TJF", "SurroundChannels", current, 0)
state = 0
end
end
local enable = true
if state ~= 1 then
state = 1
-------------------WILL SET MASTER CHANNEL REASURROUND PLUGIN
--local fx = reaper.TrackFX_AddByName(track, "ReaSurround", false, 1)
--reaper.TrackFX_SetPreset( track, fx, "Master Channel 5.1 to 5.1 outputs" )
else
state = 0
channels = 2
enable = false
--index = reaper.TrackFX_AddByName(track, "Master 5.1 to Stereo Downmixer.rfxchain", false, 1 )
--reaper.SetMediaTrackInfo_Value(track, "I_NCHAN", 2)
-------------------WILL SET MASTER CHANNEL REASURROUND PLUGIN
--local fx = reaper.TrackFX_AddByName(track, "ReaSurround", false, 1)
--reaper.TrackFX_SetPreset( track, fx, "Master Channel 5.1 to Stereo Mix Down" )
end
-------------SET MASTER TRACK
reaper.SetMediaTrackInfo_Value(track, "I_NCHAN", channels)
local fx = reaper.TrackFX_AddByName( track, "ReaSurround", false, 0)
if fx >= 0 then reaper.TrackFX_SetEnabled( track, fx, enable ) end
fx = reaper.TrackFX_AddByName( track, "Surround Pan 2.1", false, 0)
if fx >= 0 then reaper.TrackFX_SetEnabled( track, fx, enable ) end
-------------SET ALL OTHER TRACKS
for i=0, reaper.CountTracks(0)-1 do -- set all tracks to channels
--------Set Number of Track Channels for all tracks
track = reaper.GetTrack(0,i)
reaper.SetMediaTrackInfo_Value(track, "I_NCHAN", channels)
--------Enable/Disable Surround Plugins for all tracks
fx = reaper.TrackFX_AddByName( track, "ReaSurround", false, 0)
if fx >= 0 then reaper.TrackFX_SetEnabled( track, fx, enable ) end
fx = reaper.TrackFX_AddByName( track, "Surround Pan 2.1", false, 0)
if fx >= 0 then reaper.TrackFX_SetEnabled( track, fx, enable ) end
end
]]--
-------------SET ITEMS
function AddMonoCenter()
for i=0, reaper.CountMediaItems(0)-1 do
local take = reaper.GetActiveTake(reaper.GetMediaItem(0,i))
local source = reaper.GetMediaItemTake_Source(take)
local totalchan = reaper.GetMediaSourceNumChannels( source )
local chanmode = reaper.GetMediaItemTakeInfo_Value(take, "I_CHANMODE")
if totalchan == 1 or (chanmode > 1 and chanmode < 67 ) then
local fx reaper.TakeFX_AddByName( take, "TJF Mono to Channel 3 (Center)", 1)
end
end
end--AddMonoCenter()
function RemoveMonoCenter()
for i=0, reaper.CountMediaItems(0)-1 do
local take = reaper.GetActiveTake(reaper.GetMediaItem(0,i))
local fx = reaper.TakeFX_AddByName( take, "TJF Mono to Channel 3 (Center)", 0)
if fx >= 0 then reaper.TakeFX_Delete( take, fx ) end
end
end--RemoveMonoCenter()
function Main()
local state = reaper.GetToggleCommandStateEx(0,reaper.NamedCommandLookup("_RS01195a2f4fa80dd3dea539db37f9d0729d14c07a"))
if state == 1 then AddMonoCenter()
else RemoveMonoCenter()
end
end--Main()
reaper.Undo_BeginBlock()
Main()
reaper.UpdateArrange()
--reaper.SetToggleCommandState( 0, cmd_id, state)
--reaper.RefreshToolbar2(0, cmd_id)
reaper.Undo_EndBlock("TJF Surround Toggle",0)