Autonaming tracks with last imported sound file

Hi Everyone, is there a functional script that creates a track and auto name’s it after the file that i importing the last? I have a huge session and i have always to rename all of my tracks when importing a new file. It takes forever.

I don’t have a script on hand, but I’d be happy to provide some pointers or basic code snippets. Can I get you to elaborate on what the desired behavior is? For example:

  • What specifically are you trying to rename?
    • Whole events
    • Individual audio tracks
    • etc.
  • When is it that you want to trigger the renaming?
    • File import
    • Replacing an existing file with a new one
    • Adding a new file to an event or track
    • etc.

A short series of steps explaining what exactly you’re trying to do would be great.

thanks for the answer. One of our programmers helped me out making a script, that auto names tracks with a shortcut once you have selected a audio clip on your track. You can change the shortcut in the script. right now it is alt&2 on mac. Is here a pool with already existing script for sharing my script?

1 Like

There’s no pool, but you’re more than welcome to share the script in this thread.

of course, feel free to use it.

/// Renames tracks based on their clips
/// If a track is selected, it will rename based on the first clip
/// If a specific clip is selected it will rename its track after it


studio.menu.addMenuItem({
  name: "Track Name from Clip",
  isEnabled: hasTrackOrSoundSelected,
  execute: trackNameFromClip,
  keySequence: "Ctrl+F2",
});

function trackNameFromClip()
{
  var selectedObjects = studio.window.editorSelection();
  for(var i = 0; i < selectedObjects.length; i++)
  {
    var selectedObject = selectedObjects[i];
    if(selectedObject.isOfExactType("GroupTrack")) // if track is selected, name it based on the first sound
    {
      nameTrackBasedOnFirstSound(selectedObject);
    }
    else if(selectedObject.isOfType("ManagedObject")) // if specific instrument on track is selected, name its track after it
    {
      nameTrackOfSoundBasedOnSound(selectedObject);
    }
  }
}

// check if track or sound is selected
function hasTrackOrSoundSelected()
{
  var selectedObjects = studio.window.editorSelection();
  for(var i = 0; i < selectedObjects.length; i++)
  {
    var selectedObject = selectedObjects[i];
    if(selectedObject.isOfExactType("GroupTrack"))
      return true;
    else if(selectedObject.isOfType("Sound"))
      return true;
    else if(selectedObject.isOfExactType("EventSound"))
      return true;
  }
  return false;
}

function nameTrackBasedOnFirstSound(track)
{
  var modules = track.modules;
  for(var i = 0; i < modules.length; i++)
  {
    var module = modules[i];
    if(module.isOfType("Sound") || module.isOfExactType("EventSound"))
    {
      var soundName = getModuleName(module);
      if(soundName && soundName.length > 0)
      {
        console.log("Name Track " + track.mixerGroup.name + " based on first sound " + soundName);
        track.mixerGroup.name = soundName;
        return;
      }
    }
  }
  console.log("Track " + track.mixerGroup.name + " has no sounds on it to name it after.");
}

function nameTrackOfSoundBasedOnSound(module)
{
  var moduleName = getModuleName(module);
  if(moduleName && moduleName.length > 0)
  {
    var mixerGroup = module.audioTrack.mixerGroup;
    console.log("Name Track " + mixerGroup.name + " of sound " + moduleName + " based on the sound.");
    mixerGroup.name = moduleName;
  }
}

function getModuleName(module)
{
  if(module.name && module.name.length > 0)
    return module.name;
  if(module.isOfExactType("SingleSound"))
  {
    if(module.audioFile)
    {
      return GetAssetName(module.audioFile);
    }
  }
  else if(module.isOfExactType("MultiSound")) // for multi-sound instruments, use the name of the first sound
  {
    if(module.sounds && module.sounds.length > 0)
    {
      return getModuleName(module.sounds[0]);
    }
  }
  else if(module.isOfExactType("EventSound"))
  {
    return module.event.name;
  }

  return null;
}

function GetFullAssetName(asset){
    var assetPath = asset.getAssetPath().split('/');
    return assetPath.pop()
}

function GetAssetName(asset){
    var assetName = GetFullAssetName(asset);
    var lastIndexOf = assetName.lastIndexOf('.');
    return assetName.slice(0, lastIndexOf);
}

1 Like