예제 #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();
    }
  }
예제 #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();
    }
  }