Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions MIDI note counter

  • Posted by Kevin Gries on July 11, 2015 at 8:58 pm

    I have a video of me playing piano along with a MIDI file containing all of the notes I played. I would like to use After Effects to add a note counter to the video which displays how many notes I’ve played so far at that point in the video. Basically it counts up by one as each note is pressed. Think Guitar Hero’s note streak display; it counts up for each note you play.

    I have imported the MIDI file into AE, so now each note pressed is a keyframe. All of the keyframes are on a single layer, so all that’s left to do is write an expression that counts up by one each time it comes across a keyframe and displays the current count on the screen.

    I’ve spent the last three hours searching the internet for someone who has done something like this before and have had no luck. The closest I came was this post:

    https://forums.creativecow.net/thread/227/15045

    …but it appears to count markers, not keyframes. Unfortunately, I’m not experienced enough in expressions to understand all of what is going on there in the code from that post, so I’m not even 100% sure that it’s doing what I think it’s doing. I’ve tried writing the expression myself, but I can’t get it figured out.

    Can anyone help?

    Kevin Gries replied 11 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 12, 2015 at 12:33 am

    You didn’t say which property has the keyframes, so I’m assuming a slider. If you apply this to the source text of a text layer, it should give you the number of keyframes up to that point:


    p = thisComp.layer("midi layer").effect("Slider Control")("Slider");
    n = 0;
    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time) n--;
    }
    n

    Dan

  • Kevin Gries

    July 12, 2015 at 12:58 am

    Dan,

    Yes, you are correct, it is a slider. Your code worked perfectly. I am so very thankful for your help!

    I’m sitting here going through your code trying to figure out what it all means. The logic of it all makes sense and lines up with my programming experience. My initial attempts to get this to work followed the same format. However, it’s the syntax of the terms like .numKeys, .nearestKey(time).index, .key().time that were missing from my brain preventing me from figuring it out. I googled these terms when I was trying to dissect the code to which I linked in my first post and the best I found was this:

    https://helpx.adobe.com/after-effects/using/expression-language-reference.html

    It explained what “numKeys” does, but not so much how it works or how to use it, at least not enough for me to grasp. If I could ask you for a bit more help, would you be able to recommend any good references for learning how these commands work and how to use them? So far, everything I’ve come across is either too simple (ex. how to write a script to display a slider’s value) or too specialized (and difficult to apply to anything other than one specific example). I’m looking for something I can pair with that (above linked) expression language reference to be a good go-to when I need to figure something like this out. Hopefully that makes sense…

    Is there anything you would recommend?

    Either way, thank you again for your help!

    Kevin

  • Dan Ebberts

    July 12, 2015 at 1:08 am

    For nitty gritty syntax details, I don’t know of anything better than the AE help Expression Language Reference, which you’ve found. My suggestion would be to find some expression you like, and pick through it and modify it until you understand exactly how it works, using the reference as a guide. If there’s anything in particular tripping you up, come back here and ask.

    Dan

  • Kevin Gries

    July 12, 2015 at 1:27 am

    Ok, thank you very much Dan! You’ve been a great help.

    FYI: The first movement of Beethoven’s Waldstein Sonata has approximately 8,506 notes in it. At 11 minutes and 40 seconds long, it averages approximately 12 notes per second.

    Today I Learned.

    Kevin

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy