a test program for BFileGameSound, written by Tim de Jong

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1291 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2002-09-29 16:18:18 +00:00
parent 6991af8cd8
commit 716d20e1e9
7 changed files with 361 additions and 0 deletions

View File

@ -1,6 +1,7 @@
SubDir OBOS_TOP src tests kits ; SubDir OBOS_TOP src tests kits ;
SubInclude OBOS_TOP src tests kits app ; SubInclude OBOS_TOP src tests kits app ;
SubInclude OBOS_TOP src tests kits game ;
SubInclude OBOS_TOP src tests kits interface ; SubInclude OBOS_TOP src tests kits interface ;
SubInclude OBOS_TOP src tests kits media ; SubInclude OBOS_TOP src tests kits media ;
SubInclude OBOS_TOP src tests kits midi ; SubInclude OBOS_TOP src tests kits midi ;

View File

@ -0,0 +1,4 @@
SubDir OBOS_TOP src tests kits game ;
SubInclude OBOS_TOP src tests kits game file_game_sound_test ;

View File

@ -0,0 +1,26 @@
/**Class to test the BFileGameSound class
@author Tim de Jong
@date 21/09/2002
@version 1.0
*/
#include "FileSoundTest.h"
#include "FileSoundWindow.h"
#include <Rect.h>
int main()
{
FileSoundTest test;
test.Run();
return 0;
}
FileSoundTest::FileSoundTest()
:BApplication("application/x-vnd.FileSoundTest")
{
//show app window
BRect windowBounds(50,50,400,170);
FileSoundWindow *window = new FileSoundWindow(windowBounds);
window -> Show();
}

View File

@ -0,0 +1,18 @@
/**Class to test the BFileGameSound class
@author Tim de Jong
@date 21/09/2002
@version 1.0
*/
#ifndef FILE_SOUND_TEST
#define FILE_SOUND_TEST
#include <Application.h>
#include <FileGameSound.h>
class FileSoundTest: public BApplication
{
public:
FileSoundTest();
};
#endif

View File

