waieiさんが投稿したコード一覧

HSP MIDIキーボードの鍵盤入力を取得

; KORGのnanoKEY2でしか動作確認していないのでそこんとこよろしく
; 別にこれ↓やっておく必要ないんだけど渡された数値表示するよりはわかりやすいかと
	sdim code,64,128
	code(0x0)  = "c ","c#","d ","d#","e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#"
	code(0x10) = "e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#","e ","f ","f#","g "
	code(0x20) = "g#","a ","a#","b ","c ","c#","d ","d#","e ","f ","f#","g ","g#","a ","a#","b "
	code(0x30) = "c ","c#","d ","d#","e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#"
	code(0x40) = "e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#","e ","f ","f#","g "
	code(0x50) = "g#","a ","a#","b ","c ","c#","d ","d#","e ","f ","f#","g ","g#","a ","a#","b "
	code(0x60) = "c ","c#","d ","d#","e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#"
	code(0x70) = "e ","f ","f#","g ","g#","a ","a#","b ","c ","c#","d ","d#","e ","f ","f#","g "
	repeat length(code)
		code(cnt)=code(cnt)+" ("+(cnt/12-3)+")"
	loop

#define CALLBACK_NULL     0x00000000
#define CALLBACK_FUNCTION 0x00030000
#define MMSYSERR_NOERROR 0x0
#define MIM_DATA     0x3C3
#define MIM_ERROR    0x3C5
#define MIM_LONGDATA 0x3C4

	title "MIDIコントローラの入力取得"

#include "hscallbk.as"	;ちょくとさんのコールバックプラグイン
#include "winmm.as"

#uselib ""
#func clbkGetMidi "" int,int,int,int,int

	md_getmax = 24		; 同時認識最大キー数
	dim md_current,md_getmax
	repeat md_getmax
		md_current(cnt)=-1
	loop
	onexit *lEnd
	textMidiInfo = ""	; 画面に表示させる情報
	md_id = 0			; とりあえず0番目のデバイスを選択
	md_hnd = 0			; ハンドル

	; 有効なデバイス数を取得
	midiInGetNumDevs
	md_cnt = stat
	if md_cnt == 0 {
		dialog "接続されていません"
		goto *lEnd
	}

	; デバイスの情報を取得
	dim md_caps,11
	midiInGetDevCaps md_id, varptr(md_caps), 44
	md_caps_mid = md_caps(0) & 0xFF
	md_caps_pid = (md_caps(0)>>8) & 0xFF
	md_caps_ver = md_caps(1)
	sdim md_caps_name,32
	memcpy md_caps_name, md_caps, 32, 0, 8

	; デバイスの情報を表示
	font "meiryo",14
	objmode 2,1
	objsize 100,30
	pos ginfo_winx-110,10
	button gosub "リセット",*lMidiReset
	pos 10, 10
	mes "wMid : "+md_caps_mid
	mes "wPid : "+md_caps_pid
	mes "vDriverVersion : "+strf("%x",md_caps_ver)
	mes "szPname : "+md_caps_name

	; コールバック関数登録
	setcallbk procGetMidi, clbkGetMidi, *lGetMidi

	; 受付開始
	gosub *lMidiOpen

	stop

; デバイスの入力受け付け開始
*lMidiOpen
	; デバイスを開く
	midiInOpen varptr(md_hnd), md_id, varptr(procGetMidi), 0, CALLBACK_FUNCTION
	textMidiInfo = "\nmidiOpen : "+stat+"\nHndle : "+md_hnd
	if stat != MMSYSERR_NOERROR {
		dialog "midiInエラー"
		goto *lEnd
	}
	; デバイスの使用開始
	midiInStart md_hnd
	gosub *lDrawMidiInfo
	return

; デバイスの入力受け付け停止、情報リセット、閉じる
*lMidiClose
	if md_hnd!=0 {
		midiInStop md_hnd
		midiInReset md_hnd
		midiInClose md_hnd
	}
	return

