跳转到内容

LNNBot/  /musicjs

来自希顶维基
DGCK81LNN留言 | 贡献2025年9月20日 (六) 23:35的版本 (创建页面,内容为“{{LNNBot指令信息 |别名= |属性= |所属插件=[https://github.com/DGCK81LNN/koishi-plugin-music @dgck81lnn/music] |父级指令=util.script |所需权限= }} '''<code>musicjs</code>''' 允许用户通过一套 JavaScript API 来合成旋律。 == 用法 == musicjs <code...> <code>code</code> 为 JavaScript 代码,提供以下函数和变量: * <code>note(tone: number, beats: number, temperament = 12)</code> 创建平均律音符 *: 相当于 <c…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
musicjs
     @dgck81lnn/music
     util.script

musicjs          JavaScript API      。

  

musicjs <code...>

code   JavaScript   ,         :

  • note(tone: number, beats: number, temperament = 12)        
        noteHz(baseFrequency * (2 ** (tone / temperament)), beats)
    • tone             (     ,     )
    • beats      ( )
    • temperament        ;      tone      
  • noteJust(ratio: number, beats: number)       
        noteHz(baseFrequency * ratio, beats)
    • ratio              
    • beats      ( )
  • noteHz(frequency: number, beats: number)            
    • frequency    (  )
    • beats      ( )
  • rest(beats: number)   
    • beats      ( )
  • bpm: Number = 120      
              ,                       ,          ;          ,       。
  • baseFrequency = 440      
  • gain = 0.5   
  • time = 0      ( )

              time     ,              。          (   rest()       )                    。  ,  《D    》        :

bpm = 60
note(9, 1); note(7, 1); note(5, 1); note(4, 1) // #F5 E5 D5 #C5
note(2, 1); note(0, 1); note(2, 1); note(4, 1) // B4 A4 B4 #C5
// 由于速度为每分钟 60 拍,演奏了 8 个一拍长的音符,此时 time 为 8.0
// 我们回到最开头,再创建大提琴的音符
time = 0 // 也可以用 rest(-8),后退 8 拍
note(-19, 1); note(-24, 1); note(-22, 1); note(-27, 1) // D3 A2 B2 #F2
note(-26, 1); note(-31, 1); note(-26, 1); note(-24, 1) // G2 D2 G2 A2