赞 | 3 |
VIP | 1 |
好人卡 | 40 |
积分 | 1 |
经验 | 93188 |
最后登录 | 2020-7-27 |
在线时间 | 1379 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 76
- 在线时间
- 1379 小时
- 注册时间
- 2012-7-5
- 帖子
- 1698
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
我弃坑了 总之还是要把成果发出来
首先你需要有一个1.9.3的ruby然后gem install midilib <几秒钟就行了
然后你就可以运行这个了
需要midilib和1.9.3.rar
(8.85 KB, 下载次数: 56)
或者我也可以把代码扔出来 FILE部分自己改文件名即可
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib') require 'win32api' require 'midilib' MIDIOUTOPEN = Win32API.new("winmm","midiOutOpen","pllll","l") MIDIOUTCLOSE = Win32API.new("winmm","midiOutClose","l","l") MIDIOUTSHORTMSG = Win32API.new("winmm","midiOutShortMsg","ll","l") #MCISENDSTRING = Win32API.new("winmm","mciSendString","pll","l") hmidi = [0].pack("L") MIDIOUTOPEN.call(hmidi,-1,0,0,0) $hMidiOut = hmidi.unpack("L").first FILE = './2012822182130.mid' seq = MIDI::Sequence.new() File.open(FILE, 'rb') { | file | seq.read(file) { | track, num_tracks, i | } } def MidiOutMessage (iStatus,iChannel,iData1,iData2) dwMessage = iStatus | iChannel | (iData1 << 8) | (iData2 << 16) return MIDIOUTSHORTMSG.call($hMidiOut, dwMessage) end seq.each{|track| track.each{|event| print_decimal_numbers = true print_note_names = true note = event.instance_variable_get(:@note) time = event.instance_variable_get(:@delta_time) status = event.instance_variable_get(:@status) channel = event.instance_variable_get(:@channel) velocity = event.instance_variable_get(:@velocity) print "#{note} #{time} #{status} #{channel} #{velocity}\n" if note != nil next if note == nil sleep(time/1000.0) MidiOutMessage(status, channel, note, velocity) } } MIDIOUTCLOSE.call
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'win32api'
require 'midilib'
MIDIOUTOPEN = Win32API.new("winmm","midiOutOpen","pllll","l")
MIDIOUTCLOSE = Win32API.new("winmm","midiOutClose","l","l")
MIDIOUTSHORTMSG = Win32API.new("winmm","midiOutShortMsg","ll","l")
#MCISENDSTRING = Win32API.new("winmm","mciSendString","pll","l")
hmidi = [0].pack("L")
MIDIOUTOPEN.call(hmidi,-1,0,0,0)
$hMidiOut = hmidi.unpack("L").first
FILE = './2012822182130.mid'
seq = MIDI::Sequence.new()
File.open(FILE, 'rb') { | file |
seq.read(file) { | track, num_tracks, i |
}
}
def MidiOutMessage (iStatus,iChannel,iData1,iData2)
dwMessage = iStatus | iChannel | (iData1 << 8) | (iData2 << 16)
return MIDIOUTSHORTMSG.call($hMidiOut, dwMessage)
end
seq.each{|track|
track.each{|event|
print_decimal_numbers = true
print_note_names = true
note = event.instance_variable_get(:@note)
time = event.instance_variable_get(:@delta_time)
status = event.instance_variable_get(:@status)
channel = event.instance_variable_get(:@channel)
velocity = event.instance_variable_get(:@velocity)
print "#{note} #{time} #{status} #{channel} #{velocity}\n" if note != nil
next if note == nil
sleep(time/1000.0)
MidiOutMessage(status, channel, note, velocity)
}
}
MIDIOUTCLOSE.call
以及几秒钟的演示视频:本来就转码转的渣你们就不要吐槽了 |
|