Function bodies 32 total
paint function · javascript · L97-L167 (71 LOC)AutoClean.js
function paint() {
var g = mgraphics;
g.set_line_width(1.0);
// Background
setColor(g, PAL.bg);
g.rectangle(0, 0, W, H);
g.fill();
// Master "All" toggle (top-left)
drawCheckbox(g, allBox.x, allBox.y, allBox.w, allBox.h, allSelected());
setColor(g, PAL.textSec);
g.select_font_face("Arial");
g.set_font_size(10);
g.move_to(allBox.x + allBox.w + 6, allBox.y + allBox.h);
g.text_path("Select all");
g.fill();
// Section headers (gold, uppercase, with underline bar)
g.select_font_face("Arial Bold");
g.set_font_size(9);
for (var k = 0; k < sections.length; k++) {
var sec = sections[k];
setColor(g, PAL.accent);
g.move_to(sec.x, sec.y);
g.text_path(sec.label);
g.fill();
setColor(g, PAL.divider);
g.rectangle(sec.x, sec.y + 3, 100, 1);
g.fill();
}
// Checkboxes + labels
g.select_font_face("Arial");
g.set_font_size(10);
for (var i = 0; i < cdrawCheckbox function · javascript · L169-L181 (13 LOC)AutoClean.js
function drawCheckbox(g, x, y, w, h, checked) {
setColor(g, PAL.boxBg);
g.rectangle(x, y, w, h);
g.fill();
setColor(g, checked ? PAL.accent : PAL.boxBorder);
g.rectangle(x, y, w, h);
g.stroke();
if (checked) {
setColor(g, PAL.accent);
g.rectangle(x + 2, y + 2, w - 4, h - 4);
g.fill();
}
}drawRoundedRect function · javascript · L183-L194 (12 LOC)AutoClean.js
function drawRoundedRect(g, x, y, w, h, r) {
g.move_to(x + r, y);
g.line_to(x + w - r, y);
g.curve_to(x + w, y, x + w, y, x + w, y + r);
g.line_to(x + w, y + h - r);
g.curve_to(x + w, y + h, x + w, y + h, x + w - r, y + h);
g.line_to(x + r, y + h);
g.curve_to(x, y + h, x, y + h, x, y + h - r);
g.line_to(x, y + r);
g.curve_to(x, y, x, y, x + r, y);
g.close_path();
}allSelected function · javascript · L196-L201 (6 LOC)AutoClean.js
function allSelected() {
for (var i = 0; i < cbs.length; i++) {
if (!opts[cbs[i].key]) return false;
}
return true;
}setAll function · javascript · L203-L205 (3 LOC)AutoClean.js
function setAll(v) {
for (var i = 0; i < cbs.length; i++) opts[cbs[i].key] = v;
}onclick function · javascript · L209-L242 (34 LOC)AutoClean.js
function onclick(x, y, but, cmd, shift, capslock, option, ctrl) {
if (isRunning) return;
// Master "All" toggle
if (x >= allBox.x && x <= allBox.x + 80 &&
y >= allBox.y - 2 && y <= allBox.y + allBox.h + 2) {
setAll(!allSelected());
mgraphics.redraw();
return;
}
// Individual checkboxes (row hit: from checkbox to ~110px right)
for (var i = 0; i < cbs.length; i++) {
var cb = cbs[i];
if (x >= cb.x && x <= cb.x + 110 && y >= cb.y - 1 && y <= cb.y + cb.h + 1) {
opts[cb.key] = !opts[cb.key];
mgraphics.redraw();
return;
}
}
if (x >= btnRect.x && x <= btnRect.x + btnRect.w &&
y >= btnRect.y && y <= btnRect.y + btnRect.h) {
post("[AutoClean] CLEAN pressed\n");
try {
runClean();
} catch (e) {
post("[AutoClean] ERROR: " + e.message + "\n");
statusMsg = "Error — see Max console";
isRunning = fahoverIndex function · javascript · L248-L258 (11 LOC)AutoClean.js
function hoverIndex(x, y) {
if (x >= allBox.x && x <= allBox.x + 80 &&
y >= allBox.y - 2 && y <= allBox.y + allBox.h + 2) return -10;
if (x >= btnRect.x && x <= btnRect.x + btnRect.w &&
y >= btnRect.y && y <= btnRect.y + btnRect.h) return -20;
for (var i = 0; i < cbs.length; i++) {
var cb = cbs[i];
if (x >= cb.x && x <= cb.x + 110 && y >= cb.y - 1 && y <= cb.y + cb.h + 1) return i;
}
return -1;
}Repobility (the analyzer behind this table) · https://repobility.com
onidle function · javascript · L260-L269 (10 LOC)AutoClean.js
function onidle(x, y) {
var idx = hoverIndex(x, y);
if (idx === lastHoverIdx) return;
lastHoverIdx = idx;
hoverMsg = (idx === -10) ? ALL_TIP
: (idx === -20) ? CLEAN_TIP
: (idx >= 0) ? cbs[idx].tip
: "";
mgraphics.redraw();
}onidleout function · javascript · L271-L276 (6 LOC)AutoClean.js
function onidleout() {
if (lastHoverIdx === -99 && !hoverMsg) return;
lastHoverIdx = -99;
hoverMsg = "";
mgraphics.redraw();
}bang function · javascript · L279-L284 (6 LOC)AutoClean.js
function bang() {
if (!isRunning) {
try { runClean(); }
catch (e) { post("[AutoClean] ERROR: " + e.message + "\n"); isRunning = false; }
}
}addLog function · javascript · L288-L293 (6 LOC)AutoClean.js
function addLog(msg) {
if (!msg || msg.length === 0) return;
statusMsg = msg;
post("[AutoClean] " + msg + "\n");
mgraphics.redraw();
}runClean function · javascript · L297-L329 (33 LOC)AutoClean.js
function runClean() {
isRunning = true;
mgraphics.redraw();
addLog("Started...");
var liveSet = new LiveAPI("live_set");
var trackCount = liveSet.getcount("tracks");
if (trackCount === 0) {
addLog("No tracks found.");
isRunning = false;
mgraphics.redraw();
return;
}
addLog("Tracks: " + trackCount);
addLog("");
safePhase("clips", opts.deleteClips, function(){ deleteDisabledClips(liveSet, trackCount); });
safePhase("empty", opts.deleteEmptyClips, function(){ deleteEmptyClips(liveSet, trackCount); });
safePhase("bypassed", opts.deleteBypassed, function(){ deleteBypassedDevices(liveSet, trackCount); });
safePhase("recolor", opts.recolorGroupChildren, function(){ recolorGroupChildren(liveSet, trackCount); });
safePhase("clip-color", opts.recolorGroupClips, function(){ recolorGroupClips(liveSet, trackCount); });
// Re-query track count — previous phasegetInt function · javascript · L333-L336 (4 LOC)AutoClean.js
function getInt(api, prop) {
var v = api.get(prop);
return (v === null || v === undefined) ? 0 : parseInt(v);
}getStr function · javascript · L338-L341 (4 LOC)AutoClean.js
function getStr(api, prop) {
var v = api.get(prop);
return (v === null || v === undefined) ? "" : String(v);
}isNormalTrack function · javascript · L343-L345 (3 LOC)AutoClean.js
function isNormalTrack(track) {
return getInt(track, "has_audio_input") === 1 || getInt(track, "has_midi_input") === 1;
}Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
safePhase function · javascript · L347-L354 (8 LOC)AutoClean.js
function safePhase(name, enabled, fn) {
if (!enabled) return;
try { fn(); }
catch (e) {
post("[AutoClean] phase '" + name + "' failed: " + e.message + "\n");
addLog("Phase " + name + " skipped (error)");
}
}deleteDisabledClips function · javascript · L358-L390 (33 LOC)AutoClean.js
function deleteDisabledClips(liveSet, trackCount) {
addLog("[Clips] Scanning...");
var deleted = 0;
for (var t = 0; t < trackCount; t++) {
var track = new LiveAPI("live_set tracks " + t);
if (!isNormalTrack(track)) continue;
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI("live_set tracks " + t + " clip_slots " + s);
if (getInt(slot, "has_clip") === 1) {
var clip = new LiveAPI("live_set tracks " + t + " clip_slots " + s + " clip");
if (getInt(clip, "muted") === 1) {
try { slot.call("delete_clip"); deleted++; } catch(e) {}
}
}
}
// Arrangement clips (iterate reverse — deletions shift indices)
var arrCount = track.getcount("arrangement_clips");
for (var a = arrCount - 1; a >= 0; a--) {
var ac = new LiveAPI("live_set tracks " + t + " arrandeleteBypassedDevices function · javascript · L394-L411 (18 LOC)AutoClean.js
function deleteBypassedDevices(liveSet, trackCount) {
addLog("Bypassed: scanning");
var deleted = 0;
// Regular tracks
for (var t = 0; t < trackCount; t++) {
deleted += scanTrackForBypassed("live_set tracks " + t, t);
}
// Return tracks
var retCount = parseInt(liveSet.getcount("return_tracks"));
for (var r = 0; r < retCount; r++) {
deleted += scanTrackForBypassed("live_set return_tracks " + r, -1);
}
// Master track
deleted += scanTrackForBypassed("live_set master_track", -1);
addLog("Bypassed: " + deleted + " deleted");
}scanTrackForBypassed function · javascript · L413-L432 (20 LOC)AutoClean.js
function scanTrackForBypassed(trackPath, tIndex) {
var removed = 0;
var track = new LiveAPI(trackPath);
if (!track || parseInt(track.id) === 0) return 0;
var devCount = track.getcount("devices");
for (var d = devCount - 1; d >= 0; d--) {
try {
var dev = new LiveAPI(trackPath + " devices " + d);
if (getInt(dev, "is_active") !== 0) continue;
// Skip our own AutoClean device — never delete self
var devName = getStr(dev, "name");
if (devName && devName.indexOf("AutoClean") >= 0) continue;
if (hasOnOffAutomationPath(track, trackPath, d)) continue;
track.call("delete_device", d);
removed++;
} catch (e) { /* skip */ }
}
return removed;
}hasOnOffAutomationPath function · javascript · L434-L455 (22 LOC)AutoClean.js
function hasOnOffAutomationPath(track, trackPath, d) {
var param = new LiveAPI(trackPath + " devices " + d + " parameters 0");
if (!param || parseInt(param.id) === 0) return false;
var paramId = parseInt(param.id);
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI(trackPath + " clip_slots " + s);
if (getInt(slot, "has_clip") === 1) {
var clip = new LiveAPI(trackPath + " clip_slots " + s + " clip");
var res = clip.call("get_automation_envelope", paramId);
if (res && res.length > 0 && parseInt(res[0]) !== 0) return true;
}
}
var arrCount = track.getcount("arrangement_clips");
for (var a = 0; a < arrCount; a++) {
var ac = new LiveAPI(trackPath + " arrangement_clips " + a);
var res2 = ac.call("get_automation_envelope", paramId);
if (res2 && res2.length > 0 && parseInt(res2[0]) !== 0) return true;
}
return fahasOnOffAutomation function · javascript · L457-L482 (26 LOC)AutoClean.js
function hasOnOffAutomation(track, t, d) {
var param = new LiveAPI("live_set tracks " + t + " devices " + d + " parameters 0");
if (!param || parseInt(param.id) === 0) return false;
var paramId = parseInt(param.id);
// Check session clips
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI("live_set tracks " + t + " clip_slots " + s);
if (getInt(slot, "has_clip") === 1) {
var clip = new LiveAPI("live_set tracks " + t + " clip_slots " + s + " clip");
var res = clip.call("get_automation_envelope", paramId);
if (res && res.length > 0 && parseInt(res[0]) !== 0) return true;
}
}
// Check arrangement clips
var arrCount = track.getcount("arrangement_clips");
for (var a = 0; a < arrCount; a++) {
var ac = new LiveAPI("live_set tracks " + t + " arrangement_clips " + a);
var res2 = ac.call("get_automation_envelope", paramIddeleteMutedTracks function · javascript · L486-L502 (17 LOC)AutoClean.js
function deleteMutedTracks(liveSet, trackCount) {
addLog("Muted tracks: scanning");
var deleted = 0;
for (var t = trackCount - 1; t >= 0; t--) {
try {
var track = new LiveAPI("live_set tracks " + t);
if (!isNormalTrack(track)) continue;
if (getInt(track, "is_foldable") === 1) continue;
if (getInt(track, "mute") !== 1) continue;
liveSet.call("delete_track", t);
deleted++;
} catch (e) { /* skip */ }
}
addLog("Muted tracks: " + deleted + " deleted");
}deleteUnusedTracks function · javascript · L504-L528 (25 LOC)AutoClean.js
function deleteUnusedTracks(liveSet, trackCount) {
addLog("Unused tracks: scanning");
var deleted = 0;
// Build set of routing targets (names that other tracks output to)
var routingTargets = collectRoutingTargets(liveSet, trackCount);
for (var t = trackCount - 1; t >= 0; t--) {
try {
var track = new LiveAPI("live_set tracks " + t);
if (!isNormalTrack(track)) continue;
if (getInt(track, "is_foldable") === 1) continue;
if (trackHasClips(track, t)) continue;
var name = getStr(track, "name");
if (routingTargets[name]) continue; // something routes into this track
liveSet.call("delete_track", t);
deleted++;
} catch (e) { /* skip */ }
}
addLog("Unused tracks: " + deleted + " deleted");
}Repobility's GitHub App fixes findings like these · https://github.com/apps/repobility-bot
trackHasClips function · javascript · L530-L538 (9 LOC)AutoClean.js
function trackHasClips(track, t) {
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI("live_set tracks " + t + " clip_slots " + s);
if (getInt(slot, "has_clip") === 1) return true;
}
if (track.getcount("arrangement_clips") > 0) return true;
return false;
}collectRoutingTargets function · javascript · L540-L565 (26 LOC)AutoClean.js
function collectRoutingTargets(liveSet, trackCount) {
var targets = {};
var record = function(api) {
try {
var ort = api.get("output_routing_type");
if (!ort) return;
var s = (typeof ort === "string") ? ort : JSON.stringify(ort);
// Extract display_name values from the routing type dict.
var re = /"display_name"\s*:\s*"([^"]+)"/g;
var m;
while ((m = re.exec(s)) !== null) {
targets[m[1]] = true;
}
} catch (e) { /* ignore */ }
};
for (var t = 0; t < trackCount; t++) {
record(new LiveAPI("live_set tracks " + t));
}
var retCount = parseInt(liveSet.getcount("return_tracks"));
for (var r = 0; r < retCount; r++) {
record(new LiveAPI("live_set return_tracks " + r));
}
return targets;
}deleteEmptyClips function · javascript · L569-L607 (39 LOC)AutoClean.js
function deleteEmptyClips(liveSet, trackCount) {
addLog("Empty clips: scanning");
var deleted = 0;
for (var t = 0; t < trackCount; t++) {
var track = new LiveAPI("live_set tracks " + t);
if (!isNormalTrack(track)) continue;
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI("live_set tracks " + t + " clip_slots " + s);
if (getInt(slot, "has_clip") !== 1) continue;
var clip = new LiveAPI("live_set tracks " + t + " clip_slots " + s + " clip");
try {
if (clipIsEmpty(clip)) {
slot.call("delete_clip");
deleted++;
}
} catch (e) { /* skip this clip */ }
}
// Arrangement clips
var arrCount = track.getcount("arrangement_clips");
for (var a = arrCount - 1; a >= 0; a--) {
var ac = new LiveAPI("live_set tracks " + t + " arclipIsEmpty function · javascript · L609-L626 (18 LOC)AutoClean.js
function clipIsEmpty(clip) {
var len = parseFloat(clip.get("length"));
if (isNaN(len) || len <= 0) return true;
var isMidi = getInt(clip, "is_midi_clip") === 1;
if (isMidi) {
try {
var notes = clip.call("get_notes_extended", 0, 128, 0, len);
if (notes === null || notes === undefined) return false;
var s = (typeof notes === "string") ? notes : String(notes);
// Empty if notes array is empty OR no pitch entries exist.
if (/"notes"\s*:\s*\[\s*\]/.test(s)) return true;
if (s.indexOf("\"pitch\"") < 0) return true;
return false;
} catch (e) { return false; }
}
return false;
}deleteEmptyOrMutedGroups function · javascript · L630-L656 (27 LOC)AutoClean.js
function deleteEmptyOrMutedGroups(liveSet, trackCount) {
addLog("Groups: scanning");
var deleted = 0;
// Iterate reverse — deleting a group removes its children too, shifting indices.
for (var t = trackCount - 1; t >= 0; t--) {
try {
var track = new LiveAPI("live_set tracks " + t);
if (getInt(track, "is_foldable") !== 1) continue;
// Case 1: group itself is muted
if (getInt(track, "mute") === 1) {
liveSet.call("delete_track", t);
deleted++;
continue;
}
// Case 2: all children inside the group are muted or empty
if (groupChildrenAllEmpty(liveSet, t)) {
liveSet.call("delete_track", t);
deleted++;
}
} catch (e) { /* skip */ }
}
addLog("Groups: " + deleted + " deleted");
}groupChildrenAllEmpty function · javascript · L658-L686 (29 LOC)AutoClean.js
function groupChildrenAllEmpty(liveSet, groupIndex) {
var groupTrack = new LiveAPI("live_set tracks " + groupIndex);
var groupId = parseInt(groupTrack.id);
var trackCount = parseInt(liveSet.getcount("tracks"));
var foundChild = false;
// Children are consecutive tracks after the group whose group_track matches.
for (var t = groupIndex + 1; t < trackCount; t++) {
var child = new LiveAPI("live_set tracks " + t);
// Stop when we leave this group (hit another group or a track with a different parent).
var parentId = parseGroupId(child.get("group_track"));
if (parentId !== groupId) break;
// Skip nested sub-groups — only inspect leaf tracks.
if (getInt(child, "is_foldable") === 1) continue;
foundChild = true;
// If the child is muted, it counts as "empty" for our purposes.
if (getInt(child, "mute") === 1) continue;
// If the child has any clips it is NOT empty.
if (trackHrecolorGroupClips function · javascript · L690-L725 (36 LOC)AutoClean.js
function recolorGroupClips(liveSet, trackCount) {
addLog("Clip color: scanning");
var recolored = 0;
for (var t = 0; t < trackCount; t++) {
try {
var track = new LiveAPI("live_set tracks " + t);
if (getInt(track, "is_foldable") === 1) continue;
var groupId = parseGroupId(track.get("group_track"));
if (!groupId) continue;
var parent = new LiveAPI("id " + groupId);
if (!parent || parseInt(parent.id) === 0) continue;
var parentColor = parseInt(parent.get("color"));
if (isNaN(parentColor)) continue;
var slotCount = track.getcount("clip_slots");
for (var s = 0; s < slotCount; s++) {
var slot = new LiveAPI("live_set tracks " + t + " clip_slots " + s);
if (getInt(slot, "has_clip") !== 1) continue;
var clip = new LiveAPI("live_set tracks " + t + " clip_slots " + s + " clip");
try { clip.separseGroupId function · javascript · L727-L732 (6 LOC)AutoClean.js
function parseGroupId(raw) {
if (!raw) return 0;
if (typeof raw === "object" && raw.length >= 2) return parseInt(raw[1]);
var n = parseInt(raw);
return isNaN(n) ? 0 : n;
}Repobility · code-quality intelligence · https://repobility.com
recolorGroupChildren function · javascript · L734-L767 (34 LOC)AutoClean.js
function recolorGroupChildren(liveSet, trackCount) {
addLog("Recolor: scanning");
var recolored = 0;
for (var t = 0; t < trackCount; t++) {
try {
var track = new LiveAPI("live_set tracks " + t);
if (getInt(track, "is_foldable") === 1) continue;
var groupIdVal = track.get("group_track");
var groupId = 0;
if (groupIdVal) {
if (typeof groupIdVal === "object" && groupIdVal.length >= 2) {
groupId = parseInt(groupIdVal[1]);
} else {
groupId = parseInt(groupIdVal);
}
}
if (!groupId || isNaN(groupId) || groupId === 0) continue;
var parent = new LiveAPI("id " + groupId);
if (!parent || parseInt(parent.id) === 0) continue;
var parentColor = parseInt(parent.get("color"));
var myColor = parseInt(track.get("color"));
if (isNaN(parentColor) ||