aboutsummaryrefslogtreecommitdiffstats
path: root/audio/tcd/files/patch-tcd.c
blob: 435bdfbe2cc61c7cbcda61865ef3117e04917a5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
--- src/tcd.c.orig  2004-06-15 22:32:31.000000000 +0200
+++ src/tcd.c   2008-07-25 13:25:50.000000000 +0200
@@ -33,6 +33,7 @@
 #include <unistd.h>
 
 #include <SDL/SDL.h>
+#include <sys/cdio.h>
 
 #include "cd-utils.h"
 #include "cddb.h"
@@ -80,37 +81,40 @@
 
 static void handle_next_track(void)
 {
-    if (!CD_INDRIVE(state.cdrom->status)) {
+    int next_track;
+
+    if (!CD_INDRIVE(state.cdrom->status))
         return;
-    }
-    if (state.cdrom->cur_track == state.cdrom->numtracks - 1) {
-        SDL_CDStop(state.cdrom);
-    } else if (state.play_method == REPEAT_TRK) {
-        SDL_CDPlayTracks(state.cdrom, state.cdrom->cur_track + 1, 0, 1, 0);
-    } else {
-        SDL_CDPlayTracks(state.cdrom, state.cdrom->cur_track + 1, 0, 0, 0);
-    }
+
+    if (state.cdrom->cur_track == state.cdrom->numtracks - 1)
+   next_track = 0;
+    else
+   next_track = state.cdrom->cur_track + 1;
+
+    if (state.play_method == REPEAT_TRK)
+        SDL_CDPlayTracks(state.cdrom, next_track, 0, 1, 0);
+    else
+        SDL_CDPlayTracks(state.cdrom, next_track, 0, 0, 0);
 }
 
 static void handle_prev_track(void)
 {
     int prev_track;
 
-    if (!CD_INDRIVE(state.cdrom->status)) {
+    if (!CD_INDRIVE(state.cdrom->status))
         return;
-    }
-    if (state.cdrom->cur_track == 0) {
-        prev_track = 0;
-    } else if (state.cdrom->cur_frame / CD_FPS < 5) {
-        prev_track = state.cdrom->cur_track - 1;
-    } else {
+
+    if (state.cdrom->cur_frame / CD_FPS > 5)
         prev_track = state.cdrom->cur_track;
-    }
-    if (state.play_method == REPEAT_TRK) {
+    else if (state.cdrom->cur_track == 0)
+   prev_track = state.cdrom->numtracks - 1;
+    else
+   prev_track = state.cdrom->cur_track - 1;
+
+    if (state.play_method == REPEAT_TRK)
         SDL_CDPlayTracks(state.cdrom, prev_track, 0, 1, 0);
-    } else {
+    else
         SDL_CDPlayTracks(state.cdrom, prev_track, 0, 0, 0);
-    }
 }
 
 static void handle_goto(void)
@@ -134,11 +138,6 @@
     }
 }
 
-static void handle_repeat_track(void)
-{
-    state.play_method = REPEAT_TRK;
-}
-
 static void handle_eject(void)
 {
     SDL_CDEject(state.cdrom);
@@ -179,6 +178,26 @@
     }
 }
 
+static void inc_volume(void)
+{
+    struct ioc_vol arg;
+    if(ioctl(state.cdrom->id, CDIOCGETVOL, &arg) == -1)
+    return;
+    arg.vol[0] += arg.vol[0] > 250 ? 255 - arg.vol[0] : 5;
+    arg.vol[1] += arg.vol[1] > 250 ? 255 - arg.vol[1] : 5;
+    ioctl(state.cdrom->id, CDIOCSETVOL, &arg);
+}
+
+static void dec_volume(void)
+{
+    struct ioc_vol arg;
+    if(ioctl(state.cdrom->id, CDIOCGETVOL, &arg) == -1)
+    return;
+    arg.vol[0] -= arg.vol[0] < 5 ? arg.vol[0] : 5;
+    arg.vol[1] -= arg.vol[1] < 5 ? arg.vol[1] : 5;
+    ioctl(state.cdrom->id, CDIOCSETVOL, &arg);
+}
+
 static void init_SDL(int cdrom_num)
 {
     int err = SDL_Init(SDL_INIT_CDROM);
@@ -218,10 +237,12 @@
 {
     unsigned long discid = cddb_discid(state.cdrom);
     if (discid != state.current_discid) {
-        if (state.cd_info.modified) {
+        if (state.cd_info.modified)
             tcd_writediskinfo(&state.cd_info, state.cdrom);
-        }
-        tcd_readdiskinfo(&state.cd_info, state.cdrom);
+        if (CD_INDRIVE(state.cdrom->status))
+            tcd_readdiskinfo(&state, state.cdrom);
+        else
+            bzero(&state.cd_info, sizeof(state.cd_info));
         state.current_discid = discid;
     }
 }
@@ -237,7 +258,7 @@
     state.play_method = NORMAL;
 
     init_SDL((argc > 1) ? strtol(argv[1], NULL, 0) : 0);
-    tcd_readdiskinfo(&state.cd_info, state.cdrom);
+    tcd_readdiskinfo(&state, state.cdrom);
     tcd_ui_init();
     tcd_ui_update(&state);
     state.current_discid = cddb_discid(state.cdrom);
@@ -255,14 +276,17 @@
             case '-': case '_': handle_prev_track(); break;
             case 'g': case 'G': handle_goto(); break;
             case 'c': case 'C': state.play_method = REPEAT_CD; break;
-            case 'r': case 'R': handle_repeat_track(); break;
+            case 'r': case 'R': state.play_method = REPEAT_TRK; break;
             case 'm': case 'M': handle_method(); break;
             case 'e': case 'E': handle_eject(); break;
             case 't': case 'T': handle_editor(); break;
-            case 's': case 'S': handle_stop(); break;
+            case 's': case 'S': state.play_method = NORMAL;
+                                handle_stop(); break;
             case ']': handle_skip_forward(); break;
             case '[': handle_skip_back(); break;
-   }
+            case '*': inc_volume(); break;
+            case '/': dec_volume(); break;
+    }
     }
     tcd_ui_shutdown();
     if (state.cd_info.modified) {