Sample piano score file
Piano specific xml attributes
note = The note attribute require a value that corresponds to a key on a piano.
pedal = The beat attribute accepts a boolean thats true when the pedal is pressed down.
loudness = The loudness attribute accepts a double between 0-1 that corresponds to the speed a key is pressed. The closer to one this value is the louder the note will appear.
How it works
The persistance ascept of the piano instrument is acomplished through the CPianoInstrument class which can store the duration, loudness, and pedal attributes so they don't have to be repeated in every note tag. This means that any one of these attributes will apply to all the note tags that follow until another tag overrides its value.
For every note tag, the CPianoInstrumentFactory will parse the xml and then create a CPianoInstrument class and feed it the parsed values. This means every new CPianoInstrument will get duration, loudness, pedal, and wave table attributes.
When the program is first starting, the CPianoInstrumentFactory will create a wave table for every piano note. This way it can create the piano instrument class fast enough to output piano chords in real-time. The piano note wave tables are stored in a map that contains a string (note name) for the key and a wave table for the value.
Once the CPianoInstruments have been created and fed the required xml attributes, they will output the modified audio when Generate() is called. Creating a new piano instrument that doesn't override the wave table automatically deals with polyphony.
To simulate the damping sound, the instrument will use an envelope to slowly fade out the wave file after the require duration has passed. Two constants control this fading; the first determines how fast the wave table will fade, while the second determines the lower bound of the fade.
In order to accurately simulate a piano's pedal, a sound is played when the pedal is pressed down and released, and the fade will disappear while the pedal attribute is true. This allows the piano wave table notes to sustain for their full duration. The pedal attribute doens't have to be placed in a note tag that has a pedal note value like displayed above, but the note value must be set to "pedald" or "pedalu" in order to hear the pedal.
Finally the loudness attribute simulates how loud a piano note is played based on the speed the key is pressed down. This is implemented by using two wave tables for every piano note. These dynamics are further improved by interpolating between the two wave table notes so any volume of note between the loud and soft notes can be achieved.