-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathMoveEditCursorToPreviousCut.lua
More file actions
134 lines (98 loc) · 4.5 KB
/
MoveEditCursorToPreviousCut.lua
File metadata and controls
134 lines (98 loc) · 4.5 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
-- @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(iStart, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToEndOfPreviousItem()
reaper.SetEditCurPos(previousItemEnd, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function MoveCursorToEndOfLastItem()
reaper.SetEditCurPos(lastItemEnd, moveview == true, seekplay == true)
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function SelectPreviousItem()
reaper.SetMediaItemSelected(previousItem, 1);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function SelectLastItem()
reaper.SetMediaItemSelected(lastItem, 1);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
function UnselectAllItems()
reaper.SelectAllMediaItems(0,0);
end
----------------------------------------------------------------------------------------------------------------------------------------------------
-- Main Function --
function MoveEditCursorToNextCut()
if iMax == 0
then return
end
for i = 0, iLast do
firstItem = reaper.GetTrackMediaItem(currentTrack,0)
firstItemStart = reaper.GetMediaItemInfo_Value(firstItem, "D_POSITION")
if cursorPos <= firstItemStart
then break
else if cursorPos > firstItemStart
then
currentItem = reaper.GetTrackMediaItem(currentTrack,i);
iStart = reaper.GetMediaItemInfo_Value(currentItem,"D_POSITION");
iLength = reaper.GetMediaItemInfo_Value(currentItem,"D_LENGTH");
iEnd = iStart + iLength;
p = i-1;
previousItem = reaper.GetTrackMediaItem(currentTrack,p);
if p ~= -1
then
previousItemStart = reaper.GetMediaItemInfo_Value(previousItem,"D_POSITION");
previousItemLength = reaper.GetMediaItemInfo_Value(previousItem,"D_LENGTH");
previousItemEnd = previousItemStart + previousItemLength;
else previousItem = firstItem;
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 iStart == previousItemEnd
then
UnselectAllItems();
SelectPreviousItem();
MoveCursorToStartOfItem();
break
else
MoveCursorToStartOfItem();
break
end
end
if cursorPos <= iStart and cursorPos > previousItemEnd
then
UnselectAllItems();
SelectPreviousItem();
MoveCursorToEndOfPreviousItem();
break
end
if cursorPos > lastItemEnd
then
MoveCursorToEndOfLastItem()
SelectLastItem()
end
end
end
end
end
----------------------------------------------------------------------------------------------------------------------------------------------------
-- Action --
MoveEditCursorToNextCut();