コード例 #1
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
  @Test
  public void sampleTest2() {
    String input =
        "d^f^f ^cee|de^f g^fe|d^f^f ^cee|d^fe dBA|\n"
            + "d^f^f ^cee|de^f g^fe|^fa^f g^fe|[1 d^fe dBA:|[2 d^fe d^cB|]\n"
            + "A3 B3|g^fe ^fdB|A^FA B2^c|d^fe d^cB|\n"
            + "A3 B3|e^fe e^fg|^fa^f g^fe|[1 d^fe d^cB:|[2 d^fe dBA|]\n"
            + "^fAA eAA| de^f g^fe|^fAA eAA|d^fe dBA|\n"
            + "^fAA eAA| de^f g^fe|^fa^f g^fe|d^fe dBA:|\n";

    CharStream stream = new ANTLRInputStream(RepeatHandler.handleRepeats(input));
    MusicGrammarLexer lexer = new MusicGrammarLexer(stream);
    lexer.reportErrorsAsExceptions();
    TokenStream tokens = new CommonTokenStream(lexer);
    MusicGrammarParser parser = new MusicGrammarParser(tokens);
    parser.reportErrorsAsExceptions();
    ParseTree tree = parser.root();
    ParseTreeWalker walker = new ParseTreeWalker();
    ConstructMusic listener = new ConstructMusic(new HeaderInfo());
    walker.walk(listener, tree);
    Music sample = listener.getExpression();
    try {
      SequencePlayer player = new SequencePlayer(200, 12);
      sample.play(player, 0);
      player.play();
      Thread.sleep((long) sample.duration() * 1000);
    } catch (MidiUnavailableException | InvalidMidiDataException e) {
      e.printStackTrace();
    } catch (InterruptedException uie) {
      uie.printStackTrace();
    }
  }
コード例 #2
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
  @Test
  public void sampleTest() {
    String input =
        "C,, D,, E,, F,, | G,, A,, B,, C, | "
            + "C, D, E, F, | G, A, B, C | "
            + "C D E F | G A B c "
            + "| c d e f | g a b c' | "
            + "c' d' e' f' | g' a' b' c''\n";

    CharStream stream = new ANTLRInputStream(input);
    MusicGrammarLexer lexer = new MusicGrammarLexer(stream);
    lexer.reportErrorsAsExceptions();
    TokenStream tokens = new CommonTokenStream(lexer);
    MusicGrammarParser parser = new MusicGrammarParser(tokens);
    parser.reportErrorsAsExceptions();
    ParseTree tree = parser.root();
    ParseTreeWalker walker = new ParseTreeWalker();
    ConstructMusic listener = new ConstructMusic(new HeaderInfo());
    walker.walk(listener, tree);
    Music sample = listener.getExpression();
    try {
      SequencePlayer player = new SequencePlayer(140, 12);
      sample.play(player, 0);
      player.play();
      Thread.sleep((long) sample.duration() * 1000);
    } catch (MidiUnavailableException | InvalidMidiDataException e) {
      e.printStackTrace();
    } catch (InterruptedException uie) {
      uie.printStackTrace();
    }
  }
コード例 #3
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // chordEqualsFalseTest(): all false partitions covered except last
 @Test
 public void chordEqualsFalseTest() {
   Music a = new Chord(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Chord(new Note(3, new Pitch('D')), new Note(5, new Pitch('B'))).transpose(-2);
   Music c = new Chord(new Note(2, new Pitch('D')).transpose(-2), new Note(5, new Pitch('B')));
   assertFalse(a.equals(b));
   assertFalse(b.equals(c));
   assertFalse(a.equals(c));
 }
コード例 #4
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // parallelEqualsFalseTest(): all false partitions covered except last
 @Test
 public void parallelEqualsFalseTest() {
   Parallel a = new Parallel(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Parallel(new Note(3, new Pitch('D')), new Note(5, new Pitch('B'))).transpose(-2);
   Music c = new Parallel(new Note(2, new Pitch('D')).transpose(-2), new Note(5, new Pitch('B')));
   assertFalse(a.equals(b));
   assertFalse(b.equals(c));
   assertFalse(a.equals(c));
 }
コード例 #5
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicPlayEmptyTest(): empty music
 @Test
 public void musicPlayEmptyTest() {
   SequencePlayer player;
   try {
     player = new SequencePlayer(140, 12);
     Music empty = new Parallel(new Rest(0), new Merge(new Rest(0), new Rest(0)));
     empty.play(player, 0);
     assertEquals("Meta event: END_OF_TRACK Tick: 0\n", player.toString());
   } catch (MidiUnavailableException | InvalidMidiDataException e) {
     e.printStackTrace();
   }
 }
コード例 #6
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicPlaySingleNoteTest(): single note
 @Test
 public void musicPlaySingleNoteTest() {
   SequencePlayer player;
   try {
     player = new SequencePlayer(140, 12);
     Music a = new Note(1, new Pitch('A'));
     a.play(player, 0);
     assertEquals(
         "Event: NOTE_ON  Pitch: 69  Tick: 0\n"
             + "Event: NOTE_OFF Pitch: 69  Tick: 12\n"
             + "Meta event: END_OF_TRACK Tick: 12\n",
         player.toString());
   } catch (MidiUnavailableException | InvalidMidiDataException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicTransposeLargeCaseTest(): row row row your boat
 @Test
 public void musicTransposeLargeCaseTest() {
   String transposedRowRowRowYourBoatString =
       "D1.0 D1.0 D0.75 E0.25 ^F1.0 ^F0.75 E0.25 ^F0.75 G0.25 A2.0 "
           + "D'0.3333333333333333 D'0.3333333333333333 D'0.3333333333333333 "
           + "A0.3333333333333333 A0.3333333333333333 A0.3333333333333333 "
           + "^F0.3333333333333333 ^F0.3333333333333333 ^F0.3333333333333333 "
           + "D0.3333333333333333 D0.3333333333333333 D0.3333333333333333 "
           + "A0.75 G0.25 ^F0.75 E0.25 D2.0";
   assertEquals(transposedRowRowRowYourBoatString, rowRowRowYourBoat.transpose(2).toString());
 }
コード例 #8
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicPlayLargeCaseTest(): row row row your boat
 @Test
 public void musicPlayLargeCaseTest() {
   try {
     SequencePlayer player = new SequencePlayer(140, 12);
     rowRowRowYourBoat.play(player, .125);
     player.play();
     Thread.sleep(10000);
   } catch (MidiUnavailableException mue) {
     mue.printStackTrace();
   } catch (InvalidMidiDataException imde) {
     imde.printStackTrace();
   } catch (InterruptedException ie) {
     ie.printStackTrace();
   }
 }
コード例 #9
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // chordlHashCodeTest()
 @Test
 public void chordHashCodeTest() {
   Chord a = new Chord(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Chord(new Note(2, new Pitch('D')), new Note(5, new Pitch('B'))).transpose(-2);
   assertEquals(a.hashCode(), b.hashCode());
 }
コード例 #10
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // mergeEqualsFalseWrongOrderTest(): musics are identical but in wrong order
 @Test
 public void mergeEqualsFalseWrongOrderTest() {
   Music a = new Merge(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Merge(new Note(5, new Pitch('A')), new Note(2, new Pitch('C')));
   assertFalse(a.equals(b));
 }
コード例 #11
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicTransposeEmptyTest(): empty music
 @Test
 public void musicTransposeEmptyTest() {
   Music empty = new Parallel(new Rest(0), new Merge(new Rest(0), new Rest(0)));
   Music emptyTransposed = empty.transpose(10);
   assertEquals(empty, emptyTransposed);
 }
コード例 #12
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicDurationLargeCaseTest(): row row row your boat
 @Test
 public void musicDurationLargeCaseTest() {
   assertTrue(16.0 == rowRowRowYourBoat.duration());
 }
コード例 #13
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicDurationSingleNoteTest(): single note
 @Test
 public void musicDurationSingleNoteTest() {
   Music singleNote =
       new Parallel(new Rest(0), new Merge(new Note(5.5, new Pitch(66)), new Rest(0)));
   assertTrue(singleNote.duration() == 5.5);
 }
コード例 #14
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicDurationEmptyTest(): empty music
 @Test
 public void musicDurationEmptyTest() {
   Music empty = new Parallel(new Rest(0), new Merge(new Rest(0), new Rest(0)));
   assertTrue(empty.duration() == 0);
 }
コード例 #15
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // parallelHashCodeTest()
 @Test
 public void parallelHashCodeTest() {
   Parallel a = new Parallel(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Parallel(new Note(2, new Pitch('D')), new Note(5, new Pitch('B'))).transpose(-2);
   assertEquals(a.hashCode(), b.hashCode());
 }
コード例 #16
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // musicTransposeSingleNoteTest(): single note
 @Test
 public void musicTransposeSingleNoteTest() {
   Music a = new Note(1, new Pitch('A'));
   Music c = new Note(1, new Pitch('C'));
   assertEquals(a.transpose(2), c.transpose(11));
 }
コード例 #17
0
ファイル: MusicTest.java プロジェクト: amargvela/abc_player
 // mergeHashCodeTest()
 @Test
 public void mergeHashCodeTest() {
   Music a = new Merge(new Note(2, new Pitch('C')), new Note(5, new Pitch('A')));
   Music b = new Merge(new Note(2, new Pitch('D')), new Note(5, new Pitch('B'))).transpose(-2);
   assertEquals(a.hashCode(), b.hashCode());
 }