1/*
2 * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT license.
4 *
5 * Author:
6 *		DarkWyrm, bpmagic@columbus.rr.com
7 */
8#ifndef CDAUDIODEVICE_H
9#define CDAUDIODEVICE_H
10
11#include <List.h>
12#include <String.h>
13#include <SupportDefs.h>
14
15
16// The SCSI table of contents consists of a 4-byte header followed by 100 track
17// descriptors, which are each 8 bytes. We don't really need the first 5 bytes
18// of the track descriptor, so we'll just ignore them. All we really want is the
19// fLength of each track, which happen to be the last 3 bytes of the descriptor.
20typedef struct {
21	uint8	reserved;
22	uint8	adr_control;	// bytes 0-3 are control, 4-7 are ADR
23	uint8	track_number;
24	uint8	reserved2;
25
26	uint8	reserved3;
27	uint8	min;
28	uint8	sec;
29	uint8	frame;
30} TrackDescriptor;
31
32enum CDState {
33	kNoCD = 0,
34	kStopped,
35	kPaused,
36	kPlaying,
37	kSkipping,
38	kError,
39	kInit
40};
41
42
43class CDAudioTime {
44	public:
45		CDAudioTime(const int32 min = -1, const int32 &sec = -1);
46		CDAudioTime(const CDAudioTime &from);
47		CDAudioTime &operator=(const CDAudioTime &from);
48		CDAudioTime operator+(const CDAudioTime &from);
49		CDAudioTime operator-(const CDAudioTime &from);
50
51		void SetMinutes(const int32& minutes)
52		{
53			fMinutes = minutes;
54		}
55
56		void SetSeconds(const int32& seconds)
57		{
58			fSeconds = seconds;
59		}
60
61		int32 GetMinutes() const
62		{
63			return fMinutes;
64		}
65
66		int32 GetSeconds() const
67		{
68			return fSeconds;
69		}
70
71	private:
72		int32	fMinutes;
73		int32	fSeconds;
74};
75
76
77class CDAudioData {
78	public:
79		CDAudioData(const int32 &id = -1, const int32 &count = -1,
80			const int32 &discLength = -1);
81		CDAudioData(const CDAudioData &from);
82		CDAudioData &operator=(const CDAudioData &from);
83
84	private:
85		int32	fDiscId;
86		int32	fTrackCount;
87		int32	fLength;
88		BString fFrameOffsets;
89};
90
91
92class CDAudioDevice {
93	public:
94		CDAudioDevice();
95		~CDAudioDevice();
96
97		bool Play(const int16 &track);
98		bool Pause();
99		bool Resume();
100		bool Stop();
101		bool Eject();
102
103		bool StartFastFwd();
104		bool StopFastFwd();
105
106		bool StartRewind();
107		bool StopRewind();
108
109		bool SetVolume(uint8 value);
110		uint8 GetVolume();
111
112		CDState GetState();
113
114		int16 CountTracks();
115		int16 GetTrack();
116
117		uint8 CountDrives();
118		bool SetDrive(const int32 &drive);
119		const char* GetDrivePath() const;
120
121		int32 GetDrive() const
122		{
123			return fDriveIndex;
124		}
125
126		bool GetTime(CDAudioTime &track, CDAudioTime &disc);
127		bool GetTimeForTrack(const int16 &index, CDAudioTime &track);
128		bool GetTimeForDisc(CDAudioTime &disc);
129		int32 GetDiscID();
130
131		bool IsDataTrack(const int16 &track);
132
133	private:
134		int32 _FindDrives(const char *path);
135
136		int			fFileHandle;
137		BString*	fDrivePath;
138		BList 		fDriveList;
139		int32		fDriveIndex;
140};
141
142#endif	// CDAUDIODEVICE_H
143