Added CD Audio support for OpenAL.
[blender-staging.git] / intern / SoundSystem / sdl / SND_SDLCDDevice.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * SND_SDLCDDevice
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #ifdef WIN32
39 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
40 #endif //WIN32
41
42 #include "MT_Scalar.h"
43
44 #include "SND_SDLCDDevice.h"
45 #include "SoundDefines.h"
46
47 #include <SDL.h>
48
49 SND_SDLCDDevice::SND_SDLCDDevice() :
50         m_cdrom(NULL),
51         m_cdplaying(false),
52         m_cdtrack(0),
53         m_cdplaymode(SND_CD_TRACK),
54         m_frame(0)
55 {
56         init();
57 }
58
59 void SND_SDLCDDevice::init()
60 {
61         if (SDL_InitSubSystem(SDL_INIT_CDROM))
62         {
63                 fprintf(stderr, "Error initializing CDROM\n");
64                 return;
65         }
66         
67         /* Check for CD drives */
68         if(!SDL_CDNumDrives())
69         {
70                 /* None found */
71                 fprintf(stderr, "No CDROM devices available\n");
72                 return;
73         }
74
75         /* Open the default drive */
76         m_cdrom = SDL_CDOpen(0);
77
78         /* Did if open? Check if cdrom is NULL */
79         if(!m_cdrom)
80         {
81                 fprintf(stderr, "Couldn't open drive: %s", SDL_GetError());
82                 return;
83         }
84 }
85
86 SND_SDLCDDevice::~SND_SDLCDDevice()
87 {
88         StopCD();
89         SDL_CDClose(m_cdrom);
90 }
91
92 void SND_SDLCDDevice::NextFrame()
93 {
94         m_frame++;
95         m_frame &= 127;
96         
97         if (!m_frame && m_cdrom && m_cdplaying && SDL_CDStatus(m_cdrom) == CD_STOPPED)
98         {
99                 switch (m_cdplaymode)
100                 {
101                         case SND_CD_ALL:
102                                 if (m_cdtrack < m_cdrom->numtracks)
103                                         PlayCD(m_cdtrack + 1);
104                                 else
105                                         m_cdplaying = false;
106                                 break;
107                         default:
108                         case SND_CD_TRACK:
109                                 m_cdplaying = false;
110                                 break;
111                         case SND_CD_TRACKLOOP:
112                                 PlayCD(m_cdtrack);
113                                 break;
114                 }
115         
116         }
117 }
118         
119 void SND_SDLCDDevice::PlayCD(int track)
120 {
121         if ( m_cdrom && CD_INDRIVE(SDL_CDStatus(m_cdrom)) ) {
122                 SDL_CDPlayTracks(m_cdrom, track-1, 0, track, 0);
123                 m_cdplaying = true;
124                 m_cdtrack = track;
125         }
126 }
127
128
129 void SND_SDLCDDevice::PauseCD(bool pause)
130 {
131         if (!m_cdrom)
132                 return;
133                 
134         if (pause)
135                 SDL_CDPause(m_cdrom);
136         else
137                 SDL_CDResume(m_cdrom);
138 }
139
140 void SND_SDLCDDevice::StopCD()
141 {
142         if (m_cdrom)
143                 SDL_CDStop(m_cdrom);
144         m_cdplaying = false;
145 }
146
147 void SND_SDLCDDevice::SetCDPlaymode(int playmode)
148 {
149         m_cdplaymode = playmode;
150 }
151
152 void SND_SDLCDDevice::SetCDGain(MT_Scalar gain)
153 {
154
155 }