; 意図的なリセット
; リセット直後に入力があるような状態は避けてください
*lMidiReset
	gosub *lMidiClose
	repeat md_getmax
		md_current(cnt)=-1
	loop
	gosub *lMidiOpen
	return

; 入力情報の表示
; 単純に textMidiInfo に入っている文字を描画するだけ
*lDrawMidiInfo
	redraw 0,0,240,640,480
	color 255,255,255 : boxf 0,240,640,480
	color 0,0,0
	pos  10, 240 : mes "Info : "+textMidiInfo
	pos 200, 240 : mes "現在入力中のキー"
	repeat md_getmax
		if md_current(cnt)!=-1{
			mes ""+code(md_current(cnt))
		}
		if (cnt\8)==7 : pos ginfo_cx+80,260
	loop
	redraw 1,0,240,640,480
	return

; コールバック
;	CALLBACK MidiInProc(
;		HMIDIIN hMidiIn,
;		UINT wMsg,
;		DWORD dwInstance,
;		DWORD dwParam1,
;		DWORD dwParam2
;	)
*lGetMidi
	clbk_md_hnd  = callbkarg(0)
	clbk_md_msg  = callbkarg(1)
	clbk_md_ins  = callbkarg(2)
	clbk_md_prm1 = callbkarg(3)
	clbk_md_prm2 = callbkarg(4)
	textMidiInfo = ""
	if clbk_md_hnd == md_hnd {
		; エラー
		if clbk_md_msg == MIM_ERROR {
			textMidiInfo = "\nエラー"
			textMidiInfo+= "\nParam1 : "   + strf("0x%X",clbk_md_prm1)
			textMidiInfo+= "\nParam2 : "   + strf("0x%X",clbk_md_prm2)
			gosub *lMidiReset
		; 情報取得
		} else:if clbk_md_msg == MIM_DATA {
			textMidiInfo+= "\nMIM_DATA"
			textMidiInfo+= "\nMsg : "      + strf("0x%X",clbk_md_msg)
			textMidiInfo+= "\nInstance : " + clbk_md_ins
			textMidiInfo+= "\nParam1 : "   + strf("0x%X",clbk_md_prm1)
			textMidiInfo+= "\nParam2 : "   + clbk_md_prm2+" ms"
			textMidiInfo+= "\n"

			; この辺はもしかするとデバイスによって異なるかも
			md_get_code  = (clbk_md_prm1>>8) & 0xFF		; 押したキー
			md_get_state = (clbk_md_prm1)>>4 & 0xF		; キーの押下状態
			md_get_gain  = (clbk_md_prm1>>16) & 0xFF	; 押下した強さ

			; 表示用に内容解析
			textMidiInfo+= "\n音 : "+code(md_get_code)
			if md_get_state == 9 {
				textMidiInfo+= "\n押した"
				_flag = 0
				_cur = -1
				repeat md_getmax
					if md_current(cnt)==md_get_code {
						_flag = 1
					} else:if _cur==-1 && md_current(cnt)==-1 {
						_cur = cnt
					}
					if _flag==1 && _cur!=-1 : break
				loop
				if _flag == 0 && _cur!=-1 {
					md_current(_cur) = md_get_code
				}
			} else:if md_get_state == 8 {
				textMidiInfo+= "\n離した"
				repeat md_getmax
					if md_current(cnt)==md_get_code {
						md_current(cnt) = -1
					}
				loop
			}
			textMidiInfo+= "\n強さ : "+strf("%d%%",md_get_gain*100/127)
		}
	}
	gosub *lDrawMidiInfo
	return

; 終了
*lEnd
	gosub *lMidiClose
	end

HSP 【HSP3】Media Foundationを使用しての動画再生(修正)

