Luckily I like Renoise, PHP, and being under appreciated. Seriously, why come my alias can’t be blue or red?
Introducing: xrns_delete_unused_tracks.php
This is in CVS now…
Luckily I like Renoise, PHP, and being under appreciated. Seriously, why come my alias can’t be blue or red?
Introducing: xrns_delete_unused_tracks.php
This is in CVS now…
Not tried this yet, but that rules dude.
This should definitely be a feature that is included in the Software proper. No reason for it to be left out, especially as we now have the code sitting in front of us!
Thanks!
Yeah, this should indeed be in Renoise, and there is a bit more to check before its safe to trash a track:
Even when there is no pattern data set, we’ll have to check for FX which produce sound without getting feed with events from Renoise. Thats true for Renoises LineIn device and for VSTs which do not autosuspend and run their own sequencer (like a Reaktor FX or Energy XT FX for example).
For Send Tracks, there must be checked if other tracks link to them by checking the SendDevices in all other tracks…
The “specification” for this script came from this thread.
Delete Unused Tracks. The track would be deleted if there are no notes or commands and even if there are effects assigned to the track.
Yes, this script is destructive, but since it saves to a new file you don’t loose the original. It is therefore “safe” to use. Also, send tracks aren’t touched.
I don’t think PHP Code and Renoise are necessarily the same. I invite other coders to improve this script. Most of the code is unpacking and packing the song. The algorithm for the delete unused tracks is fairly “simple”.
// ----------------------------------------------------------------------------
// Search & Destroy
// ----------------------------------------------------------------------------
// Find stuff
$in_use = array();
foreach ($sx1->PatternPool->Patterns->Pattern as $p) {
$i = 0;
foreach ($p->Tracks->PatternTrack as $x) {
if ($x->Lines) {
$in_use[$i] = true;
}
++$i;
}
}
// Delete stuff
$total = count($sx1->Tracks->SequencerTrack);
foreach ($sx1->PatternPool->Patterns->Pattern as $p) {
for($i = $total - 1; $i >= 0; --$i) {
if (!isset($in_use[$i])) {
unset($p->Tracks->PatternTrack[$i]);
}
}
}
for($i = $total - 1; $i >= 0; --$i) {
if (!isset($in_use[$i])) {
unset($sx1->Tracks->SequencerTrack[$i]);
}
}
// Prevent Renoise from crashing ...
$sx1->SelectedTrackIndex = 0;
The “tricky parts” were doing the for() loops in reverse, because unsetting an array changed the position of elements, and $sx1->SelectedTrackIndex = 0; to prevent kernel panics if a track didn’t exist (Took me a while to figure this out… Perhaps this should be handled more gracefully than a kernel panic?) Repeat unnecessary “quotation marks”.
It’s funny, i always wanted something like this and only today noticed it in the drop down box of the frontend. Grrr, i guess it was lying there since quite a while.
Thanks a lot Dac!