@ -0,0 +1,257 @@
/**App window for the FileSoundWindow test
@author Tim de Jong
@date 21/09/2002
@version 1.0
*/
#include "FileSoundWindow.h"
#include <Application.h>
#include <Box.h>
#include <TextControl.h>
#include <Button.h>
#include <CheckBox.h>
#include <Alert.h>
#include <Path.h>
#include <stdio.h>
#include <stdlib.h>
FileSoundWindow::FileSoundWindow(BRect windowBounds)
:BWindow(windowBounds,"BFileGameSound test",B_TITLED_WINDOW,B_NOT_ZOOMABLE|B_NOT_RESIZABLE)
{
//init private vars
loop = false;
preload = false;
playing = false;
rampTime = 0;
//make openPanel and let it send its messages to this window
openPanel = new BFilePanel();
openPanel -> SetTarget(this);
//get appBounds
BRect appBounds = Bounds();
//make a cosmetic box
BBox *box = new BBox(appBounds);
//textcontrol to display the chosen file
BRect textBounds(appBounds.left + 10, appBounds.top + 10, appBounds.right - 70, appBounds.top + 20);
textControl = new BTextControl(textBounds,"filechosen","Play File:","No file chosen yet.", NULL);
textControl -> SetEnabled(false);
float x1 = textControl -> Bounds().left;
float x2 = textControl -> Bounds().right;
float dividerX = 0.20 * (x2 - x1);
textControl -> SetDivider(dividerX);
box -> AddChild(textControl);
//button to choose file
BRect browseBounds(textBounds.right + 5,textBounds.top, appBounds.right - 5, textBounds.bottom);
BMessage *browseMessage = new BMessage(BROWSE_MSG);
BButton *browseButton = new BButton(browseBounds,"browseButton","Browse" B_UTF8_ELLIPSIS,browseMessage);
box -> AddChild(browseButton);
//make play button
BRect playBounds(textBounds.left,textBounds.bottom + 15, textBounds.left + 50, textBounds.bottom + 25);
BMessage *playMessage = new BMessage(PLAY_MSG);
playButton = new BButton(playBounds,"playbutton","Play", playMessage);
box -> AddChild(playButton);
//make pause button
BRect pauseBounds(playBounds.right + 10,playBounds.top, playBounds.right + 60, playBounds.bottom);
BMessage *pauseMessage = new BMessage(PAUSE_MSG);
pauseButton = new BButton(pauseBounds,"pausebutton","Pause",pauseMessage);
box -> AddChild(pauseButton);
//make textcontrol to enter delay for pausing/resuming
BRect delayBounds(pauseBounds.right + 10, pauseBounds.top,pauseBounds.right + 50, pauseBounds.bottom);
BMessage *delayMessage = new BMessage(DELAY_MSG);
delayControl = new BTextControl(delayBounds,"delay","","",delayMessage);
delayControl -> SetDivider(0);
box -> AddChild(delayControl);
//make loop checkbox
BRect loopBounds(playBounds.left,playBounds.bottom + 20, playBounds.left + 150, playBounds.bottom + 30);
BMessage *loopMessage = new BMessage(LOOP_MSG);
loopCheck = new BCheckBox(loopBounds,"loopcheckbox","Loop the sound file",loopMessage);
box -> AddChild(loopCheck);
//make preload checkbox
BRect preloadBounds(loopBounds.right + 10,loopBounds.top, loopBounds.right + 150, loopBounds.bottom);
BMessage *preloadMessage = new BMessage(PRELOAD_MSG);
preloadCheck = new BCheckBox(preloadBounds,"loopcheckbox","Preload the sound file",preloadMessage);
box -> AddChild(preloadCheck);
//add background box to window
AddChild(box);
}
FileSoundWindow::~FileSoundWindow()
{
//delete openPanel;
//delete fileSound;
}
void FileSoundWindow::MessageReceived(BMessage *message)
{
switch (message -> what)
{
case BROWSE_MSG:
openPanel -> Show();
break;
case B_REFS_RECEIVED:
{
message->FindRef("refs", 0, &fileref);
BPath path(new BEntry(&fileref));
textControl -> SetText(path.Path());
}
break;
case PLAY_MSG:
{
if (!playing)
{
fileSound = new BFileGameSound(&fileref,loop);
status_t error = fileSound -> InitCheck();
if (error != B_OK)
{
if (error == B_NO_MEMORY)
{
BAlert *alert = new BAlert("alert","Not enough memory.","Ok");
alert -> Go();
}
else if (error == B_ERROR)
{
BAlert *alert = new BAlert("alert","Unable to create a sound player.","Ok");
alert -> Go();
}
else
{
BAlert *alert = new BAlert("alert","Other kind of error!","Ok");
alert -> Go();
}
}
//preload sound file?
if (preload)
{
status_t preloadError = fileSound -> Preload();
if (preloadError != B_OK)
{
BAlert *alert = new BAlert("alert","Port errors. Unable to communicate with the streaming sound port.","Ok");
alert -> Go();
}
}
//play it!
status_t playerror = fileSound -> StartPlaying();
if (playerror != B_OK)
{
if (playerror == EALREADY)
{
BAlert *alert = new BAlert("alert","Sound is already playing","Ok");
alert -> Go();
}
else
{
BAlert *alert = new BAlert("alert","Error playing sound","Ok");
alert -> Go();
}
}
else
{
playButton -> SetLabel("Stop");
playing = true;
}
}
else
{
//stop it!
status_t stoperror = fileSound -> StopPlaying();
if (stoperror != B_OK)
{
if (stoperror == EALREADY)
{
BAlert *alert = new BAlert("alert","Sound is already stopped","Ok");
alert -> Go();
}
else
{
BAlert *alert = new BAlert("alert","Error stopping sound","Ok");
alert -> Go();
}
}
else
{
playButton -> SetLabel("Play");
playing = false;
}
}
}
break;
case PAUSE_MSG:
{
int32 pausedValue = fileSound -> IsPaused();
if (pausedValue != BFileGameSound::B_PAUSE_IN_PROGRESS)
{
status_t error;
char *label;
if (paused)
{
paused = false;
label = "Pause";
error = fileSound ->SetPaused(paused, rampTime);
}
else
{
paused = true;
label = "Resume";
error = fileSound ->SetPaused(paused, rampTime);
}
if (error != B_OK)
{
if (error == EALREADY)
{
BAlert *alert = new BAlert("alert","Already in requested state","Ok");
alert -> Go();
}
else
{
BAlert *alert = new BAlert("alert","Error!","Ok");
alert -> Go();
}
}
else
{
pauseButton -> SetLabel(label);
}
}
}
break;
case LOOP_MSG:
{
int32 checkValue = loopCheck -> Value();
if (checkValue == B_CONTROL_ON)
loop = true;
else loop = false;
}
break;
case PRELOAD_MSG:
{
int32 checkValue = preloadCheck -> Value();
if (checkValue == B_CONTROL_ON)
preload = true;
else preload = false;
}
break;
case DELAY_MSG:
{
//set delay time for resuming/pausing
rampTime = atol(delayControl -> Text());
}
break;
}
}
bool FileSoundWindow::QuitRequested()
{
/*if (fileSound != 0 && fileSound -> IsPlaying())
fileSound -> StopPlaying();*/
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
}

View File

@ -0,0 +1,48 @@
/**App window for the FileSoundWindow test
@author Tim de Jong
@date 21/09/2002
@version 1.0
*/
#ifndef FILE_SOUND_WINDOW
#define FILE_SOUND_WINDOW
#include <Window.h>
#include <Rect.h>
#include <Message.h>
#include <FileGameSound.h>
#include <Entry.h>
#include <FilePanel.h>
//message constants
#define BROWSE_MSG 1
#define PLAY_MSG 2
#define PAUSE_MSG 3
#define LOOP_MSG 4
#define PRELOAD_MSG 5
#define DELAY_MSG 6
class FileSoundWindow : public BWindow
{
public:
FileSoundWindow(BRect windowBounds);
virtual ~FileSoundWindow();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
private:
BCheckBox *loopCheck;
BCheckBox *preloadCheck;
BFileGameSound *fileSound;
BFilePanel *openPanel;
BTextControl *textControl;
BButton *playButton;
BButton *pauseButton;
BTextControl *delayControl;
//private variables
bool loop;
bool paused;
bool preload;
bool playing;
bigtime_t rampTime;
entry_ref fileref;
};
#endif

View File

@ -0,0 +1,7 @@
SubDir OBOS_TOP src tests kits game file_game_sound_test ;
SimpleTest file_game_sound_test
: FileSoundTest.cpp FileSoundWindow.cpp
: game tracker be root
;