// item_read.cpp — the single MediaItem* read seam (GUID + fixed-lane name). See
// item_read.h. Compiled into the reaper_reasampler module; includes
// reaper_plugin_functions.h WITHOUT REAPERAPI_IMPLEMENT (main.cpp is the one TU that
// defines the API pointers).

#include "shell/capture/item_read.h"

#include <cstdio>

#define REAPERAPI_MINIMAL
#define REAPERAPI_WANT_GetSetMediaItemInfo_String
#define REAPERAPI_WANT_GetMediaItemInfo_Value
#define REAPERAPI_WANT_GetSetMediaTrackInfo_String
#include "reaper_plugin_functions.h"

namespace reasampler {

std::string itemGuid(MediaItem* it) {
    char buf[64] = {0};
    if (!GetSetMediaItemInfo_String(it, "GUID", buf, false)) return {};
    return std::string(buf);
}

std::string itemLaneName(MediaTrack* tr, MediaItem* it) {
    const int laneIdx = static_cast<int>(GetMediaItemInfo_Value(it, "I_FIXEDLANE"));
    char parm[32];
    std::snprintf(parm, sizeof(parm), "P_LANENAME:%d", laneIdx);
    char buf[512] = {0};
    if (!GetSetMediaTrackInfo_String(tr, parm, buf, false)) return {};
    return std::string(buf);
}

}  // namespace reasampler
