1 /*
2 * music_cdrom.c music server CDROM part
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: music_cdrom.c,v 1.2 2002/09/01 11:54:51 chikama Exp $ */
23
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "portab.h"
28 #include "music_server.h"
29 #include "music_cdrom.h"
30 #include "cdrom.h"
31
32 enum {
33 CDROM_START,
34 CDROM_STOPCHECK,
35 CDROM_LOOPCHECK,
36 CDROM_STOP,
37 CDROM_NOP
38 };
39
muscd_init()40 int muscd_init() {
41 int st = cd_init(&prv.cddev);
42 int ret;
43
44 if (st == -1) {
45 prv.cd_valid = FALSE;
46 ret = NG;
47 } else {
48 prv.cd_valid = TRUE;
49 prv.cdrom.dev = &prv.cddev;
50 prv.cdrom.st = CDROM_NOP;
51 prv.cdrom.in_play = FALSE;
52 ret = OK;
53 }
54
55 return ret;
56 }
57
muscd_exit()58 int muscd_exit() {
59 if (prv.cd_valid) {
60 prv.cddev.exit();
61 }
62 return OK;
63 }
64
muscd_start(int trk,int loop)65 int muscd_start(int trk, int loop) {
66 prv.cdrom.track = trk;
67 prv.cdrom.loop = loop;
68 prv.cdrom.cnt = 0;
69
70 prv.cdrom.st = CDROM_START;
71 prv.cdrom.in_play = FALSE;
72
73 memset(&prv.cdrom.time, 0, sizeof(cd_time));
74
75 return OK;
76 }
77
muscd_stop()78 int muscd_stop() {
79 prv.cdrom.st = CDROM_STOP;
80 return OK;
81 }
82
muscd_getpos()83 cd_time muscd_getpos() {
84 cd_time tm;
85 prv.cddev.getpos(&tm);
86 return tm;
87 }
88
muscd_cb()89 int muscd_cb() {
90 cdobj_t *obj = &prv.cdrom;
91
92 switch(obj->st) {
93 case CDROM_START:
94 obj->in_play = TRUE;
95 obj->dev->start(obj->track);
96 obj->st = CDROM_STOPCHECK;
97 break;
98 case CDROM_STOPCHECK:
99 if (NG == obj->dev->getpos(&(obj->time))) {
100 obj->st = CDROM_LOOPCHECK;
101 }
102 break;
103 case CDROM_LOOPCHECK:
104 obj->cnt++;
105 if (obj->loop == 0) {
106 obj->st = CDROM_START;
107 break;
108 }
109 if (--obj->loop == 0) {
110 obj->st = CDROM_STOP;
111 } else {
112 obj->st = CDROM_START;
113 }
114 break;
115 case CDROM_STOP:
116 obj->dev->stop();
117
118 obj->in_play = FALSE;
119 obj->st = CDROM_NOP;
120 break;
121 case CDROM_NOP:
122 break;
123 }
124
125 return OK;
126 }
127