BSimpleGameSound test application

contributed by Christopher ML Zumwalt May


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1586 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2002-10-21 16:56:53 +00:00
parent 6eaf18596d
commit b518f06251
4 changed files with 310 additions and 0 deletions

View File

@ -2,4 +2,5 @@ SubDir OBOS_TOP src tests kits game ;
SubInclude OBOS_TOP src tests kits game file_game_sound_test ;
SubInclude OBOS_TOP src tests kits game set_mouse_position_test ;
SubInclude OBOS_TOP src tests kits game simple_game_sound_test ;

View File

@ -0,0 +1,6 @@
SubDir OBOS_TOP src tests kits game simple_game_sound_test ;
SimpleTest simple_game_sound_test
: SimpleSoundTest.cpp
: game tracker be root
;

View File

@ -0,0 +1,228 @@
//------------------------------------------------------------------------------
// SimpleSoundTest.cpp
//
// Unit test for the game kit.
//
// Copyright (c) 2001 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: SimpleSoundTest.h
// Author: Christopher ML Zumwalt May (zummy@users.sf.net)
// Description: BSimpleGameSound test application
//------------------------------------------------------------------------------
#include <stdlib.h>
#include <Button.h>
#include <Slider.h>
#include <CheckBox.h>
#include <FilePanel.h>
#include <TextControl.h>
#include <SimpleGameSound.h>
#include <SimpleSoundTest.h>
const int32 SLIDER_PAN = 'SPan';
const int32 SLIDER_GAIN = 'Gain';
const int32 BUTTON_START = 'Strt';
const int32 BUTTON_STOP = 'Stop';
const int32 BUTTON_BROWSE = 'Open';
const int32 CHECK_LOOP = 'Loop';
int main(int, char**)
{
SimpleSoundApp app("application/x-vnd.OBOS.GameKitApp");
app.Run();
return 0;
}
// SimpleSoundApp ---------------------------------------------------------
SimpleSoundApp::SimpleSoundApp(const char *signature)
: BApplication(signature)
{
}
void SimpleSoundApp::ReadyToRun()
{
fWin = new SimpleSoundWin(BRect(100, 200, 330, 450), "GameKit Unit Test");
fWin->Show();
}
void SimpleSoundApp::RefsReceived(BMessage* message)
{
uint32 type;
int32 count;
message->GetInfo("refs", &type, &count);
if (type == B_REF_TYPE)
{
// Load the files
for(int32 i = 0; i < count; i++)
{
entry_ref file;
if (message->FindRef("refs", i, &file) == B_OK)
{
BSimpleGameSound * sound = new BSimpleGameSound(&file);
if (sound->InitCheck() == B_OK)
fWin->SetSound(sound);
else
delete sound;
}
}
}
}
// SimpleSoundWin ---------------------------------------------------------------
SimpleSoundWin::SimpleSoundWin(BRect frame, const char * title)
: BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS)
{
BRect r(10, 10, 100, 40);
fBrowse = new BButton(r, "buttonBrowse", "Browse", new BMessage(BUTTON_BROWSE));
fBrowse->SetEnabled(true);
AddChild(fBrowse);
// Add the button which start and stop playback of the choosen sound
r.OffsetBy(0, 50);
fStart = new BButton(r, "buttonStart", "Start", new BMessage(BUTTON_START));
fStart->SetEnabled(false);
AddChild(fStart);
r.OffsetBy(110, 0);
fStop = new BButton(r, "buttonStop", "Stop", new BMessage(BUTTON_STOP));
fStop->SetEnabled(false);
AddChild(fStop);
// Control the sound's volumn (gain)
r.Set(10, 100, 200, 40);
fGain = new BSlider(r, "sliderGain", "Gain", new BMessage(SLIDER_GAIN), 0, 100);
fGain->SetHashMarks(B_HASH_MARKS_BOTTOM);
fGain->SetHashMarkCount(10);
fGain->SetLimitLabels("Mute", "Full");
fGain->SetPosition(1.0);
fGain->SetEnabled(false);
AddChild(fGain);
// Control the sound's pan
r.OffsetBy(0, 60);
fPan = new BSlider(r, "sliderPan", "Pan", new BMessage(SLIDER_PAN), -100, 100);
fPan->SetHashMarks(B_HASH_MARKS_BOTTOM);
fPan->SetHashMarkCount(10);
fPan->SetLimitLabels("Left", "Right");
fPan->SetEnabled(false);
AddChild(fPan);
r.Set(10, 220, 110, 40);
fRamp = new BTextControl(r, "txtRamp", "Ramp", "20", NULL);
fRamp->SetDivider(30);
fRamp->SetEnabled(true);
AddChild(fRamp);
r.Set(120, 220, 200, 40);
fLoop = new BCheckBox(r, "chkLoop", "Loop", new BMessage(CHECK_LOOP));
fLoop->SetEnabled(false);
AddChild(fLoop);
}
SimpleSoundWin::~SimpleSoundWin()
{
delete fPanel;
delete fSound;
}
void SimpleSoundWin::Quit()
{
be_app->PostMessage(B_QUIT_REQUESTED);
BWindow::Quit();
}
void SimpleSoundWin::MessageReceived(BMessage *msg)
{
int32 pos;
bigtime_t ramp = bigtime_t(atoi(fRamp->Text()) * 100000.0);
switch (msg->what)
{
case BUTTON_START:
fStop->SetEnabled(true);
fGain->SetEnabled(true);
fPan->SetEnabled(true);
fLoop->SetEnabled(true);
fSound->StartPlaying();
break;
case BUTTON_STOP:
fStop->SetEnabled(false);
fGain->SetEnabled(false);
fPan->SetEnabled(false);
fLoop->SetEnabled(false);
fSound->StopPlaying();
break;
case SLIDER_GAIN:
fSound->SetGain(fGain->Position(), ramp);
break;
case SLIDER_PAN:
pos = fPan->Value();
fSound->SetPan(pos / 100.0, ramp);
break;
case BUTTON_BROWSE:
if (!fPanel) fPanel = new BFilePanel(B_OPEN_PANEL, &be_app_messenger);
fPanel->Show();
break;
case CHECK_LOOP:
fSound->SetIsLooping(fLoop->Value() == B_CONTROL_ON);
break;
default:
BWindow::MessageReceived(msg);
break;
}
}
void SimpleSoundWin::SetSound(BSimpleGameSound * sound)
{
delete fSound;
// enable the Start button if we were given a valid sound
Lock();
fStart->SetEnabled((sound != NULL));
fLoop->SetValue(B_CONTROL_OFF);
fGain->SetPosition(1.0);
fPan->SetPosition(0.0);
Unlock();
fSound = sound;
}

View File

@ -0,0 +1,75 @@
//------------------------------------------------------------------------------
// SimpleSoundTest.h
//
// Unit test for the game kit.
//
// Copyright (c) 2001 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: SimpleSoundTest.h
// Author: Christopher ML Zumwalt May (zummy@users.sf.net)
// Description: BSimpleGameSound test application
//------------------------------------------------------------------------------
#ifndef _SIMPLESOUNDTEST_H
#define _SIMPLESOUNDTEST_H
#include <Application.h>
#include <Window.h>
class SimpleSoundWin : public BWindow
{
public:
SimpleSoundWin(BRect frame, const char * title);
~SimpleSoundWin();
void Quit();
void MessageReceived(BMessage* msg);
void SetSound(BSimpleGameSound* sound);
private:
BSlider * fGain;
BSlider * fPan;
BButton * fBrowse;
BButton * fStart;
BButton * fStop;
BCheckBox * fLoop;
BTextControl * fRamp;
BSimpleGameSound * fSound;
BFilePanel * fPanel;
};
class SimpleSoundApp : public BApplication
{
public:
SimpleSoundApp(const char * signature);
void ReadyToRun();
void RefsReceived(BMessage * message);
private:
SimpleSoundWin * fWin;
};
#endif