LNNBot/ /musicjs
外观
musicjs
| ||
| | | |
| | @dgck81lnn/music | |
| | util.script
| |
musicjs JavaScript API 。
musicjs <code:rawtext>
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
musicjs*: aj() ,