diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/CDAudio.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/CDAudio.java')
| -rw-r--r-- | NET/worlds/scape/CDAudio.java | 597 |
1 files changed, 597 insertions, 0 deletions
diff --git a/NET/worlds/scape/CDAudio.java b/NET/worlds/scape/CDAudio.java new file mode 100644 index 0000000..9fb5928 --- /dev/null +++ b/NET/worlds/scape/CDAudio.java @@ -0,0 +1,597 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.console.Main; +/* */ import NET.worlds.console.MainCallback; +/* */ import NET.worlds.console.MainTerminalCallback; +/* */ import NET.worlds.core.IniFile; +/* */ import NET.worlds.network.URL; +/* */ import java.io.File; +/* */ import java.io.IOException; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class CDAudio +/* */ implements Runnable, MainCallback, MainTerminalCallback +/* */ { +/* */ private static final int STOP = 0; +/* */ private static final int PLAY = 1; +/* */ private static final int PAUSE = 2; +/* */ private static final int NEXT = 3; +/* */ private static final int PREV = 4; +/* */ private static final int CHANGE = 5; +/* */ private static final int CHANGE_MIDI = 6; +/* */ private boolean performedStartupPlay; +/* */ private boolean cancel; +/* */ private Thread playerThread; +/* 67 */ private Vector<Integer> commandBuffer = new Vector(); +/* */ private boolean paused; +/* */ private int driveID; +/* */ private CDTrackInfo tracks; +/* */ private int trackOffset; +/* 72 */ private Object tracksMutex = new Object(); +/* */ private int pos; +/* */ private SoundPlayer midiPlayer; +/* 75 */ private URL defaultMIDIFile = URL.make("home:start.mid"); +/* 76 */ private URL curMIDIFile = this.defaultMIDIFile; +/* 77 */ private int trackToRepeat = -1; +/* 78 */ private int repeatingTrack = -1; +/* 79 */ private boolean enabled = true; +/* */ +/* 81 */ private static CDAudio instance = new CDAudio(); +/* */ +/* */ public static CDAudio get() +/* */ { +/* 85 */ return instance; +/* */ } +/* */ +/* */ public String getTimeReadout() +/* */ { +/* 90 */ synchronized (this.tracksMutex) { +/* 91 */ if (this.tracks == null) +/* */ { +/* 93 */ this.tracksMutex.notify(); +/* 94 */ return "00 [00:00]"; +/* */ } +/* 96 */ int count = this.tracks.getNumTracks(); +/* 97 */ if (this.pos != 0) { +/* 98 */ for (int i = 0; i < count; i++) +/* 99 */ if (this.pos < this.tracks.getEndFrames(i)) +/* 100 */ return +/* 101 */ fmt2(i + 1) + " " + fmtFrames(this.pos - this.tracks.getStartFrames(i)); +/* */ } +/* 103 */ return +/* 104 */ fmt2(count) + " " + fmtFrames(this.tracks.getEndFrames(count - 1)); +/* */ } +/* */ } +/* */ +/* */ public void setEnabled(boolean state) +/* */ { +/* 110 */ if (this.enabled != state) { +/* 111 */ this.enabled = state; +/* 112 */ if (!this.enabled) { +/* 113 */ stop(); +/* */ } else +/* 115 */ change(true); +/* */ } +/* */ } +/* */ +/* 119 */ public void play() { queueCommand(1); } +/* 120 */ public void pause() { queueCommand(2); } +/* 121 */ public void stop() { queueCommand(0); } +/* 122 */ public void next() { queueCommand(3); } +/* 123 */ public void prev() { queueCommand(4); } +/* */ +/* */ public void change(boolean loop) +/* */ { +/* 127 */ queueCommand(5); +/* */ } +/* */ +/* */ public static void startupPlay() { +/* 131 */ get(); +/* */ } +/* */ +/* */ public void setMIDIFile(URL url) +/* */ { +/* 136 */ this.curMIDIFile = url; +/* */ } +/* */ +/* */ public URL getDefaultMIDIFile() +/* */ { +/* 141 */ return this.defaultMIDIFile; +/* */ } +/* */ +/* */ public URL getMIDIFile() +/* */ { +/* 146 */ return this.curMIDIFile; +/* */ } +/* */ +/* */ public void setCDTrack(int track) +/* */ { +/* 151 */ this.trackToRepeat = (track - 1); +/* */ } +/* */ +/* */ public int getCDTrack() +/* */ { +/* 156 */ return this.trackToRepeat + 1; +/* */ } +/* */ +/* */ private CDAudio() { +/* 160 */ this.playerThread = new Thread(this); +/* 161 */ this.playerThread.start(); +/* */ } +/* */ +/* */ public void run() +/* */ { +/* 166 */ Main.register(this); +/* */ +/* 168 */ int numDrives = CDPlayerAction.getNumDrives(); +/* 169 */ while (!this.cancel) { +/* 170 */ for (int i = 0; i < numDrives; i++) { +/* 171 */ this.cdInDrive = false; +/* */ try { +/* 173 */ if ((this.driveID = CDPlayerAction.openDrive(i)) != 0) { +/* 174 */ if (!CDPlayerAction.isPlaying(this.driveID)) { +/* 175 */ CDTrackInfo tmp = +/* 176 */ CDPlayerAction.getDriveTrackList(this.driveID); +/* 177 */ char drive = (char)(65 + +/* 178 */ CDPlayerAction.getDriveLetterOffset(i)); +/* */ +/* */ +/* */ +/* 182 */ File f = new File(drive + ":\\WORLDS.CD"); +/* 183 */ if (f.exists()) { +/* 184 */ synchronized (this.tracksMutex) { +/* 185 */ this.tracks = tmp; +/* 186 */ this.trackOffset = 0; +/* */ +/* */ +/* */ +/* */ +/* 191 */ if (f.length() == 1L) +/* 192 */ this.trackOffset = 1; +/* */ } +/* 194 */ this.cdInDrive = true; +/* 195 */ if (this.performedStartupPlay) { +/* 196 */ flushPendingCommands(); +/* */ } else +/* 198 */ this.performedStartupPlay = true; +/* 199 */ change(true); +/* 200 */ waitForCommands(); +/* */ } +/* */ } +/* 203 */ this.driveID = 0; +/* */ } +/* */ } +/* */ catch (IOException localIOException) {} +/* */ +/* 208 */ if (this.driveID != 0) { +/* */ try { +/* 210 */ CDPlayerAction.closeDrive(this.driveID); +/* */ } catch (IOException localIOException1) {} +/* 212 */ this.driveID = 0; +/* 213 */ this.paused = false; +/* 214 */ this.pos = 0; +/* */ } +/* */ } +/* 217 */ this.performedStartupPlay = true; +/* */ +/* 219 */ this.cdInDrive = false; +/* */ +/* 221 */ synchronized (this.tracksMutex) { +/* 222 */ this.tracks = null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 228 */ if (!this.cancel) +/* */ { +/* */ +/* 231 */ timedWait(10); +/* */ +/* 233 */ synchronized (this.tracksMutex) +/* */ { +/* */ +/* 236 */ if (!this.cancel) { +/* */ try { +/* 238 */ this.tracksMutex.wait(); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* */ } +/* */ } +/* */ } +/* */ } +/* 245 */ Main.unregister(this); +/* */ } +/* */ +/* 248 */ static boolean useMidiFlag = IniFile.gamma().getIniInt("MIDIONSTART", 1) != 0; +/* 249 */ static boolean useAutoCDFlag = IniFile.gamma().getIniInt("AUTOPLAYCD", 1) != 0; +/* */ private boolean cdInDrive; +/* */ private boolean allowMIDIAnyway; +/* */ private boolean midiPaused; +/* */ private boolean midiStarted; +/* */ +/* 255 */ public void useAutoCD(boolean f) { if (f != useAutoCDFlag) { +/* 256 */ useAutoCDFlag = f; +/* 257 */ IniFile.gamma().setIniInt("AUTOPLAYCD", useAutoCDFlag ? 1 : 0); +/* */ +/* 259 */ if (f) { +/* 260 */ if (this.trackToRepeat != -1) { +/* 261 */ queueCommand(5); +/* */ } +/* */ } else { +/* 264 */ queueCommand(0); +/* */ } +/* */ } +/* */ } +/* */ +/* */ private synchronized void flushPendingCommands() { +/* 270 */ this.commandBuffer.removeAllElements(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private synchronized void queueCommand(int command) +/* */ { +/* 278 */ if (command != 6) +/* 279 */ this.allowMIDIAnyway = false; +/* 280 */ this.commandBuffer.addElement(new Integer(command)); +/* */ } +/* */ +/* */ private synchronized int getQueuedCommand(boolean isMidi) +/* */ { +/* 285 */ if (this.commandBuffer.size() <= 0) { +/* 286 */ return -1; +/* */ } +/* 288 */ int command = ((Integer)this.commandBuffer.elementAt(0)).intValue(); +/* */ +/* 290 */ if (command == 6) { +/* 291 */ if (!isMidi) { +/* 292 */ return -1; +/* */ } +/* 294 */ } else if (isMidi == this.cdInDrive) { +/* 295 */ return -1; +/* */ } +/* 297 */ this.commandBuffer.removeElementAt(0); +/* 298 */ return command; +/* */ } +/* */ +/* */ private synchronized int peekQueuedCommand() { +/* 302 */ if (this.commandBuffer.size() <= 0) { +/* 303 */ return -1; +/* */ } +/* 305 */ return ((Integer)this.commandBuffer.elementAt(0)).intValue(); +/* */ } +/* */ +/* */ +/* */ private void waitForCommands() +/* */ throws IOException +/* */ { +/* */ for (;;) +/* */ { +/* 314 */ if (this.cancel) { +/* 315 */ CDPlayerAction.stopAudio(this.driveID); +/* 316 */ return; +/* */ } +/* 318 */ boolean playing = CDPlayerAction.isPlaying(this.driveID); +/* 319 */ if (playing) { +/* 320 */ int tmp = CDPlayerAction.getPosition(this.driveID); +/* 321 */ if (tmp > this.pos) +/* 322 */ this.pos = tmp; +/* 323 */ this.paused = false; +/* */ } +/* */ else +/* */ { +/* 327 */ CDPlayerAction.checkDrive(this.driveID); +/* 328 */ if (!this.paused) +/* 329 */ this.pos = 0; +/* 330 */ if (this.repeatingTrack != -1) { +/* 331 */ this.pos = this.tracks.getStartFrames(this.repeatingTrack + +/* 332 */ this.trackOffset); +/* 333 */ CDPlayerAction.playAudio(this.driveID, this.pos, +/* 334 */ this.tracks.getEndFrames(this.repeatingTrack + +/* 335 */ this.trackOffset)); +/* */ } +/* */ } +/* */ int command; +/* 339 */ if ((command = getQueuedCommand(false)) < 0) +/* */ { +/* */ +/* 342 */ timedWait(1); } else { boolean playing; +/* */ int command; +/* 344 */ processCommand(command, playing); +/* */ } +/* */ } +/* */ } +/* */ +/* */ private void processCommand(int command, boolean playing) throws IOException +/* */ { +/* 351 */ int wasRepeatingTrack = this.repeatingTrack; +/* 352 */ this.repeatingTrack = -1; +/* 353 */ switch (command) { +/* */ case 5: +/* 355 */ if ((useAutoCDFlag) && (this.enabled)) +/* */ { +/* 357 */ if ((this.trackToRepeat == -1) || (this.trackToRepeat < this.tracks.getNumTracks())) { +/* 358 */ this.repeatingTrack = this.trackToRepeat; +/* 359 */ if ((wasRepeatingTrack == this.trackToRepeat) && +/* 360 */ (wasRepeatingTrack != -1)) +/* */ break; +/* */ } else { +/* 363 */ CDPlayerAction.stopAudio(this.driveID); +/* 364 */ if (this.repeatingTrack == -1) { +/* 365 */ this.allowMIDIAnyway = true; +/* 366 */ queueCommand(6); +/* */ } +/* 368 */ this.paused = false; } } +/* 369 */ break; +/* */ case 0: +/* 371 */ if ((playing) || (this.paused)) +/* 372 */ CDPlayerAction.stopAudio(this.driveID); +/* 373 */ this.paused = false; +/* 374 */ break; +/* */ case 1: +/* 376 */ if (!playing) +/* 377 */ play(-this.pos); +/* 378 */ break; +/* */ case 2: +/* 380 */ if ((playing) && (!this.paused)) { +/* 381 */ CDPlayerAction.stopAudio(this.driveID); +/* 382 */ this.paused = true; +/* */ } +/* 384 */ break; +/* */ case 3: +/* 386 */ if ((playing) || (this.paused)) { +/* 387 */ for (int i = 0; i < this.tracks.getNumTracks() - 1; i++) { +/* 388 */ if ((this.pos >= this.tracks.getStartFrames(i)) && +/* 389 */ (this.pos < this.tracks.getEndFrames(i))) { +/* 390 */ play(i + 1); +/* 391 */ break; +/* */ } +/* */ +/* */ } +/* */ } else +/* 396 */ play(0); +/* 397 */ break; +/* */ case 4: +/* 399 */ if ((playing) || (this.paused)) { +/* 400 */ for (int i = 0; i < this.tracks.getNumTracks(); i++) { +/* 401 */ if (this.pos < this.tracks.getEndFrames(i)) { +/* 402 */ if ((i > 0) && (this.pos < this.tracks.getStartFrames(i) + 75)) { +/* 403 */ play(i - 1); break; +/* */ } +/* 405 */ play(i); +/* 406 */ break; +/* */ } +/* */ } +/* */ } +/* */ break; +/* */ } +/* */ } +/* */ +/* */ private void play(int location) throws IOException +/* */ { +/* 416 */ if (location < 0) { +/* 417 */ this.pos = (-location); +/* */ } else +/* 419 */ this.pos = this.tracks.getStartFrames(location); +/* 420 */ CDPlayerAction.playAudio(this.driveID, this.pos, +/* 421 */ this.tracks.getEndFrames(this.tracks.getNumTracks() - +/* 422 */ 1)); +/* 423 */ this.paused = false; +/* */ } +/* */ +/* */ private void startMidi() +/* */ { +/* 428 */ if (this.curMIDIFile == this.defaultMIDIFile) { +/* 429 */ return; +/* */ } +/* */ +/* */ +/* */ +/* 434 */ if (this.midiPlayer != null) { +/* 435 */ this.midiPlayer.stop(); +/* 436 */ this.midiPlayer.close(); +/* */ +/* 438 */ this.midiStarted = false; +/* 439 */ if ((MCISoundPlayer.isActive()) || (WMPSoundPlayer.isActive())) { +/* 440 */ this.midiPlayer = null; +/* */ } +/* */ +/* */ } +/* 444 */ else if ((MCISoundPlayer.isActive()) || (WMPSoundPlayer.isActive())) { +/* 445 */ return; +/* */ } +/* */ +/* 448 */ Sound s = new Sound(this.curMIDIFile); +/* */ +/* 450 */ if ((this.curMIDIFile.endsWith(".mid")) || (this.curMIDIFile.endsWith(".wav"))) { +/* 451 */ this.midiPlayer = new MCISoundPlayer(s); +/* */ } else { +/* 453 */ this.midiPlayer = new WMPSoundPlayer(s); +/* */ } +/* 455 */ this.midiPlayer.open(1.0F, 0.0F, false, false); +/* */ +/* 457 */ if (!this.midiPaused) +/* */ { +/* 459 */ this.midiPlayer.start(1); +/* */ } +/* */ } +/* */ +/* */ private void killMidi() { +/* 464 */ if (this.midiPlayer != null) { +/* 465 */ this.midiStarted = false; +/* 466 */ this.midiPlayer.stop(); +/* 467 */ this.midiPlayer.close(); +/* 468 */ this.midiPlayer = null; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void useMidi() +/* */ { +/* 479 */ if ((useMidiFlag) && (this.enabled) && ((!this.cdInDrive) || (this.allowMIDIAnyway))) { +/* 480 */ if (this.midiPlayer == null) { +/* 481 */ startMidi(); +/* */ } +/* 483 */ else if (this.midiPlayer.getState() == 1) +/* */ { +/* 485 */ if (this.midiStarted) { +/* 486 */ startMidi(); +/* 487 */ this.midiStarted = false; +/* */ } +/* */ } else { +/* 490 */ this.midiStarted = true; +/* */ } +/* */ } +/* */ +/* 494 */ if ((!useMidiFlag) || (!this.enabled) || ((this.cdInDrive) && (!this.allowMIDIAnyway))) +/* 495 */ killMidi(); +/* */ } +/* */ +/* */ public void setMidiFlag(boolean f) { +/* 499 */ useMidiFlag = f; +/* 500 */ IniFile.gamma().setIniInt("MIDIONSTART", useMidiFlag ? 1 : 0); +/* */ } +/* */ +/* */ public void mainCallback() { +/* 504 */ if (!this.performedStartupPlay) { +/* 505 */ return; +/* */ } +/* 507 */ useMidi(); +/* */ +/* 509 */ while ((this.midiPlayer != null) || (peekQueuedCommand() == 6)) { +/* 510 */ if ((this.cdInDrive) && (this.repeatingTrack != -1)) { +/* 511 */ if (peekQueuedCommand() == 6) +/* 512 */ getQueuedCommand(true); +/* 513 */ this.allowMIDIAnyway = false; +/* 514 */ useMidi(); return; +/* */ } +/* */ +/* */ int command; +/* */ +/* 519 */ if ((command = getQueuedCommand(true)) < 0) { +/* 520 */ return; +/* */ } +/* 522 */ switch (command) { +/* */ case 5: +/* */ case 6: +/* 525 */ if ((useMidiFlag) && (this.enabled)) { +/* 526 */ this.midiStarted = false; +/* 527 */ this.midiPaused = false; +/* 528 */ startMidi(); +/* */ } +/* 530 */ break; +/* */ case 1: +/* 532 */ if ((this.midiPaused) || (!this.midiStarted)) { +/* 533 */ this.midiPaused = false; +/* 534 */ startMidi(); +/* */ } +/* 536 */ break; +/* */ +/* */ +/* */ case 0: +/* */ case 2: +/* 541 */ this.midiPaused = true; +/* 542 */ this.midiPlayer.stop(); +/* 543 */ this.midiStarted = false; +/* 544 */ break; +/* */ +/* */ case 3: +/* */ case 4: +/* 548 */ startMidi(); +/* */ } +/* */ +/* */ } +/* */ } +/* */ +/* */ private synchronized void timedWait(int secs) +/* */ { +/* 556 */ if (!this.cancel) +/* */ try { +/* 558 */ wait(secs * 1000); +/* */ } catch (InterruptedException localInterruptedException) {} +/* */ } +/* */ +/* */ public void terminalCallback() { +/* 563 */ this.cancel = true; +/* 564 */ killMidi(); +/* */ +/* 566 */ synchronized (this) { +/* 567 */ notify(); +/* */ } +/* */ +/* 570 */ synchronized (this.tracksMutex) { +/* 571 */ this.tracksMutex.notify(); +/* */ } +/* */ } +/* */ +/* */ private static String fmt2(int val) +/* */ { +/* 577 */ if (val < 10) +/* 578 */ return "0" + val; +/* 579 */ return val; +/* */ } +/* */ +/* */ private static String fmtFrames(int frames) +/* */ { +/* 584 */ if (frames < 0) +/* 585 */ frames = 0; +/* 586 */ int minutes = frames / 4500; +/* 587 */ frames -= minutes * 4500; +/* 588 */ int seconds = frames / 75; +/* 589 */ return "[" + fmt2(minutes) + ":" + fmt2(seconds) + "]"; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\CDAudio.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |