使用 Midi 库解析事件并存储在 Vector C++

发布于 2024-11-17 08:47:00 字数 1825 浏览 5 评论 0原文

我是一名 PHP 程序员,决定通过开发 MissWatson 的简单替代方案来涉足 C++,该替代方案允许我通过 PHP 命令行通过 VST 处理 MIDI 文件。

我从 Steinberg VST SDK 开始,一直在使用这个 MIDI 库: https:// ccrma.stanford.edu/software/stk/index.html

我被困在向量上,特别是存储 MIDI 事件的向量。这是要清理的最后一段代码(请记住,我对 C++ 完全是菜鸟,并且可能做错了大部分内容):

std::string midiPath = "C:\\creative\\midi\\m1.mid";

if (argc > 1) {
    midiPath = argv[1];
}

//MidiFileIn::MidiFileIn(midiPath);
stk::MidiFileIn::MidiFileIn(midiPath);

//std::vector<_Ty> * midiEvents;
std::vector<_Ty> midiEvents(200);

stk::MidiFileIn::getNextEvent(midiEvents, 0);
//char* midiEvents[200];
//VstEvents* midiEvents;
//processMidi(effect, VstEvents*);

const char* wavPath = argv[2];
//processAudio(effect, 0, x, x);

以下是错误:

1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(370): error C2065: '_Ty' : undeclared identifier
1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(370): error C2514: 'std::vector' : class has no constructors
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(480) : see declaration of 'std::vector'
1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(372): error C2664: 'stk::MidiFileIn::getNextEvent' : cannot convert parameter 1 from 'std::vector' to 'std::vector<_Ty> *'
1>          with
1>          [
1>              _Ty=unsigned char
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>

那么,如何使用 _Ty 构造函数?我是在正确的轨道上还是只是疯了?

I'm a PHP programmer whose decided to take the plunge into C++ by developing a simple alternative to MissWatson that would allow me to, via the command line with PHP, process a MIDI file through a VST.

I started with the Steinberg VST SDK and I've been using this MIDI library: https://ccrma.stanford.edu/software/stk/index.html.

I'm stuck on vectors, specifically the vectors that would store the MIDI events into. Here's the last bit of code to clean up (keep in mind I'm a total noob to C++ and am probably doing most of this wrong):

std::string midiPath = "C:\\creative\\midi\\m1.mid";

if (argc > 1) {
    midiPath = argv[1];
}

//MidiFileIn::MidiFileIn(midiPath);
stk::MidiFileIn::MidiFileIn(midiPath);

//std::vector<_Ty> * midiEvents;
std::vector<_Ty> midiEvents(200);

stk::MidiFileIn::getNextEvent(midiEvents, 0);
//char* midiEvents[200];
//VstEvents* midiEvents;
//processMidi(effect, VstEvents*);

const char* wavPath = argv[2];
//processAudio(effect, 0, x, x);

and here are the errors:

1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(370): error C2065: '_Ty' : undeclared identifier
1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(370): error C2514: 'std::vector' : class has no constructors
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(480) : see declaration of 'std::vector'
1>c:\users\andrew\downloads\vst_sdk2_4_rev2\vstsdk2.4\public.sdk\samples\vst2.x\minihost\source\score.cpp(372): error C2664: 'stk::MidiFileIn::getNextEvent' : cannot convert parameter 1 from 'std::vector' to 'std::vector<_Ty> *'
1>          with
1>          [
1>              _Ty=unsigned char
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>

So, how do I use the _Ty constructor? Am I on the right track or just crazy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

财迷小姐 2024-11-24 08:47:00

_Ty 只是模板参数的占位符。您已经有了 std::vector<_Ty>,它是一个模板类,但您需要定义要使用哪个类。在这种情况下,它将是您的 MIDI 事件类 - 可能是 VstEvents

_Ty is just a placeholder for a template parameter. You've got std::vector<_Ty> which is a templated class, but you need to define which class you're going to use for it. In this case it will be whatever your MIDI event class is - probably VstEvents

空宴 2024-11-24 08:47:00

@the_mandrill 是正确的,但我只是想指出,您应该使用 VstEvent* 类型,而不是 VstEventsVstEvents 结构包含 VstEvent 对象的列表,您可能希望将它们分解为向量。所以给你一些伪代码:

// Initialization
std::vector<VstEvent *> midiEvents();

// Somewhere inside of stk::MidiFileIn::getNextEvent()
while(youReadTheMidiEvents) {
  VstEvents *inEvents = yourReadMidiEventsFunction();
  for(int i = 0; i < inEvents->numEvents; i++) {
    midiEvents.push_back(inEvents->events[i]);
  }
}

// Somewhere much later in your destructor
for(int i = 0; i < midiEvents.size(); i++) {
  free(midiEvents.at(i));
}
midiEvents.clear();

我不知道你实际上是如何从文件中读取 MIDI 事件的(因此是 your* 的东西),但上面的代码只是假设你正在返回一个 VstEvents 数组以某种方式。因此,请考虑它只是如何在向量中存储指针的简要概述。

@the_mandrill is correct, but I just wanted to note that you should be using a VstEvent* type, not VstEvents. A VstEvents structure contains a list of VstEvent objects, and you probably want to break them down into the vector. So some pseudocode for you:

// Initialization
std::vector<VstEvent *> midiEvents();

// Somewhere inside of stk::MidiFileIn::getNextEvent()
while(youReadTheMidiEvents) {
  VstEvents *inEvents = yourReadMidiEventsFunction();
  for(int i = 0; i < inEvents->numEvents; i++) {
    midiEvents.push_back(inEvents->events[i]);
  }
}

// Somewhere much later in your destructor
for(int i = 0; i < midiEvents.size(); i++) {
  free(midiEvents.at(i));
}
midiEvents.clear();

I have no idea how you are actually reading MIDI events from file (hence the your* stuff), but the above code is simply assuming that you are getting back a VstEvents array somehow. So consider it just a terse overview of how you're going to have to store pointers in your vector.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文