Title Banner

Previous Book Contents Book Index Next

Newton Developer Technical Information: Newton Programmer's Guide: 2.1 OS Addendum /
Chapter 7 - Sound / Using Sound


Using the protoRecorderView

The system includes a new proto, *protoRecorderView, that implements a simple user interface object to record and play sounds. The proto incorporates all the code necessary to record and play sounds. You can use this proto to add sound recording and playback capabilities to any application by embedding it in a view in the application. The proto is shown in Figure 7-3.

Figure 7-3 protoRecorderView



You retrieve the sound data recorded in a *protoRecorderView by sending the view the *GetSounds message. This method returns the array of sound frames recorded.

The recorder (*protoRecorderView) has an internal state that changes when the user taps one of its buttons. Each time there's an event that causes a state change, the recorder sends a *SetState message to the statusText slot in the view. By default the statusText slot is nil. You can catch state changes by implementing a statusText slot that contains a frame that contains a *SetState method. For example, here is how you could implement such a frame to handle the *SetState message.

myProtoRecorderView.ViewSetupFormScript := func()

begin self.statusText := { _parent: self, // only if you want to call inherited SetState: func(oldState, newState, hasSound) begin // do your work here // for example, catch a transition to the stopped state // and call GetSounds to retrieve the recorded sounds end, } end;

The *SetState method is called with three parameters. The first, (oldState in the example) is an integer representing the recorder's previous state; the second (newState in the example) is an integer representing the recorder's new state; and the third (hasSound in the example) is a Boolean that is true if the recorder currently has some sound frames defined. This last parameter allows you to determine if the recorder view has any data to play (Boolean is true), or if it has none (Boolean is nil).

The first two parameters to *SetState (oldState and newState in the example) can have the following values:

kInactive := 1; // default state (stopped)

kRecording := 2; // sent before recording is started kPlaying := 4; // sent before playing is started kPlayPaused := 8; // sent before playing is paused kRecordPaused := 16; // sent before recording is paused kStopping := 32; // sent before the sound channel is stopped kSetupStore := 64; // sent before recording is started

The kSetupStore state indicates that recording is about to start. After the kSetupStore message is sent, the state is immediately set back to kInactive. The kStopping value indicates that recording or playback is about to stop. After it has completely stopped, the state is set to kInactive.

If you want to explicitly set the store where recorded sounds are stored by the recorder view, you can set the slot *protoRecorderView.RecordEngine.fStore to the destination store. Otherwise the default store is used for recorded sounds (in VBOs).


Previous Book Contents Book Index Next

© Apple Computer, Inc.
26 APR 1997



Navigation graphic, see text links

Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help