〜 メディア 〜
MIDI音源の全出力を停止 (要WINMM.DLL)

MIDI出力デバイスにメッセージを送信することで音を奏でることが可能です。
最大16音を同時に再生できるのですが、停止合図を送らなければ延々鳴り続ける音色(楽器)もあります。
音の強さ「ゼロ」のキーを送信することで停止可能なのですが、
停止できるのは「指定したチャンネル」の「指定した鍵盤」だけなので、
1つのチャンネルしか使用していなくても複数音階を使用している場合は、
使用している全ての鍵盤に停止メッセージを送信しなければ鳴り続けてしまう可能性があります。
同時再生している場合に全出力をオフにするのはもっと大変ですので、
命令一発で全チャンネルの全キー音を停止する方法を載せておきます。
他のMIDI共通モジュールと併せて使用する形としており、
出力を停止するmidireset命令以外についてはコチラをご覧ください。
冒頭に16音同時と書きましたが、チャンネル9だけはパーカッション(リズム)音色として
他のチャンネルとは性質が少し異なっていますので注意してください。
	

midiopen
[パラメータなし]MIDIデバイスを使用可能状態にするだけのため、パラメータは必要ない。
尚、下記midisetkey命令内でデバイスチェックしているので命令を実行する必要はない。

midisetkey 鍵盤, 強さ, チャンネル
鍵盤使用する鍵盤(但し、チャンネル9だけはリズム楽器)を指定する。
尚、低い「ド」を0としており、指定可能値は−60〜67である。
強さ鍵盤を押す強さを0〜127で指定する。尚、強さ0は無音を指す。
チャンネル使用チャンネルを0〜15のいずれかで指定する。

midireset
[パラメータなし]MIDIデバイスの出力を停止するだけのため、パラメータは必要ない。

midiclose
[パラメータなし]MIDIデバイスを解放するだけのため、パラメータは必要ない。
尚、終了時に自動的に呼び出されるので命令を実行する必要はない。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	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

#module
#deffunc midiopen
	ll_getptr midh : ll_ret ptr
	prm = ptr, -1, 0, 0, 0
	ll_callfunc prm, 4, midiOutOpen@
	return

