• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Piano Visualizer

New Here ,
Oct 12, 2019 Oct 12, 2019

Copy link to clipboard

Copied

Here is the Projekt that i want to make:

Unbenannt.PNGI want that everytime a white bar hits the top of the piano, thelayer keylight (the red lights) wich i created apears.

Another thing is that i want to reuse this method in other projekts,for example if the bars are colored diffrentry then in the screenshot i provided.

I would be really gratefull if someone could give me a step by step guide on how to do that cause im rather new to Aftereffects and expressions.

Thanks in advance!

                                     

-Tom-

 

 

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2019 Oct 12, 2019

Copy link to clipboard

Copied

There are at least two recent threads on this forum discussing different techniques for this type of piano roll animation. Try doing a search for them. 

 

I would use an expression tied to the position of the light effects using the sampleImage(point, radius = [.5, .5], postEffect = true, t = time) method found in the Layer>General section of the Expression Language menu in the timeline. This will give you a color value in a 4 digit array from the position of the point. To start I would define "point" as being equal to the position of a null or an Effect>Expression Controls>Point. control that is attached to each key. 

 

You'll find solutions in the other posts. Sorry, I don't have time to look them up for you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2019 Oct 12, 2019

Copy link to clipboard

Copied

Yeah i read the threats you mentioned but i cant get it to work :c

No worries il understand if you dont have the time to help, but if you maybe find some time in the future, i would appriciate it if you return to my post and explain me how to do it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2019 Oct 12, 2019

Copy link to clipboard

Copied

Thanks Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

I don't know how you set up your lighting effect layer. You mentioned Keylight but that effect is usually used to separate foreground elements on footage that has a consistent background color. To make a scenario using some kind of keying effect I would have to see the layer and know all of the modified properties and your workflow. 

 

If all you want to do to is generate some kind of glow every time one of the white bars intersects with the moving piano roll by far the easiest solution is to have the entire animated piano roll on a single layer, duplicate the layer, create a shape layer that covers just the intersection of the piano keys and the piano roll layer, use that as a track matte, then add a glow effect and/or some blur and color effects to the masked top copy of the piano roll layer. Something as simple as this:

Screenshot_2019-10-13 04.44.13_axEA3R.png

If you want to use the "sampleImage" expression method to detect where the intersection takes place and control something like lens flare brightness then look at this solution presented by Dan Ebberts: Using Sample Image

 

You will end up with a lot more complex composition but a different look. Something like this:

Screenshot_2019-10-13 05.15.50_8Bzgrs.png

The problem with this approach is that effect(index) does not seem to work as I would expect it to so you have to manually rename every instance of the lens flare, and every image sample takes time to calculate, so this approach would much slower to render.

 

Let me know exactly how you created your Keylight layer and how you expect to add the lighting effect to each layer and maybe I can help but I think your workflow may be a lot more complicated than it needs to be.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

Hey Rick Thanks for replying!

The keylight effect is just a combination of the Trapcode starglow effects and the Video Copilot Saber effect. I just tried a little bit until i got a reasonably good lokking keylight.keylight explanaton.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

To get that custom lighting effect to work you'll have to get rid of the pre-comp put all of those layers in the main comp. If you then move the anchor point of each of those layers directly over the appropriate piano key you can add an expression to each layer to change the opacity based on the layer position. If you duplicate the piano roll layer, turn it into a guide layer, and add directional blur, you can ramp the opacity up and down instead of just turning it on and off. The comp would look something like this:

Screenshot_2019-10-13 09.24.07_tLdyM0.png

And here's the expression:

 

target = thisComp.layer("Piano Roll 2");
point = thisLayer.position;
alpha = target.sampleImage(point,[3.5, 3.5])[3];
linear(alpha, 0, 1, 0, 100)

 

 It's not going to render very fast, but it will work. 

 

You could make it work with all of the lighting effects on a single layer and modify the expression to adjust the values of each parameter by modifying the point variable and the tMin, tMax, Value1, and Value2 portion of the expression. It all depends on what you want to do and which parameters you want to animate.  You could even add a bunch of nulls to the comp and use the position property of the nulls as the point variable. There are a lot of ways to go but I think this is the easiest.

 

Here's a sample comp that is greatly simplified: https://www.dropbox.com/s/mxsr09uer2zf0js/piano%20roll.aep?dl=0

