Request: identify layer NUMBER unambiguously

Post your questions here and we'll all try to help.
Post Reply
User avatar
gpvillamil
Posts: 550
Joined: Mon Apr 04, 2005 03:33
Location: San Francisco, California

Request: identify layer NUMBER unambiguously

Post by gpvillamil »

I'm doing a lot of stuff with OpenSoundControl and Avenue 4, so I need to address specific layers in Resolume from other programs.

I usually relabel layers with a descriptive name, so I lose track of the layer #. Also if you re-arrange layers after they are created, they keep their original labels, so the numbers in the layer label no longer match the layer's OSC address.

Would there be a way of displaying the "true" layer number in the UI? Maybe in the format <layer number>:<layer label>, where <layer number> is the true OSC layer address?

Right now I have to count up layers, which is kind of a pain in a set with a lot of layers.

Joris
Posts: 5186
Joined: Fri May 22, 2009 11:38

Re: Request: identify layer NUMBER unambiguously

Post by Joris »

I'm not quite sure what you're asking for here. You can see the layers true OSC address by going into the Application OSC map and clicking on the layer you want to target. Is that not what you're looking for?

User avatar
gpvillamil
Posts: 550
Joined: Mon Apr 04, 2005 03:33
Location: San Francisco, California

Re: Request: identify layer NUMBER unambiguously

Post by gpvillamil »

That is the number I'm looking for, but when you're setting up a set in Ableton Live using the M4L patches, its nice to be able to just glance at Resolume and see the layer number, vs having to enter the mapping mode.

User avatar
Tschoepler
Posts: 467
Joined: Fri Mar 13, 2009 04:26

Re: Request: identify layer NUMBER unambiguously

Post by Tschoepler »

big +1 :)
████▀ ▄█ tschoepler.net █████ zweifarbton.net █▄ ▀████

User avatar
Tryll
Posts: 40
Joined: Thu Sep 29, 2011 06:04

Re: Request: identify layer NUMBER unambiguously

Post by Tryll »

+1

Finding it easy to lose track of layers. Resolume makes it easy to rename them, and then shuffle them around. It would be helpful to be able to have an easy-to-see ID that never changes.

SeanBannister
Posts: 25
Joined: Tue Dec 27, 2022 10:45

Re: Request: identify layer NUMBER unambiguously

Post by SeanBannister »

I know I'm 14 years to late but for anyone looking for a solution via Google. I had to write some javascript code that calls the Resolume Rest API to solve this problem. This code will give you a object like:

Code: Select all

let id = {
  group1: {
    id: 1,
    layer1: { id: 1 },
    layer2: { id: 2 },
    layer3: { id: 3 }
  },
  layer4: { id: 4 },
  layer5: { id: 5 }
}
Then you can reference a layer like id.layer4.id or id.group1.layer2.id where "layer1" and "group1" are the names you used in Resolume.

Code: Select all

/************************************************************
 * Layer and Group IDs
 ************************************************************/
// Every time you add a new layer or group in Resolume, the IDs change.
// This script fetches the IDs of all layers and groups in the composition using the Resolume REST API and then allows you 
// to query them by name in the format of id.group.layer.id or id.layer.id
// Resolume REST API Docs: http://127.0.0.1:7002/api/docs/rest/

export let id = {};

// Fetches a group by "UI ID". This is the same ID as the one shown in the Resolume UI when checking OSC IDs.
// Get layers in this group and retrieve the "JSON IDs". This is a different ID that is only seen in JSON files.
// It also retrieves the name of the group.
async function parseGroups(groupId) {
  try {
    const response = await fetch('http://127.0.0.1:7002/api/v1/composition/layergroups/' + groupId);
    
    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
    
    const json = await response.json();
    
    id[json.name.value] = {
      id: groupId
    };
    
    json.layers.forEach(layer => {
      id[json.name.value][layer.name.value] = {
        jsonId: layer.id
      };
    });
    
    return id;
    
  } catch (error) {
    if (!error.message.includes('404')) { // Ignore 404 errors, which indicate no more groups are available
      console.error('Error fetching groups:', error);
    }
    return {};
  }
}

// The parseGroups function has no way of knowing the "UI ID" of the layer names it retrieves from groups. Because the ID it returns is different to the one
// used in the Resolume UI. We loop over this function calling the "UI ID" and match these to the "JSON IDs" in the returned JSON. 
async function parseLayers(layerId) {
  try {
    const response = await fetch('http://127.0.0.1:7002/api/v1/composition/layers/' + layerId);
    
    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
    
    const json = await response.json();
    
    let found = false;
    
    // Loop through each group in the composition
    Object.keys(id).forEach(groupKey => {
      // Loop through each layer in the group
      Object.keys(id[groupKey]).forEach(layerKey => {
        // Check if this layer has a jsonId and if it matches
        if (id[groupKey][layerKey].jsonId === json.id) {
          // Add the UI layerId to the matching layer
          id[groupKey][layerKey].id = layerId;
          found = true;
        }
      });
    });
    
    // If layer wasn't found in any group, add it directly to composition
    if (!found && json.name) {
      id[json.name.value] = {
        id: layerId,
        jsonId: json.id
      };
    }
    
    return id;
    
  } catch (error) {
    if (!error.message.includes('404')) { // Ignore 404 errors, which indicate no more layers are available
      console.error('Error fetching layers:', error);
    }
    return {};
  }
}

async function fetchIDs() {
  try {
    // Fetch groups first
    let groupId = 1;
    while (true) {
      const result = await parseGroups(groupId);
      if (Object.keys(result).length === 0) break;
      groupId++;
    }
    
    // Then fetch layers
    let layerId = 1;
    while (true) {
      const result = await parseLayers(layerId);
      if (Object.keys(result).length === 0) break;
      layerId++;
    }
    
    // Log the final results
    console.log(id);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

// Start the process
fetchIDs();

Post Reply