HyperTalk and Lingo Scripting for Music Programs

Sam Reese, University of Illinois at Urbana-Champaign

    This article discusses a process for writing scripts for use in multimedia music learning software. It describes software models, identifies key script elements and explains three example applications of these scripts. The focus is on scripts that automate time-based processes such as synchronizing events at a specific time in a piece of music with events that occur on the screen. Some of these processes might be:

    The function of these scripts is to continuously translate a precise time in the music to a precise location on screen or to initiate a specific action on screen at a specific musical time. The scripts use a structure that is efficient and that can be easily customized by others for use in their particular software projects. The article is intended for intermediate-level HyperTalk (HyperCard) and Lingo (Director) scripters.
    Since the step-by-step detail for actually writing these script handlers is too lengthy for this publication, readers are encouraged to download a document which provides the specific instructions for this process. (Reese, 1997)

Rationale
    Teachers of music listening have always faced the difficulty of describing and explaining the elements and structure of pieces of music as these features constantly change over time. Verbal explanations of these features while students are listening are disruptive to focused perception of musical characteristics. Teachers need ways to present information to students precisely at the time that musical events are occurring. For example, if the mode of a piece has changed from major to minor, or the meter from duple to triple, students need to have this pointed out exactly at the time it occurs in order for perception to be improved. For many years, music teachers have developed paper-based aids such as call charts, marked scores, listening maps and other guided listening activities to partially overcome these difficulties.
    Hypermedia presents an additional, powerful means of dealing with music's dynamic nature by presenting text, graphic, or picture information to students at precise times in the music. It can present just the right information in just the right format at just the right time without being obtrusive to the learner's focused perception on the music itself.
    Software that uses time-based events helps users focus attention on specific melodic, rhythmic, harmonic, timbral, or formal events that occur at a specific time in the music by automating a visual event on screen at the time the musical event occurs. For example, the software may be presenting the rhythmic element of meter and is trying to help the novice listener hear the organization of beats into groups. By displaying the numbers "I,,, "T', and "T' on screen at exactly the time the beats occur in the music, the user is more likely to hear and feel the organization of triple meter as he listens. This is only one of many possible examples of how using scripts to synchronize visual, screen events with music events can reinforce perception of musical events.
    To develop hypermedia capable of presenting information to users as music moves through time, knowledge and skill to write time-based scripts is needed. Additionally, a consistent structure is needed to prevent tedious rewriting of scripts for each new piece of music. These skills will be very useful to developers of hypermedia music software designed to develop perceptiveness, analytic ability, and understanding of pieces of music. This information will also be helpful to teachers of multimedia authoring and development courses.

Software Models
    A number of software developers have created HyperCard stacks using both audio CD and MIDI sound sources that synchronize continuously changing music times with events on screen. One example is the HyperCard stack Eine Kleine Nachimusik (Reese, 1992) based on the first movement of Mozart's well-known serenade. It uses MIDI sound sources controlled by the MIDIPlay XCMDs from Opcode. It presents examples of scripts that move arrows on screen over music notation and changes "cards" as the music plays.
    Another example is Listener's Guide (Reese, 1996) which allows listeners to create multimedia listening guides for any piece of music recorded on audio CD or as a standard MIDI file. It automates the switching of "cards" for the listening guide based upon time "markers" identified by the guide author. The author can use the "cards" to present text, graphics, or pictures which explain the important musical events that are occurring at that precise time in the music. It also allows the listeners to navigate forward and backward in the music by dragging an arrow on screen or clicking blocks on a chart which represents the sections of the piece.

Script Elements
    The script examples briefly described below use four main "building blocks": handlers, XFCN's, variables, and HyperCard objects (buttons, fields, cards). Examples are:

External Functions (XFCN's)
    The handlers use XFCN's to get and return values describing the current elapsed time in the music or the length of the piece, whether played from an audio CD or from a standard MIDI file.

Audio CD
    The handlers use two XFCN's from the Apple CD XCMD's (Available in the Voyageur CD AudioStack) for audio CD's: CDElapsedTrack( and CI)TrackTime(tracklVurnber). CDElapsedTrack( returns the current track number and elapsed time from the beginning of the track in a comma separated list.

CI)TrackTime(tracktNumber). returns the length of the specified track in a comma separated list.

Standard MIDI File
   
The handlers use the MIDIfun(function) XFCN from the Opcode MIDIPlay XCMD's (Out of print but available in the Opcode MIDIPlay HyperCard stack). The MIDIfun("status") function returns a string of five words that describe the current state of the MIIX file. Word 3 of this string is the current metrical time in a comma separated list.

    Word 4 of this string is the elapsed time in clocks. The MIDIfun("fileinfo") function returns a string of four words that describe the current file. Word 4 of this string is the length of the file in clock units.

Example 1: Displaying a Counter
   
A simple handler can display a minutes-seconds (audio CD) or a bar-beat (MIDI file) counter in a field. It continuously gets the current time in the music and displays the appropriate numeric values. Figure I shows two examples:


Figure 1: A minutes:seconds counter for audio CD and a barbeat counter for standard MIDI files

Example 2: Changing Cards at a Specific Musical Time
    Handlers can also initiate changes from one card to another at a specific elapsed time in the music. As the music plays, it repeatedly compares the current elapsed time in the music to the ending time for the current card. If they are the same, the card changes.


Figure 2: Changing from one card to the next at a specific elapsed time in the music.

Example 3: Moving an arrow on screen in relation to a chart or phrase of music notation
   
Handlers can move an arrow button on screen proportionate to the amount of time that has elapsed in the music. As the music plays, it continuously translates a specific time in the music to a pixel location on screen and sets the arrow to that location.


Figure 3: Moving an arrow on screen proportionate to the amount of time elapsed in the music.

To illustrate, the following script moves an on-screen arrow in proportion to the amount of music that has been played from a track of an audio CD.

        on idle
                global ratio
                get CDElapsedTrack(
                put ((item 2 of it) 60) * 75 into curMin
                put (item 3 of it) 75 into curSec
                put item 4 of it into curBlk
                put curMin + curSec + curBlk into curTime
                put (round of (ratio * curTime)) into newLoc
                set the left of background button "Pointer" to newLoc + 7
        end idle

    This script changes cards at a precise time in the music being played from a standard MIDI file

        on idle
                global sectionTimes
                put item 1 to 2 of word 3 of MIDIfun("status") into currentTime
                put word 3 of the short name of
this card into currentSection 
                if currentTime = (item 6 to 7 of line currentSection of sectionTimes) then
   
                     go to next card of this background
                end if
        end idle

Note. For detailed explanations of the process for writing these scripts, the reader is again encouraged to download "Time-Based Scripts for Synchronizing Music Events with Screen Events." (Reese, 1997)

References
Reese, S. (1992). Eine Kleine Nachtmusik [Computer software]. Champaign, IL: Electronic Courseware Systems.

Reese, S. (1996). Listener's Guide [Unpublished computer software]. Available on the World Wide Web at http//camil40.music.uiuc.edu/faculty/reese/guide.htmI

Reese, S. (1997). Time-based scripts for synchronizing music events with screen events. Unpublished manuscript. Available on the World Wide Web at http://camil40.music.uiuc.edu/Projects/tbmi/ teaching/scripting/download.htmI