number of clips in track

robin.meier's icon

is there a way to know the number of clips present in a track using the m4l api?
thank you, robin

broc's icon
Jay Walker's icon

Thanks for the manual! However,
is there a way to know the number of clips present in a track using the m4l api?

I found has_clip. I'm not sure that's the right thing to use. And I know it will take more than one patcher to get the list of clips. Max isn't straightforward around simple tasks. Not sure if the manual is the best answer in this case, I'd love an example if someone has one.

Here's my initial stab at it, which fails as I can't figure out how to get a list of all clips with has_clip = 1.

Max Patch
Copy patch and select New From Clipboard in Max.

Len Richardson's icon

Yes.
I agree with Broc. You should deep dive into the LOM reference and also in the Live API Overview. It is more than worth the effort i would say.

Here is one way to count the number of clips in one track.

Max Patch
Copy patch and select New From Clipboard in Max.

Jay Walker's icon

Thank you Len that's exactly what I was looking for. And thanks for the encouragement to study those documents, which I will do in more depth. Still, after looking at your example I feel that's more valuable to me to understand common practices, flow, etc, that isn't included in a patcher-by-patcher description. I think like a lot of programming languages Max has a ton of hidden knowledge and gotchas all over the place. For me, I've been turning the forum and examples to get most of my working knowledge of Max as I also find the documentation very difficult to learn from.

Jay Walker's icon

Posting just for reference. Somehow, I'm finding that JS is way more readable and easy. This may not be the most efficient function, but gets the job done in a way I can totally relate to and reuse. I figured out how to use this by looking at JS functions in devices I've picked up from various places.

function getSelectedTrack() {
    // GET SELECTED TRACK DETAILS
    var selectedTrackObject = new LiveAPI("live_set view selected_track");
    var selectedTrack = selectedTrackObject.path;
    var trackNumber = Number (selectedTrackObject.unquotedpath.split (' ')[2]);
    var trackId = Number(selectedTrackObject.id);
    log("Track ID:", selectedTrackObject.id);
    log("Track Number:", trackNumber);
    log("Track Path:", selectedTrackObject.path);
    outlet(0, trackId);
    outlet(1, trackNumber);
    outlet(2, selectedTrackObject.path);

    // GET ALL CLIP SLOTS ON THE TRACK    
    var clipSlotCount = selectedTrackObject.getcount("clip_slots");
    log("Total Clips:", clipSlotCount);

    var clipSlot = new LiveAPI();

    // GET NUMBER OF CLIPS THAT EXIST
    var hasClipCount = 0;    
    for (var j=0 ; j<clipSlotCount ; j++) {
        var clip_slot_path = selectedTrackObject.path.replace(/['"]+/g, '')+" clip_slots "+j; //'
        clipSlot.path = clip_slot_path;
        var hasClip = parseInt(clipSlot.get("has_clip"));

        if (hasClip==1) {
            var clip_path = clip_slot_path + " clip";
            var clip = new LiveAPI(null, clip_path);
            hasClipCount = hasClipCount+1;    
        }
    }
    log("Last Available Clip:", clip_path);
    log("hasClipCount:", hasClipCount);    
}

Jan Andersson's icon

Thanks for your code Jay. I am a beginner in all means and despite trying to document deep dive I am struggling with finding solutions. Your getcount("clip_slots") made my day.

Kind regards,
Jan

Rob Rox's icon

Thanks a lot for "getcount". Definitely not documented in the LOM reference, is it