Computer Programming vs. Scripting Languages in the Development of Music
Education Software

Scott D. Lipscomb, Institute for Music Research, University of Texas at San Antonio

    With the proliferation of authoring tools such as HyperCard, Director, Authorware, and Toolbook, music educators have seemingly fled from traditional programming languages, apparently maintaining the belief that scripting languages are easier to learn and take less time in the development of useful software. What many of these individuals do not realize is that, during the past decade, programming languages have increased significantly in user friendliness through the use of automation, point-and-click creation of graphical interfaces, and event-driven architecture. Despite marketing hype and dogmatic user claims to the contrary, the learning curve for a traditional programming language is not significantly different from that of a scripting language and programming languages do not share many of the limitations inherent in a scripting environment, allowing the programmer low-level access to the computer's operating system if desired. In reality, whether scripting or programming in code, the user must learn keywords (or commands) and the fundamentals of program flow in order to put them to work in an appropriate syntactical context. For example, the following lines of code show how one changes the background color of a window using Visual Basic and Director's Lingo scripting language.

Table 1.
Programming Language vs. Scripting in Eliciting a Change in Background Color.

        Visual Basic                     - MainForm.BackColor = GREEN

        Director's Lingo script    - set the stage color to 0
 

    Though the scripting language uses no mathematical symbols and mimics more closely spoken language, using the global variable "GREEN" in Visual Basic makes the programming code easier to interpret for the lay person than the Lingo script.
    Recent software like Visual Basic-and even Visual C++, to a certain extent-allow the developer to concentrate on the end result rather than getting bogged down in presentation aesthetics and complex programming code. Both of these programming languages incorporate point-and-click creation of the user interface and easy-to-learn methods for attaching code to each object (e.g., buttons, text boxes, check boxes, menus, etc.). In its most recent incarnation, the Cross-Development Platform edition of Visual C++ allows a developer to create programs for Windows 95 or Windows NT using the Microsoft Foundation Class of functions created and debugged by Microsoft programmers and, by simply recompiling the program while selecting the Macintosh operating system option, to translate this code into native PowerPC applications for the Macintosh giving the resulting software the look and performance of a C++ program created from scratch on the Macintosh.

Are Programming Languages More Difficult?
    There was a time-not so long ago--when fear and loathing may have been an appropriate reaction to the thought of learning a programming language with its cryptic symbols and complex logical structures. The code listed in the left column of Table 2 was excerpted from an antiquated program written in QuickBasic by the author to aid in performing pitch class and durational melodic analyses. Essentially, this portion of the routine prints the note duration (e.g., quarter note), followed by a series of asterisks representing the number of times that particular duration appeared in the melodic excerpt under examination. However, comprehension of the meaning of such programming code requires a familiarity with the Basic programming commands and syntax. To the uninitiated, the inherent structure and logic contained in this code is less than obvious and may contain little more comprehensible information than if written in Greek (see right column in the table below).

Table 2. An Example of QuickBasic Code.

