Win32 API 日本語リファレンス
ホームMedia.Audio › midiOutCacheDrumPatches

midiOutCacheDrumPatches

関数
MIDI出力デバイスに指定ドラムパッチをキャッシュする。
DLLWINMM.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// WINMM.dll
#include <windows.h>

DWORD midiOutCacheDrumPatches(
    HMIDIOUT hmo,
    DWORD uPatch,
    WORD* pwkya,
    DWORD fuCache
);

パラメーター

名前方向説明
hmoHMIDIOUTin開いている MIDI 出力デバイスへのハンドル。このデバイスは内部 MIDI シンセサイザーである必要があります。このパラメーターには、HMIDIOUT にキャストした MIDI ストリームのハンドルを指定することもできます。
uPatchDWORDin使用するドラムパッチ番号。既定のドラムパッチをキャッシュするには、このパラメーターを 0 に設定します。
pwkyaWORD*inキャッシュまたはキャッシュ解除する、指定したパーカッションパッチのキー番号を示す KEYARRAY 配列へのポインター。
fuCacheDWORDin

キャッシュ操作のオプション。次のいずれかのフラグを指定できます。

意味
MIDI_CACHE_ALL 指定したすべてのパッチをキャッシュします。すべてをキャッシュできない場合は、いずれもキャッシュせず、KEYARRAY 配列をクリアして MMSYSERR_NOMEM を返します。
MIDI_CACHE_BESTFIT 指定したすべてのパッチをキャッシュします。すべてをキャッシュできない場合は、可能な限り多くのパッチをキャッシュし、キャッシュされたパッチを反映するように KEYARRAY 配列を変更して MMSYSERR_NOMEM を返します。
MIDI_CACHE_QUERY 現在キャッシュされているパッチを示すように KEYARRAY 配列を変更します。
MIDI_UNCACHE 指定したパッチのキャッシュを解除し、KEYARRAY 配列をクリアします。

戻り値の型: DWORD

公式ドキュメント

midiOutCacheDrumPatches 関数は、内部 MIDI シンセサイザーデバイスに対して、指定したキーベースのパーカッションパッチ一式を事前に読み込んでキャッシュするよう要求します。

戻り値

成功した場合は MMSYSERR_NOERROR を返し、それ以外の場合はエラーを返します。発生し得るエラー値には次のものがあります。

戻り値 説明
MMSYSERR_INVALFLAG
wFlags で指定されたフラグが無効です。
MMSYSERR_INVALHANDLE
指定されたデバイスハンドルが無効です。
MMSYSERR_INVALPARAM
lpKeyArray 配列が指す配列が無効です。
MMSYSERR_NOMEM
要求されたすべてのパッチをキャッシュするのに十分なメモリがデバイスにありません。
MMSYSERR_NOTSUPPORTED
指定されたデバイスはパッチのキャッシュをサポートしていません。

解説(Remarks)

一部のシンセサイザーは、すべてのパーカッションパッチを同時に読み込んだ状態に保つことができません。パッチをキャッシュすることで、指定したパッチが確実に利用可能になります。

KEYARRAY 配列の各要素は、128 個のキーベースのパーカッションパッチのうちの 1 つを表し、その特定のパッチを使用する 16 個の MIDI チャネルごとにビットが設定されます。最下位ビットは物理チャネル 0 を表し、最上位ビットは物理チャネル 15 を表します。たとえば、キー番号 60 のパッチが物理チャネル 9 と 15 で使用されている場合、要素 60 は 0x8200 に設定されます。

この関数は内部 MIDI シンセサイザーデバイスにのみ適用されます。すべての内部シンセサイザーがパッチのキャッシュをサポートしているわけではありません。デバイスがパッチのキャッシュをサポートしているかどうかを確認するには、MIDICAPS_CACHE フラグを使用して、midiOutGetDevCaps 関数によって設定される MIDIOUTCAPS 構造体の dwSupport メンバーをテストします。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// WINMM.dll
#include <windows.h>

