From d2fd01c2415c911a07598f4c84a457109885fe70 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 14 Dec 2016 11:42:54 +0000 Subject: add API to Evoral::SMF to retrieve all track/instrument names for use when importing --- libs/evoral/evoral/SMF.hpp | 4 +++- libs/evoral/src/SMF.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'libs/evoral') diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index 0cbd5bb638..1a9d2c1084 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -78,8 +78,10 @@ public: bool is_type0 () const { return _type0; } std::set channels () const { return _type0channels; } + void track_names (std::vector&) const; + void instrument_names (std::vector&) const; -private: + private: smf_t* _smf; smf_track_t* _smf_track; bool _empty; ///< true iff file contains(non-empty) events diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index f5dc4fa1e0..4abd69796c 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -472,4 +472,55 @@ SMF::round_to_file_precision (double val) const return round (val * div) / div; } +void +SMF::track_names(vector& names) const +{ + if (!_smf) { + return; + } + + names.clear (); + + Glib::Threads::Mutex::Lock lm (_smf_lock); + + for (uint16_t n = 0; n < _smf->number_of_tracks; ++n) { + smf_track_t* trk = smf_get_track_by_number (_smf, n+1); + if (!trk) { + names.push_back (string()); + } else { + if (trk->name) { + names.push_back (trk->name); + } else { + names.push_back (string()); + } + } + } +} + +void +SMF::instrument_names(vector& names) const +{ + if (!_smf) { + return; + } + + names.clear (); + + Glib::Threads::Mutex::Lock lm (_smf_lock); + + for (uint16_t n = 0; n < _smf->number_of_tracks; ++n) { + smf_track_t* trk = smf_get_track_by_number (_smf, n+1); + if (!trk) { + names.push_back (string()); + } else { + if (trk->instrument) { + names.push_back (trk->instrument); + } else { + names.push_back (string()); + } + } + } +} + + } // namespace Evoral -- cgit v1.2.3