使用 Midi 库解析事件并存储在 Vector C++
我是一名 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
_Ty
只是模板参数的占位符。您已经有了std::vector<_Ty>
,它是一个模板类,但您需要定义要使用哪个类。在这种情况下,它将是您的 MIDI 事件类 - 可能是VstEvents
_Ty
is just a placeholder for a template parameter. You've gotstd::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 - probablyVstEvents
@the_mandrill 是正确的,但我只是想指出,您应该使用
VstEvent*
类型,而不是VstEvents
。VstEvents
结构包含VstEvent
对象的列表,您可能希望将它们分解为向量。所以给你一些伪代码:我不知道你实际上是如何从文件中读取 MIDI 事件的(因此是
your*
的东西),但上面的代码只是假设你正在返回一个VstEvents
数组以某种方式。因此,请考虑它只是如何在向量中存储指针的简要概述。@the_mandrill is correct, but I just wanted to note that you should be using a
VstEvent*
type, notVstEvents
. AVstEvents
structure contains a list ofVstEvent
objects, and you probably want to break them down into the vector. So some pseudocode for you: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 aVstEvents
array somehow. So consider it just a terse overview of how you're going to have to store pointers in your vector.