将 MIDI 事件添加到时钟 - Java

发布于 2024-10-04 18:10:09 字数 299 浏览 4 评论 0原文

我正在使用 C# 创建一个简单的 MIDI 应用程序,其中包含一个开源库,该库允许用户指定通道、音高和速度并将它们添加到时钟。然后,该时钟可以按照添加的顺序播放所有音符。

一切都运行良好,现在我正在创建应用程序的 Java 版本,我似乎遇到的唯一麻烦是我找不到任何简单的教程或解释时钟系统如何在 MIDI Java 中工作。

Java 声音框架中是否存在时钟,或者这是我必须自己实现的东西?

谢谢!

I am creating a simple MIDI application in C# with an open source library that allows the user to specify a channel, pitch and velocity and add them to a Clock. This clock can then play all the notes in the sequence that they were added.

Everything works great and now I am in the process of creating a Java version of the application, the only trouble I seem to be having is that I can't find any simple tutorial or explanation of how the clock system works within MIDI Java.

Does the Clock exist in Java Sound Framework or is this something I will have to implement myself?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

勿忘初心 2024-10-11 18:10:09

我已经很长时间没有接触 Java Midi 了,但一般来说,要以编程方式构建 MIDI,您需要执行以下步骤。

假设import javax.sound.midi;

  1. 您需要创建一个Sequencer对象:

    序列 seq = new Sequence(Squence.PPQ, 500000);
    
  2. 接下来,您需要创建一个 Track 对象(每个通道一个或所有通道一个) ,这取决于你):

    Track track = seq.createTrack();
    
  3. 现在,您可以向其中添加事件:

    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_ON, 0, 60, 127), 0));
    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_OFF, 0, 60, 127), 1000));
    //ETC。
    
  4. 完成后,您就可以像平常一样播放Sequence

查看此处的文档: http ://download.oracle.com/javase/7/docs/api/index.html?javax/sound/midi/MidiSystem.html

It's been a long time since I've touched the Java Midi stuff, but in general, to programmatically build a MIDI, you need to do the following steps.

Assuming import javax.sound.midi;:

  1. You need to create a Sequencer object:

    Sequence seq = new Sequence(Squence.PPQ, 500000);
    
  2. Next, you need to create a Track object (one per channel or one for everything, it's up to you):

    Track track = seq.createTrack();
    
  3. Now, you can add events to it:

    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_ON, 0, 60, 127), 0));
    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_OFF, 0, 60, 127), 1000));
    //etc.
    
  4. When you're done that, you can then play the Sequence like normal!

Check out the docs here: http://download.oracle.com/javase/7/docs/api/index.html?javax/sound/midi/MidiSystem.html

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