#deffunc midisetkey int, int, int
	mref key, 0 : mref velocity, 1 : mref channel, 2
	if midh = 0 : midiopen
	prm = midh, velocity * 0x10000 + 0x3C90 + (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
#global

	sdim key, 8, 13
	dim select, 13
	key = "ド", "ド#", "レ", "レ#", "ミ", "ファ", "ファ#", "ソ", "ソ#", "ラ", "ラ#", "シ", "ド"
	randomize
	objsize 40, 25
	pos 10, 10 : mes "Do you understand what sound you are?"
	pos 10, 40 : button "OK", *start
	lv = 1
	stop

*start
	color 255, 255, 255 : boxf , 40 : color
	clrobj
	pos 10, 70 : mes "Lv" + lv
	mes "Ready..."
	wait 100
	repeat 13
		play.cnt = 0
		select.cnt = 0
	loop
	repeat lv
		rnd r, 13
		if play.r : continue cnt
		play.r = 1
		midisetkey r, 0x7F, cnt
	loop
	wait 50
	mes "End..."
	midireset
	repeat 13
		pos cnt * 45 + 10, 160 : button key.cnt, *note
	loop
	pos 10, 250 : button "OK", *ok
	stop

*note
	color 255, 255, 255 : boxf stat * 45 + 10, 130, (stat + 1) * 45, 150 : color 255
	select.stat = 1 - select.stat
	if select.stat : pos stat * 45 + 20, 130 : mes "◎"
	stop

*ok
	ng = 0
	repeat 13
		if play.cnt {
			pos cnt * 45 + 20, 150 : mes "◎"
			if select.cnt = 0 : pos cnt * 45 + 20, 130 : mes "×" : ng = 1
		} else {
			if select.cnt ! 0 : pos cnt * 45 + 20, 150 : mes "×" : ng = 1
		}
	loop
	color
	pos 10, 180
	clrobj
	if ng {
		lv--
		if lv < 1 : mes "You are Dead ! See you !" : goto *exit
		mes "Error ! Level Down (xox)"
	} else {
		lv++
		if lv > 10 : mes "All Clear ! Thank you !" : goto *exit
		mes "Good Job ! Level Up (^o^)"
	}
	pos 10, 40 : button "OK", *start
	stop

*exit
	wait 300

midiopen
[パラメータなし]MIDIデバイスを使用可能状態にするだけのため、パラメータは必要ない。
尚、下記midisetkey命令内でデバイスチェックしているので命令を実行する必要はない。

midisetkey 鍵盤, 強さ, チャンネル
鍵盤使用する鍵盤(但し、チャンネル9だけはリズム楽器)を指定する。
尚、低い「ド」を0としており、指定可能値は−60〜67である。
強さ鍵盤を押す強さを0〜127で指定する。尚、強さ0は無音を指す。
チャンネル使用チャンネルを0〜15のいずれかで指定する。

midireset
[パラメータなし]MIDIデバイスの出力を停止するだけのため、パラメータは必要ない。

midiclose
[パラメータなし]MIDIデバイスを解放するだけのため、パラメータは必要ない。
尚、終了時に自動的に呼び出されるので命令を実行する必要はない。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#uselib "winmm.dll"
#func  global midiOutOpen "midiOutOpen" var, int, int, int, int
#func  global midiOutShortMsg "midiOutShortMsg" int, int
#func  global midiOutReset "midiOutReset" int
#func  global midiOutClose "midiOutClose" int

#module
#deffunc midiopen
	midiOutOpen midh, -1, 0, 0, 0
	return

#deffunc midisetkey int key, int velocity, int channel
	if midh = 0 : midiopen
	midiOutShortMsg midh, 0x3C90 + velocity * 0x10000 + key * 0x100 + channel
	return

#deffunc midireset
	if midh : midiOutReset midh // 全て停止
	return

#deffunc midiclose onexit
	if midh : midiOutClose midh
	return
#global

	sdim key, 8, 13
	dim select, length(key)
	key = "ド", "ド#", "レ", "レ#", "ミ", "ファ", "ファ#", "ソ", "ソ#", "ラ", "ラ#", "シ", "ド"
	randomize
	objsize 40, 25
	pos 10, 10 : mes "Do you understand what sound you are?"
	pos 10, 40 : button gosub "OK", *start
	lv = 1
	stop

*start
	color 255, 255, 255 : boxf , 40 : color
	clrobj
	pos 10, 70 : mes "Lv" + lv
	mes "Ready..."
	wait 100
	foreach key
		play.cnt = 0
		select.cnt = 0
	loop
	repeat lv
		r = rnd(length(key))
		if play.r : continue cnt
		play.r = 1
		midisetkey r, 0x7F, cnt
	loop
	wait 50
	mes "End..."
	midireset
	foreach key
		pos cnt * 45 + 10, 160 : button gosub key.cnt, *note
	loop
	pos 10, 250 : button gosub "OK", *ok
	return

*note
	color 255, 255, 255 : boxf stat * 45 + 10, 130, (stat + 1) * 45, 150 : color 255
	select.stat = 1 - select.stat
	if select.stat : pos stat * 45 + 20, 130 : mes "◎"
	return

*ok
	ng = 0
	foreach key
		if play.cnt {
			pos cnt * 45 + 20, 150 : mes "◎"
			if select.cnt = 0 : pos cnt * 45 + 20, 130 : mes "×" : ng = 1
		} else {
			if select.cnt ! 0 : pos cnt * 45 + 20, 150 : mes "×" : ng = 1
		}
	loop
	color
	pos 10, 180
	clrobj
	if ng {
		lv--
		if lv < 1 : mes "You are Dead ! See you !" : goto *exit
		mes "Error ! Level Down (xox)"
	} else {
		lv++
		if lv > 10 : mes "All Clear ! Thank you !" : goto *exit
		mes "Good Job ! Level Up (^o^)"
	}
	pos 10, 40 : button gosub "OK", *start
	return

*exit
	wait 300
	end