Evoral: add methods to SMF to load and access markers/cues in SMF files
This commit is contained in:
parent
4db1c02bd1
commit
f689e9ecab
|
@ -580,4 +580,45 @@ SMF::nth_tempo (size_t n) const
|
||||||
return new Tempo (t);
|
return new Tempo (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SMF::load_markers ()
|
||||||
|
{
|
||||||
|
if (!_smf_track) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::Threads::Mutex::Lock lm (_smf_lock);
|
||||||
|
|
||||||
|
if (_smf_track) {
|
||||||
|
_smf_track->next_event_number = std::min(_smf_track->number_of_events, (size_t)1);
|
||||||
|
}
|
||||||
|
|
||||||
|
smf_event_t* event;
|
||||||
|
|
||||||
|
while ((event = smf_track_get_next_event(_smf_track)) != NULL) {
|
||||||
|
|
||||||
|
if (smf_event_is_metadata(event)) {
|
||||||
|
if (event->midi_buffer[1] == 0x06) {
|
||||||
|
string marker = smf_event_decode (event);
|
||||||
|
if (!marker.empty()) {
|
||||||
|
if (marker.find ("Marker: ") == 0) {
|
||||||
|
marker = marker.substr (8);
|
||||||
|
}
|
||||||
|
_markers.push_back (MarkerAt (marker, event->time_pulses));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event->midi_buffer[1] == 0x07) {
|
||||||
|
string marker = smf_event_decode (event);
|
||||||
|
if (!marker.empty()) {
|
||||||
|
if (marker.find ("Cue Point: ") == 0) {
|
||||||
|
marker = marker.substr (8);
|
||||||
|
}
|
||||||
|
_markers.push_back (MarkerAt (marker, event->time_pulses));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Evoral
|
} // namespace Evoral
|
||||||
|
|
|
@ -118,6 +118,17 @@ public:
|
||||||
|
|
||||||
Tempo* nth_tempo (size_t n) const;
|
Tempo* nth_tempo (size_t n) const;
|
||||||
|
|
||||||
|
struct MarkerAt {
|
||||||
|
std::string text;
|
||||||
|
size_t time_pulses; /* type matches libsmf smf_event_struct.time_pulses */
|
||||||
|
|
||||||
|
MarkerAt (std::string const & txt, size_t tp) : text (txt), time_pulses (tp) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<MarkerAt> Markers;
|
||||||
|
Markers const & markers() const { return _markers; }
|
||||||
|
void load_markers ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
smf_t* _smf;
|
smf_t* _smf;
|
||||||
smf_track_t* _smf_track;
|
smf_track_t* _smf_track;
|
||||||
|
@ -126,6 +137,8 @@ public:
|
||||||
|
|
||||||
bool _type0;
|
bool _type0;
|
||||||
std::set<uint8_t> _type0channels;
|
std::set<uint8_t> _type0channels;
|
||||||
|
|
||||||
|
mutable Markers _markers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; /* namespace Evoral */
|
}; /* namespace Evoral */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user