@@ -102,9 +102,9 @@ local function updateCurrentPatternIndex()
102102 end
103103end
104104
105- local function updateCursor (item , stepIndex )
105+ local function updateCursor (currentItem , nextItem )
106106 if followCursor then
107- jumpToStep ( item , stepIndex )
107+ jumpToItem ( currentItem , nextItem )
108108 end
109109end
110110
@@ -219,19 +219,9 @@ local function loop()
219219 changedPattern , currentPatternIndex = drawSlider (ctx , ' ##Pattern' , currentPatternIndex , 1 , patternCount , 140 )
220220 reaper .ImGui_SameLine (ctx )
221221
222- local y = reaper .ImGui_GetCursorPosY (ctx )
223- reaper .ImGui_SetCursorPosY (ctx , y + 1 )
224- reaper .ImGui_PushStyleVar (ctx , reaper .ImGui_StyleVar_FramePadding (), 5 , 2 )
225- removedPattern = reaper .ImGui_Button (ctx , " -" )
226- reaper .ImGui_PopStyleVar (ctx )
227- reaper .ImGui_SameLine (ctx )
228-
229- local y = reaper .ImGui_GetCursorPosY (ctx )
230- reaper .ImGui_SetCursorPosY (ctx , y + 1 )
231- reaper .ImGui_PushStyleVar (ctx , reaper .ImGui_StyleVar_FramePadding (), 4 , 2 )
232- addedPattern = reaper .ImGui_Button (ctx , " +" )
233- reaper .ImGui_PopStyleVar (ctx )
234- reaper .ImGui_SameLine (ctx )
222+ local removePattern = drawButton (ctx , " -" )
223+ local addPattern = drawButton (ctx , " +" )
224+ local dupPattern = drawButton (ctx , " ++" )
235225
236226 reaper .ImGui_Text (ctx , ' Steps:' )
237227 reaper .ImGui_SameLine (ctx )
@@ -276,19 +266,21 @@ local function loop()
276266 updateTimeSelection ()
277267 end
278268 -- Delete pattern
279- elseif removedPattern then
269+ elseif removePattern then
280270 removeItem (currentPattern .item )
281271 updateCurrentPatternIndex ()
282- currentPattern = getPattern (sequencerTrack , currentPatternIndex - 1 )
283- if currentPattern then
284- updateCursor (currentPattern .item , 0 )
285- end
286272 updateTimeSelection ()
287273 -- Add pattern
288- elseif addedPattern then
274+ elseif addPattern then
289275 newItem = createItem (sequencerTrack , currentPattern .steps > 0 and currentPattern .steps or 16 )
276+ updateCursor (currentPattern .item , newItem )
277+ currentPatternIndex = patternCount + 1
278+ updateTimeSelection ()
279+ elseif dupPattern then
280+ newItem = createItem (sequencerTrack , currentPattern .steps )
281+ copyMidiContent (currentPattern .item , newItem )
282+ updateCursor (currentPattern .item , newItem )
290283 currentPatternIndex = patternCount + 1
291- updateCursor (newItem , 0 )
292284 updateTimeSelection ()
293285 -- Resize pattern
294286 elseif changedSteps or changedTimes then
@@ -304,8 +296,8 @@ local function loop()
304296 updateTimeSelection ()
305297 reaper .Undo_EndBlock (' Resize pattern' ,- 1 )
306298 elseif changedPattern then
307- currentPattern = getPattern (sequencerTrack , currentPatternIndex - 1 )
308- updateCursor (currentPattern .item , 0 )
299+ nextPattern = getPattern (sequencerTrack , currentPatternIndex - 1 )
300+ updateCursor (currentPattern .item , nextPattern . item )
309301 updateTimeSelection ()
310302 end
311303 else -- if currentPattern
0 commit comments