summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/CDPlayerAction.java
blob: ab5a648b0c650f08f1b3a051286db06bec6fc954 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import NET.worlds.console.Main;
/*     */ import NET.worlds.console.MainCallback;
/*     */ import NET.worlds.console.MainTerminalCallback;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CDPlayerAction
/*     */   extends Action
/*     */   implements Runnable, MainCallback, MainTerminalCallback
/*     */ {
/*     */   private static final boolean DISABLE_ALL = true;
/*     */   private static final int STATE_INITIAL = 0;
/*     */   private static final int STATE_WAITING = 1;
/*     */   private static final int STATE_DONE = 2;
/*  46 */   private static int numDrives = -1;
/*     */   
/*     */   private static CDPlayerAction active;
/*     */   
/*     */   private String artist;
/*     */   private String title;
/*     */   private String hash;
/*     */   private int start;
/*     */   private int stop;
/*     */   private boolean isStopper;
/*     */   private boolean cancel;
/*  57 */   private int state = 0;
/*     */   
/*     */ 
/*     */ 
/*     */   private boolean same(String str1, String str2)
/*     */   {
/*  63 */     if (str1 == null) {
/*  64 */       if (str2 == null)
/*  65 */         return true;
/*  66 */       return false;
/*     */     }
/*  68 */     if (str2 == null)
/*  69 */       return false;
/*  70 */     return str1.equals(str2);
/*     */   }
/*     */   
/*     */   private boolean same(CDPlayerAction other)
/*     */   {
/*  75 */     return (other != null) && 
/*  76 */       (same(this.artist, other.artist)) && (same(this.title, other.title)) && 
/*  77 */       (same(this.hash, other.hash)) && (this.start == other.start) && 
/*  78 */       (this.stop == other.stop);
/*     */   }
/*     */   
/*     */ 
/*     */   public Persister trigger(Event e, Persister seqID)
/*     */   {
/*  84 */     return null;
/*     */     
/*  86 */     boolean done = false;
/*  87 */     if (seqID == null)
/*  88 */       this.state = 0;
/*  89 */     if (this.state == 0) {
/*  90 */       if ((this.isStopper) && (!same(active))) {
/*  91 */         done = true;
/*  92 */       } else if ((active != null) && (active != this)) {
/*  93 */         active.cancel = true;
/*  94 */       } else if (this.start >= this.stop) {
/*  95 */         done = true;
/*     */       } else {
/*  97 */         active = this;
/*  98 */         this.cancel = false;
/*  99 */         Main.register(this);
/* 100 */         this.state = 1;
/* 101 */         Thread t = new Thread(this);
/* 102 */         t.setDaemon(true);
/* 103 */         t.start();
/*     */       }
/*     */     }
/* 106 */     else if (this.state == 2) {
/* 107 */       active = null;
/* 108 */       Main.unregister(this);
/* 109 */       done = true;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 116 */     return done ? null : this;
/*     */   }
/*     */   
/*     */   public void run()
/*     */   {
/* 121 */     if (numDrives == -1) {
/* 122 */       numDrives = getNumDrives();
/*     */     }
/* 124 */     for (int i = 0; i < numDrives;) {
/*     */       try {
/* 126 */         CDTrackInfo trackInfo = getTrackList(i);
/* 127 */         String curHash = null;
/* 128 */         if (trackInfo != null) {
/* 129 */           curHash = CDDBHash.hashString(trackInfo);
/* 130 */           if (curHash.equals(this.hash)) {
/* 131 */             play(i);
/* 132 */             break;
/*     */           }
/*     */         }
/* 135 */         if (this.cancel) {
/*     */           break;
/*     */         }
/* 124 */         i++;
/*     */       }
/*     */       catch (IOException localIOException) {}
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 139 */     this.state = 2;
/*     */   }
/*     */   
/*     */ 
/*     */   public void mainCallback() {}
/*     */   
/*     */ 
/*     */   public void terminalCallback()
/*     */   {
/* 148 */     this.cancel = true;
/* 149 */     if (this.state == 2) {
/* 150 */       Main.unregister(this);
/*     */     }
/*     */   }
/*     */   
/*     */   private void play(int drive) throws IOException {
/*     */     int driveID;
/* 156 */     if ((driveID = openDrive(drive)) != 0) {
/* 157 */       playAudio(driveID, this.start, this.stop);
/* 158 */       while (isPlaying(driveID)) {
/*     */         try {
/* 160 */           Thread.sleep(1000L);
/*     */         } catch (InterruptedException localInterruptedException) {}
/* 162 */         if (this.cancel) {
/* 163 */           stopAudio(driveID);
/* 164 */           break;
/*     */         }
/*     */       }
/* 167 */       closeDrive(driveID);
/*     */     }
/*     */   }
/*     */   
/*     */   public static CDTrackInfo getTrackList(int drive)
/*     */     throws IOException
/*     */   {
/* 174 */     CDTrackInfo ret = null;
/* 175 */     int driveID; if ((driveID = openDrive(drive)) != 0) {
/* 176 */       ret = getDriveTrackList(driveID);
/* 177 */       closeDrive(driveID);
/*     */     }
/* 179 */     return ret; }
/*     */   
/*     */   public static native int getNumDrives();
/*     */   
/*     */   public static native int getDriveLetterOffset(int paramInt);
/*     */   
/*     */   public static native int openDrive(int paramInt) throws IOException;
/*     */   
/*     */   public static native void closeDrive(int paramInt) throws IOException;
/*     */   
/*     */   public static native void checkDrive(int paramInt) throws IOException;
/*     */   
/*     */   public static native CDTrackInfo getDriveTrackList(int paramInt) throws IOException;
/*     */   
/*     */   public static native void playAudio(int paramInt1, int paramInt2, int paramInt3) throws IOException;
/*     */   
/*     */   public static native void stopAudio(int paramInt) throws IOException;
/*     */   public static native void pauseAudio(int paramInt) throws IOException;
/*     */   public static native void resumeAudio(int paramInt) throws IOException;
/*     */   public static native boolean isPlaying(int paramInt) throws IOException;
/*     */   public static native int getPosition(int paramInt) throws IOException;
/*     */   public static native void setNTAutoPlayCode(int paramInt);
/*     */   public static native boolean launchVolumeControlApp();
/* 202 */   public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null;
/* 203 */     switch (index - offset) {
/*     */     case 0: 
/* 205 */       if (mode == 0) {
/* 206 */         ret = StringPropertyEditor.make(new Property(this, index, 
/* 207 */           "Artist"));
/* 208 */       } else if (mode == 1) {
/* 209 */         ret = this.artist;
/* 210 */       } else if (mode == 2)
/* 211 */         this.artist = ((String)value);
/* 212 */       break;
/*     */     case 1: 
/* 214 */       if (mode == 0) {
/* 215 */         ret = StringPropertyEditor.make(new Property(this, index, 
/* 216 */           "Title"));
/* 217 */       } else if (mode == 1) {
/* 218 */         ret = this.title;
/* 219 */       } else if (mode == 2)
/* 220 */         this.title = ((String)value);
/* 221 */       break;
/*     */     case 2: 
/* 223 */       if (mode == 0) {
/* 224 */         ret = StringPropertyEditor.make(new Property(this, index, 
/* 225 */           "Disk ID (Edit or Delete to read CD)").allowSetNull());
/* 226 */       } else if (mode == 1) {
/* 227 */         if (this.hash == null) {
/*     */           try {
/* 229 */             CDTrackInfo trackList = getTrackList(0);
/* 230 */             if (trackList != null)
/* 231 */               this.hash = CDDBHash.hashString(trackList);
/*     */           } catch (IOException localIOException) {}
/*     */         }
/* 234 */         ret = this.hash;
/*     */       }
/* 236 */       else if (mode == 2) {
/* 237 */         this.hash = ((String)value); }
/* 238 */       break;
/*     */     case 3: 
/* 240 */       if (mode == 0) {
/* 241 */         ret = CDPositionPropertyEditor.make(new Property(this, index, 
/* 242 */           "Start (75ths of a second)"), 
/* 243 */           false);
/* 244 */       } else if (mode == 1) {
/* 245 */         ret = new Integer(this.start);
/* 246 */       } else if (mode == 2)
/* 247 */         this.start = ((Integer)value).intValue();
/* 248 */       break;
/*     */     case 4: 
/* 250 */       if (mode == 0) {
/* 251 */         ret = CDPositionPropertyEditor.make(new Property(this, index, 
/* 252 */           "Stop (75ths of a second)"), 
/* 253 */           true);
/* 254 */       } else if (mode == 1) {
/* 255 */         ret = new Integer(this.stop);
/* 256 */       } else if (mode == 2)
/* 257 */         this.stop = ((Integer)value).intValue();
/* 258 */       break;
/*     */     case 5: 
/* 260 */       if (mode == 0) {
/* 261 */         ret = BooleanPropertyEditor.make(
/* 262 */           new Property(this, index, "Stop identical CDPlayerAction"), 
/* 263 */           "No", "Yes");
/* 264 */       } else if (mode == 1) {
/* 265 */         ret = new Boolean(this.isStopper);
/* 266 */       } else if (mode == 2)
/* 267 */         this.isStopper = ((Boolean)value).booleanValue();
/* 268 */       break;
/*     */     
/*     */     default: 
/* 271 */       ret = super.properties(index, offset + 6, mode, value);
/*     */     }
/* 273 */     return ret;
/*     */   }
/*     */   
/* 276 */   private static Object classCookie = new Object();
/*     */   
/*     */   public void saveState(Saver s) throws IOException
/*     */   {
/* 280 */     s.saveVersion(2, classCookie);
/* 281 */     super.saveState(s);
/* 282 */     s.saveString(this.artist);
/* 283 */     s.saveString(this.title);
/* 284 */     s.saveString(this.hash);
/* 285 */     s.saveInt(this.start);
/* 286 */     s.saveInt(this.stop);
/* 287 */     s.saveBoolean(this.isStopper);
/*     */   }
/*     */   
/*     */   public void restoreState(Restorer r) throws IOException, TooNewException
/*     */   {
/* 292 */     switch (r.restoreVersion(classCookie)) {
/*     */     case 1: 
/* 294 */       super.restoreState(r);
/* 295 */       this.artist = r.restoreString();
/* 296 */       this.title = r.restoreString();
/* 297 */       this.hash = r.restoreString();
/* 298 */       this.start = r.restoreInt();
/* 299 */       this.stop = r.restoreInt();
/* 300 */       break;
/*     */     
/*     */     case 2: 
/* 303 */       super.restoreState(r);
/* 304 */       this.artist = r.restoreString();
/* 305 */       this.title = r.restoreString();
/* 306 */       this.hash = r.restoreString();
/* 307 */       this.start = r.restoreInt();
/* 308 */       this.stop = r.restoreInt();
/* 309 */       this.isStopper = r.restoreBoolean();
/* 310 */       break;
/*     */     
/*     */     default: 
/* 313 */       throw new TooNewException();
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\CDPlayerAction.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */