The raw drama inherent in the American legal system has long made it a favorite subject for shows such as “The Practice,” but putting a musical spin on raw courtroom conflicts requires a more refined touch.

“It’s a real fine line between doing something that’s sort of bordering on melodramatic and something that’s keeping an edge to it,” says composer Marco Beltrami. “Every week, it sort of takes a different face.”

The gritty tone of the series and the dialogue-heavy court scenes pose the most interesting musical challenges, Beltrami says. “Overall, it’s pretty dark. Most of it is minor key. A lot of it is texturally based.

“You have the longest cues in the courtroom scenes and you play off the emotions that are not said onscreen. Sometimes, you have to be careful of the dialogue. They often start off on a quieter note and have an arc as they carry the tension through.”

That differs from the way Beltrami can handle the music in scenes focused on characters’ relationships, for which there is a theme. He also tries to create sonic identities even for characters who only appear in three- or four-episode story arcs.

Composing the music for a specific episode usually begins on a Monday with a final cut of an episode, though as the season progresses, Beltrami says that they often begin with a not-quite-final version. Then he and his assistant decide which segments need music. The cues are written and sent to the producers for approval by Wednesday and the music is recorded the same day.

Any notes come back to them Thursday and they go right into dubbing the final music, he says.

Most of the music in the show is a combination of about three instruments and the rest is synthesized.

Beltrami earned a master’s degree in music at Yale and served an internship at USC, studying under legendary film composer Jerry Goldsmith. He wrote music for films such as “Scream” and “The Mimic” before coming to “The Practice.”

Writing music for a TV series has advantages and disadvantages over working on films, he says.

“The most immediate difference is that you do it and then you’re done, which is really sort of gratifying. Some features you can be working on and making changes for a year or two.”