MIDIでド
おお、鳴った。
require "dl/import" module MidiOut LIB = DL.dlopen("winmm") module_function def open midiOutOpen = LIB["midiOutOpen", "Ilpppp"] r, rs = midiOutOpen.call(0, nil, nil, nil, nil) return rs[0] end module_function def close(handle) midiOutClose = LIB["midiOutClose", "IL"] r, rs = midiOutClose.call(handle) return r end module_function def shortMsg(handle, sound) midiOutShortMsg = LIB["midiOutShortMsg", "ILL"] r, rs = midiOutShortMsg.call(handle, sound) return r end end h = MidiOut.open MidiOut.shortMsg(h, 0x7f3c90) MidiOut.close(h)
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回目以降鳴らないな。眠いからやめた。