quicktimeのapiで鍵盤をだす。 groovyで。 2007/10/27
2007/10/27

quicktimeのapiを使って鍵盤をだすサンプルがあったので、それをgroovyにしてみました。といっても、ほとんどjavaですが。

必要なものquicktime for javaのライブラリ。
quicktimeがインストールされているだけでいいとは思うのですが、mac osx上でしか試していません。

もともとのサンプルは、Java QuickTime Sample Codeにあります。

参考
QuickTime for Java



import quicktime.*
import quicktime.std.music.*
import quicktime.std.StdQTException

try {
QTSession.open()
ToneDescription toneDesc = new ToneDescription ()
toneDesc.pickInstrument (NoteAllocator.getDefault(), "Choose an Instrument...", 0)
toneDesc.pickInstrument(NoteAllocator.getDefault(),
"Choose an Instrument...", 0)
toneDesc = new ToneDescription (25)

NoteChannel noteChan = new NoteChannel(new NoteRequest(toneDesc))
noteChan.playNote (60, 127)
Thread.sleep (2000)
noteChan.playNote (60, 0)
} catch(e){
//e.printStackTrace()
} finally {
QTSession.close()
}



mac osx上のeclipse上で実行した模様

: