将连续控制器数据写入 MIDI 文件
我正在尝试编写一个java程序,从图像中读取数据并将其转换为midi数据。我已经使用正确的 MIDI 音符打开和音符关闭消息创建了多个轨道。但是,我还想将连续的控制器数据写入每个轨道(未使用的滑块或旋钮,而不是调制轮或弯音等预定通道之一)。我假设我需要使用 CONTROL_CHANGE ShortMessage 做一些事情,但我可能是错的。 (http://docs.oracle. com/javase/7/docs/api/javax/sound/midi/ShortMessage.html#CONTROL_CHANGE)。我真的没有java编程知识来解决这个问题。这是迄今为止我创建音符开/关 MIDI 数据的内容。我假设连续控制器数据将具有类似的设计。任何帮助将不胜感激。
private static MidiEvent createNoteOnEvent(int nKey, long lTick)
{
return createNoteEvent(ShortMessage.NOTE_ON,
nKey,
VELOCITY,
lTick);
}
private static MidiEvent createNoteOffEvent(int nKey, long lTick)
{
return createNoteEvent(ShortMessage.NOTE_OFF,
nKey,
0,
lTick);
}
private static MidiEvent createNoteEvent(int nCommand,
int nKey,
int nVelocity,
long lTick)
{
ShortMessage message = new ShortMessage();
try {
message.setMessage(nCommand,
0,
nKey,
nVelocity);
}
catch (InvalidMidiDataException e)
{
e.printStackTrace();
System.exit(1);
}
MidiEvent event = new MidiEvent(message,
lTick);
return event;
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
I'm trying to write a java program that reads data from an image and turns it into midi data. I've gotten as far as creating multiple tracks with the proper midi note on and note off messages. However, I also want to write continuous controller data to each track (an unused slider or knob, not one of the predetermined channels such as modwheel or pitchbend). I'm assuming I need to be doing some with the CONTROL_CHANGE ShortMessage, but I could be wrong. (http://docs.oracle.com/javase/7/docs/api/javax/sound/midi/ShortMessage.html#CONTROL_CHANGE). I don't really have the java programming knowledge to figure this out. Here's what I have thus far for creating the note on/off midi data. I assume the continuous controller data would be of a similiar design. Any help would be appreciated.
private static MidiEvent createNoteOnEvent(int nKey, long lTick)
{
return createNoteEvent(ShortMessage.NOTE_ON,
nKey,
VELOCITY,
lTick);
}
private static MidiEvent createNoteOffEvent(int nKey, long lTick)
{
return createNoteEvent(ShortMessage.NOTE_OFF,
nKey,
0,
lTick);
}
private static MidiEvent createNoteEvent(int nCommand,
int nKey,
int nVelocity,
long lTick)
{
ShortMessage message = new ShortMessage();
try {
message.setMessage(nCommand,
0,
nKey,
nVelocity);
}
catch (InvalidMidiDataException e)
{
e.printStackTrace();
System.exit(1);
}
MidiEvent event = new MidiEvent(message,
lTick);
return event;
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了,以防其他人遇到同样的问题。十六进制 0xB0 只是标准的连续控制器数据通道。只需键入 17,不需要十六进制。其他频道可以通过谷歌搜索 midi 格式或类似的东西找到:
Figured it out, in case someone else runs across the same problem. The hex 0xB0 is just the standard continuous controller data channel. 17 could just be typed, hex isn't required. Other channels can be found by Googling midi format or something like that:
预定义的 MIDI CC 例如音量、弯音等,这些只是推荐的分配,但从技术上讲,您可以使用任何 CC 作为您想要的备用旋钮或滑块。
The pre-defined MIDI CC's such as volume, pitchbend, etc, are just recommended assignments, but you can technically use any CC for a spare knob or slider that you wish.