Skip to content

Sample plugin

A standalone .aux2 sample that uses the external API. It reads the shared MIDI and shows BPM, time signature, bars, note count, and so on as text. The sample and its build (xmake) live in the public repo midi-info-api and are pulled into this project as a submodule (external/midi-info-api).

  • Source: external/midi-info-api/samples/api-sample/MidiApiSample.cpp (a single file, no core dependency)
  • Depends on: the AviUtl2 SDK and the public header MidiInfoAPI.h only

Build

xmake and the AviUtl2 SDK (filter2.h / plugin2.h) are required. The SDK is available from the AviUtl author's distribution page.

Point AVU2_SDK_DIR at the extracted folder (where filter2.h lives) and build.

bash
xmake build MidiInfoApiSample

The build copies MidiApiSample.aux2 to AVU2_PLUGIN_DIR (default C:\ProgramData\aviutl2\Plugin). MidiInfoApiSample is excluded from the default build, so it only builds when named explicitly.

The public repo midi-info-api can also build the sample on its own with xmake build (also needs AVU2_SDK_DIR).

Implementation highlights

Resolve the API once and cache it

cpp
const MidiInfoAPI* get_api() {
    static const MidiInfoAPI* api = [] () -> const MidiInfoAPI* {
        HMODULE h = GetModuleHandleW(L"MidiInfoObject.aux2");
        if (!h) return nullptr;
        auto fn = reinterpret_cast<MidiInfo_GetAPI_Fn>(
            GetProcAddress(h, MIDIINFO_GETAPI_SYMBOL));
        return fn ? fn(MIDIINFO_API_VERSION) : nullptr;
    }();
    return api;
}

Acquire -> display -> release

cpp
double t = api->get_shared_time();                 // sync to MIDI Source
if (!(t == t)) t = video->object->time;            // fall back if NaN

MidiInfoAnalysis* an = api->acquire(nullptr);       // shared MIDI
if (api->is_ok(an)) {
    uint8_t num, den; api->signature_at(an, t, &num, &den);
    // show bpm_at / bar_number_at / count_at / nps_at / total_notes ...
}
api->release(an);                                   // always release

The sample rasterizes text with GDI, but with note_spans you can build your own visualizers too.

Embedding in your own plugin

You only need to copy the single file MidiInfoAPI.h. No linking required (resolved at runtime via GetProcAddress). See Overview & getting started and the Function reference.