#define IID_IMFPMediaPlayer "{A714590A-58AF-430a-85BF-44F5EC838D85}"
#usecom IMFPMediaPlayer IID_IMFPMediaPlayer "{}"
#comfunc IMFPMediaPlayer_Play 3
#comfunc IMFPMediaPlayer_Pause 4
#comfunc IMFPMediaPlayer_Stop 5
#comfunc IMFPMediaPlayer_FrameStep 6
#comfunc IMFPMediaPlayer_SetRate 10 float
#comfunc IMFPMediaPlayer_Shutdown 38
newcom iMFPlayer,IMFPMediaPlayer
#uselib "Mfplay"
#func MFPCreateMediaPlayer "MFPCreateMediaPlayer" wstr,int,int,int,int,var
#uselib "Mfplat"
#func MFStartup "MFStartup" int,int
#func MFShutdown "MFShutdown"
#define MFSTARTUP_NOSOCKET 0x1
#define MFSTARTUP_LITE (MFSTARTUP_NOSOCKET)
#define MFSTARTUP_FULL 0

	screen 0,800,800
	title "Media Foundation (1.3倍速再生サンプル)"
	LOADED=0
	onexit *lEnd
	objsize 100,24
	pos ginfo_winx-500,0
	button gosub "Load",*lFileLoad
	pos ginfo_winx-400,0
	button gosub "Play",*lPlay
	pos ginfo_winx-300,0
	button gosub "Pause",*lPause
	pos ginfo_winx-200,0
	button gosub "Stop",*lStop
	pos ginfo_winx-100,0
	button gosub "Step",*lStep
	gosub *lFileLoad
	stop
*lFileLoad
	dialog "mp4;*.avi;*.mpg;*.mpeg",16
	if stat=0{
		if LOADED{
			return
		}else{
			stop
		}
	}
	file=refstr
	gosub *lLoad
	IMFPMediaPlayer_SetRate iMFPlayer,1.3	;1.3倍速再生
	return
*lLoad
	if LOADED{
		gosub *lRelease
	}
	MFStartup
	MFPCreateMediaPlayer file, 1,0,0,hwnd,iMFPlayer
	;                         ↑0にすると自動再生しない
	LOADED=1
	return
*lRelease
	gosub *lStop
	IMFPMediaPlayer_Shutdown iMFPlayer
	MFShutdown
	return
*lPlay
	if LOADED : IMFPMediaPlayer_Play iMFPlayer
	return
*lPause
	if LOADED : IMFPMediaPlayer_Pause iMFPlayer
	return
*lStop
	if LOADED : IMFPMediaPlayer_Stop iMFPlayer
	return
*lStep
	if LOADED : IMFPMediaPlayer_FrameStep iMFPlayer
	return
*lEnd
	if LOADED{
		gosub *lRelease
	}
	mes "MFShutdown:"+stat
	end

HSP HSPでAeroGlassに描画してみる(オブジェクト編)

#include "user32.as"
#define GWL_WNDPROC -4
#define WM_CREATE 0x1
#define WM_DESTROY 0x2

#uselib "uxtheme"
#cfunc BeginBufferedPaint "BeginBufferedPaint" int,int,int,int,int
#func EndBufferedPaint "EndBufferedPaint" int,int
#func BufferedPaintSetAlpha "BufferedPaintSetAlpha" int,int,int
#func BufferedPaintRenderAnimation "BufferedPaintRenderAnimation" int,int
#define BPBF_TOPDOWNDIB 2

#uselib "dwmapi"
#func DwmExtendFrameIntoClientArea "DwmExtendFrameIntoClientArea" int,int

#include "hscallbk.as"
#uselib ""
#func CallNew "" int,int,int,int

	;-- いつもの
	screen 0,580,160
	r=0,0,80,0
	DwmExtendFrameIntoClientArea hwnd,varptr(r)
	cls 4

	;-- コールバック関数
	setcallbk ProcNew, CallNew, *lCallNewWindowProc

	objx=200
	objy=50
	objsize objx,objy
	objmode 2,1 : font "meiryo",24,1+16	;-- みんな大好きメイリオ

	pos  10,10 : button gosub "透けるボタン",*lButton

	;-- ボタンのサブクラス化
	pos 310,10 : button gosub "透けないボタン",*lButton
	hButton=objinfo(stat,2)
	GetWindowLong hButton,GWL_WNDPROC
	dButtonProc=stat
	SetWindowLong hButton,GWL_WNDPROC,varptr(ProcNew)

	stop