DWORD midiOutCacheDrumPatches(
    HMIDIOUT hmo,
    DWORD uPatch,
    WORD* pwkya,
    DWORD fuCache
);
[DllImport("WINMM.dll", ExactSpelling = true)]
static extern uint midiOutCacheDrumPatches(
    IntPtr hmo,   // HMIDIOUT
    uint uPatch,   // DWORD
    ref ushort pwkya,   // WORD*
    uint fuCache   // DWORD
);
<DllImport("WINMM.dll", ExactSpelling:=True)>
Public Shared Function midiOutCacheDrumPatches(
    hmo As IntPtr,   ' HMIDIOUT
    uPatch As UInteger,   ' DWORD
    ByRef pwkya As UShort,   ' WORD*
    fuCache As UInteger   ' DWORD
) As UInteger
End Function
' hmo : HMIDIOUT
' uPatch : DWORD
' pwkya : WORD*
' fuCache : DWORD
Declare PtrSafe Function midiOutCacheDrumPatches Lib "winmm" ( _
    ByVal hmo As LongPtr, _
    ByVal uPatch As Long, _
    ByRef pwkya As Integer, _
    ByVal fuCache As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

midiOutCacheDrumPatches = ctypes.windll.winmm.midiOutCacheDrumPatches
midiOutCacheDrumPatches.restype = wintypes.DWORD
midiOutCacheDrumPatches.argtypes = [
    wintypes.HANDLE,  # hmo : HMIDIOUT
    wintypes.DWORD,  # uPatch : DWORD
    ctypes.POINTER(ctypes.c_ushort),  # pwkya : WORD*
    wintypes.DWORD,  # fuCache : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINMM.dll')
midiOutCacheDrumPatches = Fiddle::Function.new(
  lib['midiOutCacheDrumPatches'],
  [
    Fiddle::TYPE_VOIDP,  # hmo : HMIDIOUT
    -Fiddle::TYPE_INT,  # uPatch : DWORD
    Fiddle::TYPE_VOIDP,  # pwkya : WORD*
    -Fiddle::TYPE_INT,  # fuCache : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winmm")]
extern "system" {
    fn midiOutCacheDrumPatches(
        hmo: *mut core::ffi::c_void,  // HMIDIOUT
        uPatch: u32,  // DWORD
        pwkya: *mut u16,  // WORD*
        fuCache: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINMM.dll")]
public static extern uint midiOutCacheDrumPatches(IntPtr hmo, uint uPatch, ref ushort pwkya, uint fuCache);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINMM_midiOutCacheDrumPatches' -Namespace Win32 -PassThru
# $api::midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
#uselib "WINMM.dll"
#func global midiOutCacheDrumPatches "midiOutCacheDrumPatches" sptr, sptr, sptr, sptr
; midiOutCacheDrumPatches hmo, uPatch, varptr(pwkya), fuCache   ; 戻り値は stat
; hmo : HMIDIOUT -> "sptr"
; uPatch : DWORD -> "sptr"
; pwkya : WORD* -> "sptr"
; fuCache : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WINMM.dll"
#cfunc global midiOutCacheDrumPatches "midiOutCacheDrumPatches" sptr, int, var, int
; res = midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
; hmo : HMIDIOUT -> "sptr"
; uPatch : DWORD -> "int"
; pwkya : WORD* -> "var"
; fuCache : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD midiOutCacheDrumPatches(HMIDIOUT hmo, DWORD uPatch, WORD* pwkya, DWORD fuCache)
#uselib "WINMM.dll"
#cfunc global midiOutCacheDrumPatches "midiOutCacheDrumPatches" intptr, int, var, int
; res = midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
; hmo : HMIDIOUT -> "intptr"
; uPatch : DWORD -> "int"
; pwkya : WORD* -> "var"
; fuCache : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winmm = windows.NewLazySystemDLL("WINMM.dll")
	procmidiOutCacheDrumPatches = winmm.NewProc("midiOutCacheDrumPatches")
)

// hmo (HMIDIOUT), uPatch (DWORD), pwkya (WORD*), fuCache (DWORD)
r1, _, err := procmidiOutCacheDrumPatches.Call(
	uintptr(hmo),
	uintptr(uPatch),
	uintptr(pwkya),
	uintptr(fuCache),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function midiOutCacheDrumPatches(
  hmo: THandle;   // HMIDIOUT
  uPatch: DWORD;   // DWORD
  pwkya: Pointer;   // WORD*
  fuCache: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINMM.dll' name 'midiOutCacheDrumPatches';
result := DllCall("WINMM\midiOutCacheDrumPatches"
    , "Ptr", hmo   ; HMIDIOUT
    , "UInt", uPatch   ; DWORD
    , "Ptr", pwkya   ; WORD*
    , "UInt", fuCache   ; DWORD
    , "UInt")   ; return: DWORD
●midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache) = DLL("WINMM.dll", "dword midiOutCacheDrumPatches(void*, dword, void*, dword)")
# 呼び出し: midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
# hmo : HMIDIOUT -> "void*"
# uPatch : DWORD -> "dword"
# pwkya : WORD* -> "void*"
# fuCache : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winmm" fn midiOutCacheDrumPatches(
    hmo: ?*anyopaque, // HMIDIOUT
    uPatch: u32, // DWORD
    pwkya: [*c]u16, // WORD*
    fuCache: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc midiOutCacheDrumPatches(
    hmo: pointer,  # HMIDIOUT
    uPatch: uint32,  # DWORD
    pwkya: ptr uint16,  # WORD*
    fuCache: uint32  # DWORD
): uint32 {.importc: "midiOutCacheDrumPatches", stdcall, dynlib: "WINMM.dll".}
pragma(lib, "winmm");
extern(Windows)
uint midiOutCacheDrumPatches(
    void* hmo,   // HMIDIOUT
    uint uPatch,   // DWORD
    ushort* pwkya,   // WORD*
    uint fuCache   // DWORD
);
ccall((:midiOutCacheDrumPatches, "WINMM.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, UInt32, Ptr{UInt16}, UInt32),
      hmo, uPatch, pwkya, fuCache)
# hmo : HMIDIOUT -> Ptr{Cvoid}
# uPatch : DWORD -> UInt32
# pwkya : WORD* -> Ptr{UInt16}
# fuCache : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t midiOutCacheDrumPatches(
    void* hmo,
    uint32_t uPatch,
    uint16_t* pwkya,
    uint32_t fuCache);
]]
local winmm = ffi.load("winmm")
-- winmm.midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
-- hmo : HMIDIOUT
-- uPatch : DWORD
-- pwkya : WORD*
-- fuCache : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINMM.dll');
const midiOutCacheDrumPatches = lib.func('__stdcall', 'midiOutCacheDrumPatches', 'uint32_t', ['void *', 'uint32_t', 'uint16_t *', 'uint32_t']);
// midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
// hmo : HMIDIOUT -> 'void *'
// uPatch : DWORD -> 'uint32_t'
// pwkya : WORD* -> 'uint16_t *'
// fuCache : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WINMM.dll", {
  midiOutCacheDrumPatches: { parameters: ["pointer", "u32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache)
// hmo : HMIDIOUT -> "pointer"
// uPatch : DWORD -> "u32"
// pwkya : WORD* -> "pointer"
// fuCache : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t midiOutCacheDrumPatches(
    void* hmo,
    uint32_t uPatch,
    uint16_t* pwkya,
    uint32_t fuCache);
C, "WINMM.dll");
// $ffi->midiOutCacheDrumPatches(hmo, uPatch, pwkya, fuCache);
// hmo : HMIDIOUT
// uPatch : DWORD
// pwkya : WORD*
// fuCache : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Winmm extends StdCallLibrary {
    Winmm INSTANCE = Native.load("winmm", Winmm.class);
    int midiOutCacheDrumPatches(
        Pointer hmo,   // HMIDIOUT
        int uPatch,   // DWORD
        ShortByReference pwkya,   // WORD*
        int fuCache   // DWORD
    );
}
@[Link("winmm")]
lib LibWINMM
  fun midiOutCacheDrumPatches = midiOutCacheDrumPatches(
    hmo : Void*,   # HMIDIOUT
    uPatch : UInt32,   # DWORD
    pwkya : UInt16*,   # WORD*
    fuCache : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef midiOutCacheDrumPatchesNative = Uint32 Function(Pointer<Void>, Uint32, Pointer<Uint16>, Uint32);
typedef midiOutCacheDrumPatchesDart = int Function(Pointer<Void>, int, Pointer<Uint16>, int);
final midiOutCacheDrumPatches = DynamicLibrary.open('WINMM.dll')
    .lookupFunction<midiOutCacheDrumPatchesNative, midiOutCacheDrumPatchesDart>('midiOutCacheDrumPatches');
// hmo : HMIDIOUT -> Pointer<Void>
// uPatch : DWORD -> Uint32
// pwkya : WORD* -> Pointer<Uint16>
// fuCache : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function midiOutCacheDrumPatches(
  hmo: THandle;   // HMIDIOUT
  uPatch: DWORD;   // DWORD
  pwkya: Pointer;   // WORD*
  fuCache: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINMM.dll' name 'midiOutCacheDrumPatches';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "midiOutCacheDrumPatches"
  c_midiOutCacheDrumPatches :: Ptr () -> Word32 -> Ptr Word16 -> Word32 -> IO Word32
-- hmo : HMIDIOUT -> Ptr ()
-- uPatch : DWORD -> Word32
-- pwkya : WORD* -> Ptr Word16
-- fuCache : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let midioutcachedrumpatches =
  foreign "midiOutCacheDrumPatches"
    ((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* hmo : HMIDIOUT -> (ptr void) *)
(* uPatch : DWORD -> uint32_t *)
(* pwkya : WORD* -> (ptr uint16_t) *)
(* fuCache : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winmm (t "WINMM.dll"))
(cffi:use-foreign-library winmm)

(cffi:defcfun ("midiOutCacheDrumPatches" midi-out-cache-drum-patches :convention :stdcall) :uint32
  (hmo :pointer)   ; HMIDIOUT
  (u-patch :uint32)   ; DWORD
  (pwkya :pointer)   ; WORD*
  (fu-cache :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $midiOutCacheDrumPatches = Win32::API::More->new('WINMM',
    'DWORD midiOutCacheDrumPatches(HANDLE hmo, DWORD uPatch, LPVOID pwkya, DWORD fuCache)');
# my $ret = $midiOutCacheDrumPatches->Call($hmo, $uPatch, $pwkya, $fuCache);
# hmo : HMIDIOUT -> HANDLE
# uPatch : DWORD -> DWORD
# pwkya : WORD* -> LPVOID
# fuCache : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。