(if your browser adds a .txt extension when you download the file just delete it.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

I dont know i did everything you said but the keylight layers arent showing up, the opacity is at 0% all the time.

Maybe it has something to do with moving all the layers to the main comp like you said but i dont know what you mean by that i only have one comp.

keylight not showing.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

I tried it again but now the keylight is there all the time and its not getting changed by the Piano Roll Layer.

Im sorry i know it may seem easy and straightforward for you but but its pretty hard for me im sorry.

forum key light.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

Did you download the sample project? Does the Piano Roll layer have a transparent background? If it does not you need to change the [3] at the end of the alpha = so that it uses one of the colors. The sampleImage method returns an array of 4 values, RGBA or [0, 1, 2, 3] and you can only use one of them at a time in this expression.

 

Try this:

  1. Start a new comp
  2. Add a small rectangle shape layer with any kind of fill or stroke
  3. Name the shape layer Piano Roll
  4. Duplicate the Piano Roll layer and add a directional blur of about 40 pixels
  5. Add small colored solid to the comp and name it test
  6. Add the following expression to the small solid's opacity property

 

 

target = thisComp.layer("Piano Roll 2");
point = thisLayer.position;
alpha = target.sampleImage(point,[.5, .5])[3];
linear(alpha, 0, 1, 0, 100)​

 

 

  • Parent the two shape layers together and turn off the visibility (eyeball in the timeline) of Piano Roll 2
  • Drag the parent of the shape layer around so that it passes by the solid and the opacity should increase as you get closer to the solid
  • Reverse the test and drag the "Test" layer around and watch what happens as it moves over the shape layers

As the anchor point of the solid "Test" layer approaches the blurred edge of the shape layer you should see the opacity increase. There is really not much to this. As long as the anchor point of your lighting effect ('keylight") layer is over the center of the effect any change to the alpha channel of the layer that is sampled (piano roll) will cause a change in the opacity of the layer with the expression.

 

One More Time: If your piano roll layer does not have a transparent background then you'll have to sample one of the color channels. You can pick any one of them. Red is [0], Green is [1], and Blue is [2].  That is the end value in the alpha variable in the expression. 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

Ok i did all the steps and it worked perfectly fine but when i apply those steps to my projekt it is not working anymore.

Here is what i get:

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

The anchor point is not in the center of the red rectangle. It should be. The opacity seems to be reversed. I notice you are using blue [2] instead of red. The test layer is also not at 100% scale.

 

Try soloing the Piano 2 layer and make it visible so you can actually see the area you are sampling. Make sure that the Info Panel is open and expanded and set to decimal:

Screenshot_2019-10-14 04.19.18_9fokkA.png

then mouse over the solid part of the piano roll and check out the maximum value for the color with the highest number. In this sample, the highest value is Red [1] at .9569. In this sample:

Screenshot_2019-10-14 04.23.57_ctzN3R.png

the highest value is still red at 0.6078

 

This means that I should change the tMax value in the linear expression from 1 to .6078. 

 

In your video the opacity of the test layer changes but it does not line up with the visible layers. This tells me that the Piano Roll 2 layer is not at it's default position scale and rotation values. Here's what I would do to continue the test.

 

Fix the anchor point, make sure that the test layer and the layer you are sampling are visible by soloing both layers so you can actually see what is being sampled, Turn on Transparency grid so you can see any transparency, but I don't think there is any and if the highest color value you see is red and something like .4403 change the expression to this:

 

 

target = thisComp.layer("Piano Roll 2");
point = thisLayer.position;
alpha = target.sampleImage(point,[.5, .5])[0];
linear(alpha, 0, .4403, 0, 100)​

 

 

As long as the layer you are sampling has not been moved or scaled this expression should work and the test layer's opacity should be 100% when its anchor point moves over anything that has a red value of at least .4403.

 

If the layer has been scaled or moved from the default position you can just select it and pre-compose. That is a lot easier than adding layer space transformations to the expression.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

OK i think i know what the problem was all the time.

In the Piano Roll that i was using is a green and a blue bar over the dropping notes wich you didnt see because i expanded the timeline so that you could see all the details of the layers.

forum problem.PNGwhen i hover over the informationsbars at the top of the Piano Roll red hasn´t always the highest value. maybe that caused the problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

So did you ever get this to work?

 

Your workflow is a lot more complicated than it needs to be. If I were doing it I would find the layer that is generating the original piano roll, duplicate just that layer, name the copy Piano Roll 2, then put it in your main comp to drive the animation of the lighting effect you have generated. You should be able to get a comp with the Piano Roll 2 and the lighting effect to work just fine. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

yeah it did work but i have one more question. how can i scale the Piano Roll and keep the expression working?

Precomposing  the layer somehow doesen´t help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

The piano roll layer that you are using to sample colors and the piano roll layer you are using for the image must be the same size.

 

If you scale one then you have to scale the other. Scaling will break the expression because the position of the dots will change so you have to Pre-compose both the Piano Roll layer and the Piano Roll 2 layer one at a time and make sure you move all attributes to the new comp. If you just take the default name it will have comp and a number added to the name. Delete the Comp 1 that was added so the expression does not break. That should be all that you have to do. If you want to rename the pre-comps you'll have to edit the expression.

 

One more thing, the only reason you have to duplicate the piano roll comp is to add a blur so that the light effect will ramp up and down instead of just turning on and off in a single frame. The layer will still be sampled, even if the visibility is off. Turning off the visibility will shorten your render time. 

 

I hope this is clear. If you do not move all attributes when you create a pre-comp from the piano roll 2 layer (the layer you sample the colors from) the samples will not line up with the image. Modifying the expression with layer space transformations just complicates things and shouldn't be necessary. 

 

I hope this helps. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

LATEST

Ok i tried it again and now everything is working perfect.

huge thanks for your help and your patience with me! next up is the particular part but thats for another day.

Thanks again for your help and have a nice day!

 

Tom

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines