예제 #1
1
  /** 实现计时功能 */
  @SuppressWarnings("deprecation")
  public void run() {
    try {
      Thread.sleep(1000); // 延迟1s
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }
    while (true) {
      if (blacktime > 0 && whitetime > 0 && blackOneTime > 0 && whiteOneTime > 0) {
        if (cb.isBlack) {
          whiteOneTime = maxOneStepTime;
          blacktime--;
          blackOneTime--;
        } else {
          blackOneTime = maxOneStepTime;
          whitetime--;
          whiteOneTime--;
        }
        blackMessage = this.initTime(blacktime);
        whiteMessage = this.initTime(whitetime);
        if (blackOneTime < 5 || whiteOneTime < 5) {
          v.play("clock");
        }
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      if (blackOneTime == 0 || blacktime == 0) {
        JOptionPane.showMessageDialog(cb, "黑方时间到,白方胜");
        cb.message = "黑方时间到,白方胜";
        v.play("end");
        cb.changeColor = true;
        cb.canPlay = false;
        cb.whiteWin++;
        rp.ready.setText("准备");
        rp.isReady = false;
        t.suspend();
      }
      if (whiteOneTime == 0 || whitetime == 0) {
        JOptionPane.showMessageDialog(cb, "白方时间到,黑方胜");
        cb.message = "白方时间到,黑方胜";
        v.play("end");
        cb.changeColor = true;
        cb.canPlay = false;
        cb.blackWin++;
        rp.ready.setText("准备");
        rp.isReady = false;
        t.suspend();
      }

      cb.repaint();
    }
  }
예제 #2
1
  /**
   * 实现对认输的处理
   *
   * @param dis
   */
  @SuppressWarnings("deprecation")
  public void giveUpAnswer(DataInputStream dis) {
    try {
      boolean isplayer1 = dis.readBoolean();
      boolean isplayer2 = dis.readBoolean();
      cb.changeColor = true;
      cb.canPlay = false;
      v.play("end");
      t.suspend();
      rp.ready.setText("准备");
      rp.isReady = false;
      if (isplayer1 == true && isplayer2 == false) {
        JOptionPane.showMessageDialog(cb, "黑方已经认输,白方胜");
        cb.message = "黑方已经认输,白方胜";
        cb.whiteWin++;
      }
      if (isplayer2 == true && isplayer1 == false) {
        JOptionPane.showMessageDialog(cb, "白方已经认输,黑方胜");
        cb.message = "白方已经认输,黑方胜";
        cb.blackWin++;
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #3
1
 /** 实现对求和的处理 */
 @SuppressWarnings("deprecation")
 public void drawAnswer() {
   if (answer == 0) {
     cb.message = "双方言和,平局!";
     cb.changeColor = true;
     cb.canPlay = false;
     cb.su.update(0, 0, HallPlayerPanel.nickname);
     rp.ready.setText("准备");
     rp.isReady = false;
     t.suspend();
     v.play("end");
     JOptionPane.showMessageDialog(cb, "对方同意了你的求和!");
   }
   if (answer != 0) {
     JOptionPane.showMessageDialog(cb, "对方拒绝了你的请求!");
   }
   answer = 3;
 }
예제 #4
0
  @Test
  public void testVoiceHashCode() {
    Voice voice1 = new Voice("Bass", 1.0);
    Voice voice2 = new Voice("Bass", 1.0);

    assertEquals(true, voice1.hashCode() == voice1.hashCode());
    assertEquals(true, voice1.hashCode() == voice2.hashCode());
  }
예제 #5
0
파일: Staff.java 프로젝트: makyo/lywriter
  /** @param _instrument */
  public void setInstrument(Instrument _instrument) {
    instrument = _instrument;

    for (Voice v : voices) {
      if (v instanceof Voice) {
        v.setInstrument(instrument);
      }
    }
  }
예제 #6
0
  @Test
  public void testVoiceEquals() {
    Voice voice1 = new Voice("Bass", 1.0);
    Voice voice2 = new Voice("Bass", 1.0);
    Voice voice3 = new Voice("Soprano", 1.0);
    Voice voice4 = new Voice("Bass", 1.5);
    Voice voice5 = new Voice("Soprano", 2.0);

    assertEquals(true, voice1.equals(voice2));
    assertEquals(true, voice1.equals(voice1));
    assertEquals(false, voice1.equals(voice3));
    assertEquals(false, voice1.equals(voice4));
    assertEquals(false, voice1.equals(voice5));
  }
예제 #7
0
  public void endDestinationVoiceCall(
      String sourcePhoneNumber, String destinationPhoneNumber, int duration) {

    if (duration < 0) throw new InvalidDurationException(sourcePhoneNumber, destinationPhoneNumber);

    Phone destinationPhone = getPhone(destinationPhoneNumber);

    Voice activeCommunication =
        (Voice)
            destinationPhone.checkActiveCommunication(
                sourcePhoneNumber, destinationPhoneNumber, AnacomData.CommunicationType.VOICE);
    activeCommunication.setDuration(duration);

    destinationPhone.endReceivedVoiceCall(activeCommunication);
  }
예제 #8
0
 /**
  * Dumps this utterance in textual form.
  *
  * @param output where to send the formatted output
  * @param pad the initial padding
  * @param title the title to print when dumping out the utterance
  * @param justRelations if true don't print voice features
  */
 public void dump(PrintWriter output, int pad, String title, boolean justRelations) {
   output.println(" ============ " + title + " ========== ");
   if (!justRelations) {
     voice.dump(output, pad + 4, "Voice");
     features.dump(output, pad + 4, "Features");
   }
   relations.dump(output, pad + 4, "Relations");
   output.flush();
 }
예제 #9
0
  public void endSourceVoiceCall(
      String sourcePhoneNumber, String destinationPhoneNumber, int duration) {
    if (duration < 0) throw new InvalidDurationException(sourcePhoneNumber, destinationPhoneNumber);

    Phone sourcePhone = getPhone(sourcePhoneNumber);

    Voice activeCommunication =
        (Voice)
            sourcePhone.checkActiveCommunication(
                sourcePhoneNumber, destinationPhoneNumber, AnacomData.CommunicationType.VOICE);

    boolean sameOperator = sameOperator(sourcePhoneNumber, destinationPhoneNumber);
    int cost = sourcePhone.getOperator().getPlan().calcCostVoice(duration, sameOperator);

    sourcePhone.decreaseBalanceBy(cost);

    activeCommunication.setCost(cost);
    activeCommunication.setDuration(duration);

    sourcePhone.endSentVoiceCall(activeCommunication);
  }
예제 #10
0
  /**
   * Read a frame into the given buffer of floats
   *
   * @param floatBuffer
   */
  private final void floatRead(float[] floatBuffer) {
    bufferSize = floatBuffer.length;
    updateGenerators();

    for (Voice audioGen : audioOutputGenerators) {
      int bufferPos = 0;
      if (audioGen.startFramePos > 0) // Don't need this on wav export
      {
        bufferPos = (int) (2 * (audioGen.startFramePos - frameBufferPos));
        if (bufferPos < 0) bufferPos = 0;
      }

      if (bufferPos < floatBuffer.length) {
        int endBufferPos = 0;

        while (audioGen.interrupts.size() > 0) {
          VoiceInterrupt interrupt = audioGen.interrupts.get(0);
          if (interrupt.interruptFramePos > 0) {
            endBufferPos = (int) (2 * (interrupt.interruptFramePos - frameBufferPos));
            if (endBufferPos < 0) endBufferPos = 0;
          }

          if (endBufferPos <= floatBuffer.length) {
            audioGen.fillBuffer(bufferPos, endBufferPos, floatBuffer);
            interrupt.doInterrupt();
            bufferPos = endBufferPos;
            audioGen.interrupts.remove(0);
          } else break;
        }

        audioGen.fillBuffer(bufferPos, floatBuffer.length, floatBuffer);
        audioGen.startFramePos = 0;
      }
    }

    processFinalOutput(floatBuffer);
  }
예제 #11
0
  public void testVoiceAddMusicalElementAndGetMusicalElements() {
    Voice voice1 = new Voice("Bass", 1.0);

    List<Note> notesToCheck = new LinkedList<Note>();

    List<Pitch> pitches1 = new LinkedList<Pitch>();
    pitches1.add(new Pitch('C'));
    pitches1.add(new Pitch('E'));
    pitches1.add(new Pitch('G'));

    List<Pitch> pitches2 = new LinkedList<Pitch>();
    pitches2.add(new Pitch('C'));
    pitches2.add(new Pitch('F'));
    pitches2.add(new Pitch('G'));

    Note note1 = new Note(new Pitch('C'), new Fraction(1, 4));
    Note note2 = new Note(new Pitch('E'), new Fraction(1, 2));

    try {
      voice1.addMusicalElement(note1);
    } catch (Exception e) {
      e.printStackTrace();
    }

    notesToCheck.add(note1);
    assertEquals(true, voice1.getMusicalElements().equals(notesToCheck));

    try {
      voice1.addMusicalElement(note1);
    } catch (Exception e) {
      e.printStackTrace();
    }

    notesToCheck.add(note1);
    assertEquals(true, voice1.getMusicalElements().equals(notesToCheck));

    try {
      voice1.addMusicalElement(note2);
    } catch (Exception e) {
      e.printStackTrace();
    }

    notesToCheck.add(note2);
    assertEquals(true, voice1.getMusicalElements().equals(notesToCheck));
  }
 @Override
 public void visit(Body body) {
   for (Voice v : body.getVoices()) v.accept(this);
 }
예제 #13
0
 public void voiceEvent(Voice arg0) {
   layer = arg0.getVoice();
 }
예제 #14
0
 /**
  * Used by synths to add a new generator (midi note)
  *
  * @param transmitter - the generator to add
  */
 public final void addTransmitter(Voice transmitter) {
   if (isRealtime) transmitter.startFramePos = getFramePos();
   addedTransmitters.add(transmitter);
 }
 private void notifyFailureAndLog(String reason, Activity activity) {
   LogUtils.e(reason);
   Voice.notifyFailure(activity, reason);
 }
예제 #16
0
  @Test
  public void testVoiceTestGetNotesPerVoice() {
    Voice voice1 = new Voice("Bass", 1.0);
    Voice voice2 = new Voice("Bass", 1.0);
    Voice voice3 = new Voice("Soprano", 1.0);
    Voice voice4 = new Voice("Bass", 1.5);
    Voice voice5 = new Voice("Soprano", 2.0);

    assertEquals(true, voice1.getNotesPerVoice() == 1.0);
    assertEquals(false, voice1.getNotesPerVoice() == 1.5);
    assertEquals(true, voice1.getNotesPerVoice() == voice2.getNotesPerVoice());
    assertEquals(true, voice1.getNotesPerVoice() == voice3.getNotesPerVoice());
    assertEquals(false, voice1.getNotesPerVoice() == voice4.getNotesPerVoice());
    assertEquals(false, voice1.getNotesPerVoice() == voice5.getNotesPerVoice());
  }
예제 #17
0
  @Test
  public void testVoiceToString() {
    Voice voice1 = new Voice("Bass", 1.0);
    Voice voice2 = new Voice("Bass", 1.0);
    Voice voice3 = new Voice("Soprano", 1.0);
    Voice voice4 = new Voice("Bass", 1.5);
    Voice voice5 = new Voice("Soprano", 2.0);

    assertEquals(true, voice1.toString().equals(voice2.toString()));
    assertEquals(true, voice1.toString().equals(voice1.toString()));
    assertEquals(false, voice1.toString().equals(voice3.toString()));
    assertEquals(true, voice1.toString().equals(voice4.toString()));
    assertEquals(false, voice1.toString().equals(voice5.toString()));
  }
 @Override
 public void visit(Voice voice) {
   this.musicForVoiceName.put(voice.getVoiceName(), voice.getSongComponents());
 }
예제 #19
0
  @Test
  public void testVoiceGetTicksPerWholeNote() {
    Voice voice1 = new Voice("Bass", 1.0);
    Voice voice2 = new Voice("Soprano", 1.0);
    Voice voice3 = new Voice("Tenor", 1.0);
    Voice voice4 = new Voice("Bob", 1.0);

    Note note1 = new Note(new Pitch('C'), new Fraction(1, 4));
    Note note2 = new Note(new Pitch('E'), new Fraction(1, 2));
    Note note3 = new Note(new Pitch('C'), new Fraction(1, 2));
    Note note4 = new Note(new Pitch('F'), new Fraction(1, 4));

    try {
      voice1.addMusicalElement(note1);
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      voice2.addMusicalElement(note2);
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      voice3.addMusicalElement(note3);
    } catch (Exception e) {
      e.printStackTrace();
    }
    try {
      voice4.addMusicalElement(note4);
    } catch (Exception e) {
      e.printStackTrace();
    }

    assertEquals(true, voice1.getTicksPerWholeNote() == voice4.getTicksPerWholeNote());
    assertEquals(true, voice2.getTicksPerWholeNote() == voice3.getTicksPerWholeNote());
    assertEquals(false, voice1.getTicksPerWholeNote() == voice2.getTicksPerWholeNote());
  }