gpt4 book ai didi

java - MIDI 乐器列表?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:05:20 25 4
gpt4 key购买 nike

我最近用 Head First Java 中的代码实现了一个 MIDI Beatbox,并且真的很想用 Java 的 MIDI 功能做更多的事情。我想我可以从向现有代码添加更多非打击乐器开始,但我似乎无法找到可用乐器及其 int 键的简单列表。

JDK 附带的Soundbank是否存在这样的列表?

最佳答案

像这样运动吗?

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

class Instruments {

public static void main(String[] args) throws MidiUnavailableException {
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
Instrument[] orchestra = synthesizer.getAvailableInstruments();

final StringBuilder sb = new StringBuilder();
String eol = System.getProperty("line.separator");
sb.append("The orchestra has ");
sb.append(orchestra.length);
sb.append(" instruments.");
sb.append(eol);
for (Instrument instrument : orchestra) {
sb.append(instrument.toString());
sb.append(eol);
}
synthesizer.close();

Runnable r = new Runnable() {

@Override
public void run() {
JOptionPane.showMessageDialog(null,
new JScrollPane(new JTextArea(sb.toString(), 20, 30)));
}
};
SwingUtilities.invokeLater(r);
}
}

输出

The orchestra has 411 instruments.
Instrument Piano (bank 0 program 0)
Instrument Bright Piano (bank 0 program 1)
Instrument Electric Grand (bank 0 program 2)
Instrument Honky Tonk Piano (bank 0 program 3)
Instrument Electric Piano 1 (bank 0 program 4)
Instrument Electric Piano 2 (bank 0 program 5)
Instrument Harpsichord (bank 0 program 6)
Instrument Clavinet (bank 0 program 7)
Instrument Celesta (bank 0 program 8)
Instrument Glockenspiel (bank 0 program 9)
...

关于java - MIDI 乐器列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7809581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com