| 1 |
// Listing 9.19 Polymorphism with an array of StkInstruments |
| 2 |
|
| 3 |
// Example of polymorphism and base class use |
| 4 |
// make an array of generic instruments |
| 5 |
StkInstrument inst[4]; |
| 6 |
|
| 7 |
// make each instrument a different type |
| 8 |
Sitar inst0 @=> inst[0] => dac; |
| 9 |
Mandolin inst1 @=> inst[1] => dac; |
| 10 |
Clarinet inst2 @=> inst[2] => dac; |
| 11 |
BlowBotl inst3 @=> inst[3] => dac; |
| 12 |
|
| 13 |
// take advantage of polymorphism to play them all |
| 14 |
for (0 => int i; i < 4; i++) { |
| 15 |
500.0 - (i*100.0) => inst[i].freq; |
| 16 |
1 => inst[i].noteOn; |
| 17 |
second => now; |
| 18 |
1 => inst[i].noteOff; |
| 19 |
} |
| 20 |
|