#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP

3D
3D Photo Gallery (Part 1)
3D Photo Gallery (Part 2)

Audio
Poor Man's MIDI
Make A Metronome
iPod Tricks (Part 1)
iPod Tricks (Part 2)
iPod Tricks (Part 3)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls and Windows
Double Click Listbox
Draggable Metal Window
Double Click Canvas
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls


General RB
Scrolling Windows
Using Mesage Dialogs
Case-Sensitive Word Finder
Introduction to Stacks
Wiggle Window
JPEG in PDF
Listbox Checkboxes
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 1)
Software Distribution (Part 2)
Software Distribution (Part 3)
Software Distribution (Part 4)
Exceptions
Tips and Tricks
Text Clippings Made Easy

Graphics
Drawing a Simple Gradient
The SpriteSurface: Space Game
Image Spinner
Cropping Graphics (Part 1)
Cropping Graphics (Part 2)
Cropping Graphics (Part 3)
Cropping Graphics (Part 4)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Mac OS X
Global Hot Key Event (Carbon Events)
Login Welcomer (Carbon Events)
Add/Remove Buttons
Resizable Sheets
Mac OS X Preferences Window
Using Sheets in REALbasic
Build a Bundle (Part 1)
Build a Bundle (Part 2)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Menus
Window Menu
Templates Menu
Listbox Menu

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 1)
Merlin Simulator (Part 2)
Merlin Simulator (Part 3)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation
Network Registration Codes

Resources
Picture Extractor (Part 1)
Picture Extractor (Part 2)

Serial
Caller ID (Part 1)
Caller ID (Part 2)
Caller ID (Part 3)

Speech
Speech Recognition

Socket Communication
Easy Peer-to-Peer File Sharing
MacPAD Version Checking
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part I)
Stock Ticker (Part 2)
AIM Mate

XML Manipulation
Simple XML Introduction

Video
Big Brother Video Capture

Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.

resexc2.gif (20k)




REALbasic for Dummies
by Erick Tejkowski

$19.99 @ Amazon





Files are in Stuffit 6.5 or earlier, or ZIP format.
Download Stuffit Expander

Tell us about a bad link.

REALbasic Phone Home
10-25-01




This week we'll create a fun REALbasic project that spits out audio files. These audio files will play a tone like your telephone produces when you press the number keys.

Background

Telephones keypads in the United States produce tones in a unique manner called "DTMF". DMTF stands for Dual-Tone Multi-Frequency. There's no need to sweat the terminology if you're a technophobe. All it really means is that each row and column on a telephone keypad produces a unique tone. In other words, The 1, 4, 7, and * keys all share a common tone, and keys 1, 2, 3 produce a common tone. When you press a key, it sounds two simultaneous tones (hence the Dual in DTMF). If you'd like to hear the tone for a particular row or column, pick up your telephone and press two keys in the same row or column. The tone you hear is the frequency that the row or column shares. For the technically inclined out there, these tones are pure sine waves. So, in our code, we will produce audio files that contain sine waves of the two tones for any particular telephone key. If you'd like to know more about how DTMF and phones work, there's lots of info on the web. Try this site or do a search on Google for DTMF. The good news is that I (along with some help from Cubie award winner Wade) have taken care of the hard part of creating the tones for you and put them in a RB class. You just have to "wire up" the class in your own project to take advantage of it. So, let's get started.

Build the Interface

Launch REALbasic and open Window1. To the window add 12 PushButtons and rename the "1" key, giving it a name like "NumKey" and change its Index property to a value of 0 (zero). Then copy the "NumKey" name to the clipboard and select the "2" key and paste the name in for this key. When you press return, you should notice that the Index property will automatically increment to the next available number. Continue in this fashion for each key. When you're finished, you should have twelve PushButtons that share the same name, but each with a unique index number between 0 and 11 inclusive.

Next, add a checkbox to the window and give it some descriptive text. We will use this checkbox to decide if we want the two tones played together as we do on a phone, or separated between the stereo field, with one tone in the left speaker and one in the right. This is just so you can hear the tones separated like the example above where you pressed two keys on the phone at once.

Finally, add a ChasingArrow control to the window and make it invisible by unchecking its Visible property. It takes a little while to produce an audio file, so we will use this to show the user that we are hard at work producing the file. You may arrange the interface however you want, but it might look something like this.

interface.jpg (10k)

Add the Code

To create phone tones, you'll need to either download the phone tone class or download the completed project listed at the end of this tutorial. If you choose to download the class, drag it into your project window. If you download the completed project, it already contains the class.

Next, enter the following code in the Action event of any of the Window1 PushButtons (they share the same code since they are an array of controls):

code.jpg (36k)

First, this code turns on the ChasingArrows to show that a process is taking place. Then the code asks for a file where the user may save the audio. If one is chosen, the code then creates a new object based on the phone tone class (named "System7Creator"). Once the object is created, we send it the following messages:

  • SFILCreatePhoneNumberWave - creates the audio sine wave data based on which key was pressed
  • SetOutputFile - hopefully self-explanatory
  • MakeFile - make the sucker!

When the code has done its thing, hide the ChasingArrows again.

Conclusion

Well, that's it! Run the project and when you're happy with the results, build it. This project should work just fine on Carbon as well. If you'd like to download this week's example instead of typing it in, you can download the completed project. Oh, and if you've made it this far... look at the first and last initials in my name versus the title of this project to see if you can figure out my poor excuse for humor. Honest, there's a joke in there somewhere. See you next week!






Please support ResExcellence by Visiting our Sponsors. One click makes a difference.


Download REALbasic and create your own software!

#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP