本文整理汇总了C++中MidiTrack::BuildNoteSet方法的典型用法代码示例。如果您正苦于以下问题:C++ MidiTrack::BuildNoteSet方法的具体用法?C++ MidiTrack::BuildNoteSet怎么用?C++ MidiTrack::BuildNoteSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MidiTrack
的用法示例。
在下文中一共展示了MidiTrack::BuildNoteSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFromStream
MidiTrack MidiTrack::ReadFromStream(std::istream &stream)
{
// Verify the track header
const static string MidiTrackHeader = "MTrk";
// I could use (MidiTrackHeader.length() + 1), but then this has to be
// dynamically allocated. More hassle than it's worth. MIDI is well
// defined and will always have a 4-byte header. We use 5 so we get
// free null termination.
char header_id[5] = { 0, 0, 0, 0, 0 };
unsigned long track_length;
stream.read(header_id, static_cast<streamsize>(MidiTrackHeader.length()));
stream.read(reinterpret_cast<char*>(&track_length), sizeof(unsigned long));
if (stream.fail()) throw MidiError(MidiError_TrackHeaderTooShort);
string header(header_id);
if (header != MidiTrackHeader) throw MidiError_BadTrackHeaderType;
// Pull the full track out of the file all at once -- there is an
// End-Of-Track event, but this allows us handle malformed MIDI a
// little more gracefully.
track_length = BigToSystem32(track_length);
char *buffer = new char[track_length + 1];
buffer[track_length] = 0;
stream.read(buffer, track_length);
if (stream.fail())
{
delete[] buffer;
throw MidiError(MidiError_TrackTooShort);
}
// We have to jump through a couple hoops because istringstream
// can't handle binary data unless constructed through an std::string.
string buffer_string(buffer, track_length);
istringstream event_stream(buffer_string, ios::binary);
delete[] buffer;
MidiTrack t;
// Read events until we run out of track
char last_status = 0;
unsigned long current_pulse_count = 0;
while (event_stream.peek() != char_traits<char>::eof())
{
MidiEvent ev = MidiEvent::ReadFromStream(event_stream, last_status);
last_status = ev.StatusCode();
t.m_events.push_back(ev);
current_pulse_count += ev.GetDeltaPulses();
t.m_event_pulses.push_back(current_pulse_count);
}
t.BuildNoteSet();
t.DiscoverInstrument();
return t;
}