*lButton
	dialog "Push"
	return
*lCallNewWindowProc
	if callbkarg(0)=hButton{	;--該当ボタン
		;-- WM_PAINT以外は通常通りの動作をする
		CallWindowProc dButtonProc,callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3)
		ret=stat
		if callbkarg(1)=0xf{	;--WM_PAINT
			r=5,5,objx-5,objy-5	;-- ボタンの角が円いので少し小さめにしておかないと余計な部分まで不透明になる
								;   ……はずなのだが、HSPのボタンはなぜか下地が見えちゃってるので意味なし
			pp=16,0,0,0
			mhdc=0
			GetWindowDC hButton
			dcButton=stat
			pb=BeginBufferedPaint(dcButton,varptr(r),BPBF_TOPDOWNDIB,varptr(pp),varptr(mhdc))
			if pb!0{
				CallWindowProc dButtonProc,callbkarg(0),callbkarg(1),mhdc,callbkarg(3)
				ret=stat
				BufferedPaintSetAlpha pb,varptr(r),255
				EndBufferedPaint pb,1
			}
			ReleaseDC hButton,dcButton
		}
	}
	return ret

HSP HSPでAeroGlassに描画してみる

#include "a2d.hsp"

#module
#uselib "user32"
#func GetDC "GetDC" int
#func ReleaseDC "ReleaseDC" int,int
#deffunc alSetAeroGlass
	alReleaseAeroGlass
	wid=ginfo_sel
	GetDC hwnd
	dc=stat
	return dc
#deffunc alReleaseAeroGlass onexit
	old_wid=ginfo_sel
	if dc:gsel wid:ReleaseDC hwnd,dc:gsel old_wid
	return 0
#deffunc _alCopyImageToAeroGlass int p1, int x, int y, int w, int h
	if imgValidArr@a2d(p1) {
		; 実スクリーンの Graphics 作成
		gsel wid
		GdipCreateFromHDC@a2d dc, varptr(tmpGraphics)

		if tmpGraphics {
			GdipSetCompositingMode@a2d tmpGraphics, 1
			GdipDrawImageRectRectI@a2d tmpGraphics, imgImageArr@a2d(p1), x, y, w,h, x, y, w,h, UnitPixel@a2d, pImageAttr@a2d, 0, 0
			GdipDeleteGraphics@a2d tmpGraphics	; tmpGraphics を削除
			tmpGraphics = 0
			return 0
		}
	}
	return -1
#global
#define alCopyImageToAeroGlass(%1,%2=ginfo_cx,%3=ginfo_cy,%4=ginfo_winx,%5=ginfo_winy) _alCopyImageToAeroGlass %1,%2,%3,%4,%5

#uselib "dwmapi"
#func DwmIsCompositionEnabled "DwmIsCompositionEnabled" int
#func DwmExtendFrameIntoClientArea "DwmExtendFrameIntoClientArea" int,int
	aerorect=-1,0,0,0
	wx=640 : wy=480
	screen 0,wx,wy,2
	cls 4 : gsel 0,1
	gosub *lAeroChk
	oncmd gosub *lAeroChk,0x031E	;Aeroの状態が変わった時
	oncmd gosub *lWRedraw,0x3		;画面外に行った時に消えるので描画しなおす(高負荷なので工夫して)
	alSetAeroGlass
	alCreateImage 0,wx,wy
	repeat 10
	_y=cnt
	repeat 10
	_x=cnt
	alHsvColor ((_y*10+_x)*2)\192,255,100+_y*15,200-_x*15
	alFillRect _x*(wx/10)+1,_y*(wy/10)+1,(wx/10)-1,(wy/10)-1
	loop
	loop
	alFont "meiryo",60 : alColor 0,0,0,255
	alDrawText "そしてこの\n黒文字である\n透けていないでしょ?",0,0,wx,wy,1,1
	repeat
	gosub *lWRedraw
	wait 5	;最小化からの復帰時の再描画がうまくいかないのでとりあえずループ監視
	loop
	stop

