ll_libload winmm, "winmm.dll"
ll_getproc midiOutOpen, "midiOutOpen", winmm
ll_getproc midiOutShortMsg, "midiOutShortMsg", winmm
ll_getproc midiOutReset, "midiOutReset", winmm
ll_getproc midiOutClose, "midiOutClose", winmm
ll_getproc midiOutShortMsg, "midiOutShortMsg", winmm
#module
#deffunc midiopen
ll_getptr midh : ll_ret ptr
prm = ptr, -1, 0, 0, 0
ll_callfunc prm, 4, midiOutOpen@ // MIDIデバイスオープン
return
#deffunc midisetkey int, int, int
mref key, 0 : mref velocity, 1 : mref channel, 2
if midh = 0 : midiopen
prm = midh, 0x003C90 + (velocity * 0x10000) + (key * 0x100) + channel
ll_callfunc prm, 2, midiOutShortMsg@ // 音を鳴らす
return
#deffunc midireset
if midh : ll_callfunc midh, 1, midiOutReset@ // 全て停止
return
#deffunc midiclose onexit
if midh : ll_callfunc midh, 1, midiOutClose@
return
#deffunc midisettone int, int
mref tone, 0 : mref channel, 1
if midh = 0 : midiopen
prm = midh, tone * 0x100 + 0xC0 + channel
ll_callfunc prm, 2, midiOutShortMsg@ // 音色を変更
return
#global
sdim types, 16, 8
sdim list, 128
dim typno, 8
dim push, 56
dim sleep, 56
types = "ピアノ", "オルガン", "アコーディオン", "バイオリン", "トランペット", "サックス", "尺八", "三味線"
typno = 0, 16, 21, 40, 56, 64, 77, 106
// 音階
push.0 = 0, 2, 4, 0, 4, 0, 4 // ドレミドミドミ
push.7 = 2, 4, 5, 5, 4, 2, 5 // レミファファミレファ
push.14 = 4, 5, 7, 4, 7, 4, 7 // ミファソミソミソ
push.21 = 5, 7, 9, 9, 7, 5, 9 // ファソララソファラ
push.28 = 7, 0, 2, 4, 5, 7, 9 // ソドレミファソラ〜
push.35 = 9, 2, 4, 6, 7, 9, 11 // ラレミファ♯ソラシ
push.42 = 11, 2, 6, 8, 9, 11, 12 // シミファ♯ソ♯ラシド
push.49 = 11, 10, 9, 5, 11, 7, 12 // シシ♭ラファシソド
// ウェイト
sleep.0 = 3, 1, 3, 1, 2, 2, 5
sleep.7 = 3, 1, 1, 1, 1, 1, 5
sleep.14 = 3, 1, 3, 1, 2, 2, 4
sleep.21 = 3, 1, 1, 1, 1, 1, 5
sleep.28 = 3, 1, 1, 1, 1, 1, 5
sleep.35 = 3, 1, 1, 1, 1, 1, 5
sleep.42 = 3, 1, 1, 1, 1, 1, 5
sleep.49 = 1, 1, 2, 2, 2, 2, 5
repeat 8
if cnt : list += "\n" + types.cnt : else : list = types
loop
objsize 160, 25
combox no, 100, list
button "上記の楽器で演奏", *start
midisetkey // 一度再生しないと音色が変わらない?
stop
*start
midireset
midisettone typno.no // 音色変更する
repeat 65
midisetkey push.cnt, 0x7F
wait 20 * sleep.cnt
midisetkey push.cnt
loop
stop
|