0

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?

grandcameo
  • 185
  • 2
  • 11
  • Its not... I don't know what its supposed to do. Correct me if I'm wrong but a vector is supposed to be like an array that can be dynamically resized? – grandcameo Jun 26 '11 at 14:32
  • There's some additional machinery in there, but yes essentially. I'm not sure about the `_Ty` piece (it is Googleable, but the situations I've found haven't applied). One thing is true, your `getNextEvent` method is expecting a `vector<_Ty>*`, so you need to instantiate `midiEvents *` (declaring it like you have one the commented line isn't enough). – jonsca Jun 26 '11 at 15:01

2 Answers2

2

_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

the_mandrill
  • 29,792
  • 6
  • 64
  • 93
1

@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.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160