命令行接口-使用Midi库分析事件并存储在矢量C++中
command line interface - Using Midi Library To Parse Events And Store In 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:usersandrewdownloadsvst_sdk2_4_rev2vstsdk2.4public.sdksamplesvst2.xminihostsourcescore.cpp(370): error C2065: '_Ty' : undeclared identifier
1>c:usersandrewdownloadsvst_sdk2_4_rev2vstsdk2.4public.sdksamplesvst2.xminihostsourcescore.cpp(370): error C2514: 'std::vector' : class has no constructors
1> c:program files (x86)microsoft visual studio 10.0vcincludevector(480) : see declaration of 'std::vector'
1>c:usersandrewdownloadsvst_sdk2_4_rev2vstsdk2.4public.sdksamplesvst2.xminihostsourcescore.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构造函数呢?我是走在正确的轨道上,还是只是疯了?
_Ty
只是模板参数的占位符。您有一个std::vector<_Ty>
,它是一个模板化的类,但您需要定义要用于它的类。在这种情况下,它将是您的MIDI事件类的任何一个-可能是VstEvents
@the_mandrill是正确的,但我只是想注意,您应该使用VstEvent*
类型,而不是VstEvents
。VstEvents
结构包含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
数组。所以,把它看作是一个关于如何在向量中存储指针的简要概述。
相关文章:
- 将字符串存储在c++中的稳定内存中
- std::原子加载和存储都需要吗
- C++:将控制台输出存储在宏中更好吗
- 使用QProcess执行命令,并将结果存储在QStringList中
- 访问存储在向量C++中的结构的多态成员
- 如何从存储在std::映射中的std::集中删除元素
- 存储模板类型以强制转换回派生<T>
- 类型总是使用其大小存储在内存中吗
- 当字符串存储在变量中时,如何将字符串转换为wchar_t
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 带结构的二维矢量:如何存储元素
- 添加存储在向量中的大整数的函数出现问题
- 从文件中读取多个字节,并将它们存储在C++中进行比较
- 在std::vector上存储带有模板的类实例
- 谷歌测试中的期望值存储在哪里
- 为什么C中的通用链表中存储的数据已损坏
- 在c++中获取两个大int,并将它们存储在数组中
- 在reactor中存储eventHandlers的最佳方式是什么