-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathMoveEditCursorToNextCut.lua
More file actions
134 lines (96 loc) · 4.04 KB
/
MoveEditCursorToNextCut.lua
File metadata and controls
134 lines (96 loc) · 4.04 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
-- @noindex
-- Global Variables --
cursorPos = reaper.GetCursorPosition(0);
currentTrack = reaper.GetSelectedTrack(0,0);
i = 0;
t = 0;
iMax = reaper.CountTrackMediaItems(currentTrack);
iLast = iMax - 1;
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToStartOfFirstItem()
reaper.SetEditCurPos(firstItemStart, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToStartOfItem()
reaper.SetEditCurPos(nextItemStart, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToEndOfItem()
reaper.SetEditCurPos(iEnd, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToEndOfLastItem()
reaper.SetEditCurPos(lastItemEnd, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function SelectNextItem()
reaper.SetMediaItemSelected(nextItem, 1);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function SelectFirstItem()
reaper.SetMediaItemSelected(firstItem, 1);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function UnselectAllItems()
reaper.SelectAllMediaItems(0,0);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveEditCursorToNextCut()
if iMax == 0
then return
end
for i = 0, iMax do
firstItem = reaper.GetTrackMediaItem(currentTrack,0)
firstItemStart = reaper.GetMediaItemInfo_Value(firstItem, "D_POSITION")
if cursorPos < firstItemStart
then
MoveCursorToStartOfFirstItem()
SelectFirstItem()
else
currentItem = reaper.GetTrackMediaItem(currentTrack,i);
iStart = reaper.GetMediaItemInfo_Value(currentItem,"D_POSITION");
iLength = reaper.GetMediaItemInfo_Value(currentItem,"D_LENGTH");
iEnd = iStart + iLength;
n = i + 1;
nextItem = reaper.GetTrackMediaItem(currentTrack,n);
if n ~= iMax
then nextItemStart = reaper.GetMediaItemInfo_Value(nextItem,"D_POSITION");
end
lastItem = reaper.GetTrackMediaItem(currentTrack,iLast);
lastItemStart = reaper.GetMediaItemInfo_Value(lastItem,"D_POSITION");
lastItemLength = reaper.GetMediaItemInfo_Value(lastItem,"D_LENGTH");
lastItemEnd = lastItemStart + lastItemLength;
if cursorPos >= iStart and cursorPos < iEnd
then
if nextItemStart == iEnd
then
UnselectAllItems();
SelectNextItem();
MoveCursorToEndOfItem();
break
else
MoveCursorToEndOfItem();
break
end
end
if iMax > 1
then
if cursorPos < nextItemStart and cursorPos >= iEnd
then
UnselectAllItems();
SelectNextItem();
MoveCursorToStartOfItem();
SelectNextItem();
break
end
else return
end
if cursorPos >= lastItemEnd
then break
end
end
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------
-- Action --
MoveEditCursorToNextCut();