1 //------------------------------------------------------------------------------
4 // Unit test for the game kit.
6 // Copyright (c) 2001 OpenBeOS Project
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included
16 // in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
26 // File Name: SimpleSoundTest.h
27 // Author: Christopher ML Zumwalt May (zummy@users.sf.net)
28 // Description: BSimpleGameSound test application
29 //------------------------------------------------------------------------------
36 #include <FilePanel.h>
37 #include <TextControl.h>
39 #include "SimpleGameSound.h"
40 #include "SimpleSoundTest.h"
42 const int32 SLIDER_PAN
= 'SPan';
43 const int32 SLIDER_GAIN
= 'Gain';
44 const int32 BUTTON_START
= 'Strt';
45 const int32 BUTTON_STOP
= 'Stop';
46 const int32 BUTTON_BROWSE
= 'Open';
47 const int32 CHECK_LOOP
= 'Loop';
51 SimpleSoundApp
app("application/x-vnd.OBOS.GameKitApp");
57 // SimpleSoundApp ---------------------------------------------------------
58 SimpleSoundApp::SimpleSoundApp(const char *signature
)
59 : BApplication(signature
)
64 void SimpleSoundApp::ReadyToRun()
66 fWin
= new SimpleSoundWin(BRect(100, 200, 330, 450), "GameKit Unit Test");
71 void SimpleSoundApp::RefsReceived(BMessage
* msg
)
75 msg
->GetInfo("refs", &type
, &count
);
76 if (type
== B_REF_TYPE
)
79 for(int32 i
= 0; i
< count
; i
++)
82 if (msg
->FindRef("refs", i
, &file
) == B_OK
)
84 BSimpleGameSound
* sound
= new BSimpleGameSound(&file
);
86 if (sound
->InitCheck() == B_OK
)
87 fWin
->SetSound(sound
);
96 // SimpleSoundWin ---------------------------------------------------------------
97 SimpleSoundWin::SimpleSoundWin(BRect frame
, const char * title
)
98 : BWindow(frame
, title
, B_TITLED_WINDOW
, B_NOT_RESIZABLE
| B_ASYNCHRONOUS_CONTROLS
),
102 BRect
r(10, 10, 100, 40);
103 fBrowse
= new BButton(r
, "buttonBrowse", "Browse", new BMessage(BUTTON_BROWSE
));
104 fBrowse
->SetEnabled(true);
107 // Add the button which start and stop playback of the choosen sound
109 fStart
= new BButton(r
, "buttonStart", "Start", new BMessage(BUTTON_START
));
110 fStart
->SetEnabled(false);
114 fStop
= new BButton(r
, "buttonStop", "Stop", new BMessage(BUTTON_STOP
));
115 fStop
->SetEnabled(false);
118 // Control the sound's volumn (gain)
119 r
.Set(10, 100, 200, 40);
120 fGain
= new BSlider(r
, "sliderGain", "Gain", new BMessage(SLIDER_GAIN
), 0, 100);
121 fGain
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
122 fGain
->SetHashMarkCount(10);
123 fGain
->SetLimitLabels("Mute", "Full");
124 fGain
->SetPosition(1.0);
125 fGain
->SetEnabled(false);
128 // Control the sound's pan
130 fPan
= new BSlider(r
, "sliderPan", "Pan", new BMessage(SLIDER_PAN
), -100, 100);
131 fPan
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
132 fPan
->SetHashMarkCount(10);
133 fPan
->SetLimitLabels("Left", "Right");
134 fPan
->SetEnabled(false);
137 r
.Set(10, 220, 110, 40);
138 fRamp
= new BTextControl(r
, "txtRamp", "Ramp", "20", NULL
);
139 fRamp
->SetDivider(30);
140 fRamp
->SetEnabled(true);
143 r
.Set(120, 220, 200, 40);
144 fLoop
= new BCheckBox(r
, "chkLoop", "Loop", new BMessage(CHECK_LOOP
));
145 fLoop
->SetEnabled(false);
150 SimpleSoundWin::~SimpleSoundWin()
157 void SimpleSoundWin::Quit()
159 be_app
->PostMessage(B_QUIT_REQUESTED
);
164 void SimpleSoundWin::MessageReceived(BMessage
*msg
)
167 bigtime_t ramp
= bigtime_t(atoi(fRamp
->Text()) * 100000.0);
172 fStop
->SetEnabled(true);
173 fGain
->SetEnabled(true);
174 fPan
->SetEnabled(true);
175 fLoop
->SetEnabled(true);
177 fSound
->StartPlaying();
181 fStop
->SetEnabled(false);
182 fGain
->SetEnabled(false);
183 fPan
->SetEnabled(false);
184 fLoop
->SetEnabled(false);
186 fSound
->StopPlaying();
190 fSound
->SetGain(fGain
->Position(), ramp
);
195 fSound
->SetPan(pos
/ 100.0, ramp
);
199 if (!fPanel
) fPanel
= new BFilePanel(B_OPEN_PANEL
, &be_app_messenger
);
205 fSound
->SetIsLooping(fLoop
->Value() == B_CONTROL_ON
);
209 BWindow::MessageReceived(msg
);
215 void SimpleSoundWin::SetSound(BSimpleGameSound
* sound
)
219 // enable the Start button if we were given a valid sound
222 fStart
->SetEnabled((sound
!= NULL
));
223 fLoop
->SetValue(B_CONTROL_OFF
);
224 fGain
->SetPosition(1.0);
225 fPan
->SetPosition(0.0);