将连续控制器数据写入 MIDI 文件

发布于 2025-01-08 15:23:28 字数 1815 浏览 2 评论 0原文

我正在尝试编写一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与他有关 2025-01-15 15:23:28

想通了,以防其他人遇到同样的问题。十六进制 0xB0 只是标准的连续控制器数据通道。只需键入 17,不需要十六进制。其他频道可以通过谷歌搜索 midi 格式或类似的东西找到:

private static MidiEvent createCCData(int cc, int val, long lTick) {
    ShortMessage mm = new ShortMessage();
    mm = new ShortMessage();
    try {
        mm.setMessage(0xB0,cc,val);
    } 
    catch (InvalidMidiDataException e) {
        e.printStackTrace();
        System.exit(1);
    }
    MidiEvent me = new MidiEvent(mm,lTick);     
    return me;
}

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:

private static MidiEvent createCCData(int cc, int val, long lTick) {
    ShortMessage mm = new ShortMessage();
    mm = new ShortMessage();
    try {
        mm.setMessage(0xB0,cc,val);
    } 
    catch (InvalidMidiDataException e) {
        e.printStackTrace();
        System.exit(1);
    }
    MidiEvent me = new MidiEvent(mm,lTick);     
    return me;
}
末蓝 2025-01-15 15:23:28

预定义的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文