ScriptControl使ってHTAで音鳴らす
下の方で書いたRubyのコードにこんな風なのを付け足す。
def midiOpen MidiOut.open end def midiClose(handle) MidiOut.close(handle) end def midiSound(handle, sound_param) MidiOut.shortMsg(handle, sound_param) end
そしてHTAを適当に書く。
var rubyFile = "c:/ruby/test/winmm/test.rb"; var sc = new ActiveXObject("ScriptControl"); sc.Language = "RubyScript"; sc.AddCode(readData(rubyFile)); var ruby = sc.CodeObject; window.onload = function(){ $("sound").onclick = function(){ var handle = ruby.midiOpen(); var command = 255*0x10000 + 50*0x100 + 0x9 * 0x10; ruby.midiSound(handle, command); ruby.midiClose(handle); }; }; function $(id){ return document.getElementById(id); } function readData(path){ var fso; try{ fso = WScript.CreateObject("Scripting.FileSystemObject"); } catch(e){ fso = new ActiveXObject("Scripting.FileSystemObject"); } var ForReading = 1; var ts = fso.OpenTextFile(path, ForReading); var s = ts.ReadAll(); ts.Close(); return s; }
soundボタンを押すとちゃんと音が鳴ったけど、2回目以降鳴らないな。眠いからやめた。