upper left corner
upper right corner
header end left header end right Flash Audio
Martin Wilde

Build a MIDI Synth with Flash

page 1 2 3 4 5

Creating MIDI Patches

Now it’s time to construct the MIDI patches from this collection of Sound objects.  While there is no direct support for patch changes in Flash, just think of the individual MIDI channels as your available patches.  By convention, we use channel 10 as the percussion channel.  That still leaves 15 channels onto which we can map at least 15 different timbres.  Note that it is possible to map more than one patch per channel by splitting the note range within a channel.  It all depends on what you want to do.

Here we use a two-dimensional array called NoteObjects to define the patches in terms of MIDI channel and note mappings.  We place the names of the above-defined Sound objects into the appropriate channel and note position within that channel.  For example, here is the specification for channel 2 of the NoteObjects array in this SWF:

//Channel 2
[0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
note0232, 0, 0, note0235, 0, note0237, 0, note0239,
0, note0241, note0242, 0, note0244, 0, 0, note0247,
0, 0, 0, note0251, 0, note0253, 0, 0,
note0256, 0, 0, note0259, note0260, 0, 0, note0263,
0, 0, 0, 0, note0268,  0, note0270 , 0,
note0272, note0273, 0, note0275, note0276, note0277, 0, note0279,
note0280, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]

These mappings associate the given sound object with the channel and note numbers in the MIDI score.  Using the example above, our Flash MDI synthesizer plays the Sound object named ‘note0272’, whenever the MIDI score calls for a noteOn on channel 2, note 72.

You don’t have to specify any more NoteObjects elements than the highest channel you wish to use.  For this reason, you may want to make sure the SMF contains no empty channels across its tracks.  While this doesn’t save any appreciable space in the output SWF, it does take the confusion out of having a lot of zero-filled arrays.  In the FLA presented here, for the sake of completeness I’ve defined similar mappings for channels 0, 2 and 3, defined a single note on channel 9 (the 10th channel used for percussion), and included all the other empty channels in the NoteObjects array.

page 1 2 3 4 5

upper left corner
upper right corner
header end left
header end right
Sponsors
 
header end left
header end right
Contribute
  • Contribute an Article
    Demonstrate your professional skills and knowledge to the community.
  • Become a Sponsor
    Promote your service to Sonify's community of professional content and application developers.
  • Submit News
    Help keep the community informed about industry developments.
header end left
header end right
About Sonify.org

Sonify.org is a community resource where Developers can unite with the common goals of adding interactive audio to the Web, Wireless and Digital Devices as well as advancing the development of the underlying interactive audio technologies. Read more.