‘‘I try to take every project — whether it’s an album, making just one song, or doing a score like this — and enjoy it for what the limitations are and how that sets you free in other ways,’’ says Batmanglij, whose ‘‘Modern Vampires of the City’’ won the Grammy this year for best alternative album.

Batmanglij has written five classical pieces for the play — two each that bookend Acts 1 and 2 and a longer song for when theatergoers noisily arrive, rustling their Playbills and chatting. He put plenty of thought into each.

Get The Weekender in your inbox:

The Globe's top picks for what to see and do each weekend, in Boston and beyond.

‘‘I know there’ll be some people sitting in the audience who will be listening to every note just because they can’t help it. I’m like that sometimes. If there’s music around, I have to be listening to it. It’s hard for me to turn that off,’’ he said. ‘‘I have to keep it interesting for those people.’’

The Kenneth Lonergan play, which follows 48 hours in the life of three young New Yorkers in 1982, includes three Frank Zappa songs, and Batmanglij decided not to compete. ‘‘I thought it was important that the music in the world of the play be separate,’’ he said.

Anna D. Shapiro, who directs the play, said she was delighted by the result, which was first heard at Chicago’s Steppenwolf Theatre Company this summer. It is now in previews at the Cort, and opens Sept. 11.

‘‘He understands the function of music without you having to explain it to him,’’ said Shapiro. ‘‘If he sees that one part of the narrative is taken care of, he’s not going to double down. He’s not going to try to out-Frank Zappa Frank Zappa. Thank God.’’

Batmanglij took inspiration from the play’s setting on the Upper West Side, which he got to know while majoring in music at Columbia University. He asked himself: What instrument is most associated with the neighborhood? He decided on a piano. So he started experimenting.

Batmanglij often records himself playing melodies with his iPhone and it turns out that Memo 471 on his device became the skeleton of one song. When he plays it, a lovely piano riff emerges, betraying the composer’s classical roots.

‘‘I studied classical music at college so, for me, this is almost more of what I was trained to do than what I do for a living,’’ he said. ‘‘I hear it in everything, and I think it’s a part of all the music that I make.’’

Batmanglij may be a novice when it comes to writing for the stage, but he’s penned music for films, including ‘‘Sound of My Voice’’ (2011) and a piano piece for ‘‘The East’’ (2013), both directed by his brother, Zal.

Producer Scott Rudin — who recently tapped James Murphy of LCD Soundsystem to write music for the Broadway revival of ‘‘Betrayal’’ — knew Batmanglij was a fan of Lonergan’s films and sent him the script for ‘‘This Is Our Youth.’’ He read it in one sitting and was hooked.

Batmanglij has had to adjust the work for the Broadway run, including adding the tune as the audience arrives, mixing in some strings and lengthening the Act 1 ender from 10 seconds to 10 minutes.

‘I studied classical music at college . . .I hear it in everything, and I think it’s a part of all the music that I make.’

He said he’s loved collaborating with new people and using a different part of his brain. He also hopes the music he’s written for Broadway will have another life, and even won’t rule out returning one day to write a musical.

For now, though, his day job is calling: He’s got a song coming out soon with Charli XCX, and he’s always collaborating with his Vampire Weekend bandmates. ‘‘I’ve definitely enjoyed this project a lot, but I also feel like the world of songs is calling me,’’ he said.