Skip to content

Commit d64eb02

Browse files
author
eritiro
committed
Change sequencer default track
1 parent 0aa9ae3 commit d64eb02

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

Modules/GUI.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,16 @@ function SameLineAutoWrap(ctx, widgetWidth, spacing)
100100
reaper.ImGui_NewLine(ctx)
101101
end
102102
reaper.ImGui_SameLine(ctx, spacing)
103-
end
103+
end
104+
105+
function drawTrackLabel(ctx, sprite, text)
106+
reaper.ImGui_Image(ctx, sprite.i, sprite.w, sprite.h)
107+
108+
local minX,minY = reaper.ImGui_GetItemRectMin(ctx)
109+
local maxX,maxY = reaper.ImGui_GetItemRectMax(ctx)
110+
local tw,th = reaper.ImGui_CalcTextSize(ctx, text)
111+
local cx = (minX + maxX - tw) * 0.5
112+
local cy = (minY + maxY - th) * 0.5
113+
local dl = reaper.ImGui_GetWindowDrawList(ctx)
114+
reaper.ImGui_DrawList_AddText(dl, cx, cy, 0xFFFFFFFF, text)
115+
end

Modules/MIDI.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
1-
function getDrumbruteTrack()
1+
function getSequencerTrack()
22
local track
33
for i = 0, reaper.CountTracks(0) - 1 do
44
local t = reaper.GetTrack(0, i)
55
local _, name = reaper.GetTrackName(t, "")
6-
if name == "MIDI-Drumbrute" then track = t break end
6+
if name == "Sequencer" then track = t break end
77
end
88
if not track then -- create it if missing
99
local idx = reaper.CountTracks(0)
1010
reaper.InsertTrackAtIndex(idx, true)
1111
track = reaper.GetTrack(0, idx)
12-
reaper.GetSetMediaTrackInfo_String(track, "P_NAME", "MIDI-Drumbrute", true)
12+
reaper.GetSetMediaTrackInfo_String(track, "P_NAME", "Sequencer", true)
1313
end
1414
return track
1515
end
1616

17-
function createPattern(steps)
18-
local tr = getDrumbruteTrack()
17+
function createPattern(track, steps)
1918
local beatsInSec = reaper.TimeMap2_beatsToTime(0, 1)
2019
local itemLength = (steps / time_resolution) * beatsInSec
2120

2221
-- place new pattern right after the last item (or at 0.0 if none)
2322
local lastPos = 0
24-
for i = 0, reaper.CountTrackMediaItems(tr) - 1 do
25-
local it = reaper.GetTrackMediaItem(tr, i)
23+
for i = 0, reaper.CountTrackMediaItems(track) - 1 do
24+
local it = reaper.GetTrackMediaItem(track, i)
2625
local pos = reaper.GetMediaItemInfo_Value(it, "D_POSITION")
2726
local len = reaper.GetMediaItemInfo_Value(it, "D_LENGTH")
2827
if pos + len > lastPos then lastPos = pos + len end
2928
end
3029

31-
local newItem = reaper.CreateNewMIDIItemInProj(tr, lastPos, lastPos + itemLength, false)
30+
local newItem = reaper.CreateNewMIDIItemInProj(track, lastPos, lastPos + itemLength, false)
3231

3332
local take = reaper.GetMediaItemTake(newItem, 0)
34-
local patNum = reaper.CountTrackMediaItems(tr) -- simple increment
33+
local patNum = reaper.CountTrackMediaItems(track) -- simple increment
3534
reaper.GetSetMediaItemTakeInfo_String(take, "P_NAME", "Pattern " .. patNum, true)
3635

3736
reaper.UpdateArrange()

brute-seq.lua

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ local function loop()
9595
reaper.ImGui_PushFont(ctx,font)
9696
reaper.ImGui_PushStyleColor(ctx,reaper.ImGui_Col_WindowBg(),0x222222FF)
9797

98-
local drumTrack = getDrumbruteTrack()
99-
local patternCount = reaper.CountTrackMediaItems(drumTrack)
98+
local sequencerTrack = getSequencerTrack()
99+
local patternCount = reaper.CountTrackMediaItems(sequencerTrack)
100100

101101
currentPatternIndex = math.min(currentPatternIndex or 1, patternCount);
102-
local currentPattern = getPattern(drumTrack, currentPatternIndex - 1)
102+
local currentPattern = getPattern(sequencerTrack, currentPatternIndex - 1)
103103

104104
if currentPattern then
105105
-- top bar
@@ -158,7 +158,7 @@ local function loop()
158158
end
159159

160160
if addedPattern then
161-
createPattern(currentPattern.steps > 0 and currentPattern.steps or 16)
161+
createPattern(sequencerTrack, currentPattern.steps > 0 and currentPattern.steps or 16)
162162
changedPattern = true
163163
if followCursor then
164164
currentPatternIndex = patternCount + 1
@@ -167,7 +167,7 @@ local function loop()
167167

168168
-- Jump to step
169169
if changedPattern and followCursor then
170-
currentPattern = getPattern(drumTrack, currentPatternIndex - 1)
170+
currentPattern = getPattern(sequencerTrack, currentPatternIndex - 1)
171171
jumpToStep(currentPattern.item, 0)
172172
end
173173

@@ -180,26 +180,26 @@ local function loop()
180180
end
181181
resizeItem(currentPattern.item, currentPattern.times)
182182
if ripple then
183-
rippleFollowingItems(drumTrack, currentPattern.item, originalLength)
183+
rippleFollowingItems(sequencerTrack, currentPattern.item, originalLength)
184184
end
185185
reaper.Undo_EndBlock('Resize pattern',-1)
186186
end
187187

188188
-- Change time selection
189189
if changedPattern or changedLoopPatternOption or changedLoopSongOption or changedSteps or changedTimes then
190-
currentPattern = getPattern(drumTrack, currentPatternIndex - 1)
190+
currentPattern = getPattern(sequencerTrack, currentPatternIndex - 1)
191191
if loopPattern then
192192
setTimeSelectionFromItem(currentPattern.item)
193193
elseif loopSong then
194-
setTimeSelectionFromTrack(drumTrack)
194+
setTimeSelectionFromTrack(sequencerTrack)
195195
end
196196
end
197197

198198
-- Follow cursor
199-
local itemIndexAtCursor = getItemIndexAtCursor(drumTrack)
199+
local itemIndexAtCursor = getItemIndexAtCursor(sequencerTrack)
200200
if followCursor and itemIndexAtCursor and itemIndexAtCursor ~= currentPatternIndex - 1 then
201201
currentPatternIndex = itemIndexAtCursor + 1
202-
currentPattern = getPattern(drumTrack, currentPatternIndex - 1)
202+
currentPattern = getPattern(sequencerTrack, currentPatternIndex - 1)
203203
end
204204

205205
reaper.ImGui_Separator(ctx)
@@ -211,7 +211,7 @@ local function loop()
211211

212212
reaper.ImGui_PushStyleVar(ctx, reaper.ImGui_StyleVar_ItemSpacing(), 2, 2) -- (x,y)
213213

214-
reaper.ImGui_Image(ctx, images.Channel_button_on.i, images.Channel_button_on.w, images.Channel_button_on.h)
214+
drawTrackLabel(ctx, images.Channel_button_on, "Sequencer")
215215
for s=1, currentPattern.steps do
216216
reaper.ImGui_SameLine(ctx)
217217
local isCurrent = currentStep and s == currentStep
@@ -243,15 +243,7 @@ local function loop()
243243
local sprite = selected and images.Channel_button_on
244244
or images.Channel_button_off
245245

246-
reaper.ImGui_Image(ctx, sprite.i, sprite.w, sprite.h)
247-
248-
local minX,minY = reaper.ImGui_GetItemRectMin(ctx)
249-
local maxX,maxY = reaper.ImGui_GetItemRectMax(ctx)
250-
local tw,th = reaper.ImGui_CalcTextSize(ctx, trk.name)
251-
local cx = (minX + maxX - tw) * 0.5
252-
local cy = (minY + maxY - th) * 0.5
253-
local dl = reaper.ImGui_GetWindowDrawList(ctx)
254-
reaper.ImGui_DrawList_AddText(dl, cx, cy, 0xFFFFFFFF, trk.name)
246+
drawTrackLabel(ctx, sprite, trk.name)
255247
reaper.ImGui_SameLine(ctx)
256248

257249
for s=1, currentPattern.steps do
@@ -288,7 +280,7 @@ local function loop()
288280
reaper.ImGui_Text(ctx, "Add a pattern to start")
289281
reaper.ImGui_SameLine(ctx)
290282
if reaper.ImGui_Button(ctx, "Add Pattern") then
291-
createPattern(16)
283+
createPattern(sequencerTrack, 16)
292284
currentPatternIndex = 1
293285
end
294286
end

0 commit comments

Comments
 (0)