Programming: A New Generation
    There have been two dramatic changes to the manner in which programs are currently written. First and foremost is the ease with which the user-interface is created. Both Visual Basic and Visual C++ provide a method of creating the user interface that resembles a drawing program more than a programming language. The programmer simply clicks on one of the tools provided in a Tool palette (e.g., button, text box, label, scroll bar, etc.) and draws a rectangle at the position where the object should be placed (Figure 1). Resizing or relocating any created object is accomplished by clicking and dragging with the mouse. The actual assembly language code necessary for creating the resulting objects is generated automatically by the program. Secondly, rather than maintaining a sequential ordering from the beginning of a program until its termination, programs written using the new-generation programming languages are "event-driven." In other words, the user determines the sequence of events by the manner in which he or she interacts with the graphical interface (i.e., buttons, text boxes, menus, etc.). For example, clicking a button with the mouse or typing on the keyboard sends a message to the to the operating system. The programmer is responsible for deciding which of these messages to respond to and determining the resulting action of the program.

    In an attempt to understand these fundamental programming objects, perhaps a real-world analogy will prove useful. Imagine a table (an object). The table has certain properties that distinguish it from other objects of its type; e.g.., color, height, width, material. etc. Likewise, programming objects have properties that can be determined as the program is developed (design-time) or changed as the program is used (run-time). For example, every window on the computer screen has a specific height, width, background color, forecolor (text color), name, etc. In fact, in Visual Basic (VB), a form (VB's term for an on-screen "window") has a total of forty-three properties that are easily manipulated by the programmer. Changing a property value at design-time is extremely easy. In the "Properties" window (left side of screen in Figure 1), simply click on the property you would like to change and type the desired value. For example, to change the name of a form click on the form (so that its properties are reflected in the Properties window), click on "Name" in the Properties window, then type: MainForm. Voila! You have just given your form a name.
   
The object-property relationship is expressed in VB programming with a "period" syntax (e.g., Object.Property). For example, in Table I above, the line of VB code sets the "BackColor" property of the object "MainForm" to "GREEN." If we would like for the background color to change when the user clicks on a button (event), then we follow these simple steps: (a) draw a button on the form, (b) double-click the button (causes a dialog box to open),(3 Double-clicking on an object in this manner causes a code window to open to a default event so that the programmer may begin entering code for events generated by the selected object. For the button object, the default event is the "click event that occurs anytime a user clicks on the button with the mouse. In addition to the click event, button objects can respond to many other events, e.g., double-click, drag-drop, key press, receiving the focus, etc. In order to respond to any of these events, the programmer simply selects the appropriate event from a drop-down list and begins typing code. In the context of the present paper, only the default events will be utilized. Each of these events will be identified in parentheses following the "double-click" instruction.) and type the single line of VB code provided in Table 1. This procedure is certainly no more complicated than writing a HyperCard or Lingo script.
    Visual Basic provides a large number of objects that can be incorporated directly into your programs. The following three programs were all created in real-time during the final fifteen minutes of the conference presentation in order to illustrate the ease with which software can be developed using this programming language. For each example, it is assumed that a new VB "project" has been begun.

A Fully-Functional Clip Art Viewer (with only 4 lines of code?!!)
    Using the tool palette, create the following objects on a form: a DriveListBox, a DirListBox, a FileListBox, a PictureBox, and a Label. The resulting form should look similar to the one in Figure 2. Simply accept the default names assigned by VB: Drivel, Dir 1, File 1, Picturel, and Labell, respectively. The DriveListBox, DirListBox, and FileListBox make navigation to various subdirectories on any computer floppy or hard drive trivial to incorporate. Because we want the FileListBox to reflect the files contained in the subdirectory highlighted in the DirListBox, double-click on Dirl (change event) and type:

            Filel.Path = Dirl.Path

    The "Path" property reads or sets the currently opened directory path in a DirListBox or FileListBox. Therefore, the statement above sets the current directory (property) of Filet (object) to the path (property) pointed to by Dir I (Object).(Identification) of "objects" and "properties" in the preceding sentence is included for the purpose of solidifying these concepts in the context of a real programming example. For the remainder of this paper, objects and properties will no longer be explicitly identified, leaving that task to the reader.)
   
Since we also want the subdirectories fisted in the DirListBox to reflect those contained on the drive highlighted in Drivel, double-click on Drive I (change event) and type:

            Dirl.Path = Drivel.Drive

    If you were to run the program now, you would see that it is possible to navigate to every subdirectory on each drive of the computer, viewing the appropriate files in the File I window. However, the PictureBox and Label do not yet function ... a situation that shall be remedied by setting a single property of the File I object and adding two lines of code.
    Because we are creating a Clip Art viewer, it would not make sense to display all files in the FileListBox window. Instead, we will limit the display to typical Windows graphic files by setting the "Pattern" property of Filet to "*.BMP;*.WMF;*.ICO;*.RLE" (i.e., bitmaps, Windows metafiles, icons, and min-length encoded formats, respectively). Therefore, any file displayed in the Window should be compatible with our viewer. Finally, only two lines of code are required to present the text of the path & filename in Label l and to display the referenced graphic image in Picture I. To complete this task, double-click on the FileListBox (click event) and type:

            Labell.Caption = FileI.Path & "\" & Filel.FileName
            Forml.Picturel.Picture = LoadPicture(Labell.Caption)

    Whenever the user clicks on a graphic file listed in Filet, the first statement sets the "Caption" property of Labell to the complete path and filename for the graphic file and the second statement uses that text to load the picture into the "Picture" property of Picture 1.
    There you have it ... four lines of code and a My-functional Clip Art viewer!! 

Simple Animation
   
For this example the following objects must first be placed on the form: a timer and three image boxes. To add a picture to the image box, click on the image box object, click on the "Picture" property of one of the image boxes, and locate an available graphic file. In Figure 2, 1 have loaded a graphic entitled "Bflyl.bmp" (a butterfly with open wings) into the object "Imagel" and "Bfly2.bmp" (the same butterfly with closed wings) into "Image2." Set the "Visible" property of the "Imagel" and "Image2" objects to "False"--effectively making them invisible. Since the default for an object's "Visible" property is "True," we don't need to do anything to "ImageY except set the "Picture" property to "Bflyl.bmp," like "Imagel." Now, click on the "Timer I" object and set the "Interval" property to "250." This is the time interval (in milliseconds) between "timer events" (i.e., at each of these intervals a "Timer message" is sent to the operating system). Finally, double-click on the Timer object (timer event) and enter the following code:

                Static PickBMP As Integer
                If PickBMP = True Then
                    Image3.Picture = Imagel.Picture
                Else
                    Image3.Picture = Image2.Picture
                End If
                PickBW = Not PickBMP

    Every time the timer event occurs (every 250 ms), the picture in "Image3" will change, alternating between the butterfly with open wings and the butterfly with closed wings, creating a simple animation. By setting the "Left' property to a slightly greater value every time a timer event occurs will make the butterfly appear that it is flying toward the right side of the screen.

Multimedia
    Incorporating multimedia into a program has never been easier. One of the objects supplied with VB is the Multimedia Control, which resembles the controls found on a typical cassette deck or CD player (Figure 3). Playing multimedia involves two or three (depending on type) basic steps: 1) identify the type of multimedia device, 2) provide the path and name of a sound file (if necessary), and 3) "open" the device so that it can be controlled by the multimedia control. For this program, simply place a single multimedia control object on the form. Double-click the form itself (load event, i.e., this code will be executed immediately when the program starts) and type the following: 

            MMControll.DeviceType = "CDAudio"
   
         MMControll.Command = ItOpen"

    These two lines of code successfully prepare the multimedia control shown in Figure 3 for playing an audio CD. The user can play, pause, stop, skip to another track, or eject the CD by clicking on the appropriate button. 


