Skip to content

Commit

Permalink
Add method to get deduped track objects (only the most recent version…
Browse files Browse the repository at this point in the history
… of each row)
  • Loading branch information
ben-xo committed Apr 16, 2022
1 parent 95858fd commit 8331d6a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion SSL/SSLHistoryDom.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,42 @@ public function getTracks()
}
return $tracks;
}


/**
* @return array of SSLTrack
*/
public function getDedupedTracks()
{
$tracks = $this->getTracks();

// raw session files are append-only when in use, and often contain multiple entries
// for the same track written at different points in the lifecycle (e.g. deck load /
// deck eject). Newer versions of Serato clean these up when you end the session,
// but it can still happen if you crash etc.

$seen_ids = array();
$positions_to_filter = array();

$ptr = count($tracks);
while($ptr > 0)
{
// work backward through the array removing younger dupes

$ptr--;
$row_id = $tracks[$ptr]->getRow();
if(isset($seen_ids[$row_id]))
{
$tracks[$ptr] = null;
}
else
{
$seen_ids[$row_id] = true;
}
}

return array_filter($tracks);
}

/**
* @return array of SSLAdatChunk
*/
Expand Down

0 comments on commit 8331d6a

Please sign in to comment.