制作 midi:midifile 的实例

发布于 2024-09-29 19:08:16 字数 835 浏览 5 评论 0原文

我正在为我正在进行的一个小项目使用 Lisp MIDI 库。首先,我尝试编写一个简单的 MIDI 文件来播放中音 C。但是我似乎无法让它工作,也找不到任何有关如何执行此类操作的文档。这是我的代码:

(defun make-track () 
  (list
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 0)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 0)))

(defun make-tracks ()
  (list (make-track)))

(defun try-to-write-midi-file ()
  (let* ((my-midi-file (make-instance 'midi:midifile
                     :format 1
                     :tracks (make-tracks)
                     :division 25)))
    (midi:write-midi-file my-midi-file "opus.mid")))

它正在创建一个 MIDI 文件,但持续时间为 0 秒,其中似乎没有播放中音 C。

谁能告诉我我在这里做错了什么?

I'm using a Lisp MIDI library for a small project I'm working on. Just to get started, I'm trying to write a simple MIDI file that plays middle C. However I can't seem to get this to work and can not find any documentation on how to do this sort of thing. Here is my code:

(defun make-track () 
  (list
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 0)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 0)))

(defun make-tracks ()
  (list (make-track)))

(defun try-to-write-midi-file ()
  (let* ((my-midi-file (make-instance 'midi:midifile
                     :format 1
                     :tracks (make-tracks)
                     :division 25)))
    (midi:write-midi-file my-midi-file "opus.mid")))

It is creating a MIDI file but one of 0 seconds duration, which does not seem to have a middle C playing in it.

Can anyone tell me what I'm doing wrong here?

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

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

发布评论

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

评论(1

美煞众生 2024-10-06 19:08:16

David Lewis,该库的维护者之一,向我解释了我做错了什么。这是正确的代码:

(defun make-track () 
  (list
   ;; The STATUS values you give to your messages gives the sequencer channel 
   ;; information but, rather than taking the channel as you'd expect to see it
   ;; (i.e. an integer between 0-15), it takes it in the form the MIDI itself 
   ;; uses, which for NOTE-ON is (+ 144 channel) and for NOTE-OFF is 
   ;; (+ 128 channel).
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 144)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 128)))

David Lewis, one of the maintainers of the library, explained to me what I was doing wrong. Here is the correct code:

(defun make-track () 
  (list
   ;; The STATUS values you give to your messages gives the sequencer channel 
   ;; information but, rather than taking the channel as you'd expect to see it
   ;; (i.e. an integer between 0-15), it takes it in the form the MIDI itself 
   ;; uses, which for NOTE-ON is (+ 144 channel) and for NOTE-OFF is 
   ;; (+ 128 channel).
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 144)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 128)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文