diff --git a/src/tests/kits/Jamfile b/src/tests/kits/Jamfile index eb611bf836..ac00c630a7 100644 --- a/src/tests/kits/Jamfile +++ b/src/tests/kits/Jamfile @@ -1,6 +1,7 @@ SubDir OBOS_TOP src tests kits ; 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 media ; SubInclude OBOS_TOP src tests kits midi ; diff --git a/src/tests/kits/game/Jamfile b/src/tests/kits/game/Jamfile new file mode 100644 index 0000000000..525f09f454 --- /dev/null +++ b/src/tests/kits/game/Jamfile @@ -0,0 +1,4 @@ +SubDir OBOS_TOP src tests kits game ; + +SubInclude OBOS_TOP src tests kits game file_game_sound_test ; + diff --git a/src/tests/kits/game/file_game_sound_test/FileSoundTest.cpp b/src/tests/kits/game/file_game_sound_test/FileSoundTest.cpp new file mode 100644 index 0000000000..2238ae220e --- /dev/null +++ b/src/tests/kits/game/file_game_sound_test/FileSoundTest.cpp @@ -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 + +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(); +} \ No newline at end of file diff --git a/src/tests/kits/game/file_game_sound_test/FileSoundTest.h b/src/tests/kits/game/file_game_sound_test/FileSoundTest.h new file mode 100644 index 0000000000..3ccdec3c08 --- /dev/null +++ b/src/tests/kits/game/file_game_sound_test/FileSoundTest.h @@ -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 +#include + +class FileSoundTest: public BApplication +{ + public: + FileSoundTest(); +}; +#endif \ No newline at end of file diff --git a/src/tests/kits/game/file_game_sound_test/FileSoundWindow.cpp b/src/tests/kits/game/file_game_sound_test/FileSoundWindow.cpp new file mode 100644 index 0000000000..0b07f5b170 --- /dev/null +++ b/src/tests/kits/game/file_game_sound_test/FileSoundWindow.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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); +} \ No newline at end of file diff --git a/src/tests/kits/game/file_game_sound_test/FileSoundWindow.h b/src/tests/kits/game/file_game_sound_test/FileSoundWindow.h new file mode 100644 index 0000000000..f20e73bfff --- /dev/null +++ b/src/tests/kits/game/file_game_sound_test/FileSoundWindow.h @@ -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 +#include +#include +#include +#include +#include +//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 \ No newline at end of file diff --git a/src/tests/kits/game/file_game_sound_test/Jamfile b/src/tests/kits/game/file_game_sound_test/Jamfile new file mode 100644 index 0000000000..0c0fe06171 --- /dev/null +++ b/src/tests/kits/game/file_game_sound_test/Jamfile @@ -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 +; +