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.
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 thestatusText
slot in the view. By default thestatusText
slot isnil
. You can catch state changes by implementing astatusText
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.
The *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;
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 istrue
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 istrue
), or if it has none (Boolean isnil
).The first two parameters to *
SetState
(oldState
andnewState
in the example) can have the following values:
ThekInactive := 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
kSetupStore
state indicates that recording is about to start. After thekSetupStore
message is sent, the state is immediately set back tokInactive
. ThekStopping
value indicates that recording or playback is about to stop. After it has completely stopped, the state is set tokInactive
.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).
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help