Dr. Limb has been putting jazz musicians into a functional magnetic resonance imaging machine, a process which requires them to lie on their backs, slide into the brain scanner, and keep their heads perfectly still, while their hands, stretched out in front of them outside the scanner, play on a jury-rigged piano keyboard. The musicians' brain activity is monitored as they played a written-down jazz melody they were asked to memorize and then as they improvised to the chord changes of that melody.

When the musicians improvised, Dr. Limb found, areas of the brain's prefrontal cortex linked to self-expression were activated, but an area linked to inhibition and self-monitoring "kind of shuts down when you go creative," he said. That did not happen when musicians played a memorized piece.

Dr. Limb is also putting hip-hop artists into the brain scanner. "They're totally into it," he said. "They say, 'You know I've wanted to know what's going on in my head for the past 20 years.'" He asks them to recite a memorized rap and then to improvise lyrics using certain cued words. Preliminary results suggest that rap improvisation activates different areas from music improvisation.

Aaron Berkowitz, who has researched the neural basis of improvisation and is also a pianist and fortepianist, used a different approach to compare the brains of musicians and nonmusicians when they created five-note melodies. He found that the amount of novelty in the melodies was the same for musicians and nonmusicians, and that musicians were not activating more music-related areas of the brain. But he found that "musicians were turning off a part of the brain," involved in "a special type of attention," he said. It was a different area from what Dr. Limb was studying, but the implication is similar. The fact that this area gets inhibited when musicians play enables the performers to tune out a cellphone ring in the audience or noise from a malfunctioning amplifier, Dr. Berkowitz said.

Asked how, when performing music, he balances the ideas and feelings in his head with the external stimuli of the audience, the place he is performing, and extraneous sounds, Mr. Metheny explained his approach. He respects and appreciates the audience, but "I'm playing for myself – anything other than that would be a guess," he said. "If you start worrying about what critics say, or a record company, or the audience, then you get paralyzed. The only thing I know for sure is what I love."

Mr. Metheny said that when he plays, "to a certain degree I remain somewhat detached emotionally; I'm kind of listening" and thinking at various points, "if I was listening to this, which I am, what would I like the guitar player to play next? And I would do it, or sometimes I would do the opposite. The best musicians are not the best players, they're the best listeners."

But even Mr. Metheny's decades of experience doesn't give him the ability to always play the notes he wants to. "You've told me that actually the music coming out of the guitar is not nearly as good as what you're hearing in your head," Dr. Limb said.