|
8-23-01
Create an iTunes Plugin with REALbasic by Erick Tejkowsi
This week we'll create a simple REALbasic application that enables you to churn out custom iTunes visual plugins. Have a fun message you want to
surprise a co-worker or loved one with? Try passing it along via iTunes to really get their attention.
I know what you're saying.... "You can't build an iTunes plugin with REALbasic!". Fundamentally this is true.
Using a few tricks, though, we can fake it. Using an existing plugin, we will replace a few items within it
and build a new copy of the plugin with the revised settings, thus making a "new" plugin. The end effect
is an iTunes plugin of your very own that happily draws your name in multiple colors when run.
Build the Interface
This week's interface is drop-dead simple to create. Launch REALbasic, open Window1 and drag an EditField, StaticText, and PushButton
into the window. The EditField will be used as a place to enter your name. Pressing the PushButton will:
- Open a "Save" dialog to let you name the plugin file
- Build the plugin
To give you an idea of how this might look:
Add the Code
Before we jump in and start coding, you need to know a few things. First, the plugins you will create are based on a template plugin
named "ResexPlugin". When installed, this plugin is a fully functioning. It displays the word "ResExcellence" in flickering colors.
Further, the name of the plugin (as it appears in the iTunes menu) is "ResEx Plugin". If you do a quick count, you will see the following:
| ResExcellence |
13 characters long |
| ResEx Plugin |
12 characters long |
The plan is to replace these two bits of information with your own data. Since this resides within the data fork of the plugin, it is
vital that you not change the length of either string. Changing them will likely render the plugin useless. Don't need all the characters? We'll fill
in any blank spots with a "space", since it maintains the string lengths yet won't alter the display.
The code is fairly minimal this week as well. For starters, double-click PushButton1 and enter the following code:
dim src,dest as folderItem
dim s,yourname,yourpluginname as string
dim binin as binaryStream
//find the default plugin
src=GetFolderItem("ResexPlugin")
if src<>nil and src.exists then
dest = GetSaveFolderItem("",EditField1.text+" plugin")
if dest<>nil then
CopyFileOrFolder(src,dest)
//we are going to change the file , so openAsBinaryFile(TRUE)
binin = dest.openAsBinaryFile(TRUE)
//ResExcellence = default text drawn onscreen
//ResEx Plugin = default plugin name
s = binin.read(binin.length+1)
//add thirteen spaces to the name to be certain we
//have the minimum number of characters
yourname = left(Editfield1.text+" ",13)
s = replaceAll(s,"ResExcellence",yourname)
//the longest plugin name is 12 characters
yourpluginname = left(Editfield1.text+ " Plugin ",12)
s = replaceAll(s,"ResEx Plugin",yourpluginname)
binin.position = 0
binin.write s
binin.close
end if
end if
If you were paying attention, you may have noticed the undefined CopyFileOrFolder call. This leads us to our last code example.
Select Edit->New Method and create a new method:
You may recognize this method from the Language Reference in REALbasic. In fact, if you navigate to the "FolderItem" entry in the
Language Reference, you will find the code for CopyFileOrFolder, which you can drag from into your new method. In case you like to type,
the code is:
Dim i as Integer
Dim newFolder as FolderItem
If source.directory then //it's a folder
newFolder=destination.child(source.name)
newFolder.createAsFolder
For i=1 to source.count //go through each item
If source.item(i).directory then
//it's a folder
CopyFileOrFolder source.item(i), newFolder
//recursively call this
//routine passing it the folder
else
source.item(i).CopyFileTo newFolder //it's a file so copy it
end if
next
else //it's not a folder
source.CopyFileTo destination
end if
Conclusion
That's it! Test the project and when you're happy with the results, build the final application.
The resulting plugin should produce somthing that looks like this:
Don't forget to keep a copy of the
template plugin (entitled "ResexPlugin") in the same folder as your application.
As usual, you can download the application and completed project.
It also includes the C source code in case you are interested in building your own iTunes plugin in CodeWarrior. Until next week!
8-21-01
REALbasic News
by Erick Tejkowsi
REALbasic 3.5 Arrives!
REALbasic 3.5 has reached final release. In case you missed
it, this version includes the following new features:
- 3D graphics
- Regular Expressions
- REALbasic interpreter
- Office Automation
- New database control
- Bug fixes
A set of links to get your REALbasic fix:
Another MacTech Challenge
MacTech runs a monthly code contest. This time they are permitting you to submit your
entry in REALbasic. The challenge involves building an application capable of
rendering
Nassi-Schneiderman diagrams.
db Reports 2.5.
db Reports has reached version 2.5.
db Reports is a cross platform report writing application that works
on Mac OS Classic, Mac OS X, and any Win32 platform. With db Reports,
you can extract, format and print data from one of various data
sources.
Out in the Garage.
RB Garage has posted a new version
of their Euro Converter (version 2.5).
What's your angle?
George Clark has released a new reusable class called TexTangle
...based on the Canvas Class, combines the features of a StaticText
control and a Rectangle control into one convenient package. All of the
properties of a StaticText (with the exception of MultiLine; a TexTangle is
always in "multiline" mode), and of a Rectangle are duplicated in a
TexTangle. Plus TexTangle adds some refinements all its own...
Position text vertically (top, center, bottom) as well as horizontally
(left, center, right)
LeftMargin and RightMargin properties allow you to place text horizontally
just where you want it
A VerticalOffset property to add extra padding above text aligned at the
top, or below text aligned at the bottom, of the TexTangle
TexTangle uses the Backdrop property of the Canvas class, so you have full
access to all of the other Events of a Canvas. TexTangle is made with pure
REALbasic code, and requires no plug-ins.
Help for Balloon Help.
Don't miss the new BalloonHelp 1.2 class.
This version allows you to compile Carbon or Win32 builds (where
balloon help is not supported) without problems.
|