Exemplo n.º 1
0
  @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();
    }
  }
Exemplo n.º 2
0
  @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();
    }
  }
Exemplo n.º 3
0
 // 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));
 }
Exemplo n.º 4
0
 // 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));
 }
Exemplo n.º 5
0
 // 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();
   }
 }
Exemplo n.º 6
0
 // 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();
   }
 }
Exemplo n.º 7
0
 // 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());
 }
Exemplo n.º 8
0
 // 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();
   }
 }
Exemplo n.º 9
0
 // 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());
 }
Exemplo n.º 10
0
 // 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));
 }
Exemplo n.º 11
0
 // 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);
 }
Exemplo n.º 12
0
 // musicDurationLargeCaseTest(): row row row your boat
 @Test
 public void musicDurationLargeCaseTest() {
   assertTrue(16.0 == rowRowRowYourBoat.duration());
 }
Exemplo n.º 13
0
 // 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);
 }
Exemplo n.º 14
0
 // 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);
 }
Exemplo n.º 15
0
 // 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());
 }
Exemplo n.º 16
0
 // 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));
 }
Exemplo n.º 17
0
 // 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());
 }