add API to Evoral::SMF to retrieve all track/instrument names for use when importing
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 14 Dec 2016 11:42:54 +0000 (11:42 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 14 Dec 2016 11:46:26 +0000 (11:46 +0000)
libs/evoral/evoral/SMF.hpp
libs/evoral/src/SMF.cpp

index 0cbd5bb638a21a623d981c7c4349ba041afbce2e..1a9d2c1084ce5b07feb7e7c675076f3a598a73ac 100644 (file)
@@ -78,8 +78,10 @@ public:
 
        bool is_type0 () const { return _type0; }
        std::set<uint8_t> channels () const { return _type0channels; }
+       void track_names (std::vector<std::string>&) const;
+       void instrument_names (std::vector<std::string>&) const;
 
-private:
+  private:
        smf_t*       _smf;
        smf_track_t* _smf_track;
        bool         _empty; ///< true iff file contains(non-empty) events
index f5dc4fa1e0def3555b5b94f3cd7161dd4bc82239..4abd69796c137f7f43471d3a616650f35889fe69 100644 (file)
@@ -472,4 +472,55 @@ SMF::round_to_file_precision (double val) const
        return round (val * div) / div;
 }
 
+void
+SMF::track_names(vector<string>& 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<string>& 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