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