How to get index of cursor track in trackBank

Post Reply New Topic
RELATED
PRODUCTS

Post

I'm wondering how I can get the index if a cursor track in my current trackBank. What I find is that if a track is grouped, cursorTrack.position reports the position inside a group, not the global position.

Example :

Code: Select all

track > position = 0
track > position = 1
group > position = 2
   - track > position = 0
   - track > position = 1
track > position = 3
I have no way of telling the global position in my current track view. If the groups are folded up, all is fine. But what do I do if groups are folded out?
I want to highlight the selected track in my clip launcher.

Post

First you need to decide if you want to monitor the track flat (all at once) or hierarchical (you only see the tracks in a group or the top tracks):

if (hasFlatTrackList)
{
tb = controllerHost.createMainTrackBank (numTracks, numSends, numScenes);
tb.followCursorTrack (this.cursorTrack);
}
else
tb = this.cursorTrack.createSiblingsTrackBank (numTracks, numSends, numScenes, false, false);

By doing it that way, you normally do not need the position since the bank page adjusts itself automatically if you click on a track in Bitwig.
To mark selections in your page you can monitor the cursorIndex () property of the bank.

If you want to get the absolute position but have decided to do it the hierarchical way, you would need to create additionally a flat track bank and then use the position property with it.

Post

Thank you a lot for your quick answer.

I'm not sure how this would help me, though. Maybe I phrased my question poorly.

I'm working on a clip launcher (launchpad-style) on the linnstrument. It can switch between regular linnstrument mode and the clip launcher view. It works fine. I want to use the bottom row of buttons for selecting the currently highlighted track in Bitwig, so that I can play that track from the linnstrument when the cliplauncher view is not active.

I do it like this:
if (buttonYCoordinate == lowRowY)
{
trackBank.getItemAt(buttonXCoordinate).selectInEditor();
}

The track back is a "MainTrackBank". It works as expected. I can select tracks and groups no matter if the groups are unfolded or not.
However, I want to have a led indication of what track is selected. For this I need to know the index of the selected track (CursorTrack) in my track view so that I can light up the matching button.

Post

As I wrote above: Add an observer to the cursorIndex () property of the trackbank.
I do it like this: I have a track object for each track in the bank page. When the observer fires I set the selected attribute of the changed tracks (the unselected and selected).
When you redraw on flush(), simply check the selected state and light your LEDs accordingly,

Post

Ah, I was assuming that the cursorIndex is the leftmost index that is included in the banks "viewport".

I made the change. I now have an observer registered on trackBank.cursorIndex(). The callback is called once after registering the observer (the reported index is -1). But contrary to my wish, when I select tracks either in the GUI or via my linnstrument, the callback is not called.
The doc for TrackBank#cursorIndex() states: "An integer value that defines the location of the cursor that this bank is following." I'm not sure how to interpret this. What cursor is the bank following? It's a "MainTrackBank" that I can shift around to show a subset of the tracks on my controller. What does cursor even mean in that context?

EDIT: AH, I shoud've followed your first post more clearly. the missing link was trackBank.followCursorTrack (cursorTrack);
Though I must admit, I don't find this very intuitive. What's actually happening when a track bank is following the cursor track?

It's working now as expected. Thanks again for your help, Jürgen!

Post Reply

Return to “Controller Scripting”