This answer is almost criminally short given the richness of detail with which we know the various systems mentioned. Many of these systems are discussed in greater detail in other blog posts, and so relevant links are provided to encourage deeper engagement with the components of the motor pathway.
The important cortical structures for planning and executing voluntary movement are the primary motor cortex (M1), the premotor and supplementary motor areas (PMA and SMA), and the prefrontal cortex (PFC).
M1 executes movements by sending signals to the spinal cord, wherein reside the lower motor neurons, which communicate with the muscles. Not every signal generated by M1 results in movement. Sequences generated by M1 are gated by the basal ganglia.
These ganglia are in close communcation with the PFC, which makes executive decisions about which goals to pursue on the basis of value information computed by other frontal structures and mid-brain structures.
PFC also communicates with SMA and PMA, sending them a continual stream of potential goals to turn into motor plans, without regard to whether they will eventually be approved by the basal ganglia.
Pre-motor area acts, among other things, as a "staging area", ramping up its firing during the run-up to movement. It also contains the "mirror neurons", which fire not only during a certain action, but also while watching someone else perform that action, or even when imagining that action!
The supplementary motor area generates motor sequences: short, stereotyped collections of actions. The stimulation of SMA neurons produces these stereotyped actions, like raising the arm to a given position, or baring the teeth.
Check out the UTH online neuroscience textbook for more information about these areas, and about M1.
During sustained movements, the brain must keep track of whether the resulting movement is the one it planned for, or whether an error has occured, due to, for example, an unexpected change in load – e.g. a toddler grabbing onto your leg – or due to incorrect sensory information, as when one has a bit too much to drink, or when a cat overestimates its jumping ability.
This task falls to the cerebellum, which integrates sensory signals with motor commands and adjusts spinal output accordingly.
When the decision to reach is made by the prefrontal cortex, it sends a signal to the PMA to prepare a reach and another signal to the basal ganglia encoding the value of the reach target. The PMA recruits the SMA, which produces a series of activations representing, e.g., the rotation of the wrist, the lifting of the arm, and then the bending of the elbow. These activations take effect by recruting specific collections of cells in M1, which, after passing their activations past the filter of the basal ganglia, direct the upper motor neurons of the spinal cord to activate their pools of lower motor neurons in just such a way that the desired reaching motion is achieved.
While playing the piano
All of the above occurs, with perhaps more two-way communication between the PFC and the basal ganglia regarding the correct action selection – is now the time for Debussy or Piano Man?
If the piece is well-rehearsed, then the SMA will have sequences already prepared, while an improvization would require the cooperation of the frontal areas and the PMA. Playing along with a teacher would recruit the mirror neurons of the PMA, as would the highly imaginative act of an air guitar solo.
For a complex movement like a sonata, the feedback of the cerebellum will be critical – especially if the piano is a novel one, with differently weighted or spaced keys.