groovyでカエルの歌 2007/08/25

どう書く?org
Tiny MML どう書く?orgというお題があったので、思わずアカウントを作成して投稿してみた。

NoteChannelのplayNoteRawメソッドを使用しています。

pitch - MIDI pitch values (0 to 127, 60 is middle C)
velocity - velocity of note, where 0 = silence - note off.
NoteChannel


Note names, MIDI numbers and frequencies

pitchに-1入れて音がたまたまならなかったのですが、本当はもうちょっと丁寧処理したほうがいいのかもしれない。

import quicktime.QTSession
import quicktime.std.music.ToneDescription
import quicktime.std.music.NoteChannel
import quicktime.std.music.NoteRequest

// kaeru_song_player
// cがド、dがレ、eがミ、fがファ、gがソ、aがラ、bがシ、rが休符
def tbl = ['c':60, 'd':62, 'e':64, 'f':65, 'g':67, 'a':69, 'b':71, r:-1]
def song = "cdefedcrefgagfercrcrcrcrcdefedcr"

QTSession.open()
NoteChannel noteChannel = new NoteChannel(new NoteRequest(new ToneDescription(1)))

for(c in song){
noteChannel.playNoteRaw(tbl[c] as int, 60)
sleep(300)
}

QTSession.close()

: