【问题标题】:How to get a reference to a non default MIDI Sequencer?如何获取对非默认 MIDI 音序器的引用?
【发布时间】:2012-06-11 21:42:17
【问题描述】:

我正在构建一个 Java 应用程序,它以编程方式生成一个 MIDI 序列,然后通过 LoopBe Internal Midi Port 发送,以便我可以使用 Ableton Live 乐器获得更好的声音播放质量。

如果我错了,请纠正我。我需要的是生成一个Sequence,其中包含Tracks,其中包含MidiEvents,其中包含MIDI messages 和时间信息。我想我下来了。

真正的问题是如何通过 LoopBe MIDI 端口发送它。为此,我应该需要一个Sequencer,但我不知道如何获得一个而不是默认的,我不想要那个。

我想一种解决方法是将序列写入 .mid 文件,然后以编程方式在 LoopBe 端口上播放它。

所以我的问题是:如何获得非默认的 Sequencer?

【问题讨论】:

标签: java midi javasound


【解决方案1】:

你需要方法MidiSystem.getSequencer(boolean)。当您使用false 参数调用它时,它会为您提供未连接的音序器。

从您的目标 MIDI 设备获取 Receiver 实例,并使用 seq.getTransmitter().setReceiver(rec) 调用将其设置为音序器。

示例 sn-p:

MIDIDevice device = ... // obtain the MIDIDevice instance
Sequencer seq = MidiSystem.getSequencer(false);
Receiver rec = device.getReceiver();
seq.getTransmitter().setReceiver(rec)

有关 Sequencer 的使用示例,请参阅http://docs.oracle.com/javase/tutorial/sound/MIDI-seq-methods.html 上的教程

【讨论】:

  • 完美。在 mac 上,必须使用外部库,例如“coreMidi4j”才能查看所有可用的外部 MIDI 设备。
【解决方案2】:

对于我自己的项目,我使用 LoopBe1 将 MIDI 信号发送到 REAPER。 当然,LoopBe1 应该已经安装好了。

在这个例子中,我为 LoopBe 的外部 MIDI 端口遍历系统的 MIDI 设备,然后发送音符 C 10 次。

import javax.sound.midi.*;

public class Main {
    public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, InterruptedException {
        MidiDevice external;

        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();

        //Iterate through the devices to get the External LoopBe MIDI port

        for (MidiDevice.Info deviceInfo : devices) {

            if(deviceInfo.getName().equals("LoopBe Internal MIDI")){
                if(deviceInfo.getDescription().equals("External MIDI Port")){
                    external = MidiSystem.getMidiDevice(deviceInfo);
                    System.out.println("Device Name : " + deviceInfo.getName());
                    System.out.println("Device Description : " + deviceInfo.getDescription() + "\n");

                    external.open();
                    Receiver receiver = external.getReceiver();
                    ShortMessage message = new ShortMessage();


                    for (int i = 0; i < 10; i++) {
                        // Start playing the note Middle C (60),
                        // moderately loud (velocity = 93).
                        message.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
                        long timeStamp = -1;
                        receiver.send(message, timeStamp);
                        Thread.sleep(1000);
                    }

                    external.close();
                }
            }
        }
    }
}

有关发送 MIDI 信号的更多信息,请参阅此链接:

https://docs.oracle.com/javase/tutorial/sound/MIDI-messages.html

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多