Every story's a little different. With GIVING UP THE GHOST, I listened to a lot of Lisa Germano and The Dresden Dolls while I was brainstorming and outlining, because that seemed like the sort of stuff my main character would listen to. It got me into the right mindset for imagining her telling her story.
With POSSESSING LUCY, I made an iTunes playlist of songs by various artists that had the right feel, or seemed to relate to certain elements of the story, which I listened to while brainstorming. Mostly rock and alternative stuff, because that's mostly what I have. I also came across two songs that seemed to capture the core of the story really strongly, which I often listened to when I sat down to write to get me back into the story world. I'd close my eyes and let images from scenes in the story run through my head to fit the lyrics, as if the book had been made into a movie and then someone had made a fan music video for it. Always got me ready and eager to dive back into the story.
Strangely, I didn't really use music at all with THE HALFWAY HERO. Maybe because I'd been working on the outline so long the story and characters were pretty clear in my head, and then it came so fast that I didn't need to stop and get myself back into the story. If I need mood-setting music for the next draft I'll probably put on some fantasy and adventure movie soundtracks.
Where I use music the most, though, is when I don't have any one story I'm really set on. Often when I'm stuck I'll just listen to a bunch of my favorite music and let my mind wander. The lyrics and/or mood often give me ideas for characters and storylines, either completely new ones or ones that tie into existing ideas I haven't fully developed yet. One idea I've been playing with exists solely because of one line in one song that just struck me, and I thought, that would make an awesome story, and it went from there.
How about you? :) Do you use music while you're writing? Brainstorming? Ever gotten a story idea from a song?