C 没有声音。通过RubyDL使用Ruby和winmm
预期行为:在一个midi设备上播放中间C,然后在另一个midi设备上播放。实际行为:DL弃用警告,没有声音。运行Windows7 守则:C 没有声音。通过RubyDL使用Ruby和winmm,c,ruby,windows,midi,rubydl,C,Ruby,Windows,Midi,Rubydl,预期行为:在一个midi设备上播放中间C,然后在另一个midi设备上播放。实际行为:DL弃用警告,没有声音。运行Windows7 守则: require "dl/import" class LiveMIDI ON = 0x90 OFF =0x80 PC = 0xc0 def initialize open end def note_on(channel, note, velocity=64) message(O
require "dl/import"
class LiveMIDI
ON = 0x90
OFF =0x80
PC = 0xc0
def initialize
open
end
def note_on(channel, note, velocity=64)
message(ON | channel, note, velocity)
end
def note_off(channel, note, velocity=64)
message(OFF | channel, note, velocity)
end
def program_change(channel, preset)
message(PC | channel, preset)
end
module C
extend DL::Importer
dlload "winmm"
extern "int midiOutOpen(HMIDIOUT*, int, int, int, int)"
extern "int midiOutClose(int)"
extern "int midiOutShortMsg(int, int)"
end
def open
@device = DL.malloc(DL::Importer.sizeof("int"))
C.midiOutOpen(@device, -1, 0, 0, 0)
end
def close
C.midiOutClose(@device.ptr.to_i)
end
def message(one, two=0, three=0)
message = one + (two << 8) + (three << 16)
C.midiOutShortMsg(DL::CPtr.to_ptr(@device).to_i, message)
end
end
midi = LiveMIDI.new
midi.note_on(0, 60, 100)
sleep(1)
midi.note_off(0, 60)
midi.program_change(1, 40)
midi.note_on(1, 60, 100)
sleep(1)
midi.note_off(1, 60)
需要“dl/import”
LiveMIDI类
ON=0x90
关闭=0x80
PC=0xc0
def初始化
打开
结束
def注释打开(通道,注释,速度=64)
信息(在|通道、注释、速度上)
结束
def注释关闭(通道,注释,速度=64)
信息(非通道、注释、速度)
结束
def程序_更改(频道、预设)
消息(PC |频道,预设)
结束
模块C
扩展DL::导入程序
dlload“winmm”
外部“int midiOutOpen(HMIDIOUT*,int,int,int,int)”
外部“int midiOutClose(int)”
外部“内部midiOutShortMsg(内部,内部)”
结束
def打开
@device=DL.malloc(DL::Importer.sizeof(“int”))
C.midiOutOpen(@device,-1,0,0,0)
结束
def关闭
C.midiOutClose(@device.ptr.to_i)
结束
def消息(一,二=0,三=0)
信息=1+(2你必须写
DL::CPtr.malloc(DL::Importer.sizeof("int")
而不是
DL.malloc(DL::Importer.sizeof("int"))
创建一个指针对象(DL::CPtr
),而不仅仅是获取一个作为整数的地址
也
一定是
@device.ptr.to_i
甚至可能
@device.ptr
以下是使用DL替换的代码的固定版本:
require'fiddle/import'
需要“提琴/打字”
LiveMIDI类
ON=0x90
关闭=0x80
PC=0xc0
def初始化
打开
结束
def注释打开(通道,注释,速度=64)
信息(在|通道、注释、速度上)
结束
def注释关闭(通道,注释,速度=64)
信息(非通道、注释、速度)
结束
def程序_更改(频道、预设)
消息(PC |频道,预设)
结束
模块C
扩展小提琴::导入器
dlload'winmm'
#定义一些特定于Windows的类型,如DWORD或UINT
include Fiddle::Win32Types
#上一行未定义的某些其他类型
类型别名'HMIDIOUT','void*'
类型别名'LPHMIDIOUT','HMIDIOUT*'
类型别名'DWORD_PTR','uintpttr_t'
类型别名“MMRESULT”、“UINT”
外部“MMR结果midiOutOpen(LPHMIDIOUT、UINT、DWORD_PTR、DWORD_PTR、DWORD)”
外部“mmoutclose(HMIDIOUT)”命令
外部'MMG(HMIDIOUT,DWORD)'
结束
def打开
@device=Fiddle::Pointer.malloc(Fiddle::SIZEOF\u VOIDP)
C.midiOutOpen(@device,-1,0,0,0)
结束
def关闭
C.midiOutClose(@device.ptr)
结束
def消息(一,二=0,三=0)
message=1+(2我认为应该是DL::CPtr.malloc(DL::Importer.sizeof(“int”)
和@device.ptr.to_I
而不是DL::CPtr.to_ptr(@device.to_I
)。此外,一些类型是错误的,代码可能在64位Windows上不起作用。除非有可能的答案,否则我无法使用Fiddle(DL的继任者)进行测试对你来说没问题。太好了!我做了更改,它成功了!如果你想做这些更改并将其作为答案发布,我会接受。如果你给我看小提琴代码,我也会很感激。非常感谢!
@device.ptr
require 'fiddle/import'
require 'fiddle/types'
class LiveMIDI
ON = 0x90
OFF = 0x80
PC = 0xc0
def initialize
open
end
def note_on(channel, note, velocity = 64)
message(ON | channel, note, velocity)
end
def note_off(channel, note, velocity = 64)
message(OFF | channel, note, velocity)
end
def program_change(channel, preset)
message(PC | channel, preset)
end
module C
extend Fiddle::Importer
dlload 'winmm'
# defines a few Windows-specific types such as DWORD or UINT
include Fiddle::Win32Types
# some other types not defined by the previous line
typealias 'HMIDIOUT', 'void*'
typealias 'LPHMIDIOUT', 'HMIDIOUT*'
typealias 'DWORD_PTR', 'uintptr_t'
typealias 'MMRESULT', 'UINT'
extern 'MMRESULT midiOutOpen(LPHMIDIOUT, UINT, DWORD_PTR, DWORD_PTR, DWORD)'
extern 'MMRESULT midiOutClose(HMIDIOUT)'
extern 'MMRESULT midiOutShortMsg(HMIDIOUT, DWORD)'
end
def open
@device = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
C.midiOutOpen(@device, -1, 0, 0, 0)
end
def close
C.midiOutClose(@device.ptr)
end
def message(one, two = 0, three = 0)
message = one + (two << 8) + (three << 16)
C.midiOutShortMsg(@device.ptr, message)
end
end