MCPcopy Index your code
hub / github.com/stemdeckapp/stemdeck / wireLoopDrag

Function wireLoopDrag

static/js/transport.js:260–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

258// region. Drag direction doesn't matter -- start and end get sorted.
259// Tiny drags are treated as clicks and seek the playhead instead.
260function wireLoopDrag() {
261 let dragging = false;
262 let dragStartTime = 0;
263 let activePointerId = null;
264 let moved = false;
265
266 const startDrag = (e, surface) => {
267 if (e.button !== 0 || e.target.closest(".loop-region")) return;
268 const t = timeFromClientX(e.clientX);
269 if (t === null) return;
270 dragging = true;
271 activePointerId = e.pointerId;
272 moved = false;
273 dragStartTime = t;
274 setLoopStart(t);
275 setLoopEnd(t);
276 setLoopEnabled(true);
277 loopBtn.classList.add("active");
278 updateLoopRegionVisual();
279 surface.setPointerCapture(e.pointerId);
280 e.preventDefault();
281 };
282
283 const moveDrag = (e) => {
284 if (!dragging || e.pointerId !== activePointerId) return;
285 const t = timeFromClientX(e.clientX);
286 if (t === null) return;
287 if (Math.abs(t - dragStartTime) >= MIN_LOOP_SEC) moved = true;
288 if (t < dragStartTime) {
289 setLoopStart(t);
290 setLoopEnd(dragStartTime);
291 } else {
292 setLoopStart(dragStartTime);
293 setLoopEnd(t);
294 }
295 updateLoopRegionVisual();
296 };
297
298 const finishDrag = (e) => {
299 if (!dragging || e.pointerId !== activePointerId) return;
300 dragging = false;
301 activePointerId = null;
302 const clicked = !moved || loopEnd - loopStart < MIN_LOOP_SEC;
303 if (clicked) {
304 setLoopEnabled(false);
305 loopBtn.classList.remove("active");
306 updateLoopRegionVisual();
307 setPlayheadTime(dragStartTime);
308 }
309 };
310
311 const wavesColumn = document.querySelector(".waves-column");
312 const surfaces = [rulerTime, wavesColumn].filter(Boolean);
313 for (const surface of surfaces) {
314 surface.addEventListener("pointerdown", (e) => {
315 if (surface === rulerTime && e.target !== rulerTime) return;
316 startDrag(e, surface);
317 });

Callers 1

wireTransportButtonsFunction · 0.85

Calls 1

startDragFunction · 0.70

Tested by

no test coverage detected