private void interruptPlayback(PlayerState st) {
    if (state == st) return;

    PlayerThread th = currentPlayerThread.get();
    if (th != null) {
      if (th.isAlive()) th.die(st);
      else if (currentPlayerThread.compareAndSet(th, null)) setStateNotify(st);
    } else setStateNotify(st);
  }
  /**
   * Attemts to start playback. If playback already running this method has no any effect. Playback
   * startup is async operation: method initiates playback preparation and returns immediate -
   * playback may run later.
   */
  public void play() {
    if (state == PlayerState.PLAYING) return;
    PlayerThread th = currentPlayerThread.get();

    if (th == null) {
      th = new PlayerThread(this);
      if (currentPlayerThread.compareAndSet(null, th)) th.start();
    }
  }
Example #3
0
  public void playSequenceFromJFugueString(String noteString, int instrument) {

    initialize();
    try {
      sequencer.open();
      synthesizer.open();
    } catch (MidiUnavailableException e) {
      e.printStackTrace();
    }

    noteString = "I[" + instrument + "] " + noteString;
    player = new Player(sequencer);
    Pattern pattern = new Pattern(noteString);
    PlayerThread thread = new PlayerThread(player, pattern);
    thread.start();
  }
 /**
  * Creates a new ClipPanel component for the given clip. Also attaches to the given player thread,
  * and will show a visual indication of playback position for that thread.
  *
  * @param clip
  * @param playerThread
  * @return
  */
 public static ClipPanel newInstance(Clip clip, PlayerThread playerThread) {
   ClipPanel cp = new ClipPanel(clip);
   clip.addClipDataChangeListener(cp.clipDataChangeHandler);
   playerThread.addPlaybackPositionListener(cp.clipPositionHeader);
   cp.clipPositionHeader.setPlayerThread(playerThread);
   return cp;
 }
Example #5
0
 public ParallelRedoPlayer(
     boolean writable,
     boolean unloggedReplay,
     boolean ignoreReplayErrors,
     boolean skipDeleteOps,
     int numThreads,
     int queueCapacity) {
   super(writable, unloggedReplay, ignoreReplayErrors, skipDeleteOps);
   ZimbraLog.redolog.debug("Starting ParallelRedoPlayer");
   numThreads = Math.max(numThreads, 1);
   mPlayerThreads = new PlayerThread[numThreads];
   for (int i = 0; i < numThreads; i++) {
     String name = "RedoPlayer-" + Integer.toString(i);
     PlayerThread player = new PlayerThread(queueCapacity);
     mPlayerThreads[i] = player;
     player.setName(name);
     player.start();
   }
 }
Example #6
0
 @Override
 protected void playOp(RedoableOp op) throws Exception {
   checkError();
   int mboxId = op.getMailboxId();
   if (mboxId == RedoableOp.MAILBOX_ID_ALL || mboxId == RedoableOp.UNKNOWN_ID) {
     // Multi-mailbox ops are executed by the main thread to prevent later ops
     // that depend on this op's result aren't run out of order.
     if (ZimbraLog.redolog.isDebugEnabled()) ZimbraLog.redolog.info("Executing: " + op.toString());
     op.redo();
   } else {
     // Ops for the same mailbox must be played back in order.  To ensure that,
     // all ops for the same mailbox are sent to the same player thread.  The
     // ops are added to the thread's internal queue and played back in order.
     // This assignment of ops to threads will result in uneven distribution.
     int index = Math.abs(mboxId % mPlayerThreads.length);
     PlayerThread player = mPlayerThreads[index];
     RedoTask task = new RedoTask(op);
     if (ZimbraLog.redolog.isDebugEnabled()) ZimbraLog.redolog.info("Enqueuing: " + op.toString());
     try {
       player.enqueue(task);
     } catch (InterruptedException e) {
     }
   }
 }
 @Override
 public void mousePressed(MouseEvent e) {
   playerThread.setPlaybackPosition(e.getX() * clip.getFrameTimeSamples());
 }