使用Midi Sequencer时返回错误代码 [英] Error Code Returned when using Midi Sequencer

查看:93
本文介绍了使用Midi Sequencer时返回错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与Midi Sequencer一起玩,并进行练习,其中涉及使用ControlEventListener根据音乐的节拍在面板上以随机的颜色,形状和位置重新绘制正方形.当我在笔记本电脑上执行此操作时,一切正常.但是,当我在PC上执行此操作时,出现此错误:

I have been playing with the Midi Sequencer and doing an exercise involving repainting squares on a panel in random colors, shapes, and locations based on the beat of the music using a ControlEventListener. When I do this on my laptop, everything works just fine. However, when I do this on my PC, I get this error:

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的书中摘录的,我只对面板进行了一些更改以调整代码以做一些不同的事情. 有人知道此代码的含义吗? 我已经用谷歌搜索了,什么也没找到.这本书没有任何关于这种代码的说明.

The program works just fine. Compiles and does exactly what it's supposed to do, and, as I stated earlier, I have no problems with this exact code on my laptop.
Also, much of this code was taken out of a book about Java, I only made a few changes to the panel to tweak the code to do the same thing a little differently. Does anyone know what this code means? I've googled for it and found nothing. The book states nothing about this kind of code.

任何帮助将不胜感激.预先感谢您花费时间阅读本文档以及您花费任何时间来帮助解决此问题.

Any help would be greatly appreciated. Thank you in advance for your time reading this and any time that you spend helping with this question.

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);
    }
}

推荐答案

只需关闭警告日志即可:

Just let the warning log shut up:

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

这篇关于使用Midi Sequencer时返回错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