*lWRedraw
	// 再描画(Aero環境の場合、画面外にウインドウが行くと再描画が必要)
	if aero{
		alCopyImageToAeroGlass 0
	}else{
		alCopyImageToScreen 0,0
		redraw
	}
	return

*lAeroChk
	DwmIsCompositionEnabled varptr(aero)
	if aero!0{
		color 0,0,0 : boxf
		DwmExtendFrameIntoClientArea hwnd,varptr(aerorect)
		wait 1	;何故かgselでウインドウ表示後ウエイトを入れないと中身が表示されない
				;(生成時のアニメーション中だとだめ?最小化から復帰アニメーション中もだめっぽい)
	}else{
		color 0,0,0 : boxf
	}
	gosub *lWRedraw
	return

TEXT StepMania5.0で任意のパラメータを呼び出す

function GetSMParameter(song,prm)
	local st=song:GetAllSteps();
	if #st<1 then
		return "";
	end;
	local t;
	t=st[1]:GetFilename();
	if not FILEMAN:DoesFileExist(t) then
		return "";
	end;
	local f=RageFileUtil.CreateRageFile();
	f:Open(t,1);
	local tmp={};
	local pl=string.lower(prm);
	while true do
		l=f:GetLine();
		local ll=string.lower(l);
		if string.find(ll,"#notes:.*") or f:AtEOF() then
			tmp[1]="";
			break;
		-- [ja] BOM考慮して .* を頭につける
		elseif string.find(ll,".*#"..pl..":.*") then
			tmp=split(":",l);
			if tmp[2]==";" then
				tmp[1]="";
			else
				tmp=split(";",tmp[2]);
			end;
			break;
		end;
	end;
	f:Close();
	return tmp[1];
end;

function Str2Color(prm)
	local c={"1.0","1.0","1.0","1.0"};
	c=split(",",prm);
	if #c<4 then
		c={"1.0","1.0","1.0","1.0"}
	end;
	return c;
end;

TEXT StepMania5.0 Alpha1でジャケットとCDを読み込ませる

function GetJacketPath_a1(song)
	local f={};
	local ret="";
	f=FILEMAN:GetDirListing(song:GetSongDir());
	for i=1,#f do
		if string.find(f[i],".*jacket.*[png$jpeg$jpg$gif$bmp$avi$mpg$mpeg]") then
			if FILEMAN:DoesFileExist(song:GetSongDir().."/"..f[i]) then
				ret=song:GetSongDir().."/"..f[i];
				return ret;
			else
				ret="";
			end;
		end;
	end;
	return ret;
end;

function HasJacket_a1(song)
	local f={};
	local ret="";
	f=FILEMAN:GetDirListing(song:GetSongDir());
	for i=1,#f do
		if string.find(f[i],".*jacket.*[png$jpeg$jpg$gif$bmp$avi$mpg$mpeg]") then
			if FILEMAN:DoesFileExist(song:GetSongDir().."/"..f[i]) then
				return true;
			end;
		end;
	end;
	return false;
end;

function GetCDImagePath_a1(song)
	local f={};
	local ret="";
	f=FILEMAN:GetDirListing(song:GetSongDir());
	for i=1,#f do
		if string.find(f[i],".+cd.?[png$jpeg$jpg$gif$bmp$avi$mpg$mpeg]") then
			if FILEMAN:DoesFileExist(song:GetSongDir().."/"..f[i]) then
				ret=song:GetSongDir().."/"..f[i];
				return ret;
			else
				ret="";
			end;
		end;
	end;
	return ret;
end;

function HasCDImage_a1(song)
	local f={};
	local ret="";
	f=FILEMAN:GetDirListing(song:GetSongDir());
	for i=1,#f do
		if string.find(f[i],".+cd.?[png$jpeg$jpg$gif$bmp$avi$mpg$mpeg]") then
			if FILEMAN:DoesFileExist(song:GetSongDir().."/"..f[i]) then
				return true;
			end;
		end;
	end;
	return false;
end;

よく投稿されているコード

タグ

最近投稿されたコード