TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
musicplayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : musicplayer.cpp
4 created : Fri Dec 23 17:35:18 CET 2011
5 copyright : (C) 2011 Bernhard Wymann
6 email : berniw@bluewin.ch
7 version : $Id$
8
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#include "musicplayer.h"
21
22#include <GL/glut.h>
23#include <string.h>
24#include <tgf.h>
25#include <portability.h>
26
27#include "OggSoundStream.h"
28#include "OpenALMusicPlayer.h"
29
30
31static bool isEnabled()
32{
33 const int BUFSIZE = 1024;
34 char buf[BUFSIZE];
35 snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), MM_SOUND_PARM_CFG);
36 bool enabled = false;
37
40
41 if (strcmp(s, MM_VAL_SOUND_ENABLED) == 0) {
42 enabled = true;
43 }
44
45 GfParmReleaseHandle(handle);
46 return enabled;
47}
48
49
50// Path relative to CWD, e.g "data/music/torcs1.ogg"
51static SoundStream* getMenuSoundStream(char* oggFilePath)
52{
53 static OggSoundStream stream(oggFilePath);
54 return &stream;
55}
56
57
59{
60 const int BUFSIZE = 1024;
61 char oggFilePath[BUFSIZE];
62 strncpy(oggFilePath, "data/music/torcs1.ogg", BUFSIZE);
63
64 static OpenALMusicPlayer player(getMenuSoundStream(oggFilePath));
65 return &player;
66}
67
68
69static void playMenuMusic(int /* value */)
70{
71 const int nextcallinms = 100;
72
74 if (player->playAndManageBuffer()) {
75 glutTimerFunc(nextcallinms, playMenuMusic, 0);
76 }
77}
78
79
81{
82 if (isEnabled()) {
84 player->start();
86 }
87}
88
89
91{
93 player->stop();
94 player->rewind();
95}
virtual bool playAndManageBuffer()
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
Definition params.cpp:2453
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
Definition params.cpp:1963
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition params.cpp:1173
static SoundStream * getMenuSoundStream(char *oggFilePath)
void stopMenuMusic()
static OpenALMusicPlayer * getMusicPlayer()
void startMenuMusic()
static bool isEnabled()
static void playMenuMusic(int)
#define MM_ATT_SOUND_ENABLE
Definition musicplayer.h:25
#define MM_SOUND_PARM_CFG
Definition musicplayer.h:23
#define MM_SCT_SOUND
Definition musicplayer.h:24
#define MM_VAL_SOUND_ENABLED
Definition musicplayer.h:26
#define MM_VAL_SOUND_DISABLED
Definition musicplayer.h:27
char * GetLocalDir(void)
Definition tgf.cpp:230
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
Definition tgf.h:266
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
Definition tgf.h:264