使用Midi Sequencer时返回错误代码

时间:2013-08-07 17:19:56

标签: java midi

我一直在使用Midi Sequencer进行练习,并使用ControlEventListener根据音乐的节拍以随机颜色,形状和位置重新绘制面板上的方块。当我在笔记本电脑上执行此操作时,一切正常。但是,当我在我的电脑上执行此操作时,我收到此错误:

Aug 07, 2013 1:10:11 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
BUILD SUCCESSFUL (total time: 27 seconds)

程序运行正常。编译并完成它应该做的事情,并且,正如我之前所说,我的笔记本电脑上的这些确切代码没有问题。
此外,大部分代码都是从一本关于Java的书中删除的,我只对面板进行了一些更改,以调整代码以稍微不同地执行相同的操作。 有谁知道这段代码是什么意思? 我用Google搜索并没有发现任何东西。这本书没有说明这种代码。

非常感谢任何帮助。提前感谢您阅读本文以及您花时间帮助解决此问题的时间。

This is the code in its entirity:

import javax.swing.*;
import java.awt.*;
import javax.sound.midi.*;

public class Check implements ControllerEventListener{
    JFrame frame;
    DrawPanel dp;
    public void controlChange(ShortMessage a) {
        frame.repaint();
    }
    public static void main(String[] args) {
        new Check().buildGui();
    }
    private void buildGui() {
        frame = new JFrame("Woot");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        dp = new DrawPanel();

        frame.getContentPane().add(dp);

        frame.setVisible(true);
        frame.setSize(500, 500);
        frame.setResizable(false);
        frame.setLocation(375, 50);
        playMusic();
    }
    private void playMusic() {
        try {
        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();
        int[] trackedInt = {127};
        sequencer.addControllerEventListener(this, trackedInt);

        Sequence seq = new Sequence(Sequence.PPQ,4);
        Track track = seq.createTrack();

        for(int i = 0; i < 50; i++) {
            int rI = (int)(Math.random()*50)+30;
            track.add(makeEvent(144,9,rI,100,i*10));
            track.add(makeEvent(176,1,127,0,i*10));
            track.add(makeEvent(128,9,rI,0,i*2+2));
        }

        sequencer.setSequence(seq);
        sequencer.setTempoInBPM(160);
        sequencer.start();
        } catch(Exception exc){}
    }
    private MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
       MidiEvent event = null;
       try {
           ShortMessage a = new ShortMessage();
           a.setMessage(comd, chan, one, two);
           event = new MidiEvent(a, tick);
       } catch (Exception exc){}
       return event;
    }
}
class DrawPanel extends JPanel {
    public void paintComponent(Graphics g) {
        int r = (int)(Math.random()*256);
        int gr = (int)(Math.random()*256);
        int b = (int)(Math.random()*256);
        g.setColor(new Color(r,gr,b));
        int x = (int)(Math.random()*200)+20;
        int y = (int)(Math.random()*200)+20;
        int h = (int)(Math.random()*500)+20;
        int w = (int)(Math.random()*500)+20;
        g.fillRect(x, y, w, h);
    }
}

1 个答案:

答案 0 :(得分:-2)

只需关闭警告日志:

PlatformLogger.getLogger("java.util.prefs")
        .setLevel(PlatformLogger.Level.SEVERE);