Figure 3. The Multimedia Control.
  •  

    Controlling other types of sound and animation files with the multimedia control are no more difficult. In order to play an audio (WAV) file, simply substitute the following code:

                MMControll.DeviceType = "WaveAudio"
   
             MMControll.FileName = "C:\windows\chord.wav"
                MMControll.Command = "Open"

... or to play an audio-video interleave (AVI) file, use the following: 

                MMControll.DeviceType = "AVIVideo"
                MMControll.FileName = "c:\windows\skiing.avi" 
                MMControll.Command = "Open"

Conclusion
    In choosing to develop software using one of the popular authoring system, one is limited to the capabilities of the personal computer encapsulated by that particular system, e.g., Director, Toolbook, HyperCard, etc. These authoring systems provide a multimedia equivalent of desktop publishing software, allowing the software developer a means of easily assembling text, pictures, sounds, and video into lively screen presentations. However, in exchange for this ease-of-use, the developer is limited to accessing only those capabilities allowed via the authoring system. The advantage of a true programming language, on the other hand, is its extendibility, i.e., the ability to utilize capabilities beyond those envisioned by the creators of any authoring system. A programming language provides a powerful, flexible, and completely extensible development system (Aitken & Jarol, 1995). With recent advances in user friendliness and the additional capabilities inherent in a true programming language, perhaps it is time to reconsider whether scripting languages really do provide an easier means of developing multimedia software.

References
Aitken, P. & Jarol, S. (1995). Visual C++ multimedia: Adventure set. Scottsdale, AZ: Coriolis Group, Inc.

Goodman, D. (1993). The complete HyperCard 2.2 handbook 4th ed. New York: Random House.

Roberts, J, (1995). Director demystified. Berkeley, CA: Peachpit Press.

Thompson, J. T. (1996). Macromedia director lingo workshop for Macintosh. Indianapolis: Hayden Books.