image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Build a Drum Machine! by Erick Tejkowsi
10-04-01

Printer Version




This week we'll create a fun little project that mimics a drum machine. This project is somewhat unique in that it uses high quality samples for the drum loops, lets you start and stop the loops at will, and yet the whole thing only requires two lines of code! How are we going to pull this one off? Read on!

Introduction

The secret behind this week's project involves two file formats : SoundFont(.sf2) and Downloadable Sounds(.dls). These two file types are capable of storing multiple audio samples in one file. Think of them as audio packages. All audio samples are located conveniently in one file. These samples might represent a variety of sounds: orchestral instruments, pop vocals, car horns, or dog barks.

To hear the sounds within SF2 and DLS files, you can trigger them with MIDI from REALbasic. QuickTime added SF2 and DLS support beginning with QuickTime 5 and REALbasic works great in combination with it. (For best results on this project, download the latest version of QuickTime.) To install a SF2 or DLS file, drag it into one of the following folders on your hard drive:

  • For Mac OS 8/9 - Hard Drive:System Folder:Extensions Folder: QuickTime Extensions
  • For Mac OS X - Home:Library:Audio:Sounds:Banks

In case you don't have any SF2 or DLS files, some are included with the project download at the end of this tutorial. There are also many free files in SF2 and DLS format. SF2 has been fairly popular in the Windows world for several years, so you will find many of this file type on the web. DLS is a somewhat newer format, so it hasn't gained as much momentum yet. Files in this format are harder to find right now. DLS, however, is now the de facto standard (it's part of the MPEG4 spec., for example), so expect to see more it in the future. At the end of this tutorial are some links, where you can find sounds or learn to build them yourself.

Once you have moved your SF2 and DLS files to the proper location on your hard drive, open the QuickTime Control Panel (Mac OS 9) or the QuickTime Panel of the System Preferences (Mac OS X). Select your file and press "Make Default" for Mac OS X. For Mac OS 9, simply click the little black circle to the left of the sound bank's name.

10-04_osxqt.jpg (26k)10-04_qtsettings.jpg (26k)

After you select a sound bank, close the QuickTime settings and launch REALbasic.

Build an Interface and Add the Code

To begin building the interface, double click Window1 in the Project Window. Drag four NotePlayers and eight PushButton controls from the Toolbar to your interface. Name them according to this chart:

Control Settings Number of Controls With This Name
NotePlayer Name : NotePlayer1
Give each NotePlayer a unique Index number starting at 0 (zero). Give each NotePlayer a unique Instrument number starting at 1
4
PushButton Name : PlayButton
Give each PlayButton a unique Index number starting at 0 (zero)
4
PushButton Name : StopButton
Give each StopButton a unique Index number starting at 0 (zero)
4

Notice above that we are using control arrays. In other words, 4 buttons share the same name (PlayButton, for example), but each has its own unique Index number. This permits you to write code one time and let each control with the same name use that code. The NotePlayer Instrument number normally corresponds to a General MIDI Instrument as listed in the RB Language Reference. It needn't, however. When a SF2 or DLS file is used as the QuickTime music engine, the instruments are numbered according to the order they appear in the file. The demo files included with this project have four "instruments" per file.

10-04_playbutton.jpg (18k)10-04_stopbutton.jpg (17k)

The completed interface might look something like this:

10-04_interface.jpg (18k)

The final step is to add the two lines of code. Double click any one of the PlayButtons and enter this line:

NotePlayer1(Index).PlayNote(60,127)

This simple line of code starts up the NotePlayer control that shares the same Index number as this PushButton. It plays MIDI note number 60 at a volume of 127 (volume = 0-127). The second line of code is equally small - it turns off the note, by sending it a volume fo zero. Place this code in the Action event of the StopButton

NotePlayer1(Index).PlayNote(60,0)

Conclusion

That's it! Test your project by selecting Debug->Run. If all is working well, you should hear some unique sounds coming out of QuickTime, instead of those boring old QT Instruments you're used to. Feel free to download some other SoundFont or DLS files and activate them the same way. Your project can then instantly make use of the new sounds.

If you're too lazy to build this week's project, there may be no hope for you. :-) We still have the project available for download, though. It also contains a few sound banks for your listening enjoyment. You can learn more about SoundFont and DLS at the following URLs:

BEST Software Design - Creators of PolyPhontics, the forthcoming Macintosh SoundFont and DLS Editor.

Creative Technologies - Co-inventors of the SF2 format. Creators of the Mac-compatible SoundBlaster card.

SynthZone - A huge listing of SoundFont and DLS sites.

Sonic Implants - Sells commerical SoundFont and DLS samples. They also hand out some great freebies too.

HammerSound - Another large collection of SoundFont files.

Have fun and see you next week!




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]